mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Gauge: Set min and max for percent unit (#67517)
* Gauge: Set min and max for percent unit * Remove exclamation mark * Add parentheses around ternary
This commit is contained in:
parent
a3b10b2c8d
commit
6570ec7afe
@ -1,6 +1,6 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
|
||||
import { FieldDisplay, getFieldDisplayValues, PanelProps } from '@grafana/data';
|
||||
import { FieldDisplay, getDisplayProcessor, getFieldDisplayValues, PanelProps } from '@grafana/data';
|
||||
import { DataLinksContextMenu, Gauge, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
||||
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
||||
import { config } from 'app/core/config';
|
||||
@ -54,6 +54,19 @@ export class GaugePanel extends PureComponent<PanelProps<PanelOptions>> {
|
||||
|
||||
getValues = (): FieldDisplay[] => {
|
||||
const { data, options, replaceVariables, fieldConfig, timeZone } = this.props;
|
||||
|
||||
for (let frame of data.series) {
|
||||
for (let field of frame.fields) {
|
||||
// Set the Min/Max value automatically for percent and percentunit
|
||||
if (field.config.unit === 'percent' || field.config.unit === 'percentunit') {
|
||||
const min = field.config.min ?? 0;
|
||||
const max = field.config.max ?? (field.config.unit === 'percent' ? 100 : 1);
|
||||
field.state = field.state ?? {};
|
||||
field.state.range = { min, max, delta: max - min };
|
||||
field.display = getDisplayProcessor({ field, theme: config.theme2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
return getFieldDisplayValues({
|
||||
fieldConfig,
|
||||
reduceOptions: options.reduceOptions,
|
||||
|
Loading…
Reference in New Issue
Block a user