From 354a3857ccff04095e69d241a081e26309518dfb Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 27 Nov 2017 02:41:50 -0800 Subject: [PATCH] remove excess methods and process around metadata type coercion --- src/components/continuous/util.js | 74 +++---------------------------- 1 file changed, 6 insertions(+), 68 deletions(-) diff --git a/src/components/continuous/util.js b/src/components/continuous/util.js index 9f69f4f1..fadccb62 100644 --- a/src/components/continuous/util.js +++ b/src/components/continuous/util.js @@ -10,38 +10,18 @@ export const innerHeight = height - 2; 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) => { const newArr = [] _.each(data, (value, key) => { if (value.range) { 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 */ - type: types["Number"], - scale: d3.scaleSqrt().range([innerHeight, 0]) + type: { + 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])]; }); }; - -/***************************************** -****************************************** - 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 - } -}