Scale: Fixes handling of NaN percent when data min = data max (#40622)

pull/40622/merge
Torkel Ödegaard 4 years ago committed by GitHub
parent 6ec2c54c5b
commit c174664e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      packages/grafana-data/src/field/scale.test.ts
  2. 4
      packages/grafana-data/src/field/scale.ts

@ -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…
Cancel
Save