diff --git a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts index 144f9ddb7d8..f56b3f4d777 100644 --- a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts +++ b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts @@ -112,6 +112,22 @@ describe('nullInsertThreshold Transformer', () => { expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 10, 11]); expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, 8, null]); expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, 'c', null]); + + // should work for frames with 1 datapoint + const df2 = new MutableDataFrame({ + refId: 'A', + fields: [ + { name: 'Time', type: FieldType.time, config: { interval: 1 }, values: [1] }, + { name: 'One', type: FieldType.number, values: [1] }, + { name: 'Two', type: FieldType.string, values: ['a'] }, + ], + }); + + const result2 = applyNullInsertThreshold(df2, null, 13); + + expect(result2.fields[0].values.toArray()).toStrictEqual([1, 2]); + expect(result2.fields[1].values.toArray()).toStrictEqual([1, null]); + expect(result2.fields[2].values.toArray()).toStrictEqual(['a', null]); }); // TODO: make this work @@ -132,12 +148,12 @@ describe('nullInsertThreshold Transformer', () => { expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, 'c']); }); - test('should noop on fewer than two values', () => { + test('should noop on 0 datapoints', () => { const df = new MutableDataFrame({ refId: 'A', fields: [ - { name: 'Time', type: FieldType.time, config: { interval: 1 }, values: [1] }, - { name: 'Value', type: FieldType.number, values: [1] }, + { name: 'Time', type: FieldType.time, config: { interval: 1 }, values: [] }, + { name: 'Value', type: FieldType.number, values: [] }, ], }); diff --git a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts index 35b0fcd325f..c46b6cf6af0 100644 --- a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts +++ b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts @@ -15,7 +15,7 @@ export function applyNullInsertThreshold( refFieldPseudoMax: number | null = null, insertMode: InsertMode = INSERT_MODES.threshold ): DataFrame { - if (frame.length < 2) { + if (frame.length === 0) { return frame; }