@easyv/charts 1.6.13 → 1.6.15

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.
Files changed (62) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/commitlint.config.js +1 -1
  5. package/lib/components/Background.js +2 -2
  6. package/lib/components/Band.js +3 -3
  7. package/lib/components/Brush.js +2 -2
  8. package/lib/components/Chart.js +2 -2
  9. package/lib/components/ChartContainer.js +2 -2
  10. package/lib/components/ConicalGradient.js +21 -21
  11. package/lib/components/ExtentData.js +2 -2
  12. package/lib/components/Indicator.js +2 -2
  13. package/lib/components/Label.js +7 -5
  14. package/lib/components/Legend.js +70 -20
  15. package/lib/components/Lighter.js +2 -2
  16. package/lib/components/Line.js +2 -2
  17. package/lib/components/LinearGradient.js +2 -2
  18. package/lib/components/StereoBar.js +2 -2
  19. package/lib/css/index.module.css +42 -42
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/formatter/legend.js +3 -2
  22. package/lib/hooks/useAnimateData.js +6 -6
  23. package/lib/hooks/useAxes.js +1 -2
  24. package/lib/hooks/useFilterData.js +5 -5
  25. package/lib/hooks/useStackData.js +5 -5
  26. package/lib/hooks/useTooltip.js +11 -11
  27. package/package.json +55 -55
  28. package/src/components/Background.tsx +61 -61
  29. package/src/components/Band.tsx +271 -271
  30. package/src/components/Brush.js +159 -159
  31. package/src/components/Chart.js +154 -154
  32. package/src/components/ChartContainer.tsx +71 -71
  33. package/src/components/ConicalGradient.js +258 -258
  34. package/src/components/Control.jsx +241 -241
  35. package/src/components/ExtentData.js +18 -18
  36. package/src/components/Indicator.js +58 -58
  37. package/src/components/Label.js +247 -246
  38. package/src/components/Legend.js +189 -166
  39. package/src/components/Lighter.jsx +173 -173
  40. package/src/components/Line.js +153 -153
  41. package/src/components/LinearGradient.js +29 -29
  42. package/src/components/PieTooltip.jsx +160 -160
  43. package/src/components/StereoBar.tsx +307 -307
  44. package/src/components/index.js +59 -59
  45. package/src/context/index.js +2 -2
  46. package/src/css/index.module.css +42 -42
  47. package/src/css/piechart.module.css +26 -26
  48. package/src/element/ConicGradient.jsx +55 -55
  49. package/src/element/Line.tsx +33 -33
  50. package/src/element/index.ts +3 -3
  51. package/src/formatter/index.js +1 -1
  52. package/src/formatter/legend.js +114 -112
  53. package/src/hooks/index.js +20 -20
  54. package/src/hooks/useAnimateData.ts +68 -68
  55. package/src/hooks/useAxes.js +1 -2
  56. package/src/hooks/useFilterData.js +78 -78
  57. package/src/hooks/useStackData.js +102 -102
  58. package/src/hooks/useTooltip.ts +104 -104
  59. package/src/index.js +6 -6
  60. package/src/types/index.d.ts +68 -68
  61. package/src/utils/index.js +782 -782
  62. package/tsconfig.json +23 -23
