I want to get the start and end angles for each arc in the sunburst example as in http://bl.ocks.org/4063423:
You can see them in the code:
var arc = d3.svg.arc()
.startAngle(function(d) { return d.x; })
.endAngle(function(d) { return d.x + d.dx; })
.innerRadius(function(d) { return Math.sqrt(d.y); })
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
So your start angle is in the x attribute and x + dx give your end angle.
The trick is that the x, dx, y and dy are all set by the layout function:
var partition = d3.layout.partition()
.sort(null)
.size([2 * Math.PI, radius * radius])
.value(function(d) { return 1; });
sort(null) tells it not to reorder your data size(...) tells it the output range for x and y coordinate (radius is squared because we are mapping to an area). value(...) is the value accessor for how to weight each item.
You can use this simple code:
...
.data(partition.nodes)
.filter(function(d) { // You're not restricted to use the "filter" function
var startAngle = arc.startAngle()(d);
var endAngle = arc.endAngle()(d);
});
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With