chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.selectAll(".mcpio")
.data(features.features)
.join("path")
.attr("class", "mcpio")
.style("stroke", "#ddd")
.style("stroke-width", 0.5)
.style("fill", "none")
.attr("d", d => path(d));
svg
.selectAll(".depto")
.data(geoJSON.features)
.join("path")
.attr("class", "depto")
.style("fill", "none")
.style("stroke", "#aaa")
.style("stroke-width", 0.5)
.attr("d", d => path(d));
svg
.selectAll(".mountain")
.data(features.features)
.join("path")
.attr("transform", d => `translate(${projection(d3.geoCentroid(d))})`)
.attr("class", "mountain")
.style("fill", "#eee")
.style("fill-opacity", 0.9)
.style("stroke", "steelblue")
.style("stroke-width", 1)
.attr("d", d => mountain(d.properties[spikeBy]));
svg
.selectAll(".legend")
.data(d3.range(0, h.domain()[1] + 1, h.domain()[1] / 6))
.join("g")
.attr(
"transform",
(d, i) =>
`translate(${width -
margin.left -
margin.right -
200 +
i * 30},${height - margin.bottom - margin.top - 20})`
)
.call(legend =>
legend
.append("path")
.attr("class", "legend mountain")
.style("fill", "#eee")
.style("fill-opacity", 0.9)
.style("stroke", "steelblue")
.style("stroke-width", 0.7)
.attr("d", d => mountain(d))
)
.call(legend =>
legend
.append("text")
.style("font-size", "6pt")
.style("text-anchor", "middle")
.style("font-family", "sans-serif")
.attr("y", 10)
.text(d => fmt(d))
);
return svg.node();
}