@easyv/charts 1.3.28 → 1.3.29
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.
|
@@ -15,6 +15,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
15
15
|
|
|
16
16
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
17
|
|
|
18
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
19
|
+
|
|
18
20
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
21
|
|
|
20
22
|
var _hooks = require("../hooks");
|
|
@@ -69,6 +71,11 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
69
71
|
filterData = _ref.filterData;
|
|
70
72
|
var context = (0, _react.useContext)(_context.chartContext);
|
|
71
73
|
|
|
74
|
+
var _useState = (0, _react.useState)(false),
|
|
75
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
76
|
+
isHover = _useState2[0],
|
|
77
|
+
setIsHover = _useState2[1];
|
|
78
|
+
|
|
72
79
|
var _useContext = (0, _react.useContext)(_context.chartContext),
|
|
73
80
|
chartWidth = _useContext.width,
|
|
74
81
|
chartHeight = _useContext.height,
|
|
@@ -80,7 +87,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
80
87
|
axes: axesConfig,
|
|
81
88
|
context: context
|
|
82
89
|
});
|
|
83
|
-
var axisX = (0, _hooks.useCarouselAxisX)(axes.get('x'), animation);
|
|
90
|
+
var axisX = (0, _hooks.useCarouselAxisX)(axes.get('x'), animation, isHover);
|
|
84
91
|
|
|
85
92
|
var _useTooltip = (0, _hooks.useTooltip)({
|
|
86
93
|
svg: svg,
|
|
@@ -128,8 +135,14 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
128
135
|
height: height,
|
|
129
136
|
marginLeft: marginLeft,
|
|
130
137
|
marginTop: marginTop,
|
|
138
|
+
onMouseEnter: function onMouseEnter() {
|
|
139
|
+
setIsHover(true);
|
|
140
|
+
},
|
|
131
141
|
onMouseMove: setIndex,
|
|
132
|
-
onMouseLeave:
|
|
142
|
+
onMouseLeave: function onMouseLeave(e) {
|
|
143
|
+
setIsHover(false);
|
|
144
|
+
setIndex(e);
|
|
145
|
+
},
|
|
133
146
|
ref: svg
|
|
134
147
|
}, background && /*#__PURE__*/_react["default"].createElement(_.Background, {
|
|
135
148
|
length: isVertical ? chartWidth : chartHeight,
|
|
@@ -23,7 +23,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
23
23
|
|
|
24
24
|
var initialState = {
|
|
25
25
|
currentIndex: null,
|
|
26
|
-
flag: false
|
|
26
|
+
flag: false //表示是否为首次加载,true表示首次加载,不需要立刻执行动画,false表示可以执行轮播动画
|
|
27
|
+
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* x轴滚动逻辑
|
|
@@ -32,10 +33,11 @@ var initialState = {
|
|
|
32
33
|
* @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
|
|
33
34
|
*/
|
|
34
35
|
|
|
35
|
-
var _default = function _default(axis, config) {
|
|
36
|
+
var _default = function _default(axis, config, isHover) {
|
|
36
37
|
var show = config.show,
|
|
37
38
|
interval = config.interval,
|
|
38
|
-
duration = config.duration
|
|
39
|
+
duration = config.duration,
|
|
40
|
+
hover = config.hover;
|
|
39
41
|
var time = duration + interval;
|
|
40
42
|
var tickCount = axis.tickCount,
|
|
41
43
|
allTicks = axis.allTicks,
|
|
@@ -62,13 +64,19 @@ var _default = function _default(axis, config) {
|
|
|
62
64
|
setStatus = _useState4[1];
|
|
63
65
|
|
|
64
66
|
(0, _react.useEffect)(function () {
|
|
65
|
-
var handler;
|
|
66
|
-
|
|
67
67
|
if (show && time && tickLength > tickCount) {
|
|
68
68
|
setStatus({
|
|
69
69
|
currentIndex: 0,
|
|
70
70
|
flag: true
|
|
71
71
|
});
|
|
72
|
+
} else {
|
|
73
|
+
setStatus(initialState);
|
|
74
|
+
}
|
|
75
|
+
}, [show, time, tickCount, tickLength]);
|
|
76
|
+
(0, _react.useEffect)(function () {
|
|
77
|
+
var handler;
|
|
78
|
+
|
|
79
|
+
if (!(hover && isHover) && show && time && tickLength > tickCount) {
|
|
72
80
|
handler = setInterval(function () {
|
|
73
81
|
setStatus(function (_ref) {
|
|
74
82
|
var currentIndex = _ref.currentIndex;
|
|
@@ -79,14 +87,12 @@ var _default = function _default(axis, config) {
|
|
|
79
87
|
};
|
|
80
88
|
});
|
|
81
89
|
}, time * 1000);
|
|
82
|
-
} else {
|
|
83
|
-
setStatus(initialState);
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
return function () {
|
|
87
93
|
handler && clearInterval(handler);
|
|
88
94
|
};
|
|
89
|
-
}, [show, time, tickCount, tickLength]);
|
|
95
|
+
}, [show, time, tickCount, tickLength, hover, isHover]);
|
|
90
96
|
(0, _react.useEffect)(function () {
|
|
91
97
|
var animation;
|
|
92
98
|
var currentIndex = status.currentIndex,
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import React, {
|
|
5
5
|
memo,
|
|
6
6
|
useMemo,
|
|
7
|
+
useState,
|
|
7
8
|
createRef,
|
|
8
9
|
useContext,
|
|
9
10
|
useCallback,
|
|
@@ -60,6 +61,7 @@ const Chart = memo(
|
|
|
60
61
|
filterData,
|
|
61
62
|
}) => {
|
|
62
63
|
const context = useContext(chartContext);
|
|
64
|
+
const [isHover, setIsHover] = useState(false);
|
|
63
65
|
const {
|
|
64
66
|
width: chartWidth,
|
|
65
67
|
height: chartHeight,
|
|
@@ -68,7 +70,7 @@ const Chart = memo(
|
|
|
68
70
|
} = useContext(chartContext);
|
|
69
71
|
const svg = createRef();
|
|
70
72
|
const axes = useAxes({ axes: axesConfig, context });
|
|
71
|
-
const axisX = useCarouselAxisX(axes.get('x'), animation);
|
|
73
|
+
const axisX = useCarouselAxisX(axes.get('x'), animation, isHover);
|
|
72
74
|
|
|
73
75
|
const {
|
|
74
76
|
x: tooltipX,
|
|
@@ -125,8 +127,9 @@ const Chart = memo(
|
|
|
125
127
|
height={height}
|
|
126
128
|
marginLeft={marginLeft}
|
|
127
129
|
marginTop={marginTop}
|
|
130
|
+
onMouseEnter={()=>{setIsHover(true)}}
|
|
128
131
|
onMouseMove={setIndex}
|
|
129
|
-
onMouseLeave={setIndex}
|
|
132
|
+
onMouseLeave={(e)=>{setIsHover(false);setIndex(e)}}
|
|
130
133
|
ref={svg}
|
|
131
134
|
>
|
|
132
135
|
{background && (
|
|
@@ -3,7 +3,7 @@ import { animate, linear } from 'popmotion';
|
|
|
3
3
|
|
|
4
4
|
const initialState = {
|
|
5
5
|
currentIndex: null,
|
|
6
|
-
flag: false,
|
|
6
|
+
flag: false, //表示是否为首次加载,true表示首次加载,不需要立刻执行动画,false表示可以执行轮播动画
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -13,8 +13,8 @@ const initialState = {
|
|
|
13
13
|
* @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
export default (axis, config) => {
|
|
17
|
-
const { show, interval, duration } = config;
|
|
16
|
+
export default (axis, config, isHover) => {
|
|
17
|
+
const { show, interval, duration, hover } = config;
|
|
18
18
|
const time = duration + interval;
|
|
19
19
|
|
|
20
20
|
const {
|
|
@@ -37,12 +37,18 @@ export default (axis, config) => {
|
|
|
37
37
|
const [status, setStatus] = useState(initialState);
|
|
38
38
|
|
|
39
39
|
useEffect(() => {
|
|
40
|
-
let handler;
|
|
41
40
|
if (show && time && tickLength > tickCount) {
|
|
42
41
|
setStatus({
|
|
43
42
|
currentIndex: 0,
|
|
44
43
|
flag: true,
|
|
45
44
|
});
|
|
45
|
+
} else {
|
|
46
|
+
setStatus(initialState);
|
|
47
|
+
}
|
|
48
|
+
}, [show, time, tickCount, tickLength]);
|
|
49
|
+
useEffect(()=>{
|
|
50
|
+
let handler;
|
|
51
|
+
if(!(hover && isHover) && show && time && tickLength > tickCount){
|
|
46
52
|
handler = setInterval(() => {
|
|
47
53
|
setStatus(({ currentIndex }) => {
|
|
48
54
|
const tmp = +currentIndex + 1;
|
|
@@ -52,13 +58,11 @@ export default (axis, config) => {
|
|
|
52
58
|
};
|
|
53
59
|
});
|
|
54
60
|
}, time * 1000);
|
|
55
|
-
} else {
|
|
56
|
-
setStatus(initialState);
|
|
57
61
|
}
|
|
58
62
|
return () => {
|
|
59
63
|
handler && clearInterval(handler);
|
|
60
64
|
};
|
|
61
|
-
},
|
|
65
|
+
},[show, time, tickCount, tickLength, hover, isHover])
|
|
62
66
|
|
|
63
67
|
useEffect(() => {
|
|
64
68
|
let animation;
|