Merge pull request #808 from bluewave-labs/fix/barchart-animations

Fixed janky bar animations
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-09-05 14:23:53 -07:00
commit 09850299cf
2 files changed
+22 -15

No files matched your search

@@ -10,6 +10,7 @@ import {
import { Box, Stack, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import "./index.css"; import "./index.css";
import React, { useMemo } from "react";
const CustomToolTip = ({ active, payload, label }) => { const CustomToolTip = ({ active, payload, label }) => {
const theme = useTheme(); const theme = useTheme();
@@ -96,14 +97,16 @@ const MonitorDetailsAreaChart = ({ checks }) => {
}); });
}; };
const memoizedChecks = useMemo(() => checks, []);
const theme = useTheme(); const theme = useTheme();
return ( return (
<ResponsiveContainer width="100%" height={220}> <ResponsiveContainer width="100%" minWidth={25} height={220}>
<AreaChart <AreaChart
width="100%" width="100%"
height="100%" height="100%"
data={checks} data={memoizedChecks}
margin={{ margin={{
top: 10, top: 10,
right: 0, right: 0,
@@ -9,7 +9,7 @@ import {
RadialBar, RadialBar,
} from "recharts"; } from "recharts";
import { formatDate } from "../../../../Utils/timeUtils"; import { formatDate } from "../../../../Utils/timeUtils";
import { useState } from "react"; import { memo, useMemo, useState } from "react";
const CustomLabels = ({ const CustomLabels = ({
x, x,
@@ -39,7 +39,7 @@ const CustomLabels = ({
); );
}; };
export const UpBarChart = ({ data, type, onBarHover }) => { export const UpBarChart = memo(({ data, type, onBarHover }) => {
const theme = useTheme(); const theme = useTheme();
const [chartHovered, setChartHovered] = useState(false); const [chartHovered, setChartHovered] = useState(false);
@@ -54,10 +54,10 @@ export const UpBarChart = ({ data, type, onBarHover }) => {
}; };
// TODO - REMOVE THIS LATER // TODO - REMOVE THIS LATER
let reversedData = [...data].reverse(); const reversedData = useMemo(() => [...data].reverse(), [data]);
return ( return (
<ResponsiveContainer width="100%" height={155}> <ResponsiveContainer width="100%" minWidth={210} height={155}>
<BarChart <BarChart
width="100%" width="100%"
height="100%" height="100%"
@@ -120,19 +120,19 @@ export const UpBarChart = ({ data, type, onBarHover }) => {
</BarChart> </BarChart>
</ResponsiveContainer> </ResponsiveContainer>
); );
}; });
export const DownBarChart = ({ data, type, onBarHover }) => { export const DownBarChart = memo(({ data, type, onBarHover }) => {
const theme = useTheme(); const theme = useTheme();
const [chartHovered, setChartHovered] = useState(false); const [chartHovered, setChartHovered] = useState(false);
const [hoveredBarIndex, setHoveredBarIndex] = useState(null); const [hoveredBarIndex, setHoveredBarIndex] = useState(null);
// TODO - REMOVE THIS LATER // TODO - REMOVE THIS LATER
let reversedData = [...data].reverse(); const reversedData = useMemo(() => [...data].reverse(), [data]);
return ( return (
<ResponsiveContainer width="100%" height={155}> <ResponsiveContainer width="100%" minWidth={250} height={155}>
<BarChart <BarChart
width="100%" width="100%"
height="100%" height="100%"
@@ -192,15 +192,19 @@ export const DownBarChart = ({ data, type, onBarHover }) => {
</BarChart> </BarChart>
</ResponsiveContainer> </ResponsiveContainer>
); );
}; });
export const ResponseGaugeChart = ({ data }) => { export const ResponseGaugeChart = ({ data }) => {
const theme = useTheme(); const theme = useTheme();
let max = 1000; // max ms let max = 1000; // max ms
data = [{ response: max, fill: "transparent", background: false }, ...data];
let responseTime = Math.floor(data[1].response); const memoizedData = useMemo(
() => [{ response: max, fill: "transparent", background: false }, ...data],
[data[0].response]
);
let responseTime = Math.floor(memoizedData[1].response);
let responseProps = let responseProps =
responseTime <= 200 responseTime <= 200
? { ? {
@@ -227,12 +231,12 @@ export const ResponseGaugeChart = ({ data }) => {
}; };
return ( return (
<ResponsiveContainer width="100%" height={155}> <ResponsiveContainer width="100%" minWidth={210} height={155}>
<RadialBarChart <RadialBarChart
width="100%" width="100%"
height="100%" height="100%"
cy="89%" cy="89%"
data={data} data={memoizedData}
startAngle={180} startAngle={180}
endAngle={0} endAngle={0}
innerRadius={100} innerRadius={100}