diff --git a/public/app/core/utils/ConfigProvider.tsx b/public/app/core/utils/ConfigProvider.tsx index 6883401ad27..1a7c394434d 100644 --- a/public/app/core/utils/ConfigProvider.tsx +++ b/public/app/core/utils/ConfigProvider.tsx @@ -14,7 +14,7 @@ export const provideConfig = (component: React.ComponentType) => { }; interface ThemeProviderProps { - children: (theme: GrafanaTheme) => JSX.Element; + children: (theme: GrafanaTheme) => JSX.Element | JSX.Element[]; } export const ThemeProvider = ({ children }: ThemeProviderProps) => { diff --git a/public/app/plugins/panel/gauge/GaugePanel.tsx b/public/app/plugins/panel/gauge/GaugePanel.tsx index 928f9a43909..040a06eed5c 100644 --- a/public/app/plugins/panel/gauge/GaugePanel.tsx +++ b/public/app/plugins/panel/gauge/GaugePanel.tsx @@ -9,77 +9,82 @@ import { Gauge } from '@grafana/ui'; // Types import { GaugeOptions } from './types'; -import { PanelProps, NullValueMode, TimeSeriesValue } from '@grafana/ui/src/types'; +import { PanelProps, NullValueMode } from '@grafana/ui/src/types'; import { ThemeProvider } from 'app/core/utils/ConfigProvider'; interface Props extends PanelProps {} export class GaugePanel extends PureComponent { - render() { - console.log('renduru'); - const { panelData, width, height, onInterpolate, options } = this.props; + renderMultipleGauge(vmSeries, theme) { + const { options, width } = this.props; + const gauges = []; + + for (let i = 0; i < vmSeries.length; i++) { + const singleStatWidth = 1 / vmSeries.length * 100; + const gaugeWidth = Math.floor(width / vmSeries.length) - 10; // make Gauge slightly smaller than panel. + + gauges.push( +
+ {this.renderGauge(vmSeries[i].stats[options.stat], gaugeWidth, theme)} + +
Gauge {i}
+
+ ); + } + return gauges; + } + + renderGauge(value, width, theme) { + const { height, onInterpolate, options } = this.props; const prefix = onInterpolate(options.prefix); const suffix = onInterpolate(options.suffix); - let value: TimeSeriesValue; + return ( + + ); + } + + renderSingleGauge(timeSeries, theme) { + const { options, width } = this.props; + const timeSeriesValue = timeSeries[0].stats[options.stat]; + return
{this.renderGauge(timeSeriesValue, width, theme)}
; + } + + renderGaugeWithTableData(panelData, theme) { + const { width } = this.props; + + const firstTableDataValue = panelData.tableData.rows[0].find(prop => prop > 0); + return
{this.renderGauge(firstTableDataValue, width, theme)}
; + } + + renderPanel(theme) { + const { panelData } = this.props; if (panelData.timeSeries) { - const vmSeries = processTimeSeries({ + const timeSeries = processTimeSeries({ timeSeries: panelData.timeSeries, nullValueMode: NullValueMode.Null, }); - const gauges = []; - if (vmSeries.length > 1) { - for (let i = 0; i < vmSeries.length; i++) { - gauges.push( - - {theme => ( -
- -
Gauge {i}
-
- )} -
- ); - } - return [gauges]; - } else if (vmSeries.length > 0) { - value = vmSeries[0].stats[options.stat]; + if (timeSeries.length > 1) { + return this.renderMultipleGauge(timeSeries, theme); + } else if (timeSeries.length > 0) { + return this.renderSingleGauge(timeSeries, theme); } else { - value = null; + return null; } } else if (panelData.tableData) { - value = panelData.tableData.rows[0].find(prop => prop > 0); + return this.renderGaugeWithTableData(panelData, theme); + } else { + return
No time series data available
; } + } - return ( - - {theme => ( -
- -
- )} -
- ); + render() { + return {theme => this.renderPanel(theme)}; } }