@agions/taroviz 1.7.0 → 1.10.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 +7 -3
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +960 -136
- package/package.json +1 -1
- package/src/adapters/__tests__/index.test.ts +4 -2
- package/src/adapters/h5/index.ts +16 -0
- package/src/adapters/types.ts +28 -120
- package/src/charts/boxplot/types.ts +5 -3
- package/src/charts/common/BaseChartWrapper.tsx +193 -32
- package/src/charts/liquid/index.tsx +6 -5
- package/src/charts/liquid/types.ts +4 -4
- package/src/charts/parallel/types.ts +6 -3
- package/src/charts/tree/types.ts +4 -4
- package/src/charts/types.ts +1 -1
- package/src/core/animation/AnimationManager.ts +69 -42
- package/src/core/components/Annotation.tsx +12 -10
- package/src/core/components/BaseChart.tsx +75 -12
- package/src/core/components/ErrorBoundary.tsx +30 -17
- package/src/core/components/LazyChart.tsx +14 -9
- package/src/core/themes/ThemeManager.ts +33 -0
- package/src/core/types/common.ts +21 -110
- package/src/core/types/index.ts +4 -135
- package/src/core/types/platform.ts +38 -230
- package/src/core/utils/chartUtils.ts +8 -3
- package/src/core/utils/export/ExportUtils.ts +10 -1
- package/src/core/utils/performance/PerformanceAnalyzer.ts +21 -1
- package/src/core/utils/performance/types.ts +5 -0
- package/src/hooks/__tests__/index.test.tsx +7 -5
- package/src/hooks/index.ts +23 -1
- package/src/hooks/useAnimation.ts +427 -0
- package/src/hooks/useChartHistory.ts +273 -0
- package/src/hooks/useChartSelection.ts +350 -0
- package/src/hooks/usePerformance.ts +291 -0
- package/src/themes/__tests__/index.test.ts +7 -13
|
@@ -578,6 +578,39 @@ class ThemeManager {
|
|
|
578
578
|
return this.currentTheme.isDark || this.currentTheme.type === 'dark';
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
/**
|
|
582
|
+
* 检测系统 prefers-color-scheme 是否为暗色
|
|
583
|
+
*/
|
|
584
|
+
public getSystemPrefersDark(): boolean {
|
|
585
|
+
if (typeof window === 'undefined') return false;
|
|
586
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* 订阅系统主题变化,自动切换匹配的主题
|
|
591
|
+
* @returns 取消订阅的函数
|
|
592
|
+
*/
|
|
593
|
+
public watchSystemTheme(): () => void {
|
|
594
|
+
if (typeof window === 'undefined') return () => {};
|
|
595
|
+
|
|
596
|
+
const mq = window.matchMedia('(prefers-color-scheme: dark)');
|
|
597
|
+
const handler = (e: MediaQueryListEvent) => {
|
|
598
|
+
// 当系统主题切换时,自动应用对应主题
|
|
599
|
+
this.setTheme(e.matches ? 'dark' : 'default');
|
|
600
|
+
};
|
|
601
|
+
mq.addEventListener('change', handler);
|
|
602
|
+
return () => mq.removeEventListener('change', handler);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* 应用初始主题(根据系统偏好自动选择 dark/default)
|
|
607
|
+
* 必须在 DOM 加载后调用
|
|
608
|
+
*/
|
|
609
|
+
public applyInitialTheme(): void {
|
|
610
|
+
const prefersDark = this.getSystemPrefersDark();
|
|
611
|
+
this.setTheme(prefersDark ? 'dark' : 'default');
|
|
612
|
+
}
|
|
613
|
+
|
|
581
614
|
/**
|
|
582
615
|
* 注册主题变更监听器
|
|
583
616
|
*/
|
package/src/core/types/common.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ECharts 类型定义
|
|
3
3
|
*/
|
|
4
|
-
export type EChartsOption
|
|
4
|
+
export type { EChartsOption } from 'echarts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 图表事件参数类型
|
|
8
|
+
* 使用 ECharts 内的事件参数接口
|
|
9
|
+
*/
|
|
10
|
+
export interface ChartEventParams {
|
|
11
|
+
componentType?: string;
|
|
12
|
+
seriesType?: string;
|
|
13
|
+
seriesIndex?: number;
|
|
14
|
+
seriesName?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
dataIndex?: number;
|
|
17
|
+
data?: unknown;
|
|
18
|
+
value?: unknown;
|
|
19
|
+
color?: string;
|
|
20
|
+
borderColor?: string;
|
|
21
|
+
borderWidth?: number;
|
|
22
|
+
target?: unknown;
|
|
23
|
+
}
|
|
5
24
|
|
|
6
25
|
/**
|
|
7
26
|
* 图表事件监听器
|
|
8
27
|
*/
|
|
9
|
-
export type ChartEventListener = Record<string, (params:
|
|
28
|
+
export type ChartEventListener = Record<string, (params: ChartEventParams) => void>;
|
|
10
29
|
|
|
11
30
|
/**
|
|
12
31
|
* 图表渲染器类型
|
|
@@ -17,24 +36,9 @@ export type ChartRenderer = 'canvas' | 'svg';
|
|
|
17
36
|
* DataURL选项
|
|
18
37
|
*/
|
|
19
38
|
export interface DataURLOption {
|
|
20
|
-
/**
|
|
21
|
-
* 导出的图片类型
|
|
22
|
-
*/
|
|
23
39
|
type?: 'png' | 'jpeg';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 设备像素比
|
|
27
|
-
*/
|
|
28
40
|
pixelRatio?: number;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 背景色
|
|
32
|
-
*/
|
|
33
41
|
backgroundColor?: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 排除的组件列表
|
|
37
|
-
*/
|
|
38
42
|
excludeComponents?: string[];
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -42,14 +46,7 @@ export interface DataURLOption {
|
|
|
42
46
|
* 图表尺寸类型
|
|
43
47
|
*/
|
|
44
48
|
export interface ChartSize {
|
|
45
|
-
/**
|
|
46
|
-
* 宽度
|
|
47
|
-
*/
|
|
48
49
|
width?: number | string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 高度
|
|
52
|
-
*/
|
|
53
50
|
height?: number | string;
|
|
54
51
|
}
|
|
55
52
|
|
|
@@ -57,29 +54,10 @@ export interface ChartSize {
|
|
|
57
54
|
* 图表动画设置
|
|
58
55
|
*/
|
|
59
56
|
export interface ChartAnimation {
|
|
60
|
-
/**
|
|
61
|
-
* 是否启用动画
|
|
62
|
-
*/
|
|
63
57
|
enabled?: boolean;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 动画时长
|
|
67
|
-
*/
|
|
68
58
|
duration?: number;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 动画缓动效果
|
|
72
|
-
*/
|
|
73
59
|
easing?: string;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 初始动画时长
|
|
77
|
-
*/
|
|
78
60
|
animationDuration?: number;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 更新动画时长
|
|
82
|
-
*/
|
|
83
61
|
animationDurationUpdate?: number;
|
|
84
62
|
}
|
|
85
63
|
|
|
@@ -87,29 +65,10 @@ export interface ChartAnimation {
|
|
|
87
65
|
* 图表主题设置
|
|
88
66
|
*/
|
|
89
67
|
export interface ChartTheme {
|
|
90
|
-
/**
|
|
91
|
-
* 主题名称或配置
|
|
92
|
-
*/
|
|
93
68
|
theme?: string | object;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 背景色
|
|
97
|
-
*/
|
|
98
69
|
backgroundColor?: string;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 文本颜色
|
|
102
|
-
*/
|
|
103
70
|
textColor?: string;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 轴线颜色
|
|
107
|
-
*/
|
|
108
71
|
axisLineColor?: string;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 分割线颜色
|
|
112
|
-
*/
|
|
113
72
|
splitLineColor?: string;
|
|
114
73
|
}
|
|
115
74
|
|
|
@@ -117,64 +76,17 @@ export interface ChartTheme {
|
|
|
117
76
|
* 图表加载状态配置
|
|
118
77
|
*/
|
|
119
78
|
export interface ChartLoadingOptions {
|
|
120
|
-
/**
|
|
121
|
-
* 加载提示文本
|
|
122
|
-
*/
|
|
123
79
|
text?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 加载动画颜色
|
|
127
|
-
*/
|
|
128
80
|
color?: string;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 文本颜色
|
|
132
|
-
*/
|
|
133
81
|
textColor?: string;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 遮罩颜色
|
|
137
|
-
*/
|
|
138
82
|
maskColor?: string;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* z层级
|
|
142
|
-
*/
|
|
143
83
|
zlevel?: number;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 字体大小
|
|
147
|
-
*/
|
|
148
84
|
fontSize?: number;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 是否显示旋转器
|
|
152
|
-
*/
|
|
153
85
|
showSpinner?: boolean;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 旋转器半径
|
|
157
|
-
*/
|
|
158
86
|
spinnerRadius?: number;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* 线宽
|
|
162
|
-
*/
|
|
163
87
|
lineWidth?: number;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 字体粗细
|
|
167
|
-
*/
|
|
168
88
|
fontWeight?: number | string;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 字体样式
|
|
172
|
-
*/
|
|
173
89
|
fontStyle?: string;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* 字体族
|
|
177
|
-
*/
|
|
178
90
|
fontFamily?: string;
|
|
179
91
|
}
|
|
180
92
|
|
|
@@ -216,7 +128,6 @@ export enum ChartEventType {
|
|
|
216
128
|
BRUSHSELECTED = 'brushselected',
|
|
217
129
|
RENDERED = 'rendered',
|
|
218
130
|
FINISHED = 'finished',
|
|
219
|
-
// 自定义事件
|
|
220
131
|
CHART_READY = 'chartReady',
|
|
221
132
|
CHART_RESIZE = 'chartResize',
|
|
222
133
|
CHART_ERROR = 'chartError',
|
package/src/core/types/index.ts
CHANGED
|
@@ -10,14 +10,12 @@ export * from './chart';
|
|
|
10
10
|
import type { EChartsType } from 'echarts';
|
|
11
11
|
|
|
12
12
|
import { ChartOptions } from './chart';
|
|
13
|
+
import { ChartEventParams } from './common';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* TaroViz核心类型定义
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
-
* ECharts类型定义
|
|
20
|
-
*/
|
|
21
19
|
export { EChartsType };
|
|
22
20
|
|
|
23
21
|
// 导出动画相关类型
|
|
@@ -72,7 +70,7 @@ export type RendererType = 'canvas' | 'svg';
|
|
|
72
70
|
/**
|
|
73
71
|
* 图表事件回调类型
|
|
74
72
|
*/
|
|
75
|
-
export type ChartEventCallback = (params:
|
|
73
|
+
export type ChartEventCallback = (params: ChartEventParams) => void;
|
|
76
74
|
|
|
77
75
|
/**
|
|
78
76
|
* 图表事件处理器映射
|
|
@@ -122,160 +120,31 @@ export interface ThemeType {
|
|
|
122
120
|
fontSize?: number;
|
|
123
121
|
};
|
|
124
122
|
};
|
|
125
|
-
[key: string]:
|
|
123
|
+
[key: string]: unknown;
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
/**
|
|
129
127
|
* 渲染性能优化配置
|
|
130
128
|
*/
|
|
131
129
|
export interface RenderOptimizationConfig {
|
|
132
|
-
/**
|
|
133
|
-
* 是否开启渐进式渲染
|
|
134
|
-
*/
|
|
135
130
|
progressive?: boolean;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 渐进式渲染的阈值
|
|
139
|
-
*/
|
|
140
131
|
progressiveThreshold?: number;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 是否启用懒更新
|
|
144
|
-
*/
|
|
145
132
|
lazyUpdate?: boolean;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 是否启用动画
|
|
149
|
-
*/
|
|
150
133
|
animation?: boolean;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 是否启用硬件加速
|
|
154
|
-
*/
|
|
155
134
|
hardwareAcceleration?: boolean;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 帧率限制
|
|
159
|
-
*/
|
|
160
135
|
frameRate?: number;
|
|
161
136
|
}
|
|
162
137
|
|
|
163
|
-
/**
|
|
164
|
-
* 适配器接口定义
|
|
165
|
-
*/
|
|
166
|
-
export interface Adapter {
|
|
167
|
-
/**
|
|
168
|
-
* 初始化图表
|
|
169
|
-
*/
|
|
170
|
-
init(options?: any): EChartsType;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 设置图表配置
|
|
174
|
-
*/
|
|
175
|
-
setOption(option: any, notMerge?: boolean): void;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 获取图表实例
|
|
179
|
-
*/
|
|
180
|
-
getInstance(): EChartsType | null;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 设置组件实例
|
|
184
|
-
*/
|
|
185
|
-
setComponent?(component: any): void;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* 绑定事件
|
|
189
|
-
*/
|
|
190
|
-
on(eventName: string, handler: (params: any) => void): void;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 解绑事件
|
|
194
|
-
*/
|
|
195
|
-
off(eventName: string, handler?: (params: any) => void): void;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 调整图表大小
|
|
199
|
-
*/
|
|
200
|
-
resize(): void;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* 显示加载中
|
|
204
|
-
*/
|
|
205
|
-
showLoading(options?: any): void;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* 隐藏加载中
|
|
209
|
-
*/
|
|
210
|
-
hideLoading(): void;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 清空图表
|
|
214
|
-
*/
|
|
215
|
-
clear(): void;
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 销毁图表
|
|
219
|
-
*/
|
|
220
|
-
dispose(): void;
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 获取DataURL
|
|
224
|
-
*/
|
|
225
|
-
getDataURL?(opts?: any): string | undefined;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 转换为DataURL
|
|
229
|
-
*/
|
|
230
|
-
convertToDataURL?(opts?: any): string | undefined;
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* 渲染图表(仅 H5 环境需要,小程序适配器不需要)
|
|
234
|
-
*/
|
|
235
|
-
render?(): JSX.Element | null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
138
|
/**
|
|
239
139
|
* 适配器配置选项
|
|
240
140
|
*/
|
|
241
141
|
export interface AdapterConfig {
|
|
242
|
-
/**
|
|
243
|
-
* 平台类型
|
|
244
|
-
*/
|
|
245
142
|
platformType?: string;
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 目标canvas元素ID
|
|
249
|
-
*/
|
|
250
143
|
canvasId?: string;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* 图表主题
|
|
254
|
-
*/
|
|
255
144
|
theme?: string;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* 渲染器类型
|
|
259
|
-
*/
|
|
260
145
|
renderer?: 'canvas' | 'svg';
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* 设备像素比
|
|
264
|
-
*/
|
|
265
146
|
devicePixelRatio?: number;
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* 宽度
|
|
269
|
-
*/
|
|
270
147
|
width?: number;
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* 高度
|
|
274
|
-
*/
|
|
275
148
|
height?: number;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* 额外选项
|
|
279
|
-
*/
|
|
280
|
-
[key: string]: any;
|
|
149
|
+
[key: string]: unknown;
|
|
281
150
|
}
|