GraphPanel.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Libraries
  2. import _ from 'lodash';
  3. import React, { PureComponent } from 'react';
  4. import {
  5. Graph,
  6. PanelProps,
  7. NullValueMode,
  8. colors,
  9. TimeSeriesVMs,
  10. ColumnType,
  11. getFirstTimeColumn,
  12. processTimeSeries,
  13. } from '@grafana/ui';
  14. import { Options } from './types';
  15. interface Props extends PanelProps<Options> {}
  16. export class GraphPanel extends PureComponent<Props> {
  17. render() {
  18. const { data, timeRange, width, height } = this.props;
  19. const { showLines, showBars, showPoints } = this.props.options;
  20. const vmSeries: TimeSeriesVMs = [];
  21. for (const table of data) {
  22. const timeColumn = getFirstTimeColumn(table);
  23. if (timeColumn >= 0) {
  24. for (let i = 0; i < table.columns.length; i++) {
  25. const column = table.columns[i];
  26. // Show all numeric columns
  27. if (column.type === ColumnType.number) {
  28. const tsvm = processTimeSeries({
  29. data: [table],
  30. xColumn: timeColumn,
  31. yColumn: i,
  32. nullValueMode: NullValueMode.Null,
  33. })[0];
  34. const colorIndex = vmSeries.length % colors.length;
  35. tsvm.color = colors[colorIndex];
  36. vmSeries.push(tsvm);
  37. }
  38. }
  39. }
  40. }
  41. return (
  42. <Graph
  43. timeSeries={vmSeries}
  44. timeRange={timeRange}
  45. showLines={showLines}
  46. showPoints={showPoints}
  47. showBars={showBars}
  48. width={width}
  49. height={height}
  50. />
  51. );
  52. }
  53. }