From e84c9a4a110be1f093b1e5c82441e2abff26b8bc Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 15 Dec 2024 17:00:08 +0800 Subject: [PATCH] fix: overview chart toFixed(2) --- src/App.tsx | 4 ++-- src/components/ServerDetailChart.tsx | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index a8610c0..a39a267 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import { useQuery } from "@tanstack/react-query" import React, { useCallback } from "react" +import { useTranslation } from "react-i18next" import { Route, BrowserRouter as Router, Routes } from "react-router-dom" import Footer from "./components/Footer" @@ -10,7 +11,6 @@ import ErrorPage from "./pages/ErrorPage" import NotFound from "./pages/NotFound" import Server from "./pages/Server" import ServerDetail from "./pages/ServerDetail" -import { useTranslation } from "react-i18next" const App: React.FC = () => { const { data: settingData, error } = useQuery({ @@ -48,7 +48,7 @@ const App: React.FC = () => { Array.from(tempDiv.childNodes).forEach((node) => { if (node.nodeType === Node.ELEMENT_NODE) { const element = node as HTMLElement - ; (handlers[element.tagName] || handlers.DEFAULT)(element) + ;(handlers[element.tagName] || handlers.DEFAULT)(element) } else if (node.nodeType === Node.TEXT_NODE) { document.body.appendChild(document.createTextNode(node.textContent || "")) } diff --git a/src/components/ServerDetailChart.tsx b/src/components/ServerDetailChart.tsx index 2e14352..4c9f785 100644 --- a/src/components/ServerDetailChart.tsx +++ b/src/components/ServerDetailChart.tsx @@ -138,7 +138,7 @@ function GpuChart({ now, gpuStat, gpuName }: { now: number; gpuStat: number; gpu {gpuName &&

GPU: {gpuName}

}
-

{gpuStat.toFixed(0)}%

+

{gpuStat.toFixed(2)}%

CPU

-

{cpu.toFixed(0)}%

+

{cpu.toFixed(2)}%

-

{mem.toFixed(0)}%

+

{mem.toFixed(2)}%

@@ -424,7 +424,7 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) { value={swap} primaryColor="hsl(var(--chart-10))" /> -

{swap.toFixed(0)}%

+

{swap.toFixed(2)}%

@@ -642,14 +642,26 @@ function NetworkChart({ now, data }: { now: number; data: NezhaServer }) {

{t("serverDetailChart.upload")}

-

{up.toFixed(2)} M/s

+

+ {up >= 1024 + ? `${(up / 1024).toFixed(2)}G/s` + : up >= 1 + ? `${up.toFixed(2)}M/s` + : `${(up * 1024).toFixed(2)}K/s`} +

{t("serverDetailChart.download")}

-

{down.toFixed(2)} M/s

+

+ {down >= 1024 + ? `${(down / 1024).toFixed(2)}G/s` + : down >= 1 + ? `${down.toFixed(2)}M/s` + : `${(down * 1024).toFixed(2)}K/s`} +