diff --git a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts index 2888434cf9d..210233a89b9 100644 --- a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts +++ b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.test.ts @@ -59,9 +59,9 @@ describe('nullInsertThreshold Transformer', () => { const result = applyNullInsertThreshold(df); - expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 10]); - expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, 8]); - expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, 'c']); + expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, null, null, null, null, null, 8]); + expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, null, null, null, null, null, 'c']); }); test('should insert nulls at +threshold between adjacent > threshold: 2', () => { @@ -93,9 +93,9 @@ describe('nullInsertThreshold Transformer', () => { const result = applyNullInsertThreshold(df); - expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 10]); - expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, 8]); - expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, 'c']); + expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, null, null, null, null, null, 8]); + expect(result.fields[2].values.toArray()).toStrictEqual(['a', null, 'b', null, null, null, null, null, null, 'c']); }); test('should insert trailing null at end +interval when timeRange.to.valueOf() exceeds threshold', () => { @@ -110,9 +110,21 @@ describe('nullInsertThreshold Transformer', () => { const result = applyNullInsertThreshold(df, null, 13); - 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]); + expect(result.fields[0].values.toArray()).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); + expect(result.fields[1].values.toArray()).toStrictEqual([4, null, 6, null, null, null, null, null, null, 8, null]); + expect(result.fields[2].values.toArray()).toStrictEqual([ + 'a', + null, + 'b', + null, + null, + null, + null, + null, + null, + 'c', + null, + ]); // should work for frames with 1 datapoint const df2 = new MutableDataFrame({ diff --git a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts index c46b6cf6af0..6c61426f930 100644 --- a/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts +++ b/packages/grafana-ui/src/components/GraphNG/nullInsertThreshold.ts @@ -13,7 +13,8 @@ export function applyNullInsertThreshold( frame: DataFrame, refFieldName?: string | null, refFieldPseudoMax: number | null = null, - insertMode: InsertMode = INSERT_MODES.threshold + insertMode: InsertMode = INSERT_MODES.threshold, + thorough = true ): DataFrame { if (frame.length === 0) { return frame; @@ -49,7 +50,14 @@ export function applyNullInsertThreshold( const frameValues = frame.fields.map((field) => field.values.toArray()); - const filledFieldValues = nullInsertThreshold(refValues, frameValues, threshold, refFieldPseudoMax, insertMode); + const filledFieldValues = nullInsertThreshold( + refValues, + frameValues, + threshold, + refFieldPseudoMax, + insertMode, + thorough + ); if (filledFieldValues === frameValues) { return frame; @@ -77,7 +85,9 @@ function nullInsertThreshold( threshold: number, // will insert a trailing null when refFieldPseudoMax > last datapoint + threshold refFieldPseudoMax: number | null = null, - getInsertValue: InsertMode + getInsertValue: InsertMode, + // will insert the value at every missing interval + thorough: boolean ) { const len = refValues.length; let prevValue: number = refValues[0]; @@ -86,8 +96,14 @@ function nullInsertThreshold( for (let i = 1; i < len; i++) { const curValue = refValues[i]; - if (curValue - prevValue > threshold) { + while (curValue - prevValue > threshold) { refValuesNew.push(getInsertValue(prevValue, curValue, threshold)); + + prevValue += threshold; + + if (!thorough) { + break; + } } refValuesNew.push(curValue);