GraphPanel.tsx 1.6 KB

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