Commit 145901c0 by Torkel Ödegaard Committed by GitHub

Thresholds: Fixes color assigned to null values (#29010)

* Thresholds: Fixes color assigned to null values

* Updates
parent ab078133
...@@ -16,9 +16,8 @@ function getDisplayProcessorFromConfig(config: FieldConfig) { ...@@ -16,9 +16,8 @@ function getDisplayProcessorFromConfig(config: FieldConfig) {
function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) { function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) {
processors.forEach(processor => { processors.forEach(processor => {
const value = processor(input); const value = processor(input);
expect(value.text).toEqual(match.text); for (const key of Object.keys(match)) {
if (match.hasOwnProperty('numeric')) { expect((value as any)[key]).toEqual((match as any)[key]);
expect(value.numeric).toEqual(match.numeric);
} }
}); });
} }
...@@ -89,6 +88,27 @@ describe('Process simple display values', () => { ...@@ -89,6 +88,27 @@ describe('Process simple display values', () => {
}); });
}); });
describe('Process null values', () => {
const processors = [
getDisplayProcessorFromConfig({
min: 0,
max: 100,
thresholds: {
mode: ThresholdsMode.Absolute,
steps: [
{ value: -Infinity, color: '#000' },
{ value: 0, color: '#100' },
{ value: 100, color: '#200' },
],
},
}),
];
it('Null should get -Infinity (base) color', () => {
assertSame(null, processors, { text: '', numeric: NaN, color: '#000' });
});
});
describe('Format value', () => { describe('Format value', () => {
it('should return if value isNaN', () => { it('should return if value isNaN', () => {
const valueMappings: ValueMapping[] = []; const valueMappings: ValueMapping[] = [];
......
...@@ -115,7 +115,7 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP ...@@ -115,7 +115,7 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
} }
} }
return { text, numeric, prefix, suffix, ...scaleFunc(0) }; return { text, numeric, prefix, suffix, ...scaleFunc(-Infinity) };
}; };
} }
......
...@@ -18,7 +18,12 @@ export function getScaleCalculator(field: Field, theme: GrafanaTheme): ScaleCalc ...@@ -18,7 +18,12 @@ export function getScaleCalculator(field: Field, theme: GrafanaTheme): ScaleCalc
const info = getMinMaxAndDelta(field); const info = getMinMaxAndDelta(field);
return (value: number) => { return (value: number) => {
const percent = (value - info.min!) / info.delta; let percent = 0;
if (value !== -Infinity) {
percent = (value - info.min!) / info.delta;
}
const threshold = getActiveThresholdForValue(field, value, percent); const threshold = getActiveThresholdForValue(field, value, percent);
return { return {
......
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