@agions/taroviz 1.2.0 → 1.3.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 +53 -41
- package/dist/cjs/index.js +1 -0
- package/dist/esm/index.js +9103 -0
- package/package.json +99 -10
- package/src/adapters/__tests__/index.test.ts +2 -2
- package/src/adapters/h5/index.ts +1 -1
- package/src/adapters/index.ts +99 -167
- package/src/charts/bar/index.tsx +2 -11
- package/src/charts/common/BaseChartWrapper.tsx +2 -2
- package/src/charts/funnel/index.tsx +2 -17
- package/src/charts/gauge/index.tsx +2 -17
- package/src/charts/heatmap/index.tsx +2 -17
- package/src/charts/index.ts +6 -1
- package/src/charts/line/index.tsx +2 -11
- package/src/charts/pie/index.tsx +3 -6
- package/src/charts/radar/index.tsx +2 -17
- package/src/charts/sankey/index.tsx +18 -0
- package/src/charts/scatter/index.tsx +2 -17
- package/src/charts/sunburst/index.tsx +18 -0
- package/src/charts/treemap/index.tsx +18 -0
- package/src/charts/types.ts +761 -30
- package/src/charts/utils.ts +1 -1
- package/src/core/__tests__/platform.test.ts +1 -1
- package/src/core/animation/AnimationManager.ts +2 -2
- package/src/core/components/Annotation.tsx +346 -0
- package/src/core/components/BaseChart.tsx +12 -18
- package/src/core/components/ErrorBoundary.tsx +153 -0
- package/src/core/components/LazyChart.tsx +200 -0
- package/src/core/echarts.ts +80 -0
- package/src/core/index.ts +4 -1
- package/src/core/themes/ThemeManager.ts +628 -0
- package/src/core/utils/__tests__/common.test.ts +1 -1
- package/src/core/utils/chartInstances.ts +2 -2
- package/src/core/utils/codeGenerator/CodeGenerator.ts +2 -2
- package/src/core/utils/codeGenerator/types.ts +0 -2
- package/src/core/utils/configGenerator/ConfigGenerator.ts +12 -12
- package/src/core/utils/debug/DebugPanel.tsx +1 -1
- package/src/core/utils/debug/debugger.ts +1 -1
- package/src/core/utils/export/ExportUtils.ts +385 -0
- package/src/core/utils/index.ts +1 -1
- package/src/core/utils/performance/PerformanceAnalyzer.ts +5 -5
- package/src/editor/ThemeEditor.tsx +9 -9
- package/src/hooks/index.ts +441 -61
- package/src/index.ts +72 -4
- package/src/main.tsx +1 -1
- package/src/themes/index.ts +651 -256
- package/dist/index.esm.js +0 -68685
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz 懒加载图表组件
|
|
3
|
+
* 用于按需加载图表,减少首屏体积
|
|
4
|
+
*/
|
|
5
|
+
import React, { Suspense, lazy, ComponentType } from 'react';
|
|
6
|
+
|
|
7
|
+
// 懒加载各个图表组件
|
|
8
|
+
const LazyLineChart = lazy(() => import('../../charts/line'));
|
|
9
|
+
const LazyBarChart = lazy(() => import('../../charts/bar'));
|
|
10
|
+
const LazyPieChart = lazy(() => import('../../charts/pie'));
|
|
11
|
+
const LazyScatterChart = lazy(() => import('../../charts/scatter'));
|
|
12
|
+
const LazyRadarChart = lazy(() => import('../../charts/radar'));
|
|
13
|
+
const LazyHeatmapChart = lazy(() => import('../../charts/heatmap'));
|
|
14
|
+
const LazyGaugeChart = lazy(() => import('../../charts/gauge'));
|
|
15
|
+
const LazyFunnelChart = lazy(() => import('../../charts/funnel'));
|
|
16
|
+
const LazyTreeMapChart = lazy(() => import('../../charts/treemap'));
|
|
17
|
+
const LazySunburstChart = lazy(() => import('../../charts/sunburst'));
|
|
18
|
+
const LazySankeyChart = lazy(() => import('../../charts/sankey'));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 懒加载图表包装器
|
|
22
|
+
*/
|
|
23
|
+
interface LazyChartWrapperProps {
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
fallback?: React.ReactNode;
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
loadingText?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 默认加载状态组件
|
|
32
|
+
*/
|
|
33
|
+
const DefaultLoadingFallback: React.FC<{ text?: string }> = ({ text = '加载中...' }) => (
|
|
34
|
+
<div
|
|
35
|
+
style={{
|
|
36
|
+
display: 'flex',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
justifyContent: 'center',
|
|
39
|
+
width: '100%',
|
|
40
|
+
height: '100%',
|
|
41
|
+
minHeight: '200px',
|
|
42
|
+
backgroundColor: '#f5f5f5',
|
|
43
|
+
borderRadius: '8px',
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<div style={{ textAlign: 'center' }}>
|
|
47
|
+
<div
|
|
48
|
+
style={{
|
|
49
|
+
width: '40px',
|
|
50
|
+
height: '40px',
|
|
51
|
+
border: '3px solid #1890ff',
|
|
52
|
+
borderTopColor: 'transparent',
|
|
53
|
+
borderRadius: '50%',
|
|
54
|
+
animation: 'taroviz-spin 1s linear infinite',
|
|
55
|
+
margin: '0 auto 12px',
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
<style>
|
|
59
|
+
{`
|
|
60
|
+
@keyframes taroviz-spin {
|
|
61
|
+
to { transform: rotate(360deg); }
|
|
62
|
+
}
|
|
63
|
+
`}
|
|
64
|
+
</style>
|
|
65
|
+
<span style={{ color: '#666', fontSize: '14px' }}>{text}</span>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 懒加载图表包装组件
|
|
72
|
+
*/
|
|
73
|
+
export function withLazyLoad<P extends object>(
|
|
74
|
+
ChartComponent: ComponentType<P>,
|
|
75
|
+
loadingFallback?: ComponentType<{ text?: string }>
|
|
76
|
+
): ComponentType<P & { loadingText?: string; fallback?: React.ReactNode }> {
|
|
77
|
+
const LazyWrapper: React.FC<P & { loadingText?: string; fallback?: React.ReactNode }> = ({
|
|
78
|
+
loadingText,
|
|
79
|
+
fallback,
|
|
80
|
+
...props
|
|
81
|
+
}) => {
|
|
82
|
+
const LoadingComponent = loadingFallback || DefaultLoadingFallback;
|
|
83
|
+
return (
|
|
84
|
+
<Suspense fallback={<LoadingComponent text={loadingText} />}>
|
|
85
|
+
{fallback ? (
|
|
86
|
+
<React.Fragment>
|
|
87
|
+
{fallback}
|
|
88
|
+
<ChartComponent {...props} />
|
|
89
|
+
</React.Fragment>
|
|
90
|
+
) : (
|
|
91
|
+
<ChartComponent {...props} />
|
|
92
|
+
)}
|
|
93
|
+
</Suspense>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
LazyWrapper.displayName = `withLazyLoad(${ChartComponent.displayName || ChartComponent.name || 'Chart'})`;
|
|
98
|
+
|
|
99
|
+
return LazyWrapper;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 预加载图表组件
|
|
104
|
+
* 在需要显示图表之前预先加载
|
|
105
|
+
*/
|
|
106
|
+
export function preloadChart(chartType: string): void {
|
|
107
|
+
const chartModules: Record<string, () => Promise<{ default: ComponentType<any> }>> = {
|
|
108
|
+
line: () => import('../../charts/line'),
|
|
109
|
+
bar: () => import('../../charts/bar'),
|
|
110
|
+
pie: () => import('../../charts/pie'),
|
|
111
|
+
scatter: () => import('../../charts/scatter'),
|
|
112
|
+
radar: () => import('../../charts/radar'),
|
|
113
|
+
heatmap: () => import('../../charts/heatmap'),
|
|
114
|
+
gauge: () => import('../../charts/gauge'),
|
|
115
|
+
funnel: () => import('../../charts/funnel'),
|
|
116
|
+
treemap: () => import('../../charts/treemap'),
|
|
117
|
+
sunburst: () => import('../../charts/sunburst'),
|
|
118
|
+
sankey: () => import('../../charts/sankey'),
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const loader = chartModules[chartType];
|
|
122
|
+
if (loader) {
|
|
123
|
+
loader().catch(console.error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 预加载所有图表组件
|
|
129
|
+
*/
|
|
130
|
+
export function preloadAllCharts(): void {
|
|
131
|
+
const chartTypes = [
|
|
132
|
+
'line',
|
|
133
|
+
'bar',
|
|
134
|
+
'pie',
|
|
135
|
+
'scatter',
|
|
136
|
+
'radar',
|
|
137
|
+
'heatmap',
|
|
138
|
+
'gauge',
|
|
139
|
+
'funnel',
|
|
140
|
+
'treemap',
|
|
141
|
+
'sunburst',
|
|
142
|
+
'sankey',
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
chartTypes.forEach((type) => preloadChart(type));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 创建懒加载图表映射
|
|
150
|
+
* 用于动态导入图表
|
|
151
|
+
*/
|
|
152
|
+
export function createLazyChart(chartType: string): ComponentType<any> | null {
|
|
153
|
+
const lazyCharts: Record<string, ComponentType<any>> = {
|
|
154
|
+
line: LazyLineChart,
|
|
155
|
+
bar: LazyBarChart,
|
|
156
|
+
pie: LazyPieChart,
|
|
157
|
+
scatter: LazyScatterChart,
|
|
158
|
+
radar: LazyRadarChart,
|
|
159
|
+
heatmap: LazyHeatmapChart,
|
|
160
|
+
gauge: LazyGaugeChart,
|
|
161
|
+
funnel: LazyFunnelChart,
|
|
162
|
+
treemap: LazyTreeMapChart,
|
|
163
|
+
sunburst: LazySunburstChart,
|
|
164
|
+
sankey: LazySankeyChart,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return lazyCharts[chartType] || null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 懒加载图表注册表
|
|
172
|
+
* 用于按名称动态获取懒加载图表组件
|
|
173
|
+
*/
|
|
174
|
+
export const LazyChartRegistry = {
|
|
175
|
+
get(chartType: string): ComponentType<any> | null {
|
|
176
|
+
return createLazyChart(chartType);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
preload(chartType: string): void {
|
|
180
|
+
preloadChart(chartType);
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
preloadAll(): void {
|
|
184
|
+
preloadAllCharts();
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
LazyLineChart,
|
|
190
|
+
LazyBarChart,
|
|
191
|
+
LazyPieChart,
|
|
192
|
+
LazyScatterChart,
|
|
193
|
+
LazyRadarChart,
|
|
194
|
+
LazyHeatmapChart,
|
|
195
|
+
LazyGaugeChart,
|
|
196
|
+
LazyFunnelChart,
|
|
197
|
+
LazyTreeMapChart,
|
|
198
|
+
LazySunburstChart,
|
|
199
|
+
LazySankeyChart,
|
|
200
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECharts 组件注册中心
|
|
3
|
+
* 统一管理所有图表组件的注册,避免重复注册
|
|
4
|
+
*
|
|
5
|
+
* 使用 tree-shaking 友好型导入
|
|
6
|
+
* 仅在用户使用特定图表时加载对应模块
|
|
7
|
+
*/
|
|
8
|
+
import * as echarts from 'echarts/core';
|
|
9
|
+
|
|
10
|
+
// 图表类型 - 按需导入
|
|
11
|
+
import { PieChart } from 'echarts/charts';
|
|
12
|
+
import { LineChart } from 'echarts/charts';
|
|
13
|
+
import { BarChart } from 'echarts/charts';
|
|
14
|
+
import { GaugeChart } from 'echarts/charts';
|
|
15
|
+
import { ScatterChart } from 'echarts/charts';
|
|
16
|
+
import { RadarChart } from 'echarts/charts';
|
|
17
|
+
import { HeatmapChart } from 'echarts/charts';
|
|
18
|
+
import { FunnelChart } from 'echarts/charts';
|
|
19
|
+
|
|
20
|
+
// 组件 - 按需导入
|
|
21
|
+
import {
|
|
22
|
+
TitleComponent,
|
|
23
|
+
TooltipComponent,
|
|
24
|
+
LegendComponent,
|
|
25
|
+
GridComponent,
|
|
26
|
+
DataZoomComponent,
|
|
27
|
+
VisualMapComponent,
|
|
28
|
+
} from 'echarts/components';
|
|
29
|
+
|
|
30
|
+
// 渲染器
|
|
31
|
+
import { CanvasRenderer } from 'echarts/renderers';
|
|
32
|
+
|
|
33
|
+
// 注册渲染器
|
|
34
|
+
echarts.use(CanvasRenderer);
|
|
35
|
+
|
|
36
|
+
// 注册所有图表类型
|
|
37
|
+
const chartTypes = [
|
|
38
|
+
PieChart,
|
|
39
|
+
LineChart,
|
|
40
|
+
BarChart,
|
|
41
|
+
GaugeChart,
|
|
42
|
+
ScatterChart,
|
|
43
|
+
RadarChart,
|
|
44
|
+
HeatmapChart,
|
|
45
|
+
FunnelChart,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
// 注册所有组件
|
|
49
|
+
const components = [
|
|
50
|
+
TitleComponent,
|
|
51
|
+
TooltipComponent,
|
|
52
|
+
LegendComponent,
|
|
53
|
+
GridComponent,
|
|
54
|
+
DataZoomComponent,
|
|
55
|
+
VisualMapComponent,
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// 统一注册
|
|
59
|
+
echarts.use([...chartTypes, ...components]);
|
|
60
|
+
|
|
61
|
+
export default echarts;
|
|
62
|
+
|
|
63
|
+
// 导出图表类型供按需加载使用
|
|
64
|
+
export {
|
|
65
|
+
PieChart,
|
|
66
|
+
LineChart,
|
|
67
|
+
BarChart,
|
|
68
|
+
GaugeChart,
|
|
69
|
+
ScatterChart,
|
|
70
|
+
RadarChart,
|
|
71
|
+
HeatmapChart,
|
|
72
|
+
FunnelChart,
|
|
73
|
+
TitleComponent,
|
|
74
|
+
TooltipComponent,
|
|
75
|
+
LegendComponent,
|
|
76
|
+
GridComponent,
|
|
77
|
+
DataZoomComponent,
|
|
78
|
+
VisualMapComponent,
|
|
79
|
+
CanvasRenderer,
|
|
80
|
+
};
|
package/src/core/index.ts
CHANGED
|
@@ -12,8 +12,11 @@ export * from './utils';
|
|
|
12
12
|
// 核心组件
|
|
13
13
|
export type { ChartProps } from './components/BaseChart';
|
|
14
14
|
|
|
15
|
+
// ECharts 统一导出
|
|
16
|
+
export { default as echarts } from './echarts';
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* 库信息
|
|
17
20
|
*/
|
|
18
21
|
export const name = 'taroviz';
|
|
19
|
-
export const version = '1.
|
|
22
|
+
export const version = '1.2.0';
|