import { BaseChart } from "@/Components/design-elements"; import Stack from "@mui/material/Stack"; import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import { useTheme } from "@mui/material/styles"; import { useMemo, useState, useEffect } from "react"; import { getInfraGaugeColor } from "@/Utils/MonitorUtils"; const MINIMUM_VALUE = 0; const MAXIMUM_VALUE = 100; export const Gauge = ({ isLoading = false, progress = 0, radius = 70, strokeWidth = 15, precision = 1, unit = "%", }: { isLoading?: boolean; progress?: number; radius?: number; strokeWidth?: number; precision?: number; unit?: string; }) => { const theme = useTheme(); const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE)); // Calculate the length of the stroke for the circle const { circumference, totalSize, strokeLength } = useMemo( () => ({ circumference: 2 * Math.PI * radius, totalSize: radius * 2 + strokeWidth * 2, strokeLength: (progress / 100) * (2 * Math.PI * radius), }), [radius, strokeWidth, progress] ); const [offset, setOffset] = useState(circumference); useEffect(() => { setOffset(circumference); const timer = setTimeout(() => { setOffset(circumference - strokeLength); }, 100); return () => clearTimeout(timer); }, [progress, circumference, strokeLength]); const fillColor = getInfraGaugeColor(progressWithinRange, theme); if (isLoading) { return; } return ( {`${progressWithinRange.toFixed(precision)}${unit}`} ); }; export const DetailGauge = ({ title, progress, upperLabel, upperValue, lowerLabel, lowerValue, }: { title: string; progress: number; upperLabel?: string; upperValue?: string | number; lowerLabel?: string; lowerValue?: string | number; }) => { const theme = useTheme(); return ( {upperLabel} {upperValue} {lowerLabel} {lowerValue} ); };