types.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import type {EChartsOption} from 'echarts';
  2. /**
  3. * Defines the keys which may be passed into the chartcuterie chart rendering
  4. * service.
  5. *
  6. * When adding or removing from this list, please also update the
  7. * sentry/charts/types.py file
  8. */
  9. export enum ChartType {
  10. SLACK_DISCOVER_TOTAL_PERIOD = 'slack:discover.totalPeriod',
  11. SLACK_DISCOVER_TOTAL_DAILY = 'slack:discover.totalDaily',
  12. SLACK_DISCOVER_TOP5_PERIOD = 'slack:discover.top5Period',
  13. SLACK_DISCOVER_TOP5_PERIOD_LINE = 'slack:discover.top5PeriodLine',
  14. SLACK_DISCOVER_TOP5_DAILY = 'slack:discover.top5Daily',
  15. SLACK_DISCOVER_PREVIOUS_PERIOD = 'slack:discover.previousPeriod',
  16. SLACK_METRIC_ALERT_EVENTS = 'slack:metricAlert.events',
  17. SLACK_METRIC_ALERT_SESSIONS = 'slack:metricAlert.sessions',
  18. }
  19. /**
  20. * XXX(epurkhiser): These are copied directly over from chartucterie to avoid
  21. * installing the package, which has some system-level dependencies we would
  22. * prefer not to install with sentry.
  23. */
  24. export type RenderOption = Omit<EChartsOption, 'animation' | 'tooltip' | 'toolbox'>;
  25. /**
  26. * Describes configuration for a renderable chart style
  27. */
  28. export type RenderDescriptor<D extends string = string> = {
  29. /**
  30. * Produce the echart option config for rendering the charts series. It is up
  31. * to the implementation to declare what data it should receive, as long as
  32. * it produces a valid ECharts Option config.
  33. */
  34. getOption: (data: any) => RenderOption;
  35. /**
  36. * Height of the produced image in pixels
  37. */
  38. height: number;
  39. key: D;
  40. /**
  41. * Width of the produced image in pixels
  42. */
  43. width: number;
  44. };
  45. /**
  46. * Maps style keys to style descriptor configuration
  47. */
  48. export type RenderConfig<D extends string = string> = Map<D, RenderDescriptor<D>>;
  49. /**
  50. * The data given to the service to render a chart
  51. */
  52. export type RenderData = {
  53. /**
  54. * Arbitrary series data. The RenderDescriptor.getOption should transform this
  55. * into a valid echarts series.
  56. */
  57. data: any;
  58. /**
  59. * Globally unique render ID.
  60. */
  61. requestId: string;
  62. /**
  63. * The style config key
  64. */
  65. style: string;
  66. };
  67. /**
  68. * Performs any additional initialization steps on Chartcuterie's global
  69. * echarts object on service start up. For example, registerMaps can
  70. * be called here to register any available maps to ECharts.
  71. */
  72. export type InitFn = (echarts: any) => void;
  73. /**
  74. * The configuration object type expected to be provided to the service
  75. */
  76. export type ChartcuterieConfig = {
  77. renderConfig: RenderConfig;
  78. /**
  79. * A string version identifier for the configuration. This may be useful for
  80. * validating that a chart is being rendered using a specific known
  81. * configuration.
  82. */
  83. version: string;
  84. /**
  85. * The optional initialization function to run when the service starts
  86. * or restarts due to configuration updates.
  87. */
  88. init?: InitFn;
  89. };
  90. /**
  91. * Configuration to specify how often to poll for configuration changes
  92. */
  93. export type PollingConfig = {
  94. /**
  95. * The number of seconds between each polling attempt when the application boots
  96. * and has yet to load a configuration.
  97. */
  98. bootInterval: number;
  99. /**
  100. * The number of seconds between each polling attempt after the application
  101. * has already loaded a valid configuration file
  102. */
  103. idleInterval: number;
  104. };