echarts.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. // subtype of the component to which the clicked glyph belongs
  41. // i.e. 'scatter', 'line', etc
  42. componentSubType: string;
  43. // type of the component to which the clicked glyph belongs
  44. // i.e., 'series', 'markLine', 'markPoint', 'timeLine'
  45. componentType: string;
  46. // incoming raw data item
  47. data: Record<string, any>;
  48. // data index in incoming data array
  49. dataIndex: number;
  50. // Some series, such as sankey or graph, maintains more than
  51. // one types of data (nodeData and edgeData), which can be
  52. // distinguished from each other by dataType with its value
  53. // 'node' and 'edge'.
  54. // On the other hand, most series has only one type of data,
  55. // where dataType is not needed.
  56. dataType: string;
  57. // data name, category name
  58. name: string;
  59. seriesId: string;
  60. // series index in incoming option.series (make sense when componentType is 'series')
  61. seriesIndex: number;
  62. // series name (make sense when componentType is 'series')
  63. seriesName: string;
  64. // series type (make sense when componentType is 'series')
  65. // i.e., 'line', 'bar', 'pie'
  66. seriesType: string;
  67. // incoming data value
  68. value: number | number[];
  69. }
  70. export type EChartMouseOutHandler = EChartEventHandler<EChartMouseEventParam>;
  71. export type EChartMouseOverHandler = EChartEventHandler<EChartMouseEventParam>;
  72. export type EChartClickHandler = EChartEventHandler<EChartMouseEventParam>;
  73. export type EChartDataZoomHandler = EChartEventHandler<{
  74. /**
  75. * percentage of zoom finish position, 0 - 100
  76. */
  77. end: number;
  78. /**
  79. * percentage of zoom start position, 0 - 100
  80. */
  81. start: number;
  82. type: 'datazoom';
  83. /**
  84. * data value of zoom finish position; only exists in zoom event of
  85. * triggered by toolbar
  86. */
  87. endValue?: number;
  88. /**
  89. * data value of zoom start position; only exists in zoom event of
  90. * triggered by toolbar
  91. */
  92. startValue?: number;
  93. }>;
  94. export type DataPoint = Pick<SeriesDataUnit, 'name' | 'value'>;
  95. export type EChartRestoreHandler = EChartEventHandler<{type: 'restore'}>;
  96. export type EChartFinishedHandler = EChartEventHandler<{}>;
  97. export type EChartRenderedHandler = EChartEventHandler<{}>;