function drawPersonDiagram(dataList, options) {
options = addDefaults(
options,
Object({
caption: 'No Label',
nIcons: 100,
funcFormatValue: d3.format(','),
iconsPerRow: 20
})
);
const totalValue = dataList.reduce(
(totalValue, d) => totalValue + d.value,
0
);
const [childList, iAll] = dataList.reduce(
function([childList, iAll], d) {
const n = Math.round((d.value * options.nIcons) / totalValue, 0);
return range(0, n).reduce(
function([childList, iAll], i) {
iAll += 1;
let iconOptions = d;
iconOptions = addDefaults(iconOptions, options);
iconOptions = addDefaults(iconOptions, { fill: d.color });
childList.push(drawIcon(d.iconID, iconOptions));
if (iAll % options.iconsPerRow === 0) {
childList.push(_('br'));
}
return [childList, iAll];
},
[childList, iAll]
);
},
[[], 0]
);
const legendChildList = dataList.map(function(d) {
return _('div', [
drawIcon(d.iconID, addDefaults(options, { fill: d.color })),
_('span', `${d.label} (${options.funcFormatValue(d.value)})`)
]);
});
return _(
'figure',
[
_('div', childList),
_('div', legendChildList, { style: { margin: '32px' } }),
_('figcaption', 'Figure: ' + options.caption, {
style: { 'text-align': 'center' }
})
],
{ style: { padding: '32px', 'text-align': 'center' } }
);
}