D3 Sunburst arc sizes

六眼飞鱼酱① 提交于 2020-12-12 09:43:46

问题


I am trying to create a D3 sunburst chart based on this example:

https://bl.ocks.org/maybelinot/5552606564ef37b5de7e47ed2b7dc099

I'd like the arcs created to close the full circle but they don't.

For testing purpose and simplicity, the sum of every element's size in the the same depth equals 360.

Follows my jsFiddle:

https://jsfiddle.net/igasparetto/uz8rz13d/

Something is telling me the problem is on these lines:

var partition = d3.partition();

var arc = d3.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x0))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x1))); })
.innerRadius(function(d) { return Math.max(0, y(d.y0)); })
.outerRadius(function(d) { return Math.max(0, y(d.y1)); });

Thanks


回答1:


Your problem appears to be that size variables defined for the parent nodes are included when you do root.sum to make values. Essentially the parent value is set not just to be the sum of its children, but you get the parent size added as "free space"

https://github.com/d3/d3-hierarchy/blob/master/README.md#node_sum

"The node.value property of each node is set to the numeric value returned by the specified function plus the combined value of all descendants."

This works as it ignores non-leaf node size values:

  root.sum(function(d) { return !d.children || d.children.length === 0 ? d.size :0; });

https://jsfiddle.net/uz8rz13d/2/



来源:https://stackoverflow.com/questions/41649418/d3-sunburst-arc-sizes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!