@@ -1,166 +1,189 @@
1
- /**
2
- * 图例
3
- */
4
- import React, { memo, useCallback } from 'react';
5
- import { getIcon, sortPie } from '../utils';
6
- import TextOverflow from './TextOverflow';
7
-
8
- const defaultFont = {
9
- fontStyle: 'normal',
10
- fontWeight: 'normal',
11
- };
12
-
13
- export default memo(
14
- ({
15
- series,
16
- config,
17
- config: {
18
- show,
19
- order = '',
20
- interactive,
21
- maxWidth,
22
- textOverflow,
23
- speed,
24
- layout: {
25
- alignment = 'right center',
26
- gridTemplateColumns,
27
- gridGap: { gridColumnGap, gridRowGap },
28
- translate: { x, y },
29
- },
30
- font: { italic, bold, ...font } = defaultFont,
31
- unselect: { opacity = 1 } = {},
32
- },
33
- filterData,
34
- formatter,
35
- judge
36
- }) => {
37
- if (!show) return null;
38
- const _series = sortPie(series, order);
39
- const [_alignment, position] = alignment.split(' ');
40
- const length = _series.length;
41
-
42
- const onClick = useCallback(
43
- (e) => {
44
- const { dataset } = e.currentTarget;
45
- const { name } = dataset;
46
- filterData && interactive && filterData(name);
47
- },
48
- [interactive, filterData]
49
- );
50
-
51
- if (judge == 0) {
52
- _series.forEach((d) => {
53
- d.percent=0
54
- })
55
- }
56
-
57
- return (
58
- <div
59
- className='__easyv-legend-wrapper'
60
- style={{
61
- position: 'absolute',
62
- height: 'auto',
63
- display: 'flex',
64
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
65
- ...getPosition(position, _alignment),
66
- }}
67
- >
68
- <ul
69
- style={{
70
- display: 'grid',
71
- gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
72
- gridTemplateColumns:
73
- 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
74
- }}
75
- >
76
- {_series.map((series, index) => {
77
- const { type, name, displayName, icon, selected } = series;
78
- const _icon = getIcon(type, icon, series?.config?.line?.type);
79
- return (
80
- <li
81
- key={index}
82
- onClick={onClick}
83
- data-name={name}
84
- style={{
85
- display: 'flex',
86
- opacity: selected === false ? opacity / 100 : 1,
87
- alignItems: 'center',
88
- cursor: "pointer",
89
- gap: _icon.gap,
90
- }}
91
- >
92
- {formatter ? (
93
- formatter(series, config)
94
- ) : (
95
- <>
96
- <span style={_icon} />
97
- <TextOverflow type={textOverflow} value={displayName || name} style={{
98
- ...font,
99
- width:maxWidth,
100
- fontStyle: italic ? 'italic' : 'normal',
101
- fontWeight: bold ? 'bold' : 'normal',
102
- }} speed={speed}></TextOverflow>
103
-
104
- </>
105
- )}
106
- </li>
107
- );
108
- })}
109
- </ul>
110
- </div>
111
- );
112
- }
113
- );
114
-
115
- const getPosition = (position, alignment) => {
116
- switch (position) {
117
- case 'top':
118
- return {
119
- left: 0,
120
- right: 0,
121
- top: 5,
122
- justifyContent:
123
- alignment === 'center'
124
- ? 'center'
125
- : alignment === 'left'
126
- ? 'flex-start'
127
- : 'flex-end',
128
- };
129
- case 'right':
130
- return {
131
- top: 0,
132
- bottom: 0,
133
- right: 10,
134
- alignItems:
135
- alignment === 'center'
136
- ? 'center'
137
- : alignment === 'left'
138
- ? 'flex-start'
139
- : 'flex-end',
140
- };
141
- case 'left':
142
- return {
143
- top: 0,
144
- bottom: 0,
145
- left: 10,
146
- alignItems:
147
- alignment === 'center'
148
- ? 'center'
149
- : alignment === 'left'
150
- ? 'flex-start'
151
- : 'flex-end',
152
- };
153
- default:
154
- return {
155
- left: 0,
156
- right: 0,
157
- bottom: 5,
158
- justifyContent:
159
- alignment === 'center'
160
- ? 'center'
161
- : alignment === 'left'
162
- ? 'flex-start'
163
- : 'flex-end',
164
- };
165
- }
166
- };
1
+ /**
2
+ * 图例
3
+ */
4
+ import React, { memo, useCallback, useState, useEffect, useRef } from 'react';
5
+ import { getIcon, sortPie } from '../utils';
6
+ import TextOverflow from './TextOverflow';
7
+
8
+ const defaultFont = {
9
+ fontStyle: 'normal',
10
+ fontWeight: 'normal',
11
+ };
12
+
13
+ export default memo(
14
+ ({
15
+ series,
16
+ config,
17
+ config: {
18
+ show,
19
+ order = '',
20
+ interactive,
21
+ maxWidth,
22
+ textOverflow,
23
+ speed,
24
+ layout: {
25
+ alignment = 'right center',
26
+ gridTemplateColumns,
27
+ gridGap: { gridColumnGap, gridRowGap },
28
+ translate: { x, y },
29
+ },
30
+ loop = {},
31
+ font: { italic, bold, ...font } = defaultFont,
32
+ unselect: { opacity = 1 } = {},
33
+ },
34
+ filterData,
35
+ formatter,
36
+ judge
37
+ }) => {
38
+ if (!show) return null;
39
+
40
+ const ref_container = useRef(null); // 滚动容器
41
+ const ref_scrollTop = useRef(0); // 当前滚动距离
42
+
43
+ const [scrollStep, setScrollStep] = useState(0); // 行高度
44
+
45
+ // 初始化行高
46
+ useEffect(() => {
47
+ if (ref_container.current) {
48
+ const rowHeight = ref_container.current.querySelector('li').clientHeight + gridRowGap;
49
+ setScrollStep(rowHeight);
50
+ }
51
+ }, [gridRowGap]);
52
+
53
+ // 启动自动滚动定时器
54
+ useEffect(() => {
55
+ if (!loop.show) return;
56
+
57
+ ref_scrollTop.current = 0;
58
+
59
+ const timer = setInterval(() => {
60
+ handleAutoScroll();
61
+ }, loop.interval * 1000); // 每隔3秒滚动一次
62
+
63
+ // 清除定时器
64
+ return () => clearInterval(timer);
65
+ }, [scrollStep, loop.show, loop.interval])
66
+
67
+ const handleAutoScroll = () => {
68
+ const table = ref_container.current;
69
+ if (!table) return;
70
+
71
+ // 如果已经滚动到了底部,则返回顶部
72
+ if (ref_scrollTop.current + table.clientHeight >= table.scrollHeight) {
73
+ ref_scrollTop.current = 0;
74
+ } else {
75
+ // 否则,滚动一行的高度
76
+ ref_scrollTop.current += scrollStep;
77
+ }
78
+
79
+ table.scrollTo({ top: ref_scrollTop.current, behavior: 'smooth' });
80
+ };
81
+
82
+ const _series = sortPie(series, order);
83
+ const [_alignment, position] = alignment.split(' ');
84
+ const length = _series.length;
85
+
86
+ const onClick = useCallback(
87
+ (e) => {
88
+ const { dataset } = e.currentTarget;
89
+ const { name } = dataset;
90
+ filterData && interactive && filterData(name);
91
+ },
92
+ [interactive, filterData]
93
+ );
94
+
95
+ if (judge == 0) {
96
+ _series.forEach((d) => {
97
+ d.percent=0
98
+ })
99
+ }
100
+
101
+ return (
102
+ <div
103
+ className='__easyv-legend-wrapper'
104
+ style={{
105
+ position: 'absolute',
106
+ display: 'flex',
107
+ ...getPosition(position, _alignment, x, y),
108
+ height: loop.show ? loop.height : 'auto',
109
+ overflowY: loop.show ? 'scroll' : 'auto',
110
+ }}
111
+ ref={ref_container}
112
+ >
113
+ <ul
114
+ style={{
115
+ display: 'grid',
116
+ gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
117
+ gridTemplateColumns:
118
+ 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
119
+ }}
120
+ >
121
+ {_series.map((series, index) => {
122
+ const { type, name, displayName, icon, selected } = series;
123
+ const _icon = getIcon(type, icon, series?.config?.line?.type);
124
+ return (
125
+ <li
126
+ key={index}
127
+ onClick={onClick}
128
+ data-name={name}
129
+ style={{
130
+ display: 'flex',
131
+ opacity: selected === false ? opacity / 100 : 1,
132
+ alignItems: 'center',
133
+ cursor: "pointer",
134
+ gap: _icon.gap,
135
+ }}
136
+ >
137
+ {formatter ? (
138
+ formatter(series, config)
139
+ ) : (
140
+ <>
141
+ <span style={_icon} />
142
+ <TextOverflow type={textOverflow} value={displayName || name} style={{
143
+ ...font,
144
+ width:maxWidth,
145
+ fontStyle: italic ? 'italic' : 'normal',
146
+ fontWeight: bold ? 'bold' : 'normal',
147
+ }} speed={speed}></TextOverflow>
148
+
149
+ </>
150
+ )}
151
+ </li>
152
+ );
153
+ })}
154
+ </ul>
155
+ </div>
156
+ );
157
+ }
158
+ );
159
+
160
+ const getPosition = (position, alignment, x = 0, y = 0) => {
161
+ switch (position) {
162
+ case 'top':
163
+ return {
164
+ left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
165
+ right: alignment == 'right' ? 10 : '',
166
+ top: 5,
167
+ transform: `translate3d(calc(${alignment == 'center' ? '-50%' : '0px'} + ${x}px), ${y}px, 0px)`
168
+ };
169
+ case 'right':
170
+ return {
171
+ top: '50%',
172
+ right: 10,
173
+ transform: `translate3d(${x}px, calc(-50% + ${y}px), 0px)`
174
+ };
175
+ case 'left':
176
+ return {
177
+ top: '50%',
178
+ left: 5,
179
+ transform: `translate3d(${x}px, calc(-50% + ${y}px), 0px)`
180
+ };
181
+ default: // bottom
182
+ return {
183
+ left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
184
+ right: alignment == 'right' ? 10 : '',
185
+ bottom: 5,
186
+ transform: `translate3d(calc(${alignment == 'center' ? '-50%' : '0px'} + ${x}px), ${y}px, 0px)`
187
+ };
188
+ }
189
+ };