Increasing the connecting link length in d3 when the node is expanded

后端 未结 1 1946
醉话见心
醉话见心 2021-01-28 10:33

I am working on collapsible force layout in d3.The problem I am facing is I need to increase the length of the link between the nodes when it is clicked keeping the link distanc

相关标签:
1条回答
  • 2021-01-28 10:56

    Yes you can do this by defining a function for the force.linkDistance something like this:

    var force = d3.layout.force()
        .linkDistance(function(d){
            if(d.target._children){
                return 50;//target is not expanded so link distance is 50
            } else {
                return 200;//target is expanded so link distance is 200
            }
        })
    

    Full working code here.

    0 讨论(0)
提交回复
热议问题