diff --git a/packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx b/packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx index 886ebf439e1..b5d43851686 100644 --- a/packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx +++ b/packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx @@ -170,6 +170,18 @@ describe('BarGauge', () => { }); }); + describe('Vertical bar', () => { + it('should adjust empty region to always have same width as colored bar', () => { + const props = getProps({ + width: 150, + value: getValue(100), + orientation: VizOrientation.Vertical, + }); + const styles = getBasicAndGradientStyles(props); + expect(styles.emptyBar.width).toBe('150px'); + }); + }); + describe('Vertical bar without title', () => { it('should not include title height in height', () => { const props = getProps({ @@ -273,6 +285,16 @@ describe('BarGauge', () => { const styles = getTitleStyles(props); expect(styles.title.width).toBe('37px'); }); + + it('should adjust empty region to always have same height as colored bar', () => { + const props = getProps({ + height: 150, + value: getValue(100), + orientation: VizOrientation.Horizontal, + }); + const styles = getBasicAndGradientStyles(props); + expect(styles.emptyBar.height).toBe('150px'); + }); }); describe('Gradient', () => { diff --git a/packages/grafana-ui/src/components/BarGauge/BarGauge.tsx b/packages/grafana-ui/src/components/BarGauge/BarGauge.tsx index 65c1357d51d..7e5e4bf9ac2 100644 --- a/packages/grafana-ui/src/components/BarGauge/BarGauge.tsx +++ b/packages/grafana-ui/src/components/BarGauge/BarGauge.tsx @@ -486,6 +486,9 @@ export function getBasicAndGradientStyles(props: Props): BasicAndGradientStyles // adjust so that filled in bar is at the bottom emptyBar.bottom = '-3px'; + //adjust empty region to always have same width as colored bar + emptyBar.width = `${valueWidth}px`; + if (isBasic) { // Basic styles barStyles.background = `${tinycolor(valueColor).setAlpha(0.35).toRgbString()}`; @@ -509,6 +512,9 @@ export function getBasicAndGradientStyles(props: Props): BasicAndGradientStyles // shift empty region back to fill gaps due to border radius emptyBar.left = '-3px'; + //adjust empty region to always have same height as colored bar + emptyBar.height = `${valueHeight}px`; + if (isBasic) { // Basic styles barStyles.background = `${tinycolor(valueColor).setAlpha(0.35).toRgbString()}`; diff --git a/packages/grafana-ui/src/components/BarGauge/__snapshots__/BarGauge.test.tsx.snap b/packages/grafana-ui/src/components/BarGauge/__snapshots__/BarGauge.test.tsx.snap index a5910cdd095..3907e77f271 100644 --- a/packages/grafana-ui/src/components/BarGauge/__snapshots__/BarGauge.test.tsx.snap +++ b/packages/grafana-ui/src/components/BarGauge/__snapshots__/BarGauge.test.tsx.snap @@ -56,6 +56,7 @@ exports[`BarGauge Render with basic options should render 1`] = ` "borderRadius": "3px", "display": "flex", "flexGrow": 1, + "height": "300px", "left": "-3px", "position": "relative", } diff --git a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx index 3a54036363c..0930d6c6d4a 100644 --- a/public/app/plugins/panel/bargauge/BarGaugePanel.tsx +++ b/public/app/plugins/panel/bargauge/BarGaugePanel.tsx @@ -8,6 +8,7 @@ import { FieldConfig, DisplayProcessor, DisplayValue, + VizOrientation, } from '@grafana/data'; import { BarGauge, DataLinksContextMenu, VizRepeater, VizRepeaterRenderValueProps } from '@grafana/ui'; @@ -52,12 +53,12 @@ export class BarGaugePanel extends PureComponent> { }; renderValue = (valueProps: VizRepeaterRenderValueProps): JSX.Element => { - const { value } = valueProps; + const { value, orientation } = valueProps; const { hasLinks, getLinks } = value; if (hasLinks && getLinks) { return ( -
+
{(api) => this.renderComponent(valueProps, api)}