d3 / d3-selection

Transform the DOM by selecting elements and joining to data.
https://d3js.org/d3-selection
ISC License
558 stars 294 forks source link

Handle touch events in pointer() #318

Closed qrest closed 4 months ago

qrest commented 4 months ago

When calling pointer() on a touch event it fails with following error message: SVGPoint.x setter: Value being assigned is not a finite floating-point value. This is because clientX/Y is only present in the respective touch object.

This PR detects if a touch event is present and handles it appropriately.

mbostock commented 4 months ago

You’re supposed to use d3.pointers for this instead of using d3.pointer. It’s to encourage you to think about multitouch rather than assuming that the first touch is equivalent to a pointer.

qrest commented 4 months ago

The documentation for pointer() states "event can be a MouseEvent, a PointerEvent, a Touch, or a custom event holding a UIEvent as event.sourceEvent." So either it's a bug in the code or the documentation is wrong.

mbostock commented 4 months ago

No, the docs are right. A Touch and a TouchEvent are two different things. Given a TouchEvent event you can pass a Touch event.touches[0] to d3.pointer.

qrest commented 4 months ago

I see, thank you for clarifying