echarts.tsx 4.0 KB

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