echarts.tsx 3.3 KB

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