From 06a5eedd0e456ffbb9fc20170d4b00991656a83c Mon Sep 17 00:00:00 2001 From: bkmartinjr Date: Wed, 9 May 2018 21:10:59 -0700 Subject: [PATCH] performance - remove scaling from inner render loop --- src/globals.js | 8 ++++++ .../updateCellSelectionMiddleware.js | 25 ++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/globals.js b/src/globals.js index 962e68a6..bd6986ba 100644 --- a/src/globals.js +++ b/src/globals.js @@ -78,11 +78,19 @@ export const graphXScale = scaleLinear( [0, 1], [0 + graphMargin.left, graphWidth - graphMargin.right] ); +graphXScale.invert = scaleLinear( + [0 + graphMargin.left, graphWidth - graphMargin.right], + [0, 1] +); // d3.scaleLinear().domain([0,1]).range([graphHeight - graphMargin.bottom, 0 + graphMargin.top]) export const graphYScale = scaleLinear( [0, 1], [graphHeight - graphMargin.bottom, 0 + graphMargin.top] ); +graphYScale.invert = scaleLinear( + [graphHeight - graphMargin.bottom, 0 + graphMargin.top], + [0, 1] +); export const ordinalColors = [ "#0ac115", diff --git a/src/middleware/updateCellSelectionMiddleware.js b/src/middleware/updateCellSelectionMiddleware.js index 5ac370f1..7d507dd4 100644 --- a/src/middleware/updateCellSelectionMiddleware.js +++ b/src/middleware/updateCellSelectionMiddleware.js @@ -73,18 +73,31 @@ const updateCellSelectionMiddleware = store => { ? action.brushCoords : s.controls.graphBrushSelection; + const northwestX = globals.graphXScale.invert( + graphBrushSelection.northwestX + ); + const southeastX = globals.graphXScale.invert( + graphBrushSelection.southeastX + ); + const northwestY = globals.graphYScale.invert( + graphBrushSelection.northwestY + ); + const southeastY = globals.graphYScale.invert( + graphBrushSelection.southeastY + ); + const graphVec = s.controls.graphVec; for (let i = 0; i < newSelection.length; i++) { const cell = newSelection[i]; const cellId = cell.__cellIndex__; - const x = globals.graphXScale(graphVec[2 * cellId]); - const y = globals.graphYScale(graphVec[2 * cellId + 1]); + const x = graphVec[2 * cellId]; + const y = graphVec[2 * cellId + 1]; const pointIsInsideBrushBounds = - x >= graphBrushSelection.northwestX && - x <= graphBrushSelection.southeastX && - y >= graphBrushSelection.northwestY && - y <= graphBrushSelection.southeastY; + x >= northwestX && + x <= southeastX && + y <= northwestY && + y >= southeastY; if (!pointIsInsideBrushBounds) { cell.__selected__ = false;