@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,274 +1,52 @@
1
1
  /**
2
2
  * TaroViz HarmonyOS适配器
3
3
  * 基于HarmonyOS Canvas实现图表渲染
4
+ * 继承 MiniAppAdapter,复用通用逻辑
4
5
  */
5
6
  import * as React from 'react';
6
7
 
7
- import { Adapter, AdapterOptions } from '../types';
8
-
9
- // 扩展 AdapterOptions 类型
10
- interface ExtendedHarmonyAdapterOptions extends AdapterOptions {
11
- /**
12
- * HarmonyOS组件实例
13
- */
14
- component?: any;
15
- /**
16
- * 画布ID
17
- */
18
- canvasId?: string;
19
- /**
20
- * 宽度
21
- */
22
- width?: number | string;
23
- /**
24
- * 高度
25
- */
26
- height?: number | string;
27
- /**
28
- * 主题
29
- */
30
- theme?: string | object;
31
- /**
32
- * 图表选项
33
- */
34
- option?: any;
35
- /**
36
- * 初始化回调
37
- */
38
- onInit?: (instance: any) => void;
39
- }
8
+ import type { EChartsType } from 'echarts';
9
+ import { MiniAppAdapter, createMiniAppAdapter } from '../MiniAppAdapter';
40
10
 
41
11
  /**
42
12
  * HarmonyOS环境下的图表适配器
43
13
  */
44
- class HarmonyAdapter implements Adapter {
45
- /**
46
- * 配置项
47
- */
48
- private config: ExtendedHarmonyAdapterOptions;
49
-
50
- /**
51
- * 图表实例
52
- */
53
- private chartInstance: any | null = null;
54
-
55
- /**
56
- * 组件实例
57
- */
58
- private component: any | null = null;
59
-
60
- /**
61
- * 构造函数
62
- * @param config 适配器配置
63
- */
64
- constructor(config: ExtendedHarmonyAdapterOptions) {
65
- this.config = config;
66
- this.component = config.component;
67
- }
68
-
69
- /**
70
- * 创建HarmonyOS适配器实例
71
- * @param options 适配器选项
72
- * @returns 适配器实例
73
- */
74
- static create(options: ExtendedHarmonyAdapterOptions): HarmonyAdapter {
75
- return new HarmonyAdapter(options);
76
- }
77
-
78
- /**
79
- * 获取图表实例
80
- */
81
- getInstance(): any {
82
- return this.chartInstance;
83
- }
84
-
85
- /**
86
- * 初始化图表
87
- */
88
- init(): any {
89
- const { canvasId, width, height, theme, option } = this.config;
90
-
91
- if (!this.component) {
92
- console.error('[TaroViz] HarmonyAdapter: component is required');
93
- return null;
94
- }
95
-
96
- if (!canvasId) {
97
- console.error('[TaroViz] HarmonyAdapter: canvasId is required');
98
- return null;
99
- }
100
-
101
- // 创建图表实例
102
- const chart = this.component.createChart({
103
- id: canvasId,
104
- width: width,
105
- height: height,
106
- theme: theme,
107
- });
108
-
109
- // 设置图表选项
110
- if (option) {
111
- chart.setOption(option);
112
- }
113
-
114
- // 存储图表实例
115
- this.chartInstance = chart;
116
-
117
- // 初始化回调
118
- if (this.config.onInit) {
119
- this.config.onInit(chart);
120
- }
121
-
122
- return chart;
123
- }
124
-
125
- /**
126
- * 设置图表选项
127
- */
128
- setOption(option: any, opts?: any): void {
129
- if (this.chartInstance) {
130
- this.chartInstance.setOption(option, opts);
131
- } else {
132
- this.config.option = option;
133
- }
134
- }
135
-
136
- /**
137
- * 设置主题
138
- */
139
- setTheme(theme: string | object): void {
140
- this.config.theme = theme;
141
- if (this.chartInstance) {
142
- this.chartInstance.setTheme?.(theme);
143
- }
144
- }
145
-
146
- /**
147
- * 获取图表宽度
148
- */
149
- getWidth(): number {
150
- return 0;
151
- }
152
-
153
- /**
154
- * 获取图表高度
155
- */
156
- getHeight(): number {
157
- return 0;
158
- }
159
-
160
- /**
161
- * 获取DOM元素
162
- */
163
- getDom(): HTMLElement | null {
164
- return null;
165
- }
166
-
167
- /**
168
- * 转换为DataURL
169
- */
170
- convertToDataURL(opts?: any): string | undefined {
171
- return this.chartInstance?.getDataURL(opts);
172
- }
173
-
174
- /**
175
- * 清空图表
176
- */
177
- clear(): void {
178
- if (this.chartInstance) {
179
- this.chartInstance.clear();
180
- }
181
- }
182
-
14
+ class HarmonyAdapter extends MiniAppAdapter {
183
15
  /**
184
- * 绑定事件
16
+ * 平台名称
185
17
  */
186
- on(event: string, handler: (params: any) => void): void {
187
- if (this.chartInstance) {
188
- this.chartInstance.on(event, handler);
189
- }
18
+ protected get platformName(): string {
19
+ return 'Harmony';
190
20
  }
191
21
 
192
22
  /**
193
- * 解绑事件
23
+ * 初始化图表(覆盖父类方法,返回 EChartsType)
194
24
  */
195
- off(event: string, handler?: (params: any) => void): void {
196
- if (this.chartInstance) {
197
- this.chartInstance.off(event, handler);
198
- }
199
- }
200
-
201
- /**
202
- * 显示加载动画
203
- */
204
- showLoading(opts?: object): void {
205
- if (this.chartInstance) {
206
- this.chartInstance.showLoading(opts);
207
- }
208
- }
209
-
210
- /**
211
- * 隐藏加载动画
212
- */
213
- hideLoading(): void {
214
- if (this.chartInstance) {
215
- this.chartInstance.hideLoading();
216
- }
217
- }
218
-
219
- /**
220
- * 销毁图表
221
- */
222
- dispose(): void {
223
- if (this.chartInstance) {
224
- this.chartInstance.dispose();
225
- this.chartInstance = null;
226
- }
227
- }
228
-
229
- /**
230
- * 处理图表大小变化
231
- */
232
- resize(opts?: any): void {
233
- if (this.chartInstance) {
234
- this.chartInstance.resize(opts);
235
- }
236
- }
237
-
238
- /**
239
- * 设置组件实例
240
- */
241
- setComponent(component: any): void {
242
- this.component = component;
25
+ init(): EChartsType {
26
+ const result = super.init();
27
+ return result as EChartsType;
243
28
  }
244
29
 
245
30
  /**
246
31
  * 渲染图表组件
247
32
  */
248
- render(): JSX.Element {
249
- const { canvasId = 'ec-canvas', width = '100%', height = '300px', style = {} } = this.config;
250
- // 注意:这里需要根据实际使用的Taro版本和组件库来调整
33
+ render(): React.ReactElement {
34
+ const config = this.config;
35
+ const canvasId = (config.canvasId as string) || 'ec-canvas';
36
+ const width = (config.width as string) || '100%';
37
+ const height = (config.height as string) || '300px';
38
+ const style = (config.style as React.CSSProperties) || {};
39
+
251
40
  return React.createElement('view', {
252
41
  id: canvasId,
253
42
  style: { width, height, ...style },
254
43
  });
255
44
  }
256
-
257
- /**
258
- * 触发图表行为
259
- */
260
- dispatchAction(payload: any): void {
261
- if (this.chartInstance) {
262
- this.chartInstance.dispatchAction(payload);
263
- }
264
- }
265
-
266
- /**
267
- * 获取DataURL
268
- */
269
- getDataURL(opts?: any): string | undefined {
270
- return this.chartInstance?.getDataURL(opts);
271
- }
272
45
  }
273
46
 
47
+ /**
48
+ * 创建 Harmony 适配器
49
+ */
50
+ export const createHarmonyAdapter = createMiniAppAdapter(HarmonyAdapter);
51
+
274
52
  export default HarmonyAdapter;
@@ -6,6 +6,8 @@
6
6
  */
7
7
 
8
8
  import { PlatformType } from '../core';
9
+ import { detectRuntime } from '../core/utils/runtime';
10
+ import type { RuntimeInfo } from '../core/utils/runtime';
9
11
  import type { AdapterOptions, Adapter } from './types';
10
12
 
11
13
  /**
@@ -31,40 +33,37 @@ const PLATFORM_CONFIGS: Record<PlatformType, PlatformConfig> = {
31
33
  [PlatformType.HARMONY]: { name: 'HarmonyOS', requireComponent: true },
32
34
  };
33
35
 
36
+ /** Map RuntimeInfo miniAppType to PlatformType */
37
+ const MINI_APP_TO_PLATFORM: Record<string, PlatformType> = {
38
+ weapp: PlatformType.WEAPP,
39
+ alipay: PlatformType.ALIPAY,
40
+ swan: PlatformType.SWAN,
41
+ tt: PlatformType.TT,
42
+ qq: PlatformType.QQ,
43
+ jd: PlatformType.JD,
44
+ dd: PlatformType.DD,
45
+ qywx: PlatformType.QYWX,
46
+ lark: PlatformType.LARK,
47
+ kwai: PlatformType.KWAI,
48
+ };
49
+
34
50
  /**
35
51
  * 检测当前运行的平台环境
52
+ *
53
+ * Delegates to the unified detectRuntime() and maps the result to PlatformType.
54
+ * Also checks for HarmonyOS via userAgent, which is not a mini-app.
36
55
  */
37
56
  export function detectPlatform(): PlatformType {
38
- if (typeof window === 'undefined') {
39
- return PlatformType.H5;
57
+ const runtime: RuntimeInfo = detectRuntime();
58
+
59
+ if (runtime.platform === 'miniapp' && runtime.miniAppType) {
60
+ return MINI_APP_TO_PLATFORM[runtime.miniAppType] ?? PlatformType.H5;
40
61
  }
41
62
 
42
- const win = window as Window & {
43
- wx?: { getSystemInfoSync?: unknown; qy?: unknown };
44
- my?: { getSystemInfoSync?: unknown };
45
- swan?: { getSystemInfoSync?: unknown };
46
- tt?: { getSystemInfoSync?: unknown; env?: { appName?: string } };
47
- qq?: { getSystemInfoSync?: unknown };
48
- jd?: { getSystemInfoSync?: unknown };
49
- dd?: { getSystemInfoSync?: unknown };
50
- };
51
-
52
- const checks: Array<{ test: () => boolean; platform: PlatformType }> = [
53
- { test: () => !!win.wx?.getSystemInfoSync && !win.wx?.qy, platform: PlatformType.WEAPP },
54
- { test: () => !!win.my?.getSystemInfoSync, platform: PlatformType.ALIPAY },
55
- { test: () => !!win.swan?.getSystemInfoSync, platform: PlatformType.SWAN },
56
- { test: () => !!win.tt?.getSystemInfoSync, platform: PlatformType.TT },
57
- { test: () => !!win.qq?.getSystemInfoSync, platform: PlatformType.QQ },
58
- { test: () => !!win.jd?.getSystemInfoSync, platform: PlatformType.JD },
59
- { test: () => !!win.dd?.getSystemInfoSync, platform: PlatformType.DD },
60
- { test: () => !!win.wx?.qy, platform: PlatformType.QYWX },
61
- { test: () => win.tt?.env?.appName === 'lark', platform: PlatformType.LARK },
62
- { test: () => navigator.userAgent.includes('HarmonyOS'), platform: PlatformType.HARMONY },
63
- ];
64
-
65
- for (const check of checks) {
66
- if (check.test()) {
67
- return check.platform;
63
+ // HarmonyOS: detected via userAgent in browser context
64
+ if (runtime.platform === 'browser' && typeof navigator !== 'undefined') {
65
+ if (navigator.userAgent.includes('HarmonyOS')) {
66
+ return PlatformType.HARMONY;
68
67
  }
69
68
  }
70
69
 
@@ -75,13 +74,12 @@ export function detectPlatform(): PlatformType {
75
74
  * 判断运行环境
76
75
  */
77
76
  export function getEnv(): 'h5' | 'weapp' | 'unknown' {
78
- if (typeof window !== 'undefined' && typeof document !== 'undefined') {
77
+ const runtime = detectRuntime();
78
+
79
+ if (runtime.isBrowser) {
79
80
  return 'h5';
80
81
  }
81
- if (
82
- typeof global !== 'undefined' &&
83
- (global as Global & { wx?: { getSystemInfoSync?: unknown } })?.wx?.getSystemInfoSync
84
- ) {
82
+ if (runtime.isMiniApp && runtime.miniAppType === 'weapp') {
85
83
  return 'weapp';
86
84
  }
87
85
  return 'unknown';
@@ -114,34 +112,39 @@ export async function getAdapter(options: AdapterOptions): Promise<Adapter> {
114
112
  case PlatformType.LARK:
115
113
  case PlatformType.KWAI: {
116
114
  const { default: h5Adapter } = await import('./h5');
117
- return h5Adapter.create(options);
115
+
116
+ return h5Adapter.create(options as any);
118
117
  }
119
118
  case PlatformType.WEAPP: {
120
- const { default: weappAdapter } = await import('./weapp');
121
- return weappAdapter.create(options);
119
+ const { createWeappAdapter } = await import('./weapp');
120
+ return createWeappAdapter(options as any);
122
121
  }
123
122
  case PlatformType.SWAN: {
124
- const { default: swanAdapter } = await import('./swan');
125
- return swanAdapter.create(options);
123
+ const { createSwanAdapter } = await import('./swan');
124
+ return createSwanAdapter(options as any);
126
125
  }
127
126
  case PlatformType.TT: {
128
- const { default: ttAdapter } = await import('./tt');
129
- return ttAdapter.create(options);
127
+ const { createTTAdapter } = await import('./tt');
128
+ return createTTAdapter(options as any);
130
129
  }
131
130
  case PlatformType.HARMONY: {
132
- const { default: harmonyAdapter } = await import('./harmony');
133
- return harmonyAdapter.create(options);
131
+ const { HarmonyAdapter } = (await import('./harmony')) as unknown as {
132
+ HarmonyAdapter: { create: (_opts: object) => Adapter };
133
+ };
134
+ return HarmonyAdapter.create(options);
134
135
  }
135
136
  default: {
136
137
  const { default: h5Adapter } = await import('./h5');
137
- return h5Adapter.create(options);
138
+
139
+ return h5Adapter.create(options as any);
138
140
  }
139
141
  }
140
142
  } catch (error) {
141
143
  console.error(`[TaroViz] Failed to load adapter for platform '${platform}':`, error);
142
144
  // 降级到 H5 适配器
143
145
  const { default: h5Adapter } = await import('./h5');
144
- return h5Adapter.create(options);
146
+
147
+ return h5Adapter.create(options as any);
145
148
  }
146
149
  }
147
150
 
@@ -155,7 +158,8 @@ export { default as HarmonyAdapter } from './harmony';
155
158
  /**
156
159
  * 版本信息
157
160
  */
158
- export const version = '1.2.0';
161
+ // 导出版本信息
162
+ export { VERSION as version } from '../core/version';
159
163
 
160
164
  export * from './types';
161
165
 
@@ -1,77 +1,14 @@
1
1
  /**
2
2
  * TaroViz 百度小程序适配器
3
- * 基于百度小程序canvas组件实现图表渲染
4
3
  */
4
+ import { MiniAppAdapter, createMiniAppAdapter } from '../MiniAppAdapter';
5
+ import type { SwanAdapterOptions } from '../types';
5
6
 
6
- import { BaseAdapter } from '../BaseAdapter';
7
- import type { Adapter, SwanAdapterOptions } from '../types';
8
-
9
- export class SwanAdapter extends BaseAdapter {
10
- private component: unknown = null;
11
-
12
- constructor(config: SwanAdapterOptions) {
13
- super(config);
14
- this.component = config.component;
15
- }
16
-
17
- static create(options: SwanAdapterOptions): Adapter {
18
- return new SwanAdapter(options) as unknown as Adapter;
19
- }
20
-
21
- init(): unknown {
22
- const config = this.config as SwanAdapterOptions & { canvasId?: string };
23
- const { canvasId, width, height, theme, option } = config;
24
-
25
- if (!this.component) {
26
- console.error('[TaroViz] SwanAdapter: component is required');
27
- return null;
28
- }
29
-
30
- if (!canvasId) {
31
- console.error('[TaroViz] SwanAdapter: canvasId is required');
32
- return null;
33
- }
34
-
35
- const chart = (this.component as { createChart: (config: unknown) => unknown }).createChart({
36
- id: canvasId,
37
- width,
38
- height,
39
- theme,
40
- });
41
-
42
- if (option) {
43
- (chart as { setOption: (o: unknown) => void }).setOption(option);
44
- }
45
-
46
- this.chartInstance = chart;
47
-
48
- const onInit = this.config['onInit'] as ((instance: unknown) => void) | undefined;
49
- if (onInit) {
50
- onInit(chart);
51
- }
52
-
53
- return chart;
54
- }
55
-
56
- getWidth(): number {
57
- return this.parseSize((this.config as SwanAdapterOptions).width, 300);
58
- }
59
-
60
- getHeight(): number {
61
- return this.parseSize((this.config as SwanAdapterOptions).height, 300);
62
- }
63
-
64
- setComponent(component: unknown): void {
65
- this.component = component;
66
- }
67
-
68
- dispatchAction(action: unknown): void {
69
- (this.chartInstance as { dispatchAction?: (a: unknown) => void })?.dispatchAction?.(action);
70
- }
71
-
72
- getDataURL(opts?: unknown): string | undefined {
73
- return (this.chartInstance as { getDataURL?: (o?: unknown) => string })?.getDataURL?.(opts);
7
+ export class SwanAdapter extends MiniAppAdapter {
8
+ protected get platformName(): string {
9
+ return 'Swan';
74
10
  }
75
11
  }
76
12
 
13
+ export const createSwanAdapter = createMiniAppAdapter(SwanAdapter);
77
14
  export default SwanAdapter;
@@ -1,77 +1,14 @@
1
1
  /**
2
- * TaroViz 抖音小程序适配器
3
- * 基于抖音小程序canvas组件实现图表渲染
2
+ * TaroViz 字节跳动小程序适配器
4
3
  */
4
+ import { MiniAppAdapter, createMiniAppAdapter } from '../MiniAppAdapter';
5
+ import type { TTAdapterOptions } from '../types';
5
6
 
6
- import { BaseAdapter } from '../BaseAdapter';
7
- import type { Adapter, TTAdapterOptions } from '../types';
8
-
9
- export class TTAdapter extends BaseAdapter {
10
- private component: unknown = null;
11
-
12
- constructor(config: TTAdapterOptions) {
13
- super(config);
14
- this.component = config.component;
15
- }
16
-
17
- static create(options: TTAdapterOptions): Adapter {
18
- return new TTAdapter(options) as unknown as Adapter;
19
- }
20
-
21
- init(): unknown {
22
- const config = this.config as TTAdapterOptions & { canvasId?: string };
23
- const { canvasId, width, height, theme, option } = config;
24
-
25
- if (!this.component) {
26
- console.error('[TaroViz] TTAdapter: component is required');
27
- return null;
28
- }
29
-
30
- if (!canvasId) {
31
- console.error('[TaroViz] TTAdapter: canvasId is required');
32
- return null;
33
- }
34
-
35
- const chart = (this.component as { createChart: (config: unknown) => unknown }).createChart({
36
- id: canvasId,
37
- width,
38
- height,
39
- theme,
40
- });
41
-
42
- if (option) {
43
- (chart as { setOption: (o: unknown) => void }).setOption(option);
44
- }
45
-
46
- this.chartInstance = chart;
47
-
48
- const onInit = this.config['onInit'] as ((instance: unknown) => void) | undefined;
49
- if (onInit) {
50
- onInit(chart);
51
- }
52
-
53
- return chart;
54
- }
55
-
56
- getWidth(): number {
57
- return this.parseSize((this.config as TTAdapterOptions).width, 300);
58
- }
59
-
60
- getHeight(): number {
61
- return this.parseSize((this.config as TTAdapterOptions).height, 300);
62
- }
63
-
64
- setComponent(component: unknown): void {
65
- this.component = component;
66
- }
67
-
68
- dispatchAction(action: unknown): void {
69
- (this.chartInstance as { dispatchAction?: (a: unknown) => void })?.dispatchAction?.(action);
70
- }
71
-
72
- getDataURL(opts?: unknown): string | undefined {
73
- return (this.chartInstance as { getDataURL?: (o?: unknown) => string })?.getDataURL?.(opts);
7
+ export class TTAdapter extends MiniAppAdapter {
8
+ protected get platformName(): string {
9
+ return 'TT';
74
10
  }
75
11
  }
76
12
 
13
+ export const createTTAdapter = createMiniAppAdapter(TTAdapter);
77
14
  export default TTAdapter;