chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.call(grid);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const dot = svg.append("g")
.attr("fill", "currentColor")
.attr("stroke", "white")
.selectAll("circle")
.data(data)
.join("circle")
.attr("r", 3)
.attr("cx", d => x(d.POP_1980))
.attr("cy", d => y(d.R90_10_1980));
const label = svg.append("g")
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 4)
.selectAll("text")
.data(data.filter(d => d.highlight))
.join("text")
.call(text => text.append("tspan")
.attr("dy", "-0.6em")
.attr("x", d => x(d.POP_1980))
.attr("y", d => y(d.R90_10_1980))
.text(d => d.nyt_display)
.clone(true)
.attr("fill", "currentColor")
.attr("stroke", "none"))
.selectAll("tspan");
return Object.assign(svg.node(), {
update(year) {
const t = svg.transition()
.duration(750);
dot.transition(t)
.attr("cx", d => x(d[`POP_${year}`]))
.attr("cy", d => y(d[`R90_10_${year}`]));
label.transition(t)
.attr("x", d => x(d[`POP_${year}`]))
.attr("y", d => y(d[`R90_10_${year}`]));
}
});
}