add forward ref to gauage for tooltip
This commit is contained in:
1 parent
f4b14e7df9
commit
d18a53eec2
1 file changed
+21
-13
@@ -1,30 +1,36 @@
|
|||||||
import { BaseChart } from "@/Components/design-elements";
|
import { BaseChart } from "@/Components/design-elements";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box, { type BoxProps } from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useMemo, useState, useEffect } from "react";
|
import { forwardRef, useMemo, useState, useEffect } from "react";
|
||||||
import { getInfraGaugeColor } from "@/Utils/MonitorUtils";
|
import { getInfraGaugeColor } from "@/Utils/MonitorUtils";
|
||||||
|
|
||||||
const MINIMUM_VALUE = 0;
|
const MINIMUM_VALUE = 0;
|
||||||
const MAXIMUM_VALUE = 100;
|
const MAXIMUM_VALUE = 100;
|
||||||
|
|
||||||
export const Gauge = ({
|
interface GaugeProps extends Omit<BoxProps, "color"> {
|
||||||
isLoading = false,
|
|
||||||
progress = 0,
|
|
||||||
radius = 70,
|
|
||||||
strokeWidth = 15,
|
|
||||||
precision = 1,
|
|
||||||
unit = "%",
|
|
||||||
}: {
|
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
progress?: number;
|
progress?: number;
|
||||||
radius?: number;
|
radius?: number;
|
||||||
strokeWidth?: number;
|
strokeWidth?: number;
|
||||||
precision?: number;
|
precision?: number;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
}) => {
|
}
|
||||||
|
|
||||||
|
export const Gauge = forwardRef<HTMLDivElement, GaugeProps>(function Gauge(
|
||||||
|
{
|
||||||
|
isLoading = false,
|
||||||
|
progress = 0,
|
||||||
|
radius = 70,
|
||||||
|
strokeWidth = 15,
|
||||||
|
precision = 1,
|
||||||
|
unit = "%",
|
||||||
|
...rest
|
||||||
|
},
|
||||||
|
ref
|
||||||
|
) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE));
|
const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE));
|
||||||
|
|
||||||
@@ -51,17 +57,19 @@ export const Gauge = ({
|
|||||||
const fillColor = getInfraGaugeColor(progressWithinRange, theme);
|
const fillColor = getInfraGaugeColor(progressWithinRange, theme);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
ref={ref}
|
||||||
display={"inline-block"}
|
display={"inline-block"}
|
||||||
position={"relative"}
|
position={"relative"}
|
||||||
width={radius}
|
width={radius}
|
||||||
height={radius}
|
height={radius}
|
||||||
bgcolor={theme.palette.background.paper}
|
bgcolor={theme.palette.background.paper}
|
||||||
borderRadius={"50%"}
|
borderRadius={"50%"}
|
||||||
|
{...rest}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
viewBox={`0 0 ${totalSize} ${totalSize}`}
|
viewBox={`0 0 ${totalSize} ${totalSize}`}
|
||||||
@@ -105,7 +113,7 @@ export const Gauge = ({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export const DetailGauge = ({
|
export const DetailGauge = ({
|
||||||
title,
|
title,
|
||||||
|
|||||||
Reference in new issue
Block a user