Skip to content

Instantly share code, notes, and snippets.

@xoor-io
Created May 11, 2018 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoor-io/269253985e24094782e58d1432f638c8 to your computer and use it in GitHub Desktop.
Save xoor-io/269253985e24094782e58d1432f638c8 to your computer and use it in GitHub Desktop.
d3-canvas-brush-zoom-09
const selection = svgChart.select(".selection");
const posValue = Math.abs(distance);
selection.attr('width', posValue * scale).attr('height', posValue);
if (xPosition < brushStartPoint.x) {
selection.attr('x', xPosition);
}
if (yPosition < brushStartPoint.y) {
selection.attr('y', yPosition);
}
const minX = Math.min(brushStartPoint.x, xPosition);
const maxX = Math.max(brushStartPoint.x, xPosition);
const minY = Math.min(brushStartPoint.y, yPosition);
const maxY = Math.max(brushStartPoint.y, yPosition);
lastSelection = { x1: minX, x2: maxX, y1: minY, y2: maxY };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment