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

77 lines
1.5 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";
const Gauge = ({ progressValue, displayText, theme }) => {
2024-10-29 14:03:41 -04:00
const BASE_TEXT_STYLE = {
2024-10-29 10:24:03 -04:00
textAnchor: "middle",
dominantBaseline: "middle",
};
2024-10-29 14:03:41 -04:00
const getStyles = (theme) => ({
text: {
...BASE_TEXT_STYLE,
style: { fontSize: "12px", fill: theme.palette.text.tertiary },
},
});
2024-10-29 10:24:03 -04:00
const data = [{ value: 100 }];
2024-10-29 14:03:41 -04:00
const commonRadialBarProps = {
minAngle: 15,
clockWise: true,
dataKey: "value",
cornerRadius: 0
};
2024-10-29 10:24:03 -04:00
return (
<ResponsiveContainer
width="100%"
height={150}
>
<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 10:24:03 -04:00
fill="#8884d8"
background={{ fill: "#bed2ea" }}
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 14:03:41 -04:00
{...getStyles(theme).text}
2024-10-29 10:24:03 -04:00
>
{`${progressValue}%`}
</text>
<text
x="50%"
y="55%"
2024-10-29 14:03:41 -04:00
{...getStyles(theme).text}
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;