spike_chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, 975, 610]);
svg
.append("path")
.datum(topojson.feature(shapefile, shapefile.objects.nation))
.attr("fill", "#e0e0e0")
.attr("d", path);
svg
.append("path")
.datum(
topojson.mesh(shapefile, shapefile.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", "1.3em")
.text(length.tickFormat(4, "s"));
svg
.append("g")
.attr("fill", "red")
.attr("fill-opacity", 0.3)
.attr("stroke", "red")
.selectAll("path")
.data(
data1.sort(
(a, b) =>
d3.ascending(a["long_"], b["long_"]) ||
d3.ascending(a["lat"], b["lat"])
)
)
.join("path")
.attr("transform", d => `translate(${d["long_"]})`)
.attr("transform", d => `translate(${d["lat"]})`)
.attr("d", d => spike(length(d.value)))
.append("title")
.text(
d => `${d.title}
${format(d.value)}`
);
return svg.node();
}