Stop Force Layout on d3js and start free dragging nodes

半腔热情 提交于 2019-12-03 06:43:28
riccardo.tasso

At the end I found this related question which implements a solution which I'll adopt.

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

http://bl.ocks.org/norrs/2883411

function nameOfFunction () {
    d3.selectAll(".classOfYourNodes").each(
        function(d) {
            d.fixed = true;
        }
    )
}

The method .each calls the anonymous function, which in this case sets the "fixed" attribute to true for every node within the selection.

Edit: The above is in regards to your comment about wanting to stop all of the nodes and not have the force simulation continue when you drag a node, as calling force.stop() does.

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