Skip to content

Commit

Permalink
Handle missing targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jul 30, 2019
1 parent 65c9592 commit 9bce1bd
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/pointer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
export default function(event, node = event.currentTarget) {
var svg = node.ownerSVGElement || node;

if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
point.x = event.clientX, point.y = event.clientY;
point = point.matrixTransform(node.getScreenCTM().inverse());
return [point.x, point.y];
if (node) {
var svg = node.ownerSVGElement || node;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
point.x = event.clientX, point.y = event.clientY;
point = point.matrixTransform(node.getScreenCTM().inverse());
return [point.x, point.y];
}
if (node.getBoundingClientRect) {
var rect = node.getBoundingClientRect();
return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
}
}

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

return [event.pageX, event.pageY];
}

0 comments on commit 9bce1bd

Please sign in to comment.