chart = {
const root = tree(d3.hierarchy(scoreNested)
.sort((a, b) => d3.ascending(a.data.region, b.data.region)));
const svg = d3.create("svg");
const tooltip = d3tip()
.attr('class', "d3-tip")
.style("background-color", "white")
.style("padding", "6px")
.style("border-radius", "10px")
.offset([-10, 0])
.html(root, d => `<div>${d.children.data.children.data.data.label}</div>`);
svg.call(tooltip);
svg.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.2)
.attr("stroke-width", 1)
.selectAll("path")
.data(root.links())
.join("path")
.attr("d", d3.linkRadial()
.angle(d => d.x)
.radius(d => d.y));
const circles = svg.append("g")
.attr("class", "circles");
circles
.selectAll("circle")
.data(root.descendants())
.join("circle")
.attr("transform", d => `
rotate(${d.x * 180 / Math.PI - 90})
translate(${d.y},0)
`)
.attr("fill", d => color(d.data.data.color))
.attr("stroke", d => d.data.data.sum == 0 ? "black" : "none")
.attr("r", d => size(d.data.data.sum == 0 ? 2 : d.data.data.sum))
.attr("opacity", .33)
.on("mouseover", tooltip.show)
.on("mouseout", tooltip.hide);
circles.append("style").text(`
.circles circle:hover {
opacity: 1;
}
`);
svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("stroke-linejoin", "round")
.attr("stroke-width", 3)
.selectAll("text")
.data(root.descendants())
.join("text")
.attr("transform", d => `
rotate(${d.x * 180 / Math.PI - 90})
translate(${d.y},0)
rotate(${d.x >= Math.PI ? 180 : 0})
`)
.attr("dy", "0.31em")
.attr("x", d => d.x < Math.PI === !d.children ? 6 : -6)
.attr("text-anchor", d => d.x < Math.PI === !d.children ? "start" : "end")
.text(d => d.data.data.country === "root" ? "" : d.data.data.country)
.on("mouseover", tooltip.show)
.on("mouseout", tooltip.hide)
.clone(true).lower()
.attr("stroke", "white");
return svg.attr("viewBox", autoBox).node();
}