d3 / d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
https://d3js.org/d3-zoom
ISC License
501 stars 144 forks source link

About click behavior #223

Closed youlinaa closed 3 years ago

youlinaa commented 3 years ago

Hello, I have a doubt after reading your zoomjs code

There is a problem when the mouse is clicked (not moved) but the mousemove (zoom) event is triggered.

In the mousemoved method of zoomjs, it seems to only refresh the state of g.moved without blocking the zoom event

Did i miss something else about g.moved? Why not to stop emit?

 if (!g.moved) {
   var dx = event.clientX - x0, dy = event.clientY - y0;
   g.moved = dx * dx + dy * dy > clickDistance2;
 }

 if(!g.moved) return

 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));

https://github.com/d3/d3-zoom/blob/db169eadbacc1ab952ced249c9dbe8db3b68bac2/src/zoom.js#L292

mbostock commented 3 years ago

It’s not clear to me whether this is a question or a bug report. If this is a bug report, please include a live example that demonstrates the problem. Thank you.