本文介绍了D3力布局固定根节点在中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法绘制一些基本的d3力布局图,但努力如何修复根节点在中心。
我的数据相当简单;一个具有一级子节点的根节点。只有一个级别。
我的图的另一个特别的事情是链接距离根据一些参数而变化。
我希望根节点位于图形的中心。
设置其属性'fixed': true不工作。
任何想要将根节点放在中心?
解决方案
on(tick,function(){
nodes [0] .x = w / 2;
nodes [0] .y = h / 2;
应该这样做。
I managed to draw some basic d3 force layout graph, but struggling how to fix root node at the center.
My data is rather simple; one root node with one-level children. Only one level. Another particular thing about my graph is that the link distance varies based on some parameter.
I want root node to be at the center of the graph.
Setting its property 'fixed':true doesn't work. Any idea to place root node at the center?
解决方案force.on("tick", function() { nodes[0].x = w / 2; nodes[0].y = h / 2;
That should do it.
这篇关于D3力布局固定根节点在中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!