element.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { ComponentType } from 'react';
  2. import { RegistryItem } from '@grafana/data';
  3. import { PanelOptionsSupplier } from '@grafana/data/src/panel/PanelPlugin';
  4. import { DimensionContext } from '../dimensions/context';
  5. import { BackgroundConfig, Constraint, LineConfig, Placement } from './types';
  6. /**
  7. * This gets saved in panel json
  8. *
  9. * depending on the type, it may have additional config
  10. *
  11. * @alpha
  12. */
  13. export interface CanvasElementOptions<TConfig = any> {
  14. name: string; // configured unique display name
  15. type: string;
  16. // Custom options depending on the type
  17. config?: TConfig;
  18. // Standard options available for all elements
  19. constraint?: Constraint; // defaults vertical - top, horizontal - left
  20. placement?: Placement;
  21. background?: BackgroundConfig;
  22. border?: LineConfig;
  23. }
  24. export interface CanvasElementProps<TConfig = any, TData = any> {
  25. // Saved config
  26. config: TConfig;
  27. // Raw data
  28. data?: TData;
  29. }
  30. /**
  31. * Canvas item builder
  32. *
  33. * @alpha
  34. */
  35. export interface CanvasElementItem<TConfig = any, TData = any> extends RegistryItem {
  36. /** The default width/height to use when adding */
  37. defaultSize?: Placement;
  38. prepareData?: (ctx: DimensionContext, cfg: TConfig) => TData;
  39. /** Component used to draw */
  40. display: ComponentType<CanvasElementProps<TConfig, TData>>;
  41. getNewOptions: (options?: CanvasElementOptions) => Omit<CanvasElementOptions<TConfig>, 'type' | 'name'>;
  42. /** Build the configuration UI */
  43. registerOptionsUI?: PanelOptionsSupplier<CanvasElementOptions<TConfig>>;
  44. }