diff --git a/src/components/d3/monitoring/D3MonitoringCharts.tsx b/src/components/d3/monitoring/D3MonitoringCharts.tsx index 8215cce..3edb11e 100644 --- a/src/components/d3/monitoring/D3MonitoringCharts.tsx +++ b/src/components/d3/monitoring/D3MonitoringCharts.tsx @@ -35,13 +35,14 @@ const roundTo = (v: number, to: number = 50) => { return (v > 0 ? Math.ceil : Math.round)(v / to) * to } +const getNear = (n: number) => { + let k = 0 + for (let c = Math.abs(n); c >= 1; c /= 10) k++ + return Math.pow(10, k) * Math.sign(n) +} + const calculateDomain = (mm: MinMax): Required => { - let round = Math.abs((mm.max ?? 0) - (mm.min ?? 0)) - if (round < 10) round = 10 - else if (round < 100) round = roundTo(round, 10) - else if (round < 1000) round = roundTo(round, 100) - else if (round < 10000) round = roundTo(round, 1000) - else round = 0 + const round = getNear(Math.abs((mm.max ?? 0) - (mm.min ?? 0))) || 10 let min = roundTo(mm.min ?? 0, round) let max = roundTo(mm.max ?? round, round) if (round && Math.abs(min - max) < round) {