Selecting Arc/element
In the sunburst, how can I make code select a root arc, just after all arcs was generated? For example, in the code: var first_arc = '' .json('../data/flare.json', function(json) {
Solution 1:
The root node is the one with a "depth" attribute set to 0. So you can say:
d3.selectAll("path").filter(function(d) { return d.depth === 0; })
Your attempts above weren't working because D3 uses CSS3 to select elements. So you can only use d3.select and d3.selectAll with CSS3 selectors i.e. you can't access the data bound to each element this way. The way to filter on the bound data is to use selection.filter.
D3 selections are literally an array of elements, see the "Operating on Selections" section.
Lastly, you can get the bound __data__
property for an element using selection.datum().
Post a Comment for "Selecting Arc/element"