Skip to content
Advertisement

D3v6 nested graph – nested join()?

I want to visualize the “children” insight each node. I guess the D3v6 .join() function can be nested. Unfortunately I can´t find any example. The snippet below contains an outerGraph with 3 nodes and children as attribute. So far those children aren´t used yet.

The innerGraph instead visualize the small nodes which will be obsolete as soon as the children approach is working. Another Idea would be to work with those two graphs and create a gravity / cluster, which will be the parent.

Goal: Either utilize the children attribute or combine both graphs with the help of an cluster /gravity or even nested join(). I am appreciating any hint / tip. The visuals result should be:

enter image description here

JavaScript

I will update the post as soon as I found a solution.

Advertisement

Answer

Here’s a slightly hack way to do it – I am a bit disappointed in the outcome because if you play with the outerNodes then the links between innerNodes cross over in an unattractive way.

The changes I made in your code:

  • update innerGraph so nodes have a parent property (plus add the links required to match your screenshot in the question)
  • add an additional class on outerNodes so that each outer node can be identified e.g. .outer_A, .outer_B etc
  • add an additional class on innerNodes so that each inner node can be identified e.g. .child_A1, .child_A2 etc
  • in ticked – for innerNodes return a point for the inner node so that it is sitting inside centre of it’s parent at roughly 20px from the centre on the vector between the original force simulation selected point and the parent’s centre.
  • in ticked – for innerLinks, force the source and target coordinates to update per the previous step

Those last two points are per here and here.

So it works – but only just. Vertical scrolling in the stack snippet seems to upset it a bit but it’s maybe better if you try it out on your own dev environment. I still think you could you look at other tools – maybe this one from cytoscape.js and also the webcola example I mentioned in the comments?

JavaScript
JavaScript
Advertisement