@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.
- package/CHANGELOG.md +245 -0
- package/README.md +104 -302
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/vendors.js +1 -0
- package/dist/cjs/vendors~echarts.js +1 -0
- package/dist/esm/index.js +1 -58151
- package/dist/esm/vendors.js +1 -0
- package/dist/esm/vendors~echarts.js +1 -0
- package/package.json +19 -25
- package/src/adapters/MiniAppAdapter.ts +136 -0
- package/src/adapters/__tests__/index.test.ts +1 -1
- package/src/adapters/h5/__tests__/index.test.ts +4 -2
- package/src/adapters/h5/index.ts +63 -64
- package/src/adapters/harmony/index.ts +23 -245
- package/src/adapters/index.ts +49 -45
- package/src/adapters/swan/index.ts +6 -69
- package/src/adapters/tt/index.ts +7 -70
- package/src/adapters/types.ts +25 -58
- package/src/adapters/weapp/index.ts +6 -69
- package/src/charts/__tests__/testUtils.tsx +87 -0
- package/src/charts/boxplot/__tests__/index.test.tsx +49 -103
- package/src/charts/boxplot/index.tsx +2 -1
- package/src/charts/boxplot/types.ts +17 -16
- package/src/charts/common/BaseChartWrapper.tsx +90 -82
- package/src/charts/common/__mocks__/BaseChartWrapper.tsx +17 -0
- package/src/charts/createChartComponent.tsx +36 -0
- package/src/charts/createOptionChartComponent.tsx +32 -0
- package/src/charts/funnel/__tests__/index.test.tsx +99 -0
- package/src/charts/funnel/index.tsx +60 -10
- package/src/charts/funnel/types.ts +6 -0
- package/src/charts/graph/__tests__/index.test.tsx +102 -33
- package/src/charts/graph/index.tsx +66 -9
- package/src/charts/graph/types.ts +6 -0
- package/src/charts/heatmap/__tests__/index.test.tsx +139 -0
- package/src/charts/heatmap/index.tsx +103 -10
- package/src/charts/heatmap/types.ts +6 -0
- package/src/charts/index.ts +74 -26
- package/src/charts/liquid/__tests__/index.test.tsx +52 -0
- package/src/charts/liquid/index.tsx +239 -182
- package/src/charts/liquid/types.ts +11 -11
- package/src/charts/parallel/__tests__/index.test.tsx +40 -67
- package/src/charts/parallel/index.tsx +2 -1
- package/src/charts/parallel/types.ts +19 -18
- package/src/charts/radar/__tests__/index.test.tsx +210 -0
- package/src/charts/radar/index.tsx +143 -10
- package/src/charts/radar/types.ts +13 -0
- package/src/charts/sankey/__tests__/index.test.tsx +124 -0
- package/src/charts/sankey/index.tsx +62 -10
- package/src/charts/sankey/types.ts +6 -0
- package/src/charts/tree/__tests__/index.test.tsx +71 -0
- package/src/charts/tree/index.tsx +5 -2
- package/src/charts/tree/types.ts +9 -9
- package/src/charts/types.ts +208 -106
- package/src/charts/utils.ts +9 -7
- package/src/charts/wordcloud/__tests__/index.test.tsx +98 -31
- package/src/charts/wordcloud/index.tsx +75 -9
- package/src/charts/wordcloud/types.ts +6 -0
- package/src/components/DataFilter/index.tsx +32 -10
- package/src/core/animation/types.ts +6 -6
- package/src/core/components/Annotation.tsx +6 -7
- package/src/core/components/BaseChart.tsx +110 -168
- package/src/core/components/ErrorBoundary.tsx +17 -4
- package/src/core/components/LazyChart.tsx +54 -55
- package/src/core/components/hooks/index.ts +6 -2
- package/src/core/components/hooks/useChartInit.ts +6 -3
- package/src/core/components/hooks/usePerformance.ts +8 -2
- package/src/core/components/hooks/useVirtualScroll.ts +2 -1
- package/src/core/index.ts +1 -1
- package/src/core/themes/ThemeManager.ts +1 -1
- package/src/core/types/common.ts +2 -1
- package/src/core/types/index.ts +0 -12
- package/src/core/types/platform.ts +3 -5
- package/src/core/utils/__tests__/deepClone.test.ts +317 -0
- package/src/core/utils/__tests__/index.test.ts +2 -1
- package/src/core/utils/chartInstances.ts +13 -0
- package/src/core/utils/common.ts +20 -29
- package/src/core/utils/deepClone.ts +114 -0
- package/src/core/utils/download.ts +128 -0
- package/src/core/utils/drillDown.ts +34 -353
- package/src/core/utils/drillDownHelpers.ts +426 -0
- package/src/core/utils/events.ts +12 -0
- package/src/core/utils/export/ExportUtils.ts +36 -67
- package/src/core/utils/format.ts +44 -0
- package/src/core/utils/index.ts +21 -154
- package/src/core/utils/merge.ts +25 -0
- package/src/core/utils/performance/PerformanceAnalyzer.ts +38 -21
- package/src/core/utils/performance/hooks.ts +7 -0
- package/src/core/utils/performance/index.ts +2 -0
- package/src/{hooks → core/utils/performance}/useAnimation.ts +45 -41
- package/src/core/utils/performance/useDataZoom.ts +324 -0
- package/src/{hooks → core/utils/performance}/usePerformance.ts +49 -41
- package/src/core/utils/performance/usePerformanceHooks.ts +278 -0
- package/src/core/utils/performanceUtils.ts +310 -0
- package/src/core/utils/runtime.ts +190 -0
- package/src/core/utils/setOptionUtils.ts +59 -0
- package/src/core/version.ts +14 -0
- package/src/editor/EnhancedThemeEditor.tsx +362 -540
- package/src/editor/ThemeEditor.tsx +55 -321
- package/src/editor/components/ThemeBasicSettings.tsx +113 -0
- package/src/editor/components/ThemeColorEditor.tsx +105 -0
- package/src/editor/components/ThemeSelector.tsx +70 -0
- package/src/editor/hooks/useThemeEditorState.ts +201 -0
- package/src/editor/index.ts +10 -2
- package/src/hooks/__tests__/index.test.tsx +3 -1
- package/src/hooks/chartConnectHelpers.ts +341 -0
- package/src/hooks/index.ts +55 -660
- package/src/hooks/types.ts +189 -0
- package/src/hooks/useChartAutoResize.ts +73 -0
- package/src/hooks/useChartConnect.ts +92 -238
- package/src/hooks/useChartDownload.ts +25 -27
- package/src/hooks/useChartHistory.ts +34 -49
- package/src/hooks/useChartInit.ts +59 -0
- package/src/hooks/useChartOptions.ts +259 -0
- package/src/hooks/useChartPerformance.ts +109 -0
- package/src/hooks/useChartSelection.ts +52 -49
- package/src/hooks/useChartTheme.ts +51 -0
- package/src/hooks/useDataTransform.ts +19 -4
- package/src/hooks/utils/chartDownloadUtils.ts +40 -53
- package/src/hooks/utils/dataTransformUtils.ts +22 -0
- package/src/index.ts +48 -34
- package/src/main.tsx +4 -9
- package/src/react-dom.d.ts +3 -3
- package/src/themes/index.ts +30 -855
- package/src/themes/palettes/blue-green.ts +13 -0
- package/src/themes/palettes/chalk.ts +13 -0
- package/src/themes/palettes/cyber.ts +44 -0
- package/src/themes/palettes/dark.ts +52 -0
- package/src/themes/palettes/default.ts +52 -0
- package/src/themes/palettes/elegant.ts +34 -0
- package/src/themes/palettes/forest.ts +13 -0
- package/src/themes/palettes/glass.ts +49 -0
- package/src/themes/palettes/golden.ts +13 -0
- package/src/themes/palettes/neon.ts +43 -0
- package/src/themes/palettes/ocean.ts +39 -0
- package/src/themes/palettes/pastel.ts +37 -0
- package/src/themes/palettes/purple-passion.ts +13 -0
- package/src/themes/palettes/retro.ts +33 -0
- package/src/themes/palettes/sunset.ts +40 -0
- package/src/themes/palettes/walden.ts +13 -0
- package/src/themes/registry.ts +184 -0
- package/src/themes/types.ts +213 -0
- package/src/charts/bar/__tests__/index.test.tsx +0 -113
- package/src/charts/bar/index.tsx +0 -14
- package/src/charts/candlestick/__tests__/index.test.tsx +0 -40
- package/src/charts/candlestick/index.tsx +0 -13
- package/src/charts/gauge/index.tsx +0 -14
- package/src/charts/line/__tests__/index.test.tsx +0 -107
- package/src/charts/line/index.tsx +0 -15
- package/src/charts/pie/__tests__/index.test.tsx +0 -112
- package/src/charts/pie/index.tsx +0 -14
- package/src/charts/scatter/index.tsx +0 -14
- package/src/charts/sunburst/index.tsx +0 -18
- package/src/charts/treemap/index.tsx +0 -18
- package/src/core/utils/codeGenerator/CodeGenerator.ts +0 -669
- package/src/core/utils/codeGenerator/index.ts +0 -13
- package/src/core/utils/codeGenerator/types.ts +0 -198
- package/src/core/utils/configGenerator/ConfigGenerator.ts +0 -583
- package/src/core/utils/configGenerator/index.ts +0 -13
- package/src/core/utils/configGenerator/types.ts +0 -445
- package/src/core/utils/debug/DebugPanel.tsx +0 -637
- package/src/core/utils/debug/debugger.ts +0 -322
- package/src/core/utils/debug/index.ts +0 -21
- package/src/core/utils/debug/types.ts +0 -142
- 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 {
|
|
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
|
|
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
|
-
|
|
187
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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():
|
|
249
|
-
const
|
|
250
|
-
|
|
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;
|
package/src/adapters/index.ts
CHANGED
|
@@ -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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
115
|
+
|
|
116
|
+
return h5Adapter.create(options as any);
|
|
118
117
|
}
|
|
119
118
|
case PlatformType.WEAPP: {
|
|
120
|
-
const {
|
|
121
|
-
return
|
|
119
|
+
const { createWeappAdapter } = await import('./weapp');
|
|
120
|
+
return createWeappAdapter(options as any);
|
|
122
121
|
}
|
|
123
122
|
case PlatformType.SWAN: {
|
|
124
|
-
const {
|
|
125
|
-
return
|
|
123
|
+
const { createSwanAdapter } = await import('./swan');
|
|
124
|
+
return createSwanAdapter(options as any);
|
|
126
125
|
}
|
|
127
126
|
case PlatformType.TT: {
|
|
128
|
-
const {
|
|
129
|
-
return
|
|
127
|
+
const { createTTAdapter } = await import('./tt');
|
|
128
|
+
return createTTAdapter(options as any);
|
|
130
129
|
}
|
|
131
130
|
case PlatformType.HARMONY: {
|
|
132
|
-
const {
|
|
133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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;
|
package/src/adapters/tt/index.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
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;
|