From bb1dac3c7201e1a8b3bc7def7fdc355c1830623a Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Fri, 9 Jul 2021 11:33:49 -0500 Subject: [PATCH] Stat: use shared data min/max for y auto-ranging (#36497) --- .../src/components/Sparkline/Sparkline.tsx | 1 + .../src/components/uPlot/config/UPlotScaleBuilder.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx index a8bd93707b0..e639b68747c 100755 --- a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx +++ b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx @@ -143,6 +143,7 @@ export class Sparkline extends PureComponent { direction: ScaleDirection.Up, min: field.config.min, max: field.config.max, + getDataMinMax: () => field.state?.range, }); builder.addAxis({ diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts index 1f7e5aee56b..425cfd5efd4 100644 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts @@ -2,7 +2,7 @@ import uPlot, { Scale, Range } from 'uplot'; import { PlotConfigBuilder } from '../types'; import { ScaleOrientation, ScaleDirection } from '../config'; import { ScaleDistribution } from '../models.gen'; -import { isBooleanUnit } from '@grafana/data'; +import { isBooleanUnit, NumericRange } from '@grafana/data'; export interface ScaleProps { scaleKey: string; @@ -16,6 +16,7 @@ export interface ScaleProps { orientation: ScaleOrientation; direction: ScaleDirection; log?: number; + getDataMinMax?: () => NumericRange | undefined; } export class UPlotScaleBuilder extends PlotConfigBuilder { @@ -62,6 +63,15 @@ export class UPlotScaleBuilder extends PlotConfigBuilder { // uPlot range function const rangeFn = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => { + let { getDataMinMax } = this.props; + + // cumulative data min/max across multiple charts, usually via VizRepeater + if (getDataMinMax) { + let dataRange = getDataMinMax()!; + dataMin = dataRange.min!; + dataMax = dataRange.max!; + } + const scale = u.scales[scaleKey]; let minMax: uPlot.Range.MinMax = [dataMin, dataMax];