@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.
- package/README.md +318 -53
- package/dist/index.esm.js +67955 -3318
- package/package.json +102 -20
- package/src/__tests__/integration.test.tsx +168 -0
- package/src/adapters/__tests__/index.test.ts +91 -0
- package/src/adapters/h5/__tests__/index.test.ts +156 -0
- package/src/adapters/h5/index.ts +301 -0
- package/src/adapters/harmony/index.ts +274 -0
- package/src/adapters/index.ts +234 -0
- package/src/adapters/swan/index.ts +274 -0
- package/src/adapters/tt/index.ts +274 -0
- package/src/adapters/types.ts +162 -0
- package/src/adapters/weapp/index.ts +237 -0
- package/src/charts/bar/__tests__/index.test.tsx +113 -0
- package/src/charts/bar/index.tsx +27 -0
- package/src/charts/common/BaseChartWrapper.tsx +136 -0
- package/src/charts/funnel/index.tsx +33 -0
- package/src/charts/gauge/index.tsx +33 -0
- package/src/charts/heatmap/index.tsx +33 -0
- package/src/charts/index.ts +21 -0
- package/src/charts/line/__tests__/index.test.tsx +107 -0
- package/src/charts/line/index.tsx +27 -0
- package/src/charts/pie/__tests__/index.test.tsx +112 -0
- package/src/charts/pie/index.tsx +22 -0
- package/src/charts/radar/index.tsx +33 -0
- package/src/charts/scatter/index.tsx +33 -0
- package/src/charts/types.ts +146 -0
- package/src/charts/utils.ts +56 -0
- package/src/core/__tests__/platform.test.ts +48 -0
- package/src/core/animation/AnimationManager.ts +391 -0
- package/src/core/animation/index.ts +20 -0
- package/src/core/animation/types.ts +248 -0
- package/src/core/components/BaseChart.tsx +1319 -0
- package/src/core/index.ts +19 -0
- package/src/core/types/chart.ts +66 -0
- package/src/core/types/common.ts +224 -0
- package/src/core/types/index.ts +281 -0
- package/src/core/types/platform.ts +325 -0
- package/src/core/utils/__tests__/common.test.ts +52 -0
- package/src/core/utils/__tests__/environment.test.ts +94 -0
- package/src/core/utils/__tests__/i18n.test.ts +247 -0
- package/src/core/utils/__tests__/index.test.ts +219 -0
- package/src/core/utils/__tests__/uuid.test.ts +78 -0
- package/src/core/utils/chartInstances.ts +69 -0
- package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
- package/src/core/utils/codeGenerator/index.ts +13 -0
- package/src/core/utils/codeGenerator/types.ts +200 -0
- package/src/core/utils/common.ts +58 -0
- package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
- package/src/core/utils/configGenerator/index.ts +13 -0
- package/src/core/utils/configGenerator/types.ts +445 -0
- package/src/core/utils/debug/DebugPanel.tsx +637 -0
- package/src/core/utils/debug/debugger.ts +322 -0
- package/src/core/utils/debug/index.ts +21 -0
- package/src/core/utils/debug/types.ts +142 -0
- package/src/core/utils/i18n.ts +452 -0
- package/src/core/utils/index.ts +162 -0
- package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
- package/src/core/utils/performance/index.ts +13 -0
- package/src/core/utils/performance/types.ts +180 -0
- package/src/core/utils/uuid.ts +30 -0
- package/src/editor/ThemeEditor.tsx +449 -0
- package/src/editor/index.ts +10 -0
- package/src/hooks/__tests__/index.test.tsx +333 -0
- package/src/hooks/index.ts +214 -0
- package/src/index.ts +75 -0
- package/src/main.tsx +247 -0
- package/src/react-dom.d.ts +7 -0
- package/src/themes/__tests__/index.test.ts +91 -0
- package/src/themes/index.ts +465 -0
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -4012
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz H5 适配器
|
|
3
|
+
* 基于 HTML Canvas 实现图表渲染
|
|
4
|
+
*/
|
|
5
|
+
import type { EChartsType } from 'echarts';
|
|
6
|
+
import {
|
|
7
|
+
GridComponent,
|
|
8
|
+
TooltipComponent,
|
|
9
|
+
TitleComponent,
|
|
10
|
+
LegendComponent,
|
|
11
|
+
} from 'echarts/components';
|
|
12
|
+
import * as echarts from 'echarts/core';
|
|
13
|
+
import { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
|
|
16
|
+
import { Adapter, H5AdapterOptions } from '../types';
|
|
17
|
+
|
|
18
|
+
// 扩展 H5AdapterOptions 类型
|
|
19
|
+
interface ExtendedH5AdapterOptions extends H5AdapterOptions {
|
|
20
|
+
canvasId?: string;
|
|
21
|
+
width?: number | string;
|
|
22
|
+
height?: number | string;
|
|
23
|
+
theme?: string | object;
|
|
24
|
+
option?: any;
|
|
25
|
+
onInit?: (instance: any) => void;
|
|
26
|
+
containerRef?: any;
|
|
27
|
+
direction?: 'ltr' | 'rtl';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 注册基础组件和渲染器
|
|
31
|
+
echarts.use([
|
|
32
|
+
GridComponent,
|
|
33
|
+
TooltipComponent,
|
|
34
|
+
TitleComponent,
|
|
35
|
+
LegendComponent,
|
|
36
|
+
CanvasRenderer,
|
|
37
|
+
SVGRenderer,
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* H5环境适配器
|
|
42
|
+
* 提供基础的Web浏览器环境下的图表渲染支持
|
|
43
|
+
*/
|
|
44
|
+
class H5Adapter implements Adapter {
|
|
45
|
+
/**
|
|
46
|
+
* 图表实例
|
|
47
|
+
*/
|
|
48
|
+
private instance: any = null;
|
|
49
|
+
private options: ExtendedH5AdapterOptions;
|
|
50
|
+
private containerRef: any = null;
|
|
51
|
+
private canvasId: string;
|
|
52
|
+
|
|
53
|
+
constructor(options: ExtendedH5AdapterOptions) {
|
|
54
|
+
this.options = options || ({} as ExtendedH5AdapterOptions);
|
|
55
|
+
this.containerRef = options.containerRef;
|
|
56
|
+
this.canvasId = this.options.canvasId || 'taroviz-echarts-canvas';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 创建H5适配器实例
|
|
61
|
+
* @param options 适配器选项
|
|
62
|
+
* @returns 适配器实例
|
|
63
|
+
*/
|
|
64
|
+
static create(options: ExtendedH5AdapterOptions): H5Adapter {
|
|
65
|
+
return new H5Adapter(options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 初始化图表
|
|
70
|
+
*/
|
|
71
|
+
init(options?: any): EChartsType {
|
|
72
|
+
if (this.instance) {
|
|
73
|
+
return this.instance;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 获取容器元素
|
|
77
|
+
const container = this.containerRef?.current || document.getElementById(this.canvasId);
|
|
78
|
+
if (!container) {
|
|
79
|
+
console.error('[TaroViz] H5Adapter: container not found');
|
|
80
|
+
// 如果容器未找到,返回一个空对象
|
|
81
|
+
return {} as EChartsType;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 初始化图表
|
|
85
|
+
this.instance = echarts.init(container, this.options.theme, {
|
|
86
|
+
// 性能优化选项
|
|
87
|
+
useDirtyRect: true, // 使用脏矩形渲染,减少重绘区域
|
|
88
|
+
renderer: this.options.renderer || 'canvas',
|
|
89
|
+
} as any); // 使用类型断言允许额外的配置选项
|
|
90
|
+
|
|
91
|
+
// 设置性能优化相关的全局配置
|
|
92
|
+
if (this.instance) {
|
|
93
|
+
// 渐进式渲染配置
|
|
94
|
+
this.instance.setOption(
|
|
95
|
+
{
|
|
96
|
+
animation: this.options.option?.animation !== false,
|
|
97
|
+
animationDurationUpdate: 300,
|
|
98
|
+
animationEasingUpdate: 'cubicOut',
|
|
99
|
+
progressive: 500,
|
|
100
|
+
progressiveThreshold: 1000,
|
|
101
|
+
},
|
|
102
|
+
true
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 设置初始化选项,使用notMerge: false和lazyUpdate: true优化性能
|
|
107
|
+
if (this.options.option && this.instance) {
|
|
108
|
+
this.instance.setOption(this.options.option, {
|
|
109
|
+
notMerge: false, // 合并新选项和旧选项
|
|
110
|
+
lazyUpdate: true, // 延迟更新,合并多次setOption调用
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 执行初始化回调
|
|
115
|
+
if (this.options.onInit && this.instance) {
|
|
116
|
+
this.options.onInit(this.instance);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this.instance as EChartsType;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 获取图表实例
|
|
124
|
+
*/
|
|
125
|
+
getInstance(): any {
|
|
126
|
+
return this.instance;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 设置图表选项
|
|
131
|
+
*/
|
|
132
|
+
setOption(option: any, opts?: any): void {
|
|
133
|
+
if (this.instance) {
|
|
134
|
+
// 使用性能优化选项,默认启用lazyUpdate
|
|
135
|
+
this.instance.setOption(option, {
|
|
136
|
+
lazyUpdate: true,
|
|
137
|
+
...opts,
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
this.options.option = option;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 设置主题
|
|
146
|
+
*/
|
|
147
|
+
setTheme(theme: string | object): void {
|
|
148
|
+
this.options.theme = theme;
|
|
149
|
+
if (this.instance) {
|
|
150
|
+
// 使用类型断言来访问私有方法
|
|
151
|
+
(this.instance as any).setTheme?.(theme);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 获取图表宽度
|
|
157
|
+
*/
|
|
158
|
+
getWidth(): number {
|
|
159
|
+
return this.instance?.getWidth() || 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 获取图表高度
|
|
164
|
+
*/
|
|
165
|
+
getHeight(): number {
|
|
166
|
+
return this.instance?.getHeight() || 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 获取DOM元素
|
|
171
|
+
*/
|
|
172
|
+
getDom(): HTMLElement | null {
|
|
173
|
+
return this.containerRef?.current || null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 转换为DataURL
|
|
178
|
+
*/
|
|
179
|
+
convertToDataURL(opts?: {
|
|
180
|
+
type?: 'svg' | 'png' | 'jpeg';
|
|
181
|
+
pixelRatio?: number;
|
|
182
|
+
backgroundColor?: string;
|
|
183
|
+
}): string | undefined {
|
|
184
|
+
return this.instance?.getDataURL(opts);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 清空图表
|
|
189
|
+
*/
|
|
190
|
+
clear(): void {
|
|
191
|
+
if (this.instance) {
|
|
192
|
+
this.instance.clear();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 绑定事件
|
|
198
|
+
*/
|
|
199
|
+
on(event: string, handler: (params: any) => void): void {
|
|
200
|
+
if (this.instance) {
|
|
201
|
+
this.instance.on(event, handler);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 解绑事件
|
|
207
|
+
*/
|
|
208
|
+
off(event: string, handler?: (params: any) => void): void {
|
|
209
|
+
if (this.instance) {
|
|
210
|
+
this.instance.off(event, handler);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 显示加载动画
|
|
216
|
+
*/
|
|
217
|
+
showLoading(opts?: object): void {
|
|
218
|
+
if (this.instance) {
|
|
219
|
+
this.instance.showLoading(opts);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 隐藏加载动画
|
|
225
|
+
*/
|
|
226
|
+
hideLoading(): void {
|
|
227
|
+
if (this.instance) {
|
|
228
|
+
this.instance.hideLoading();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 设置组件实例
|
|
234
|
+
*/
|
|
235
|
+
setComponent(component: any): void {
|
|
236
|
+
this.containerRef = component;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 渲染图表组件
|
|
241
|
+
*/
|
|
242
|
+
render(): JSX.Element {
|
|
243
|
+
const { width = '100%', height = '300px', style = {}, direction = 'ltr' } = this.options;
|
|
244
|
+
// 注意:这里需要根据实际使用的Taro版本和组件库来调整
|
|
245
|
+
return React.createElement('div', {
|
|
246
|
+
id: this.canvasId,
|
|
247
|
+
ref: this.containerRef,
|
|
248
|
+
style: { width, height, direction, ...style },
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 销毁图表
|
|
254
|
+
*/
|
|
255
|
+
dispose(): void {
|
|
256
|
+
if (this.instance) {
|
|
257
|
+
this.instance.dispose();
|
|
258
|
+
this.instance = null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 处理图表大小变化
|
|
264
|
+
*/
|
|
265
|
+
resize(opts?: any): void {
|
|
266
|
+
if (this.instance) {
|
|
267
|
+
this.instance.resize(opts);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 获取适配器名称
|
|
273
|
+
* @returns 适配器名称
|
|
274
|
+
*/
|
|
275
|
+
getName(): string {
|
|
276
|
+
return 'H5Adapter';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 获取适配器版本
|
|
281
|
+
* @returns 适配器版本
|
|
282
|
+
*/
|
|
283
|
+
getVersion(): string {
|
|
284
|
+
return '1.1.1';
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 获取平台信息
|
|
289
|
+
* @returns 平台信息
|
|
290
|
+
*/
|
|
291
|
+
getPlatformInfo(): Record<string, any> {
|
|
292
|
+
return {
|
|
293
|
+
platform: 'h5',
|
|
294
|
+
renderer: this.options.renderer || 'canvas',
|
|
295
|
+
userAgent: navigator.userAgent,
|
|
296
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export default H5Adapter;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz HarmonyOS适配器
|
|
3
|
+
* 基于HarmonyOS Canvas实现图表渲染
|
|
4
|
+
*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
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
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* HarmonyOS环境下的图表适配器
|
|
43
|
+
*/
|
|
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
|
+
|
|
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 HarmonyAdapter;
|