projects
/
websub-hub
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'v1.3-dev'
[websub-hub]
/
src
/
template
/
histogram-svg.js
diff --git
a/src/template/histogram-svg.js
b/src/template/histogram-svg.js
index 13d0c91becb0d4ae94f9dcfe454f8e279e1390c6..9f01054a7b66b36077f0bc14e0fcc2d11e833820 100644
(file)
--- a/
src/template/histogram-svg.js
+++ b/
src/template/histogram-svg.js
@@
-19,11
+19,23
@@
const optionsDefaults = {
maxItems: undefined,
};
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}%)`;
}
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 [
`<svg
function svgHeader(options, width, height) {
return [
`<svg
@@
-43,6
+55,12
@@
preserveAspectRatio="xMinYMin meet"`,
];
}
];
}
+/**
+ *
+ * @param {options} options options
+ * @param {number} width width
+ * @returns {string} element
+ */
function svgFrame(options, width) {
if (!options.frameColor) {
return '';
function svgFrame(options, width) {
if (!options.frameColor) {
return '';
@@
-52,6
+70,12
@@
function svgFrame(options, width) {
\t</g>\n`;
}
\t</g>\n`;
}
+/**
+ *
+ * @param {object} options options
+ * @param {number} width width
+ * @returns {string} element
+ */
function svgTicks(options, width) {
if (!options.tickEvery) {
return '';
function svgTicks(options, width) {
if (!options.tickEvery) {
return '';
@@
-68,6
+92,13
@@
function svgTicks(options, width) {
\t</g>\n`;
}
\t</g>\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) {
function svgLabels(options, width, height) {
const labels = [];
if (!options.labelHeight) {
@@
-85,10
+116,21
@@
function svgLabels(options, width, height) {
return labels;
}
return labels;
}
+/**
+ * @returns {string} element
+ */
function svgFooter() {
return '</svg>';
}
function svgFooter() {
return '</svg>';
}
+/**
+ *
+ * @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;
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 = {}) => {
}
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;
const maxValue = items.reduce((a, b) => Math.max(a, b), 0);
const hasLabel = !!options.labelX || !!options.labelZero;