2024-10-29 10:24:03 -04:00
|
|
|
import React from "react";
|
|
|
|
|
import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts";
|
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
|
2024-10-29 21:35:58 -04:00
|
|
|
const data = [{ value: 100 }];
|
|
|
|
|
const commonRadialBarProps = {
|
|
|
|
|
minAngle: 15,
|
|
|
|
|
clockWise: true,
|
|
|
|
|
dataKey: "value",
|
|
|
|
|
cornerRadius: 0
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-29 10:24:03 -04:00
|
|
|
const Gauge = ({ progressValue, displayText, theme }) => {
|
|
|
|
|
return (
|
2024-10-29 21:35:58 -04:00
|
|
|
<ResponsiveContainer>
|
2024-10-29 10:24:03 -04:00
|
|
|
<RadialBarChart
|
|
|
|
|
cx="50%"
|
|
|
|
|
cy="50%"
|
|
|
|
|
innerRadius="45%"
|
|
|
|
|
outerRadius="100%"
|
|
|
|
|
startAngle={90}
|
|
|
|
|
endAngle={-270}
|
|
|
|
|
data={data}
|
|
|
|
|
>
|
|
|
|
|
<RadialBar
|
2024-10-29 14:03:41 -04:00
|
|
|
{...commonRadialBarProps}
|
2024-10-29 21:35:58 -04:00
|
|
|
fill={
|
|
|
|
|
progressValue > 50
|
|
|
|
|
? theme.palette.primary.main
|
|
|
|
|
: theme.palette.percentage.uptimePoor
|
|
|
|
|
}
|
|
|
|
|
background={{ fill: theme.palette.background.fill }}
|
2024-10-29 14:03:41 -04:00
|
|
|
data={[{ value: progressValue }]}
|
2024-10-29 10:24:03 -04:00
|
|
|
/>
|
|
|
|
|
<RadialBar
|
2024-10-29 14:03:41 -04:00
|
|
|
{...commonRadialBarProps}
|
2024-10-29 10:24:03 -04:00
|
|
|
data={data}
|
|
|
|
|
style={{
|
|
|
|
|
transform: "rotate(180deg)",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "0",
|
|
|
|
|
left: "0",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<text
|
|
|
|
|
x="50%"
|
|
|
|
|
y="45%"
|
2024-10-29 21:35:58 -04:00
|
|
|
style={theme.palette.gaugePercentageText}
|
2024-10-29 10:24:03 -04:00
|
|
|
>
|
|
|
|
|
{`${progressValue}%`}
|
|
|
|
|
</text>
|
|
|
|
|
<text
|
|
|
|
|
x="50%"
|
|
|
|
|
y="55%"
|
2024-10-29 21:35:58 -04:00
|
|
|
style={theme.palette.gaugeDisplayText}
|
2024-10-29 10:24:03 -04:00
|
|
|
>
|
|
|
|
|
{`${displayText}`}
|
|
|
|
|
</text>
|
|
|
|
|
</RadialBarChart>
|
|
|
|
|
</ResponsiveContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Gauge.propTypes = {
|
2024-10-29 14:03:41 -04:00
|
|
|
progressValue: PropTypes.number.isRequired,
|
|
|
|
|
displayText: PropTypes.string.isRequired,
|
|
|
|
|
theme: PropTypes.object.isRequired,
|
2024-10-29 10:24:03 -04:00
|
|
|
};
|
|
|
|
|
export default Gauge;
|