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

d3Selection.pointer does not work on mobile device #270

Closed
stoneshell opened this issue Nov 25, 2020 · 3 comments
Closed

d3Selection.pointer does not work on mobile device #270

stoneshell opened this issue Nov 25, 2020 · 3 comments

Comments

@stoneshell
Copy link

event.clientX, event.clientY are undefined.
1606265752401

Maybe get the values from event.touches ?
1606265926164

@mbostock
Copy link
Member

Please read the documentation:

https://github.com/d3/d3-selection/blob/master/README.md#pointer

You need to pass a Touch to d3.pointer, not a TouchEvent. Also see d3.pointers.

@HarelM
Copy link

HarelM commented Oct 8, 2022

I migrated to latest version and also suffered from this mistake.
But moreover, I'm listening to both touch and mouse and I'm passing the e.touches[0] in case of touch and e in case of mouse.
The problem is that the currentTarget for Touch does not exists so passing Touch to pointer will result in an unwanted behavior.
While I understand I can pass the e.currentTarget it would be helpful to write it in the docs linked above or even in the method description to prevent other developers from creating a bug :-)

@HarelM
Copy link

HarelM commented Oct 8, 2022

So basically my code looks like this when using pointer

const expectedEvent = (window.TouchEvent && e instanceof TouchEvent) ? e.touches[0] : e;
return this.chartElements.xScale.invert(d3.pointer(expectedEvent, e.currentTarget)[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants