@easyv/charts 1.0.75 → 1.1.2
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/.husky/commit-msg +4 -0
- package/CHANGELOG.md +18 -0
- package/commitlint.config.js +1 -0
- package/lib/components/AnimateData.js +2 -2
- package/lib/components/Axis.js +36 -17
- package/lib/components/Background.js +2 -2
- package/lib/components/Band.js +4 -1
- package/lib/components/Carousel.js +2 -2
- package/lib/components/CartesianChart.js +8 -2
- package/lib/components/Chart.js +2 -2
- package/lib/components/ConicalGradient.js +21 -21
- package/lib/components/Indicator.js +2 -2
- package/lib/components/Lighter.js +180 -0
- package/lib/components/LinearGradient.js +2 -2
- package/lib/components/Tooltip.js +30 -12
- package/lib/components/index.js +8 -0
- package/lib/css/index.module.css +41 -41
- package/lib/css/piechart.module.css +26 -26
- package/lib/element/ConicGradient.js +73 -0
- package/lib/hooks/useAnimateData.js +5 -5
- package/lib/hooks/useAxes.js +5 -5
- package/lib/hooks/useCarouselAxisX.js +5 -5
- package/lib/hooks/useExtentData.js +6 -6
- package/lib/hooks/useFilterData.js +5 -5
- package/lib/hooks/useStackData.js +5 -5
- package/lib/hooks/useTooltip.js +10 -10
- package/lib/utils/index.js +1 -1
- package/package.json +52 -34
- package/src/components/AnimateData.tsx +24 -24
- package/src/components/Axis.tsx +354 -336
- package/src/components/Background.tsx +45 -45
- package/src/components/Band.tsx +173 -171
- package/src/components/Brush.js +159 -159
- package/src/components/Carousel.tsx +144 -144
- package/src/components/CartesianChart.js +7 -1
- package/src/components/Chart.js +99 -99
- package/src/components/ChartContainer.tsx +63 -63
- package/src/components/ConicalGradient.js +258 -258
- package/src/components/ExtentData.js +17 -17
- package/src/components/FilterData.js +23 -23
- package/src/components/Indicator.js +13 -13
- package/src/components/Label.js +206 -206
- package/src/components/Legend.js +158 -158
- package/src/components/Lighter.jsx +173 -162
- package/src/components/Line.js +144 -144
- package/src/components/LinearGradient.js +29 -29
- package/src/components/Mapping.js +71 -71
- package/src/components/PieChart.js +1097 -1097
- package/src/components/StackData.js +20 -20
- package/src/components/StereoBar.tsx +298 -298
- package/src/components/Tooltip.js +168 -133
- package/src/components/index.js +51 -49
- package/src/context/index.js +2 -2
- package/src/css/index.module.css +41 -41
- 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 +90 -90
- package/src/hooks/index.js +17 -17
- package/src/hooks/useAnimateData.ts +62 -62
- package/src/hooks/useAxes.js +144 -144
- package/src/hooks/useCarouselAxisX.js +163 -163
- package/src/hooks/useExtentData.js +88 -88
- package/src/hooks/useFilterData.js +72 -72
- package/src/hooks/useStackData.js +100 -100
- package/src/hooks/useTooltip.ts +96 -96
- package/src/index.js +6 -6
- package/src/types/index.d.ts +62 -59
- package/src/utils/index.js +696 -692
- package/tsconfig.json +22 -22
|
@@ -1,133 +1,168 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 提示框
|
|
3
|
-
*/
|
|
4
|
-
import { memo } from 'react';
|
|
5
|
-
import { getFontStyle, getMargin, getTranslate3d } from '../utils';
|
|
6
|
-
import { getIcon } from '../utils';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
config: {
|
|
16
|
-
tip: {
|
|
17
|
-
data: {
|
|
18
|
-
xAxis,
|
|
19
|
-
xAxis: { align, font, translate: translateXAxis },
|
|
20
|
-
data: dataConfig,
|
|
21
|
-
data: { lineHeight, iconSize, name, value, suffix },
|
|
22
|
-
},
|
|
23
|
-
image,
|
|
24
|
-
margin,
|
|
25
|
-
size: { width, height },
|
|
26
|
-
translate: translateTip,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
formatter,
|
|
30
|
-
isVertical,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 提示框
|
|
3
|
+
*/
|
|
4
|
+
import { memo, useMemo } from 'react';
|
|
5
|
+
import { getFontStyle, getMargin, getTranslate3d } from '../utils';
|
|
6
|
+
import { getIcon } from '../utils';
|
|
7
|
+
export default memo(
|
|
8
|
+
({
|
|
9
|
+
x: position,
|
|
10
|
+
tickName: x,
|
|
11
|
+
marginLeft,
|
|
12
|
+
marginTop,
|
|
13
|
+
data,
|
|
14
|
+
series,
|
|
15
|
+
config: {
|
|
16
|
+
tip: {
|
|
17
|
+
data: {
|
|
18
|
+
xAxis,
|
|
19
|
+
xAxis: { align, font, translate: translateXAxis },
|
|
20
|
+
data: dataConfig,
|
|
21
|
+
data: { lineHeight, iconSize, name, value, suffix },
|
|
22
|
+
},
|
|
23
|
+
image,
|
|
24
|
+
margin,
|
|
25
|
+
size: { width: tipWidth, height: tipHeight },
|
|
26
|
+
translate: translateTip,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
formatter,
|
|
30
|
+
isVertical,
|
|
31
|
+
width,
|
|
32
|
+
height,
|
|
33
|
+
}) => {
|
|
34
|
+
const tipPosition = useMemo(() => {
|
|
35
|
+
const translate3d = isVertical
|
|
36
|
+
? {
|
|
37
|
+
...translateTip,
|
|
38
|
+
y: translateTip.y + position + marginTop,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
...translateTip,
|
|
42
|
+
x: translateTip.x + position + marginLeft,
|
|
43
|
+
};
|
|
44
|
+
if (translate3d.x + tipWidth > width) {
|
|
45
|
+
const newPositon = position + marginLeft - tipWidth - translateTip.x;
|
|
46
|
+
translate3d.x = newPositon >= 0 ? newPositon : 0;
|
|
47
|
+
}
|
|
48
|
+
if (translate3d.y + tipHeight > height) {
|
|
49
|
+
const newPositon = position + marginTop - tipHeight - translateTip.y;
|
|
50
|
+
translate3d.y = newPositon >= 0 ? newPositon : height - tipHeight;
|
|
51
|
+
}
|
|
52
|
+
return getTranslate3d(translate3d);
|
|
53
|
+
}, [
|
|
54
|
+
width,
|
|
55
|
+
height,
|
|
56
|
+
marginLeft,
|
|
57
|
+
marginTop,
|
|
58
|
+
position,
|
|
59
|
+
tipWidth,
|
|
60
|
+
tipHeight,
|
|
61
|
+
translateTip,
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
className='__easyv-tooltip'
|
|
67
|
+
style={{
|
|
68
|
+
pointerEvents: 'none',
|
|
69
|
+
transform: tipPosition,
|
|
70
|
+
width: tipWidth,
|
|
71
|
+
height: tipHeight,
|
|
72
|
+
padding: getMargin(margin),
|
|
73
|
+
background: image
|
|
74
|
+
? '50% 50% / 100% 100% no-repeat url(' +
|
|
75
|
+
window.appConfig.ASSETS_URL +
|
|
76
|
+
image +
|
|
77
|
+
')'
|
|
78
|
+
: 'rgba(48, 55, 66, 0.85)',
|
|
79
|
+
...getFontStyle(font),
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
{formatter ? (
|
|
83
|
+
formatter({
|
|
84
|
+
series,
|
|
85
|
+
x: { x, config: xAxis },
|
|
86
|
+
data: { data, config: dataConfig },
|
|
87
|
+
})
|
|
88
|
+
) : (
|
|
89
|
+
<dl
|
|
90
|
+
style={{
|
|
91
|
+
display: 'flex',
|
|
92
|
+
flexDirection: 'column',
|
|
93
|
+
justifyContent: 'space-between',
|
|
94
|
+
height: '100%',
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<dt
|
|
98
|
+
style={{
|
|
99
|
+
textAlign: align,
|
|
100
|
+
transform: getTranslate3d(translateXAxis),
|
|
101
|
+
...font,
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
{x}
|
|
105
|
+
</dt>
|
|
106
|
+
{data.map(({ showY, s }, index) => {
|
|
107
|
+
const { type, icon, displayName } = series.find(
|
|
108
|
+
(series) => series.name == s
|
|
109
|
+
);
|
|
110
|
+
const {
|
|
111
|
+
show: showSuffix,
|
|
112
|
+
content,
|
|
113
|
+
font: suffiixFont,
|
|
114
|
+
translate: suffixTranslate,
|
|
115
|
+
} = suffix;
|
|
116
|
+
const tmp = new Map();
|
|
117
|
+
Object.values(content).forEach((item) => {
|
|
118
|
+
tmp.set(item['suffix'].name, item['suffix'].suffix);
|
|
119
|
+
});
|
|
120
|
+
const _icon = getIcon(type, icon);
|
|
121
|
+
return (
|
|
122
|
+
<dd
|
|
123
|
+
style={{
|
|
124
|
+
display: 'flex',
|
|
125
|
+
justifyContent: 'space-between',
|
|
126
|
+
lineHeight: lineHeight + 'px',
|
|
127
|
+
}}
|
|
128
|
+
key={index}
|
|
129
|
+
>
|
|
130
|
+
<span
|
|
131
|
+
style={{
|
|
132
|
+
border: '1px solid red',
|
|
133
|
+
display: 'flex',
|
|
134
|
+
alignItems: 'center',
|
|
135
|
+
gap: icon.iconGap,
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<span
|
|
139
|
+
style={{
|
|
140
|
+
..._icon,
|
|
141
|
+
width: iconSize + 'px',
|
|
142
|
+
height: iconSize + 'px',
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
145
|
+
<span style={getFontStyle(name)}>{displayName || s}</span>
|
|
146
|
+
</span>
|
|
147
|
+
<span style={getFontStyle(value)}>
|
|
148
|
+
{showY}
|
|
149
|
+
{showSuffix && (
|
|
150
|
+
<span
|
|
151
|
+
style={{
|
|
152
|
+
...getFontStyle(suffiixFont),
|
|
153
|
+
transform: getTranslate3d(suffixTranslate),
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{tmp.get(s)}
|
|
157
|
+
</span>
|
|
158
|
+
)}
|
|
159
|
+
</span>
|
|
160
|
+
</dd>
|
|
161
|
+
);
|
|
162
|
+
})}
|
|
163
|
+
</dl>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
);
|
package/src/components/index.js
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import Mapping from './Mapping';
|
|
2
|
-
import AnimateData from './AnimateData';
|
|
3
|
-
import FilterData from './FilterData';
|
|
4
|
-
import ExtentData from './ExtentData';
|
|
5
|
-
import StackData from './StackData';
|
|
6
|
-
import ChartContainer from './ChartContainer';
|
|
7
|
-
import Legend from './Legend';
|
|
8
|
-
import Axis from './Axis';
|
|
9
|
-
import Tooltip from './Tooltip';
|
|
10
|
-
import Indicator from './Indicator';
|
|
11
|
-
import Band from './Band';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
import Mapping from './Mapping';
|
|
2
|
+
import AnimateData from './AnimateData';
|
|
3
|
+
import FilterData from './FilterData';
|
|
4
|
+
import ExtentData from './ExtentData';
|
|
5
|
+
import StackData from './StackData';
|
|
6
|
+
import ChartContainer from './ChartContainer';
|
|
7
|
+
import Legend from './Legend';
|
|
8
|
+
import Axis from './Axis';
|
|
9
|
+
import Tooltip from './Tooltip';
|
|
10
|
+
import Indicator from './Indicator';
|
|
11
|
+
import Band from './Band';
|
|
12
|
+
import Lighter from './Lighter';
|
|
13
|
+
import Line from './Line';
|
|
14
|
+
import Background from './Background';
|
|
15
|
+
import LinearGradient from './LinearGradient';
|
|
16
|
+
import Brush from './Brush';
|
|
17
|
+
import Label from './Label';
|
|
18
|
+
import StereoBar from './StereoBar';
|
|
19
|
+
import Carousel from './Carousel';
|
|
20
|
+
import Chart from './Chart';
|
|
21
|
+
import ConicalGradient from './ConicalGradient';
|
|
22
|
+
import CartesianChart from './CartesianChart';
|
|
23
|
+
import PieChart from './PieChart';
|
|
24
|
+
|
|
25
|
+
const Area = Line;
|
|
26
|
+
export {
|
|
27
|
+
Mapping,
|
|
28
|
+
AnimateData,
|
|
29
|
+
FilterData,
|
|
30
|
+
StackData,
|
|
31
|
+
ExtentData,
|
|
32
|
+
ChartContainer,
|
|
33
|
+
Legend,
|
|
34
|
+
Tooltip,
|
|
35
|
+
Axis,
|
|
36
|
+
Indicator,
|
|
37
|
+
Band,
|
|
38
|
+
Lighter,
|
|
39
|
+
Line,
|
|
40
|
+
Area,
|
|
41
|
+
Background,
|
|
42
|
+
LinearGradient,
|
|
43
|
+
Brush,
|
|
44
|
+
Label,
|
|
45
|
+
StereoBar,
|
|
46
|
+
Carousel,
|
|
47
|
+
CartesianChart,
|
|
48
|
+
PieChart,
|
|
49
|
+
Chart,
|
|
50
|
+
ConicalGradient,
|
|
51
|
+
};
|
package/src/context/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
export const chartContext = createContext();
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
export const chartContext = createContext();
|
package/src/css/index.module.css
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
.rotateClockwise {
|
|
2
|
-
animation-name: rotateClockwise;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
@keyframes rotateClockwise {
|
|
6
|
-
0% {
|
|
7
|
-
transform: rotate(0deg);
|
|
8
|
-
}
|
|
9
|
-
100% {
|
|
10
|
-
transform: rotate(360deg);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.rotateCounterClockwise {
|
|
15
|
-
animation-name: rotateCounterClockwise;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@keyframes rotateCounterClockwise {
|
|
19
|
-
0% {
|
|
20
|
-
transform: rotate(360deg);
|
|
21
|
-
}
|
|
22
|
-
100% {
|
|
23
|
-
transform: rotate(0deg);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.showAllStyle {
|
|
28
|
-
display: grid;
|
|
29
|
-
width: 100%;
|
|
30
|
-
grid-template-columns: 40% 30% 30%;
|
|
31
|
-
align-items: center;
|
|
32
|
-
flex-direction: row;
|
|
33
|
-
justify-content: space-between;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.notShowAllStyle {
|
|
37
|
-
display: flex;
|
|
38
|
-
width: 100%;
|
|
39
|
-
align-items: center;
|
|
40
|
-
flex-direction: row;
|
|
41
|
-
justify-content: space-between;
|
|
1
|
+
.rotateClockwise {
|
|
2
|
+
animation-name: rotateClockwise;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
@keyframes rotateClockwise {
|
|
6
|
+
0% {
|
|
7
|
+
transform: rotate(0deg);
|
|
8
|
+
}
|
|
9
|
+
100% {
|
|
10
|
+
transform: rotate(360deg);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.rotateCounterClockwise {
|
|
15
|
+
animation-name: rotateCounterClockwise;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@keyframes rotateCounterClockwise {
|
|
19
|
+
0% {
|
|
20
|
+
transform: rotate(360deg);
|
|
21
|
+
}
|
|
22
|
+
100% {
|
|
23
|
+
transform: rotate(0deg);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.showAllStyle {
|
|
28
|
+
display: grid;
|
|
29
|
+
width: 100%;
|
|
30
|
+
grid-template-columns: 40% 30% 30%;
|
|
31
|
+
align-items: center;
|
|
32
|
+
flex-direction: row;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.notShowAllStyle {
|
|
37
|
+
display: flex;
|
|
38
|
+
width: 100%;
|
|
39
|
+
align-items: center;
|
|
40
|
+
flex-direction: row;
|
|
41
|
+
justify-content: space-between;
|
|
42
42
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/*甜甜圈图专用css*/
|
|
2
|
-
.label-line {
|
|
3
|
-
stroke-dasharray: 100;
|
|
4
|
-
stroke-dashoffset: 100;
|
|
5
|
-
animation: dash 800ms ease forwards;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.label-text {
|
|
9
|
-
opacity: 0;
|
|
10
|
-
animation: show 800ms ease forwards;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.inner-arc {
|
|
14
|
-
animation: dash 2s ease forwards;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@keyframes dash {
|
|
18
|
-
100% {
|
|
19
|
-
stroke-dashoffset: 0%;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@keyframes show {
|
|
24
|
-
100% {
|
|
25
|
-
opacity: 1;
|
|
26
|
-
}
|
|
1
|
+
/*甜甜圈图专用css*/
|
|
2
|
+
.label-line {
|
|
3
|
+
stroke-dasharray: 100;
|
|
4
|
+
stroke-dashoffset: 100;
|
|
5
|
+
animation: dash 800ms ease forwards;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.label-text {
|
|
9
|
+
opacity: 0;
|
|
10
|
+
animation: show 800ms ease forwards;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.inner-arc {
|
|
14
|
+
animation: dash 2s ease forwards;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@keyframes dash {
|
|
18
|
+
100% {
|
|
19
|
+
stroke-dashoffset: 0%;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes show {
|
|
24
|
+
100% {
|
|
25
|
+
opacity: 1;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import * as d3 from 'd3';
|
|
2
|
-
|
|
3
|
-
//只支持在svg中使用
|
|
4
|
-
//在<clipPath>标签中绘制圆环路径,在<foreignObject>中使用conic-gradient来制作角向渐变
|
|
5
|
-
//然后在foreignObject中调用clipPath来剪切dom元素,实现环形渐变效果
|
|
6
|
-
export default function ConicGradient(props){
|
|
7
|
-
const {
|
|
8
|
-
gradientId, //渐变ID,每一个环形渐变都需要使用独有的id,防止大屏中存在多个环形渐变时,出现渐变混用的情况。
|
|
9
|
-
colorConfig={},
|
|
10
|
-
circleConfig={}
|
|
11
|
-
} = props,
|
|
12
|
-
{
|
|
13
|
-
colorType = "linear", //渐变类型
|
|
14
|
-
colors = [{offset:0,color:"rgba(255,0,0,0.5)"},
|
|
15
|
-
{offset:50,color:"rgba(0,255,0,0.5)"},
|
|
16
|
-
{offset:100,color:"rgba(0,0,255,0.5)"}] //渐变颜色
|
|
17
|
-
} = colorConfig,
|
|
18
|
-
{
|
|
19
|
-
innerRadius = 80, //圆环内半径
|
|
20
|
-
outerRadius = 100, //圆环外半径
|
|
21
|
-
startAngle = 0, //初始角度
|
|
22
|
-
endAngle = 360, //结束角度
|
|
23
|
-
cornerRadius = 0, //圆环两端的圆角
|
|
24
|
-
padAngle = 0 //圆环内边距,用于多个圆环之间的间距
|
|
25
|
-
} = circleConfig;
|
|
26
|
-
const arc = d3
|
|
27
|
-
.arc()
|
|
28
|
-
.innerRadius(innerRadius)
|
|
29
|
-
.outerRadius(outerRadius)
|
|
30
|
-
.startAngle((startAngle * Math.PI) / 180)
|
|
31
|
-
.endAngle((endAngle * Math.PI) / 180)
|
|
32
|
-
.cornerRadius(cornerRadius)
|
|
33
|
-
.padAngle(padAngle);
|
|
34
|
-
return <g>
|
|
35
|
-
<clipPath id={""+gradientId} style={{transform:`translate(50%,50%)`}}>
|
|
36
|
-
<path d={arc()}></path>
|
|
37
|
-
</clipPath>
|
|
38
|
-
<foreignObject style={{
|
|
39
|
-
width:"100%",
|
|
40
|
-
height:"100%",
|
|
41
|
-
transform:`translate(-50%,-50%)`,
|
|
42
|
-
background:colorType==="pure"?
|
|
43
|
-
colors : `conic-gradient(${colorsToString(colors)})`,
|
|
44
|
-
clipPath:`url(${'#'+gradientId})`
|
|
45
|
-
}}></foreignObject>
|
|
46
|
-
</g>
|
|
47
|
-
}
|
|
48
|
-
function colorsToString(colors){
|
|
49
|
-
let s="";
|
|
50
|
-
colors.sort((a,b)=>{
|
|
51
|
-
return a.offset-b.offset;
|
|
52
|
-
}).map(d=>{
|
|
53
|
-
s=s+d.color+" "+d.offset+"%,";
|
|
54
|
-
})
|
|
55
|
-
return s.slice(0,-1)
|
|
1
|
+
import * as d3 from 'd3';
|
|
2
|
+
|
|
3
|
+
//只支持在svg中使用
|
|
4
|
+
//在<clipPath>标签中绘制圆环路径,在<foreignObject>中使用conic-gradient来制作角向渐变
|
|
5
|
+
//然后在foreignObject中调用clipPath来剪切dom元素,实现环形渐变效果
|
|
6
|
+
export default function ConicGradient(props){
|
|
7
|
+
const {
|
|
8
|
+
gradientId, //渐变ID,每一个环形渐变都需要使用独有的id,防止大屏中存在多个环形渐变时,出现渐变混用的情况。
|
|
9
|
+
colorConfig={},
|
|
10
|
+
circleConfig={}
|
|
11
|
+
} = props,
|
|
12
|
+
{
|
|
13
|
+
colorType = "linear", //渐变类型
|
|
14
|
+
colors = [{offset:0,color:"rgba(255,0,0,0.5)"},
|
|
15
|
+
{offset:50,color:"rgba(0,255,0,0.5)"},
|
|
16
|
+
{offset:100,color:"rgba(0,0,255,0.5)"}] //渐变颜色
|
|
17
|
+
} = colorConfig,
|
|
18
|
+
{
|
|
19
|
+
innerRadius = 80, //圆环内半径
|
|
20
|
+
outerRadius = 100, //圆环外半径
|
|
21
|
+
startAngle = 0, //初始角度
|
|
22
|
+
endAngle = 360, //结束角度
|
|
23
|
+
cornerRadius = 0, //圆环两端的圆角
|
|
24
|
+
padAngle = 0 //圆环内边距,用于多个圆环之间的间距
|
|
25
|
+
} = circleConfig;
|
|
26
|
+
const arc = d3
|
|
27
|
+
.arc()
|
|
28
|
+
.innerRadius(innerRadius)
|
|
29
|
+
.outerRadius(outerRadius)
|
|
30
|
+
.startAngle((startAngle * Math.PI) / 180)
|
|
31
|
+
.endAngle((endAngle * Math.PI) / 180)
|
|
32
|
+
.cornerRadius(cornerRadius)
|
|
33
|
+
.padAngle(padAngle);
|
|
34
|
+
return <g>
|
|
35
|
+
<clipPath id={""+gradientId} style={{transform:`translate(50%,50%)`}}>
|
|
36
|
+
<path d={arc()}></path>
|
|
37
|
+
</clipPath>
|
|
38
|
+
<foreignObject style={{
|
|
39
|
+
width:"100%",
|
|
40
|
+
height:"100%",
|
|
41
|
+
transform:`translate(-50%,-50%)`,
|
|
42
|
+
background:colorType==="pure"?
|
|
43
|
+
colors : `conic-gradient(${colorsToString(colors)})`,
|
|
44
|
+
clipPath:`url(${'#'+gradientId})`
|
|
45
|
+
}}></foreignObject>
|
|
46
|
+
</g>
|
|
47
|
+
}
|
|
48
|
+
function colorsToString(colors){
|
|
49
|
+
let s="";
|
|
50
|
+
colors.sort((a,b)=>{
|
|
51
|
+
return a.offset-b.offset;
|
|
52
|
+
}).map(d=>{
|
|
53
|
+
s=s+d.color+" "+d.offset+"%,";
|
|
54
|
+
})
|
|
55
|
+
return s.slice(0,-1)
|
|
56
56
|
}
|