@agions/taroviz 1.1.0 → 1.2.0

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 (73) hide show
  1. package/README.md +318 -53
  2. package/dist/index.esm.js +67955 -3318
  3. package/package.json +102 -20
  4. package/src/__tests__/integration.test.tsx +168 -0
  5. package/src/adapters/__tests__/index.test.ts +91 -0
  6. package/src/adapters/h5/__tests__/index.test.ts +156 -0
  7. package/src/adapters/h5/index.ts +301 -0
  8. package/src/adapters/harmony/index.ts +274 -0
  9. package/src/adapters/index.ts +234 -0
  10. package/src/adapters/swan/index.ts +274 -0
  11. package/src/adapters/tt/index.ts +274 -0
  12. package/src/adapters/types.ts +162 -0
  13. package/src/adapters/weapp/index.ts +237 -0
  14. package/src/charts/bar/__tests__/index.test.tsx +113 -0
  15. package/src/charts/bar/index.tsx +27 -0
  16. package/src/charts/common/BaseChartWrapper.tsx +136 -0
  17. package/src/charts/funnel/index.tsx +33 -0
  18. package/src/charts/gauge/index.tsx +33 -0
  19. package/src/charts/heatmap/index.tsx +33 -0
  20. package/src/charts/index.ts +21 -0
  21. package/src/charts/line/__tests__/index.test.tsx +107 -0
  22. package/src/charts/line/index.tsx +27 -0
  23. package/src/charts/pie/__tests__/index.test.tsx +112 -0
  24. package/src/charts/pie/index.tsx +22 -0
  25. package/src/charts/radar/index.tsx +33 -0
  26. package/src/charts/scatter/index.tsx +33 -0
  27. package/src/charts/types.ts +146 -0
  28. package/src/charts/utils.ts +56 -0
  29. package/src/core/__tests__/platform.test.ts +48 -0
  30. package/src/core/animation/AnimationManager.ts +391 -0
  31. package/src/core/animation/index.ts +20 -0
  32. package/src/core/animation/types.ts +248 -0
  33. package/src/core/components/BaseChart.tsx +1319 -0
  34. package/src/core/index.ts +19 -0
  35. package/src/core/types/chart.ts +66 -0
  36. package/src/core/types/common.ts +224 -0
  37. package/src/core/types/index.ts +281 -0
  38. package/src/core/types/platform.ts +325 -0
  39. package/src/core/utils/__tests__/common.test.ts +52 -0
  40. package/src/core/utils/__tests__/environment.test.ts +94 -0
  41. package/src/core/utils/__tests__/i18n.test.ts +247 -0
  42. package/src/core/utils/__tests__/index.test.ts +219 -0
  43. package/src/core/utils/__tests__/uuid.test.ts +78 -0
  44. package/src/core/utils/chartInstances.ts +69 -0
  45. package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
  46. package/src/core/utils/codeGenerator/index.ts +13 -0
  47. package/src/core/utils/codeGenerator/types.ts +200 -0
  48. package/src/core/utils/common.ts +58 -0
  49. package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
  50. package/src/core/utils/configGenerator/index.ts +13 -0
  51. package/src/core/utils/configGenerator/types.ts +445 -0
  52. package/src/core/utils/debug/DebugPanel.tsx +637 -0
  53. package/src/core/utils/debug/debugger.ts +322 -0
  54. package/src/core/utils/debug/index.ts +21 -0
  55. package/src/core/utils/debug/types.ts +142 -0
  56. package/src/core/utils/i18n.ts +452 -0
  57. package/src/core/utils/index.ts +162 -0
  58. package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
  59. package/src/core/utils/performance/index.ts +13 -0
  60. package/src/core/utils/performance/types.ts +180 -0
  61. package/src/core/utils/uuid.ts +30 -0
  62. package/src/editor/ThemeEditor.tsx +449 -0
  63. package/src/editor/index.ts +10 -0
  64. package/src/hooks/__tests__/index.test.tsx +333 -0
  65. package/src/hooks/index.ts +214 -0
  66. package/src/index.ts +75 -0
  67. package/src/main.tsx +247 -0
  68. package/src/react-dom.d.ts +7 -0
  69. package/src/themes/__tests__/index.test.ts +91 -0
  70. package/src/themes/index.ts +465 -0
  71. package/dist/index.esm.js.map +0 -1
  72. package/dist/index.js +0 -4012
  73. package/dist/index.js.map +0 -1
