mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
Scale: Fixes handling of NaN percent when data min = data max (#40622)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user