@agions/taroviz 1.11.5 → 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 (118) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/README.md +31 -46
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/vendors.js +1 -1
  5. package/dist/cjs/vendors~echarts.js +1 -1
  6. package/dist/esm/index.js +1 -14270
  7. package/dist/esm/vendors.js +1 -16770
  8. package/dist/esm/vendors~echarts.js +1 -59417
  9. package/package.json +10 -15
  10. package/src/adapters/h5/index.ts +38 -38
  11. package/src/adapters/index.ts +32 -34
  12. package/src/adapters/types.ts +23 -55
  13. package/src/charts/boxplot/types.ts +2 -2
  14. package/src/charts/common/BaseChartWrapper.tsx +9 -7
  15. package/src/charts/createChartComponent.tsx +9 -21
  16. package/src/charts/createOptionChartComponent.tsx +32 -0
  17. package/src/charts/funnel/__tests__/index.test.tsx +99 -0
  18. package/src/charts/funnel/index.tsx +64 -0
  19. package/src/charts/funnel/types.ts +6 -0
  20. package/src/charts/graph/__tests__/index.test.tsx +116 -0
  21. package/src/charts/graph/index.tsx +70 -0
  22. package/src/charts/graph/types.ts +6 -0
  23. package/src/charts/heatmap/__tests__/index.test.tsx +139 -0
  24. package/src/charts/heatmap/index.tsx +107 -0
  25. package/src/charts/heatmap/types.ts +6 -0
  26. package/src/charts/index.ts +47 -57
  27. package/src/charts/liquid/__tests__/index.test.tsx +52 -0
  28. package/src/charts/liquid/index.tsx +7 -133
  29. package/src/charts/liquid/types.ts +6 -6
  30. package/src/charts/parallel/types.ts +3 -3
  31. package/src/charts/radar/__tests__/index.test.tsx +210 -0
  32. package/src/charts/radar/index.tsx +147 -0
  33. package/src/charts/radar/types.ts +13 -0
  34. package/src/charts/sankey/__tests__/index.test.tsx +124 -0
  35. package/src/charts/sankey/index.tsx +70 -0
  36. package/src/charts/sankey/types.ts +6 -0
  37. package/src/charts/tree/__tests__/index.test.tsx +71 -0
  38. package/src/charts/tree/index.tsx +1 -1
  39. package/src/charts/tree/types.ts +8 -8
  40. package/src/charts/types.ts +208 -106
  41. package/src/charts/wordcloud/__tests__/index.test.tsx +106 -0
  42. package/src/charts/wordcloud/index.tsx +79 -0
  43. package/src/charts/wordcloud/types.ts +6 -0
  44. package/src/components/DataFilter/index.tsx +7 -6
  45. package/src/core/animation/types.ts +6 -6
  46. package/src/core/components/Annotation.tsx +6 -6
  47. package/src/core/components/BaseChart.tsx +97 -133
  48. package/src/core/components/LazyChart.tsx +3 -8
  49. package/src/core/components/hooks/index.ts +6 -2
  50. package/src/core/components/hooks/usePerformance.ts +8 -2
  51. package/src/core/components/hooks/useVirtualScroll.ts +2 -1
  52. package/src/core/types/common.ts +2 -1
  53. package/src/core/types/platform.ts +1 -0
  54. package/src/core/utils/__tests__/deepClone.test.ts +317 -0
  55. package/src/core/utils/__tests__/index.test.ts +2 -1
  56. package/src/core/utils/chartInstances.ts +13 -0
  57. package/src/core/utils/common.ts +20 -36
  58. package/src/core/utils/deepClone.ts +114 -0
  59. package/src/core/utils/download.ts +22 -28
  60. package/src/core/utils/drillDown.ts +1 -0
  61. package/src/core/utils/events.ts +12 -0
  62. package/src/core/utils/export/ExportUtils.ts +2 -1
  63. package/src/core/utils/format.ts +44 -0
  64. package/src/core/utils/index.ts +18 -159
  65. package/src/core/utils/merge.ts +25 -0
  66. package/src/core/utils/performance/PerformanceAnalyzer.ts +3 -1
  67. package/src/core/utils/performance/hooks.ts +7 -0
  68. package/src/core/utils/performance/index.ts +2 -0
  69. package/src/{hooks → core/utils/performance}/useAnimation.ts +6 -5
  70. package/src/{hooks → core/utils/performance}/useDataZoom.ts +7 -2
  71. package/src/{hooks → core/utils/performance}/usePerformance.ts +39 -39
  72. package/src/{hooks → core/utils/performance}/usePerformanceHooks.ts +39 -39
  73. package/src/core/utils/runtime.ts +190 -0
  74. package/src/editor/components/ThemeSelector.tsx +3 -3
  75. package/src/hooks/chartConnectHelpers.ts +6 -0
  76. package/src/hooks/index.ts +54 -626
  77. package/src/hooks/types.ts +27 -0
  78. package/src/hooks/useChartAutoResize.ts +73 -0
  79. package/src/hooks/useChartConnect.ts +5 -1
  80. package/src/hooks/useChartDownload.ts +1 -1
  81. package/src/hooks/useChartHistory.ts +1 -3
  82. package/src/hooks/useChartInit.ts +59 -0
  83. package/src/hooks/useChartOptions.ts +259 -0
  84. package/src/hooks/useChartPerformance.ts +109 -0
  85. package/src/hooks/useChartSelection.ts +23 -12
  86. package/src/hooks/useChartTheme.ts +51 -0
  87. package/src/hooks/useDataTransform.ts +19 -4
  88. package/src/index.ts +5 -10
  89. package/src/react-dom.d.ts +3 -3
  90. package/src/themes/index.ts +30 -855
  91. package/src/themes/palettes/blue-green.ts +13 -0
  92. package/src/themes/palettes/chalk.ts +13 -0
  93. package/src/themes/palettes/cyber.ts +44 -0
  94. package/src/themes/palettes/dark.ts +52 -0
  95. package/src/themes/palettes/default.ts +52 -0
  96. package/src/themes/palettes/elegant.ts +34 -0
  97. package/src/themes/palettes/forest.ts +13 -0
  98. package/src/themes/palettes/glass.ts +49 -0
  99. package/src/themes/palettes/golden.ts +13 -0
  100. package/src/themes/palettes/neon.ts +43 -0
  101. package/src/themes/palettes/ocean.ts +39 -0
  102. package/src/themes/palettes/pastel.ts +37 -0
  103. package/src/themes/palettes/purple-passion.ts +13 -0
  104. package/src/themes/palettes/retro.ts +33 -0
  105. package/src/themes/palettes/sunset.ts +40 -0
  106. package/src/themes/palettes/walden.ts +13 -0
  107. package/src/themes/registry.ts +184 -0
  108. package/src/themes/types.ts +213 -0
  109. package/src/core/utils/codeGenerator/CodeGenerator.ts +0 -669
  110. package/src/core/utils/codeGenerator/index.ts +0 -13
  111. package/src/core/utils/codeGenerator/types.ts +0 -198
  112. package/src/core/utils/configGenerator/ConfigGenerator.ts +0 -583
  113. package/src/core/utils/configGenerator/index.ts +0 -13
  114. package/src/core/utils/configGenerator/types.ts +0 -449
  115. package/src/core/utils/debug/DebugPanel.tsx +0 -640
  116. package/src/core/utils/debug/debugger.ts +0 -322
  117. package/src/core/utils/debug/index.ts +0 -21
  118. package/src/core/utils/debug/types.ts +0 -142
