@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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified runtime detection for TaroViz
|
|
3
|
+
*
|
|
4
|
+
* Consolidates environment detection logic that was previously duplicated
|
|
5
|
+
* between core/utils/common.ts and adapters/index.ts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Mini-app platform subtypes */
|
|
9
|
+
export type MiniAppType =
|
|
10
|
+
| 'weapp'
|
|
11
|
+
| 'alipay'
|
|
12
|
+
| 'swan'
|
|
13
|
+
| 'tt'
|
|
14
|
+
| 'qq'
|
|
15
|
+
| 'jd'
|
|
16
|
+
| 'dd'
|
|
17
|
+
| 'kwai'
|
|
18
|
+
| 'qywx'
|
|
19
|
+
| 'lark';
|
|
20
|
+
|
|
21
|
+
/** Unified runtime information */
|
|
22
|
+
export interface RuntimeInfo {
|
|
23
|
+
platform: 'browser' | 'node' | 'miniapp' | 'react-native' | 'unknown';
|
|
24
|
+
miniAppType?: MiniAppType;
|
|
25
|
+
isBrowser: boolean;
|
|
26
|
+
isNode: boolean;
|
|
27
|
+
isMiniApp: boolean;
|
|
28
|
+
isReactNative: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Cached runtime result — detection only runs once */
|
|
32
|
+
let cachedRuntime: RuntimeInfo | null = null;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reset the cached runtime info (useful for testing).
|
|
36
|
+
*/
|
|
37
|
+
export function resetRuntimeCache(): void {
|
|
38
|
+
cachedRuntime = null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function makeResult(
|
|
42
|
+
platform: RuntimeInfo['platform'],
|
|
43
|
+
opts: Partial<Pick<RuntimeInfo, 'miniAppType'>> = {}
|
|
44
|
+
): RuntimeInfo {
|
|
45
|
+
const isMiniApp = platform === 'miniapp';
|
|
46
|
+
const result: RuntimeInfo = {
|
|
47
|
+
platform,
|
|
48
|
+
isBrowser: platform === 'browser',
|
|
49
|
+
isNode: platform === 'node',
|
|
50
|
+
isMiniApp,
|
|
51
|
+
isReactNative: platform === 'react-native',
|
|
52
|
+
};
|
|
53
|
+
if (opts.miniAppType) {
|
|
54
|
+
result.miniAppType = opts.miniAppType;
|
|
55
|
+
}
|
|
56
|
+
cachedRuntime = result;
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Safe access to global mini-app objects */
|
|
61
|
+
function getGlobalObj(): Record<string, unknown> {
|
|
62
|
+
if (typeof window !== 'undefined') return window as unknown as Record<string, unknown>;
|
|
63
|
+
if (typeof globalThis !== 'undefined') return globalThis as unknown as Record<string, unknown>;
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function hasGetSystemInfoSync(key: string): boolean {
|
|
68
|
+
const g = getGlobalObj();
|
|
69
|
+
const obj = g[key];
|
|
70
|
+
return (
|
|
71
|
+
typeof obj !== 'undefined' &&
|
|
72
|
+
typeof (obj as Record<string, unknown>)?.getSystemInfoSync === 'function'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Detect the current runtime environment.
|
|
78
|
+
*
|
|
79
|
+
* Combines detection logic from:
|
|
80
|
+
* - src/core/utils/common.ts (isBrowser, isNode, isReactNative, isMiniApp)
|
|
81
|
+
* - src/adapters/index.ts (detectPlatform with getSystemInfoSync checks)
|
|
82
|
+
*
|
|
83
|
+
* Results are cached after the first call.
|
|
84
|
+
*/
|
|
85
|
+
export function detectRuntime(): RuntimeInfo {
|
|
86
|
+
if (cachedRuntime) return cachedRuntime;
|
|
87
|
+
|
|
88
|
+
const g = getGlobalObj();
|
|
89
|
+
|
|
90
|
+
// --- Mini-app detection (order matters: more specific checks first) ---
|
|
91
|
+
|
|
92
|
+
// Enterprise WeChat must be checked before regular WeChat
|
|
93
|
+
const wx = g['wx'] as Record<string, unknown> | undefined;
|
|
94
|
+
if (typeof wx !== 'undefined' && wx?.qy) {
|
|
95
|
+
return makeResult('miniapp', { miniAppType: 'qywx' });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (hasGetSystemInfoSync('wx')) {
|
|
99
|
+
return makeResult('miniapp', { miniAppType: 'weapp' });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (hasGetSystemInfoSync('my')) {
|
|
103
|
+
return makeResult('miniapp', { miniAppType: 'alipay' });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (hasGetSystemInfoSync('swan')) {
|
|
107
|
+
return makeResult('miniapp', { miniAppType: 'swan' });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (hasGetSystemInfoSync('tt')) {
|
|
111
|
+
// Lark (Feishu) runs on the TT runtime but with appName === 'lark'
|
|
112
|
+
const ttObj = g['tt'] as Record<string, unknown> | undefined;
|
|
113
|
+
const env = ttObj?.env as Record<string, unknown> | undefined;
|
|
114
|
+
const isLark = env?.appName === 'lark';
|
|
115
|
+
return makeResult('miniapp', { miniAppType: isLark ? 'lark' : 'tt' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (hasGetSystemInfoSync('qq')) {
|
|
119
|
+
return makeResult('miniapp', { miniAppType: 'qq' });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (hasGetSystemInfoSync('jd')) {
|
|
123
|
+
return makeResult('miniapp', { miniAppType: 'jd' });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (hasGetSystemInfoSync('dd')) {
|
|
127
|
+
return makeResult('miniapp', { miniAppType: 'dd' });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Kwai / Kuaishou: presence of ks global
|
|
131
|
+
if (typeof g['ks'] !== 'undefined') {
|
|
132
|
+
return makeResult('miniapp', { miniAppType: 'kwai' });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// --- Browser detection ---
|
|
136
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
137
|
+
return makeResult('browser');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- Node.js detection ---
|
|
141
|
+
try {
|
|
142
|
+
const proc = (globalThis as Record<string, unknown>).process as
|
|
143
|
+
| Record<string, unknown>
|
|
144
|
+
| undefined;
|
|
145
|
+
if (
|
|
146
|
+
typeof proc !== 'undefined' &&
|
|
147
|
+
proc.versions &&
|
|
148
|
+
(proc.versions as Record<string, unknown>).node &&
|
|
149
|
+
Object.prototype.toString.call(proc) === '[object process]'
|
|
150
|
+
) {
|
|
151
|
+
return makeResult('node');
|
|
152
|
+
}
|
|
153
|
+
} catch {
|
|
154
|
+
// ignore
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// --- React Native detection ---
|
|
158
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
159
|
+
return makeResult('react-native');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return makeResult('unknown');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 检测当前环境(简易版,向后兼容)
|
|
167
|
+
* @returns 环境信息
|
|
168
|
+
*/
|
|
169
|
+
export function getEnvironment() {
|
|
170
|
+
const isServer = typeof window === 'undefined';
|
|
171
|
+
const isClient = !isServer;
|
|
172
|
+
|
|
173
|
+
// 使用类型断言解决wx和my未定义的问题
|
|
174
|
+
const win = window as Window & { wx?: unknown; my?: unknown };
|
|
175
|
+
const isWeapp =
|
|
176
|
+
typeof win.wx !== 'undefined' &&
|
|
177
|
+
typeof (win.wx as { getSystemInfoSync?: unknown })?.getSystemInfoSync === 'function';
|
|
178
|
+
const isAlipay =
|
|
179
|
+
typeof win.my !== 'undefined' &&
|
|
180
|
+
typeof (win.my as { getSystemInfoSync?: unknown })?.getSystemInfoSync === 'function';
|
|
181
|
+
const isWeb = isClient && !isWeapp && !isAlipay;
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
isServer,
|
|
185
|
+
isClient,
|
|
186
|
+
isWeapp,
|
|
187
|
+
isAlipay,
|
|
188
|
+
isWeb,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECharts setOption 优化工具
|
|
3
|
+
* 提供带性能优化的 setOption 调用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { EChartsOption } from 'echarts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 优化后的 setOption 调用
|
|
10
|
+
* @param chartInstance ECharts 实例
|
|
11
|
+
* @param option 图表配置
|
|
12
|
+
* @param notMerge 是否不合并配置,默认 false
|
|
13
|
+
* @param lazyUpdate 是否延迟更新,默认 true(提升性能)
|
|
14
|
+
*/
|
|
15
|
+
export function setOptionWithOptimization(
|
|
16
|
+
chartInstance:
|
|
17
|
+
| { setOption: (option: EChartsOption, notMerge?: boolean, lazyUpdate?: boolean) => void }
|
|
18
|
+
| null
|
|
19
|
+
| undefined,
|
|
20
|
+
option: EChartsOption,
|
|
21
|
+
notMerge = false,
|
|
22
|
+
lazyUpdate = true
|
|
23
|
+
): void {
|
|
24
|
+
if (!chartInstance?.setOption) return;
|
|
25
|
+
|
|
26
|
+
// 使用 lazyUpdate = true 减少重绘次数,提升动画性能
|
|
27
|
+
chartInstance.setOption(option, notMerge, lazyUpdate);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 批量 setOption 调用(用于动画等场景)
|
|
32
|
+
* 合并多次 setOption 调用,减少重绘
|
|
33
|
+
*/
|
|
34
|
+
export function batchSetOption(
|
|
35
|
+
chartInstance:
|
|
36
|
+
| { setOption: (option: EChartsOption, notMerge?: boolean, lazyUpdate?: boolean) => void }
|
|
37
|
+
| null
|
|
38
|
+
| undefined,
|
|
39
|
+
options: EChartsOption[],
|
|
40
|
+
notMerge = false
|
|
41
|
+
): void {
|
|
42
|
+
if (!chartInstance?.setOption || options.length === 0) return;
|
|
43
|
+
|
|
44
|
+
// 合并所有配置
|
|
45
|
+
const mergedOption = options.reduce((acc, opt) => {
|
|
46
|
+
if (!acc) return opt;
|
|
47
|
+
// 安全合并 series
|
|
48
|
+
const accSeries = Array.isArray(acc.series) ? acc.series : [];
|
|
49
|
+
const optSeries = Array.isArray(opt.series) ? opt.series : [];
|
|
50
|
+
return {
|
|
51
|
+
...acc,
|
|
52
|
+
...opt,
|
|
53
|
+
series: [...accSeries, ...optSeries],
|
|
54
|
+
};
|
|
55
|
+
}, {} as EChartsOption);
|
|
56
|
+
|
|
57
|
+
// 一次性调用,使用 lazyUpdate
|
|
58
|
+
chartInstance.setOption(mergedOption, notMerge, true);
|
|
59
|
+
}
|