- Update based on coderabbitai feedback
This commit is contained in:
1 parent
239bd9c14e
commit
fe5f2af649
1 file changed
+21
-21
@@ -3,13 +3,23 @@ import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
const Gauge = ({ progressValue, displayText, theme }) => {
|
const Gauge = ({ progressValue, displayText, theme }) => {
|
||||||
const myStyle = { fontSize: "12px", fill: theme.palette.text.tertiary };
|
const BASE_TEXT_STYLE = {
|
||||||
const textStyle = {
|
|
||||||
textAnchor: "middle",
|
textAnchor: "middle",
|
||||||
dominantBaseline: "middle",
|
dominantBaseline: "middle",
|
||||||
style: myStyle
|
|
||||||
};
|
};
|
||||||
|
const getStyles = (theme) => ({
|
||||||
|
text: {
|
||||||
|
...BASE_TEXT_STYLE,
|
||||||
|
style: { fontSize: "12px", fill: theme.palette.text.tertiary },
|
||||||
|
},
|
||||||
|
});
|
||||||
const data = [{ value: 100 }];
|
const data = [{ value: 100 }];
|
||||||
|
const commonRadialBarProps = {
|
||||||
|
minAngle: 15,
|
||||||
|
clockWise: true,
|
||||||
|
dataKey: "value",
|
||||||
|
cornerRadius: 0
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<ResponsiveContainer
|
<ResponsiveContainer
|
||||||
width="100%"
|
width="100%"
|
||||||
@@ -25,19 +35,13 @@ const Gauge = ({ progressValue, displayText, theme }) => {
|
|||||||
data={data}
|
data={data}
|
||||||
>
|
>
|
||||||
<RadialBar
|
<RadialBar
|
||||||
minAngle={15}
|
{...commonRadialBarProps}
|
||||||
clockWise={true}
|
|
||||||
dataKey="value"
|
|
||||||
fill="#8884d8"
|
fill="#8884d8"
|
||||||
background={{ fill: "#bed2ea" }}
|
background={{ fill: "#bed2ea" }}
|
||||||
cornerRadius={0}
|
data={[{ value: progressValue }]}
|
||||||
data={[{ value: progressValue ?? 50 }]}
|
|
||||||
/>
|
/>
|
||||||
<RadialBar
|
<RadialBar
|
||||||
minAngle={15}
|
{...commonRadialBarProps}
|
||||||
clockWise={true}
|
|
||||||
dataKey="value"
|
|
||||||
cornerRadius={0}
|
|
||||||
data={data}
|
data={data}
|
||||||
style={{
|
style={{
|
||||||
transform: "rotate(180deg)",
|
transform: "rotate(180deg)",
|
||||||
@@ -49,18 +53,14 @@ const Gauge = ({ progressValue, displayText, theme }) => {
|
|||||||
<text
|
<text
|
||||||
x="50%"
|
x="50%"
|
||||||
y="45%"
|
y="45%"
|
||||||
textAnchor={textStyle.textAnchor}
|
{...getStyles(theme).text}
|
||||||
dominantBaseline={textStyle.dominantBaseline}
|
|
||||||
style={textStyle.style}
|
|
||||||
>
|
>
|
||||||
{`${progressValue}%`}
|
{`${progressValue}%`}
|
||||||
</text>
|
</text>
|
||||||
<text
|
<text
|
||||||
x="50%"
|
x="50%"
|
||||||
y="55%"
|
y="55%"
|
||||||
textAnchor={textStyle.textAnchor}
|
{...getStyles(theme).text}
|
||||||
dominantBaseline={textStyle.dominantBaseline}
|
|
||||||
style={textStyle.style}
|
|
||||||
>
|
>
|
||||||
{`${displayText}`}
|
{`${displayText}`}
|
||||||
</text>
|
</text>
|
||||||
@@ -70,8 +70,8 @@ const Gauge = ({ progressValue, displayText, theme }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Gauge.propTypes = {
|
Gauge.propTypes = {
|
||||||
progressValue: PropTypes.string,
|
progressValue: PropTypes.number.isRequired,
|
||||||
displayText: PropTypes.string,
|
displayText: PropTypes.string.isRequired,
|
||||||
theme: PropTypes.object,
|
theme: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
export default Gauge;
|
export default Gauge;
|
||||||
Reference in new issue
Block a user