mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Bar Gauge: Add max height option (#76042)
Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
@@ -29,10 +29,12 @@ It extends [SingleStatBaseOptions](#singlestatbaseoptions).
|
|||||||
| Property | Type | Required | Default | Description |
|
| Property | Type | Required | Default | Description |
|
||||||
|-----------------|-------------------------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------------|-------------------------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `displayMode` | string | **Yes** | | Enum expressing the possible display modes<br/>for the bar gauge component of Grafana UI<br/>Possible values are: `basic`, `lcd`, `gradient`. |
|
| `displayMode` | string | **Yes** | | Enum expressing the possible display modes<br/>for the bar gauge component of Grafana UI<br/>Possible values are: `basic`, `lcd`, `gradient`. |
|
||||||
| `minVizHeight` | uint32 | **Yes** | `10` | |
|
| `maxVizHeight` | uint32 | **Yes** | `300` | |
|
||||||
| `minVizWidth` | uint32 | **Yes** | `0` | |
|
| `minVizHeight` | uint32 | **Yes** | `75` | |
|
||||||
|
| `minVizWidth` | uint32 | **Yes** | `75` | |
|
||||||
| `namePlacement` | string | **Yes** | | Allows for the bar gauge name to be placed explicitly<br/>Possible values are: `auto`, `top`, `left`. |
|
| `namePlacement` | string | **Yes** | | Allows for the bar gauge name to be placed explicitly<br/>Possible values are: `auto`, `top`, `left`. |
|
||||||
| `showUnfilled` | boolean | **Yes** | `true` | |
|
| `showUnfilled` | boolean | **Yes** | `true` | |
|
||||||
|
| `sizing` | string | **Yes** | | Allows for the bar gauge size to be set explicitly<br/>Possible values are: `auto`, `manual`. |
|
||||||
| `valueMode` | string | **Yes** | | Allows for the table cell gauge display type to set the gauge mode.<br/>Possible values are: `color`, `text`, `hidden`. |
|
| `valueMode` | string | **Yes** | | Allows for the table cell gauge display type to set the gauge mode.<br/>Possible values are: `color`, `text`, `hidden`. |
|
||||||
| `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 |
|
||||||
|
|||||||
@@ -644,6 +644,14 @@ export enum BarGaugeNamePlacement {
|
|||||||
Top = 'top',
|
Top = 'top',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows for the bar gauge size to be set explicitly
|
||||||
|
*/
|
||||||
|
export enum BarGaugeSizing {
|
||||||
|
Auto = 'auto',
|
||||||
|
Manual = 'manual',
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO docs
|
* TODO docs
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -249,6 +249,9 @@ BarGaugeValueMode: "color" | "text" | "hidden" @cuetsy(kind="enum")
|
|||||||
// Allows for the bar gauge name to be placed explicitly
|
// Allows for the bar gauge name to be placed explicitly
|
||||||
BarGaugeNamePlacement: "auto" | "top" | "left" @cuetsy(kind="enum")
|
BarGaugeNamePlacement: "auto" | "top" | "left" @cuetsy(kind="enum")
|
||||||
|
|
||||||
|
// Allows for the bar gauge size to be set explicitly
|
||||||
|
BarGaugeSizing: "auto" | "manual" @cuetsy(kind="enum")
|
||||||
|
|
||||||
// TODO docs
|
// TODO docs
|
||||||
VizTooltipOptions: {
|
VizTooltipOptions: {
|
||||||
mode: TooltipDisplayMode
|
mode: TooltipDisplayMode
|
||||||
|
|||||||
@@ -15,18 +15,22 @@ export const pluginVersion = "10.3.0-pre";
|
|||||||
|
|
||||||
export interface Options extends common.SingleStatBaseOptions {
|
export interface Options extends common.SingleStatBaseOptions {
|
||||||
displayMode: common.BarGaugeDisplayMode;
|
displayMode: common.BarGaugeDisplayMode;
|
||||||
|
maxVizHeight: number;
|
||||||
minVizHeight: number;
|
minVizHeight: number;
|
||||||
minVizWidth: number;
|
minVizWidth: number;
|
||||||
namePlacement: common.BarGaugeNamePlacement;
|
namePlacement: common.BarGaugeNamePlacement;
|
||||||
showUnfilled: boolean;
|
showUnfilled: boolean;
|
||||||
|
sizing: common.BarGaugeSizing;
|
||||||
valueMode: common.BarGaugeValueMode;
|
valueMode: common.BarGaugeValueMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions: Partial<Options> = {
|
export const defaultOptions: Partial<Options> = {
|
||||||
displayMode: common.BarGaugeDisplayMode.Gradient,
|
displayMode: common.BarGaugeDisplayMode.Gradient,
|
||||||
minVizHeight: 10,
|
maxVizHeight: 300,
|
||||||
minVizWidth: 0,
|
minVizHeight: 75,
|
||||||
|
minVizWidth: 75,
|
||||||
namePlacement: common.BarGaugeNamePlacement.Auto,
|
namePlacement: common.BarGaugeNamePlacement.Auto,
|
||||||
showUnfilled: true,
|
showUnfilled: true,
|
||||||
|
sizing: common.BarGaugeSizing.Auto,
|
||||||
valueMode: common.BarGaugeValueMode.Color,
|
valueMode: common.BarGaugeValueMode.Color,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { clamp } from 'lodash';
|
||||||
import React, { PureComponent, CSSProperties } from 'react';
|
import React, { PureComponent, CSSProperties } from 'react';
|
||||||
|
|
||||||
import { VizOrientation } from '@grafana/data';
|
import { VizOrientation } from '@grafana/data';
|
||||||
@@ -28,6 +29,7 @@ interface Props<V, D> {
|
|||||||
autoGrid?: boolean;
|
autoGrid?: boolean;
|
||||||
minVizWidth?: number;
|
minVizWidth?: number;
|
||||||
minVizHeight?: number;
|
minVizHeight?: number;
|
||||||
|
maxVizHeight?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VizRepeaterRenderValueProps<V, D = {}> {
|
export interface VizRepeaterRenderValueProps<V, D = {}> {
|
||||||
@@ -149,6 +151,7 @@ export class VizRepeater<V, D = {}> extends PureComponent<Props<V, D>, State<V>>
|
|||||||
getAlignmentFactors,
|
getAlignmentFactors,
|
||||||
autoGrid,
|
autoGrid,
|
||||||
orientation,
|
orientation,
|
||||||
|
maxVizHeight,
|
||||||
minVizWidth,
|
minVizWidth,
|
||||||
minVizHeight,
|
minVizHeight,
|
||||||
} = this.props as PropsWithDefaults<V, D>;
|
} = this.props as PropsWithDefaults<V, D>;
|
||||||
@@ -170,15 +173,16 @@ export class VizRepeater<V, D = {}> extends PureComponent<Props<V, D>, State<V>>
|
|||||||
let vizHeight = height;
|
let vizHeight = height;
|
||||||
let vizWidth = width;
|
let vizWidth = width;
|
||||||
|
|
||||||
let resolvedOrientation = this.getOrientation();
|
const resolvedOrientation = this.getOrientation();
|
||||||
|
|
||||||
switch (resolvedOrientation) {
|
switch (resolvedOrientation) {
|
||||||
case VizOrientation.Horizontal:
|
case VizOrientation.Horizontal:
|
||||||
|
const defaultVizHeight = (height + itemSpacing) / values.length - itemSpacing;
|
||||||
repeaterStyle.flexDirection = 'column';
|
repeaterStyle.flexDirection = 'column';
|
||||||
repeaterStyle.height = `${height}px`;
|
repeaterStyle.height = `${height}px`;
|
||||||
itemStyles.marginBottom = `${itemSpacing}px`;
|
itemStyles.marginBottom = `${itemSpacing}px`;
|
||||||
vizWidth = width;
|
vizWidth = width;
|
||||||
vizHeight = Math.max(height / values.length - itemSpacing + itemSpacing / values.length, minVizHeight ?? 0);
|
vizHeight = clamp(defaultVizHeight, minVizHeight ?? 0, maxVizHeight ?? defaultVizHeight);
|
||||||
break;
|
break;
|
||||||
case VizOrientation.Vertical:
|
case VizOrientation.Vertical:
|
||||||
repeaterStyle.flexDirection = 'row';
|
repeaterStyle.flexDirection = 'row';
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import React from 'react';
|
|||||||
import { dateMath, dateTime, EventBus, LoadingState, TimeRange, toDataFrame, VizOrientation } from '@grafana/data';
|
import { dateMath, dateTime, EventBus, LoadingState, TimeRange, toDataFrame, VizOrientation } from '@grafana/data';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import { BarGaugeDisplayMode, BarGaugeValueMode } from '@grafana/schema';
|
import { BarGaugeDisplayMode, BarGaugeValueMode } from '@grafana/schema';
|
||||||
import { BarGaugeNamePlacement } from '@grafana/schema/dist/esm/common/common.gen';
|
import { BarGaugeNamePlacement, BarGaugeSizing } from '@grafana/schema/dist/esm/common/common.gen';
|
||||||
|
|
||||||
import { BarGaugePanel, BarGaugePanelProps } from './BarGaugePanel';
|
import { BarGaugePanel, BarGaugePanelProps } from './BarGaugePanel';
|
||||||
|
|
||||||
@@ -100,10 +100,12 @@ function buildPanelData(overrideValues?: Partial<BarGaugePanelProps>): BarGaugeP
|
|||||||
},
|
},
|
||||||
orientation: VizOrientation.Horizontal,
|
orientation: VizOrientation.Horizontal,
|
||||||
showUnfilled: true,
|
showUnfilled: true,
|
||||||
|
maxVizHeight: 100,
|
||||||
minVizHeight: 10,
|
minVizHeight: 10,
|
||||||
minVizWidth: 0,
|
minVizWidth: 0,
|
||||||
valueMode: BarGaugeValueMode.Color,
|
valueMode: BarGaugeValueMode.Color,
|
||||||
namePlacement: BarGaugeNamePlacement.Auto,
|
namePlacement: BarGaugeNamePlacement.Auto,
|
||||||
|
sizing: BarGaugeSizing.Auto,
|
||||||
},
|
},
|
||||||
transparent: false,
|
transparent: false,
|
||||||
timeRange,
|
timeRange,
|
||||||
|
|||||||
@@ -12,11 +12,12 @@ import {
|
|||||||
DisplayValue,
|
DisplayValue,
|
||||||
VizOrientation,
|
VizOrientation,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
import { BarGaugeSizing } from '@grafana/schema';
|
||||||
import { BarGauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui';
|
import { BarGauge, DataLinksContextMenu, 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 { Options } from './panelcfg.gen';
|
import { Options, defaultOptions } from './panelcfg.gen';
|
||||||
|
|
||||||
export class BarGaugePanel extends PureComponent<BarGaugePanelProps> {
|
export class BarGaugePanel extends PureComponent<BarGaugePanelProps> {
|
||||||
renderComponent = (
|
renderComponent = (
|
||||||
@@ -93,9 +94,40 @@ export class BarGaugePanel extends PureComponent<BarGaugePanelProps> {
|
|||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrientation(): VizOrientation {
|
||||||
|
const { options, width, height } = this.props;
|
||||||
|
const { orientation } = options;
|
||||||
|
|
||||||
|
if (orientation === VizOrientation.Auto) {
|
||||||
|
if (width > height) {
|
||||||
|
return VizOrientation.Vertical;
|
||||||
|
} else {
|
||||||
|
return VizOrientation.Horizontal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
calcBarSize() {
|
||||||
|
const { options } = this.props;
|
||||||
|
|
||||||
|
const orientation = this.getOrientation();
|
||||||
|
const isManualSizing = options.sizing === BarGaugeSizing.Manual;
|
||||||
|
const isVertical = orientation === VizOrientation.Vertical;
|
||||||
|
const isHorizontal = orientation === VizOrientation.Horizontal;
|
||||||
|
const minVizWidth = isManualSizing && isVertical ? options.minVizWidth : defaultOptions.minVizWidth;
|
||||||
|
const minVizHeight = isManualSizing && isHorizontal ? options.minVizHeight : defaultOptions.minVizHeight;
|
||||||
|
const maxVizHeight = isManualSizing && isHorizontal ? options.maxVizHeight : defaultOptions.maxVizHeight;
|
||||||
|
|
||||||
|
return { minVizWidth, minVizHeight, maxVizHeight };
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { height, width, options, data, renderCounter } = this.props;
|
const { height, width, options, data, renderCounter } = this.props;
|
||||||
|
|
||||||
|
const { minVizWidth, minVizHeight, maxVizHeight } = this.calcBarSize();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VizRepeater
|
<VizRepeater
|
||||||
source={data}
|
source={data}
|
||||||
@@ -105,8 +137,9 @@ export class BarGaugePanel extends PureComponent<BarGaugePanelProps> {
|
|||||||
renderCounter={renderCounter}
|
renderCounter={renderCounter}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
minVizWidth={options.minVizWidth}
|
maxVizHeight={maxVizHeight}
|
||||||
minVizHeight={options.minVizHeight}
|
minVizWidth={minVizWidth}
|
||||||
|
minVizHeight={minVizHeight}
|
||||||
itemSpacing={this.getItemSpacing()}
|
itemSpacing={this.getItemSpacing()}
|
||||||
orientation={options.orientation}
|
orientation={options.orientation}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { PanelPlugin, VizOrientation } from '@grafana/data';
|
import { PanelPlugin, VizOrientation } from '@grafana/data';
|
||||||
import { BarGaugeDisplayMode, BarGaugeNamePlacement, BarGaugeValueMode } from '@grafana/schema';
|
import { BarGaugeDisplayMode, BarGaugeNamePlacement, BarGaugeSizing, BarGaugeValueMode } from '@grafana/schema';
|
||||||
import { commonOptionsBuilder, sharedSingleStatPanelChangedHandler } from '@grafana/ui';
|
import { commonOptionsBuilder, sharedSingleStatPanelChangedHandler } from '@grafana/ui';
|
||||||
|
|
||||||
import { addOrientationOption, addStandardDataReduceOptions } from '../stat/common';
|
import { addOrientationOption, addStandardDataReduceOptions } from '../stat/common';
|
||||||
@@ -61,19 +61,58 @@ export const plugin = new PanelPlugin<Options>(BarGaugePanel)
|
|||||||
defaultValue: defaultOptions.showUnfilled,
|
defaultValue: defaultOptions.showUnfilled,
|
||||||
showIf: (options) => options.displayMode !== 'lcd',
|
showIf: (options) => options.displayMode !== 'lcd',
|
||||||
})
|
})
|
||||||
.addNumberInput({
|
.addRadio({
|
||||||
|
path: 'sizing',
|
||||||
|
name: 'Bar size',
|
||||||
|
settings: {
|
||||||
|
options: [
|
||||||
|
{ value: BarGaugeSizing.Auto, label: 'Auto' },
|
||||||
|
{ value: BarGaugeSizing.Manual, label: 'Manual' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
defaultValue: defaultOptions.sizing,
|
||||||
|
})
|
||||||
|
.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.orientation === VizOrientation.Vertical,
|
settings: {
|
||||||
|
min: 0,
|
||||||
|
max: 300,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
showIf: (options) =>
|
||||||
|
options.sizing === BarGaugeSizing.Manual &&
|
||||||
|
(options.orientation === VizOrientation.Auto || 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.orientation === VizOrientation.Horizontal,
|
settings: {
|
||||||
|
min: 0,
|
||||||
|
max: 300,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
showIf: (options) =>
|
||||||
|
options.sizing === BarGaugeSizing.Manual &&
|
||||||
|
(options.orientation === VizOrientation.Auto || options.orientation === VizOrientation.Horizontal),
|
||||||
|
})
|
||||||
|
.addSliderInput({
|
||||||
|
path: 'maxVizHeight',
|
||||||
|
name: 'Max height',
|
||||||
|
description: 'Maximum row height (horizontal orientation)',
|
||||||
|
defaultValue: defaultOptions.maxVizHeight,
|
||||||
|
settings: {
|
||||||
|
min: 0,
|
||||||
|
max: 300,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
showIf: (options) =>
|
||||||
|
options.sizing === BarGaugeSizing.Manual &&
|
||||||
|
(options.orientation === VizOrientation.Auto || options.orientation === VizOrientation.Horizontal),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.setPanelChangeHandler(sharedSingleStatPanelChangedHandler)
|
.setPanelChangeHandler(sharedSingleStatPanelChangedHandler)
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ composableKinds: PanelCfg: {
|
|||||||
valueMode: common.BarGaugeValueMode & (*"color" | _)
|
valueMode: common.BarGaugeValueMode & (*"color" | _)
|
||||||
namePlacement: common.BarGaugeNamePlacement & (*"auto" | _)
|
namePlacement: common.BarGaugeNamePlacement & (*"auto" | _)
|
||||||
showUnfilled: bool | *true
|
showUnfilled: bool | *true
|
||||||
minVizWidth: uint32 | *0
|
sizing: common.BarGaugeSizing & (*"auto" | _)
|
||||||
minVizHeight: uint32 | *10
|
minVizWidth: uint32 | *75
|
||||||
|
minVizHeight: uint32 | *75
|
||||||
|
maxVizHeight: uint32 | *300
|
||||||
} @cuetsy(kind="interface")
|
} @cuetsy(kind="interface")
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|||||||
@@ -12,18 +12,22 @@ import * as common from '@grafana/schema';
|
|||||||
|
|
||||||
export interface Options extends common.SingleStatBaseOptions {
|
export interface Options extends common.SingleStatBaseOptions {
|
||||||
displayMode: common.BarGaugeDisplayMode;
|
displayMode: common.BarGaugeDisplayMode;
|
||||||
|
maxVizHeight: number;
|
||||||
minVizHeight: number;
|
minVizHeight: number;
|
||||||
minVizWidth: number;
|
minVizWidth: number;
|
||||||
namePlacement: common.BarGaugeNamePlacement;
|
namePlacement: common.BarGaugeNamePlacement;
|
||||||
showUnfilled: boolean;
|
showUnfilled: boolean;
|
||||||
|
sizing: common.BarGaugeSizing;
|
||||||
valueMode: common.BarGaugeValueMode;
|
valueMode: common.BarGaugeValueMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions: Partial<Options> = {
|
export const defaultOptions: Partial<Options> = {
|
||||||
displayMode: common.BarGaugeDisplayMode.Gradient,
|
displayMode: common.BarGaugeDisplayMode.Gradient,
|
||||||
minVizHeight: 10,
|
maxVizHeight: 300,
|
||||||
minVizWidth: 0,
|
minVizHeight: 75,
|
||||||
|
minVizWidth: 75,
|
||||||
namePlacement: common.BarGaugeNamePlacement.Auto,
|
namePlacement: common.BarGaugeNamePlacement.Auto,
|
||||||
showUnfilled: true,
|
showUnfilled: true,
|
||||||
|
sizing: common.BarGaugeSizing.Auto,
|
||||||
valueMode: common.BarGaugeValueMode.Color,
|
valueMode: common.BarGaugeValueMode.Color,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user