chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 975, 610])
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");
svg.append("path")
.datum(topojson.mesh(us, us.objects.states))
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("d", path);
const state = svg.append("g")
.attr("stroke", "#000")
.selectAll("path")
.data(topojson.feature(us, us.objects.states).features.filter(d => data.has(d.id)))
.join("path")
.attr("vector-effect", "non-scaling-stroke")
.attr("d", path)
.attr("fill", d => color(data.get(d.id)[0]))
.attr("transform", d => transform(d, 0));
state.append("title")
.text(d => `${d.properties.name}
${format(data.get(d.id)[0])} in 2014
${format(data.get(d.id)[1])} in 2018
${format(data.get(d.id)[2])} in 2022`);
return Object.assign(svg.node(), {
update(year) {
state.transition()
.duration(750)
.attr("fill", d => color(data.get(d.id)[year]))
.attr("transform", d => transform(d, year));
}
});
}