@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,166 @@
1
+ /**
2
+ * TaroViz 平台适配器
3
+ * 自动检测并加载适合当前平台的适配器
4
+ */
5
+
6
+ import { PlatformType } from '../core';
7
+
8
+ import type { AdapterOptions, Adapter } from './types';
9
+
10
+ /**
11
+ * 平台配置映射
12
+ */
13
+ interface PlatformConfig {
14
+ name: string;
15
+ requireComponent?: boolean;
16
+ }
17
+
18
+ const PLATFORM_CONFIGS: Record<PlatformType, PlatformConfig> = {
19
+ [PlatformType.H5]: { name: 'H5' },
20
+ [PlatformType.WEAPP]: { name: 'Wechat', requireComponent: true },
21
+ [PlatformType.ALIPAY]: { name: 'Alipay', requireComponent: true },
22
+ [PlatformType.SWAN]: { name: 'Baidu', requireComponent: true },
23
+ [PlatformType.TT]: { name: 'ByteDance', requireComponent: true },
24
+ [PlatformType.QQ]: { name: 'QQ', requireComponent: true },
25
+ [PlatformType.JD]: { name: 'JD', requireComponent: true },
26
+ [PlatformType.DD]: { name: 'DingTalk', requireComponent: true },
27
+ [PlatformType.QYWX]: { name: 'QiyeWechat' },
28
+ [PlatformType.LARK]: { name: 'Lark' },
29
+ [PlatformType.HARMONY]: { name: 'HarmonyOS', requireComponent: true },
30
+ };
31
+
32
+ /**
33
+ * 检测当前运行的平台环境
34
+ */
35
+ export function detectPlatform(): PlatformType {
36
+ if (typeof window === 'undefined') {
37
+ return PlatformType.H5;
38
+ }
39
+
40
+ const checks: Array<{ test: () => boolean; platform: PlatformType }> = [
41
+ {
42
+ test: () =>
43
+ 'wx' in window && (window as any).wx?.getSystemInfoSync && !(window as any).wx?.qy,
44
+ platform: PlatformType.WEAPP,
45
+ },
46
+ {
47
+ test: () => 'my' in window && (window as any).my?.getSystemInfoSync,
48
+ platform: PlatformType.ALIPAY,
49
+ },
50
+ {
51
+ test: () => 'swan' in window && (window as any).swan?.getSystemInfoSync,
52
+ platform: PlatformType.SWAN,
53
+ },
54
+ {
55
+ test: () => 'tt' in window && (window as any).tt?.getSystemInfoSync,
56
+ platform: PlatformType.TT,
57
+ },
58
+ {
59
+ test: () => 'qq' in window && (window as any).qq?.getSystemInfoSync,
60
+ platform: PlatformType.QQ,
61
+ },
62
+ {
63
+ test: () => 'jd' in window && (window as any).jd?.getSystemInfoSync,
64
+ platform: PlatformType.JD,
65
+ },
66
+ {
67
+ test: () => 'dd' in window && (window as any).dd?.getSystemInfoSync,
68
+ platform: PlatformType.DD,
69
+ },
70
+ { test: () => 'wx' in window && (window as any).wx?.qy, platform: PlatformType.QYWX },
71
+ {
72
+ test: () => 'tt' in window && (window as any).tt?.env?.appName === 'lark',
73
+ platform: PlatformType.LARK,
74
+ },
75
+ { test: () => navigator.userAgent.includes('HarmonyOS'), platform: PlatformType.HARMONY },
76
+ ];
77
+
78
+ for (const check of checks) {
79
+ if (check.test()) {
80
+ return check.platform;
81
+ }
82
+ }
83
+
84
+ return PlatformType.H5;
85
+ }
86
+
87
+ /**
88
+ * 判断运行环境
89
+ */
90
+ export function getEnv(): 'h5' | 'weapp' | 'unknown' {
91
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
92
+ return 'h5';
93
+ }
94
+ if (typeof global !== 'undefined' && (global as any)?.wx?.getSystemInfoSync) {
95
+ return 'weapp';
96
+ }
97
+ return 'unknown';
98
+ }
99
+
100
+ /**
101
+ * 创建适配器实例
102
+ */
103
+ function createAdapterInstance(platform: PlatformType, options: AdapterOptions): Adapter {
104
+ const adapters: Record<PlatformType, () => Adapter> = {
105
+ [PlatformType.H5]: () => require('./h5').default.create(options),
106
+ [PlatformType.WEAPP]: () => require('./weapp').default.create(options),
107
+ [PlatformType.SWAN]: () => require('./swan').default.create(options),
108
+ [PlatformType.TT]: () => require('./tt').default.create(options),
109
+ [PlatformType.HARMONY]: () => require('./harmony').default.create(options),
110
+ [PlatformType.ALIPAY]: () => require('./h5').default.create(options),
111
+ [PlatformType.QQ]: () => require('./h5').default.create(options),
112
+ [PlatformType.JD]: () => require('./h5').default.create(options),
113
+ [PlatformType.DD]: () => require('./h5').default.create(options),
114
+ [PlatformType.QYWX]: () => require('./h5').default.create(options),
115
+ [PlatformType.LARK]: () => require('./h5').default.create(options),
116
+ };
117
+
118
+ return adapters[platform]();
119
+ }
120
+
121
+ /**
122
+ * 获取适配器
123
+ */
124
+ export function getAdapter(options: AdapterOptions): Adapter {
125
+ const platform = detectPlatform();
126
+ const config = PLATFORM_CONFIGS[platform];
127
+
128
+ // 检查是否需要 component 属性
129
+ if (config?.requireComponent && !('component' in options)) {
130
+ console.warn(
131
+ `[TaroViz] ${config.name}Adapter requires component property, fallback to H5Adapter`
132
+ );
133
+ }
134
+
135
+ try {
136
+ return createAdapterInstance(platform, options);
137
+ } catch (error) {
138
+ console.error(`[TaroViz] Failed to load adapter for platform '${platform}':`, error);
139
+ return require('./h5').default.create(options);
140
+ }
141
+ }
142
+
143
+ // 导出所有适配器
144
+ export { default as H5Adapter } from './h5';
145
+ export { default as WeappAdapter } from './weapp';
146
+ export { default as SwanAdapter } from './swan';
147
+ export { default as TTAdapter } from './tt';
148
+ export { default as HarmonyAdapter } from './harmony';
149
+
150
+ /**
151
+ * 版本信息
152
+ */
153
+ export const version = '1.2.0';
154
+
155
+ export * from './types';
156
+
157
+ export default {
158
+ getAdapter,
159
+ getEnv,
160
+ detectPlatform,
161
+ h5: require('./h5').default,
162
+ weapp: require('./weapp').default,
163
+ swan: require('./swan').default,
164
+ tt: require('./tt').default,
165
+ harmony: require('./harmony').default,
166
+ };
@@ -0,0 +1,274 @@
1
+ /**
2
+ * TaroViz 百度小程序适配器
3
+ * 基于百度小程序canvas组件实现图表渲染
4
+ */
5
+ import * as React from 'react';
6
+
7
+ import { Adapter, SwanAdapterOptions } from '../types';
8
+
9
+ // 扩展 SwanAdapterOptions 类型
10
+ interface ExtendedSwanAdapterOptions extends SwanAdapterOptions {
11
+ /**
12
+ * 百度小程序组件实例
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
+ }
40
+
41
+ /**
42
+ * 百度小程序环境下的图表适配器
43
+ */
44
+ class SwanAdapter implements Adapter {
45
+ /**
46
+ * 配置项
47
+ */
48
+ private config: ExtendedSwanAdapterOptions;
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: ExtendedSwanAdapterOptions) {
65
+ this.config = config;
66
+ this.component = config.component;
67
+ }
68
+
69
+ /**
70
+ * 创建百度小程序适配器实例
71
+ * @param options 适配器选项
72
+ * @returns 适配器实例
73
+ */
74
+ static create(options: ExtendedSwanAdapterOptions): SwanAdapter {
75
+ return new SwanAdapter(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] SwanAdapter: component is required');
93
+ return null;
94
+ }
95
+
96
+ if (!canvasId) {
97
+ console.error('[TaroViz] SwanAdapter: 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
+
183
+ /**
184
+ * 绑定事件
185
+ */
186
+ on(event: string, handler: (params: any) => void): void {
187
+ if (this.chartInstance) {
188
+ this.chartInstance.on(event, handler);
189
+ }
190
+ }
191
+
192
+ /**
193
+ * 解绑事件
194
+ */
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;
243
+ }
244
+
245
+ /**
246
+ * 渲染图表组件
247
+ */
248
+ render(): JSX.Element {
249
+ const { canvasId = 'ec-canvas', width = '100%', height = '300px', style = {} } = this.config;
250
+ // 注意:这里需要根据实际使用的Taro版本和组件库来调整
251
+ return React.createElement('view', {
252
+ id: canvasId,
253
+ style: { width, height, ...style },
254
+ });
255
+ }
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
+ }
273
+
274
+ export default SwanAdapter;
@@ -0,0 +1,274 @@
1
+ /**
2
+ * TaroViz 字节跳动小程序适配器
3
+ * 基于字节跳动小程序canvas组件实现图表渲染
4
+ */
5
+ import * as React from 'react';
6
+
7
+ import { Adapter, AdapterOptions } from '../types';
8
+
9
+ // 扩展 AdapterOptions 类型
10
+ interface ExtendedTTAdapterOptions extends AdapterOptions {
11
+ /**
12
+ * 字节跳动小程序组件实例
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
+ }
40
+
41
+ /**
42
+ * 字节跳动小程序环境下的图表适配器
43
+ */
44
+ class TTAdapter implements Adapter {
45
+ /**
46
+ * 配置项
47
+ */
48
+ private config: ExtendedTTAdapterOptions;
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: ExtendedTTAdapterOptions) {
65
+ this.config = config;
66
+ this.component = config.component;
67
+ }
68
+
69
+ /**
70
+ * 创建字节跳动小程序适配器实例
71
+ * @param options 适配器选项
72
+ * @returns 适配器实例
73
+ */
74
+ static create(options: ExtendedTTAdapterOptions): TTAdapter {
75
+ return new TTAdapter(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] TTAdapter: component is required');
93
+ return null;
94
+ }
95
+
96
+ if (!canvasId) {
97
+ console.error('[TaroViz] TTAdapter: 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
+
183
+ /**
184
+ * 绑定事件
185
+ */
186
+ on(event: string, handler: (params: any) => void): void {
187
+ if (this.chartInstance) {
188
+ this.chartInstance.on(event, handler);
189
+ }
190
+ }
191
+
192
+ /**
193
+ * 解绑事件
194
+ */
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;
243
+ }
244
+
245
+ /**
246
+ * 渲染图表组件
247
+ */
248
+ render(): JSX.Element {
249
+ const { canvasId = 'ec-canvas', width = '100%', height = '300px', style = {} } = this.config;
250
+ // 注意:这里需要根据实际使用的Taro版本和组件库来调整
251
+ return React.createElement('view', {
252
+ id: canvasId,
253
+ style: { width, height, ...style },
254
+ });
255
+ }
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
+ }
273
+
274
+ export default TTAdapter;