@easyv/charts 1.3.29 → 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.
- package/lib/components/Carousel.js +29 -15
- package/lib/components/PieChart.js +8 -1
- package/lib/hooks/useAxes.js +2 -4
- package/package.json +1 -1
- package/src/components/Carousel.tsx +33 -19
- package/src/components/ChartContainer.tsx +19 -18
- package/src/components/PieChart.js +3 -1
- package/src/hooks/useAxes.js +2 -6
|
@@ -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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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/lib/hooks/useAxes.js
CHANGED
|
@@ -128,13 +128,11 @@ var _default = function _default(_ref) {
|
|
|
128
128
|
if (auto === false) {
|
|
129
129
|
switch (mode) {
|
|
130
130
|
case 'count':
|
|
131
|
-
_ticks = (0, _utils2.getYTicks)(domain[1], domain[0],
|
|
132
|
-
// hasNullDomain?_ticks[0]:domain[0],
|
|
133
|
-
+tickCount);
|
|
131
|
+
_ticks = (0, _utils2.getYTicks)(domain[1], domain[0], +tickCount);
|
|
134
132
|
break;
|
|
135
133
|
|
|
136
134
|
case 'step':
|
|
137
|
-
_ticks = (0, _utils2.getYTicksByStep)(newDomain[1],
|
|
135
|
+
_ticks = (0, _utils2.getYTicksByStep)(newDomain[1], newDomain[0], +step);
|
|
138
136
|
break;
|
|
139
137
|
}
|
|
140
138
|
}
|
package/package.json
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
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={{
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -100,9 +100,9 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
100
100
|
if(mode == "count" && type !== 'ordinal' && !isNaN(domain[1])){
|
|
101
101
|
newDomain = getNewDomain(domain, mode, step);
|
|
102
102
|
}
|
|
103
|
+
|
|
103
104
|
const scaler = scales[type]().domain(newDomain).range(range);
|
|
104
105
|
scaler.type = type;
|
|
105
|
-
|
|
106
106
|
if (type !== 'ordinal') scaler.nice().clamp(true);
|
|
107
107
|
const allTicks = ticks
|
|
108
108
|
? ticks
|
|
@@ -121,24 +121,20 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
121
121
|
_ticks = getYTicks(
|
|
122
122
|
domain[1],
|
|
123
123
|
domain[0],
|
|
124
|
-
// hasNullDomain?_ticks[_ticks.length - 1]:domain[1],
|
|
125
|
-
// hasNullDomain?_ticks[0]:domain[0],
|
|
126
124
|
+tickCount
|
|
127
125
|
);
|
|
128
126
|
break;
|
|
129
127
|
case 'step':
|
|
130
128
|
_ticks = getYTicksByStep(
|
|
131
129
|
newDomain[1],
|
|
132
|
-
|
|
130
|
+
newDomain[0],
|
|
133
131
|
+step
|
|
134
132
|
);
|
|
135
133
|
break;
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
|
-
|
|
140
137
|
const lengthWithoutPaddingOuter = length - _paddingOuter;
|
|
141
|
-
|
|
142
138
|
if (type == 'linear' && config.on) {
|
|
143
139
|
const zeroPosition = scaler(0);
|
|
144
140
|
if (zeroPosition !== range[0] && !isNaN(zeroPosition)) {
|