addLegend = (container) => {
const dx = legendMargin.left;
const dy = canvasHeight - ((participationPercentageSlices.length * legendMarkSideLength) + legendMargin.bottom);
const legend = container.append("g")
.attr("id", "legend")
.attr("transform", `translate(${dx},${dy})`);
let percentageSliceLowerBound = 0;
for (let i = 0; i < participationPercentageSlices.length; i++) {
const percentageSliceUpperBound = participationPercentageSlices[i];
const mark = legend.append("g")
.attr("class", "mark");
mark.append("rect")
.attr("y", legendMarkSideLength * i)
.attr("width", legendMarkSideLength)
.attr("height", legendMarkSideLength)
.attr("fill", participatingCountryColors[i]);
mark.append("text")
.attr("dx", legendMarkSideLength + 10)
.attr("dy", (legendMarkSideLength * i) + (legendMarkSideLength / 2))
.text(`${format(percentageSliceLowerBound)} - ${format(percentageSliceUpperBound)}`)
percentageSliceLowerBound = percentageSliceUpperBound;
}
}