Recentering D3 force layout diagram on node click

前端 未结 2 838
忘掉有多难
忘掉有多难 2021-01-05 11:23

I am trying to create a force diagram that gets re-centered on click.

I am following this as a base:

\"e

2条回答
  •  无人及你
    2021-01-05 11:57

    You can access the nodes using force.nodes() and iterate to set the fixed attribute to false.

    force.nodes().forEach(function(d) { d.fixed = false; });
    

    and then update the graph. I forked your example here and added a double click listener that restart the force layout. Regards,

提交回复
热议问题