Giter VIP home page Giter VIP logo

Comments (4)

mbostock avatar mbostock commented on May 2, 2024 6

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.

mbostock avatar mbostock commented on May 2, 2024

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.

flekschas avatar flekschas commented on May 2, 2024

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.

mbostock avatar mbostock commented on May 2, 2024

Fixed in 1.1.0.

from d3-drag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.