X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Fhistogram-svg.js;h=9f01054a7b66b36077f0bc14e0fcc2d11e833820;hb=1c37a7c533a5530390489ea9a49dcca492db1074;hp=13d0c91becb0d4ae94f9dcfe454f8e279e1390c6;hpb=c0c8d2d8be8dddb5924ebae12cab07a6f49757f7;p=websub-hub diff --git a/src/template/histogram-svg.js b/src/template/histogram-svg.js index 13d0c91..9f01054 100644 --- a/src/template/histogram-svg.js +++ b/src/template/histogram-svg.js @@ -19,11 +19,23 @@ const optionsDefaults = { maxItems: undefined, }; +/** + * + * @param {number} percent grey value + * @returns {string} rgb value + */ function grey(percent) { const value = Math.round(95 * (1.0 - percent)); return `rgb(${value}%, ${value}%, ${value}%)`; } +/** + * + * @param {object} options options + * @param {number} width width + * @param {number} height height + * @returns {string} svg element + */ function svgHeader(options, width, height) { return [ `\n`; } +/** + * + * @param {object} options options + * @param {number} width width + * @returns {string} element + */ function svgTicks(options, width) { if (!options.tickEvery) { return ''; @@ -68,6 +92,13 @@ function svgTicks(options, width) { \t\n`; } +/** + * + * @param {object} options options + * @param {number} width width + * @param {number} height height + * @returns {string} element + */ function svgLabels(options, width, height) { const labels = []; if (!options.labelHeight) { @@ -85,10 +116,21 @@ function svgLabels(options, width, height) { return labels; } +/** + * @returns {string} element + */ function svgFooter() { return ''; } +/** + * + * @param {object} options options + * @param {number} value value + * @param {number} index index + * @param {number} maxValue max value + * @returns {string} element + */ function svgBar(options, value, index, maxValue) { const id = `i${index}`; const x = options.barWidth * index; @@ -113,7 +155,10 @@ function svgBar(options, value, index, maxValue) { } module.exports = (items, options = {}) => { - options = Object.assign({}, optionsDefaults, options); + options = { + ...optionsDefaults, + ...options, + }; const maxValue = items.reduce((a, b) => Math.max(a, b), 0); const hasLabel = !!options.labelX || !!options.labelZero;