{
const svg = d3.create("svg").attr("width", width).attr("height", height);
svg
.selectAll("region")
.data(root.children)
.join("text")
.attr("class", "region")
.attr("x", (d) => d.x0)
.attr("y", (d) => d.y0 + 2)
.attr("dy", "0.6em")
.attr("dx", 3)
.text((d) => d.data.name);
const leaf = svg
.selectAll("g")
.data(root.leaves())
.join("g")
.attr("transform", (d) => `translate(${d.x0},${d.y0})`);
leaf
.append("rect")
.attr("width", (d) => d.x1 - d.x0)
.attr("height", (d) => d.y1 - d.y0)
.attr("fill", (d) => colorScale(d.parent.data.name))
.style("fill-opacity", 0.9)
.attr("rx", 3)
.attr("ry", 3);
leaf
.append("text")
.style("opacity", (d) => (d.x1 - d.x0 < 33 || d.y1 - d.y0 < 25 ? 0 : 1))
.attr("fill", (d) => (d.parent.data.name === "asia" ? "#fff" : "#111"))
.selectAll("tspan")
.data(
(d) => d.data.name.split(/(?=[A-Z][a-z])|\s+/g)
)
.join("tspan")
.attr("x", 3)
.attr("y", (d, i) => 13 * i + 13)
.text((d) => d)
.attr("class", "text");
return svg.node();
}