Commit 2afd3cf5 by Torkel Ödegaard Committed by GitHub

Merge pull request #15499 from grafana/hugoh/bug-thresholds-and-infinity

Fixes #15477
parents 730515d8 92972eed
...@@ -10,6 +10,20 @@ describe('PanelModel', () => { ...@@ -10,6 +10,20 @@ describe('PanelModel', () => {
type: 'table', type: 'table',
showColumns: true, showColumns: true,
targets: [{ refId: 'A' }, { noRefId: true }], targets: [{ refId: 'A' }, { noRefId: true }],
options: {
thresholds: [
{
color: '#F2495C',
index: 1,
value: 50,
},
{
color: '#73BF69',
index: 0,
value: null,
},
],
},
}); });
}); });
...@@ -35,6 +49,21 @@ describe('PanelModel', () => { ...@@ -35,6 +49,21 @@ describe('PanelModel', () => {
expect(saveModel.events).toBe(undefined); expect(saveModel.events).toBe(undefined);
}); });
it('should restore -Infinity value for base threshold', () => {
expect(model.options.thresholds).toEqual([
{
color: '#F2495C',
index: 1,
value: 50,
},
{
color: '#73BF69',
index: 0,
value: -Infinity,
},
]);
});
describe('when changing panel type', () => { describe('when changing panel type', () => {
beforeEach(() => { beforeEach(() => {
model.changeType('graph', true); model.changeType('graph', true);
......
...@@ -3,7 +3,7 @@ import _ from 'lodash'; ...@@ -3,7 +3,7 @@ import _ from 'lodash';
// Types // Types
import { Emitter } from 'app/core/utils/emitter'; import { Emitter } from 'app/core/utils/emitter';
import { DataQuery, TimeSeries } from '@grafana/ui'; import { DataQuery, TimeSeries, Threshold } from '@grafana/ui';
import { TableData } from '@grafana/ui/src'; import { TableData } from '@grafana/ui/src';
export interface GridPos { export interface GridPos {
...@@ -89,7 +89,9 @@ export class PanelModel { ...@@ -89,7 +89,9 @@ export class PanelModel {
timeFrom?: any; timeFrom?: any;
timeShift?: any; timeShift?: any;
hideTimeOverride?: any; hideTimeOverride?: any;
options: object; options: {
[key: string]: any;
};
maxDataPoints?: number; maxDataPoints?: number;
interval?: string; interval?: string;
...@@ -117,6 +119,8 @@ export class PanelModel { ...@@ -117,6 +119,8 @@ export class PanelModel {
_.defaultsDeep(this, _.cloneDeep(defaults)); _.defaultsDeep(this, _.cloneDeep(defaults));
// queries must have refId // queries must have refId
this.ensureQueryIds(); this.ensureQueryIds();
this.restoreInfintyForThresholds();
} }
ensureQueryIds() { ensureQueryIds() {
...@@ -129,6 +133,19 @@ export class PanelModel { ...@@ -129,6 +133,19 @@ export class PanelModel {
} }
} }
restoreInfintyForThresholds() {
if (this.options && this.options.thresholds) {
this.options.thresholds = this.options.thresholds.map((threshold: Threshold) => {
// JSON serialization of -Infinity is 'null' so lets convert it back to -Infinity
if (threshold.index === 0 && threshold.value === null) {
return { ...threshold, value: -Infinity };
}
return threshold;
});
}
}
getOptions(panelDefaults) { getOptions(panelDefaults) {
return _.defaultsDeep(this.options || {}, panelDefaults); return _.defaultsDeep(this.options || {}, panelDefaults);
} }
......
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