Skip to content

Instantly share code, notes, and snippets.

@xoor-io
Created May 11, 2018 15:06
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/d3fdae8aec1f97b2ff355f20e9c7469c to your computer and use it in GitHub Desktop.
Save xoor-io/d3fdae8aec1f97b2ff355f20e9c7469c to your computer and use it in GitHub Desktop.
d3-canvas-brush-zoom-08
let xPosition = brushStartPoint.x + distance * scale * xCorMulti;
const oldDistance = distance;
if (xPosition > width) {
distance = (width - brushStartPoint.x) / scale;
xPosition = width;
} else if (xPosition < 0) {
distance = brushStartPoint.x / scale;
xPosition = 0;
}
if (oldDistance !== distance) {
distance *= (oldDistance < 0) ? -1 : 1;
yPosition = brushStartPoint.y + distance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment