{
const svg = d3.create("svg")
.attr("width", 1152)
.attr("height", 720);
svg.append("g")
.selectAll("path")
.data(states)
.join("path")
.attr("d", path)
.attr("fill", "#ccc")
.attr("stroke", "#fff");
svg.append("g")
.selectAll("g")
.data(states)
.join("g")
.attr("transform", d => {
const [x, y] = path.centroid(d);
return `translate(${x},${y})`;
})
.each(function(d) {
const stateName = d.properties.NAME;
const data = dataset[stateName];
if (data) {
const g = d3.select(this);
g.selectAll("path")
.data(pie(data))
.join("path")
.attr("d", arc)
.attr("fill", d => color(d.data.age));
}
});
return svg.node();
}