chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("g")
.attr("transform", "translate(610,20)")
.append(() =>
legend({
color,
title: data.title,
width: 260,
tickValues: d3.utcYear.every(5).range(...color.domain()),
tickFormat: d3.utcFormat("%Y")
})
);
svg
.append("path")
.datum(topojson.mesh(us, us.objects.states))
.attr("fill", "none")
.attr("stroke", "#777")
.attr("stroke-width", 0.5)
.attr("stroke-linejoin", "round")
.attr("d", d3.geoPath());
let hex_group = svg.append("g");
hex_group
.selectAll("path")
.data(data)
.join("path")
.attr('class', 'hex')
.attr("transform", d => `translate(${d.x},${d.y})`)
.attr("d", d => hexbin.hexagon(radius(d.length)))
.attr("fill", d => color(d.date))
.attr("stroke", d => d3.lab(color(d.date)).darker())
.attr(
"title",
d => `${d.length.toLocaleString()} voters<br /> April 2020: Uniform Sample`
);
hex_group
.selectAll('path.hex')
.nodes()
.forEach(tippy);
return svg.node();
}