Standardize bar graph y axis

This commit is contained in:
Nicolas Mowen 2024-09-16 10:46:26 -06:00
parent e4ea35e626
commit 410cdf92dc

View File

@ -32,6 +32,15 @@ export function ThresholdBarGraph({
[data], [data],
); );
const yMax = useMemo(() => {
if (unit != "%") {
return undefined;
}
const yValues: number[] = data[0].data.map((point) => point?.y);
return Math.max(threshold.warning, ...yValues);
}, [data, threshold, unit]);
const { theme, systemTheme } = useTheme(); const { theme, systemTheme } = useTheme();
const formatTime = useCallback( const formatTime = useCallback(
@ -130,9 +139,10 @@ export function ThresholdBarGraph({
formatter: (val: number) => Math.ceil(val).toString(), formatter: (val: number) => Math.ceil(val).toString(),
}, },
min: 0, min: 0,
max: yMax,
}, },
} as ApexCharts.ApexOptions; } as ApexCharts.ApexOptions;
}, [graphId, threshold, unit, systemTheme, theme, formatTime]); }, [graphId, threshold, unit, yMax, systemTheme, theme, formatTime]);
useEffect(() => { useEffect(() => {
ApexCharts.exec(graphId, "updateOptions", options, true, true); ApexCharts.exec(graphId, "updateOptions", options, true, true);