d3.js, collapsible tree - how to connect different parents with same child

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 19:53:08

问题


So I am using http://bl.ocks.org/mbostock/4339083 to create a collapsible tree and it works great.

Now the thing is I have some nodes which have the same children, so I want to know if there is any way to visualize the graph in such a way that both the parents expand to the same child?

So basically when you expand the node of a parent it should automatically expand the node of the other parent leading to the same common child, is this possible with any graph?


回答1:


From your description, I gather you need to visualize directed acyclic graph, or DAG.

Tree is:

A
|\
B C
 / \
D   E

DAG is:

A
|\
B C
 \|
  D

And, no, unfortunately, D3 tree and cluster layouts simply don't support that kind of graphs. Their internal algorithms assume that the data structure is strictly a tree.

However, there are some options. Please see these five related questions for possible approaches:

d3 tree - parents having same children

How to layout a non-tree hierarchy with D3

d3.js tree nodes with same parents

Layered graphs in d3.js

JS library for displaying direct acyclic graphs (DAGs)



来源:https://stackoverflow.com/questions/20853485/d3-js-collapsible-tree-how-to-connect-different-parents-with-same-child

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