GraphPanel.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import { PanelProps, GraphWithLegend /*, GraphSeriesXY*/ } 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. width,
  11. height,
  12. options,
  13. onOptionsChange,
  14. }) => {
  15. if (!data) {
  16. return (
  17. <div className="panel-empty">
  18. <p>No data found in response</p>
  19. </div>
  20. );
  21. }
  22. const {
  23. graph: { showLines, showBars, showPoints },
  24. legend: legendOptions,
  25. } = options;
  26. const graphProps = {
  27. showBars,
  28. showLines,
  29. showPoints,
  30. };
  31. const { asTable, isVisible, ...legendProps } = legendOptions;
  32. return (
  33. <GraphPanelController data={data} options={options} onOptionsChange={onOptionsChange}>
  34. {({ onSeriesToggle, ...controllerApi }) => {
  35. return (
  36. <GraphWithLegend
  37. timeRange={timeRange}
  38. width={width}
  39. height={height}
  40. displayMode={asTable ? LegendDisplayMode.Table : LegendDisplayMode.List}
  41. isLegendVisible={isVisible}
  42. sortLegendBy={legendOptions.sortBy}
  43. sortLegendDesc={legendOptions.sortDesc}
  44. onSeriesToggle={onSeriesToggle}
  45. {...graphProps}
  46. {...legendProps}
  47. {...controllerApi}
  48. />
  49. );
  50. }}
  51. </GraphPanelController>
  52. );
  53. };