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

Flag in drag event to signal reaching clickDistance threshold #166

Closed
Herst opened this issue Feb 2, 2018 · 1 comment
Closed

Flag in drag event to signal reaching clickDistance threshold #166

Herst opened this issue Feb 2, 2018 · 1 comment

Comments

@Herst
Copy link

Herst commented Feb 2, 2018

In my application I want to do certain things only after I am certain that the user intents to do a drag, e.g.:

  • Adding the styles for dragged elements. If I would do it on the drag start event then it the style would be added on every mousedown which is not what I want.

  • .raise() the element being dragged. If I would do it right away it might cause the click event to not be triggered (at least in some browsers) if the element got removed from the DOM.

The way I solved it is to simply use the delta x and y inside the drag event handler to calculate whether the click stance threshold has been breached or not.

Now d3 already does the same calculation already, I wondered whether it couldn't just simply tell me about whether the distance has been overstepped in the drag event, e.g. using d3.event.isOutsideClickDistance.


On a side note, an alternative idea would be a .dragDistance() which would cause the start events to only appear after a certain distance. This would cause the elements to appear a bit sticky though and it depends on the specific use case whether that's what you want or not.

@Herst
Copy link
Author

Herst commented Feb 2, 2018

Oops, wrong project. I'm sorry. 😭

Reposted at d3/d3-drag#48.

@Herst Herst closed this as completed Feb 2, 2018
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

1 participant