mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 02:08:12 +08:00
remove excess methods and process around metadata type coercion
This commit is contained in:
@@ -10,38 +10,18 @@ export const innerHeight = height - 2;
|
|||||||
|
|
||||||
export const devicePixelRatio = window.devicePixelRatio || 1;
|
export const devicePixelRatio = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
export const types = {
|
|
||||||
"Number": {
|
|
||||||
key: "Number",
|
|
||||||
coerce: function(d) { return +d; },
|
|
||||||
extent: d3.extent,
|
|
||||||
within: function(d, extent, dim) { return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1]; },
|
|
||||||
defaultScale: d3.scaleSqrt().range([innerHeight, 0])
|
|
||||||
},
|
|
||||||
"String": {
|
|
||||||
key: "String",
|
|
||||||
coerce: String,
|
|
||||||
extent: function (data) { return data.sort(); },
|
|
||||||
within: function(d, extent, dim) { return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1]; },
|
|
||||||
defaultScale: d3.scalePoint().range([0, innerHeight])
|
|
||||||
},
|
|
||||||
"Date": {
|
|
||||||
key: "Date",
|
|
||||||
coerce: function(d) { return new Date(d); },
|
|
||||||
extent: d3.extent,
|
|
||||||
within: function(d, extent, dim) { return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1]; },
|
|
||||||
defaultScale: d3.scaleTime().range([0, innerHeight])
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createDimensions = (data) => {
|
export const createDimensions = (data) => {
|
||||||
const newArr = []
|
const newArr = []
|
||||||
_.each(data, (value, key) => {
|
_.each(data, (value, key) => {
|
||||||
if (value.range) {
|
if (value.range) {
|
||||||
newArr.push({
|
newArr.push({
|
||||||
key: key, /* room for confusion: lodash calls this key, it's also the name of the property parallel coords code is looking for */
|
key: key, /* room for confusion: lodash calls this key, it's also the name of the property parallel coords code is looking for */
|
||||||
type: types["Number"],
|
type: {
|
||||||
scale: d3.scaleSqrt().range([innerHeight, 0])
|
within: (d, extent, dim) => {
|
||||||
|
return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scale: d3.scaleSqrt().range([innerHeight, 0]).domain([0, value.range.max])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -69,45 +49,3 @@ export const project = (d, dimensions, xscale) => {
|
|||||||
return [xscale(i),p.scale(d[p.key])];
|
return [xscale(i),p.scale(d[p.key])];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************
|
|
||||||
******************************************
|
|
||||||
process data and extract features
|
|
||||||
******************************************
|
|
||||||
******************************************/
|
|
||||||
|
|
||||||
export const processData = (metadata, dimensions) => {
|
|
||||||
// shuffle the metadata! - or not, this is a visual effect
|
|
||||||
// metadata = d3.shuffle(metadata);
|
|
||||||
|
|
||||||
metadata.forEach((d) => {
|
|
||||||
dimensions.forEach((p) => {
|
|
||||||
d[p.key] = !d[p.key] ? null : p.type.coerce(d[p.key]);
|
|
||||||
});
|
|
||||||
|
|
||||||
// truncate long text strings to fit in metadata table
|
|
||||||
for (var key in d) {
|
|
||||||
if (d[key] && d[key].length > 35) d[key] = d[key].slice(0,36);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// type/dimension default setting happens here
|
|
||||||
dimensions.forEach((dim) => {
|
|
||||||
if (!("domain" in dim)) {
|
|
||||||
// detect domain using dimension type's extent function
|
|
||||||
dim.domain = d3_functor(dim.type.extent)(
|
|
||||||
metadata.map((d) => { return d[dim.key]; })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!("scale" in dim)) {
|
|
||||||
// use type's default scale for dimension
|
|
||||||
dim.scale = dim.type.defaultScale.copy();
|
|
||||||
}
|
|
||||||
dim.scale.domain(dim.domain);
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
processedMetadata: metadata,
|
|
||||||
processedDimensions: dimensions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user