feat: wrapping Chart Gauge adaptations

This commit is contained in:
Caio Cabral committed 2024-11-16 22:48:46 -05:00
1 parent 229135513d
commit 66cd813695
4 files changed
+122 -48

No files matched your search

+70 -41
View File
@@ -1,42 +1,32 @@
import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts";
import { RadialBarChart, RadialBar, ResponsiveContainer, Text, Legend } from "recharts";
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
const MINIMUM_VALUE = 0;
const MAXIMUM_VALUE = 100;
const DATA = [{ value: MAXIMUM_VALUE }];
const PROGRESS_THRESHOLD = 50;
const DEFAULT_CONTAINER_HEIGHT = 160;
const TEXT_POSITIONS = {
value: { x: "50%", y: "45%" },
label: { x: "50%", y: "55%" },
};
const COMMON_RADIAL_BAR_PROPS = {
minAngle: 15,
clockWise: true,
dataKey: "value",
cornerRadius: 0,
};
const DEFAULT_WIDTH = 60;
// const DEFAULT_CONTAINER_HEIGHT = 160;
// const TEXT_POSITIONS = {
// value: { x: "50%", y: "45%" },
// label: { x: "50%", y: "55%" },
// };
const RADIUS = "90%";
const START_ANGLE = 90;
const CHART_RANGE = 360;
const RADIAL_BAR_CHART_PROPS = {
cx: "50%",
cy: "50%",
innerRadius: "45%",
outerRadius: "100%",
startAngle: 90,
endAngle: -270,
innerRadius: RADIUS,
outerRadius: RADIUS,
barSize: 6,
startAngle: START_ANGLE,
endAngle: START_ANGLE - CHART_RANGE,
margin: { top: 0, right: 0, bottom: 0, left: 0 },
};
const RADIAL_BAR_OVERLAY_PROPS = {
transform: "rotate(180deg)",
position: "absolute",
top: "0",
left: "0",
};
const COMMON_HEADER_PROPS = {
textAnchor: "middle",
dominantBaseline: "middle",
const COMMON_RADIAL_BAR_PROPS = {
dataKey: "value",
cornerRadius: 8,
};
/**
@@ -64,19 +54,40 @@ const COMMON_HEADER_PROPS = {
*/
const Gauge = ({
progressValue,
displayText,
containerHeight,
gaugeHeader,
gaugeSubheader,
containerWidth,
// displayText,
// containerHeight,
// gaugeHeader,
// gaugeSubheader,
}) => {
const theme = useTheme();
const myProgressValue = Math.max(MINIMUM_VALUE, Math.min(progressValue, MAXIMUM_VALUE));
const chartData = [
{
value: MAXIMUM_VALUE,
fill: "transparent",
},
{
value: myProgressValue,
fill:
progressValue > PROGRESS_THRESHOLD
? theme.palette.primary.main
: theme.palette.percentage.uptimePoor,
},
];
const width = containerWidth ?? DEFAULT_WIDTH;
return (
<ResponsiveContainer height={containerHeight ?? DEFAULT_CONTAINER_HEIGHT}>
<ResponsiveContainer
aspect={1}
width={width}
/* height={containerHeight ?? DEFAULT_CONTAINER_HEIGHT}
width={containerWidth} */
>
<RadialBarChart
{...RADIAL_BAR_CHART_PROPS}
data={DATA}
data={chartData /* [{ ...DATA, fill: "#666666" }, { value: myProgressValue }] */}
>
<RadialBar
{...COMMON_RADIAL_BAR_PROPS}
@@ -86,14 +97,32 @@ const Gauge = ({
: theme.palette.percentage.uptimePoor
}
background={{ fill: theme.palette.background.fill }}
data={[{ value: myProgressValue }]}
label={{
position: "center",
fill: "#000000",
content: () => (
<text
x="50%"
y="50%"
textAnchor="middle"
dominantBaseline="middle"
style={{
fontSize: "12px",
fill: "#000000",
}}
>{`${myProgressValue}%`}</text>
),
}}
/* data={[{ value: myProgressValue }]} */
/>
<RadialBar
{/* <RadialBar
{...COMMON_RADIAL_BAR_PROPS}
data={DATA}
style={RADIAL_BAR_OVERLAY_PROPS}
/>
<text
/> */}
{/* TODO what is the text tag? */}
{/* <text
{...TEXT_POSITIONS.value}
role="text"
aria-label={`${myProgressValue}%`}
@@ -108,7 +137,7 @@ const Gauge = ({
style={{ ...COMMON_HEADER_PROPS, ...theme.chart.subheader, ...gaugeSubheader }}
>
{`${displayText}`}
</text>
</text> */}
</RadialBarChart>
</ResponsiveContainer>
);
@@ -121,4 +150,4 @@ Gauge.propTypes = {
gaugeHeader: PropTypes.object,
gaugeSubheader: PropTypes.object,
};
export default Gauge;
export { Gauge };
@@ -6,6 +6,13 @@
padding: var(--env-var-spacing-2);
}
/* TODO go for this approach for responsiveness. The aside needs to be taken care of */
/* @media (max-width: 1000px) {
.home-layout {
flex-direction: column !important;
}
} */
.home-layout aside {
position: sticky;
top: var(--env-var-spacing-2);