简体   繁体   English

在D3树布局中设置最大链接长度

[英]Setting Max Length of Links in D3 Tree Layout

I have a tree graph very similar to the one here: http://bl.ocks.org/mbostock/999346 and I would like to limit the spacing vertically of the nodes; 我有一个非常类似于这里的树图: http//bl.ocks.org/mbostock/999346我想限制节点的垂直间距; if you look at the tree you will see that when there are just two nodes, they take up the entire canvas (the link between the two nodes is very long), and as other nodes are inserted, the link(s) are resized to fit. 如果您查看树,您会看到当只有两个节点时,它们会占用整个画布(两个节点之间的链接非常长),并且在插入其他节点时,链接会调整为适合。 I would like to limit the link length to some max number so that the tree is more compact with fewer nodes. 我想将链接长度限制为某个最大数量,以便树更紧凑,节点更少。

Jason Davies ' approach of looping over the nodes after d3.layout.tree has run and overwriting each node's y-value works well for me. 在d3.layout.tree运行并覆盖每个节点的y值后, Jason Davies在节点上循环的方法对我来说效果很好。 (described in this d3 github issue comment ) (在本d3 github问题评论中描述)

So, something like 所以,像

nodes.forEach(function(node){
    node.y = (node.depth * 90); // 90px per level.
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM