|
|
@@ -5,38 +5,54 @@ import React, { PureComponent } from 'react';
|
|
|
import { processTimeSeries, ThemeContext } from '@grafana/ui';
|
|
|
|
|
|
// Components
|
|
|
-import { Piechart } from '@grafana/ui';
|
|
|
+import { Piechart, PieChartDataPoint } from '@grafana/ui';
|
|
|
|
|
|
// Types
|
|
|
import { PiechartOptions } from './types';
|
|
|
-import { PanelProps, NullValueMode, TimeSeriesValue } from '@grafana/ui/src/types';
|
|
|
+import { PanelProps, NullValueMode } from '@grafana/ui/src/types';
|
|
|
|
|
|
interface Props extends PanelProps<PiechartOptions> {}
|
|
|
|
|
|
export class PiechartPanel extends PureComponent<Props> {
|
|
|
render() {
|
|
|
const { panelData, width, height, options } = this.props;
|
|
|
+ const { valueOptions } = options;
|
|
|
|
|
|
- let value: TimeSeriesValue;
|
|
|
-
|
|
|
+ let datapoints: PieChartDataPoint[] = [];
|
|
|
if (panelData.timeSeries) {
|
|
|
const vmSeries = processTimeSeries({
|
|
|
timeSeries: panelData.timeSeries,
|
|
|
nullValueMode: NullValueMode.Null,
|
|
|
});
|
|
|
|
|
|
- if (vmSeries[0]) {
|
|
|
- value = vmSeries[0].stats[options.stat];
|
|
|
- } else {
|
|
|
- value = null;
|
|
|
- }
|
|
|
- } else if (panelData.tableData) {
|
|
|
- value = panelData.tableData.rows[0].find(prop => prop > 0);
|
|
|
+ vmSeries.forEach(serie => {
|
|
|
+ if (serie) {
|
|
|
+ datapoints.push({
|
|
|
+ value: serie.stats[valueOptions.stat],
|
|
|
+ // TODO: get name
|
|
|
+ name: 'tmpName',
|
|
|
+ // TODO: add color option
|
|
|
+ color: 'tmpColor'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ // TODO: support table data
|
|
|
|
|
|
return (
|
|
|
<ThemeContext.Consumer>
|
|
|
- {theme => <Piechart value={value} {...this.props.options} width={width} height={height} theme={theme} />}
|
|
|
+ {theme => (
|
|
|
+ <Piechart
|
|
|
+ width={width}
|
|
|
+ height={height}
|
|
|
+ datapoints={datapoints}
|
|
|
+ pieType={options.pieType}
|
|
|
+ unit={options.unit}
|
|
|
+ stat={options.stat}
|
|
|
+ strokeWidth={options.strokeWidth}
|
|
|
+ theme={theme}
|
|
|
+ />
|
|
|
+ )}
|
|
|
</ThemeContext.Consumer>
|
|
|
);
|
|
|
}
|