GraphNG: don't scan data for min/max when both hard limits are pre-configured (#33295)

This commit is contained in:
Leon Sorokin 2021-04-23 11:35:28 -05:00 committed by GitHub
parent 5e818146de
commit 948cba199b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -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', () => {
const builder = new UPlotConfigBuilder();

View File

@ -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
const rangeFn = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => {
const scale = u.scales[scaleKey];
let minMax = [dataMin, dataMax];
let hardMinOnly = softMin == null && hardMin != null;
let hardMaxOnly = softMax == null && hardMax != null;
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
minMax = uPlot.rangeNum(hardMinOnly ? hardMin : dataMin, hardMaxOnly ? hardMax : dataMax, rangeConfig);
@ -96,7 +96,7 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
return {
[scaleKey]: {
time: isTime,
auto: !isTime,
auto: !isTime && !(hardMinOnly && hardMaxOnly),
range: range ?? rangeFn,
dir: direction,
ori: orientation,