@agions/taroviz 1.1.1 → 1.2.1

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 (81) hide show
  1. package/README.md +324 -53
  2. package/dist/cjs/index.js +1 -0
  3. package/dist/esm/index.js +82979 -0
  4. package/package.json +160 -30
  5. package/src/__tests__/integration.test.tsx +168 -0
  6. package/src/adapters/__tests__/index.test.ts +91 -0
  7. package/src/adapters/h5/__tests__/index.test.ts +156 -0
  8. package/src/adapters/h5/index.ts +301 -0
  9. package/src/adapters/harmony/index.ts +274 -0
  10. package/src/adapters/index.ts +166 -0
  11. package/src/adapters/swan/index.ts +274 -0
  12. package/src/adapters/tt/index.ts +274 -0
  13. package/src/adapters/types.ts +162 -0
  14. package/src/adapters/weapp/index.ts +237 -0
  15. package/src/charts/bar/__tests__/index.test.tsx +113 -0
  16. package/src/charts/bar/index.tsx +18 -0
  17. package/src/charts/common/BaseChartWrapper.tsx +136 -0
  18. package/src/charts/funnel/index.tsx +18 -0
  19. package/src/charts/gauge/index.tsx +18 -0
  20. package/src/charts/heatmap/index.tsx +18 -0
  21. package/src/charts/index.ts +21 -0
  22. package/src/charts/line/__tests__/index.test.tsx +107 -0
  23. package/src/charts/line/index.tsx +18 -0
  24. package/src/charts/pie/__tests__/index.test.tsx +112 -0
  25. package/src/charts/pie/index.tsx +19 -0
  26. package/src/charts/radar/index.tsx +18 -0
  27. package/src/charts/scatter/index.tsx +18 -0
  28. package/src/charts/types.ts +619 -0
  29. package/src/charts/utils.ts +56 -0
  30. package/src/core/__tests__/platform.test.ts +48 -0
  31. package/src/core/animation/AnimationManager.ts +391 -0
  32. package/src/core/animation/index.ts +20 -0
  33. package/src/core/animation/types.ts +248 -0
  34. package/src/core/components/BaseChart.tsx +1313 -0
  35. package/src/core/components/ErrorBoundary.tsx +458 -0
  36. package/src/core/echarts.ts +58 -0
  37. package/src/core/index.ts +22 -0
  38. package/src/core/types/chart.ts +66 -0
  39. package/src/core/types/common.ts +224 -0
  40. package/src/core/types/index.ts +281 -0
  41. package/src/core/types/platform.ts +325 -0
  42. package/src/core/utils/__tests__/common.test.ts +52 -0
  43. package/src/core/utils/__tests__/environment.test.ts +94 -0
  44. package/src/core/utils/__tests__/i18n.test.ts +247 -0
  45. package/src/core/utils/__tests__/index.test.ts +219 -0
  46. package/src/core/utils/__tests__/uuid.test.ts +78 -0
  47. package/src/core/utils/chartInstances.ts +69 -0
  48. package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
  49. package/src/core/utils/codeGenerator/index.ts +13 -0
  50. package/src/core/utils/codeGenerator/types.ts +198 -0
  51. package/src/core/utils/common.ts +58 -0
  52. package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
  53. package/src/core/utils/configGenerator/index.ts +13 -0
  54. package/src/core/utils/configGenerator/types.ts +445 -0
  55. package/src/core/utils/debug/DebugPanel.tsx +637 -0
  56. package/src/core/utils/debug/debugger.ts +322 -0
  57. package/src/core/utils/debug/index.ts +21 -0
  58. package/src/core/utils/debug/types.ts +142 -0
  59. package/src/core/utils/i18n.ts +452 -0
  60. package/src/core/utils/index.ts +162 -0
  61. package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
  62. package/src/core/utils/performance/index.ts +13 -0
  63. package/src/core/utils/performance/types.ts +180 -0
  64. package/src/core/utils/uuid.ts +30 -0
  65. package/src/editor/ThemeEditor.tsx +449 -0
  66. package/src/editor/index.ts +10 -0
  67. package/src/hooks/__tests__/index.test.tsx +333 -0
  68. package/src/hooks/index.ts +594 -0
  69. package/src/index.ts +75 -0
  70. package/src/main.tsx +247 -0
  71. package/src/react-dom.d.ts +7 -0
  72. package/src/themes/__tests__/index.test.ts +91 -0
  73. package/src/themes/index.ts +860 -0
  74. package/dist/389.index.esm.js +0 -1
  75. package/dist/389.index.js +0 -1
  76. package/dist/633.index.esm.js +0 -1
  77. package/dist/633.index.js +0 -1
  78. package/dist/967.index.esm.js +0 -1
  79. package/dist/967.index.js +0 -1
  80. package/dist/index.esm.js +0 -1
  81. package/dist/index.js +0 -1
