Commit 01a4951d by Torkel Ödegaard Committed by GitHub

StatPanel: Fixes hanging issue when all values are zero (#29077)

* StatPanel: Fixes hanging issue when all values are zero

* Minor tweak
parent eba046d3
......@@ -88,6 +88,17 @@ describe('Global MinMax', () => {
expect(minmax.max).toEqual(1234);
});
it('find global min max when all values are zero', () => {
const f0 = new ArrayDataFrame<{ title: string; value: number; value2: number | null }>([
{ title: 'AAA', value: 0, value2: 0 },
{ title: 'CCC', value: 0, value2: 0 },
]);
const minmax = findNumericFieldMinMax([f0]);
expect(minmax.min).toEqual(0);
expect(minmax.max).toEqual(0);
});
describe('when value is null', () => {
it('then global min max should be null', () => {
const frame = toDataFrame({
......@@ -98,8 +109,8 @@ describe('Global MinMax', () => {
});
const { min, max } = findNumericFieldMinMax([frame]);
expect(min).toBe(Number.MIN_VALUE);
expect(max).toBe(Number.MAX_VALUE);
expect(min).toBe(null);
expect(max).toBe(null);
});
});
......
......@@ -41,13 +41,13 @@ interface OverrideProps {
}
interface GlobalMinMax {
min: number;
max: number;
min?: number | null;
max?: number | null;
}
export function findNumericFieldMinMax(data: DataFrame[]): GlobalMinMax {
let min = Number.MAX_VALUE;
let max = Number.MIN_VALUE;
let min: number | null = null;
let max: number | null = null;
const reducers = [ReducerID.min, ReducerID.max];
......@@ -58,25 +58,17 @@ export function findNumericFieldMinMax(data: DataFrame[]): GlobalMinMax {
const statsMin = stats[ReducerID.min];
const statsMax = stats[ReducerID.max];
if (statsMin !== undefined && statsMin !== null && statsMin < min) {
if (min === null || statsMin < min) {
min = statsMin;
}
if (statsMax !== undefined && statsMax !== null && statsMax > max) {
if (max === 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