legend = g => {
const legend = g.append("g")
.attr("id", "legend")
.attr("transform", `translate(75, ${height - 80})`)
const items = legend.selectAll("g.item")
.data([5000, 35000, 100000])
.join("g")
.classed("item", true);
items.append("circle")
.attr("r", d => radius(d))
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("stroke-width", 1)
.attr("cy", d => -radius(d));
items.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "-0.4em")
.text((d, i) => {
d = d.toLocaleString();
return i === 2 ? `>= ${d}` : d;
})
legend.append("text")
.classed("title", true)
.attr("y", 20)
.attr("dy", "-0.4em")
.text("Persons Affected")
const colorLegend = g.append("g")
.attr("id", "color-legend")
.attr("transform", `translate(12, ${height - 45})`);
colorLegend.append("image")
.attr("width", 125)
.attr("height", 10)
.attr("preserveAspectRatio", "none")
.attr("xlink:href", ramp(color.interpolator()).toDataURL());
colorLegend.append("g")
.attr("transform", `translate(0, 10)`)
.call(d3.axisBottom(xScale)
.tickValues(color.domain()))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").attr("y1", -10))
.call(g => g.append("text")
.classed("title", true)
.attr("x", 20)
.attr("y", 18)
.attr("text-anchor", "middle")
.text("Months Unresolved"))
}