Stop Force Layout on d3js and start free dragging nodes

前端 未结 2 1727
感动是毒
感动是毒 2021-02-09 02:10

I\'m using the force layout to represent a directed unweighted network. My inspiration comes from the following example: http://bl.ocks.org/mbostock/1153292

2条回答
  •  情歌与酒
    2021-02-09 02:49

    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.

提交回复
热议问题