performance - parse color descriptions once

This commit is contained in:
bkmartinjr
2018-04-30 20:20:50 -07:00
parent c98dd20cb3
commit 118248446e
5 changed files with 41 additions and 49 deletions
+16 -7
View File
@@ -1,6 +1,9 @@
import uri from "urijs";
import * as globals from "../globals";
import _ from "lodash";
import {
parseRGB
} from "../util/parseRGB";
/*
https://medium.com/@jacobp100/you-arent-using-redux-middleware-enough-94ffe991e6
@@ -47,7 +50,7 @@ const updateCellSelectionMiddleware = (store) => {
(a) once the cells have loaded.
(b) each time a user changes a color control we need to update currentCellSelection colors
This is available to all the draw functions as cell["__color__"]
This is available to all the draw functions as cell["__color__"] and cell["__colorRGB__"]
*/
if (action.type === "color by categorical metadata") {
@@ -57,9 +60,11 @@ const updateCellSelectionMiddleware = (store) => {
colorScale = d3.scaleOrdinal().range(globals.ordinalColors);
_.each(currentSelectionWithUpdatedColors, (cell, i) => {
currentSelectionWithUpdatedColors[i]["__color__"] = colorScale(
let c = colorScale(
cell[action.colorAccessor]
)
);
currentSelectionWithUpdatedColors[i]["__color__"] = c;
currentSelectionWithUpdatedColors[i]["__colorRGB__"] = parseRGB(c);
})
}
@@ -71,11 +76,13 @@ const updateCellSelectionMiddleware = (store) => {
.range([1,0])
_.each(currentSelectionWithUpdatedColors, (cell, i) => {
currentSelectionWithUpdatedColors[i]["__color__"] = d3.interpolateViridis(
let c = d3.interpolateViridis(
colorScale(
cell[action.colorAccessor]
)
)
);
currentSelectionWithUpdatedColors[i]["__color__"] = c;
currentSelectionWithUpdatedColors[i]["__colorRGB__"] = parseRGB(c);
})
}
@@ -113,11 +120,13 @@ const updateCellSelectionMiddleware = (store) => {
.range([1,0]) /* invert viridis... probably pass this scale through to others */
_.each(currentSelectionWithUpdatedColors, (cell, i) => {
currentSelectionWithUpdatedColors[i]["__color__"] = d3.interpolateViridis(
let c = d3.interpolateViridis(
colorScale(
expressionMap[cell.CellName][indexOfGene]
)
)
);
currentSelectionWithUpdatedColors[i]["__color__"] = c;
currentSelectionWithUpdatedColors[i]["__colorRGB__"] = parseRGB(c);
})
}