diff --git a/src/components/charts/DoughnutChart.tsx b/src/components/charts/DoughnutChart.tsx index 7609afa..19d20c3 100644 --- a/src/components/charts/DoughnutChart.tsx +++ b/src/components/charts/DoughnutChart.tsx @@ -1,82 +1,120 @@ -import { useSettingsAtom } from "@/atom/useSettingsAtom"; +import { type ChartConfig, ChartContainer } from "@/components/ui/chart"; +import { Skeleton } from "@/components/ui/skeleton"; import type { HardwareDataType } from "@/types/hardwareDataType"; import { Lightning, Speedometer, Thermometer } from "@phosphor-icons/react"; -import { - ArcElement, - Chart as ChartJS, - type ChartOptions, - Legend, - Tooltip, -} from "chart.js"; -import { Doughnut } from "react-chartjs-2"; import { useTranslation } from "react-i18next"; +import { + Label, + PolarGrid, + PolarRadiusAxis, + RadialBar, + RadialBarChart, +} from "recharts"; -ChartJS.register(ArcElement, Tooltip, Legend); - -const DoughnutChart = ({ - chartData, +export const DoughnutChart = ({ + chartValue, dataType, }: { - chartData: number; + chartValue: number; dataType: HardwareDataType; }) => { - const { settings } = useSettingsAtom(); - const { t } = useTranslation(); - const displayDataType: Record = { - usage: t("shared.usage"), - temp: t("shared.temperature"), - clock: t("shared.clock"), - }; - - const data = { - datasets: [ - { - data: [chartData, 100 - chartData], - backgroundColor: { - light: ["#374151", "#f3f4f6"], - dark: ["#888", "#222"], - }[settings.theme], - borderWidth: 0, - }, - ], - }; - - const options: ChartOptions<"doughnut"> = { - cutout: "85%", - plugins: { - tooltip: { enabled: false }, + const chartConfig: Record< + HardwareDataType, + { label: string; color: string } + > = { + usage: { + label: t("shared.usage"), + color: "hsl(var(--chart-2))", }, - }; + temp: { + label: t("shared.temperature"), + color: "hsl(var(--chart-3))", + }, + clock: { + label: t("shared.clock"), + color: "hsl(var(--chart-4))", + }, + } satisfies ChartConfig; + + const chartData = [ + { type: dataType, value: chartValue, fill: `var(--color-${dataType})` }, + ]; const dataTypeIcons: Record = { - usage: , - temp: , - clock: , + usage: , + temp: , + clock: , }; const dataTypeUnits: Record = { usage: "%", - temp: "℃", + temp: "°C", clock: "MHz", }; return ( -
- -
- - {chartData} - {dataTypeUnits[dataType]} - -
- - {dataTypeIcons[dataType]} - {displayDataType[dataType]} - -
+ + {chartData[0].value != null ? ( + + + + + + + ) : ( +
+ +
+ )} +
); }; - -export { DoughnutChart }; diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsx new file mode 100644 index 0000000..b4918a7 --- /dev/null +++ b/src/components/ui/skeleton.tsx @@ -0,0 +1,15 @@ +import { cn } from "@/lib/utils" + +function Skeleton({ + className, + ...props +}: React.HTMLAttributes) { + return ( +
+ ) +} + +export { Skeleton } diff --git a/src/template/Dashboard.tsx b/src/template/Dashboard.tsx index a4fe894..aa240a3 100644 --- a/src/template/Dashboard.tsx +++ b/src/template/Dashboard.tsx @@ -1,6 +1,5 @@ import { cpuUsageHistoryAtom, - gpuFanSpeedAtom, gpuTempAtom, graphicUsageHistoryAtom, memoryUsageHistoryAtom, @@ -20,7 +19,7 @@ import { useTranslation } from "react-i18next"; const InfoTable = ({ data }: { data: { [key: string]: string | number } }) => { return ( -
+
{Object.keys(data).map((key) => ( @@ -65,7 +64,7 @@ const CPUInfo = () => { hardwareInfo.cpu && ( <> { const { t } = useTranslation(); const [graphicUsageHistory] = useAtom(graphicUsageHistoryAtom); const [gpuTemp] = useAtom(gpuTempAtom); - const [gpuFan] = useAtom(gpuFanSpeedAtom); const { hardwareInfo } = useHardwareInfoAtom(); const getTargetInfo = (data: NameValues) => { @@ -96,21 +94,17 @@ const GPUInfo = () => { }; const targetTemperature = getTargetInfo(gpuTemp); - const targetFanSpeed = getTargetInfo(gpuFan); return ( hardwareInfo.gpus && ( <> -
+
{targetTemperature && ( - - )} - {targetFanSpeed && ( - + )}
@@ -140,7 +134,7 @@ const MemoryInfo = () => { hardwareInfo.memory && ( <>