@easyv/charts 1.8.13 → 1.8.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.
- package/lib/components/Band.js +356 -356
- package/lib/components/Label.js +356 -356
- package/lib/components/Legend.js +312 -312
- package/lib/components/PieChart.js +12 -4
- package/lib/components/pieTooltip.js +202 -202
- package/lib/utils/index.js +822 -822
- package/package.json +1 -1
- package/src/components/Carousel.tsx +72 -55
- package/src/components/PieChart.js +6 -3
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@ import React, {
|
|
|
5
5
|
useState,
|
|
6
6
|
useCallback,
|
|
7
7
|
useRef,
|
|
8
|
-
} from
|
|
9
|
-
import { interval as d3Interval, Timer } from
|
|
8
|
+
} from "react";
|
|
9
|
+
import { interval as d3Interval, Timer } from "d3v7";
|
|
10
10
|
type State = {
|
|
11
11
|
currentIndex: number | null;
|
|
12
12
|
trigger: string;
|
|
@@ -14,18 +14,18 @@ type State = {
|
|
|
14
14
|
|
|
15
15
|
const initialState = {
|
|
16
16
|
currentIndex: null,
|
|
17
|
-
trigger:
|
|
17
|
+
trigger: "",
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const carouselState = {
|
|
21
21
|
currentIndex: 0,
|
|
22
|
-
trigger:
|
|
22
|
+
trigger: "carousel",
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const defaultAnimation = {
|
|
26
26
|
on: false,
|
|
27
27
|
interval: 0,
|
|
28
|
-
interactive:
|
|
28
|
+
interactive: "",
|
|
29
29
|
canCancel: false,
|
|
30
30
|
current: { heighten: 0, opacity: 100 },
|
|
31
31
|
};
|
|
@@ -53,19 +53,28 @@ export default (Component: ComponentType<any>) =>
|
|
|
53
53
|
const timer: { current: Timer | null } = useRef(null);
|
|
54
54
|
const hoverState = useRef(false);
|
|
55
55
|
const animationOn = on && interval && dataLength;
|
|
56
|
+
// 封装计时器停止逻辑
|
|
57
|
+
const stopTimer = useCallback(() => {
|
|
58
|
+
if (timer.current) {
|
|
59
|
+
timer.current.stop();
|
|
60
|
+
timer.current = null;
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
56
63
|
|
|
57
64
|
const carousel = useCallback(() => {
|
|
65
|
+
// 先停止之前的计时器
|
|
66
|
+
stopTimer();
|
|
58
67
|
if (animationOn) {
|
|
59
68
|
setState({
|
|
60
69
|
currentIndex: 0,
|
|
61
|
-
trigger:
|
|
62
|
-
})
|
|
70
|
+
trigger: "carousel",
|
|
71
|
+
});
|
|
63
72
|
timer.current = d3Interval(() => {
|
|
64
73
|
setState(({ currentIndex }) => {
|
|
65
74
|
const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
|
|
66
75
|
return {
|
|
67
76
|
currentIndex: tmp >= dataLength ? 0 : tmp,
|
|
68
|
-
trigger:
|
|
77
|
+
trigger: "carousel",
|
|
69
78
|
};
|
|
70
79
|
});
|
|
71
80
|
}, interval * 1000);
|
|
@@ -73,7 +82,7 @@ export default (Component: ComponentType<any>) =>
|
|
|
73
82
|
timer.current = null;
|
|
74
83
|
setState({
|
|
75
84
|
currentIndex: null,
|
|
76
|
-
trigger:
|
|
85
|
+
trigger: "",
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
}, [animationOn, interval, dataLength]);
|
|
@@ -81,50 +90,54 @@ export default (Component: ComponentType<any>) =>
|
|
|
81
90
|
useEffect(() => {
|
|
82
91
|
active && carousel && carousel();
|
|
83
92
|
return () => {
|
|
84
|
-
|
|
93
|
+
stopTimer();
|
|
85
94
|
};
|
|
86
|
-
}, [carousel, active]);
|
|
87
|
-
interface Event{
|
|
88
|
-
currentIndex:number
|
|
89
|
-
type:string
|
|
95
|
+
}, [carousel, active, stopTimer]);
|
|
96
|
+
interface Event {
|
|
97
|
+
currentIndex: number;
|
|
98
|
+
type: string;
|
|
90
99
|
}
|
|
91
100
|
const onEvent = useCallback(
|
|
92
|
-
({ currentIndex, type }:Event) => {
|
|
101
|
+
({ currentIndex, type }: Event) => {
|
|
93
102
|
switch (interactive) {
|
|
94
103
|
case true:
|
|
95
|
-
case
|
|
96
|
-
if (type ==
|
|
97
|
-
|
|
104
|
+
case "click":
|
|
105
|
+
if (type == "onClick") {
|
|
106
|
+
stopTimer();
|
|
98
107
|
!hoverState.current && animationOn && carousel();
|
|
99
|
-
setState(pre => {
|
|
108
|
+
setState((pre) => {
|
|
100
109
|
return {
|
|
101
110
|
trigger: type,
|
|
102
|
-
currentIndex:
|
|
103
|
-
|
|
111
|
+
currentIndex:
|
|
112
|
+
pre.currentIndex == currentIndex && canCancel
|
|
113
|
+
? -1
|
|
114
|
+
: currentIndex,
|
|
115
|
+
};
|
|
104
116
|
});
|
|
105
117
|
}
|
|
106
118
|
break;
|
|
107
|
-
case
|
|
108
|
-
if (type ==
|
|
119
|
+
case "hover":
|
|
120
|
+
if (type == "onMouseEnter") {
|
|
109
121
|
setState({
|
|
110
|
-
trigger:type,
|
|
122
|
+
trigger: type,
|
|
111
123
|
currentIndex,
|
|
112
124
|
});
|
|
113
|
-
|
|
114
|
-
} else if (type ==
|
|
125
|
+
stopTimer();
|
|
126
|
+
} else if (type == "onMouseLeave") {
|
|
115
127
|
!hoverState.current && animationOn && carousel();
|
|
116
|
-
canCancel &&
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
128
|
+
canCancel &&
|
|
129
|
+
setState((pre) => {
|
|
130
|
+
return {
|
|
131
|
+
trigger: "onMouseEnter",
|
|
132
|
+
currentIndex: -1,
|
|
133
|
+
};
|
|
134
|
+
});
|
|
122
135
|
}
|
|
123
136
|
break;
|
|
124
137
|
case false:
|
|
125
|
-
case
|
|
138
|
+
case "":
|
|
126
139
|
break;
|
|
127
|
-
case
|
|
140
|
+
case "carousel":
|
|
128
141
|
default:
|
|
129
142
|
setState({
|
|
130
143
|
trigger: type,
|
|
@@ -133,30 +146,34 @@ export default (Component: ComponentType<any>) =>
|
|
|
133
146
|
break;
|
|
134
147
|
}
|
|
135
148
|
},
|
|
136
|
-
[interactive, canCancel, animationOn, carousel]
|
|
149
|
+
[interactive, canCancel, animationOn, carousel, stopTimer]
|
|
137
150
|
);
|
|
138
|
-
|
|
139
|
-
const hoverEvent = useCallback(
|
|
140
|
-
|
|
141
|
-
if(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
|
|
152
|
+
const hoverEvent = useCallback(
|
|
153
|
+
(isHover: boolean) => {
|
|
154
|
+
if (hoverStop) {
|
|
155
|
+
if (isHover) {
|
|
156
|
+
hoverState.current = true;
|
|
157
|
+
stopTimer();
|
|
158
|
+
} else {
|
|
159
|
+
hoverState.current = false;
|
|
160
|
+
if (animationOn) {
|
|
161
|
+
stopTimer();
|
|
162
|
+
timer.current = d3Interval(() => {
|
|
163
|
+
setState(({ currentIndex }) => {
|
|
164
|
+
const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
|
|
165
|
+
return {
|
|
166
|
+
currentIndex: tmp >= dataLength ? 0 : tmp,
|
|
167
|
+
trigger: "carousel",
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}, interval * 1000);
|
|
171
|
+
}
|
|
156
172
|
}
|
|
157
173
|
}
|
|
158
|
-
}
|
|
159
|
-
|
|
174
|
+
},
|
|
175
|
+
[hoverStop, animationOn, interval, dataLength, stopTimer]
|
|
176
|
+
);
|
|
160
177
|
|
|
161
178
|
return (
|
|
162
179
|
<Component
|
|
@@ -1097,6 +1097,7 @@ const Label = ({
|
|
|
1097
1097
|
value: {
|
|
1098
1098
|
show: showValue,
|
|
1099
1099
|
font: valueFont,
|
|
1100
|
+
sameColor:valueSameColor,
|
|
1100
1101
|
suffix: {
|
|
1101
1102
|
show: showSuffix,
|
|
1102
1103
|
text,
|
|
@@ -1104,7 +1105,7 @@ const Label = ({
|
|
|
1104
1105
|
translate: { x: suffixTranslateX, y: suffixTranslateY },
|
|
1105
1106
|
},
|
|
1106
1107
|
},
|
|
1107
|
-
percent: { show: showPercent, font: percentFont, precision },
|
|
1108
|
+
percent: { show: showPercent,sameColor:percentSameColor, font: percentFont, precision },
|
|
1108
1109
|
},
|
|
1109
1110
|
iosStyle: { isIOS, left, top },
|
|
1110
1111
|
arcs,
|
|
@@ -1238,7 +1239,7 @@ const Label = ({
|
|
|
1238
1239
|
></TextOverflow>
|
|
1239
1240
|
)}
|
|
1240
1241
|
{showValue && (
|
|
1241
|
-
<span style={getFontStyle(valueFont)}>
|
|
1242
|
+
<span style={{...getFontStyle(valueFont),"color":valueSameColor?pure:valueFont.color}}>
|
|
1242
1243
|
{data.y}
|
|
1243
1244
|
{showSuffix && (
|
|
1244
1245
|
<span
|
|
@@ -1255,7 +1256,7 @@ const Label = ({
|
|
|
1255
1256
|
</span>
|
|
1256
1257
|
)}
|
|
1257
1258
|
{showPercent && (
|
|
1258
|
-
<span style={getFontStyle(percentFont)}>
|
|
1259
|
+
<span style={{...getFontStyle(percentFont),"color":percentSameColor?pure:percentFont.color}}>
|
|
1259
1260
|
{(_showValue ? "(" : "") +
|
|
1260
1261
|
percent +
|
|
1261
1262
|
"%" +
|
|
@@ -1460,6 +1461,7 @@ const RingLabel = ({
|
|
|
1460
1461
|
style={{
|
|
1461
1462
|
...getFontStyle(valueFont),
|
|
1462
1463
|
transform: getTranslate(valueTranslate, x3 >= 0),
|
|
1464
|
+
"color":valueSameColor?pure:valueFont.color
|
|
1463
1465
|
}}
|
|
1464
1466
|
>
|
|
1465
1467
|
{realData.y}
|
|
@@ -1482,6 +1484,7 @@ const RingLabel = ({
|
|
|
1482
1484
|
style={{
|
|
1483
1485
|
...getFontStyle(percentFont),
|
|
1484
1486
|
transform: getTranslate(percentTranslate, x3 >= 0),
|
|
1487
|
+
"color":percentSameColor?pure:percentFont.color
|
|
1485
1488
|
}}
|
|
1486
1489
|
>
|
|
1487
1490
|
{(_showValue ? "(" : "") +
|