drawPartition = (root, attribute) => {
const newRoot = (valueAs == "count"
? root.copy().count()
: root.copy().sum(d => d[attribute])
).sort((a, b) => b.value - a.value);
const partitionLayout = d3.partition().size([2 * Math.PI, H / 2])(newRoot);
mutable feedback = partitionLayout;
const [svgNode, svg] = getSVG();
const radius = H / 2;
const arcGenerator = d3
.arc()
.startAngle(d => d.x0)
.endAngle(d => d.x1)
.innerRadius(d => d.y0)
.outerRadius(d => d.y1);
const chart = svg
.append("g")
.attr("transform", `translate(${W / 2},${H / 2})`);
chart
.selectAll('path')
.data(partitionLayout.descendants().filter(d => d.depth))
.join('path')
.attr('d', arcGenerator)
.style("stroke", "white")
.style("fill", d => {
while (d.depth > 1) d = d.parent;
return colorScale(d.data.name || d.data[0]);
});
chart
.append("g")
.attr("text-anchor", "middle")
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.selectAll("text")
.data(
partitionLayout
.descendants()
.filter(d => d.depth && ((d.y0 + d.y1) / 2) * (d.x1 - d.x0) > 10)
)
.join("text")
.attr("transform", function(d) {
const x = (((d.x0 + d.x1) / 2) * 180) / Math.PI;
const y = (d.y0 + d.y1) / 2;
return `rotate(${x - 90}) translate(${y},0) rotate(${x < 180 ? 0 : 180})`;
})
.attr("dy", "0.35em")
.text(d => d.data.name || d.data[0] || "");
return svgNode;
}