mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
FieldDisplay: remove auto min/max for percent units (#34234)
This commit is contained in:
parent
8f50b9abb4
commit
eba6f66fba
@ -150,23 +150,6 @@ export function applyFieldOverrides(options: ApplyFieldOverrideOptions): DataFra
|
||||
}
|
||||
}
|
||||
|
||||
// Some units have an implied range
|
||||
if (config.unit === 'percent') {
|
||||
if (!isNumber(config.min)) {
|
||||
config.min = 0;
|
||||
}
|
||||
if (!isNumber(config.max)) {
|
||||
config.max = 100;
|
||||
}
|
||||
} else if (config.unit === 'percentunit') {
|
||||
if (!isNumber(config.min)) {
|
||||
config.min = 0;
|
||||
}
|
||||
if (!isNumber(config.max)) {
|
||||
config.max = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Min/Max value automatically
|
||||
let range: NumericRange | undefined = undefined;
|
||||
if (field.type === FieldType.number) {
|
||||
|
@ -229,4 +229,22 @@ describe('sharedSingleStatMigrationHandler', () => {
|
||||
expect(panel.fieldConfig.defaults.min).toBe(undefined);
|
||||
expect(panel.fieldConfig.defaults.max).toBe(undefined);
|
||||
});
|
||||
|
||||
it('auto set min/max for percent units before 8.0', () => {
|
||||
const panel = ({
|
||||
options: {
|
||||
fieldOptions: {
|
||||
defaults: {
|
||||
unit: 'percentunit',
|
||||
},
|
||||
},
|
||||
},
|
||||
title: 'Usage',
|
||||
type: 'bargauge',
|
||||
} as unknown) as PanelModel;
|
||||
sharedSingleStatMigrationHandler(panel as any);
|
||||
expect(panel.fieldConfig.defaults.unit).toBe('percentunit');
|
||||
expect(panel.fieldConfig.defaults.min).toBe(0);
|
||||
expect(panel.fieldConfig.defaults.max).toBe(1);
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { cloneDeep, omit } from 'lodash';
|
||||
import { cloneDeep, isNumber, omit } from 'lodash';
|
||||
|
||||
import {
|
||||
fieldReducers,
|
||||
@ -216,6 +216,27 @@ export function sharedSingleStatMigrationHandler(panel: PanelModel<SingleStatBas
|
||||
}
|
||||
}
|
||||
|
||||
if (previousVersion < 8.0) {
|
||||
// Explicit min/max was removed for percent/percentunit in 8.0
|
||||
const config = panel.fieldConfig?.defaults;
|
||||
let unit = config?.unit;
|
||||
if (unit === 'percent') {
|
||||
if (!isNumber(config.min)) {
|
||||
config.min = 0;
|
||||
}
|
||||
if (!isNumber(config.max)) {
|
||||
config.max = 100;
|
||||
}
|
||||
} else if (unit === 'percentunit') {
|
||||
if (!isNumber(config.min)) {
|
||||
config.min = 0;
|
||||
}
|
||||
if (!isNumber(config.max)) {
|
||||
config.max = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options as SingleStatBaseOptions;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user