Commit 10f226c4 by Torkel Ödegaard Committed by GitHub

StatPanels: Fixes auto min max when latest value is zero (#28982)

parent b5379c53
......@@ -98,8 +98,30 @@ describe('Global MinMax', () => {
});
const { min, max } = findNumericFieldMinMax([frame]);
expect(min).toBeNull();
expect(max).toBeNull();
expect(min).toBe(Number.MIN_VALUE);
expect(max).toBe(Number.MAX_VALUE);
});
});
describe('when value values are zeo', () => {
it('then global min max should be correct', () => {
const frame = toDataFrame({
fields: [
{ name: 'Time', type: FieldType.time, values: [1, 2] },
{ name: 'Value', type: FieldType.number, values: [1, 2] },
],
});
const frame2 = toDataFrame({
fields: [
{ name: 'Time', type: FieldType.time, values: [1, 2] },
{ name: 'Value', type: FieldType.number, values: [0, 0] },
],
});
const { min, max } = findNumericFieldMinMax([frame, frame2]);
expect(min).toBe(0);
expect(max).toBe(2);
});
});
});
......
......@@ -58,25 +58,25 @@ export function findNumericFieldMinMax(data: DataFrame[]): GlobalMinMax {
const statsMin = stats[ReducerID.min];
const statsMax = stats[ReducerID.max];
if (!statsMin) {
if (statsMin !== undefined && statsMin !== null && statsMin < min) {
min = statsMin;
}
if (!statsMax) {
max = statsMax;
}
if (statsMin && statsMin < min) {
min = statsMin;
}
if (statsMax && statsMax > max) {
if (statsMax !== undefined && statsMax !== null && statsMax > max) {
max = statsMax;
}
}
}
}
if (min === Number.MAX_VALUE) {
min = Number.MIN_VALUE;
}
if (max === Number.MIN_VALUE) {
max = Number.MAX_VALUE;
}
return { min, max };
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment