mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Gauge: Simplify gauge dimension panel options (#76216)
Co-authored-by: Ihor Yeromin <yeryomin.igor@gmail.com>
This commit is contained in:
parent
49fc8214a0
commit
3e08abff3b
@ -28,10 +28,11 @@ It extends [SingleStatBaseOptions](#singlestatbaseoptions).
|
|||||||
|
|
||||||
| Property | Type | Required | Default | Description |
|
| Property | Type | Required | Default | Description |
|
||||||
|------------------------|-------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
|------------------------|-------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `minVizHeight` | uint32 | **Yes** | `75` | |
|
| `minVizHeight` | uint32 | **Yes** | `200` | |
|
||||||
| `minVizWidth` | uint32 | **Yes** | `75` | |
|
| `minVizWidth` | uint32 | **Yes** | `200` | |
|
||||||
| `showThresholdLabels` | boolean | **Yes** | `false` | |
|
| `showThresholdLabels` | boolean | **Yes** | `false` | |
|
||||||
| `showThresholdMarkers` | boolean | **Yes** | `true` | |
|
| `showThresholdMarkers` | boolean | **Yes** | `true` | |
|
||||||
|
| `sizing` | string | **Yes** | | Allows for the bar gauge size to be set explicitly<br/>Possible values are: `auto`, `manual`. |
|
||||||
| `orientation` | string | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs<br/>Possible values are: `auto`, `vertical`, `horizontal`. |
|
| `orientation` | string | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs<br/>Possible values are: `auto`, `vertical`, `horizontal`. |
|
||||||
| `reduceOptions` | [ReduceDataOptions](#reducedataoptions) | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs |
|
| `reduceOptions` | [ReduceDataOptions](#reducedataoptions) | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs |
|
||||||
| `text` | [VizTextDisplayOptions](#viztextdisplayoptions) | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs |
|
| `text` | [VizTextDisplayOptions](#viztextdisplayoptions) | No | | *(Inherited from [SingleStatBaseOptions](#singlestatbaseoptions))*<br/>TODO docs |
|
||||||
|
@ -18,11 +18,13 @@ export interface Options extends common.SingleStatBaseOptions {
|
|||||||
minVizWidth: number;
|
minVizWidth: number;
|
||||||
showThresholdLabels: boolean;
|
showThresholdLabels: boolean;
|
||||||
showThresholdMarkers: boolean;
|
showThresholdMarkers: boolean;
|
||||||
|
sizing: common.BarGaugeSizing;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions: Partial<Options> = {
|
export const defaultOptions: Partial<Options> = {
|
||||||
minVizHeight: 75,
|
minVizHeight: 200,
|
||||||
minVizWidth: 75,
|
minVizWidth: 200,
|
||||||
showThresholdLabels: false,
|
showThresholdLabels: false,
|
||||||
showThresholdMarkers: true,
|
showThresholdMarkers: true,
|
||||||
|
sizing: common.BarGaugeSizing.Auto,
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
|
||||||
import { FieldDisplay, getDisplayProcessor, getFieldDisplayValues, PanelProps } from '@grafana/data';
|
import { FieldDisplay, getDisplayProcessor, getFieldDisplayValues, PanelProps } from '@grafana/data';
|
||||||
|
import { BarGaugeSizing, VizOrientation } from '@grafana/schema';
|
||||||
import { DataLinksContextMenu, Gauge, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
import { DataLinksContextMenu, Gauge, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
||||||
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
import { DataLinksContextMenuApi } from '@grafana/ui/src/components/DataLinks/DataLinksContextMenu';
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
|
|
||||||
import { clearNameForSingleSeries } from '../bargauge/BarGaugePanel';
|
import { clearNameForSingleSeries } from '../bargauge/BarGaugePanel';
|
||||||
|
|
||||||
import { Options } from './panelcfg.gen';
|
import { defaultOptions, Options } from './panelcfg.gen';
|
||||||
|
|
||||||
export class GaugePanel extends PureComponent<PanelProps<Options>> {
|
export class GaugePanel extends PureComponent<PanelProps<Options>> {
|
||||||
renderComponent = (
|
renderComponent = (
|
||||||
@ -78,9 +79,25 @@ export class GaugePanel extends PureComponent<PanelProps<Options>> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
calculateGaugeSize = () => {
|
||||||
|
const { options } = this.props;
|
||||||
|
|
||||||
|
const orientation = options.orientation;
|
||||||
|
const isManualSizing = options.sizing === BarGaugeSizing.Manual;
|
||||||
|
const isVerticalOrientation = orientation === VizOrientation.Vertical;
|
||||||
|
const isHorizontalOrientation = orientation === VizOrientation.Horizontal;
|
||||||
|
|
||||||
|
const minVizWidth = isManualSizing && isVerticalOrientation ? options.minVizWidth : defaultOptions.minVizWidth;
|
||||||
|
const minVizHeight = isManualSizing && isHorizontalOrientation ? options.minVizHeight : defaultOptions.minVizHeight;
|
||||||
|
|
||||||
|
return { minVizWidth, minVizHeight };
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { height, width, data, renderCounter, options } = this.props;
|
const { height, width, data, renderCounter, options } = this.props;
|
||||||
|
|
||||||
|
const { minVizHeight, minVizWidth } = this.calculateGaugeSize();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VizRepeater
|
<VizRepeater
|
||||||
getValues={this.getValues}
|
getValues={this.getValues}
|
||||||
@ -91,8 +108,8 @@ export class GaugePanel extends PureComponent<PanelProps<Options>> {
|
|||||||
autoGrid={true}
|
autoGrid={true}
|
||||||
renderCounter={renderCounter}
|
renderCounter={renderCounter}
|
||||||
orientation={options.orientation}
|
orientation={options.orientation}
|
||||||
minVizHeight={options.minVizHeight}
|
minVizHeight={minVizHeight}
|
||||||
minVizWidth={options.minVizWidth}
|
minVizWidth={minVizWidth}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { PanelPlugin } from '@grafana/data';
|
import { PanelPlugin } from '@grafana/data';
|
||||||
import { VizOrientation } from '@grafana/schema';
|
import { BarGaugeSizing, VizOrientation } from '@grafana/schema';
|
||||||
import { commonOptionsBuilder } from '@grafana/ui';
|
import { commonOptionsBuilder } from '@grafana/ui';
|
||||||
|
|
||||||
import { addOrientationOption, addStandardDataReduceOptions } from '../stat/common';
|
import { addOrientationOption, addStandardDataReduceOptions } from '../stat/common';
|
||||||
@ -39,19 +39,43 @@ export const plugin = new PanelPlugin<Options>(GaugePanel)
|
|||||||
description: 'Renders the thresholds as an outer bar',
|
description: 'Renders the thresholds as an outer bar',
|
||||||
defaultValue: defaultOptions.showThresholdMarkers,
|
defaultValue: defaultOptions.showThresholdMarkers,
|
||||||
})
|
})
|
||||||
.addNumberInput({
|
.addRadio({
|
||||||
|
path: 'sizing',
|
||||||
|
name: 'Gauge size',
|
||||||
|
settings: {
|
||||||
|
options: [
|
||||||
|
{ value: BarGaugeSizing.Auto, label: 'Auto' },
|
||||||
|
{ value: BarGaugeSizing.Manual, label: 'Manual' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
defaultValue: defaultOptions.sizing,
|
||||||
|
showIf: (options: Options) => options.orientation !== VizOrientation.Auto,
|
||||||
|
})
|
||||||
|
.addSliderInput({
|
||||||
path: 'minVizWidth',
|
path: 'minVizWidth',
|
||||||
name: 'Min width',
|
name: 'Min width',
|
||||||
description: 'Minimum column width',
|
description: 'Minimum column width (vertical orientation)',
|
||||||
defaultValue: defaultOptions.minVizWidth,
|
defaultValue: defaultOptions.minVizWidth,
|
||||||
showIf: (options: Options) => options.orientation === VizOrientation.Vertical,
|
settings: {
|
||||||
|
min: 0,
|
||||||
|
max: 600,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
showIf: (options: Options) =>
|
||||||
|
options.sizing === BarGaugeSizing.Manual && options.orientation === VizOrientation.Vertical,
|
||||||
})
|
})
|
||||||
.addNumberInput({
|
.addSliderInput({
|
||||||
path: 'minVizHeight',
|
path: 'minVizHeight',
|
||||||
name: 'Min height',
|
name: 'Min height',
|
||||||
description: 'Minimum row height',
|
description: 'Minimum row height (horizontal orientation)',
|
||||||
defaultValue: defaultOptions.minVizHeight,
|
defaultValue: defaultOptions.minVizHeight,
|
||||||
showIf: (options: Options) => options.orientation === VizOrientation.Horizontal,
|
settings: {
|
||||||
|
min: 0,
|
||||||
|
max: 600,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
showIf: (options: Options) =>
|
||||||
|
options.sizing === BarGaugeSizing.Manual && options.orientation === VizOrientation.Horizontal,
|
||||||
});
|
});
|
||||||
|
|
||||||
commonOptionsBuilder.addTextSizeOptions(builder);
|
commonOptionsBuilder.addTextSizeOptions(builder);
|
||||||
|
@ -29,8 +29,9 @@ composableKinds: PanelCfg: {
|
|||||||
common.SingleStatBaseOptions
|
common.SingleStatBaseOptions
|
||||||
showThresholdLabels: bool | *false
|
showThresholdLabels: bool | *false
|
||||||
showThresholdMarkers: bool | *true
|
showThresholdMarkers: bool | *true
|
||||||
minVizWidth: uint32 | *75
|
sizing: common.BarGaugeSizing & (*"auto" | _)
|
||||||
minVizHeight: uint32 | *75
|
minVizWidth: uint32 | *200
|
||||||
|
minVizHeight: uint32 | *200
|
||||||
} @cuetsy(kind="interface")
|
} @cuetsy(kind="interface")
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -15,11 +15,13 @@ export interface Options extends common.SingleStatBaseOptions {
|
|||||||
minVizWidth: number;
|
minVizWidth: number;
|
||||||
showThresholdLabels: boolean;
|
showThresholdLabels: boolean;
|
||||||
showThresholdMarkers: boolean;
|
showThresholdMarkers: boolean;
|
||||||
|
sizing: common.BarGaugeSizing;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions: Partial<Options> = {
|
export const defaultOptions: Partial<Options> = {
|
||||||
minVizHeight: 75,
|
minVizHeight: 200,
|
||||||
minVizWidth: 75,
|
minVizWidth: 200,
|
||||||
showThresholdLabels: false,
|
showThresholdLabels: false,
|
||||||
showThresholdMarkers: true,
|
showThresholdMarkers: true,
|
||||||
|
sizing: common.BarGaugeSizing.Auto,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user