i have d3 tree based on following...
http://bl.ocks.org/mbostock/1093025
how count of children? have tried counts rows in tree...
$(".tree_badge").text(tree.links(nodes).length);
so in example should count children children orange coloured rows in tree (like in cluster, graph, etc).
thanks insight!
i had similar problem had grab of descriptions tree below particular node. answer in case , yours recursively descend tree , on way down. should this.
var count; function count_leaves(node){ if(node.children){ //go through children for(var = 0; i<node.children.length; i++){ //if current child in loop has children of own //call recurse again on decend whole tree if (node.children[i].children){ count_leaves(node.children[i]); } //if not leaf count else{ count++; } } }
note: if want count of nodes below node , not ones @ end of tree, add count++ inside if else.
Comments
Post a Comment