-
Notifications
You must be signed in to change notification settings - Fork 12
/
script.js
41 lines (35 loc) · 1.31 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function () {
d3.xml("worldmap.svg")
.mimeType("image/svg+xml")
.get(function (error, xml) {
document.querySelector("#svg").appendChild(xml.documentElement);
d3.selectAll("path").each(function () {
d3.select(this).attr("fill", "#ffce5d");
});
d3.selectAll("g").on("mouseover", function () {
d3.selectAll(".hover").classed("hover", false);
d3.selectAll("#" + this.id).classed("hover", true);
displayCountryName(this.id);
});
d3.selectAll("path").on("mouseover", function () {
d3.selectAll(".hover").classed("hover", false);
d3.selectAll("#" + this.id).classed("hover", true);
displayCountryName(this.id);
});
const flattenedCountries = countries.flatMap((country) =>
country.split(" ")
);
flattenedCountries.forEach(function (country) {
d3.select("#" + country).style("fill", "#c0442c");
d3.select("#" + country + " path").style("fill", "#c0442c");
});
d3.select("#number-countries").text(countries.length);
d3.select("#globe-percent").text(
Math.round((100 * countries.length) / 193) + "%"
);
});
})();
function displayCountryName(countryId) {
const countryName = countryId.replace(/_/g, " ");
d3.select("#country-name").text(countryName);
}