Transition from one forced-directed graph to another graph in d3js

霸气de小男生 提交于 2019-12-03 18:03:56

问题


I have two Collapsible Force Trees for same nodes.

I haven't seen an example that we can transit from one tree to another with nodes transition and edges reconstruction in d3js.

Is there any way to do that?

Another relevant question, could we initialize the position of each node for forced-directed graph?

EDIT: Here is an example. I have two trees, the link is one, and I have another tree with same molecules but different tree structure. I am thinking it will be nice if I can animate between different trees for same molecules or entities.


回答1:


In principle, these are the steps to follow.

  • Stop the force layout to freeze the positions of the nodes.
  • Disappear the links (e.g. fade out).
  • Transition the nodes to their new positions. This can be done by setting the new positions on the old data or changing the data completely and then using the same code as in the tick handler for a force layout with a transition
  • Re-add the links.
  • If the new layout also uses a force layout, start that.

I've implemented an example of this here. I uses two sets of data and two force layouts. At first, only the nodes and links of the first force layout are displayed and the second only runs in the background. Then, the first is stopped and I follow the steps outlined above.

This isn't going to satisfy all requirements (e.g. with respect to how nodes should transition), but can be used as a starting point for such an implementation.



来源:https://stackoverflow.com/questions/21122811/transition-from-one-forced-directed-graph-to-another-graph-in-d3js

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