mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scale: Fixes handling of NaN percent when data min = data max (#40622)
This commit is contained in:
parent
6ec2c54c5b
commit
c174664e63
@ -1,4 +1,4 @@
|
||||
import { ThresholdsMode, Field, FieldType } from '../types';
|
||||
import { ThresholdsMode, Field, FieldType, FieldColorModeId } from '../types';
|
||||
import { sortThresholds } from './thresholds';
|
||||
import { ArrayVector } from '../vector/ArrayVector';
|
||||
import { getScaleCalculator } from './scale';
|
||||
@ -49,4 +49,18 @@ describe('getScaleCalculator', () => {
|
||||
threshold: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle min = max', () => {
|
||||
const field: Field = {
|
||||
name: 'test',
|
||||
config: { color: { mode: FieldColorModeId.ContinuousGrYlRd } },
|
||||
type: FieldType.number,
|
||||
values: new ArrayVector([1]),
|
||||
};
|
||||
|
||||
const theme = createTheme();
|
||||
const calc = getScaleCalculator(field, theme);
|
||||
|
||||
expect(calc(1).color).toEqual('rgb(115, 191, 105)');
|
||||
});
|
||||
});
|
||||
|
@ -27,6 +27,10 @@ export function getScaleCalculator(field: Field, theme: GrafanaTheme2): ScaleCal
|
||||
|
||||
if (value !== -Infinity) {
|
||||
percent = (value - info.min!) / info.delta;
|
||||
|
||||
if (Number.isNaN(percent)) {
|
||||
percent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const threshold = getActiveThresholdForValue(field, value, percent);
|
||||
|
Loading…
Reference in New Issue
Block a user