Roughly speaking,
pack.children in v3 is replaced by the optional
children accessor you pass to
d3.hierarchy in v4, and
pack.value is likewise replaced by
node.sum. So you’d end up with something like this:
var root = d3.hierarchy(data, function(d) { return d.values; })
.sum(function(d) { return d.weging; })
.sort(function(a, b) { return b.value - a.value; });
You then pass this root to pack, your d3.pack instance. The only difference from the standard circle-packing example is that you’re using d3.hierarchy since your input data is already hierarchical, rather than d3.stratify to start with tabular data.
The last call to
node.sort is optional but recommended, and note that the
a and
b passed to the comparator function are nodes, not data, and thus
a.value and
b.value refer to the sums computed in the previous step by
node.sum; if you want to sort based on some data field, then you’d use
a.data.foo and
b.data.foo, for example. But typically you’d use the sums to sort a pack layout.