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

Add d3.pointers. #255

Merged
merged 7 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add d3.pointers.
  • Loading branch information
mbostock committed Aug 3, 2020
commit eea6d35633da7d1791208ea6021b1d3a36da2352
3 changes: 3 additions & 0 deletions src/pointer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import sourceEvent from "./sourceEvent.js";

export default function(event, node = event.currentTarget) {
event = sourceEvent(event);
Fil marked this conversation as resolved.
Show resolved Hide resolved
if (node) {
var svg = node.ownerSVGElement || node;
if (svg.createSVGPoint) {
Expand Down
10 changes: 10 additions & 0 deletions src/pointers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pointer from "./pointer.js";
import sourceEvent from "./sourceEvent.js";

export default function(events, node) {
if (events.target) { // i.e., instanceof Event, not TouchList or iterable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I’d prefer events instanceof Event here, but our current custom events in d3-drag etc. don’t extend Event, so that isn’t possible. It might be possible to change them to extend Event, although for all I know, that may introduce other problems.

events = sourceEvent(events);
events = events.touches || [events];
Fil marked this conversation as resolved.
Show resolved Hide resolved
}
return Array.from(events, event => pointer(event, node));
}
5 changes: 5 additions & 0 deletions src/sourceEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function(event) {
let sourceEvent;
while (sourceEvent = event.sourceEvent) event = sourceEvent;
return event;
}