@agions/taroviz 1.10.0 → 1.11.5

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 (109) hide show
  1. package/README.md +122 -275
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/vendors.js +1 -0
  4. package/dist/cjs/vendors~echarts.js +1 -0
  5. package/dist/esm/index.js +7106 -50834
  6. package/dist/esm/vendors.js +16770 -0
  7. package/dist/esm/vendors~echarts.js +59417 -0
  8. package/package.json +10 -11
  9. package/src/adapters/MiniAppAdapter.ts +136 -0
  10. package/src/adapters/__tests__/index.test.ts +1 -1
  11. package/src/adapters/h5/__tests__/index.test.ts +4 -2
  12. package/src/adapters/h5/index.ts +32 -33
  13. package/src/adapters/harmony/index.ts +23 -245
  14. package/src/adapters/index.ts +18 -12
  15. package/src/adapters/swan/index.ts +6 -69
  16. package/src/adapters/tt/index.ts +7 -70
  17. package/src/adapters/types.ts +2 -3
  18. package/src/adapters/weapp/index.ts +6 -69
  19. package/src/charts/__tests__/testUtils.tsx +87 -0
  20. package/src/charts/boxplot/__tests__/index.test.tsx +49 -103
  21. package/src/charts/boxplot/index.tsx +2 -1
  22. package/src/charts/boxplot/types.ts +15 -14
  23. package/src/charts/common/BaseChartWrapper.tsx +84 -78
  24. package/src/charts/common/__mocks__/BaseChartWrapper.tsx +17 -0
  25. package/src/charts/createChartComponent.tsx +48 -0
  26. package/src/charts/index.ts +88 -30
  27. package/src/charts/liquid/index.tsx +260 -77
  28. package/src/charts/liquid/types.ts +5 -5
  29. package/src/charts/parallel/__tests__/index.test.tsx +40 -67
  30. package/src/charts/parallel/index.tsx +2 -1
  31. package/src/charts/parallel/types.ts +16 -15
  32. package/src/charts/tree/index.tsx +4 -1
  33. package/src/charts/tree/types.ts +1 -1
  34. package/src/charts/utils.ts +9 -7
  35. package/src/components/DataFilter/index.tsx +25 -4
  36. package/src/core/animation/AnimationManager.ts +9 -6
  37. package/src/core/animation/types.ts +30 -0
  38. package/src/core/components/Annotation.tsx +2 -3
  39. package/src/core/components/BaseChart.tsx +60 -72
  40. package/src/core/components/ErrorBoundary.tsx +17 -4
  41. package/src/core/components/LazyChart.tsx +83 -57
  42. package/src/core/components/hooks/useChartInit.ts +6 -3
  43. package/src/core/index.ts +1 -1
  44. package/src/core/themes/ThemeManager.ts +1 -1
  45. package/src/core/types/common.ts +100 -5
  46. package/src/core/types/index.ts +0 -12
  47. package/src/core/types/platform.ts +2 -5
  48. package/src/core/utils/codeGenerator/CodeGenerator.ts +1 -1
  49. package/src/core/utils/codeGenerator/types.ts +2 -2
  50. package/src/core/utils/common.ts +12 -5
  51. package/src/core/utils/configGenerator/ConfigGenerator.ts +4 -4
  52. package/src/core/utils/configGenerator/types.ts +16 -12
  53. package/src/core/utils/debug/DebugPanel.tsx +14 -11
  54. package/src/core/utils/debug/debugger.ts +9 -9
  55. package/src/core/utils/debug/types.ts +4 -4
  56. package/src/core/utils/download.ts +134 -0
  57. package/src/core/utils/drillDown.ts +33 -353
  58. package/src/core/utils/drillDownHelpers.ts +426 -0
  59. package/src/core/utils/export/ExportUtils.ts +67 -69
  60. package/src/core/utils/index.ts +23 -15
  61. package/src/core/utils/performance/PerformanceAnalyzer.ts +43 -18
  62. package/src/core/utils/performance/types.ts +10 -1
  63. package/src/core/utils/performanceUtils.ts +310 -0
  64. package/src/core/utils/setOptionUtils.ts +59 -0
  65. package/src/core/version.ts +14 -0
  66. package/src/editor/EnhancedThemeEditor.tsx +362 -540
  67. package/src/editor/ThemeEditor.tsx +55 -321
  68. package/src/editor/components/ThemeBasicSettings.tsx +113 -0
  69. package/src/editor/components/ThemeColorEditor.tsx +105 -0
  70. package/src/editor/components/ThemeSelector.tsx +70 -0
  71. package/src/editor/hooks/useThemeEditorState.ts +201 -0
  72. package/src/editor/index.ts +10 -2
  73. package/src/hooks/__tests__/index.test.tsx +3 -1
  74. package/src/hooks/chartConnectHelpers.ts +335 -0
  75. package/src/hooks/index.ts +62 -63
  76. package/src/hooks/types.ts +162 -0
  77. package/src/hooks/useAnimation.ts +41 -38
  78. package/src/hooks/useChartConnect.ts +88 -238
  79. package/src/hooks/useChartDownload.ts +42 -288
  80. package/src/hooks/useChartHistory.ts +33 -46
  81. package/src/hooks/useChartSelection.ts +31 -39
  82. package/src/hooks/useDataTransform.ts +39 -286
  83. package/src/hooks/useDataZoom.ts +164 -168
  84. package/src/hooks/usePerformance.ts +20 -12
  85. package/src/hooks/usePerformanceHooks.ts +278 -0
  86. package/src/hooks/utils/chartDownloadUtils.ts +260 -0
  87. package/src/hooks/utils/dataTransformUtils.ts +309 -0
  88. package/src/index.ts +52 -33
  89. package/src/main.tsx +4 -9
  90. package/src/charts/bar/__tests__/index.test.tsx +0 -113
  91. package/src/charts/bar/index.tsx +0 -14
  92. package/src/charts/candlestick/__tests__/index.test.tsx +0 -37
  93. package/src/charts/candlestick/index.tsx +0 -13
  94. package/src/charts/funnel/index.tsx +0 -14
  95. package/src/charts/gauge/index.tsx +0 -14
  96. package/src/charts/graph/__tests__/index.test.tsx +0 -41
  97. package/src/charts/graph/index.tsx +0 -13
  98. package/src/charts/heatmap/index.tsx +0 -14
  99. package/src/charts/line/__tests__/index.test.tsx +0 -107
  100. package/src/charts/line/index.tsx +0 -15
  101. package/src/charts/pie/__tests__/index.test.tsx +0 -112
  102. package/src/charts/pie/index.tsx +0 -14
  103. package/src/charts/radar/index.tsx +0 -14
  104. package/src/charts/sankey/index.tsx +0 -18
  105. package/src/charts/scatter/index.tsx +0 -14
  106. package/src/charts/sunburst/index.tsx +0 -18
  107. package/src/charts/treemap/index.tsx +0 -18
  108. package/src/charts/wordcloud/__tests__/index.test.tsx +0 -36
  109. package/src/charts/wordcloud/index.tsx +0 -13
