function renderInfographic(options) {
options = addDefaults(options, {
width: INFOGRAPHIC_WIDTH,
height: INFOGRAPHIC_HEIGHT,
padding: INFOGRAPHIC_PADDING,
funcDrawInner: function(svg) {},
funcDrawLegend: function(svg) {},
kicker: 'Add Kicker Here',
title: 'Add Title Here',
subTitle: 'Add Sub Title Here',
footer: '@nuuuwan',
showGrid: false
});
const svg = getSVG({ width: options.width, height: options.height });
drawRect(svg, [0, 0], [options.width, options.height], {
fill: 'none',
stroke: 'lightgray',
strokeWidth: 2
});
options.funcDrawInner(svg);
options.funcDrawLegend(svg);
const svgTextOptions = defaultFontSizeMult =>
Object({
fill: 'black',
fontSize: defaultFontSizeMult * DEFAULT_STYLE.fontSize,
textAnchor: 'start'
});
const yTitle = options.height / 8;
drawText(
svg,
[options.padding, options.height / 16],
options.kicker.toUpperCase(),
svgTextOptions(0.8)
);
drawText(svg, [options.padding, yTitle], options.title, svgTextOptions(2));
drawText(
svg,
[options.padding, (3 * options.height) / 16],
options.subTitle,
svgTextOptions(1.2)
);
drawText(
svg,
[options.width - options.padding, (15 * options.height) / 16],
options.footer,
{ fill: 'darkgray', fontSize: DEFAULT_STYLE.fontSize, textAnchor: 'end' }
);
drawText(svg, [options.width / 2, options.height / 2], '@nuuuwan', {
fontSize: options.height / 3.5,
fill: 'rgba(0,0,0,0.01)'
});
if (options.showGrid) {
const n = 8;
const color = 'rgba(0, 0, 0, 0.05)';
range(1, n).forEach(function(i) {
const [x, y] = [(options.width * i) / n, (options.height * i) / n];
drawLine(svg, [x, 0], [x, options.height], { stroke: color });
drawLine(svg, [0, y], [options.width, y], { stroke: color });
});
}
return svg.node();
}