choropleth = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("transform", "translate(300,0)")
.append(() =>
legend({
color: nullcolor,
title: "No Data",
width: 50,
tickFormat: ".1f"
})
);
svg.append("g")
.attr("transform", "translate(600,0)")
.append(() =>
legend({
color: color,
title: data.title,
width: 250,
tickFormat: ".1f"
})
);
svg.append("g")
.selectAll("path")
.data(india_states.features)
.join("path")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 0.5)
.attr("fill", function(d){
if(data.get(d.properties.shapeID) > 0){
return color(data.get(d.properties.shapeID));
}
else{
return d3.color("black");
}
})
.attr("d", path)
.append("title")
.text(d => " Main Languge Share: " + data.get(d.properties.shapeID));
svg.selectAll(".subunit-label")
.data(india_states.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){
if(data.get(d.properties.shapeID)<0.6)
return "black";
else
return "white";
})
.attr("fill-opacity", "1")
.attr("font-size", function(d){
if(d.properties.shapeName.length > 10)
return "6px";
else
return "7px";
})
.attr("font-weight", "300")
.attr("text-anchor", "middle")
.text(function(d) { return d.properties.shapeName; })
return svg.node();
}