@@ -0,0 +1,391 @@
1
+ /**
2
+ * TaroViz 动画管理器
3
+ * 负责管理图表动画的配置、预设和执行
4
+ */
5
+
6
+ import {
7
+ AnimationConfig,
8
+ AnimationPreset,
9
+ AnimationTemplate,
10
+ AnimationManagerConfig,
11
+ AnimationType,
12
+ AnimationEventType,
13
+ } from './types';
14
+
15
+ /**
16
+ * 动画预设集合
17
+ */
18
+ const DEFAULT_ANIMATION_PRESETS: AnimationPreset[] = [
19
+ {
20
+ name: 'default',
21
+ description: '默认动画配置',
22
+ config: {
23
+ enabled: true,
24
+ duration: 1000,
25
+ easing: 'cubicOut',
26
+ appearDuration: 1200,
27
+ appearEasing: 'cubicOut',
28
+ updateDuration: 800,
29
+ updateEasing: 'cubicOut',
30
+ disappearDuration: 600,
31
+ disappearEasing: 'cubicIn',
32
+ threshold: 1000,
33
+ progressive: true,
34
+ progressiveStep: 500,
35
+ },
36
+ },
37
+ {
38
+ name: 'fast',
39
+ description: '快速动画配置',
40
+ config: {
41
+ enabled: true,
42
+ duration: 500,
43
+ easing: 'linear',
44
+ appearDuration: 600,
45
+ appearEasing: 'linear',
46
+ updateDuration: 400,
47
+ updateEasing: 'linear',
48
+ disappearDuration: 300,
49
+ disappearEasing: 'linear',
50
+ threshold: 2000,
51
+ progressive: true,
52
+ progressiveStep: 1000,
53
+ },
54
+ },
55
+ {
56
+ name: 'slow',
57
+ description: '慢速动画配置',
58
+ config: {
59
+ enabled: true,
60
+ duration: 2000,
61
+ easing: 'cubicInOut',
62
+ appearDuration: 2400,
63
+ appearEasing: 'cubicInOut',
64
+ updateDuration: 1600,
65
+ updateEasing: 'cubicInOut',
66
+ disappearDuration: 1200,
67
+ disappearEasing: 'cubicInOut',
68
+ threshold: 500,
69
+ progressive: true,
70
+ progressiveStep: 250,
71
+ },
72
+ },
73
+ {
74
+ name: 'bounce',
75
+ description: '弹跳动画配置',
76
+ config: {
77
+ enabled: true,
78
+ duration: 1500,
79
+ easing: 'bounceOut',
80
+ appearDuration: 1800,
81
+ appearEasing: 'bounceOut',
82
+ updateDuration: 1200,
83
+ updateEasing: 'bounceOut',
84
+ disappearDuration: 900,
85
+ disappearEasing: 'bounceIn',
86
+ threshold: 500,
87
+ progressive: true,
88
+ progressiveStep: 250,
89
+ },
90
+ },
91
+ {
92
+ name: 'elastic',
93
+ description: '弹性动画配置',
94
+ config: {
95
+ enabled: true,
96
+ duration: 1500,
97
+ easing: 'elasticOut',
98
+ appearDuration: 1800,
99
+ appearEasing: 'elasticOut',
100
+ updateDuration: 1200,
101
+ updateEasing: 'elasticOut',
102
+ disappearDuration: 900,
103
+ disappearEasing: 'elasticIn',
104
+ threshold: 500,
105
+ progressive: true,
106
+ progressiveStep: 250,
107
+ },
108
+ },
109
+ ];
110
+
111
+ /**
112
+ * 动画管理器类
113
+ */
114
+ export class AnimationManager {
115
+ private static instance: AnimationManager;
116
+ private presets: Map<string, AnimationPreset> = new Map();
117
+ private templates: Map<string, AnimationTemplate> = new Map();
118
+ private defaultConfig: AnimationConfig;
119
+ private performanceConfig: AnimationManagerConfig['performance'];
120
+ private eventHandlers: Map<string, Set<(event: any) => void>> = new Map();
121
+
122
+ /**
123
+ * 私有构造函数
124
+ */
125
+ private constructor(config?: AnimationManagerConfig) {
126
+ // 初始化默认配置
127
+ this.defaultConfig = config?.defaultConfig || DEFAULT_ANIMATION_PRESETS[0].config;
128
+ this.performanceConfig = config?.performance || {
129
+ monitor: false,
130
+ frameRate: 60,
131
+ hardwareAcceleration: true,
132
+ };
133
+
134
+ // 注册默认预设
135
+ this.registerPresets(DEFAULT_ANIMATION_PRESETS);
136
+ }
137
+
138
+ /**
139
+ * 获取动画管理器实例
140
+ */
141
+ public static getInstance(config?: AnimationManagerConfig): AnimationManager {
142
+ if (!AnimationManager.instance) {
143
+ AnimationManager.instance = new AnimationManager(config);
144
+ }
145
+ return AnimationManager.instance;
146
+ }
147
+
148
+ /**
149
+ * 注册动画预设
150
+ */
151
+ public registerPreset(preset: AnimationPreset): void {
152
+ this.presets.set(preset.name, preset);
153
+ }
154
+
155
+ /**
156
+ * 批量注册动画预设
157
+ */
158
+ public registerPresets(presets: AnimationPreset[]): void {
159
+ presets.forEach((preset) => this.registerPreset(preset));
160
+ }
161
+
162
+ /**
163
+ * 获取动画预设
164
+ */
165
+ public getPreset(name: string): AnimationPreset | undefined {
166
+ return this.presets.get(name);
167
+ }
168
+
169
+ /**
170
+ * 获取所有动画预设
171
+ */
172
+ public getAllPresets(): AnimationPreset[] {
173
+ return Array.from(this.presets.values());
174
+ }
175
+
176
+ /**
177
+ * 注册动画模板
178
+ */
179
+ public registerTemplate(template: AnimationTemplate): void {
180
+ this.templates.set(template.name, template);
181
+ }
182
+
183
+ /**
184
+ * 获取动画模板
185
+ */
186
+ public getTemplate(name: string): AnimationTemplate | undefined {
187
+ return this.templates.get(name);
188
+ }
189
+
190
+ /**
191
+ * 获取所有动画模板
192
+ */
193
+ public getAllTemplates(): AnimationTemplate[] {
194
+ return Array.from(this.templates.values());
195
+ }
196
+
197
+ /**
198
+ * 设置默认动画配置
199
+ */
200
+ public setDefaultConfig(config: AnimationConfig): void {
201
+ this.defaultConfig = config;
202
+ }
203
+
204
+ /**
205
+ * 获取默认动画配置
206
+ */
207
+ public getDefaultConfig(): AnimationConfig {
208
+ return this.defaultConfig;
209
+ }
210
+
211
+ /**
212
+ * 根据数据量和动画类型获取优化后的动画配置
213
+ */
214
+ public getOptimizedConfig(
215
+ config: Partial<AnimationConfig> = {},
216
+ dataLength: number = 0
217
+ ): AnimationConfig {
218
+ // 合并配置:用户配置 > 默认配置
219
+ const mergedConfig: AnimationConfig = {
220
+ ...this.defaultConfig,
221
+ ...config,
222
+ };
223
+
224
+ // 根据数据量优化动画
225
+ if (mergedConfig.threshold && dataLength > mergedConfig.threshold) {
226
+ mergedConfig.enabled = false;
227
+ }
228
+
229
+ return mergedConfig;
230
+ }
231
+
232
+ /**
233
+ * 根据动画类型获取对应的动画配置
234
+ */
235
+ public getAnimationConfigByType(
236
+ config: AnimationConfig,
237
+ animationType: AnimationType
238
+ ): {
239
+ duration: number;
240
+ easing: string;
241
+ } {
242
+ switch (animationType) {
243
+ case 'appear':
244
+ return {
245
+ duration: config.appearDuration || config.duration || 1000,
246
+ easing: config.appearEasing || config.easing || 'cubicOut',
247
+ };
248
+ case 'update':
249
+ return {
250
+ duration: config.updateDuration || config.duration || 800,
251
+ easing: config.updateEasing || config.easing || 'cubicOut',
252
+ };
253
+ case 'disappear':
254
+ return {
255
+ duration: config.disappearDuration || config.duration || 600,
256
+ easing: config.disappearEasing || config.easing || 'cubicIn',
257
+ };
258
+ case 'emphasis':
259
+ return {
260
+ duration: config.duration || 300,
261
+ easing: config.easing || 'cubicOut',
262
+ };
263
+ default:
264
+ return {
265
+ duration: config.duration || 1000,
266
+ easing: config.easing || 'cubicOut',
267
+ };
268
+ }
269
+ }
270
+
271
+ /**
272
+ * 生成ECharts动画配置
273
+ */
274
+ public generateEChartsAnimationConfig(
275
+ config: Partial<AnimationConfig> = {},
276
+ dataLength: number = 0
277
+ ): any {
278
+ const optimizedConfig = this.getOptimizedConfig(config, dataLength);
279
+
280
+ if (!optimizedConfig.enabled) {
281
+ return {
282
+ animation: false,
283
+ };
284
+ }
285
+
286
+ return {
287
+ animation: true,
288
+ animationDuration: optimizedConfig.duration,
289
+ animationEasing: optimizedConfig.easing,
290
+ animationDelay: optimizedConfig.delay,
291
+ animationDurationUpdate: optimizedConfig.updateDuration,
292
+ animationEasingUpdate: optimizedConfig.updateEasing,
293
+ animationDelayUpdate: optimizedConfig.delay,
294
+ animationThreshold: optimizedConfig.threshold,
295
+ progressive: optimizedConfig.progressive,
296
+ progressiveThreshold: optimizedConfig.progressiveStep,
297
+ progressiveChunkMode: 'sequential',
298
+ };
299
+ }
300
+
301
+ /**
302
+ * 绑定动画事件
303
+ */
304
+ public on(eventType: AnimationEventType, handler: (event: any) => void): void {
305
+ if (!this.eventHandlers.has(eventType)) {
306
+ this.eventHandlers.set(eventType, new Set());
307
+ }
308
+ this.eventHandlers.get(eventType)?.add(handler);
309
+ }
310
+
311
+ /**
312
+ * 解绑动画事件
313
+ */
314
+ public off(eventType: AnimationEventType, handler?: (event: any) => void): void {
315
+ if (!handler) {
316
+ this.eventHandlers.delete(eventType);
317
+ return;
318
+ }
319
+ this.eventHandlers.get(eventType)?.delete(handler);
320
+ }
321
+
322
+ /**
323
+ * 触发动画事件
324
+ */
325
+ public emit(eventType: AnimationEventType, data: any): void {
326
+ const handlers = this.eventHandlers.get(eventType);
327
+ if (handlers) {
328
+ handlers.forEach((handler) => {
329
+ try {
330
+ handler(data);
331
+ } catch (error) {
332
+ console.error(`Error in animation event handler:`, error);
333
+ }
334
+ });
335
+ }
336
+ }
337
+
338
+ /**
339
+ * 更新性能配置
340
+ */
341
+ public updatePerformanceConfig(config: AnimationManagerConfig['performance']): void {
342
+ this.performanceConfig = {
343
+ ...this.performanceConfig,
344
+ ...config,
345
+ };
346
+ }
347
+
348
+ /**
349
+ * 获取性能配置
350
+ */
351
+ public getPerformanceConfig(): AnimationManagerConfig['performance'] {
352
+ return this.performanceConfig;
353
+ }
354
+
355
+ /**
356
+ * 重置动画管理器
357
+ */
358
+ public reset(): void {
359
+ this.presets.clear();
360
+ this.templates.clear();
361
+ this.eventHandlers.clear();
362
+ this.registerPresets(DEFAULT_ANIMATION_PRESETS);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * 创建动画配置
368
+ */
369
+ export function createAnimationConfig(config: Partial<AnimationConfig> = {}): AnimationConfig {
370
+ const manager = AnimationManager.getInstance();
371
+ return manager.getOptimizedConfig(config);
372
+ }
373
+
374
+ /**
375
+ * 获取动画预设配置
376
+ */
377
+ export function getAnimationPreset(name: string): AnimationPreset | undefined {
378
+ const manager = AnimationManager.getInstance();
379
+ return manager.getPreset(name);
380
+ }
381
+
382
+ /**
383
+ * 生成ECharts动画配置
384
+ */
385
+ export function generateEChartsAnimationConfig(
386
+ config: Partial<AnimationConfig> = {},
387
+ dataLength: number = 0
388
+ ): any {
389
+ const manager = AnimationManager.getInstance();
390
+ return manager.generateEChartsAnimationConfig(config, dataLength);
391
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * TaroViz 动画系统入口文件
3
+ */
4
+
5
+ // 导出类型定义
6
+ export * from './types';
7
+
8
+ // 导出动画管理器
9
+ export { AnimationManager } from './AnimationManager';
10
+
11
+ // 导出工具函数
12
+ export {
13
+ createAnimationConfig,
14
+ getAnimationPreset,
15
+ generateEChartsAnimationConfig,
16
+ } from './AnimationManager';
17
+
18
+ // 导出默认动画管理器实例
19
+ import { AnimationManager } from './AnimationManager';
20
+ export const animationManager = AnimationManager.getInstance();
@@ -0,0 +1,248 @@
1
+ /**
2
+ * TaroViz 动画系统核心类型定义
3
+ */
4
+
5
+ /**
6
+ * 动画缓动函数类型
7
+ */
8
+ export type AnimationEasing =
9
+ | 'linear'
10
+ | 'quadraticIn'
11
+ | 'quadraticOut'
12
+ | 'quadraticInOut'
13
+ | 'cubicIn'
14
+ | 'cubicOut'
15
+ | 'cubicInOut'
16
+ | 'quarticIn'
17
+ | 'quarticOut'
18
+ | 'quarticInOut'
19
+ | 'quinticIn'
20
+ | 'quinticOut'
21
+ | 'quinticInOut'
22
+ | 'sinusoidalIn'
23
+ | 'sinusoidalOut'
24
+ | 'sinusoidalInOut'
25
+ | 'exponentialIn'
26
+ | 'exponentialOut'
27
+ | 'exponentialInOut'
28
+ | 'circularIn'
29
+ | 'circularOut'
30
+ | 'circularInOut'
31
+ | 'elasticIn'
32
+ | 'elasticOut'
33
+ | 'elasticInOut'
34
+ | 'backIn'
35
+ | 'backOut'
36
+ | 'backInOut'
37
+ | 'bounceIn'
38
+ | 'bounceOut'
39
+ | 'bounceInOut';
40
+
41
+ /**
42
+ * 动画类型
43
+ */
44
+ export type AnimationType = 'appear' | 'update' | 'disappear' | 'emphasis' | 'all';
45
+
46
+ /**
47
+ * 动画配置接口
48
+ */
49
+ export interface AnimationConfig {
50
+ /**
51
+ * 是否启用动画
52
+ */
53
+ enabled?: boolean;
54
+
55
+ /**
56
+ * 动画时长(毫秒)
57
+ */
58
+ duration?: number;
59
+
60
+ /**
61
+ * 动画缓动函数
62
+ */
63
+ easing?: AnimationEasing;
64
+
65
+ /**
66
+ * 初始动画时长(毫秒)
67
+ */
68
+ appearDuration?: number;
69
+
70
+ /**
71
+ * 初始动画缓动函数
72
+ */
73
+ appearEasing?: AnimationEasing;
74
+
75
+ /**
76
+ * 更新动画时长(毫秒)
77
+ */
78
+ updateDuration?: number;
79
+
80
+ /**
81
+ * 更新动画缓动函数
82
+ */
83
+ updateEasing?: AnimationEasing;
84
+
85
+ /**
86
+ * 消失动画时长(毫秒)
87
+ */
88
+ disappearDuration?: number;
89
+
90
+ /**
91
+ * 消失动画缓动函数
92
+ */
93
+ disappearEasing?: AnimationEasing;
94
+
95
+ /**
96
+ * 动画延迟(毫秒)
97
+ */
98
+ delay?: number;
99
+
100
+ /**
101
+ * 动画重复次数
102
+ */
103
+ repeat?: number;
104
+
105
+ /**
106
+ * 是否反向播放动画
107
+ */
108
+ reverse?: boolean;
109
+
110
+ /**
111
+ * 动画阈值
112
+ * 当数据项数量超过此值时,自动关闭动画以提升性能
113
+ */
114
+ threshold?: number;
115
+
116
+ /**
117
+ * 是否启用渐进式动画
118
+ */
119
+ progressive?: boolean;
120
+
121
+ /**
122
+ * 渐进式动画的步长
123
+ */
124
+ progressiveStep?: number;
125
+ }
126
+
127
+ /**
128
+ * 动画预设配置
129
+ */
130
+ export interface AnimationPreset {
131
+ /**
132
+ * 预设名称
133
+ */
134
+ name: string;
135
+
136
+ /**
137
+ * 预设描述
138
+ */
139
+ description?: string;
140
+
141
+ /**
142
+ * 预设动画配置
143
+ */
144
+ config: AnimationConfig;
145
+
146
+ /**
147
+ * 适用的图表类型
148
+ */
149
+ chartTypes?: string[];
150
+ }
151
+
152
+ /**
153
+ * 动画模板配置
154
+ */
155
+ export interface AnimationTemplate {
156
+ /**
157
+ * 模板名称
158
+ */
159
+ name: string;
160
+
161
+ /**
162
+ * 模板描述
163
+ */
164
+ description?: string;
165
+
166
+ /**
167
+ * 模板动画配置
168
+ */
169
+ config: AnimationConfig;
170
+
171
+ /**
172
+ * 模板适用的场景
173
+ */
174
+ scenarios?: string[];
175
+ }
176
+
177
+ /**
178
+ * 动画管理器配置
179
+ */
180
+ export interface AnimationManagerConfig {
181
+ /**
182
+ * 默认动画配置
183
+ */
184
+ defaultConfig?: AnimationConfig;
185
+
186
+ /**
187
+ * 性能优化配置
188
+ */
189
+ performance?: {
190
+ /**
191
+ * 是否启用性能监控
192
+ */
193
+ monitor?: boolean;
194
+
195
+ /**
196
+ * 帧率限制
197
+ */
198
+ frameRate?: number;
199
+
200
+ /**
201
+ * 是否启用硬件加速
202
+ */
203
+ hardwareAcceleration?: boolean;
204
+ };
205
+ }
206
+
207
+ /**
208
+ * 动画事件类型
209
+ */
210
+ export enum AnimationEventType {
211
+ /**
212
+ * 动画开始事件
213
+ */
214
+ ANIMATION_START = 'animationStart',
215
+
216
+ /**
217
+ * 动画更新事件
218
+ */
219
+ ANIMATION_UPDATE = 'animationUpdate',
220
+
221
+ /**
222
+ * 动画结束事件
223
+ */
224
+ ANIMATION_END = 'animationEnd',
225
+
226
+ /**
227
+ * 动画取消事件
228
+ */
229
+ ANIMATION_CANCEL = 'animationCancel',
230
+
231
+ /**
232
+ * 动画重复事件
233
+ */
234
+ ANIMATION_REPEAT = 'animationRepeat',
235
+ }
236
+
237
+ /**
238
+ * 动画事件回调类型
239
+ */
240
+ export type AnimationEventHandler = (event: {
241
+ type: AnimationEventType;
242
+ animationType: AnimationType;
243
+ chartId?: string;
244
+ seriesIndex?: number;
245
+ dataIndex?: number;
246
+ timestamp: number;
247
+ duration: number;
248
+ }) => void;