mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Stat: recompute shared y range during streaming updates (#39485)
This commit is contained in:
parent
8180121495
commit
d3815a851c
@ -10,14 +10,18 @@ import {
|
|||||||
import {
|
import {
|
||||||
DisplayValueAlignmentFactors,
|
DisplayValueAlignmentFactors,
|
||||||
FieldDisplay,
|
FieldDisplay,
|
||||||
|
FieldType,
|
||||||
getDisplayValueAlignmentFactors,
|
getDisplayValueAlignmentFactors,
|
||||||
getFieldDisplayValues,
|
getFieldDisplayValues,
|
||||||
|
NumericRange,
|
||||||
PanelProps,
|
PanelProps,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
import { StatPanelOptions } from './types';
|
import { StatPanelOptions } from './types';
|
||||||
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
||||||
|
import { findNumericFieldMinMax } from '@grafana/data/src/field/fieldOverrides';
|
||||||
|
import { isNumber } from 'lodash';
|
||||||
|
|
||||||
export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
|
export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
|
||||||
renderComponent = (
|
renderComponent = (
|
||||||
@ -83,6 +87,28 @@ export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
|
|||||||
getValues = (): FieldDisplay[] => {
|
getValues = (): FieldDisplay[] => {
|
||||||
const { data, options, replaceVariables, fieldConfig, timeZone } = this.props;
|
const { data, options, replaceVariables, fieldConfig, timeZone } = this.props;
|
||||||
|
|
||||||
|
let globalRange: NumericRange | undefined = undefined;
|
||||||
|
|
||||||
|
for (let frame of data.series) {
|
||||||
|
for (let field of frame.fields) {
|
||||||
|
let { config } = field;
|
||||||
|
// mostly copied from fieldOverrides, since they are skipped during streaming
|
||||||
|
// Set the Min/Max value automatically
|
||||||
|
if (field.type === FieldType.number) {
|
||||||
|
if (field.state?.range) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!globalRange && (!isNumber(config.min) || !isNumber(config.max))) {
|
||||||
|
globalRange = findNumericFieldMinMax(data.series);
|
||||||
|
}
|
||||||
|
const min = config.min ?? globalRange!.min;
|
||||||
|
const max = config.max ?? globalRange!.max;
|
||||||
|
field.state = field.state ?? {};
|
||||||
|
field.state.range = { min, max, delta: max! - min! };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return getFieldDisplayValues({
|
return getFieldDisplayValues({
|
||||||
fieldConfig,
|
fieldConfig,
|
||||||
reduceOptions: options.reduceOptions,
|
reduceOptions: options.reduceOptions,
|
||||||
|
Loading…
Reference in New Issue
Block a user