GraphPanel.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. continue;
  25. }
  26. for (let i = 0; i < table.columns.length; i++) {
  27. const column = table.columns[i];
  28. // Show all numeric columns
  29. if (column.type === ColumnType.number) {
  30. const tsvm = processTimeSeries({
  31. data: [table],
  32. xColumn: timeColumn,
  33. yColumn: i,
  34. nullValueMode: NullValueMode.Null,
  35. })[0];
  36. const colorIndex = vmSeries.length % colors.length;
  37. tsvm.color = colors[colorIndex];
  38. vmSeries.push(tsvm);
  39. }
  40. }
  41. }
  42. return (
  43. <Graph
  44. timeSeries={vmSeries}
  45. timeRange={timeRange}
  46. showLines={showLines}
  47. showPoints={showPoints}
  48. showBars={showBars}
  49. width={width}
  50. height={height}
  51. />
  52. );
  53. }
  54. }