From 5c49e55d950cadf3094b041c1171da3aec8cfbed Mon Sep 17 00:00:00 2001 From: zyh Date: Fri, 9 Aug 2024 16:14:30 +0800 Subject: [PATCH] =?UTF-8?q?NEZ-3498=20fix:=20=E5=9B=BE=E8=A1=A8Data?= =?UTF-8?q?=E7=BB=84=E4=B8=8Bbits=E5=8D=95=E4=BD=8D=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/chart/chartDataFormat.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nezha-fronted/src/components/chart/chartDataFormat.js b/nezha-fronted/src/components/chart/chartDataFormat.js index f2422a57b..108882685 100644 --- a/nezha-fronted/src/components/chart/chartDataFormat.js +++ b/nezha-fronted/src/components/chart/chartDataFormat.js @@ -530,19 +530,17 @@ function asciiCompute (num, ascii, units, dot = 2, isBits = false) { } num = Number(num) if (isBits) { - num = num / 8 - if (num < 8) { + if (num >= 8) { + num = num / 8 + } else { return num.toFixed(dot) + ' ' + units[0] } - if (num < ascii) { - return num.toFixed(dot) + ' ' + units[1] - } } const SIGN = num > 0 ? 1 : -1 num = Math.abs(num) let carry = 0 if (num > 1) { - let log = Math.log(num) / Math.log(ascii) + const log = Math.log(num) / Math.log(ascii) carry = Math.floor(log) num = num / Math.pow(ascii, carry) } @@ -551,6 +549,9 @@ function asciiCompute (num, ascii, units, dot = 2, isBits = false) { // carry = parseInt(log) // num = num / Math.pow(ascii, carry) // } + if (isBits) { + carry++ + } if (Number.isInteger(num)) { return num * SIGN + ' ' + units[carry] } else {