@@ -1,607 +1,49 @@
1
1
  /**
2
- * TaroViz React Hooks - 增强版
3
- * 提供与图表相关的 React Hooks
2
+ * TaroViz React Hooks
3
+ * 此文件为纯 re-export 入口,各 Hook 实现在独立文件中。
4
4
  */
5
- import { useState, useEffect, useMemo, useCallback, useRef } from 'react';
6
- import { getAdapter } from '../adapters';
7
- import { getThemeByName } from '../themes';
8
- import type { EChartsOption } from 'echarts';
9
- import { useDataZoom } from './useDataZoom';
10
- import { useChartConnect } from './useChartConnect';
11
- import { useChartDownload } from './useChartDownload';
12
- import { useChartHistory } from './useChartHistory';
13
- import { useChartSelection } from './useChartSelection';
14
- // 复用 types.ts 中的共享类型
15
- import type { ChartInstance, EventHandler, LoadingOptions } from './types';
16
-
17
- // ============================================================================
18
- // 类型定义
19
- // ============================================================================
20
-
21
- /** 图表配置 */
22
- export interface ChartConfig {
23
- width?: number | string;
24
- height?: number | string;
25
- renderer?: 'canvas' | 'svg';
26
- theme?: string | Record<string, unknown>;
27
- [key: string]: unknown;
28
- }
29
-
30
- /** 数据转换器 */
31
- export type DataTransformer<T = unknown> = (data: T) => EChartsOption;
32
-
33
- /** 响应式断点 */
34
- export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
35
-
36
- /** 断点配置 */
37
- export interface BreakpointConfig {
38
- width: number;
39
- }
40
-
41
- /** 主题切换回调 */
42
- export type ThemeChangeCallback = (theme: string | Record<string, unknown>) => void;
43
-
44
- // ============================================================================
45
- // Hooks
46
- // ============================================================================
47
-
48
- /**
49
- * 使用图表 Hook
50
- * @param chartRef 图表容器的引用
51
- * @param config 图表配置
52
- * @returns [图表实例, 设置实例函数, 是否已初始化]
53
- */
54
- export function useChart(
55
- chartRef: React.RefObject<HTMLElement>,
56
- config?: ChartConfig
57
- ): [ChartInstance | null, React.Dispatch<React.SetStateAction<ChartInstance | null>>, boolean] {
58
- const [instance, setInstance] = useState<ChartInstance | null>(null);
59
- const [initialized, setInitialized] = useState(false);
60
- const configRef = useRef(config);
61
- configRef.current = config;
62
-
63
- useEffect(() => {
64
- if (!chartRef.current || instance) {
65
- return;
66
- }
67
-
68
- const initAdapter = async () => {
69
- try {
70
- const adapter = await getAdapter(configRef.current || {});
71
- const chartInstance = adapter as unknown as ChartInstance;
72
- setInstance(chartInstance);
73
- setInitialized(true);
74
- } catch (error) {
75
- console.error('Failed to initialize chart:', error);
76
- }
77
- };
78
-
79
- initAdapter();
80
-
81
- return () => {
82
- if (instance) {
83
- try {
84
- const inst = instance as ChartInstance;
85
- if (!inst.isDisposed?.()) {
86
- inst.dispose();
87
- }
88
- } catch (e) {
89
- console.warn('Failed to dispose chart instance:', e);
90
- }
91
- setInstance(null);
92
- setInitialized(false);
93
- }
94
- };
95
- }, [chartRef]);
96
-
97
- return [instance, setInstance, initialized];
98
- }
99
-
100
- /**
101
- * 设置图表选项 Hook
102
- * @param instance 图表实例
103
- * @param option 图表选项
104
- * @param options 配置选项
105
- */
106
- export function useOption(
107
- instance: ChartInstance | null,
108
- option: EChartsOption | null,
109
- options?: {
110
- /** 是否不合并 */
111
- notMerge?: boolean;
112
- /** 是否延迟更新 */
113
- lazyUpdate?: boolean;
114
- /** 是否在数据变化时替换 */
115
- replaceMerge?: string[];
116
- /** 依赖数组 */
117
- deps?: unknown[];
118
- }
119
- ) {
120
- const { notMerge = false, lazyUpdate = false, replaceMerge, deps = [] } = options || {};
121
-
122
- useEffect(() => {
123
- if (instance && option) {
124
- try {
125
- instance.setOption(option, notMerge, lazyUpdate);
126
- } catch (e) {
127
- console.warn('Failed to set chart option:', e);
128
- }
129
- }
130
- }, [instance, option, notMerge, lazyUpdate, replaceMerge, ...deps]);
131
- }
132
-
133
- /**
134
- * 图表自适应 Hook
135
- * @param instance 图表实例
136
- * @param options 配置选项
137
- */
138
- export function useResize(
139
- instance: ChartInstance | null,
140
- options?: {
141
- /** 延迟时间 (ms) */
142
- delay?: number;
143
- /** 最小宽度 */
144
- minWidth?: number;
145
- /** 最小高度 */
146
- minHeight?: number;
147
- /** 是否启用 */
148
- enabled?: boolean;
149
- }
150
- ) {
151
- const { delay = 300, minWidth, minHeight, enabled = true } = options || {};
152
- const timeoutRef = useRef<NodeJS.Timeout>();
153
-
154
- useEffect(() => {
155
- if (!instance || !enabled) {
156
- return;
157
- }
158
-
159
- const handleResize = () => {
160
- if (timeoutRef.current) {
161
- clearTimeout(timeoutRef.current);
162
- }
163
-
164
- timeoutRef.current = setTimeout(() => {
165
- try {
166
- const dom = instance.getDom?.();
167
- if (dom) {
168
- const { clientWidth, clientHeight } = dom;
169
- if (minWidth && clientWidth < minWidth) return;
170
- if (minHeight && clientHeight < minHeight) return;
171
- }
172
- instance.resize?.();
173
- } catch (e) {
174
- console.warn('Failed to resize chart:', e);
175
- }
176
- }, delay);
177
- };
178
-
179
- window.addEventListener('resize', handleResize);
180
-
181
- // 创建一个 ResizeObserver 来监听容器大小变化
182
- const dom = instance.getDom?.();
183
- if (dom && typeof ResizeObserver !== 'undefined') {
184
- const observer = new ResizeObserver(handleResize);
185
- observer.observe(dom);
186
- return () => {
187
- observer.disconnect();
188
- window.removeEventListener('resize', handleResize);
189
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
190
- };
191
- }
192
-
193
- return () => {
194
- window.removeEventListener('resize', handleResize);
195
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
196
- };
197
- }, [instance, delay, minWidth, minHeight, enabled]);
198
- }
199
-
200
- /**
201
- * 图表事件 Hook
202
- * @param instance 图表实例
203
- * @param events 事件对象
204
- */
205
- export function useEvents(instance: ChartInstance | null, events: Record<string, EventHandler>) {
206
- useEffect(() => {
207
- if (!instance || !events) {
208
- return;
209
- }
210
-
211
- const eventEntries = Object.entries(events);
212
-
213
- // 绑定事件
214
- eventEntries.forEach(([eventName, handler]) => {
215
- try {
216
- instance.on(eventName, handler);
217
- } catch (e) {
218
- console.warn(`Failed to bind event ${eventName}:`, e);
219
- }
220
- });
221
-
222
- // 清理事件
223
- return () => {
224
- eventEntries.forEach(([eventName, handler]) => {
225
- try {
226
- instance.off(eventName, handler);
227
- } catch (e) {
228
- console.warn(`Failed to unbind event ${eventName}:`, e);
229
- }
230
- });
231
- };
232
- }, [instance, events]);
233
- }
234
-
235
- /**
236
- * 图表加载状态 Hook
237
- * @param instance 图表实例
238
- * @param loading 是否加载中
239
- * @param options 加载选项
240
- */
241
- export function useLoading(
242
- instance: ChartInstance | null,
243
- loading: boolean,
244
- options?: LoadingOptions
245
- ) {
246
- useEffect(() => {
247
- if (!instance) {
248
- return;
249
- }
250
-
251
- try {
252
- if (loading) {
253
- instance.showLoading(options);
254
- } else {
255
- instance.hideLoading();
256
- }
257
- } catch (e) {
258
- console.warn('Failed to set chart loading state:', e);
259
- }
260
- }, [instance, loading, options]);
261
- }
262
-
263
- /**
264
- * 使用图表主题
265
- * @param theme 主题名称或配置
266
- * @param darkMode 是否为暗色模式
267
- * @returns 处理后的主题
268
- */
269
- export function useChartTheme(theme: string | Record<string, unknown>, darkMode = false) {
270
- return useMemo(() => {
271
- if (typeof theme === 'string') {
272
- // 如果是字符串,尝试获取内置主题配置
273
- try {
274
- const builtinTheme = getThemeByName(theme);
275
- return builtinTheme || (darkMode ? 'dark' : theme);
276
- } catch {
277
- return darkMode ? 'dark' : theme;
278
- }
279
- }
280
- return theme;
281
- }, [theme, darkMode]);
282
- }
283
-
284
- /**
285
- * 使用图表数据变更
286
- * @param data 数据源
287
- * @param transformer 数据转换函数
288
- * @returns 转换后的图表选项
289
- */
290
- export function useChartData<T = unknown>(data: T | null, transformer: DataTransformer<T>) {
291
- return useMemo(() => {
292
- if (!data || (Array.isArray(data) && data.length === 0)) {
293
- return {};
294
- }
295
- return transformer(data);
296
- }, [data, transformer]);
297
- }
298
-
299
- /**
300
- * 使用响应式图表配置
301
- * @param config 响应式配置
302
- * @returns 当前断点和配置
303
- */
304
- export function useResponsive(config?: {
305
- /** 断点配置 */
306
- breakpoints?: Record<Breakpoint, number>;
307
- /** 默认断点 */
308
- defaultBreakpoint?: Breakpoint;
309
- }) {
310
- const { breakpoints = { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200 }, defaultBreakpoint = 'md' } =
311
- config || {};
312
-
313
- const [breakpoint, setBreakpoint] = useState<Breakpoint>(defaultBreakpoint);
314
- const [windowSize, setWindowSize] = useState({ width: 0, height: 0 });
315
-
316
- useEffect(() => {
317
- const handleResize = () => {
318
- const width = window.innerWidth;
319
- setWindowSize({ width, height: window.innerHeight });
320
-
321
- // 确定当前断点
322
- let current: Breakpoint = 'xs';
323
- if (width >= breakpoints.xl) current = 'xl';
324
- else if (width >= breakpoints.lg) current = 'lg';
325
- else if (width >= breakpoints.md) current = 'md';
326
- else if (width >= breakpoints.sm) current = 'sm';
327
-
328
- setBreakpoint(current);
329
- };
330
-
331
- handleResize();
332
- window.addEventListener('resize', handleResize);
333
-
334
- return () => window.removeEventListener('resize', handleResize);
335
- }, [breakpoints]);
336
-
337
- return { breakpoint, windowSize };
338
- }
339
-
340
- /**
341
- * 使用主题切换
342
- * @param initialTheme 初始主题
343
- * @returns [当前主题, 切换主题函数]
344
- */
345
- export function useThemeSwitcher(initialTheme = 'default') {
346
- const [theme, setTheme] = useState<string | Record<string, unknown>>(initialTheme);
347
- const [isDark, setIsDark] = useState(false);
348
-
349
- const switchTheme = useCallback((newTheme: string | Record<string, unknown>) => {
350
- setTheme(newTheme);
351
- if (typeof newTheme === 'string') {
352
- setIsDark(newTheme === 'dark' || newTheme.includes('dark'));
353
- }
354
- }, []);
355
-
356
- const toggleDark = useCallback(() => {
357
- setIsDark((prev) => !prev);
358
- setTheme((prev) => (prev === 'dark' ? 'default' : 'dark'));
359
- }, []);
360
-
361
- return { theme, isDark, switchTheme, toggleDark, setTheme };
362
- }
363
-
364
- /**
365
- * 使用数据轮询
366
- * @param fetchFn 数据获取函数
367
- * @param options 配置选项
368
- * @returns [数据, 加载状态, 错误, 刷新函数]
369
- */
370
- export function useDataPolling<T>(
371
- fetchFn: () => Promise<T>,
372
- options?: {
373
- /** 轮询间隔 (ms) */
374
- interval?: number;
375
- /** 是否自动开始 */
376
- autoStart?: boolean;
377
- /** 错误重试次数 */
378
- retryCount?: number;
379
- /** 重试延迟 (ms) */
380
- retryDelay?: number;
381
- }
382
- ) {
383
- const { interval = 5000, autoStart = false, retryCount = 3, retryDelay = 1000 } = options || {};
384
-
385
- const [data, setData] = useState<T | null>(null);
386
- const [loading, setLoading] = useState(autoStart);
387
- const [error, setError] = useState<Error | null>(null);
388
-
389
- // 用于取消进行中的请求
390
- const abortRef = useRef<{ cancelled: boolean }>({ cancelled: false });
391
-
392
- const fetchData = useCallback(async () => {
393
- // 取消之前的请求
394
- abortRef.current.cancelled = true;
395
- // 创建新的取消标记
396
- abortRef.current = { cancelled: false };
397
- const currentAbort = abortRef.current;
398
-
399
- let retries = retryCount;
400
- setLoading(true);
401
- setError(null);
402
-
403
- // retryCount < 0 表示不重试,直接一次请求
404
- if (retryCount < 0) {
405
- try {
406
- const result = await fetchFn();
407
- if (!currentAbort.cancelled) {
408
- setData(result);
409
- setLoading(false);
410
- }
411
- } catch (e) {
412
- if (!currentAbort.cancelled) {
413
- setError(e as Error);
414
- setLoading(false);
415
- }
416
- }
417
- return;
418
- }
419
-
420
- // retryCount >= 0:循环重试
421
- while (retries > 0 && !currentAbort.cancelled) {
422
- try {
423
- const result = await fetchFn();
424
- if (!currentAbort.cancelled) {
425
- setData(result);
426
- setLoading(false);
427
- }
428
- return;
429
- } catch (e) {
430
- retries--;
431
- if (retries <= 0 || currentAbort.cancelled) {
432
- if (!currentAbort.cancelled) {
433
- setError(e as Error);
434
- }
435
- setLoading(false);
436
- return;
437
- }
438
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
439
- }
440
- }
441
- }, [fetchFn, retryCount, retryDelay]);
442
5
 
443
- useEffect(() => {
444
- if (autoStart) {
445
- fetchData();
446
- }
447
-
448
- if (interval > 0) {
449
- const timer = setInterval(fetchData, interval);
450
- return () => {
451
- clearInterval(timer);
452
- abortRef.current.cancelled = true;
453
- };
454
- }
455
-
456
- return () => {
457
- abortRef.current.cancelled = true;
458
- };
459
- }, [interval, autoStart, fetchData]);
460
-
461
- const refresh = useCallback(() => {
462
- fetchData();
463
- }, [fetchData]);
464
-
465
- return { data, loading, error, refresh };
466
- }
467
-
468
- /**
469
- * 使用图表全屏
470
- * @param chartRef 图表容器引用
471
- * @returns [是否全屏, 进入/退出全屏函数]
472
- */
473
- export function useFullscreen(chartRef: React.RefObject<HTMLElement>) {
474
- const [isFullscreen, setIsFullscreen] = useState(false);
475
-
476
- const toggle = useCallback(() => {
477
- if (!chartRef.current) return;
478
-
479
- if (!isFullscreen) {
480
- if (chartRef.current.requestFullscreen) {
481
- chartRef.current.requestFullscreen();
482
- }
483
- } else {
484
- if (document.exitFullscreen) {
485
- document.exitFullscreen();
486
- }
487
- }
488
- }, [chartRef, isFullscreen]);
489
-
490
- useEffect(() => {
491
- const handleChange = () => {
492
- setIsFullscreen(!!document.fullscreenElement);
493
- };
494
-
495
- document.addEventListener('fullscreenchange', handleChange);
496
- return () => document.removeEventListener('fullscreenchange', handleChange);
497
- }, []);
498
-
499
- return { isFullscreen, toggle };
500
- }
501
-
502
- /**
503
- * 使用图表导出
504
- * @param instance 图表实例
505
- * @returns 导出函数
506
- */
507
- export function useExport(instance: ChartInstance | null) {
508
- const inst = instance as ChartInstance;
509
- const exportImage = useCallback(
510
- (options?: { type?: 'png' | 'jpeg'; pixelRatio?: number; backgroundColor?: string }) => {
511
- if (!inst) return null;
512
- const { type = 'png', pixelRatio = 2, backgroundColor } = options || {};
513
- return inst.getDataURL?.({ type, pixelRatio, backgroundColor });
514
- },
515
- [inst]
516
- );
517
-
518
- const exportSVG = useCallback(() => {
519
- if (!inst) return null;
520
- return inst.getSvgData?.();
521
- }, [inst]);
522
-
523
- const exportCSV = useCallback(
524
- (options?: { seriesIndex?: number; dimension?: number }) => {
525
- if (!inst) return null;
526
- return inst.getCompressedDataURL?.(options);
527
- },
528
- [inst]
529
- );
530
-
531
- return { exportImage, exportSVG, exportCSV };
532
- }
533
-
534
- /**
535
- * 使用图表工具
536
- * @param instance 图表实例
537
- * @returns 工具函数
538
- */
539
- export function useChartTools(instance: ChartInstance | null) {
540
- const inst = instance as ChartInstance;
541
- const getInstance = useCallback(() => instance, [instance]);
542
-
543
- const clear = useCallback(() => {
544
- inst?.clear?.();
545
- }, [inst]);
546
-
547
- const repaint = useCallback(() => {
548
- inst?.resize?.();
549
- }, [inst]);
550
-
551
- const dispatchAction = useCallback(
552
- (action: { type: string; [key: string]: unknown }) => {
553
- inst?.dispatchAction?.(action);
554
- },
555
- [inst]
556
- );
557
-
558
- const showTip = useCallback(
559
- (seriesIndex?: number, dataIndex?: number) => {
560
- inst?.dispatchAction?.({ type: 'showTip', seriesIndex, dataIndex });
561
- },
562
- [inst]
563
- );
564
-
565
- const hideTip = useCallback(() => {
566
- inst?.dispatchAction?.({ type: 'hideTip' });
567
- }, [inst]);
568
-
569
- const zoom = useCallback(
570
- (start?: number, end?: number) => {
571
- inst?.dispatchAction?.({
572
- type: 'dataZoom',
573
- start: start ?? 0,
574
- end: end ?? 100,
575
- });
576
- },
577
- [inst]
578
- );
579
-
580
- return { getInstance, clear, repaint, dispatchAction, showTip, hideTip, zoom };
581
- }
582
-
583
- // ============================================================================
584
- // v1.7.0 新增 Hooks
585
- // ============================================================================
586
-
587
- // 数据缩放 Hook
6
+ // Types
7
+ export type {
8
+ ChartConfig,
9
+ DataTransformer,
10
+ Breakpoint,
11
+ BreakpointConfig,
12
+ ThemeChangeCallback,
13
+ ChartInstance,
14
+ EventHandler,
15
+ LoadingOptions,
16
+ } from './types';
17
+
18
+ // Core hooks
19
+ export { useChart } from './useChartInit';
20
+ export {
21
+ useOption,
22
+ useEvents,
23
+ useLoading,
24
+ useResponsive,
25
+ useFullscreen,
26
+ useExport,
27
+ useChartTools,
28
+ } from './useChartOptions';
29
+ export { useResize } from './useChartAutoResize';
30
+ export { useChartTheme, useThemeSwitcher } from './useChartTheme';
31
+ export { useDataPolling } from './useChartPerformance';
588
32
  export {
589
- useDataZoom,
590
- type UseDataZoomOptions,
591
- type UseDataZoomReturn,
592
- type DataZoomType,
593
- type ZoomRange,
594
- } from './useDataZoom';
33
+ useChartData,
34
+ useDataTransform,
35
+ useTableTransform,
36
+ useTimeSeriesTransform,
37
+ useTransform,
38
+ } from './useDataTransform';
595
39
 
596
- // 图表联动 Hook
40
+ // v1.7.0 hooks
597
41
  export {
598
42
  useChartConnect,
599
43
  type UseChartConnectOptions,
600
44
  type UseChartConnectReturn,
601
45
  type ConnectEventType,
602
46
  } from './useChartConnect';
603
-
604
- // 图表下载 Hook
605
47
  export {
606
48
  useChartDownload,
607
49
  type UseChartDownloadOptions,
@@ -610,8 +52,6 @@ export {
610
52
  type DownloadImageOptions,
611
53
  type DownloadDataOptions,
612
54
  } from './useChartDownload';
613
-
614
- // 图表下载工具函数
615
55
  export {
616
56
  generateFilename,
617
57
  downloadBlob,
@@ -622,8 +62,6 @@ export {
622
62
  convertToJSON,
623
63
  createPdfFromImage,
624
64
  } from './utils/chartDownloadUtils';
625
-
626
- // 数据转换工具函数(类型导出)
627
65
  export type {
628
66
  DataItem,
629
67
  DataSource,
@@ -631,8 +69,6 @@ export type {
631
69
  TimePeriod,
632
70
  TransformMapping,
633
71
  } from './utils/dataTransformUtils';
634
-
635
- // 数据转换工具函数(值导出)
636
72
  export {
637
73
  transformLineOrBar,
638
74
  transformPie,
@@ -642,15 +78,11 @@ export {
642
78
  groupByTime,
643
79
  aggregateValues,
644
80
  } from './utils/dataTransformUtils';
645
-
646
- // 图表历史记录 Hook (Undo/Redo)
647
81
  export {
648
82
  useChartHistory,
649
83
  type UseChartHistoryOptions,
650
84
  type UseChartHistoryReturn,
651
85
  } from './useChartHistory';
652
-
653
- // 图表选择 Hook
654
86
  export {
655
87
  useChartSelection,
656
88
  type UseChartSelectionOptions,
@@ -660,20 +92,27 @@ export {
660
92
  type SelectionEvent,
661
93
  } from './useChartSelection';
662
94
 
663
- // ============================================================================
664
- // 导出
665
- // ============================================================================
666
-
667
- // 版本信息
95
+ // Version
668
96
  export { VERSION as version } from '../core/version';
669
97
 
670
- // 新增数据转换 hooks
671
- export {
672
- useDataTransform,
673
- useTableTransform,
674
- useTimeSeriesTransform,
675
- useTransform,
676
- } from './useDataTransform';
98
+ // Default export for backward compatibility
99
+ import { useChart } from './useChartInit';
100
+ import {
101
+ useOption,
102
+ useEvents,
103
+ useLoading,
104
+ useResponsive,
105
+ useFullscreen,
106
+ useExport,
107
+ useChartTools,
108
+ } from './useChartOptions';
109
+ import { useResize } from './useChartAutoResize';
110
+ import { useChartTheme, useThemeSwitcher } from './useChartTheme';
111
+ import { useDataPolling } from './useChartPerformance';
112
+ import { useChartConnect } from './useChartConnect';
113
+ import { useChartDownload } from './useChartDownload';
114
+ import { useChartHistory } from './useChartHistory';
115
+ import { useChartSelection } from './useChartSelection';
677
116
 
678
117
  export default {
679
118
  useChart,
@@ -682,25 +121,14 @@ export default {
682
121
  useEvents,
683
122
  useLoading,
684
123
  useChartTheme,
685
- useChartData,
686
124
  useResponsive,
687
125
  useThemeSwitcher,
688
126
  useDataPolling,
689
127
  useFullscreen,
690
128
  useExport,
691
129
  useChartTools,
692
- // v1.7.0 新增
693
- useDataZoom,
694
130
  useChartConnect,
695
131
  useChartDownload,
696
132
  useChartHistory,
697
133
  useChartSelection,
698
134
  };
699
-
700
- // 性能优化 Hooks
701
- export {
702
- useDebounce,
703
- useThrottle,
704
- useAnimationFrame,
705
- useWindowSizeDebounce,
706
- } from './usePerformanceHooks';