mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
GraphNG: don't scan data for min/max when both hard limits are pre-configured (#33295)
This commit is contained in:
parent
5e818146de
commit
948cba199b
@ -281,6 +281,33 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('disables autoscaling when both (and only) hardMin and hardMax are specified', () => {
|
||||||
|
const builder = new UPlotConfigBuilder();
|
||||||
|
|
||||||
|
builder.addScale({
|
||||||
|
isTime: false,
|
||||||
|
scaleKey: 'scale-y',
|
||||||
|
orientation: ScaleOrientation.Vertical,
|
||||||
|
direction: ScaleDirection.Up,
|
||||||
|
min: -100,
|
||||||
|
max: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(builder.getConfig().scales!['scale-y']!.auto).toEqual(false);
|
||||||
|
|
||||||
|
builder.addScale({
|
||||||
|
isTime: false,
|
||||||
|
scaleKey: 'scale-y2',
|
||||||
|
orientation: ScaleOrientation.Vertical,
|
||||||
|
direction: ScaleDirection.Up,
|
||||||
|
min: -100,
|
||||||
|
max: 100,
|
||||||
|
softMin: -50,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(builder.getConfig().scales!['scale-y2']!.auto).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('allows axes configuration', () => {
|
it('allows axes configuration', () => {
|
||||||
const builder = new UPlotConfigBuilder();
|
const builder = new UPlotConfigBuilder();
|
||||||
|
|
||||||
|
@ -65,15 +65,15 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let hardMinOnly = softMin == null && hardMin != null;
|
||||||
|
let hardMaxOnly = softMax == null && hardMax != null;
|
||||||
|
|
||||||
// uPlot range function
|
// uPlot range function
|
||||||
const rangeFn = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => {
|
const rangeFn = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => {
|
||||||
const scale = u.scales[scaleKey];
|
const scale = u.scales[scaleKey];
|
||||||
|
|
||||||
let minMax = [dataMin, dataMax];
|
let minMax = [dataMin, dataMax];
|
||||||
|
|
||||||
let hardMinOnly = softMin == null && hardMin != null;
|
|
||||||
let hardMaxOnly = softMax == null && hardMax != null;
|
|
||||||
|
|
||||||
if (scale.distr === 1 || scale.distr === 2) {
|
if (scale.distr === 1 || scale.distr === 2) {
|
||||||
// @ts-ignore here we may use hardMin / hardMax to make sure any extra padding is computed from a more accurate delta
|
// @ts-ignore here we may use hardMin / hardMax to make sure any extra padding is computed from a more accurate delta
|
||||||
minMax = uPlot.rangeNum(hardMinOnly ? hardMin : dataMin, hardMaxOnly ? hardMax : dataMax, rangeConfig);
|
minMax = uPlot.rangeNum(hardMinOnly ? hardMin : dataMin, hardMaxOnly ? hardMax : dataMax, rangeConfig);
|
||||||
@ -96,7 +96,7 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
|||||||
return {
|
return {
|
||||||
[scaleKey]: {
|
[scaleKey]: {
|
||||||
time: isTime,
|
time: isTime,
|
||||||
auto: !isTime,
|
auto: !isTime && !(hardMinOnly && hardMaxOnly),
|
||||||
range: range ?? rangeFn,
|
range: range ?? rangeFn,
|
||||||
dir: direction,
|
dir: direction,
|
||||||
ori: orientation,
|
ori: orientation,
|
||||||
|
Loading…
Reference in New Issue
Block a user