2018-12-17 06:55:25 -06:00
|
|
|
// Libraries
|
|
|
|
import _ from 'lodash';
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
2019-03-27 15:51:10 -05:00
|
|
|
import { Graph, PanelProps, NullValueMode, colors, GraphSeriesXY, FieldType, getFirstTimeField } from '@grafana/ui';
|
2018-12-17 06:55:25 -06:00
|
|
|
import { Options } from './types';
|
2019-03-22 17:40:17 -05:00
|
|
|
import { getFlotPairs } from '@grafana/ui/src/utils/flotPairs';
|
2018-12-17 06:55:25 -06:00
|
|
|
|
|
|
|
interface Props extends PanelProps<Options> {}
|
|
|
|
|
|
|
|
export class GraphPanel extends PureComponent<Props> {
|
|
|
|
render() {
|
2019-03-07 14:13:38 -06:00
|
|
|
const { data, timeRange, width, height } = this.props;
|
2018-12-17 06:55:25 -06:00
|
|
|
const { showLines, showBars, showPoints } = this.props.options;
|
|
|
|
|
2019-03-27 15:51:10 -05:00
|
|
|
const graphs: GraphSeriesXY[] = [];
|
2019-04-16 15:23:34 -05:00
|
|
|
for (const series of data.series) {
|
|
|
|
const timeColumn = getFirstTimeField(series);
|
|
|
|
if (timeColumn < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-28 12:15:20 -05:00
|
|
|
|
2019-04-16 15:23:34 -05:00
|
|
|
for (let i = 0; i < series.fields.length; i++) {
|
|
|
|
const field = series.fields[i];
|
2019-03-21 23:58:10 -05:00
|
|
|
|
2019-04-16 15:23:34 -05:00
|
|
|
// Show all numeric columns
|
|
|
|
if (field.type === FieldType.number) {
|
|
|
|
// Use external calculator just to make sure it works :)
|
|
|
|
const points = getFlotPairs({
|
|
|
|
series,
|
|
|
|
xIndex: timeColumn,
|
|
|
|
yIndex: i,
|
|
|
|
nullValueMode: NullValueMode.Null,
|
|
|
|
});
|
2019-03-28 12:15:20 -05:00
|
|
|
|
2019-04-16 15:23:34 -05:00
|
|
|
if (points.length > 0) {
|
|
|
|
graphs.push({
|
|
|
|
label: field.name,
|
|
|
|
data: points,
|
|
|
|
color: colors[graphs.length % colors.length],
|
|
|
|
});
|
2019-03-27 15:51:10 -05:00
|
|
|
}
|
2019-03-20 13:27:56 -05:00
|
|
|
}
|
|
|
|
}
|
2019-02-01 03:53:58 -06:00
|
|
|
}
|
2018-12-17 06:55:25 -06:00
|
|
|
|
2019-03-28 12:15:20 -05:00
|
|
|
if (graphs.length < 1) {
|
|
|
|
return (
|
|
|
|
<div className="panel-empty">
|
|
|
|
<p>No data found in response</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-17 06:55:25 -06:00
|
|
|
return (
|
|
|
|
<Graph
|
2019-03-27 15:51:10 -05:00
|
|
|
series={graphs}
|
2018-12-17 06:55:25 -06:00
|
|
|
timeRange={timeRange}
|
|
|
|
showLines={showLines}
|
|
|
|
showPoints={showPoints}
|
|
|
|
showBars={showBars}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|