|
|
@@ -2,7 +2,7 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
|
// Services & Utils
|
|
|
-import { processTimeSeries } from '@grafana/ui';
|
|
|
+import { processSingleStatPanelData } from '@grafana/ui';
|
|
|
import { config } from 'app/core/config';
|
|
|
|
|
|
// Components
|
|
|
@@ -10,7 +10,7 @@ import { Gauge, VizRepeater } from '@grafana/ui';
|
|
|
|
|
|
// Types
|
|
|
import { GaugeOptions } from './types';
|
|
|
-import { PanelProps, NullValueMode } from '@grafana/ui/src/types';
|
|
|
+import { PanelProps } from '@grafana/ui/src/types';
|
|
|
|
|
|
interface Props extends PanelProps<GaugeOptions> {}
|
|
|
|
|
|
@@ -41,55 +41,18 @@ export class GaugePanel extends PureComponent<Props> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- renderSingleGauge(timeSeries) {
|
|
|
- const { options, width, height } = this.props;
|
|
|
- const value = timeSeries[0].stats[options.valueOptions.stat];
|
|
|
-
|
|
|
- return <div style={{ display: 'flex' }}>{this.renderGauge(value, width, height)}</div>;
|
|
|
- }
|
|
|
-
|
|
|
- renderGaugeWithTableData(panelData) {
|
|
|
- const { width, height } = this.props;
|
|
|
- const firstTableDataValue = panelData.tableData.rows[0].find(prop => prop > 0);
|
|
|
-
|
|
|
- return <div style={{ display: 'flex' }}>{this.renderGauge(firstTableDataValue, width, height)}</div>;
|
|
|
- }
|
|
|
-
|
|
|
render() {
|
|
|
const { panelData, options, height, width } = this.props;
|
|
|
- const { stat } = options.valueOptions;
|
|
|
-
|
|
|
- if (panelData.timeSeries) {
|
|
|
- const timeSeries = processTimeSeries({
|
|
|
- timeSeries: panelData.timeSeries,
|
|
|
- nullValueMode: NullValueMode.Null,
|
|
|
- });
|
|
|
|
|
|
- if (timeSeries.length > 1) {
|
|
|
- return (
|
|
|
- <VizRepeater timeSeries={timeSeries} width={width} height={height}>
|
|
|
- {({ vizHeight, vizWidth, vizContainerStyle }) => {
|
|
|
- return timeSeries.map((series, index) => {
|
|
|
- const value = stat !== 'name' ? series.stats[stat] : series.label;
|
|
|
+ const values = processSingleStatPanelData({
|
|
|
+ panelData: panelData,
|
|
|
+ stat: options.valueOptions.stat,
|
|
|
+ });
|
|
|
|
|
|
- return (
|
|
|
- <div key={`${series.label}-${index}`} style={Object.assign(vizContainerStyle, { display: 'flex' })}>
|
|
|
- {this.renderGauge(value, vizWidth, vizHeight)}
|
|
|
- </div>
|
|
|
- );
|
|
|
- });
|
|
|
- }}
|
|
|
- </VizRepeater>
|
|
|
- );
|
|
|
- } else if (timeSeries.length > 0) {
|
|
|
- return this.renderSingleGauge(timeSeries);
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- } else if (panelData.tableData) {
|
|
|
- return this.renderGaugeWithTableData(panelData);
|
|
|
- } else {
|
|
|
- return <div className="singlestat-panel">No time series data available</div>;
|
|
|
- }
|
|
|
+ return (
|
|
|
+ <VizRepeater height={height} width={width} values={values} orientation="horizontal">
|
|
|
+ {({ vizHeight, vizWidth, valueInfo }) => this.renderGauge(valueInfo.value, vizWidth, vizHeight)}
|
|
|
+ </VizRepeater>
|
|
|
+ );
|
|
|
}
|
|
|
}
|