@easyv/charts 1.3.30 → 1.3.31

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.
@@ -67,7 +67,8 @@ var _default = function _default(Component) {
67
67
 
68
68
  var on = _animation.on,
69
69
  interval = _animation.interval,
70
- interactive = _animation.interactive;
70
+ interactive = _animation.interactive,
71
+ hoverStop = _animation.hoverStop;
71
72
 
72
73
  var _useState = (0, _react.useState)(on ? carouselState : initialState),
73
74
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
@@ -75,6 +76,7 @@ var _default = function _default(Component) {
75
76
  setState = _useState2[1];
76
77
 
77
78
  var timer = (0, _react.useRef)(null);
79
+ var hoverState = (0, _react.useRef)(false);
78
80
  var animationOn = on && interval && dataLength;
79
81
  var carousel = (0, _react.useCallback)(function () {
80
82
  if (animationOn) {
@@ -115,7 +117,7 @@ var _default = function _default(Component) {
115
117
  case 'click':
116
118
  if (type == 'onClick') {
117
119
  timer.current && timer.current.stop();
118
- animationOn && carousel();
120
+ !hoverState.current && animationOn && carousel();
119
121
  setState({
120
122
  trigger: type,
121
123
  currentIndex: currentIndex
@@ -132,7 +134,7 @@ var _default = function _default(Component) {
132
134
  });
133
135
  timer.current && timer.current.stop();
134
136
  } else if (type == 'onMouseLeave') {
135
- animationOn && carousel();
137
+ !hoverState.current && animationOn && carousel();
136
138
  }
137
139
 
138
140
  break;
@@ -150,21 +152,33 @@ var _default = function _default(Component) {
150
152
  break;
151
153
  }
152
154
  }, [interactive, animationOn, carousel]);
153
-
154
- if (!animationOn) {
155
- return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, rest, {
156
- state: state,
157
- onEvent: onEvent,
158
- config: _objectSpread(_objectSpread({}, config), {}, {
159
- animation: _animation
160
- }),
161
- data: data
162
- }));
163
- }
164
-
155
+ var hoverEvent = (0, _react.useCallback)(function (isHover) {
156
+ if (hoverStop) {
157
+ if (isHover) {
158
+ hoverState.current = true;
159
+ timer.current && timer.current.stop();
160
+ } else {
161
+ hoverState.current = false;
162
+
163
+ if (animationOn) {
164
+ timer.current = (0, _d3v.interval)(function () {
165
+ setState(function (_ref4) {
166
+ var currentIndex = _ref4.currentIndex;
167
+ var tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
168
+ return {
169
+ currentIndex: tmp >= dataLength ? 0 : tmp,
170
+ trigger: 'carousel'
171
+ };
172
+ });
173
+ }, interval * 1000);
174
+ }
175
+ }
176
+ }
177
+ }, [hoverStop, animationOn, carousel]);
165
178
  return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, rest, {
166
179
  state: state,
167
180
  onEvent: onEvent,
181
+ hoverEvent: hoverEvent,
168
182
  config: _objectSpread(_objectSpread({}, config), {}, {
169
183
  animation: _animation
170
184
  }),
@@ -323,6 +323,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
323
323
  currentIndex = _ref5$state.currentIndex,
324
324
  trigger = _ref5$state.trigger,
325
325
  onEvent = _ref5.onEvent,
326
+ hoverEvent = _ref5.hoverEvent,
326
327
  _ref5$data = _ref5.data,
327
328
  originData = _ref5$data === void 0 ? [] : _ref5$data;
328
329
  var data = originData.map(function (d) {
@@ -597,7 +598,13 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
597
598
  width: width,
598
599
  height: height,
599
600
  marginLeft: marginLeft,
600
- marginTop: marginTop
601
+ marginTop: marginTop,
602
+ onMouseEnter: function onMouseEnter() {
603
+ hoverEvent(true);
604
+ },
605
+ onMouseLeave: function onMouseLeave() {
606
+ hoverEvent(false);
607
+ }
601
608
  }, /*#__PURE__*/_react["default"].createElement("g", {
602
609
  style: {
603
610
  transition: 'transform ease-in-out 0.3s',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.3.30",
3
+ "version": "1.3.31",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -44,13 +44,12 @@ export default (Component: ComponentType<any>) =>
44
44
  }) => {
45
45
  const dataLength = data.length;
46
46
  const _animation = Object.assign({}, defaultAnimation, animation);
47
- const { on, interval, interactive } = _animation;
48
-
47
+ const { on, interval, interactive, hoverStop } = _animation;
49
48
  const [state, setState] = useState<State>(
50
49
  on ? carouselState : initialState
51
50
  );
52
51
  const timer: { current: Timer | null } = useRef(null);
53
-
52
+ const hoverState = useRef(false);
54
53
  const animationOn = on && interval && dataLength;
55
54
 
56
55
  const carousel = useCallback(() => {
@@ -83,15 +82,18 @@ export default (Component: ComponentType<any>) =>
83
82
  timer.current && timer.current.stop();
84
83
  };
85
84
  }, [carousel]);
86
-
85
+ interface Event{
86
+ currentIndex:number,
87
+ type:string
88
+ }
87
89
  const onEvent = useCallback(
88
- ({ currentIndex, type }) => {
90
+ ({ currentIndex, type }:Event) => {
89
91
  switch (interactive) {
90
92
  case true:
91
93
  case 'click':
92
94
  if (type == 'onClick') {
93
95
  timer.current && timer.current.stop();
94
- animationOn && carousel();
96
+ !hoverState.current && animationOn && carousel();
95
97
  setState({
96
98
  trigger: type,
97
99
  currentIndex,
@@ -101,12 +103,12 @@ export default (Component: ComponentType<any>) =>
101
103
  case 'hover':
102
104
  if (type == 'onMouseEnter') {
103
105
  setState({
104
- trigger: type,
106
+ trigger:type,
105
107
  currentIndex,
106
108
  });
107
109
  timer.current && timer.current.stop();
108
110
  } else if (type == 'onMouseLeave') {
109
- animationOn && carousel();
111
+ !hoverState.current && animationOn && carousel();
110
112
  }
111
113
  break;
112
114
  case false:
@@ -123,23 +125,35 @@ export default (Component: ComponentType<any>) =>
123
125
  },
124
126
  [interactive, animationOn, carousel]
125
127
  );
128
+
129
+ const hoverEvent = useCallback((isHover:boolean)=>{
130
+ if(hoverStop){
131
+ if(isHover){
132
+ hoverState.current = true;
133
+ timer.current && timer.current.stop();
134
+ }else{
135
+ hoverState.current = false;
136
+ if(animationOn){
137
+ timer.current = d3Interval(() => {
138
+ setState(({ currentIndex }) => {
139
+ const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
140
+ return {
141
+ currentIndex: tmp >= dataLength ? 0 : tmp,
142
+ trigger: 'carousel',
143
+ };
144
+ });
145
+ }, interval * 1000);
146
+ }
147
+ }
148
+ }
149
+ },[hoverStop, animationOn, carousel]);
126
150
 
127
- if (!animationOn) {
128
- return (
129
- <Component
130
- {...rest}
131
- state={state}
132
- onEvent={onEvent}
133
- config={{ ...config, animation: _animation }}
134
- data={data}
135
- />
136
- );
137
- }
138
151
  return (
139
152
  <Component
140
153
  {...rest}
141
154
  state={state}
142
155
  onEvent={onEvent}
156
+ hoverEvent={hoverEvent}
143
157
  config={{ ...config, animation: _animation }}
144
158
  data={data}
145
159
  />
@@ -41,23 +41,24 @@ export default memo(
41
41
  onMouseOut = event,
42
42
  }: Props,
43
43
  ref: LegacyRef<SVGSVGElement>
44
- ) => (
45
- <svg
46
- className='__easyv-svg'
47
- width={width}
48
- height={height}
49
- onMouseEnter={onMouseEnter}
50
- onMouseLeave={onMouseLeave}
51
- onMouseOut={onMouseOut}
52
- onClick={onClick}
53
- onMouseMove={onMouseMove}
54
- ref={ref}
55
- style={{ position: 'absolute', width, height, ...style }}
56
- >
57
- <g transform={'translate(' + marginLeft + ', ' + marginTop + ')'}>
58
- {children}
59
- </g>
60
- </svg>
61
- )
44
+ ) =>
45
+ {
46
+ return <svg
47
+ className='__easyv-svg'
48
+ width={width}
49
+ height={height}
50
+ onMouseEnter={onMouseEnter}
51
+ onMouseLeave={onMouseLeave}
52
+ onMouseOut={onMouseOut}
53
+ onClick={onClick}
54
+ onMouseMove={onMouseMove}
55
+ ref={ref}
56
+ style={{ position: 'absolute', width, height, ...style }}
57
+ >
58
+ <g transform={'translate(' + marginLeft + ', ' + marginTop + ')'}>
59
+ {children}
60
+ </g>
61
+ </svg>
62
+ }
62
63
  )
63
64
  );
@@ -269,9 +269,9 @@ const Component = memo(
269
269
  },
270
270
  state: { currentIndex, trigger },
271
271
  onEvent,
272
+ hoverEvent,
272
273
  data:originData = [],
273
274
  }) => {
274
-
275
275
  const data =originData.map(d=>({...d,y:d.y<0?0:d.y}));
276
276
  const prevIndex = useRef(null);
277
277
  const { precision: legendPrecision } = legend.config.percent;
@@ -553,6 +553,8 @@ const Component = memo(
553
553
  height={height}
554
554
  marginLeft={marginLeft}
555
555
  marginTop={marginTop}
556
+ onMouseEnter={()=>{hoverEvent(true)}}
557
+ onMouseLeave={()=>{hoverEvent(false)}}
556
558
  >
557
559
  <g
558
560
  style={{