D3 force layout fix root node at the center

橙三吉。 提交于 2019-11-26 17:11:45

问题


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?


回答1:


force.on("tick", function() {
    nodes[0].x = w / 2;
    nodes[0].y = h / 2;

That should do it.



来源:https://stackoverflow.com/questions/21843206/d3-force-layout-fix-root-node-at-the-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!