From e39ce8d4108353bc15269180ecddb18a7b0c7cdb Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 21 Nov 2022 10:40:47 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BE=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=8F=D0=B5=D0=BC=D1=8B=D1=85=20=D0=B4=D0=B8?= =?UTF-8?q?=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d3/monitoring/D3MonitoringCharts.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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) {