chart = {
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);
var slicedData = desiredData.map(d=>d[regions.indexOf(xxx)]).slice(0,z+1)
svg
.append('g')
.selectAll("ellipse")
.data(slicedData)
.join("ellipse")
.attr("class", (d, i) => "petal")
.attr("visibility", function (d){
return (hideCheckbox.length ===0 & d.deaths ==0)? "hidden": "visible"
})
.attr("cy", d => rScale(maxDeaths) - rScale(d.deaths))
.attr("ry", d => rScale(d.deaths))
.attr("rx", d => rScale(d.deaths)/3)
.attr("fill", function (d, i){
return (i < indexOf2021)? colorByContinent(d.region, 1, colors_):colorByContinent(d.region, 1)
})
.attr("stroke", "white")
.attr("stroke-width", strokeWidth)
.attr('transform', function(d, i) {
var rx = Math.cos(xcos(i)) * outerRadius;
var ry = Math.sin(ysin(i)) * outerRadius;
return `translate(${rx},${ry})
rotate(${xcos(i) * 180 / Math.PI + 90})
scale(${0.8})`;
})
if(z > indexOf2021){
svg
.append('g')
.selectAll("ellipse")
.data(slicedData.splice(0,indexOf2021))
.join("ellipse")
.attr("visibility", function (d){
return (hideCheckbox.length ===0 & d.deaths ==0)? "hidden": "visible"
})
.attr("cy", d => rScale(maxDeaths) - rScale(d.deaths))
.attr("ry", d => rScale(d.deaths))
.attr("rx", d => rScale(d.deaths) / 3)
.attr("fill", function (d, i){
return (i < indexOf2021)? colorByContinent(d.region, 0.1, colors_):colorByContinent(d.region, 0.1)
})
.attr("stroke", "white")
.attr("stroke-width", strokeWidth)
.attr('transform', function(d, i) {
var rx = Math.cos(xcos(i)) * outerRadius;
var ry = Math.sin(ysin(i)) * outerRadius;
return `translate(${rx},${ry})
rotate(${xcos(i) * 180 / Math.PI + 90})
scale(${0.8})`;
})
}
// color the last ellipse
// svg.selectAll(".ellipse:nth-last-child(1)")
// .attr("fill", d => colorByContinent3(d.region, 1))
// .attr("stroke", "white")
// .attr("stroke-width", 1.5)
let displayedYearWeek = desiredData.map(d=>d[regions.indexOf(xxx)])[z]["yearWeek"];
svg.append("text")
.attr("class", "label")
.attr("x", 0)
.attr("y", -15)
.text(formatter(yearWeekLookUp(displayedYearWeek)))
.attr("transform", "rotate(90)");
svg.append("text")
.attr("class", "label")
.attr("x", 0)
.attr("y", 0)
.text(desiredData.map(d=>d[regions.indexOf(xxx)])[0].region)
.attr("transform", "rotate(90)");
svg.append("text")
.attr("class", "label")
.attr("x", 0)
.attr("y", 15)
.text(desiredData.map(d=>d[regions.indexOf(xxx)])[z]["cumuDeaths"])
.attr("transform", "rotate(90)");
svg.append("text")
.attr("class", "label")
.attr("x", 0)
.attr("y", 30)
.text(`+${desiredData.map(d=>d[regions.indexOf(xxx)])[z]["deaths"]}`)
.attr("transform", "rotate(90)");
svg.attr("transform", "rotate(270)");
svg.append("g")
.call(yAxis);
return svg.node()
}