@@ -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;
@@ -114,34 +114,39 @@ export async function getAdapter(options: AdapterOptions): Promise<Adapter> {
114
114
  case PlatformType.LARK:
115
115
  case PlatformType.KWAI: {
116
116
  const { default: h5Adapter } = await import('./h5');
117
- return h5Adapter.create(options);
117
+
118
+ return h5Adapter.create(options as any);
118
119
  }
119
120
  case PlatformType.WEAPP: {
120
- const { default: weappAdapter } = await import('./weapp');
121
- return weappAdapter.create(options);
121
+ const { createWeappAdapter } = await import('./weapp');
122
+ return createWeappAdapter(options as any);
122
123
  }
123
124
  case PlatformType.SWAN: {
124
- const { default: swanAdapter } = await import('./swan');
125
- return swanAdapter.create(options);
125
+ const { createSwanAdapter } = await import('./swan');
126
+ return createSwanAdapter(options as any);
126
127
  }
127
128
  case PlatformType.TT: {
128
- const { default: ttAdapter } = await import('./tt');
129
- return ttAdapter.create(options);
129
+ const { createTTAdapter } = await import('./tt');
130
+ return createTTAdapter(options as any);
130
131
  }
131
132
  case PlatformType.HARMONY: {
132
- const { default: harmonyAdapter } = await import('./harmony');
133
- return harmonyAdapter.create(options);
133
+ const { HarmonyAdapter } = (await import('./harmony')) as unknown as {
134
+ HarmonyAdapter: { create: (opts: object) => Adapter };
135
+ };
136
+ return HarmonyAdapter.create(options);
134
137
  }
135
138
  default: {
136
139
  const { default: h5Adapter } = await import('./h5');
137
- return h5Adapter.create(options);
140
+
141
+ return h5Adapter.create(options as any);
138
142
  }
139
143
  }
