mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Stat: use shared data min/max for y auto-ranging (#36497)
This commit is contained in:
parent
9ce6e2a664
commit
bb1dac3c72
@ -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…
Reference in New Issue
Block a user