function drawLegend(svg, legendDataList, options = {}) {
options = addDefaults(options, {
parentWidth: INFOGRAPHIC_WIDTH,
parentHeight: INFOGRAPHIC_HEIGHT,
parentPadding: INFOGRAPHIC_PADDING,
legendWidth: 200,
legendItemHeight: LEGEND_ITEM_HEIGHT,
funcDataToColor: function(data) {
return 'red';
},
funcDataToLabel: function(data) {
return data;
},
opacity: DEFAULT_STYLE.opacity
});
const nLegendDataList = legendDataList.length;
legendDataList.forEach(function(legendData, i) {
const [x, y] = [
options.parentWidth - options.legendWidth,
options.parentHeight / 2 +
(i - (nLegendDataList - 1) / 2) * LEGEND_ITEM_HEIGHT
];
const r = LEGEND_ITEM_HEIGHT / 3;
drawCircle(svg, [x, y], r, {
fill: options.funcDataToColor(legendData),
stroke: null,
opacity: options.opacity
});
drawText(svg, [x + r * 2, y], options.funcDataToLabel(legendData), {
fontSize: DEFAULT_STYLE.fontSize / 1.5,
textAnchor: 'start',
fill: 'black'
});
});
}