admin管理员组文章数量:1347701
I am trying to arrange my nodes in the form of a tree. For now, I am working off of this example from here. Currently, I am relying on a force directed layout but am trying to modify it such that I can obtain a tree with predetermined number of levels i.e. if a node belongs to a particular "Layer" it should belong to the same area as other nodes in the layer.
I have tried to explain more in the picture below but does anyone have any suggestions for this? Are there any predetermined algorithms inside d3
that do this or can be tweaked to achieve this?
I am trying to arrange my nodes in the form of a tree. For now, I am working off of this example from here. Currently, I am relying on a force directed layout but am trying to modify it such that I can obtain a tree with predetermined number of levels i.e. if a node belongs to a particular "Layer" it should belong to the same area as other nodes in the layer.
I have tried to explain more in the picture below but does anyone have any suggestions for this? Are there any predetermined algorithms inside d3
that do this or can be tweaked to achieve this?
- The source contains an example for a dynamic tree. You should have a look at it, it might be what you want (at least it looks similar). edit: I mean this example. – Felix Kling Commented Mar 15, 2012 at 0:47
- 1 Is there a reason you're using a force-directed layout here instead of a static tree layout, e.g. bl.ocks/1061834 ? – nrabinowitz Commented Mar 15, 2012 at 0:48
- @nrabinowitz: +1 Thank you. Can't believe I missed it! I guess both will serve my purpose! Is there a way I can make them interactive so that the nodes just e back when I drag them somewhere? This helps drag some node and explain it to someone. – Legend Commented Mar 15, 2012 at 0:55
- @FelixKling: +1 Thank You. I had one additional question that I wrote above. – Legend Commented Mar 15, 2012 at 0:56
2 Answers
Reset to default 10Your diagram looks nearly identical to this example which uses a custom gravity force based on the depth. There's another example using a custom force which attracts to the parent node. These are both from my talk on force layouts.
Of course, force layouts are only one option—and as @nrabinowitz said there are many more hierarchy layouts. You can find more interactive hierarchy examples in my SVG Open talk.
The examples that mbostock referred to are here: https://mbostock.github.io/d3/talk/20110921/#20 You can inspect the HTML to see the Javascript code.
本文标签: javascriptHow can I construct a tree using d3 and its force layoutStack Overflow
版权声明:本文标题:javascript - How can I construct a tree using d3 and its force layout? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743835430a2547308.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论