chart = {
const root = pack(data);
const circle = d3.arc()
.innerRadius(0)
.outerRadius(d => d)
.startAngle(-Math.PI)
.endAngle(Math.PI);
const svg = d3.create("svg")
.style("width", "100%")
.style("height", "auto")
.style("background", "#fff")
.style("font", "10px sans-serif")
.attr("text-anchor", "middle");
const node = svg.selectAll("g")
.data(root.descendants().slice(rooted ? 0 : 1).reverse())
.enter().append("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + 1})`);
node.append("path")
.attr("id", d => (d.circleUid = DOM.uid("circle")).id)
.attr("d", d => circle(d.r));
const internal = node.filter(d => d.children);
internal.select("path")
.attr("stroke", d => d.data.color)
.attr("fill", "none");
internal.append("text")
.attr("dy", "1em")
.attr("fill", "#555")
.append("textPath")
.attr("xlink:href", d => d.circleUid.href)
.attr("startOffset", "50%")
.text(d => d.data.name);
const leaf = node.filter(d => !d.children)
.attr("fill", d => d.data.color);
leaf.append("text")
.each(d => {
const {lines, radius} = fit(d.data.name, isNaN(d.data.value) ? undefined : format(d.data.value));
d.lines = lines;
if (!isNaN(d.data.value)) d.lines[d.lines.length - 1].value = true;
})
.attr("fill", d => d3.lab(d.data.color).l < 60 ? lightColor : darkColor)
.selectAll("tspan")
.data(d => d.lines)
.enter().append("tspan")
.attr("x", 0)
.attr("y", (d, i, data) => (i - data.length / 2 + 0.8) * 11)
.text(d => d.text)
.filter(d => d.value)
.attr("font-weight", 300)
.attr("fill-opacity", 0.5);
return autosize(svg.node());
}