A few simple questions about d3.layout.pack() A few simple questions about d3.layout.pack() json json

A few simple questions about d3.layout.pack()


In D3's hierarchical layouts, all nodes are populated with a set of standard attributes, including a "parent" attribute. So you can avoid specifying a "group" attribute, and use "parent" instead when selecting the children of a particular node:

d3.selectAll("circle").filter(function(d) { return d.parent.name === "foo"; });

Alternatively, you can compare by object reference if you have a reference to the node object itself.

var parent = nodes.filter(function(d) { return d.name === "foo"; });d3.selectAll("circle").filter(function(d) { return d.parent === parent; });

Here I'm assuming that each node has a "name" attribute.

You also mentioned using retrieving children from a different attribute. Yes, this can be achieved using the "children" accessor. Note that this will store a node's children in an attribute called "children" on that node, overwriting anything that may be there already.