浏览代码

Moved gauge value options into a sub oject and made editor more generic, will be moved out of gauge pane later and shared between singlestat, gauge, bargauge, honecomb

Torkel Ödegaard 6 年之前
父节点
当前提交
43e0ad3f93

+ 12 - 0
public/app/features/dashboard/state/DashboardMigrator.ts

@@ -392,6 +392,18 @@ export class DashboardMigrator {
       panelUpgrades.push(panel => {
       panelUpgrades.push(panel => {
         if (panel['options-gauge']) {
         if (panel['options-gauge']) {
           panel.options = panel['options-gauge'];
           panel.options = panel['options-gauge'];
+          panel.options.valueOptions = {
+            unit: panel.options.unit,
+            stat: panel.options.stat,
+            decimals: panel.options.decimals,
+            prefix: panel.options.prefix,
+            suffix: panel.options.suffix,
+          };
+          delete panel.options.unit;
+          delete panel.options.stat;
+          delete panel.options.decimals;
+          delete panel.options.prefix;
+          delete panel.options.suffix;
           delete panel['options-gauge'];
           delete panel['options-gauge'];
         }
         }
       });
       });

+ 8 - 4
public/app/plugins/panel/gauge/GaugePanel.tsx

@@ -16,9 +16,10 @@ interface Props extends PanelProps<GaugeOptions> {}
 export class GaugePanel extends PureComponent<Props> {
 export class GaugePanel extends PureComponent<Props> {
   render() {
   render() {
     const { panelData, width, height, onInterpolate, options } = this.props;
     const { panelData, width, height, onInterpolate, options } = this.props;
+    const { valueOptions } = options;
 
 
-    const prefix = onInterpolate(options.prefix);
-    const suffix = onInterpolate(options.suffix);
+    const prefix = onInterpolate(valueOptions.prefix);
+    const suffix = onInterpolate(valueOptions.suffix);
     let value: TimeSeriesValue;
     let value: TimeSeriesValue;
 
 
     if (panelData.timeSeries) {
     if (panelData.timeSeries) {
@@ -28,7 +29,7 @@ export class GaugePanel extends PureComponent<Props> {
       });
       });
 
 
       if (vmSeries[0]) {
       if (vmSeries[0]) {
-        value = vmSeries[0].stats[options.stat];
+        value = vmSeries[0].stats[valueOptions.stat];
       } else {
       } else {
         value = null;
         value = null;
       }
       }
@@ -41,11 +42,14 @@ export class GaugePanel extends PureComponent<Props> {
         {theme => (
         {theme => (
           <Gauge
           <Gauge
             value={value}
             value={value}
-            {...this.props.options}
             width={width}
             width={width}
             height={height}
             height={height}
             prefix={prefix}
             prefix={prefix}
             suffix={suffix}
             suffix={suffix}
+            unit={valueOptions.unit}
+            decimals={valueOptions.decimals}
+            thresholds={options.thresholds}
+            valueMappings={options.valueMappings}
             theme={theme}
             theme={theme}
           />
           />
         )}
         )}

+ 9 - 3
public/app/plugins/panel/gauge/GaugePanelEditor.tsx

@@ -8,9 +8,9 @@ import {
   ValueMapping,
   ValueMapping,
 } from '@grafana/ui';
 } from '@grafana/ui';
 
 
-import { ValueOptions } from 'app/plugins/panel/gauge/ValueOptions';
+import { SingleStatValueEditor } from 'app/plugins/panel/gauge/SingleStatValueEditor';
 import { GaugeOptionsBox } from './GaugeOptionsBox';
 import { GaugeOptionsBox } from './GaugeOptionsBox';
-import { GaugeOptions } from './types';
+import { GaugeOptions, SingleStatValueOptions } from './types';
 
 
 export class GaugePanelEditor extends PureComponent<PanelEditorProps<GaugeOptions>> {
 export class GaugePanelEditor extends PureComponent<PanelEditorProps<GaugeOptions>> {
   onThresholdsChanged = (thresholds: Threshold[]) =>
   onThresholdsChanged = (thresholds: Threshold[]) =>
@@ -25,13 +25,19 @@ export class GaugePanelEditor extends PureComponent<PanelEditorProps<GaugeOption
       valueMappings,
       valueMappings,
     });
     });
 
 
+  onValueOptionsChanged = (valueOptions: SingleStatValueOptions) =>
+    this.props.onChange({
+      ...this.props.options,
+      valueOptions,
+    });
+
   render() {
   render() {
     const { onChange, options } = this.props;
     const { onChange, options } = this.props;
 
 
     return (
     return (
       <>
       <>
         <PanelOptionsGrid>
         <PanelOptionsGrid>
-          <ValueOptions onChange={onChange} options={options} />
+          <SingleStatValueEditor onChange={this.onValueOptionsChanged} options={options.valueOptions} />
           <GaugeOptionsBox onChange={onChange} options={options} />
           <GaugeOptionsBox onChange={onChange} options={options} />
           <ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={options.thresholds} />
           <ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={options.thresholds} />
         </PanelOptionsGrid>
         </PanelOptionsGrid>

+ 7 - 5
public/app/plugins/panel/gauge/ValueOptions.tsx → public/app/plugins/panel/gauge/SingleStatValueEditor.tsx

@@ -6,8 +6,7 @@ import UnitPicker from 'app/core/components/Select/UnitPicker';
 import { FormField, FormLabel, PanelOptionsGroup, Select } from '@grafana/ui';
 import { FormField, FormLabel, PanelOptionsGroup, Select } from '@grafana/ui';
 
 
 // Types
 // Types
-import { GaugeOptions } from './types';
-import { PanelEditorProps } from '@grafana/ui';
+import { SingleStatValueOptions } from './types';
 
 
 const statOptions = [
 const statOptions = [
   { value: 'min', label: 'Min' },
   { value: 'min', label: 'Min' },
@@ -25,9 +24,13 @@ const statOptions = [
 
 
 const labelWidth = 6;
 const labelWidth = 6;
 
 
-export class ValueOptions extends PureComponent<PanelEditorProps<GaugeOptions>> {
-  onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value });
+export interface Props {
+  options: SingleStatValueOptions;
+  onChange: (valueOptions: SingleStatValueOptions) => void;
+}
 
 
+export class SingleStatValueEditor extends PureComponent<Props> {
+  onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value });
   onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value });
   onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value });
 
 
   onDecimalChange = event => {
   onDecimalChange = event => {
@@ -37,7 +40,6 @@ export class ValueOptions extends PureComponent<PanelEditorProps<GaugeOptions>>
   };
   };
 
 
   onPrefixChange = event => this.props.onChange({ ...this.props.options, prefix: event.target.value });
   onPrefixChange = event => this.props.onChange({ ...this.props.options, prefix: event.target.value });
-
   onSuffixChange = event => this.props.onChange({ ...this.props.options, suffix: event.target.value });
   onSuffixChange = event => this.props.onChange({ ...this.props.options, suffix: event.target.value });
 
 
   render() {
   render() {

+ 15 - 9
public/app/plugins/panel/gauge/types.ts

@@ -1,29 +1,35 @@
 import { Threshold, ValueMapping } from '@grafana/ui';
 import { Threshold, ValueMapping } from '@grafana/ui';
 
 
 export interface GaugeOptions {
 export interface GaugeOptions {
-  decimals: number;
   valueMappings: ValueMapping[];
   valueMappings: ValueMapping[];
   maxValue: number;
   maxValue: number;
   minValue: number;
   minValue: number;
-  prefix: string;
   showThresholdLabels: boolean;
   showThresholdLabels: boolean;
   showThresholdMarkers: boolean;
   showThresholdMarkers: boolean;
-  stat: string;
-  suffix: string;
   thresholds: Threshold[];
   thresholds: Threshold[];
+  valueOptions: SingleStatValueOptions;
+}
+
+export interface SingleStatValueOptions {
   unit: string;
   unit: string;
+  suffix: string;
+  stat: string;
+  prefix: string;
+  decimals: number;
 }
 }
 
 
 export const defaults: GaugeOptions = {
 export const defaults: GaugeOptions = {
   minValue: 0,
   minValue: 0,
   maxValue: 100,
   maxValue: 100,
-  prefix: '',
   showThresholdMarkers: true,
   showThresholdMarkers: true,
   showThresholdLabels: false,
   showThresholdLabels: false,
-  suffix: '',
-  decimals: 0,
-  stat: 'avg',
-  unit: 'none',
+  valueOptions: {
+    prefix: '',
+    suffix: '',
+    decimals: 0,
+    stat: 'avg',
+    unit: 'none',
+  },
   valueMappings: [],
   valueMappings: [],
   thresholds: [],
   thresholds: [],
 };
 };