chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style('background-color', '#FFF8E7')
.style('background-color', 'white')
.attr("font-family", "sans-serif");
const title = svg.append("g");
let titleText = "";
if (property == "total_deaths_per_million")
titleText = "cumulative COVID-19 deaths ranking";
else if (property == "total_vaccinations_per_hundred")
titleText = "cumulative COVID-19 vaccinations ranking";
else if (property == "total_tests_per_thousand")
titleText = "cumulative COVID-19 tests ranking";
title
.append("text")
.attr("x", x(dates.length / 2 - 1))
.attr("y", y(0) - 6)
.attr("font-size", 6)
.attr("text-anchor", "middle")
.attr("fill", "grey")
.style("font-variant", "small-caps")
.text(titleText);
title
.append("text")
.attr("x", x(0))
.attr("y", y(euCountries.length) + 2)
.attr("font-size", 5)
.attr("text-anchor", "start")
.attr("fill", inactiveColor)
.text(dateFormat(dates[0]));
title
.append("text")
.attr("x", x(dates.length - 1))
.attr("y", y(euCountries.length) + 2)
.attr("font-size", 5)
.attr("text-anchor", "end")
.attr("fill", inactiveColor)
.text(dateFormat(dates[dates.length - 1]));
const platno = svg.append("g");
euCountries.forEach(country => {
let iso3 = country["iso-3"];
platno
.append("text")
.attr("fill", (d, i) => {
let retval = inactiveColor;
if (iso3 == "HRV") retval = "orange";
return retval;
})
.attr("text-anchor", "end")
.attr('class', `label-${iso3}`)
.attr("font-size", 5)
.attr("opacity", (d, i) => {
let retval = 0.6;
if (iso3 == "HRV") retval = 1;
return retval;
})
.attr("y", y(wrangled[property][iso3][0]) + 1)
.attr("x", x(0) - 5)
.text(country.country)
.on('mouseover', d => {
let target = d3.select(d.target);
let country = target
.attr('class')
.substring(target.attr('class').indexOf('-') + 1);
d3.select(`.path-${country}`)
.attr('stroke', 'black')
.attr('opacity', 0.4);
d3.select(d.target).attr('fill', 'black');
})
.on('mouseout', d => {
let target = d3.select(d.target);
let country = target
.attr('class')
.substring(target.attr('class').indexOf('-') + 1);
let toColor = country == 'HRV' ? 'orange' : inactiveColor;
let toOpacity = country == 'HRV' ? 1 : inactiveOpacity;
d3.select(`.path-${country}`)
.attr('stroke', toColor)
.attr('opacity', toOpacity);
d3.select(d.target).attr('fill', inactiveColor);
});
platno
.append("path")
.attr("stroke", (d, i) => {
let retval = inactiveColor;
if (iso3 == "HRV") retval = "orange";
return retval;
})
.attr('class', `path-${iso3}`)
.attr("stroke-width", (d, i) => {
let retval = 1;
if (iso3 == "HRV") retval = 2;
return retval;
})
.attr("opacity", (d, i) => {
let retval = inactiveOpacity;
if (iso3 == "HRV") retval = 1;
return retval;
})
.attr("fill", "none")
.attr("d", line(wrangled[property][iso3]));
});
return svg.node();
}