types.tsx 3.3 KB

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