调用bubble.nodes()
归结为调用d3.layout.pack().nodes()
since bubble=d3.layout.pack()
。诀窍是pack.nodes()
硬编码以使用value
输入的键children
(在本例中为所有包)来调整节点的大小(add r
)并确定位置(addx
和y
)。
在本质上,
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" a r, x, and y based on value
bubble.nodes(root);
起初这也让我感到困惑,您可以看到它classes()
没有添加r
, x
,并且y
因为classes(root)
没有这些属性。krasnaya 的回答触及了大部分内容,但我觉得它需要更多解释(至少对我来说是这样)。