javascript - d3.js tree diagram - expand only next level nodes when clicking on root node -


i have tree diagram i'm trying adapt here, problem automatically expands root nodes in tree when click on collapsed node, rather expanding immediate children. here's fiddle. how resolve this?

http://jsfiddle.net/heaversm/nw577/

the function handling toggling / collapsing of nodes:

function togglechildren(d) {     if (d.children) {         d._children = d.children;         d.children = null;     } else if (d._children) {         d.children = d._children;         d._children = null;     }     return d; } 

the problem nodes start expanded , state of individual node toggled on click. is, nodes underneath root still expanded, not shown. click root node, are. not expanded root, never collapsed.

to fix, collapse nodes start with:

tree.nodes(root).foreach(function(n) { toggle(n); }); 

complete demo here.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -