@agions/taroviz 1.11.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/README.md +104 -302
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/vendors.js +1 -0
  5. package/dist/cjs/vendors~echarts.js +1 -0
  6. package/dist/esm/index.js +1 -58151
  7. package/dist/esm/vendors.js +1 -0
  8. package/dist/esm/vendors~echarts.js +1 -0
  9. package/package.json +19 -25
  10. package/src/adapters/MiniAppAdapter.ts +136 -0
  11. package/src/adapters/__tests__/index.test.ts +1 -1
  12. package/src/adapters/h5/__tests__/index.test.ts +4 -2
  13. package/src/adapters/h5/index.ts +63 -64
  14. package/src/adapters/harmony/index.ts +23 -245
  15. package/src/adapters/index.ts +49 -45
  16. package/src/adapters/swan/index.ts +6 -69
  17. package/src/adapters/tt/index.ts +7 -70
  18. package/src/adapters/types.ts +25 -58
  19. package/src/adapters/weapp/index.ts +6 -69
  20. package/src/charts/__tests__/testUtils.tsx +87 -0
  21. package/src/charts/boxplot/__tests__/index.test.tsx +49 -103
  22. package/src/charts/boxplot/index.tsx +2 -1
  23. package/src/charts/boxplot/types.ts +17 -16
  24. package/src/charts/common/BaseChartWrapper.tsx +90 -82
  25. package/src/charts/common/__mocks__/BaseChartWrapper.tsx +17 -0
  26. package/src/charts/createChartComponent.tsx +36 -0
  27. package/src/charts/createOptionChartComponent.tsx +32 -0
  28. package/src/charts/funnel/__tests__/index.test.tsx +99 -0
  29. package/src/charts/funnel/index.tsx +60 -10
  30. package/src/charts/funnel/types.ts +6 -0
  31. package/src/charts/graph/__tests__/index.test.tsx +102 -33
  32. package/src/charts/graph/index.tsx +66 -9
  33. package/src/charts/graph/types.ts +6 -0
  34. package/src/charts/heatmap/__tests__/index.test.tsx +139 -0
  35. package/src/charts/heatmap/index.tsx +103 -10
  36. package/src/charts/heatmap/types.ts +6 -0
  37. package/src/charts/index.ts +74 -26
  38. package/src/charts/liquid/__tests__/index.test.tsx +52 -0
  39. package/src/charts/liquid/index.tsx +239 -182
  40. package/src/charts/liquid/types.ts +11 -11
  41. package/src/charts/parallel/__tests__/index.test.tsx +40 -67
  42. package/src/charts/parallel/index.tsx +2 -1
  43. package/src/charts/parallel/types.ts +19 -18
  44. package/src/charts/radar/__tests__/index.test.tsx +210 -0
  45. package/src/charts/radar/index.tsx +143 -10
  46. package/src/charts/radar/types.ts +13 -0
  47. package/src/charts/sankey/__tests__/index.test.tsx +124 -0
  48. package/src/charts/sankey/index.tsx +62 -10
  49. package/src/charts/sankey/types.ts +6 -0
  50. package/src/charts/tree/__tests__/index.test.tsx +71 -0
  51. package/src/charts/tree/index.tsx +5 -2
  52. package/src/charts/tree/types.ts +9 -9
  53. package/src/charts/types.ts +208 -106
  54. package/src/charts/utils.ts +9 -7
  55. package/src/charts/wordcloud/__tests__/index.test.tsx +98 -31
  56. package/src/charts/wordcloud/index.tsx +75 -9
  57. package/src/charts/wordcloud/types.ts +6 -0
  58. package/src/components/DataFilter/index.tsx +32 -10
  59. package/src/core/animation/types.ts +6 -6
  60. package/src/core/components/Annotation.tsx +6 -7
  61. package/src/core/components/BaseChart.tsx +110 -168
  62. package/src/core/components/ErrorBoundary.tsx +17 -4
  63. package/src/core/components/LazyChart.tsx +54 -55
  64. package/src/core/components/hooks/index.ts +6 -2
  65. package/src/core/components/hooks/useChartInit.ts +6 -3
  66. package/src/core/components/hooks/usePerformance.ts +8 -2
  67. package/src/core/components/hooks/useVirtualScroll.ts +2 -1
  68. package/src/core/index.ts +1 -1
  69. package/src/core/themes/ThemeManager.ts +1 -1
  70. package/src/core/types/common.ts +2 -1
  71. package/src/core/types/index.ts +0 -12
  72. package/src/core/types/platform.ts +3 -5
  73. package/src/core/utils/__tests__/deepClone.test.ts +317 -0
  74. package/src/core/utils/__tests__/index.test.ts +2 -1
  75. package/src/core/utils/chartInstances.ts +13 -0
  76. package/src/core/utils/common.ts +20 -29
  77. package/src/core/utils/deepClone.ts +114 -0
  78. package/src/core/utils/download.ts +128 -0
  79. package/src/core/utils/drillDown.ts +34 -353
  80. package/src/core/utils/drillDownHelpers.ts +426 -0
  81. package/src/core/utils/events.ts +12 -0
  82. package/src/core/utils/export/ExportUtils.ts +36 -67
  83. package/src/core/utils/format.ts +44 -0
  84. package/src/core/utils/index.ts +21 -154
  85. package/src/core/utils/merge.ts +25 -0
  86. package/src/core/utils/performance/PerformanceAnalyzer.ts +38 -21
  87. package/src/core/utils/performance/hooks.ts +7 -0
  88. package/src/core/utils/performance/index.ts +2 -0
  89. package/src/{hooks → core/utils/performance}/useAnimation.ts +45 -41
  90. package/src/core/utils/performance/useDataZoom.ts +324 -0
  91. package/src/{hooks → core/utils/performance}/usePerformance.ts +49 -41
  92. package/src/core/utils/performance/usePerformanceHooks.ts +278 -0
  93. package/src/core/utils/performanceUtils.ts +310 -0
  94. package/src/core/utils/runtime.ts +190 -0
  95. package/src/core/utils/setOptionUtils.ts +59 -0
  96. package/src/core/version.ts +14 -0
  97. package/src/editor/EnhancedThemeEditor.tsx +362 -540
  98. package/src/editor/ThemeEditor.tsx +55 -321
  99. package/src/editor/components/ThemeBasicSettings.tsx +113 -0
  100. package/src/editor/components/ThemeColorEditor.tsx +105 -0
  101. package/src/editor/components/ThemeSelector.tsx +70 -0
  102. package/src/editor/hooks/useThemeEditorState.ts +201 -0
  103. package/src/editor/index.ts +10 -2
  104. package/src/hooks/__tests__/index.test.tsx +3 -1
  105. package/src/hooks/chartConnectHelpers.ts +341 -0
  106. package/src/hooks/index.ts +55 -660
  107. package/src/hooks/types.ts +189 -0
  108. package/src/hooks/useChartAutoResize.ts +73 -0
  109. package/src/hooks/useChartConnect.ts +92 -238
  110. package/src/hooks/useChartDownload.ts +25 -27
  111. package/src/hooks/useChartHistory.ts +34 -49
  112. package/src/hooks/useChartInit.ts +59 -0
  113. package/src/hooks/useChartOptions.ts +259 -0
  114. package/src/hooks/useChartPerformance.ts +109 -0
  115. package/src/hooks/useChartSelection.ts +52 -49
  116. package/src/hooks/useChartTheme.ts +51 -0
  117. package/src/hooks/useDataTransform.ts +19 -4
  118. package/src/hooks/utils/chartDownloadUtils.ts +40 -53
  119. package/src/hooks/utils/dataTransformUtils.ts +22 -0
  120. package/src/index.ts +48 -34
  121. package/src/main.tsx +4 -9
  122. package/src/react-dom.d.ts +3 -3
  123. package/src/themes/index.ts +30 -855
  124. package/src/themes/palettes/blue-green.ts +13 -0
  125. package/src/themes/palettes/chalk.ts +13 -0
  126. package/src/themes/palettes/cyber.ts +44 -0
  127. package/src/themes/palettes/dark.ts +52 -0
  128. package/src/themes/palettes/default.ts +52 -0
  129. package/src/themes/palettes/elegant.ts +34 -0
  130. package/src/themes/palettes/forest.ts +13 -0
  131. package/src/themes/palettes/glass.ts +49 -0
  132. package/src/themes/palettes/golden.ts +13 -0
  133. package/src/themes/palettes/neon.ts +43 -0
  134. package/src/themes/palettes/ocean.ts +39 -0
  135. package/src/themes/palettes/pastel.ts +37 -0
  136. package/src/themes/palettes/purple-passion.ts +13 -0
  137. package/src/themes/palettes/retro.ts +33 -0
  138. package/src/themes/palettes/sunset.ts +40 -0
  139. package/src/themes/palettes/walden.ts +13 -0
  140. package/src/themes/registry.ts +184 -0
  141. package/src/themes/types.ts +213 -0
  142. package/src/charts/bar/__tests__/index.test.tsx +0 -113
  143. package/src/charts/bar/index.tsx +0 -14
  144. package/src/charts/candlestick/__tests__/index.test.tsx +0 -40
  145. package/src/charts/candlestick/index.tsx +0 -13
  146. package/src/charts/gauge/index.tsx +0 -14
  147. package/src/charts/line/__tests__/index.test.tsx +0 -107
  148. package/src/charts/line/index.tsx +0 -15
  149. package/src/charts/pie/__tests__/index.test.tsx +0 -112
  150. package/src/charts/pie/index.tsx +0 -14
  151. package/src/charts/scatter/index.tsx +0 -14
  152. package/src/charts/sunburst/index.tsx +0 -18
  153. package/src/charts/treemap/index.tsx +0 -18
  154. package/src/core/utils/codeGenerator/CodeGenerator.ts +0 -669
  155. package/src/core/utils/codeGenerator/index.ts +0 -13
  156. package/src/core/utils/codeGenerator/types.ts +0 -198
  157. package/src/core/utils/configGenerator/ConfigGenerator.ts +0 -583
  158. package/src/core/utils/configGenerator/index.ts +0 -13
  159. package/src/core/utils/configGenerator/types.ts +0 -445
  160. package/src/core/utils/debug/DebugPanel.tsx +0 -637
  161. package/src/core/utils/debug/debugger.ts +0 -322
  162. package/src/core/utils/debug/index.ts +0 -21
  163. package/src/core/utils/debug/types.ts +0 -142
  164. package/src/hooks/useDataZoom.ts +0 -323
@@ -1,323 +0,0 @@
1
- /**
2
- * useDataZoom - 数据缩放 Hook
3
- * 控制图表的数据缩放区域(dataZoom),支持拖拽和滚轮缩放
4
- */
5
- import { useRef, useCallback, useEffect } from 'react';
6
- import type { RefObject } from 'react';
7
- import type { ChartInstance } from './index';
8
-
9
- // ============================================================================
10
- // 类型定义
11
- // ============================================================================
12
-
13
- /** dataZoom 类型 */
14
- export type DataZoomType = 'inside' | 'slider';
15
-
16
- /** dataZoom 配置选项 */
17
- export interface UseDataZoomOptions {
18
- /** dataZoom 类型: inside=内置型(滚轮/双指), slider=滑块型 */
19
- type?: DataZoomType;
20
- /** 起始位置 (0-100) */
21
- start?: number;
22
- /** 结束位置 (0-100) */
23
- end?: number;
24
- /** 最小跨度 (0-100) */
25
- minSpan?: number;
26
- /** 最大跨度 (0-100) */
27
- maxSpan?: number;
28
- /** 是否锁定缩放 */
29
- zoomLock?: boolean;
30
- /** 节流时间 (ms) */
31
- throttle?: number;
32
- /** 是否禁用 */
33
- disabled?: boolean;
34
- /** 是否显示缩放痕迹 */
35
- brushSelect?: boolean;
36
- /** 缩放模式: 'scale' | 'mix' */
37
- zoomMode?: 'scale' | 'mix';
38
- /** 是否在组件卸载时重置缩放 */
39
- resetOnUnmount?: boolean;
40
- /** 缩放变化回调 */
41
- onZoomChange?: (range: { start: number; end: number }) => void;
42
- }
43
-
44
- /** 缩放范围 */
45
- export interface ZoomRange {
46
- start: number;
47
- end: number;
48
- }
49
-
50
- /** dataZoom 返回值 */
51
- export interface UseDataZoomReturn {
52
- /** 绑定 dataZoom 到图表实例 */
53
- bindDataZoom: (chartInstance: ChartInstance) => void;
54
- /** 设置缩放范围 */
55
- setZoomRange: (start: number, end: number) => void;
56
- /** 重置缩放到初始状态 */
57
- resetZoom: () => void;
58
- /** 获取当前缩放范围 */
59
- getZoomRange: () => ZoomRange;
60
- /** 起始位置的原始值 (Ref) */
61
- startValue: RefObject<number | string | Date | undefined>;
62
- /** 结束位置的原始值 (Ref) */
63
- endValue: RefObject<number | string | Date | undefined>;
64
- /** 绑定事件处理 */
65
- bindEvents: (chartInstance: ChartInstance) => void;
66
- /** 缩放变化回调 */
67
- onZoomChange?: (range: ZoomRange) => void;
68
- }
69
-
70
- // ============================================================================
71
- // Hook 实现
72
- // ============================================================================
73
-
74
- /**
75
- * 使用图表数据缩放
76
- * @param options 配置选项
77
- * @returns dataZoom 操作接口
78
- */
79
- export function useDataZoom(options: UseDataZoomOptions = {}): UseDataZoomReturn {
80
- const {
81
- type = 'inside',
82
- start = 0,
83
- end = 100,
84
- minSpan,
85
- maxSpan,
86
- zoomLock = false,
87
- throttle = 16,
88
- disabled = false,
89
- brushSelect = false,
90
- zoomMode = 'scale',
91
- resetOnUnmount = false,
92
- onZoomChange,
93
- } = options;
94
-
95
- // Refs
96
- const chartRef = useRef<ChartInstance | null>(null);
97
- const startValueRef = useRef<number | string | Date | undefined>(undefined);
98
- const endValueRef = useRef<number | string | Date | undefined>(undefined);
99
- const isBindingRef = useRef(false);
100
- const throttledHandlerRef = useRef<((...args: any[]) => void) | null>(null);
101
-
102
- // 节流处理
103
- const throttledCallback = useCallback(
104
- <T extends (...args: any[]) => void>(fn: T): T => {
105
- let lastCall = 0;
106
- return ((...args: any[]) => {
107
- const now = Date.now();
108
- if (now - lastCall >= throttle) {
109
- lastCall = now;
110
- fn(...args);
111
- }
112
- }) as T;
113
- },
114
- [throttle]
115
- );
116
-
117
- // 构建 dataZoom 配置
118
- const buildDataZoomConfig = useCallback(() => {
119
- const config: any[] = [];
120
-
121
- // 内置型 dataZoom
122
- if (type === 'inside' || zoomMode === 'mix') {
123
- config.push({
124
- type: 'inside',
125
- start,
126
- end,
127
- zoomLock,
128
- disabled,
129
- zoomOnMouseWheel: true,
130
- moveOnMouseMove: false,
131
- moveOnMouseWheel: false,
132
- preventDefaultMouseMove: true,
133
- });
134
- }
135
-
136
- // 滑块型 dataZoom
137
- if (type === 'slider' || zoomMode === 'mix') {
138
- config.push({
139
- type: 'slider',
140
- start,
141
- end,
142
- minSpan,
143
- maxSpan,
144
- zoomLock,
145
- disabled,
146
- show: true,
147
- brushSelect,
148
- throttle,
149
- });
150
- }
151
-
152
- return config;
153
- }, [type, start, end, minSpan, maxSpan, zoomLock, disabled, brushSelect, throttle]);
154
-
155
- // 绑定 dataZoom 到图表
156
- const bindDataZoom = useCallback(
157
- (chartInstance: ChartInstance) => {
158
- if (!chartInstance || isBindingRef.current) return;
159
-
160
- isBindingRef.current = true;
161
- chartRef.current = chartInstance;
162
-
163
- try {
164
- // 设置 dataZoom 配置
165
- const dataZoomConfig = buildDataZoomConfig();
166
- chartInstance.setOption(
167
- {
168
- dataZoom: dataZoomConfig,
169
- },
170
- false,
171
- true
172
- );
173
- } catch (e) {
174
- console.warn('[useDataZoom] Failed to bind dataZoom:', e);
175
- }
176
-
177
- isBindingRef.current = false;
178
- },
179
- [buildDataZoomConfig]
180
- );
181
-
182
- // 解绑 dataZoom
183
- const unbindDataZoom = useCallback(
184
- (chartInstance: ChartInstance) => {
185
- if (!chartInstance) return;
186
-
187
- try {
188
- // 通过 dispatchAction 关闭 dataZoom
189
- chartInstance.dispatchAction?.({
190
- type: 'dataZoom',
191
- start: 0,
192
- end: 100,
193
- });
194
- } catch (e) {
195
- console.warn('[useDataZoom] Failed to unbind dataZoom:', e);
196
- }
197
- },
198
- []
199
- );
200
-
201
- // 设置缩放范围
202
- const setZoomRange = useCallback((newStart: number, newEnd: number) => {
203
- const chart = chartRef.current;
204
- if (!chart) return;
205
-
206
- const clampedStart = Math.max(0, Math.min(100, newStart));
207
- const clampedEnd = Math.max(0, Math.min(100, newEnd));
208
-
209
- try {
210
- chart.dispatchAction?.({
211
- type: 'dataZoom',
212
- start: clampedStart,
213
- end: clampedEnd,
214
- });
215
- } catch (e) {
216
- console.warn('[useDataZoom] Failed to set zoom range:', e);
217
- }
218
- }, []);
219
-
220
- // 重置缩放
221
- const resetZoom = useCallback(() => {
222
- setZoomRange(start, end);
223
- }, [setZoomRange, start, end]);
224
-
225
- // 获取当前缩放范围
226
- const getZoomRange = useCallback((): ZoomRange => {
227
- const chart = chartRef.current;
228
- if (!chart) {
229
- return { start, end };
230
- }
231
-
232
- try {
233
- const option = chart.getOption?.();
234
- const dataZoom = option?.dataZoom as any[];
235
- if (Array.isArray(dataZoom) && dataZoom.length > 0) {
236
- // 优先获取 inside 类型的范围
237
- const insideZoom = dataZoom.find((dz: any) => dz.type === 'inside');
238
- const sliderZoom = dataZoom.find((dz: any) => dz.type === 'slider');
239
- const zoom = insideZoom || sliderZoom || dataZoom[0];
240
- return {
241
- start: zoom.start ?? start,
242
- end: zoom.end ?? end,
243
- };
244
- }
245
- } catch (e) {
246
- console.warn('[useDataZoom] Failed to get zoom range:', e);
247
- }
248
-
249
- return { start, end };
250
- }, [start, end]);
251
-
252
- // 绑定事件
253
- const bindEvents = useCallback(
254
- (chartInstance: ChartInstance) => {
255
- if (!chartInstance) return;
256
-
257
- // 创建缩放变化处理器
258
- const handleZoomChange = (params: any) => {
259
- if (disabled) return;
260
-
261
- const { start: newStart, end: newEnd } = params || {};
262
- if (newStart !== undefined) startValueRef.current = newStart;
263
- if (newEnd !== undefined) endValueRef.current = newEnd;
264
-
265
- onZoomChange?.({ start: newStart ?? start, end: newEnd ?? end });
266
- };
267
-
268
- // 使用节流包装
269
- throttledHandlerRef.current = throttledCallback(handleZoomChange);
270
-
271
- try {
272
- // 监听 dataZoom 事件
273
- chartInstance.on('datazoom', throttledHandlerRef.current);
274
- } catch (e) {
275
- console.warn('[useDataZoom] Failed to bind events:', e);
276
- }
277
- },
278
- [disabled, onZoomChange, throttledCallback]
279
- );
280
-
281
- // 解绑事件
282
- const unbindEvents = useCallback(
283
- (chartInstance: ChartInstance) => {
284
- if (!chartInstance || !throttledHandlerRef.current) return;
285
-
286
- try {
287
- chartInstance.off('datazoom', throttledHandlerRef.current);
288
- } catch (e) {
289
- console.warn('[useDataZoom] Failed to unbind events:', e);
290
- }
291
- },
292
- []
293
- );
294
-
295
- // 清理:组件卸载时
296
- useEffect(() => {
297
- return () => {
298
- const chart = chartRef.current;
299
- if (chart) {
300
- if (resetOnUnmount) {
301
- unbindDataZoom(chart);
302
- }
303
- unbindEvents(chart);
304
- }
305
- };
306
- }, [resetOnUnmount, unbindDataZoom, unbindEvents]);
307
-
308
- return {
309
- bindDataZoom,
310
- setZoomRange,
311
- resetZoom,
312
- getZoomRange,
313
- startValue: startValueRef,
314
- endValue: endValueRef,
315
- bindEvents,
316
- };
317
- }
318
-
319
- // ============================================================================
320
- // 导出
321
- // ============================================================================
322
-
323
- export default useDataZoom;