D3 Force Directed Graph nodes in order

只愿长相守 提交于 2019-12-08 05:00:29

问题


I am using the Force Directed Graph to build a kind of flow diagram. It works fine except that the nodes have no specific order. They are random. I would like the graph to follow a hierarchical order.

var force = d3.layout.force()
    .nodes(d3.values(nodes))
    .links(links)
    .size([width, height])
    .linkDistance(90)
    .gravity(0.6)
    .charge(-2000)
    .linkStrength(0.3);

I want to give the nodes some (numerical) hierarchy. Not explicitly define their placement.

Any help will be appreciated.


回答1:


You can use the force layout with a quantitative foci so the nodes are located based in its numerical hierarchy. A demo from Mike's talk (and the code):

  • Demo
  • Code

Regards



来源:https://stackoverflow.com/questions/19293595/d3-force-directed-graph-nodes-in-order

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