Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache getScreenCTM on start? #5

Closed
mbostock opened this issue May 6, 2016 · 1 comment
Closed

Cache getScreenCTM on start? #5

mbostock opened this issue May 6, 2016 · 1 comment

Comments

@mbostock
Copy link
Member

mbostock commented May 6, 2016

I wonder if it’s worth caching getScreenCTM (and getBoundingClientRect) on start, since they shouldn’t change during a drag gesture?

function pointSvg(node, point) {
  var matrix = node.getScreenCTM().inverse();
  return function(event) {
    point.x = event.clientX, point.y = event.clientY;
    point = point.matrixTransform(matrix);
    return [point.x, point.y];
  };
}

function pointHtml(node) {
  var rect = node.getBoundingClientRect(),
      left = rect.left + node.clientLeft,
      top = rect.top + node.clientTop;
  return function(event) {
    return [event.clientX - left, event.clientY - top];
  };
}

export default function(node) {
  var svg = node.ownerSVGElement || node;
  return svg.createSVGPoint ? pointSvg(node, svg.createSVGPoint()) : pointHtml(node);
}

Related d3/d3#1797.

@mbostock mbostock assigned mbostock and unassigned mbostock May 6, 2016
@mbostock
Copy link
Member Author

mbostock commented May 9, 2016

Not going to pursue this for now.

@mbostock mbostock closed this as completed May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant