Comments (4)
I’m going to leave this open because I think it’s still a good enhancement to use a distance threshold for suppressing click.
from d3-drag.
as soon as the mousedown event fires, D3 starts listening to the mousemove.drag event, which immediately starts firing without any actual cursor move.
I’m going to be a tiny bit pedantic, but bear with me, as your point is taken.
Yes, d3-drag listens for a mousemove following mousedown, and interprets that as a non-empty drag gesture and thus cancels the subsequent click. But no, in general, a mousemove event does not follow a mousedown event unless the mouse also moved during the button press. Yet this behavior may be browser- or platform-specific, and is certainly device-specific: given a sensitive input device, pressing the mouse button is more likely to cause a small amount of mouse movement which then triggers mousemove events.
On the devices and platforms I primarily use (macOS), the current implementation works fine. But it is brittle in that any degree of mouse movement is interpreted as a non-empty drag gesture, and given the analog (or uncertain) nature of input, it would be more robust to have a distance threshold.
I’d compute the threshold based on the squared Euclidean distance, not that it makes much difference:
let d2;
drag.on('start', () => {
d2 = 0;
});
drag.on('drag', () => {
d2 += d3.event.dx * d3.event.dx + d3.event.dy * d3.event.dy;
});
drag.on('end', () => {
if (d2 < clickTolerance) {
d3.select(window).on('click.drag', null);
}
});
Since you can have multiple active drag gestures, the d2
state here should be tracked on a per-gesture basis.
from d3-drag.
I have to confess I based my observations on one setup only (Mac OS X 10.11.6 and Google Chrome). For whatever reason I experienced constant mousemove event firing but I am unable to reproduce this. As long as I can't figure out what caused this weird behavior I assume this is no issue (or simply a technical issue on my end).
Sorry for taking up your time.
from d3-drag.
Fixed in 1.1.0.
from d3-drag.
Related Issues (20)
- Possible typo in README HOT 2
- What are the perposes of functions yesdrag and nodrag?
- Drag event on Chrome 72 HOT 3
- d3 mouseup event not firing HOT 1
- Drag Event Issue on Windows Chrome 74, related to solution for #47 HOT 1
- The default filter should return false if event.ctrlKey. HOT 5
- drag start event is don't send when Ctrl-key is press HOT 1
- drag.on("init") ? HOT 7
- Click event not firing if drag enables with simulation HOT 1
- Non-cancelable event HOT 3
- remove drag.container? HOT 1
- Use native events (*element*.dispatchEvent) instead of d3-dispatch? HOT 1
- remove dragEvent.on?
- d3.event is not available in version 6.1.1 HOT 1
- DragEvent missing event.currentTarget for arrow function node selection HOT 1
- Make event listeners non-passive. HOT 2
- d3.drag() causes error in testing mousedown event via jsdom HOT 4
- d3.pointer() could use event.touches[0] HOT 2
- Add event.currentTarget
- Support d3.drag in testing environments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-drag.