|
|
|
@ -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! }; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|