StatPanel: Fixes BizChart error max: yyy should not be less than min zzz (#28587)

This commit is contained in:
Hugo Häggmark 2020-10-28 08:04:30 +01:00 committed by GitHub
parent 5cded1d2cd
commit 0d803613d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 6 deletions

View File

@ -11,14 +11,14 @@ import { MutableDataFrame, toDataFrame } from '../dataframe';
import {
DataFrame,
Field,
FieldColorModeId,
FieldConfig,
FieldConfigPropertyItem,
FieldConfigSource,
FieldType,
InterpolateFunction,
ThresholdsMode,
FieldColorModeId,
ScopedVars,
ThresholdsMode,
} from '../types';
import { locationUtil, Registry } from '../utils';
import { mockStandardProperties } from '../utils/tests/mockStandardProperties';
@ -87,6 +87,21 @@ describe('Global MinMax', () => {
expect(minmax.min).toEqual(-20);
expect(minmax.max).toEqual(1234);
});
describe('when value is null', () => {
it('then global min max should be null', () => {
const frame = toDataFrame({
fields: [
{ name: 'Time', type: FieldType.time, values: [1] },
{ name: 'Value', type: FieldType.number, values: [null] },
],
});
const { min, max } = findNumericFieldMinMax([frame]);
expect(min).toBeNull();
expect(max).toBeNull();
});
});
});
describe('applyFieldOverrides', () => {

View File

@ -55,11 +55,23 @@ export function findNumericFieldMinMax(data: DataFrame[]): GlobalMinMax {
for (const field of frame.fields) {
if (field.type === FieldType.number) {
const stats = reduceField({ field, reducers });
if (stats[ReducerID.min] < min) {
min = stats[ReducerID.min];
const statsMin = stats[ReducerID.min];
const statsMax = stats[ReducerID.max];
if (!statsMin) {
min = statsMin;
}
if (stats[ReducerID.max] > max) {
max = stats[ReducerID.max];
if (!statsMax) {
max = statsMax;
}
if (statsMin && statsMin < min) {
min = statsMin;
}
if (statsMax && statsMax > max) {
max = statsMax;
}
}
}