mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
BarGauge: Show empty bar when value, minValue and maxValue are all equal (#53314)
* prevent returning NaN from getValuePercent * return 0 instead of NaN always
This commit is contained in:
parent
42f9a6e67b
commit
2fea3f0d9a
@ -159,6 +159,10 @@ describe('BarGauge', () => {
|
||||
it('-30 to 30 and value 30', () => {
|
||||
expect(getValuePercent(30, -30, 30)).toEqual(1);
|
||||
});
|
||||
|
||||
it('returns 0 if the min, max and value are all the same value', () => {
|
||||
expect(getValuePercent(25, 25, 25)).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Vertical bar', () => {
|
||||
|
@ -430,7 +430,9 @@ export function getCellColor(
|
||||
}
|
||||
|
||||
export function getValuePercent(value: number, minValue: number, maxValue: number): number {
|
||||
return Math.min((value - minValue) / (maxValue - minValue), 1);
|
||||
// Need special logic for when minValue === maxValue === value to prevent returning NaN
|
||||
const valueRatio = Math.min((value - minValue) / (maxValue - minValue), 1);
|
||||
return isNaN(valueRatio) ? 0 : valueRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user