d3.js: suggested node position in force layout

巧了我就是萌 提交于 2019-12-03 03:19:29

问题


I would like to create a graph where nodes have suggested positions, but I would also like to use the force layout to ensure the nodes themselves don't overlap. Is this possible in d3?


回答1:


Yes, you can do this by:

  • Disabling the default gravity and charge forces.
  • Implementing collision detection.
  • Implementing "custom" gravity that attracts each node to its suggested position.

Here's a live example:

  • http://bl.ocks.org/1804919

Similar techniques were used in Shan Carter's visualization of Obama's 2013 budget proposal, which are further discussed in a tutorial by Jim Vallandingham.



来源:https://stackoverflow.com/questions/11397961/d3-js-suggested-node-position-in-force-layout

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