D3 force directed graph with drag and drop support to make selected node position fixed when dropped

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 19:36:24

问题


Example on a force direct graph can be found here: http://bl.ocks.org/950642

How can I easily add support for drag and drop? It should set the node to fixed with current location of where it dropped it. It is important that rest of the nodes still uses the 'force directed mode' to position rest of the nodes in the graph automatically

https://github.com/mbostock/d3/wiki/Force-Layout

I've played around a bit without success, and wondering if anyone is able to give me a quick example on how to add such support as explained above.


回答1:


Finally got it working after figuring out it is not ideal to fight with two "drag" listeners (your own, and force.drag) attached to the nodes!

Much better to only have your own "drag"-listener and call tick() manually which is the key feature of getting the force graph to position the nodes for you on every new node position on the node your dragging.

Working example: http://bl.ocks.org/2883411



来源:https://stackoverflow.com/questions/10899725/d3-force-directed-graph-with-drag-and-drop-support-to-make-selected-node-positio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!