3

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?

VividD
  • 10,456
  • 6
  • 64
  • 111
X-jo
  • 491
  • 1
  • 5
  • 13
  • Maybe a [collapsible force layout](http://bl.ocks.org/mbostock/1093130) is more suitable for you? – Lars Kotthoff Dec 31 '13 at 09:50
  • its still the same, two parents don't expand to one node. ViviD says in the response that this can't be done by d3 alone. – X-jo Dec 31 '13 at 14:12
  • 1
    It can be done in D3, just not with the existing layouts. It would be easier to implement with a force layout than with a tree layout though. – Lars Kotthoff Dec 31 '13 at 14:38
  • http://stackoverflow.com/questions/20525458/how-to-get-common-child-node-in-d3-js-force-based-labeled-layout-graph i will try this, thanks – X-jo Jan 01 '14 at 10:18
  • X-jo can you post your findings? – mehmet Dec 26 '15 at 18:22

1 Answers1

6

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)

Community
  • 1
  • 1
VividD
  • 10,456
  • 6
  • 64
  • 111
  • exactly like you stated, i will look into those approaches and get back to you, thank you very much – X-jo Dec 31 '13 at 14:12
  • Thanks for posting those links VividD. For others coming to this page: As far as I can tell, none of those examples concern collapsible graphs with (non-directed) cycles, which is what OP asked about. There are good D3 examples of collapsible trees available (i.e. where no node has more than one parent), and good examples of layouts for non-tree data in which there are cyclic structures (including mulitple-parent "trees") using D3 and other libraries. Collapsing paths in a tree is inherently simpler than collapsing links in a non-tree graph; I've found no example of the latter. – Mars Feb 14 '15 at 18:16