diff --git a/packages/grafana-data/src/field/fieldDisplay.test.ts b/packages/grafana-data/src/field/fieldDisplay.test.ts index f66c47bb71b..9043f145ee9 100644 --- a/packages/grafana-data/src/field/fieldDisplay.test.ts +++ b/packages/grafana-data/src/field/fieldDisplay.test.ts @@ -72,9 +72,8 @@ describe('FieldDisplay', () => { expect(display.map((v) => v.display.numeric)).toEqual([1, 3]); // First 2 are from the first field }); - it('should not calculate min max if ensureGlobalRange is false', () => { + it('should not calculate min max automatically', () => { const options = createDisplayOptions({ - ensureGlobalRange: false, reduceOptions: { values: true, // limit: 1000, @@ -86,20 +85,6 @@ describe('FieldDisplay', () => { expect(display[0].field.max).toBeUndefined(); }); - it('should ensure global min / max on numerical fields', () => { - const options = createDisplayOptions({ - ensureGlobalRange: true, - reduceOptions: { - values: true, // - limit: 1000, - calcs: [], - }, - }); - const display = getFieldDisplayValues(options); - expect(display[0].field.min).toEqual(1); - expect(display[0].field.max).toEqual(6); - }); - it('Should return field thresholds when there is no data', () => { const options = createEmptyDisplayOptions({ fieldConfig: { diff --git a/packages/grafana-data/src/field/fieldDisplay.ts b/packages/grafana-data/src/field/fieldDisplay.ts index 1fea8363324..9f0b2bb4e25 100644 --- a/packages/grafana-data/src/field/fieldDisplay.ts +++ b/packages/grafana-data/src/field/fieldDisplay.ts @@ -22,7 +22,6 @@ import { getTimeField } from '../dataframe/processDataFrame'; import { getFieldMatcher } from '../transformations'; import { FieldMatcherID } from '../transformations/matchers/ids'; import { getFieldDisplayName } from './fieldState'; -import { ensureGlobalRangeOnState } from './scale'; /** * Options for how to turn DataFrames into an array of display values @@ -74,7 +73,6 @@ export interface GetFieldDisplayValuesOptions { sparkline?: boolean; // Calculate the sparkline theme: GrafanaTheme2; timeZone?: TimeZone; - ensureGlobalRange?: boolean; } export const DEFAULT_FIELD_DISPLAY_VALUES_LIMIT = 25; @@ -101,10 +99,6 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi let hitLimit = false; - if (options.ensureGlobalRange) { - ensureGlobalRangeOnState(data); - } - for (let s = 0; s < data.length && !hitLimit; s++) { const dataFrame = data[s]; // Name is already set diff --git a/packages/grafana-data/src/field/scale.test.ts b/packages/grafana-data/src/field/scale.test.ts index 45cd98afd03..2e6924ffb8b 100644 --- a/packages/grafana-data/src/field/scale.test.ts +++ b/packages/grafana-data/src/field/scale.test.ts @@ -1,10 +1,9 @@ import { ThresholdsMode, Field, FieldType } from '../types'; import { sortThresholds } from './thresholds'; import { ArrayVector } from '../vector/ArrayVector'; -import { ensureGlobalRangeOnState, getScaleCalculator } from './scale'; +import { getScaleCalculator } from './scale'; import { createTheme } from '../themes'; import { getColorForTheme } from '../utils'; -import { toDataFrame } from '../dataframe'; describe('getScaleCalculator', () => { it('should return percent, threshold and color', () => { @@ -51,26 +50,3 @@ describe('getScaleCalculator', () => { }); }); }); - -describe('ensure global scales', () => { - it('should fill in all numeric values', () => { - const frame = toDataFrame({ - fields: [ - { type: FieldType.number, values: [1, 2, 3] }, - { type: FieldType.number, values: [7, 8, 9] }, - { type: FieldType.string, values: ['a', 'b', 'c'] }, - ], - }); - ensureGlobalRangeOnState([frame]); - - expect(frame.fields[0].state!.range).toMatchInlineSnapshot(` - Object { - "delta": 8, - "max": 9, - "min": 1, - } - `); - - expect(frame.fields[2].state?.range).toBeUndefined(); - }); -}); diff --git a/packages/grafana-data/src/field/scale.ts b/packages/grafana-data/src/field/scale.ts index cf94162c3ca..c30fda912b5 100644 --- a/packages/grafana-data/src/field/scale.ts +++ b/packages/grafana-data/src/field/scale.ts @@ -1,9 +1,8 @@ import { isNumber } from 'lodash'; import { GrafanaTheme2 } from '../themes/types'; import { reduceField, ReducerID } from '../transformations/fieldReducer'; -import { DataFrame, Field, FieldConfig, FieldType, NumericRange, Threshold } from '../types'; +import { Field, FieldConfig, FieldType, NumericRange, Threshold } from '../types'; import { getFieldColorModeForField } from './fieldColor'; -import { findNumericFieldMinMax } from './fieldOverrides'; import { getActiveThresholdForValue } from './thresholds'; export interface ColorScaleValue { @@ -113,41 +112,3 @@ export function getFieldConfigWithMinMax(field: Field, local?: boolean): FieldCo return { ...config, ...field.state.range }; } - -/** - * This will check that each field has a range value stored on state - * If the value is missing, the global range will be calculated and - * saved in the field state. - * - * The same process usually happens in `applyFieldOverrieds`, but - * when the process can be skipped the global range may be missing - * - * @internal - */ -export function ensureGlobalRangeOnState(frames?: DataFrame[]) { - if (!frames) { - return; - } - - let globalRange: NumericRange | undefined = undefined; - for (const frame of frames) { - for (const field of frame.fields) { - if (field.type === FieldType.number) { - if (field.state?.range) { - continue; // already set - } - const { config } = field; - if (!globalRange && (config.min == null || config.max == null)) { - globalRange = findNumericFieldMinMax(frames); - } - - const min = config.min ?? globalRange!.min; - const max = config.max ?? globalRange!.max; - if (!field.state) { - field.state = {}; - } - field.state.range = { min, max, delta: max! - min! }; - } - } - } -} diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index b358650422e..914b6f46fd2 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -98,6 +98,7 @@ export class PanelQueryRunner { // If the shape is the same, we can skip field overrides if ( + data.state === LoadingState.Streaming && processFields && processedCount > 0 && lastData.length && diff --git a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx index 6f203e7b951..2288c95b756 100644 --- a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx +++ b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx @@ -73,7 +73,6 @@ export class BarGaugePanel extends PureComponent> { return getFieldDisplayValues({ fieldConfig, reduceOptions: options.reduceOptions, - ensureGlobalRange: true, replaceVariables, theme: config.theme2, data: data.series, diff --git a/public/app/plugins/panel/gauge/GaugePanel.tsx b/public/app/plugins/panel/gauge/GaugePanel.tsx index 9877756ebab..54a09983a3c 100644 --- a/public/app/plugins/panel/gauge/GaugePanel.tsx +++ b/public/app/plugins/panel/gauge/GaugePanel.tsx @@ -54,7 +54,6 @@ export class GaugePanel extends PureComponent> { const { data, options, replaceVariables, fieldConfig, timeZone } = this.props; return getFieldDisplayValues({ fieldConfig, - ensureGlobalRange: true, reduceOptions: options.reduceOptions, replaceVariables, theme: config.theme2, diff --git a/public/app/plugins/panel/stat/StatPanel.tsx b/public/app/plugins/panel/stat/StatPanel.tsx index c33c563b82d..771a054397a 100644 --- a/public/app/plugins/panel/stat/StatPanel.tsx +++ b/public/app/plugins/panel/stat/StatPanel.tsx @@ -85,7 +85,6 @@ export class StatPanel extends PureComponent> { return getFieldDisplayValues({ fieldConfig, - ensureGlobalRange: true, reduceOptions: options.reduceOptions, replaceVariables, theme: config.theme2,