choropleth = {
const svg = d3.create("svg").attr("viewBox", [0, 0, 975, 610]);
svg
.append("g")
.attr("transform", "translate(610,20)")
.append(() =>
legend({
color: color_scale,
title: "Average Cost Per Square Foot ($)",
width: 260
})
);
svg
.append("g")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.join("path")
.attr("fill", d => {
const value = totalCost.find(e => e.fips == d.id);
if ((d.fips = value)) {
return color_scale(value.cost);
} else {
return "black";
}
})
.attr("d", path)
.append("title")
.text(d => `${d.properties.name}, ${states.get(d.id.slice(0, 2)).name}`);
svg
.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-linejoin", "round")
.attr("d", path);
return svg.node();
}