-
Notifications
You must be signed in to change notification settings - Fork 375
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
Enhance Collision to handle shapes other than circles #38
Comments
Implementing a rectangular collision force is relatively straightforward. I wouldn’t overload d3.forceCollide by putting it there, but you could implement your own custom force to do it. Here’s an example in 3.x: |
That's much-needed, Mike! And would be great if it comes to real! 👍 |
I'm having trouble understanding how I am supposed to update nodes from within a callback. I'm assuming there's some async behavior in there. see: https://tonicdev.com/579956eeedc3e41200aac566/579956eeedc3e41200aac567 |
@gravitypersists Please read the documentation for simulation.tick, which says:
So in your example your tick event listener is not invoked until after the result is displayed to the console (assuming that tonic even continues to execute your code). If you want to fix a node’s y-position to zero, set node.fy = 0 and see the documentation for simulation.nodes. (Note that you don’t have to re-set simulation.nodes after setting node.fy; that’s typically only done when you add or remove nodes from the simulation, not when you modify nodes’ properties.) If you want to apply a custom force for every tick of the simulation, register a custom force using simulation.force instead of listening for tick events. Unlike in v3, tick events in v4 are intended for rendering the simulation interactively, not for affecting the result of the simulation. If you want further assistance, please use Stack Overflow tag d3.js or the d3-js Google group to ask for help. This issue is intended to be a discussion around collision detection, not debugging your code. Thank you for your understanding! |
I see. Sorry if this seemed off-topic, only in retrospect do I realize that. I was trying to implement a collide callback for rects similar to the issue at hand and made the faulty assumption that tick callbacks could affect the simulation just as force callbacks could, and was naively using the two interoperably. Thanks for your help, and apologies for asking in the wrong place. So this is not all for nothing, do you think it's appropriate to mention this in the documentation a bit more clearly? I'd be happy to try and fit it in, but only if you suggest so. |
I've been playing with this recently => generic polygon detection is easily done with |
I feel this issue is addressed by the d3-bboxCollide plugin. |
From what I can tell, d3-bboxCollide only detects bounding box collisions. d3.polygonContains only detects point collisions. Anybody found a generic polygon collision solution? That's what I believe this issue is asking for. |
I currently use D3 v3 force layout with custom collision detection to prevent overlapping of text. Instead of using circle radius to prevent overlaps, I use rectangle width/height (derived from getBBox()) as this suits text better. Can we support rectangles in D4's Collision and possibly other shapes?
The text was updated successfully, but these errors were encountered: