Added gradient to area chart

This commit is contained in:
Daniel Cojocea committed 2024-09-04 21:09:18 -04:00
1 parent 2a1afc8610
commit 7e01006cef
4 files changed
+36 -16

No files matched your search

@@ -64,6 +64,8 @@ const MonitorDetailsAreaChart = ({ checks }) => {
}); });
}; };
const theme = useTheme();
return ( return (
<ResponsiveContainer width="100%" height="100%"> <ResponsiveContainer width="100%" height="100%">
<AreaChart <AreaChart
@@ -77,6 +79,20 @@ const MonitorDetailsAreaChart = ({ checks }) => {
bottom: 0, bottom: 0,
}} }}
> >
<defs>
<linearGradient id="colorUv" x1="0" y1="0" x2="0" y2="1">
<stop
offset="0%"
stopColor={theme.palette.primary.main}
stopOpacity={0.8}
/>
<stop
offset="100%"
stopColor={theme.palette.primary.light}
stopOpacity={0}
/>
</linearGradient>
</defs>
<XAxis <XAxis
dataKey="createdAt" dataKey="createdAt"
tickFormatter={formatDate} tickFormatter={formatDate}
@@ -87,8 +103,8 @@ const MonitorDetailsAreaChart = ({ checks }) => {
<Area <Area
type="monotone" type="monotone"
dataKey="responseTime" dataKey="responseTime"
stroke="#29afee" stroke={theme.palette.primary.main}
fill="#eaf2fd" fill="url(#colorUv)"
/> />
</AreaChart> </AreaChart>
</ResponsiveContainer> </ResponsiveContainer>
@@ -54,12 +54,15 @@ export const UpBarChart = ({ data, type, onBarHover }) => {
: { main: theme.palette.error.text, light: theme.palette.error.light }; : { main: theme.palette.error.text, light: theme.palette.error.light };
}; };
// TODO - REMOVE THIS LATER
let reversedData = [...data].reverse();
return ( return (
<ResponsiveContainer width="100%" height={155}> <ResponsiveContainer width="100%" height={155}>
<BarChart <BarChart
width="100%" width="100%"
height="100%" height="100%"
data={data} data={reversedData}
onMouseEnter={() => { onMouseEnter={() => {
setChartHovered(true); setChartHovered(true);
onBarHover({ time: null, totalChecks: 0, uptimePercentage: 0 }); onBarHover({ time: null, totalChecks: 0, uptimePercentage: 0 });
@@ -80,8 +83,8 @@ export const UpBarChart = ({ data, type, onBarHover }) => {
y={0} y={0}
width="100%" width="100%"
height="100%" height="100%"
firstDataPoint={data[0]} firstDataPoint={reversedData[0]}
lastDataPoint={data[data.length - 1]} lastDataPoint={reversedData[reversedData.length - 1]}
type={type} type={type}
/> />
} }
@@ -91,7 +94,7 @@ export const UpBarChart = ({ data, type, onBarHover }) => {
maxBarSize={7} maxBarSize={7}
background={{ fill: "transparent" }} background={{ fill: "transparent" }}
> >
{data.map((entry, index) => { {reversedData.map((entry, index) => {
let { main, light } = getColorRange(entry.uptimePercentage); let { main, light } = getColorRange(entry.uptimePercentage);
return ( return (
<Cell <Cell
@@ -126,12 +129,15 @@ export const DownBarChart = ({ data, type, onBarHover }) => {
const [chartHovered, setChartHovered] = useState(false); const [chartHovered, setChartHovered] = useState(false);
const [hoveredBarIndex, setHoveredBarIndex] = useState(null); const [hoveredBarIndex, setHoveredBarIndex] = useState(null);
// TODO - REMOVE THIS LATER
let reversedData = [...data].reverse();
return ( return (
<ResponsiveContainer width="100%" height={155}> <ResponsiveContainer width="100%" height={155}>
<BarChart <BarChart
width="100%" width="100%"
height="100%" height="100%"
data={data} data={reversedData}
onMouseEnter={() => { onMouseEnter={() => {
setChartHovered(true); setChartHovered(true);
onBarHover({ time: null, totalIncidents: 0 }); onBarHover({ time: null, totalIncidents: 0 });
@@ -152,8 +158,8 @@ export const DownBarChart = ({ data, type, onBarHover }) => {
y={0} y={0}
width="100%" width="100%"
height="100%" height="100%"
firstDataPoint={data[0]} firstDataPoint={reversedData[0]}
lastDataPoint={data[data.length - 1]} lastDataPoint={reversedData[reversedData.length - 1]}
type={type} type={type}
/> />
} }
@@ -163,7 +169,7 @@ export const DownBarChart = ({ data, type, onBarHover }) => {
maxBarSize={7} maxBarSize={7}
background={{ fill: "transparent" }} background={{ fill: "transparent" }}
> >
{data.map((entry, index) => ( {reversedData.map((entry, index) => (
<Cell <Cell
key={`cell-${index}`} key={`cell-${index}`}
fill={ fill={
+3 -5
View File
@@ -481,11 +481,9 @@ const DetailsPage = ({ isAdmin }) => {
</IconBox> </IconBox>
<Typography component="h2">Response Times</Typography> <Typography component="h2">Response Times</Typography>
</Stack> </Stack>
<Box> <MonitorDetailsAreaChart
{/* <MonitorDetailsAreaChart checks={[...monitor.checks].reverse()}
checks={[...monitor.checks].reverse()} />
/> */}
</Box>
</ChartBox> </ChartBox>
<ChartBox <ChartBox
gap={theme.spacing(8)} gap={theme.spacing(8)}
+1 -1
View File
@@ -250,7 +250,7 @@ const getMonitorStatsById = async (req) => {
// Normalize checks if requested // Normalize checks if requested
if (normalize !== undefined) { if (normalize !== undefined) {
const normailzedChecks = NormalizeData(checksForDateRange, 1, 100); const normailzedChecks = NormalizeData(nthChecks, 1, 100);
monitorStats.checks = normailzedChecks; monitorStats.checks = normailzedChecks;
} else { } else {
monitorStats.checks = nthChecks; monitorStats.checks = nthChecks;