zidanow
zidanow

Reputation: 700

Start with closed nodes in indented tree

I used this indentend tree : https://bl.ocks.org/mbostock/1093025

And i want to start like this :

enter image description here

And not like this :

enter image description here

The transition to change the node is this :

// Transition exiting nodes to the parent's new position.
  node.exit().transition()
      .duration(duration)
      .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
      .style("opacity", 0)
      .remove();

How can i do it ? Thank you again for the help :)

Upvotes: 0

Views: 33

Answers (1)

Shushan
Shushan

Reputation: 1225

Adding this at the end of the initial loading (after the call to update(root)) does the trick. It relies on the _children concept utilized here to store children not currently displayed.

root.each(function(d) {
    if (d.depth > 0) {
        d._children = d.children;
        d.children = null;
    }
    update(d)
});

Upvotes: 1

Related Questions