D3 带有拖放支持的强制有向图,使选定的节点位置在放下时固定 [英] D3 force directed graph with drag and drop support to make selected node position fixed when dropped

查看:27
本文介绍了D3 带有拖放支持的强制有向图,使选定的节点位置在放下时固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在此处找到有关力直接图的示例:http://bl.ocks.org/950642

如何轻松添加对拖放的支持?它应该将节点设置为固定节点的当前位置.重要的是其余节点仍然使用力导向模式"自动定位图中的其余节点

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

我玩了一段时间没有成功,想知道是否有人能够给我一个简单的例子来说明如何添加上述支持.

解决方案

在发现与连接到节点的两个拖动"侦听器(您自己的和 force.drag)进行斗争并不理想后,终于让它工作了!

最好只拥有自己的拖动"侦听器并手动调用 tick(),这是让力图为您在拖动节点上的每个新节点位置上定位节点的关键功能.

工作示例:http://bl.ocks.org/2883411

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.

解决方案

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

这篇关于D3 带有拖放支持的强制有向图,使选定的节点位置在放下时固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