diff --git a/Client/src/Components/Charts/Gauge/index.jsx b/Client/src/Components/Charts/Gauge/index.jsx index baa5b13e7..f173c17fb 100644 --- a/Client/src/Components/Charts/Gauge/index.jsx +++ b/Client/src/Components/Charts/Gauge/index.jsx @@ -2,14 +2,38 @@ import React from "react"; import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts"; import PropTypes from "prop-types"; -const data = [{ value: 100 }]; -const commonRadialBarProps = { +const DATA = [{ value: 100 }]; +const PRGRESS_THRESHOLD = 50; +const DEFAULT_CONTAINER_HEIGHT = 160; +const DEFAULT_HEADER_FONT = { fontSize: "11px" }; +const DEFAULT_SUBHEADER_FONT = { fontSize: "9px" }; +const TEXT_POSITIONS = { + value: { x: "50%", y: "45%" }, + label: { x: "50%", y: "55%" }, +}; +const COMMON_RADIALBAR_PROPS = { minAngle: 15, clockWise: true, dataKey: "value", cornerRadius: 0, }; +const RADIALBARCHART_PROPS = { + cx: "50%", + cy: "50%", + innerRadius: "45%", + outerRadius: "100%", + startAngle: 90, + endAngle: -270, +}; + +const RADIALBAR_OVERLAY_PROPS = { + transform: "rotate(180deg)", + position: "absolute", + top: "0", + left: "0", +}; + const Gauge = ({ progressValue, displayText, @@ -18,49 +42,44 @@ const Gauge = ({ gaugeHeader, gaugeSubheader, }) => { - const header = gaugeHeader ?? { fontSize: "11px" }; - const subheader = gaugeSubheader ?? { fontSize: "9px" }; + const header = gaugeHeader ?? DEFAULT_HEADER_FONT; + const subheader = gaugeSubheader ?? DEFAULT_SUBHEADER_FONT; + const myProgressValue = + progressValue < 0 ? 0 : progressValue > DATA[0].value ? DATA[0].value : progressValue; + return ( - + 50 + progressValue > PRGRESS_THRESHOLD ? theme.palette.primary.main : theme.palette.percentage.uptimePoor } background={{ fill: theme.palette.background.fill }} - data={[{ value: progressValue }]} + data={[{ value: myProgressValue }]} /> - {`${progressValue}%`} + {`${myProgressValue}%`} {`${displayText}`}