echarts.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. export type EChartEventHandler<P> = (params: P, instance: ECharts) => void;
  30. export type EChartChartReadyHandler = (instance: ECharts) => void;
  31. export type EChartHighlightHandler = EChartEventHandler<any>;
  32. /**
  33. * XXX: These are incomplete types and can also vary depending on the component type
  34. *
  35. * Taken from https://echarts.apache.org/en/api.html#events.Mouse%20events
  36. */
  37. interface EChartMouseEventParam {
  38. // color of component (make sense when componentType is 'series')
  39. color: string;
  40. // type of the component to which the clicked glyph belongs
  41. // i.e., 'series', 'markLine', 'markPoint', 'timeLine'
  42. componentType: string;
  43. // incoming raw data item
  44. data: Record<string, any>;
  45. // data index in incoming data array
  46. dataIndex: number;
  47. // Some series, such as sankey or graph, maintains more than
  48. // one types of data (nodeData and edgeData), which can be
  49. // distinguished from each other by dataType with its value
  50. // 'node' and 'edge'.
  51. // On the other hand, most series has only one type of data,
  52. // where dataType is not needed.
  53. dataType: string;
  54. // data name, category name
  55. name: string;
  56. seriesId: string;
  57. // series index in incoming option.series (make sense when componentType is 'series')
  58. seriesIndex: number;
  59. // series name (make sense when componentType is 'series')
  60. seriesName: string;
  61. // series type (make sense when componentType is 'series')
  62. // i.e., 'line', 'bar', 'pie'
  63. seriesType: string;
  64. // incoming data value
  65. value: number | number[];
  66. }
  67. export type EChartMouseOutHandler = EChartEventHandler<EChartMouseEventParam>;
  68. export type EChartMouseOverHandler = EChartEventHandler<EChartMouseEventParam>;
  69. export type EChartClickHandler = EChartEventHandler<EChartMouseEventParam>;
  70. export type EChartDataZoomHandler = EChartEventHandler<{
  71. /**
  72. * percentage of zoom finish position, 0 - 100
  73. */
  74. end: number;
  75. /**
  76. * percentage of zoom start position, 0 - 100
  77. */
  78. start: number;
  79. type: 'datazoom';
  80. /**
  81. * data value of zoom finish position; only exists in zoom event of
  82. * triggered by toolbar
  83. */
  84. endValue?: number;
  85. /**
  86. * data value of zoom start position; only exists in zoom event of
  87. * triggered by toolbar
  88. */
  89. startValue?: number;
  90. }>;
  91. export type DataPoint = Pick<SeriesDataUnit, 'name' | 'value'>;
  92. export type EChartRestoreHandler = EChartEventHandler<{type: 'restore'}>;
  93. export type EChartFinishedHandler = EChartEventHandler<{}>;
  94. export type EChartRenderedHandler = EChartEventHandler<{}>;