diff --git a/resources/scripts/components/server/console/AreaChart.tsx b/resources/scripts/components/server/console/AreaChart.tsx index e59dd8a8b..892690368 100644 --- a/resources/scripts/components/server/console/AreaChart.tsx +++ b/resources/scripts/components/server/console/AreaChart.tsx @@ -26,7 +26,7 @@ interface Props { height?: number; } -type YDomain = [number, number | 'auto']; +type YDomain = [number, (dataMax: number) => number] | [number, string]; interface RechartsAreaChartContentProps { data: ChartPoint[]; @@ -68,6 +68,7 @@ const LazyRechartsAreaChart = lazy(async () => { // The newest sample's arrival time is the moment the visible window ends at `anchor - RIGHT_LAG_MS`. const anchor = data.at(-1)?.t; const right = (anchor ?? 0) - RIGHT_LAG_MS; + const xDomain = useMemo<[number, number]>(() => [right - windowMs, right + SLIDE_MS], [right, windowMs]); useLayoutEffect(() => { if (!slider.current || anchor === undefined) { @@ -93,6 +94,7 @@ const LazyRechartsAreaChart = lazy(async () => {
+ { fontWeight: 'var(--font-weight-normal)', }} /> + {/* Undrawn copies of the series: the axis only ticks for plotted data, and + matching inputs give it the same scale as the sliding layer. */} + {series.map(({ dataKey }) => ( + + ))}
{ ))} - + {series.map(({ dataKey, color }) => ( (null); const width = useElementWidth(container); - // Both layers share one domain so the static axis lines up with the sliding series. - const yDomain = useMemo(() => { - let max = suggestedMax ?? 0; - - for (const point of data) { - for (const { dataKey } of series) { - max = Math.max(max, point[dataKey] ?? 0); - } - } - - return [0, max > 0 ? max : 'auto']; - }, [data, series, suggestedMax]); + const yDomain = useMemo( + () => (suggestedMax === undefined ? [0, 'auto'] : [0, (dataMax: number) => Math.max(suggestedMax, dataMax)]), + [suggestedMax] + ); return (