d3 / d3-selection

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

Use changedTouches[0] if present in pointer #277

Closed tophtucker closed 3 years ago

tophtucker commented 3 years ago

So I was dragging along and d3.pointer was working for me on desktop Chrome and Safari, but on mobile Safari, clientX and clientY were coming through undefined, leading d3.pointer(event, this) to return [NaN, NaN]. But it works with the old d3.mouse(this) approach, where mouse.js has:

var event = sourceEvent();
if (event.changedTouches) event = event.changedTouches[0];

But now in pointer.js, it's just:

event = sourceEvent(event);

My example works if I add back the check for changedTouches. But maybe there was a good reason for getting rid of it, I don't know.

Examples:

Fil commented 3 years ago

See the discussion in https://github.com/d3/d3-selection/pull/253

tophtucker commented 3 years ago

Ah, I should've searched. Inspires me to add proper multitouch to the thing I was trying to do! 😅