Files
Checkmate/Client/src/Components/Charts/Gauge/index.jsx
T

81 lines
1.8 KiB
React
Raw Normal View History

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 21:35:58 -04:00
};
const Gauge = ({
progressValue,
displayText,
theme,
containerHeight,
gaugeHeader,
gaugeSubheader,
}) => {
const header = gaugeHeader ?? { fontSize: "11px" };
const subheader = gaugeSubheader ?? { fontSize: "9px" };
2024-10-29 10:24:03 -04:00
return (
<ResponsiveContainer height={containerHeight ?? 160}>
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%"
style={{ ...theme.palette.gaugeHeaderCommon, ...header }}
2024-10-29 10:24:03 -04:00
>
{`${progressValue}%`}
</text>
<text
x="50%"
y="55%"
style={{ ...theme.palette.gaugeHeaderCommon, ...subheader }}
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,
containerHeight: PropTypes.number,
gaugeHeader: PropTypes.object,
gaugeSubheader: PropTypes.object,
2024-10-29 10:24:03 -04:00
};
export default Gauge;