chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const opacity_weak = 0.15;
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg.append("g").call(grid);
function onMouseOver(selected) {
const country_code = d3.select(this).attr("class");
d3.selectAll(`.${country_code}`).attr("fill-opacity", 1).attr("stroke-opacity", 1);
}
function onMouseOut() {
const country_code = d3.select(this).attr("class");
d3.selectAll(`.${country_code}`).attr("fill-opacity", opacity_weak).attr("stroke-opacity", opacity_weak);
d3.selectAll(`text.${country_code}`).attr("fill-opacity", 0).attr("stroke-opacity", 0);
}
const country_codes = data.filter(d => d.deaths[d.deaths.length-1][1] > 5)
.map(d => d.country_code);
country_codes.forEach(function(country_code) {
svg.append("text").attr("class", `${country_code}`)
.text(data_by_country[country_code].country_name)
.attr("x", x(new Date()) - 5)
.attr("y", y(data_by_country[country_code][y_type][data_by_country["USA"][y_type].length - 1][1]) )
.style("text-anchor", "end")
.attr("font-size", 14)
.attr("fill", color(data_by_country[country_code].region))
.attr("fill-opacity", 0)
.on("mouseover", onMouseOver)
.on("mouseout", onMouseOut);
svg.append("g")
.append("circle").attr("class", `${country_code}`)
.attr("fill", d => color(code_to_region(country_code)))
.attr("fill-opacity", opacity_weak)
.attr("cx", x(new Date(last_date))).attr("cy", d => y(total_confirmed(country_code))).attr("r", 2);
svg.append("g")
.selectAll("path")
.data(data.filter(
d => d.country_code === country_code)
).join("path").attr("class", `${country_code}`)
.attr("stroke", d => color(d.region)).attr("fill", "none")
.attr("stroke-opacity", opacity_weak)
.attr("d", d => country_trajectory(d.country_code));
});
return svg.node();
}