mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
StatPanels: Fixes auto min max when latest value is zero (#28982)
This commit is contained in:
parent
b5379c5335
commit
10f226c4c2
@ -98,8 +98,30 @@ describe('Global MinMax', () => {
|
|||||||
});
|
});
|
||||||
const { min, max } = findNumericFieldMinMax([frame]);
|
const { min, max } = findNumericFieldMinMax([frame]);
|
||||||
|
|
||||||
expect(min).toBeNull();
|
expect(min).toBe(Number.MIN_VALUE);
|
||||||
expect(max).toBeNull();
|
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 statsMin = stats[ReducerID.min];
|
||||||
const statsMax = stats[ReducerID.max];
|
const statsMax = stats[ReducerID.max];
|
||||||
|
|
||||||
if (!statsMin) {
|
if (statsMin !== undefined && statsMin !== null && statsMin < min) {
|
||||||
min = statsMin;
|
min = statsMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!statsMax) {
|
if (statsMax !== undefined && statsMax !== null && statsMax > max) {
|
||||||
max = statsMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statsMin && statsMin < min) {
|
|
||||||
min = statsMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statsMax && statsMax > max) {
|
|
||||||
max = statsMax;
|
max = statsMax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (min === Number.MAX_VALUE) {
|
||||||
|
min = Number.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max === Number.MIN_VALUE) {
|
||||||
|
max = Number.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
return { min, max };
|
return { min, max };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user