map = {
let svg = d3.create("svg").attr("width", w).attr("height", h);
svg
.append("path")
.attr("d", path(d3.geoGraticule10()))
.attr("fill", "none")
.attr("stroke", "#333")
.attr("stroke-width", 0.4);
let country_group = svg.append("g");
country_group
.selectAll("path")
.data(countries.features)
.join("path")
.attr("d", path)
.attr("fill", "#eee")
.attr("stroke", "black")
.attr("stroke-width", 1);
let centroid_map = new Map();
countries.features.forEach(function (c) {
let centroid = path.centroid(c);
if (!isNaN(centroid[0])) {
centroid_map.set(c.properties.NAME, centroid);
}
});
centroid_map.set(
"United States",
centroid_map.get("United States of America")
);
centroid_map.set("Cote d Ivorie", centroid_map.get("Côte d'Ivoire"));
let p = parameter.toLowerCase().replace(" ", "_");
let max = d3.max(country_data.map((o) => +o[p]));
let bubble_group = svg.append("g");
bubble_group
.selectAll("circle")
.data(country_data.filter((o) => centroid_map.has(o.CountryName)))
.join("circle")
.attr("cx", (d) => centroid_map.get(d.CountryName)[0])
.attr("cy", (d) => centroid_map.get(d.CountryName)[1])
.attr("r", (d) => 20 * Math.sqrt(+d[p] / max))
.attr("fill", "lightblue")
.attr("stroke", "black");
return svg.node();
}