chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 960, 600]);
svg.append("path")
.datum(topojson.merge(us, us.objects.lower48.geometries))
.attr("fill", "#ddd")
.attr("d", d3.geoPath());
svg.append("path")
.datum(topojson.mesh(us, us.objects.lower48, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", d3.geoPath());
const g = svg.append("g")
.attr("fill","steelblue")
.attr("stroke", "none")
const dots = g.selectAll("circle")
.data(data)
.join("circle")
.attr("transform", d => `translate(${d})`)
.attr("opacity", .5)
let prevDate = -Infinity
let yearText = 1982
const textBlock = svg.append("g")
.attr("font-family", "Poppins")
.attr("font-weight", "bold")
const year = textBlock.append("text")
.attr("x", 800)
.attr("y", 50)
.attr("font-size", "72px")
const counter = svg.append("text")
.attr("x", 800)
.attr("y", 90)
.attr("fill", "red")
.attr("font-size", "30px")
return Object.assign(svg.node(), {
update(date) {
dots
.filter(d => d.date > prevDate && d.date <= date)
.transition().attr("r", 10)
.transition().duration(500).ease(d3.easeCubic)
.attr("r", 5)
.transition().attr("fill", "steelblue")
dots
.filter(d => d.date <= prevDate && d.date > date)
.transition().attr("fill", "red")
.transition().duration(500)
.attr("r", 0);
prevDate = date
year.text(date.getFullYear())
counter.text(`${(yearCounts[date.getFullYear()] || "")} shootings`)
}
})
}