140
144
  } catch (error) {
141
145
  console.error(`[TaroViz] Failed to load adapter for platform '${platform}':`, error);
142
146
  // 降级到 H5 适配器
143
147
  const { default: h5Adapter } = await import('./h5');
144
- return h5Adapter.create(options);
148
+
149
+ return h5Adapter.create(options as any);
145
150
  }
146
151
  }
147
152
 
@@ -155,7 +160,8 @@ export { default as HarmonyAdapter } from './harmony';
155
160
  /**
156
161
  * 版本信息
157
162
  */
158
- export const version = '1.2.0';
163
+ // 导出版本信息
164
+ export { VERSION as version } from '../core/version';
159
165
 
160
166
  export * from './types';
161
167
 
@@ -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;
@@ -20,10 +20,9 @@ export interface AdapterOptions {
20
20
  width?: number | string;
21
21
  height?: number | string;
22
22
  theme?: string | object;
23
- /** 初始化完成回调 */
23
+ option?: unknown;
24
+
24
25
  onInit?: (instance: EChartsType) => void;
25
- /** 图表配置 */
26
- option?: EChartsOption;
27
26
  style?: CSSProperties;
28
27
  autoResize?: boolean;
29
28
  devicePixelRatio?: number;
@@ -1,77 +1,14 @@
1
1
  /**
2
2
  * TaroViz 微信小程序适配器
3
- * 基于微信小程序canvas组件实现图表渲染
4
3
  */
4
+ import { MiniAppAdapter, createMiniAppAdapter } from '../MiniAppAdapter';
5
+ import type { WeappAdapterOptions } from '../types';
5
6
 
6
- import { BaseAdapter } from '../BaseAdapter';
7
- import type { Adapter, WeappAdapterOptions } from '../types';
8
-
9
- export class WeappAdapter extends BaseAdapter {
10
- private component: unknown = null;
11
-
12
- constructor(config: WeappAdapterOptions) {
13
- super(config);
14
- this.component = config.component;
15
- }
16
-
17
- static create(options: WeappAdapterOptions): Adapter {
18
- return new WeappAdapter(options) as unknown as Adapter;
19
- }
20
-
21
- init(): unknown {
22
- const config = this.config as WeappAdapterOptions & { canvasId?: string };
23
- const { canvasId, width, height, theme, option } = config;
24
-
25
- if (!this.component) {
26
- console.error('[TaroViz] WeappAdapter: component is required');
27
- return null;
28
- }
29
-
30
- if (!canvasId) {
31
- console.error('[TaroViz] WeappAdapter: 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 WeappAdapterOptions).width, 300);
58
- }
59
-
60
- getHeight(): number {
61
- return this.parseSize((this.config as WeappAdapterOptions).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 WeappAdapter extends MiniAppAdapter {
8
+ protected get platformName(): string {
9
+ return 'Weapp';
74
10
  }
75
11
  }
76
12
 
13
+ export const createWeappAdapter = createMiniAppAdapter(WeappAdapter);
77
14
  export default WeappAdapter;