The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/plugins/panel/graph2/GraphPanel.tsx

61 lines
1.5 KiB

// Libraries
import _ from 'lodash';
import React, { PureComponent } from 'react';
import {
Graph,
PanelProps,
NullValueMode,
colors,
TimeSeriesVMs,
ColumnType,
getFirstTimeColumn,
processTimeSeries,
} from '@grafana/ui';
import { Options } from './types';
interface Props extends PanelProps<Options> {}
export class GraphPanel extends PureComponent<Props> {
render() {
const { data, timeRange, width, height } = this.props;
const { showLines, showBars, showPoints } = this.props.options;
const vmSeries: TimeSeriesVMs = [];
for (const table of data) {
const timeColumn = getFirstTimeColumn(table);
if (timeColumn >= 0) {
for (let i = 0; i < table.columns.length; i++) {
const column = table.columns[i];
// Show all numeric columns
if (column.type === ColumnType.number) {
const tsvm = processTimeSeries({
data: [table],
xColumn: timeColumn,
yColumn: i,
nullValueMode: NullValueMode.Null,
})[0];
const colorIndex = vmSeries.length % colors.length;
tsvm.color = colors[colorIndex];
vmSeries.push(tsvm);
}
}
}
}
return (
<Graph
timeSeries={vmSeries}
timeRange={timeRange}
showLines={showLines}
showPoints={showPoints}
showBars={showBars}
width={width}
height={height}
/>
);
}
}