GraphPanel.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Libraries
  2. import _ from 'lodash';
  3. import React, { PureComponent } from 'react';
  4. import { Graph, PanelProps, NullValueMode, colors, TimeSeriesVMs, FieldType, getFirstTimeField } from '@grafana/ui';
  5. import { Options } from './types';
  6. import { getFlotPairs } from '@grafana/ui/src/utils/flotPairs';
  7. interface Props extends PanelProps<Options> {}
  8. export class GraphPanel extends PureComponent<Props> {
  9. render() {
  10. const { data, timeRange, width, height } = this.props;
  11. const { showLines, showBars, showPoints } = this.props.options;
  12. const vmSeries: TimeSeriesVMs = [];
  13. for (const table of data) {
  14. const timeColumn = getFirstTimeField(table);
  15. if (timeColumn < 0) {
  16. continue;
  17. }
  18. for (let i = 0; i < table.fields.length; i++) {
  19. const column = table.fields[i];
  20. // Show all numeric columns
  21. if (column.type === FieldType.number) {
  22. // Use external calculator just to make sure it works :)
  23. const points = getFlotPairs({
  24. rows: table.rows,
  25. xIndex: timeColumn,
  26. yIndex: i,
  27. nullValueMode: NullValueMode.Null,
  28. });
  29. vmSeries.push({
  30. label: column.name,
  31. data: points,
  32. color: colors[vmSeries.length % colors.length],
  33. // TODO (calculate somewhere)
  34. allIsNull: false,
  35. allIsZero: false,
  36. });
  37. }
  38. }
  39. }
  40. return (
  41. <Graph
  42. timeSeries={vmSeries}
  43. timeRange={timeRange}
  44. showLines={showLines}
  45. showPoints={showPoints}
  46. showBars={showBars}
  47. width={width}
  48. height={height}
  49. />
  50. );
  51. }
  52. }