choropleth = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("transform", "translate(650,20)")
.append(() =>
legend({
color: nullcolorforlegend,
title: "No Data",
width: 50,
tickFormat: ".1f"
})
);
svg.append("g")
.attr("transform", "translate(360,20)")
.append(() =>
legend({
color: color,
title: data.title,
width: 260,
tickFormat: ".1f"
})
);
svg.append("g")
.selectAll("path")
.data(counties.features)
.join("path")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 1)
.attr("fill", function(d){
if(data.get(d.properties.NAME) > 0){
return color(data.get(d.properties.NAME));
}
else{
return nancolor;
}
})
.attr("d", path)
.append("title")
.text(d => " Yield: " + data.get(d.properties.NAME));
svg.selectAll(".subunit-label")
.data(counties.features)
.enter().append("text")
.attr("class", function(d) { return "subunit-label " + d.id; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("fill", function(d){
var value = data.get(d.properties.NAME);
if(value > 0 && value < 210){
return "black";
}
else{
return "white";
}
})
.attr("fill-opacity", "1")
.attr("font-size", "10px")
.attr("font-weight", "300")
.attr("text-anchor", "middle")
.text(function(d) {
return d.properties.NAME;
})
return svg.node();
}