@easyv/charts 1.6.20 → 1.6.21
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/.babelrc +8 -8
- package/CHANGELOG.md +18 -18
- package/commitlint.config.js +1 -1
- package/lib/components/Background.js +2 -2
- package/lib/components/Band.js +55 -31
- package/lib/components/Brush.js +2 -2
- package/lib/components/CartesianChart.js +3 -1
- package/lib/components/Chart.js +2 -3
- package/lib/components/ChartContainer.js +2 -2
- package/lib/components/ConicalGradient.js +21 -21
- package/lib/components/ExtentData.js +2 -2
- package/lib/components/Indicator.js +2 -2
- package/lib/components/Label.js +2 -2
- package/lib/components/Legend.js +2 -2
- package/lib/components/Lighter.js +2 -2
- package/lib/components/Line.js +2 -2
- package/lib/components/LinearGradient.js +2 -2
- package/lib/components/StereoBar.js +2 -2
- package/lib/css/index.module.css +42 -42
- package/lib/css/piechart.module.css +26 -26
- package/lib/hooks/useAnimateData.js +6 -6
- package/lib/hooks/useAxes.js +20 -16
- package/lib/hooks/useFilterData.js +5 -5
- package/lib/hooks/useStackData.js +5 -5
- package/lib/hooks/useTooltip.js +11 -11
- package/package.json +55 -55
- package/src/components/Background.tsx +61 -61
- package/src/components/Band.tsx +321 -302
- package/src/components/Brush.js +159 -159
- package/src/components/CartesianChart.js +1 -1
- package/src/components/Chart.js +153 -153
- package/src/components/ChartContainer.tsx +71 -71
- package/src/components/ConicalGradient.js +258 -258
- package/src/components/Control.jsx +241 -241
- package/src/components/ExtentData.js +18 -18
- package/src/components/Indicator.js +59 -59
- package/src/components/Label.js +262 -262
- package/src/components/Legend.js +189 -189
- package/src/components/Lighter.jsx +173 -173
- package/src/components/Line.js +153 -153
- package/src/components/LinearGradient.js +29 -29
- package/src/components/PieTooltip.jsx +160 -160
- package/src/components/StereoBar.tsx +307 -307
- package/src/components/index.js +59 -59
- package/src/context/index.js +2 -2
- package/src/css/index.module.css +42 -42
- package/src/css/piechart.module.css +26 -26
- package/src/element/ConicGradient.jsx +55 -55
- package/src/element/Line.tsx +33 -33
- package/src/element/index.ts +3 -3
- package/src/formatter/index.js +1 -1
- package/src/formatter/legend.js +114 -114
- package/src/hooks/index.js +20 -20
- package/src/hooks/useAnimateData.ts +68 -68
- package/src/hooks/useAxes.js +20 -16
- package/src/hooks/useFilterData.js +78 -78
- package/src/hooks/useStackData.js +102 -102
- package/src/hooks/useTooltip.ts +104 -104
- package/src/index.js +6 -6
- package/src/types/index.d.ts +68 -68
- package/src/utils/index.js +800 -800
- package/tsconfig.json +23 -23
package/src/components/Legend.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
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
|
-
};
|
|
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
|
+
};
|