@@ -0,0 +1,465 @@
1
+ /**
2
+ * TaroViz 主题系统
3
+ * 提供图表主题配置和自定义主题功能
4
+ */
5
+
6
+ /**
7
+ * 内置主题类型
8
+ */
9
+ export type BuiltinTheme =
10
+ | 'default'
11
+ | 'light'
12
+ | 'dark'
13
+ | 'vintage'
14
+ | 'macarons'
15
+ | 'roma'
16
+ | 'shine'
17
+ | 'infographic'
18
+ | 'westeros'
19
+ | 'walden'
20
+ | 'chalk'
21
+ | 'purple-passion'
22
+ | 'blue-green'
23
+ | 'golden'
24
+ | 'forest';
25
+
26
+ /**
27
+ * 主题配置选项
28
+ */
29
+ export interface ThemeOptions {
30
+ /**
31
+ * 主题类型
32
+ */
33
+ theme?: BuiltinTheme | Record<string, any>;
34
+
35
+ /**
36
+ * 是否启用深色模式
37
+ */
38
+ darkMode?: boolean;
39
+
40
+ /**
41
+ * 颜色列表
42
+ */
43
+ colors?: string[];
44
+
45
+ /**
46
+ * 背景色
47
+ */
48
+ backgroundColor?: string;
49
+
50
+ /**
51
+ * 文本颜色
52
+ */
53
+ textColor?: string;
54
+
55
+ /**
56
+ * 字体
57
+ */
58
+ fontFamily?: string;
59
+
60
+ /**
61
+ * 主题名称
62
+ */
63
+ name?: string;
64
+
65
+ /**
66
+ * 主题描述
67
+ */
68
+ description?: string;
69
+
70
+ /**
71
+ * 主题作者
72
+ */
73
+ author?: string;
74
+
75
+ /**
76
+ * 主题版本
77
+ */
78
+ version?: string;
79
+
80
+ /**
81
+ * 主题类型
82
+ */
83
+ type?: 'light' | 'dark' | 'auto';
84
+
85
+ /**
86
+ * 图表特定配置
87
+ */
88
+ chart?: {
89
+ /**
90
+ * 图例配置
91
+ */
92
+ legend?: {
93
+ textColor?: string;
94
+ backgroundColor?: string;
95
+ borderColor?: string;
96
+ };
97
+
98
+ /**
99
+ * 坐标轴配置
100
+ */
101
+ axis?: {
102
+ textColor?: string;
103
+ lineColor?: string;
104
+ tickColor?: string;
105
+ splitLineColor?: string;
106
+ };
107
+
108
+ /**
109
+ * 提示框配置
110
+ */
111
+ tooltip?: {
112
+ textColor?: string;
113
+ backgroundColor?: string;
114
+ borderColor?: string;
115
+ };
116
+
117
+ /**
118
+ * 标题配置
119
+ */
120
+ title?: {
121
+ textColor?: string;
122
+ subTextColor?: string;
123
+ };
124
+ };
125
+ }
126
+
127
+ /**
128
+ * 主题注册表
129
+ */
130
+ const themeRegistry = new Map<string, ThemeOptions>();
131
+
132
+ /**
133
+ * 默认主题配置
134
+ */
135
+ export const defaultTheme: ThemeOptions = {
136
+ theme: 'default',
137
+ name: 'default',
138
+ description: '默认主题',
139
+ type: 'light',
140
+ darkMode: false,
141
+ colors: [
142
+ '#5470c6',
143
+ '#91cc75',
144
+ '#fac858',
145
+ '#ee6666',
146
+ '#73c0de',
147
+ '#3ba272',
148
+ '#fc8452',
149
+ '#9a60b4',
150
+ '#ea7ccc',
151
+ ],
152
+ backgroundColor: 'transparent',
153
+ textColor: '#333',
154
+ fontFamily:
155
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
156
+ };
157
+
158
+ /**
159
+ * 深色主题配置
160
+ */
161
+ export const darkTheme: ThemeOptions = {
162
+ theme: 'dark',
163
+ name: 'dark',
164
+ description: '深色主题',
165
+ type: 'dark',
166
+ darkMode: true,
167
+ colors: [
168
+ '#4992ff',
169
+ '#7cffb2',
170
+ '#fddd60',
171
+ '#ff6e76',
172
+ '#58d9f9',
173
+ '#05c091',
174
+ '#ff9f7f',
175
+ '#8d48e3',
176
+ '#dd79ff',
177
+ ],
178
+ backgroundColor: '#0f1117',
179
+ textColor: '#e1e1e1',
180
+ fontFamily:
181
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
182
+ };
183
+
184
+ /**
185
+ * Walden 主题配置
186
+ */
187
+ export const waldenTheme: ThemeOptions = {
188
+ theme: 'walden',
189
+ darkMode: false,
190
+ colors: [
191
+ '#0a437a',
192
+ '#3a84c4',
193
+ '#22a783',
194
+ '#48b591',
195
+ '#7fcdbb',
196
+ '#c9e4ca',
197
+ '#eef7d5',
198
+ '#fdf0d5',
199
+ '#fbb573',
200
+ '#f89540',
201
+ ],
202
+ backgroundColor: '#f0f8f5',
203
+ textColor: '#2c5042',
204
+ fontFamily:
205
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
206
+ };
207
+
208
+ /**
209
+ * Chalk 主题配置
210
+ */
211
+ export const chalkTheme: ThemeOptions = {
212
+ theme: 'chalk',
213
+ darkMode: false,
214
+ colors: [
215
+ '#2e8de5',
216
+ '#f0805a',
217
+ '#5ab1ef',
218
+ '#91d5ff',
219
+ '#faad14',
220
+ '#fadb14',
221
+ '#52c41a',
222
+ '#13c2c2',
223
+ '#722ed1',
224
+ '#eb2f96',
225
+ ],
226
+ backgroundColor: '#ffffff',
227
+ textColor: '#000000',
228
+ fontFamily:
229
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
230
+ };
231
+
232
+ /**
233
+ * Purple Passion 主题配置
234
+ */
235
+ export const purplePassionTheme: ThemeOptions = {
236
+ theme: 'purple-passion',
237
+ darkMode: false,
238
+ colors: [
239
+ '#9c27b0',
240
+ '#e91e63',
241
+ '#ff5722',
242
+ '#ff9800',
243
+ '#ffc107',
244
+ '#8bc34a',
245
+ '#4caf50',
246
+ '#009688',
247
+ '#00bcd4',
248
+ '#2196f3',
249
+ ],
250
+ backgroundColor: '#f5f5f5',
251
+ textColor: '#333333',
252
+ fontFamily:
253
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
254
+ };
255
+
256
+ /**
257
+ * Blue Green 主题配置
258
+ */
259
+ export const blueGreenTheme: ThemeOptions = {
260
+ theme: 'blue-green',
261
+ darkMode: false,
262
+ colors: [
263
+ '#00838f',
264
+ '#00acc1',
265
+ '#03a9f4',
266
+ '#29b6f6',
267
+ '#4fc3f7',
268
+ '#81d4fa',
269
+ '#b3e5fc',
270
+ '#e1f5fe',
271
+ '#80deea',
272
+ '#4dd0e1',
273
+ ],
274
+ backgroundColor: '#e0f7fa',
275
+ textColor: '#006064',
276
+ fontFamily:
277
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
278
+ };
279
+
280
+ /**
281
+ * Golden 主题配置
282
+ */
283
+ export const goldenTheme: ThemeOptions = {
284
+ theme: 'golden',
285
+ darkMode: false,
286
+ colors: [
287
+ '#ffd700',
288
+ '#ffed4e',
289
+ '#f9a825',
290
+ '#ffc107',
291
+ '#ffb300',
292
+ '#ffa000',
293
+ '#ff8f00',
294
+ '#ff6f00',
295
+ '#ff5722',
296
+ '#e64a19',
297
+ ],
298
+ backgroundColor: '#fff8e1',
299
+ textColor: '#ff6f00',
300
+ fontFamily:
301
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
302
+ };
303
+
304
+ /**
305
+ * Forest 主题配置
306
+ */
307
+ export const forestTheme: ThemeOptions = {
308
+ theme: 'forest',
309
+ darkMode: false,
310
+ colors: [
311
+ '#2e7d32',
312
+ '#388e3c',
313
+ '#43a047',
314
+ '#4caf50',
315
+ '#66bb6a',
316
+ '#81c784',
317
+ '#a5d6a7',
318
+ '#c8e6c9',
319
+ '#e8f5e8',
320
+ '#f1f8e9',
321
+ ],
322
+ backgroundColor: '#f1f8e9',
323
+ textColor: '#1b5e20',
324
+ fontFamily:
325
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
326
+ };
327
+
328
+ /**
329
+ * 获取主题配置
330
+ * @param options 自定义选项
331
+ * @returns 合并后的主题配置
332
+ */
333
+ export function getTheme(options?: Partial<ThemeOptions>): ThemeOptions {
334
+ if (!options) {
335
+ return defaultTheme;
336
+ }
337
+
338
+ // 如果提供了主题名称,尝试从注册表中获取
339
+ let baseTheme: ThemeOptions;
340
+ if (options.theme && typeof options.theme === 'string') {
341
+ const registeredTheme = themeRegistry.get(options.theme);
342
+ if (registeredTheme) {
343
+ baseTheme = registeredTheme;
344
+ } else {
345
+ // 如果主题不存在,使用默认主题
346
+ baseTheme = options.darkMode ? darkTheme : defaultTheme;
347
+ }
348
+ } else {
349
+ // 如果没有提供主题名称,使用默认主题或深色主题
350
+ baseTheme = options.darkMode ? darkTheme : defaultTheme;
351
+ }
352
+
353
+ return { ...baseTheme, ...options };
354
+ }
355
+
356
+ /**
357
+ * 注册主题
358
+ * @param name 主题名称
359
+ * @param theme 主题配置
360
+ */
361
+ export function registerTheme(name: string, theme: ThemeOptions): void {
362
+ // 注册主题到主题注册表
363
+ themeRegistry.set(name, {
364
+ ...theme,
365
+ name,
366
+ });
367
+ console.log(`Registering theme: ${name}`);
368
+ }
369
+
370
+ /**
371
+ * 获取已注册的主题列表
372
+ * @returns 主题列表
373
+ */
374
+ export function getRegisteredThemes(): ThemeOptions[] {
375
+ return Array.from(themeRegistry.values());
376
+ }
377
+
378
+ /**
379
+ * 获取指定主题
380
+ * @param name 主题名称
381
+ * @returns 主题配置
382
+ */
383
+ export function getThemeByName(name: string): ThemeOptions | undefined {
384
+ return themeRegistry.get(name);
385
+ }
386
+
387
+ /**
388
+ * 删除主题
389
+ * @param name 主题名称
390
+ */
391
+ export function unregisterTheme(name: string): void {
392
+ themeRegistry.delete(name);
393
+ console.log(`Theme unregistered: ${name}`);
394
+ }
395
+
396
+ /**
397
+ * 动态切换主题
398
+ * @param theme 主题名称或主题配置
399
+ * @param callback 切换完成后的回调函数
400
+ */
401
+ export function switchTheme(theme: string | ThemeOptions, callback?: () => void): ThemeOptions {
402
+ let themeConfig: ThemeOptions;
403
+
404
+ if (typeof theme === 'string') {
405
+ // 如果是主题名称,从注册表中获取
406
+ const registeredTheme = themeRegistry.get(theme);
407
+ if (registeredTheme) {
408
+ themeConfig = registeredTheme;
409
+ } else {
410
+ // 如果主题不存在,使用默认主题
411
+ themeConfig = defaultTheme;
412
+ }
413
+ } else {
414
+ // 如果是主题配置,直接使用
415
+ themeConfig = theme;
416
+ // 如果主题配置包含名称,注册到注册表
417
+ if (theme.name) {
418
+ registerTheme(theme.name, theme);
419
+ }
420
+ }
421
+
422
+ // 触发主题切换事件
423
+ const event = new CustomEvent('themeChange', {
424
+ detail: themeConfig,
425
+ });
426
+
427
+ // 检查是否在浏览器环境中
428
+ if (typeof window !== 'undefined') {
429
+ window.dispatchEvent(event);
430
+ }
431
+
432
+ // 调用回调函数
433
+ if (callback) {
434
+ callback();
435
+ }
436
+
437
+ return themeConfig;
438
+ }
439
+
440
+ // 注册内置主题
441
+ themeRegistry.set('default', defaultTheme);
442
+ themeRegistry.set('dark', darkTheme);
443
+ themeRegistry.set('walden', waldenTheme);
444
+ themeRegistry.set('chalk', chalkTheme);
445
+ themeRegistry.set('purple-passion', purplePassionTheme);
446
+ themeRegistry.set('blue-green', blueGreenTheme);
447
+ themeRegistry.set('golden', goldenTheme);
448
+ themeRegistry.set('forest', forestTheme);
449
+
450
+ export default {
451
+ defaultTheme,
452
+ darkTheme,
453
+ waldenTheme,
454
+ chalkTheme,
455
+ purplePassionTheme,
456
+ blueGreenTheme,
457
+ goldenTheme,
458
+ forestTheme,
459
+ getTheme,
460
+ registerTheme,
461
+ getRegisteredThemes,
462
+ getThemeByName,
463
+ unregisterTheme,
464
+ switchTheme,
465
+ };