Merge pull request #13 from bkmartinjr/regl-playground

performance - speed up categorical metadata deselection
This commit is contained in:
Colin Megill
2018-05-02 17:24:57 -07:00
committed by GitHub
2 changed files with 23 additions and 12 deletions
@@ -225,11 +225,9 @@ const updateCellSelectionMiddleware = (store) => {
if (inactiveCategories.length > 0) { if (inactiveCategories.length > 0) {
_.each(inactiveCategories, (d) => { _.each(inactiveCategories, (d) => {
_.each(newSelection, (cell, i) => { if (s.controls.categoricalAsCellsMap[d.category] && s.controls.categoricalAsCellsMap[d.category][d.option]) {
if (""+cell[d.category] === ""+d.option) { /* nums and strings to strings -__- */ _.forEach(s.controls.categoricalAsCellsMap[d.category][d.option], (c) => { c.__selected__ = false; });
newSelection[i]["__selected__"] = false; }
}
})
}) })
} }
+20 -7
View File
@@ -34,29 +34,27 @@ const Controls = (state = {
const graphMap = {}; const graphMap = {};
const currentCellSelection = action.data.data.metadata.slice(0); const currentCellSelection = action.data.data.metadata.slice(0);
_.each(action.data.data.graph, (g) => { graphMap[g[0]] = [g[1], g[2]] }); _.each(action.data.data.graph, (g) => { graphMap[g[0]] = [g[1], g[2]] });
_.each(currentCellSelection, (cell) => {
cell["__selected__"] = true;
cell["__color__"] = "rgba(0,0,0,1)" /* initial color for all cells in all charts */
cell["__colorRGB__"] = parseRGB(cell["__color__"]);
});
/* /*
construct a copy of the ranges object that only has categorical construct a copy of the ranges object that only has categorical
replace all counts with bool flags replace all counts with bool flags
ie., everything starts out checked ie., everything starts out checked
we mutate this map in the actions below we mutate this map in the actions below
*/ */
const categoricalAsBooleansMap = {}; const categoricalAsBooleansMap = {}, categoricalAsCellsMap = {};
const continuousUserDefinedRanges = {}; const continuousUserDefinedRanges = {};
_.each(action.data.data.ranges, (value, key) => { _.each(action.data.data.ranges, (value, key) => {
if ( if (
key !== "CellName" && key !== "CellName" &&
value.options /* it's categorical, it has options instead of ranges */ value.options /* it's categorical, it has options instead of ranges */
) { ) {
const optionsAsBooleans = {} const optionsAsBooleans = {}, optionsAsCells = {};
_.each(value.options, (_value, _key) => { _.each(value.options, (_value, _key) => {
optionsAsBooleans[_key] = true; optionsAsBooleans[_key] = true;
optionsAsCells[_key] = [];
}) })
categoricalAsBooleansMap[key] = optionsAsBooleans; categoricalAsBooleansMap[key] = optionsAsBooleans;
categoricalAsCellsMap[key] = optionsAsCells;
} else if ( } else if (
key !== "CellName" && key !== "CellName" &&
value.range value.range
@@ -65,11 +63,26 @@ const Controls = (state = {
} }
}) })
_.each(currentCellSelection, (cell) => {
cell["__selected__"] = true;
cell["__color__"] = "rgba(0,0,0,1)" /* initial color for all cells in all charts */
cell["__colorRGB__"] = parseRGB(cell["__color__"]);
// Add each cell to its categorical metadata set.
_.forEach(cell, (_value, key) => {
if (categoricalAsCellsMap[key] && categoricalAsCellsMap[key][_value]) {
const s = categoricalAsCellsMap[key][_value];
if (s) s.push(cell);
}
});
});
return Object.assign({}, state, { return Object.assign({}, state, {
allCellsOnClient: action.data.data, allCellsOnClient: action.data.data,
currentCellSelection, currentCellSelection,
graphMap, graphMap,
categoricalAsBooleansMap, categoricalAsBooleansMap,
categoricalAsCellsMap,
continuousUserDefinedRanges, continuousUserDefinedRanges,
graphBrushSelection: null, /* if we are getting new cells from the server, the layout (probably? definitely?) just changed, so this is now irrelevant, and we WILL need to call a function to reset state of this kind when cells success happens */ graphBrushSelection: null, /* if we are getting new cells from the server, the layout (probably? definitely?) just changed, so this is now irrelevant, and we WILL need to call a function to reset state of this kind when cells success happens */
}); });