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

d3.pointer multitouch #245

Closed
Fil opened this issue May 8, 2020 · 3 comments
Closed

d3.pointer multitouch #245

Fil opened this issue May 8, 2020 · 3 comments

Comments

@Fil
Copy link
Member

Fil commented May 8, 2020

(On branch two)

d3.pointer(TouchEvent) currently returns [NaN,NaN]; this can be fixed by adding at the top of src/pointer.js:

  if (event instanceof TouchEvent) event = event.touches[0];

This way we can call d3.pointer(event) to get a single point.

To access the multiple touches is still a bit complex:
[...event.touches].map(e => d3.pointer(e, event.currentTarget))

It might be nice to add d3.pointers(event[, node]), which would return an array of touches (for any event type, though only multitouch would return an array with more than one point).

demo: https://observablehq.com/d/4e6b3fcf97903e79

Ref: #191

Fil added a commit that referenced this issue May 8, 2020
- add d3.pointers for multitouch events

closes #245
This was referenced May 8, 2020
@Fil
Copy link
Member Author

Fil commented May 13, 2020

Would be fixed by #246

@mbostock
Copy link
Member

This was intentional; you’re supposed to pass a Touch to d3.pointer, not a TouchEvent, to indicate which touch you care about.

The problem with d3.pointer (and before it, d3.mouse) automatically pulling out the first touch or the first changed touch is that it always leads to broken multitouch interaction. This behavior felt like a footgun, where clients thought they were supporting touch interaction by unifying a mousedown/touchstart or mousemove/touchmove handler, but in practice it would stop working as soon as more than one touch became active.

There is the question of migration and backwards-compatibility, though. If we make d3.pointer strict (as it is now), then it becomes more tedious for callers to adopt because they have to pass in the touch themselves. But since we’re changing the API anyway, we could introduce a deprecated method that implements the old, non-recommended behavior. Something like d3.anyPointer(event), with a note that people should switch to using d3.pointer. We could even call it d3.mouse(event, node = event.currentTarget), but it still wouldn’t be backwards-compatible because you need to pass in the event. For that matter, we could also retain equivalent versions of d3.touch(eventOrTouches, identifier, node = event.currentTarget) and d3.touches(eventOrTouches, node = event.currentTarget, …) to assist migration.

@Fil
Copy link
Member Author

Fil commented May 19, 2020

Thanks for the comments they clarified a lot of things. I don't think we want a new deprecated API, better work with what we have now, and help migrate to Pointer Events.

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

2 participants