@agions/taroviz 1.6.0 → 1.9.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 +30 -21
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +49471 -2199
- package/package.json +2 -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/common/BaseChartWrapper.tsx +193 -32
- package/src/charts/index.ts +5 -1
- package/src/charts/liquid/index.tsx +227 -0
- package/src/charts/liquid/types.ts +130 -0
- package/src/charts/tree/index.tsx +117 -0
- package/src/charts/tree/types.ts +174 -0
- package/src/charts/types.ts +1 -1
- package/src/components/DataFilter/index.tsx +587 -0
- package/src/core/animation/AnimationManager.ts +69 -42
- package/src/core/components/BaseChart.tsx +72 -9
- 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/drillDown.ts +643 -0
- 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 +41 -2
- package/src/hooks/useAnimation.ts +427 -0
- package/src/hooks/useChartConnect.ts +362 -0
- package/src/hooks/useChartDownload.ts +692 -0
- package/src/hooks/useDataZoom.ts +323 -0
- package/src/hooks/usePerformance.ts +291 -0
- package/src/index.ts +25 -2
- package/src/themes/__tests__/index.test.ts +7 -13
- package/src/themes/index.ts +3 -0
- package/src/themes/useAutoTheme.ts +66 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAutoTheme - 自动跟随系统暗色模式 Hook
|
|
3
|
+
* 当用户操作系统级别的暗色模式时,图表自动切换到对应的主题
|
|
4
|
+
*/
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
|
+
import { switchTheme } from './index';
|
|
7
|
+
|
|
8
|
+
/** 自动主题配置选项 */
|
|
9
|
+
export interface UseAutoThemeOptions {
|
|
10
|
+
/** 是否启用自动跟随 */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** 暗色主题名称 */
|
|
13
|
+
darkThemeName?: string;
|
|
14
|
+
/** 亮色主题名称 */
|
|
15
|
+
lightThemeName?: string;
|
|
16
|
+
/** 延迟切换的防抖时间 ms */
|
|
17
|
+
debounceMs?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 自动跟随系统暗色模式
|
|
22
|
+
* @param options 配置选项
|
|
23
|
+
*/
|
|
24
|
+
export function useAutoTheme(options?: UseAutoThemeOptions): void {
|
|
25
|
+
const {
|
|
26
|
+
enabled = true,
|
|
27
|
+
darkThemeName = 'dark',
|
|
28
|
+
lightThemeName = 'light',
|
|
29
|
+
debounceMs = 0,
|
|
30
|
+
} = options || {};
|
|
31
|
+
|
|
32
|
+
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!enabled) return;
|
|
36
|
+
|
|
37
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
38
|
+
|
|
39
|
+
const handleChange = (e: MediaQueryListEvent) => {
|
|
40
|
+
// 清除之前的定时器
|
|
41
|
+
if (timeoutRef.current) {
|
|
42
|
+
clearTimeout(timeoutRef.current);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 防抖处理
|
|
46
|
+
timeoutRef.current = setTimeout(() => {
|
|
47
|
+
const isDark = e.matches;
|
|
48
|
+
switchTheme(isDark ? darkThemeName : lightThemeName);
|
|
49
|
+
}, debounceMs);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 初始设置
|
|
53
|
+
const isDark = mediaQuery.matches;
|
|
54
|
+
switchTheme(isDark ? darkThemeName : lightThemeName);
|
|
55
|
+
|
|
56
|
+
// 监听变化
|
|
57
|
+
mediaQuery.addEventListener('change', handleChange);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
mediaQuery.removeEventListener('change', handleChange);
|
|
61
|
+
if (timeoutRef.current) {
|
|
62
|
+
clearTimeout(timeoutRef.current);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}, [enabled, darkThemeName, lightThemeName, debounceMs]);
|
|
66
|
+
}
|