echarts.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import type {
  2. AxisPointerComponentOption,
  3. ECharts,
  4. LineSeriesOption,
  5. PatternObject,
  6. } from 'echarts';
  7. import type ReactEchartsCore from 'echarts-for-react/lib/core';
  8. import type {Confidence} from 'sentry/types/organization';
  9. export type SeriesDataUnit = {
  10. // number because we sometimes use timestamps
  11. name: string | number;
  12. value: number;
  13. confidence?: Confidence;
  14. itemStyle?: {
  15. color?: string;
  16. };
  17. onClick?: (series: Series, instance: ECharts) => void;
  18. };
  19. export type Series = {
  20. data: SeriesDataUnit[];
  21. seriesName: string;
  22. areaStyle?: {
  23. color: string | PatternObject;
  24. opacity: number;
  25. };
  26. color?: string;
  27. id?: string;
  28. lineStyle?: AxisPointerComponentOption['lineStyle'];
  29. // https://echarts.apache.org/en/option.html#series-line.z
  30. markLine?: LineSeriesOption['markLine'];
  31. stack?: string;
  32. // https://echarts.apache.org/en/option.html#series-line.stack
  33. symbol?: LineSeriesOption['symbol'];
  34. symbolSize?: LineSeriesOption['symbolSize'];
  35. z?: number;
  36. };
  37. export type ReactEchartsRef = ReactEchartsCore;
  38. export type EChartEventHandler<P> = (params: P, instance: ECharts) => void;
  39. export type EChartChartReadyHandler = (instance: ECharts) => void;
  40. export type EChartHighlightHandler = EChartEventHandler<any>;
  41. /**
  42. * XXX: These are incomplete types and can also vary depending on the component type
  43. *
  44. * Taken from https://echarts.apache.org/en/api.html#events.Mouse%20events
  45. */
  46. interface EChartMouseEventParam {
  47. // color of component (make sense when componentType is 'series')
  48. color: string;
  49. // subtype of the component to which the clicked glyph belongs
  50. // i.e. 'scatter', 'line', etc
  51. componentSubType: string;
  52. // type of the component to which the clicked glyph belongs
  53. // i.e., 'series', 'markLine', 'markPoint', 'timeLine'
  54. componentType: string;
  55. // incoming raw data item
  56. data: Record<string, any>;
  57. // data index in incoming data array
  58. dataIndex: number;
  59. // Some series, such as sankey or graph, maintains more than
  60. // one types of data (nodeData and edgeData), which can be
  61. // distinguished from each other by dataType with its value
  62. // 'node' and 'edge'.
  63. // On the other hand, most series has only one type of data,
  64. // where dataType is not needed.
  65. dataType: string;
  66. // data name, category name
  67. name: string;
  68. seriesId: string;
  69. // series index in incoming option.series (make sense when componentType is 'series')
  70. seriesIndex: number;
  71. // series name (make sense when componentType is 'series')
  72. seriesName: string;
  73. // series type (make sense when componentType is 'series')
  74. // i.e., 'line', 'bar', 'pie'
  75. seriesType: string;
  76. // incoming data value
  77. value: number | number[];
  78. }
  79. export type EChartMouseOutHandler = EChartEventHandler<EChartMouseEventParam>;
  80. export type EChartMouseOverHandler = EChartEventHandler<EChartMouseEventParam>;
  81. export type EChartClickHandler = EChartEventHandler<EChartMouseEventParam>;
  82. export type EChartDataZoomHandler = EChartEventHandler<{
  83. /**
  84. * percentage of zoom finish position, 0 - 100
  85. */
  86. end: number;
  87. /**
  88. * percentage of zoom start position, 0 - 100
  89. */
  90. start: number;
  91. type: 'datazoom';
  92. /**
  93. * data value of zoom finish position; only exists in zoom event of
  94. * triggered by toolbar
  95. */
  96. endValue?: number;
  97. /**
  98. * data value of zoom start position; only exists in zoom event of
  99. * triggered by toolbar
  100. */
  101. startValue?: number;
  102. }>;
  103. export type DataPoint = Pick<SeriesDataUnit, 'name' | 'value'>;
  104. export type EChartRestoreHandler = EChartEventHandler<{type: 'restore'}>;
  105. export type EChartFinishedHandler = EChartEventHandler<{}>;
  106. export type EChartRenderedHandler = EChartEventHandler<{}>;
  107. type EchartBrushAreas = {
  108. coordRange: number[][];
  109. range: number[][];
  110. }[];
  111. export type EChartBrushStartHandler = EChartEventHandler<{
  112. areas: EchartBrushAreas;
  113. brushId: string;
  114. type: 'brush';
  115. }>;
  116. export type EChartBrushEndHandler = EChartEventHandler<{
  117. areas: EchartBrushAreas;
  118. brushId: string;
  119. type: 'brushend';
  120. }>;
  121. export type EChartBrushSelectedHandler = EChartEventHandler<{
  122. brushId: string;
  123. type: 'brushselected';
  124. }>;