Accepted answer

Hopefully this will help out. From this example : How can I start with all the nodes collapsed in d3js?

I edited your fiddle :

I removed the original call to update(). So you have to press Load then Start.

This collapses all nodes. From there you can open up the first two hierarchies fairly easy :)

This is the main implementation :


<button id='startForce'>START</button>


document.getElementById('startForce').addEventListener('click', function() {

            var nodes = flatten(root);
            nodes.forEach(function(d) {
              d._children = d.children;
              d.children = null;

Related Query

More Query from same tag