d3 force collapsible layout - start page with all nodes collapsed

前端 未结 2 1575
予麋鹿
予麋鹿 2021-01-14 12:57

I just need a simple modification of the layout available here http://mbostock.github.io/d3/talk/20111116/force-collapsible.html

The above visualization starts with

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 13:29

           just do it like this 
            d3.json("json/results.json", function(json) {
                   root = json;
                   root.x0 = h / 2;
                    root.y0 = 0;
    
                    function toggleAll(d) {
                       if (d.children) {
                       d.children.forEach(toggleAll);
                      toggle(d);
                       }
                   }
    
                     root.children.forEach(toggleAll);
    
                      toggle(root);
                    update(root);
                     });
    

提交回复
热议问题