diff --git a/src/js/charts/AggregationChart.js b/src/js/charts/AggregationChart.js index 0877cc6..e5d2c18 100644 --- a/src/js/charts/AggregationChart.js +++ b/src/js/charts/AggregationChart.js @@ -1,6 +1,7 @@ import BaseChart from './BaseChart'; import { truncateString } from '../utils/draw-utils'; import { legendDot } from '../utils/draw'; +import { round } from '../utils/helpers'; import { getExtraWidth } from '../utils/constants'; export default class AggregationChart extends BaseChart { @@ -45,7 +46,7 @@ export default class AggregationChart extends BaseChart { s.labels = []; totals.map(d => { - s.sliceTotals.push(d[0]); + s.sliceTotals.push(round(d[0])); s.labels.push(d[1]); }); diff --git a/src/js/utils/helpers.js b/src/js/utils/helpers.js index 7a59915..592760d 100644 --- a/src/js/utils/helpers.js +++ b/src/js/utils/helpers.js @@ -104,4 +104,14 @@ export function isValidNumber(candidate, nonNegative=false) { else if (!Number.isFinite(candidate)) return false; else if (nonNegative && candidate < 0) return false; else return true; -} \ No newline at end of file +} + +/** + * Round a number to the closes precision, max max precision 4 + * @param {Number} d Any Number + */ +export function round(d) { + // https://floating-point-gui.de/ + // https://www.jacklmoore.com/notes/rounding-in-javascript/ + return Number(Math.round(d + 'e4') + 'e-4'); +}