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

dblclick zooms results in NaN mouse values #202

Closed
Fil opened this issue Feb 8, 2020 · 2 comments
Closed

dblclick zooms results in NaN mouse values #202

Fil opened this issue Feb 8, 2020 · 2 comments

Comments

@Fil
Copy link
Member

Fil commented Feb 8, 2020

In https://observablehq.com/d/7a912fba32fbe641 we've noticed that, when we dblclick to zoom (or shift-dblclick to zoom out), the value of d3.mouse() is [NaN,NaN], which resulted in spurious rotations.

I've fixed it by relying on the previously recorded mouse position (the one from the first click), but it seems wrong that d3.mouse returns NaNs.

(I'm not sure if this belongs to d3-zoom or d3-selection)

@mbostock
Copy link
Member

mbostock commented Feb 8, 2020

I think this is the expected behavior, unfortunately. The problem is that when you dblclick, the zoom behavior schedules a transition to start on the next animation frame. By the time the transition starts, and the zoom start event is dispatched, the dblclick event has expired and so the sourceEvent on the zoom start event is null causing d3.mouse to return [NaN, NaN].

If you want to get the mouse coordinates of the dblclick, you need to listen to the dblclick, not just the start event on the zoom behavior.

Alternatively, the zoom behavior would somehow need to set the sourceEvent of the zoom start event to the expired dblclick event.

@Fil
Copy link
Member Author

Fil commented May 28, 2020

With b56cc7e the dblclick handler receives a sourceEvent — I've updated the test notebook.

@Fil Fil closed this as completed in 1ec0da7 Aug 23, 2020
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