fix: rounding precision errors in aggregation chart legend
This commit is contained in:
parent
f644e19a5b
commit
d1123786cb
@ -1,6 +1,7 @@
|
|||||||
import BaseChart from './BaseChart';
|
import BaseChart from './BaseChart';
|
||||||
import { truncateString } from '../utils/draw-utils';
|
import { truncateString } from '../utils/draw-utils';
|
||||||
import { legendDot } from '../utils/draw';
|
import { legendDot } from '../utils/draw';
|
||||||
|
import { round } from '../utils/helpers';
|
||||||
import { getExtraWidth } from '../utils/constants';
|
import { getExtraWidth } from '../utils/constants';
|
||||||
|
|
||||||
export default class AggregationChart extends BaseChart {
|
export default class AggregationChart extends BaseChart {
|
||||||
@ -45,7 +46,7 @@ export default class AggregationChart extends BaseChart {
|
|||||||
|
|
||||||
s.labels = [];
|
s.labels = [];
|
||||||
totals.map(d => {
|
totals.map(d => {
|
||||||
s.sliceTotals.push(d[0]);
|
s.sliceTotals.push(round(d[0]));
|
||||||
s.labels.push(d[1]);
|
s.labels.push(d[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -105,3 +105,13 @@ export function isValidNumber(candidate, nonNegative=false) {
|
|||||||
else if (nonNegative && candidate < 0) return false;
|
else if (nonNegative && candidate < 0) return false;
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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');
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user