Calling bubble.nodes() boils down to calling d3.layout.pack().nodes() with bubble=d3.layout.pack() . The trick is that pack.nodes() hard-coded to use the value key of the children input (in this case, all packages) to determine the size of the nodes (add r ) and determine the position (add x and y ).
In fact,
var root = {"children": [ {"packageName":"cluster","className":"AgglomerativeCluster","value":3938}, {"packageName":"cluster","className":"CommunityStructure","value":3812}, {"packageName":"cluster","className":"HierarchicalCluster","value":6714}, {"packageName":"cluster","className":"MergeEdge","value":743} ]}; // This is an excerpt of the real data. var bubble = d3.layout.pack(); // pack.nodes() assigns each element of "children" ar, x, and y based on value bubble.nodes(root);
This also worked, you can see that classes() does not add r , x and y , since classes(root) does not have these attributes. the red answer affected most of this, but I felt that he needed to explain a little more (at least it was for me).
sushain97
source share