Recentering D3力布局图节点点击 [英] Recentering D3 force layout diagram on node click
问题描述
我正在追踪 :
>
点击功能相当简单:
函数点击(d){
d.fixed = true;
d.x = 10;
d.y = 10;
update();
}
我尝试将此添加到函数:
root.forEach(function(d){d.fixed = false;});
您可以使用 force.nodes()
并迭代将固定
属性设置为 false
/ p>
force.nodes()。forEach(function(d){d.fixed = false;});
,然后更新图表。我舍弃了您的示例此处,并添加了一个双击监听器,重新启动强制布局。非常感谢,
I am trying to create a force diagram that gets re-centered on click.
I am following this as a base:
I tried to adjust the click function to set d.fixed=true
and also assign fixed points for d.x
and d.y
.
However, I need to turn d.fixed=false
for all the other nodes. Also, the node does not transition to the center on click.
My question is how do I set all other fixed properties to false and then redraw the force diagram with the new center?
I have prepared an example here:
The click function is fairly straightforward:
function click(d) {
d.fixed=true;
d.x=10;
d.y=10;
update();
}
I tried adding this to the function:
root.forEach(function (d) { d.fixed = false; });
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,
这篇关于Recentering D3力布局图节点点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!