.separation(function (a, b) {
return (a.parent == b.parent ? 1 : 2) / a.depth;
})
那不起作用。我还尝试计算哪个深度有最多的子节点,然后告诉舞台的高度为children * spaceBetweenNodes
。这让我更接近了,但仍然不准确。
depthCounts = [];
nodes.forEach(function(d, i) {
d.y = d.depth * 180;
if(!depthCounts[d.depth])
depthCounts[d.depth] = 0;
if(d.children)
{
depthCounts[d.depth] += d.children.length;
}
});
tree_resize(largest_depth(depthCounts) * spaceBetweenNodes);
我也尝试在下面的方法中更改节点的x
值,以便计算y
分离,但没有成功。我本来想发布这个更改,但是我从我的代码中删除了它。
nodes.forEach(function(d, i) {
d.y = d.depth * 180;
});
如果您知道一种方法可以实现节点之间的最小垂直间距,请提供建议。非常感谢。我可能遗漏了一些非常简单的东西。