D3 强制布局将根节点固定在中心 [英] D3 force layout fix root node at the center

查看:53
本文介绍了D3 强制布局将根节点固定在中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法绘制了一些基本的 d3 力布局图,但苦于如何在中心修复根节点.

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.

设置其属性 'fixed':true 不起作用.任何想法将根节点放在中心?

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;

应该可以.

这篇关于D3 强制布局将根节点固定在中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