chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 975, 610]);
svg.append("path")
.datum(topojson.feature(us, us.objects.nation))
.attr("fill", "#e0e0e0")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(length.ticks(4).slice(1).reverse())
.join("g")
.attr("transform", (d, i) => `translate(${975 - (i + 1) * 18},590)`);
legend.append("path")
.attr("fill", "red")
.attr("fill-opacity", 0.3)
.attr("stroke", "red")
.attr("d", d => spike(length(d)));
legend.append("text")
.attr("dy", "1em")
.text(length.tickFormat(4, "s"));
svg.append("g")
.attr("fill", "red")
.attr("fill-opacity", 0.3)
.attr("stroke", "red")
.selectAll("path")
.data(data
.filter(d => d.position)
.sort((a, b) => d3.ascending(a.position[1], b.position[1])
|| d3.ascending(a.position[0], b.position[0])))
.join("path")
.attr("transform", d => `translate(${d.position})`)
.attr("d", d => spike(length(d.value)))
.append("title")
.text(d => `${d.title}
${format(d.value)}`);
return svg.node();
}