root node sum()

235 views
Skip to first unread message

Marc McIntyre

unread,
Jul 21, 2016, 4:28:00 AM7/21/16
to d3-js
Hi, 

I am trying to create a sunburst diagram using D3.js V4. On a root node there is a sum() method for calculating the value of a node + all of it's descendants. I only have a already computed value of the node's sum. Is there a way to use that value without adding up all of the descendants? 

Cheers,
Marc. 

Mike Bostock

unread,
Jul 21, 2016, 10:06:29 AM7/21/16
to d3-js
Take a look at how node.sum is implemented:

https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/sum.js

So, if you wanted to use your precomputed sum, you could say:

root.eachAfter(function(node) {
node.value = node.data.value;
});

A similar but more wasteful approach would be to pass a value accessor to node.sum that returns zero for any internal (non-leaf) node and discard your precomputed sums.

Mike
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages