From f84edc3c87c51a19808fe215af90b725a74cf766 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Thu, 10 Oct 2024 10:14:49 +0800 Subject: [PATCH] refactor: Remove commented-out code and improve CPU stats display --- src/components/area-chart.tsx | 25 ++--- src/contants.ts | 8 +- .../global-cpu/global-cpu.area-chart.tsx | 95 ++++++++++++++++++- 3 files changed, 109 insertions(+), 19 deletions(-) diff --git a/src/components/area-chart.tsx b/src/components/area-chart.tsx index 9a498cd5..626d1281 100644 --- a/src/components/area-chart.tsx +++ b/src/components/area-chart.tsx @@ -35,17 +35,19 @@ export const useAreaChartState = ( accessibility: { enabled: false, }, - title: { - text: opts.title.text, - style: { - fontFamily: "Geist Variable, Roboto, Arial, sans-serif", - fontWeight: "bold", - fontSize: "16px", - color: "#dce1e8", - }, - }, + // title: { + + // text: opts.title.text, + // style: { + // fontFamily: "Geist Variable, Roboto, Arial, sans-serif", + // fontWeight: "bold", + // fontSize: "16px", + // color: "#dce1e8", + // }, + // }, // This is the rectangle box that u can use to navigate navigator: { + enabled: false, adaptToUpdatedData: true, maskFill: other.charts.area.default.navigator.maskFill, handles: { @@ -129,6 +131,8 @@ export const useAreaChartState = ( // This is the calendar thing on the top right rangeSelector: { inputEnabled: false, + allButtonsEnabled: false, + enabled: false, floating: true, labelStyle: { @@ -176,8 +180,7 @@ export const useAreaChartState = ( }, boost: { enabled: true, - useGPUTranslations: false, - allowForce: true, + useGPUTranslations: true, }, chart: { ignoreHiddenSeries: true, diff --git a/src/contants.ts b/src/contants.ts index 44a31237..2d357cb4 100644 --- a/src/contants.ts +++ b/src/contants.ts @@ -108,9 +108,9 @@ export const themes: Record = { titlebar: commonColors.slate.titlebar, charts: { statsRing: { - cpu: "blue", + cpu: "red", memory: "cyan", - swap: "red", + swap: "blue", disk: "grape", }, area: { @@ -185,9 +185,9 @@ export const themes: Record = { titlebar: commonColors.midnight.titlebar, charts: { statsRing: { - cpu: "blue", + cpu: "red", memory: "cyan", - swap: "red", + swap: "blue", disk: "grape", }, area: { diff --git a/src/features/metrics/components/global-cpu/global-cpu.area-chart.tsx b/src/features/metrics/components/global-cpu/global-cpu.area-chart.tsx index b6bab816..f1b903c3 100644 --- a/src/features/metrics/components/global-cpu/global-cpu.area-chart.tsx +++ b/src/features/metrics/components/global-cpu/global-cpu.area-chart.tsx @@ -1,17 +1,64 @@ -import { useEffect } from "react"; +import React, { useEffect } from "react"; import AreaChart, { useAreaChartState } from "@/components/area-chart"; import Card from "@/components/card"; +import GlobalCpuStatsRing from "@/features/metrics/components/global-cpu/global-cpu.stats-ring"; import useGlobalCpuSelectors from "@/features/metrics/stores/global-cpu.store"; import fromNumberToPercentageString from "@/features/metrics/utils/from-number-to-percentage-string"; -import { useMantineTheme } from "@mantine/core"; +import { + Box, + Center, + DefaultMantineColor, + Divider, + Grid, + Group, + rem, + RingProgress, + Stack, + Text, + Title, + useMantineTheme, +} from "@mantine/core"; +import { IconCpu, TablerIconsProps } from "@tabler/icons-react"; // TODO: Remove Luxon and ChartJS // TODO: Make timestamp work automatically // TODO: fix time +interface StatsRingProps { + label: string; + stats: string; + progress: number; + color: DefaultMantineColor; + Icon: (props: TablerIconsProps) => JSX.Element; +} + +const StatsRing: React.FC = (props) => { + return ( + + + + + } + /> + + + {props.stats} + + + + ); +}; + const GlobalCpuAreaChart: React.FC = ({}) => { const metrics = useGlobalCpuSelectors.use.metrics(); + const globalCpu = useGlobalCpuSelectors.use.latest(); const { other } = useMantineTheme(); const [chartOptions, setChartOptions] = useAreaChartState({ title: { @@ -32,6 +79,9 @@ const GlobalCpuAreaChart: React.FC = ({}) => { }, }); + const progress = globalCpu.usage; + const stats = React.useMemo(() => fromNumberToPercentageString(progress), [progress]); + useEffect(() => { setChartOptions({ series: [ @@ -46,8 +96,45 @@ const GlobalCpuAreaChart: React.FC = ({}) => { }, [metrics]); return ( - - + + + +
+ + + + CPU Usage + + + + +
+
+ + + + +
); };