{
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", width / 2 + margin.bottom);
svg
.append("rect")
.attr("width", width)
.attr("height", width / 2 + 100)
.attr("fill", "#f9f9fe");
const countryGroup = svg
.append("g")
.attr("transform", "translate(" + margin.sides + " " + margin.top + ")");
countryGroup
.append("path")
.attr("d", worldPath(worldOutline))
.attr("fill", "#4488cc");
countryGroup
.selectAll(".countries")
.data(scholarWorldData)
.join("path")
.attr("d", worldPath)
.attr("class", "countries")
.attr("fill", (d) => {
if (d.scholars) {
return d3.interpolateViridis(colorScale(d.scholars[year]));
} else {
return "gray";
}
})
.attr("stroke", "white")
.attr("stroke-width", 0.5)
.on("mouseover", (e, d) => {
d3.select(e.target).transition().attr("stroke-width", 2);
d3.select("#dataHolder").text(
`${d.properties.NAME} had ${
d.scholars[year]
} international scholars in school year ${year.split("-")[0]}`
);
})
.on("mouseout", (e, d) => {
d3.select(e.target).transition().attr("stroke-width", 0.5);
d3.select("#dataHolder").text("Mouseover a country for details");
});
countryGroup
.append("path")
.attr("d", worldPath(graticules()))
.attr("stroke", "#dcdcdc")
.attr("stroke-width", 0.5)
.attr("fill", "none");
svg
.append("text")
.attr("x", width / 2)
.attr("y", width / 2 + margin.bottom / 2)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.attr("id", "dataHolder")
.attr("font-family", "Futura")
.text("Mouseover a country for details");
return svg.node();
}