@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,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz 平台适配器
|
|
3
|
+
* 自动检测并加载适合当前平台的适配器
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { PlatformType } from '../core';
|
|
7
|
+
|
|
8
|
+
import type { AdapterOptions, Adapter } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 检测当前运行的平台环境
|
|
12
|
+
* @returns 当前平台类型
|
|
13
|
+
*/
|
|
14
|
+
export function detectPlatform(): PlatformType {
|
|
15
|
+
// 服务端渲染环境
|
|
16
|
+
if (typeof window === 'undefined') {
|
|
17
|
+
return PlatformType.H5; // 默认返回H5,实际并不会在服务端渲染图表
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 微信小程序
|
|
21
|
+
if (
|
|
22
|
+
typeof window !== 'undefined' &&
|
|
23
|
+
'wx' in window &&
|
|
24
|
+
typeof (window as any).wx.getSystemInfoSync === 'function'
|
|
25
|
+
) {
|
|
26
|
+
return PlatformType.WEAPP;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 支付宝小程序
|
|
30
|
+
if (
|
|
31
|
+
typeof window !== 'undefined' &&
|
|
32
|
+
'my' in window &&
|
|
33
|
+
typeof (window as any).my.getSystemInfoSync === 'function'
|
|
34
|
+
) {
|
|
35
|
+
return PlatformType.ALIPAY;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 百度小程序
|
|
39
|
+
if (
|
|
40
|
+
typeof window !== 'undefined' &&
|
|
41
|
+
'swan' in window &&
|
|
42
|
+
typeof (window as any).swan.getSystemInfoSync === 'function'
|
|
43
|
+
) {
|
|
44
|
+
return PlatformType.SWAN;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 字节跳动小程序
|
|
48
|
+
if (
|
|
49
|
+
typeof window !== 'undefined' &&
|
|
50
|
+
'tt' in window &&
|
|
51
|
+
typeof (window as any).tt.getSystemInfoSync === 'function'
|
|
52
|
+
) {
|
|
53
|
+
return PlatformType.TT;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// QQ小程序
|
|
57
|
+
if (
|
|
58
|
+
typeof window !== 'undefined' &&
|
|
59
|
+
'qq' in window &&
|
|
60
|
+
typeof (window as any).qq.getSystemInfoSync === 'function'
|
|
61
|
+
) {
|
|
62
|
+
return PlatformType.QQ;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 京东小程序
|
|
66
|
+
if (
|
|
67
|
+
typeof window !== 'undefined' &&
|
|
68
|
+
'jd' in window &&
|
|
69
|
+
typeof (window as any).jd.getSystemInfoSync === 'function'
|
|
70
|
+
) {
|
|
71
|
+
return PlatformType.JD;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 钉钉小程序
|
|
75
|
+
if (
|
|
76
|
+
typeof window !== 'undefined' &&
|
|
77
|
+
'dd' in window &&
|
|
78
|
+
typeof (window as any).dd.getSystemInfoSync === 'function'
|
|
79
|
+
) {
|
|
80
|
+
return PlatformType.DD;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 企业微信小程序
|
|
84
|
+
if (typeof window !== 'undefined' && 'wx' in window && 'qy' in (window as any).wx) {
|
|
85
|
+
return PlatformType.QYWX;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 飞书小程序
|
|
89
|
+
if (
|
|
90
|
+
typeof window !== 'undefined' &&
|
|
91
|
+
'tt' in window &&
|
|
92
|
+
typeof (window as any).tt.getSystemInfoSync === 'function' &&
|
|
93
|
+
(window as any).tt.env?.appName === 'lark'
|
|
94
|
+
) {
|
|
95
|
+
return PlatformType.LARK;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 鸿蒙OS(通过UserAgent判断)
|
|
99
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent.includes('HarmonyOS')) {
|
|
100
|
+
return PlatformType.HARMONY;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 默认为H5
|
|
104
|
+
return PlatformType.H5;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 判断运行环境
|
|
109
|
+
* @returns 当前环境类型 ('h5' | 'weapp' | 'unknown')
|
|
110
|
+
*/
|
|
111
|
+
export function getEnv(): 'h5' | 'weapp' | 'unknown' {
|
|
112
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
113
|
+
return 'h5';
|
|
114
|
+
} else if (
|
|
115
|
+
typeof global !== 'undefined' &&
|
|
116
|
+
typeof (global as any)['wx'] !== 'undefined' &&
|
|
117
|
+
typeof (global as any)['wx'].getSystemInfoSync === 'function'
|
|
118
|
+
) {
|
|
119
|
+
return 'weapp';
|
|
120
|
+
}
|
|
121
|
+
return 'unknown';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 获取适配器
|
|
126
|
+
* @param options 适配器选项
|
|
127
|
+
* @returns 适配器实例
|
|
128
|
+
*/
|
|
129
|
+
export function getAdapter(options: AdapterOptions): Adapter {
|
|
130
|
+
const platform = detectPlatform();
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
switch (platform) {
|
|
134
|
+
case PlatformType.H5: {
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
136
|
+
const H5Adapter = require('./h5').default;
|
|
137
|
+
return H5Adapter.create(options) as Adapter;
|
|
138
|
+
}
|
|
139
|
+
case PlatformType.WEAPP: {
|
|
140
|
+
// 微信小程序环境需要component属性
|
|
141
|
+
// 如果提供了component,则使用WeappAdapter
|
|
142
|
+
// 否则回退到H5Adapter
|
|
143
|
+
if ('component' in options) {
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
145
|
+
const WeappAdapter = require('./weapp').default;
|
|
146
|
+
return WeappAdapter.create(options as any) as Adapter;
|
|
147
|
+
}
|
|
148
|
+
console.error('[TaroViz] WeappAdapter requires component property, fallback to H5Adapter');
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
150
|
+
const FallbackH5Adapter = require('./h5').default;
|
|
151
|
+
return FallbackH5Adapter.create(options) as Adapter;
|
|
152
|
+
}
|
|
153
|
+
case PlatformType.SWAN: {
|
|
154
|
+
// 百度小程序环境需要component属性
|
|
155
|
+
if ('component' in options) {
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
157
|
+
const SwanAdapter = require('./swan').default;
|
|
158
|
+
return SwanAdapter.create(options as any) as Adapter;
|
|
159
|
+
}
|
|
160
|
+
console.error('[TaroViz] SwanAdapter requires component property, fallback to H5Adapter');
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
162
|
+
const FallbackH5Adapter = require('./h5').default;
|
|
163
|
+
return FallbackH5Adapter.create(options) as Adapter;
|
|
164
|
+
}
|
|
165
|
+
case PlatformType.TT: {
|
|
166
|
+
// 字节跳动小程序环境需要component属性
|
|
167
|
+
if ('component' in options) {
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
169
|
+
const TTAdapter = require('./tt').default;
|
|
170
|
+
return TTAdapter.create(options as any) as Adapter;
|
|
171
|
+
}
|
|
172
|
+
console.error('[TaroViz] TTAdapter requires component property, fallback to H5Adapter');
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
174
|
+
const FallbackH5Adapter = require('./h5').default;
|
|
175
|
+
return FallbackH5Adapter.create(options) as Adapter;
|
|
176
|
+
}
|
|
177
|
+
case PlatformType.HARMONY: {
|
|
178
|
+
// HarmonyOS环境需要component属性
|
|
179
|
+
if ('component' in options) {
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
181
|
+
const HarmonyAdapter = require('./harmony').default;
|
|
182
|
+
return HarmonyAdapter.create(options as any) as Adapter;
|
|
183
|
+
}
|
|
184
|
+
console.error(
|
|
185
|
+
'[TaroViz] HarmonyAdapter requires component property, fallback to H5Adapter'
|
|
186
|
+
);
|
|
187
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
188
|
+
const FallbackH5Adapter = require('./h5').default;
|
|
189
|
+
return FallbackH5Adapter.create(options) as Adapter;
|
|
190
|
+
}
|
|
191
|
+
default: {
|
|
192
|
+
console.warn(`[TaroViz] Platform '${platform}' not supported, fallback to H5Adapter`);
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
194
|
+
const DefaultH5Adapter = require('./h5').default;
|
|
195
|
+
return DefaultH5Adapter.create(options) as Adapter;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error(`[TaroViz] Failed to load adapter for platform '${platform}':`, error);
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
201
|
+
const DefaultH5Adapter = require('./h5').default;
|
|
202
|
+
return DefaultH5Adapter.create(options) as Adapter;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 导出所有适配器
|
|
207
|
+
export { default as H5Adapter } from './h5';
|
|
208
|
+
export { default as WeappAdapter } from './weapp';
|
|
209
|
+
export { default as SwanAdapter } from './swan';
|
|
210
|
+
export { default as TTAdapter } from './tt';
|
|
211
|
+
export { default as HarmonyAdapter } from './harmony';
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 版本信息
|
|
215
|
+
*/
|
|
216
|
+
export const version = '1.1.1';
|
|
217
|
+
|
|
218
|
+
export * from './types';
|
|
219
|
+
|
|
220
|
+
export default {
|
|
221
|
+
getAdapter,
|
|
222
|
+
getEnv,
|
|
223
|
+
detectPlatform,
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
225
|
+
h5: require('./h5').default,
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
227
|
+
weapp: require('./weapp').default,
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
229
|
+
swan: require('./swan').default,
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
231
|
+
tt: require('./tt').default,
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
233
|
+
harmony: require('./harmony').default,
|
|
234
|
+
};
|
|
@@ -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;
|