performance - speed up categorical metadata deselection

This commit is contained in:
bkmartinjr
2018-05-01 14:54:55 -07:00
parent af09276951
commit 56e66088bf
2 changed files with 20 additions and 12 deletions
@@ -225,11 +225,8 @@ const updateCellSelectionMiddleware = (store) => {
if (inactiveCategories.length > 0) { if (inactiveCategories.length > 0) {
_.each(inactiveCategories, (d) => { _.each(inactiveCategories, (d) => {
_.each(newSelection, (cell, i) => { const cellsInCategory = _.get(s.controls.categoricalAsCellsMap, [d.category, d.option]);
if (""+cell[d.category] === ""+d.option) { /* nums and strings to strings -__- */ _.forEach(cellsInCategory, (c) => { c.__selected__ = false; });
newSelection[i]["__selected__"] = false;
}
})
}) })
} }
+18 -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,24 @@ 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) => {
const s = _.get(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 */
}); });