score:1

Accepted answer

That example toggles children open or closed with this code:

// Toggle children on click.
function click(d) {
  if (d.children) {
    d._children = d.children;
    d.children = null;
  } else {
    d.children = d._children;
    d._children = null;
  }
  update(d);
}

So you can initialize the tree to be closed at a particular level by changing the original dataset from children to _children on any level you wish to start out as collapsed.

For example (from flare.json):

{
 "name": "flare",
 "_children": [
  {
   "name": "analytics",
   "_children": [
    {
     "name": "cluster",
     "_children": [
      {"name": "AgglomerativeCluster", "size": 3938},
      {"name": "CommunityStructure", "size": 3812},
      {"name": "HierarchicalCluster", "size": 6714},
      {"name": "MergeEdge", "size": 743}
     ]
    }
...
...

Related Query