d3 / d3-drag

Drag and drop SVG, HTML or Canvas using mouse or touch input.

Home Page:https://d3js.org/d3-drag

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is React compatible with d3-drag?

alexung opened this issue · comments

My situation is that I have multiple polylines/polygons with circles at each point, and when I click a circle I'd like the polyline to move appropriately. I don't have any id's/className's on any polyline, and the circles are being caught via d3.event.

I have a version of this working (somewhat) at the moment but there are few issues:

  1. My cursor, if moving too fast, will stop dragging the previously-dragged circle
  2. The circle, if it gets too close to another point with a circle on it, will stop moving the point that I was originally moving and instead move the point that I'm close to.
  3. Sometimes, circles are completely dragged off the line and unable to rejoin the line.

screen shot 2017-09-25 at 7 47 00 pm

I'm confused about how to get drag and drop to work with d3/react and if this is even a potentially fruitful pursuit. Would appreciate some help.

If the drag behavior is only listening to your circles, then if the mouse “escapes” a circle, you’ll stop receiving mouse events and drag will stop. So typically you need to put something in the background to capture mouse events, such as a rect with fill: none and pointer-events: all.

Please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