Stat: use shared data min/max for y auto-ranging (#36497)

pull/36620/head
Leon Sorokin 4 years ago committed by GitHub
parent 9ce6e2a664
commit bb1dac3c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/grafana-ui/src/components/Sparkline/Sparkline.tsx
  2. 12
      packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts

@ -143,6 +143,7 @@ export class Sparkline extends PureComponent<SparklineProps, State> {
direction: ScaleDirection.Up,
min: field.config.min,
max: field.config.max,
getDataMinMax: () => field.state?.range,
});
builder.addAxis({

@ -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<ScaleProps, Scale> {
@ -62,6 +63,15 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
// 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];

Loading…
Cancel
Save