{
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.left + margin.right);
const clipPathLookup = {};
svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.selectAll('clipPath')
.data(nodes.filter(d => d.depth == 1), d => d.data.key)
.join("clipPath")
.attr("id", d => {
const uid = DOM.uid("clip");
clipPathLookup[d.data.key] = uid;
return uid.id;
})
.append("path")
.attr('d', d => "M" + d.polygon.join("L") + "Z");
const voronoi = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.selectAll('path')
.data(nodes.filter(d => d.depth == 2), d => d.data.id)
.join("path")
.attr('d', d => "M" + d.polygon.join("L") + "Z")
.style('fill', d => colorScale(d.data.region))
.attr("clip-path", d => clipPathLookup[d.data.parent])
.attr("stroke", "#fff")
.style("cursor", "pointer");
svg
.append("g")
.selectAll("text")
.data(nodes.filter(d => d.depth == 2), d => d.data.id)
.join(
enter =>
enter
.append('text')
.attr("x", d => d.polygon.site.x)
.attr("y", d => d.polygon.site.y)
.attr("text-anchor", "middle")
.attr("font-size", "0.8rem")
.text(d => d.data.region),
update => update.attr("fill", d => console.log("Hello"))
);
return svg.node();
}