GraphPanel.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import { PanelProps, GraphWithLegend } from '@grafana/ui';
  3. import { Options } from './types';
  4. import { GraphPanelController } from './GraphPanelController';
  5. import { LegendDisplayMode } from '@grafana/ui/src/components/Legend/Legend';
  6. interface GraphPanelProps extends PanelProps<Options> {}
  7. export const GraphPanel: React.FunctionComponent<GraphPanelProps> = ({
  8. data,
  9. timeRange,
  10. timeZone,
  11. width,
  12. height,
  13. options,
  14. onOptionsChange,
  15. onChangeTimeRange,
  16. }) => {
  17. if (!data) {
  18. return (
  19. <div className="panel-empty">
  20. <p>No data found in response</p>
  21. </div>
  22. );
  23. }
  24. const {
  25. graph: { showLines, showBars, showPoints },
  26. legend: legendOptions,
  27. } = options;
  28. const graphProps = {
  29. showBars,
  30. showLines,
  31. showPoints,
  32. };
  33. const { asTable, isVisible, ...legendProps } = legendOptions;
  34. return (
  35. <GraphPanelController
  36. data={data}
  37. options={options}
  38. onOptionsChange={onOptionsChange}
  39. onChangeTimeRange={onChangeTimeRange}
  40. >
  41. {({ onSeriesToggle, onHorizontalRegionSelected, ...controllerApi }) => {
  42. return (
  43. <GraphWithLegend
  44. timeRange={timeRange}
  45. timeZone={timeZone}
  46. width={width}
  47. height={height}
  48. displayMode={asTable ? LegendDisplayMode.Table : LegendDisplayMode.List}
  49. isLegendVisible={isVisible}
  50. sortLegendBy={legendOptions.sortBy}
  51. sortLegendDesc={legendOptions.sortDesc}
  52. onSeriesToggle={onSeriesToggle}
  53. onHorizontalRegionSelected={onHorizontalRegionSelected}
  54. {...graphProps}
  55. {...legendProps}
  56. {...controllerApi}
  57. />
  58. );
  59. }}
  60. </GraphPanelController>
  61. );
  62. };