@easyv/charts 1.8.14 → 1.8.16

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.
@@ -20,16 +20,16 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
20
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
21
  var initialState = {
22
22
  currentIndex: null,
23
- trigger: ''
23
+ trigger: ""
24
24
  };
25
25
  var carouselState = {
26
26
  currentIndex: 0,
27
- trigger: 'carousel'
27
+ trigger: "carousel"
28
28
  };
29
29
  var defaultAnimation = {
30
30
  on: false,
31
31
  interval: 0,
32
- interactive: '',
32
+ interactive: "",
33
33
  canCancel: false,
34
34
  current: {
35
35
  heighten: 0,
@@ -62,11 +62,20 @@ var _default = exports["default"] = function _default(Component) {
62
62
  var timer = (0, _react.useRef)(null);
63
63
  var hoverState = (0, _react.useRef)(false);
64
64
  var animationOn = on && interval && dataLength;
65
+ // 封装计时器停止逻辑
66
+ var stopTimer = (0, _react.useCallback)(function () {
67
+ if (timer.current) {
68
+ timer.current.stop();
69
+ timer.current = null;
70
+ }
71
+ }, []);
65
72
  var carousel = (0, _react.useCallback)(function () {
73
+ // 先停止之前的计时器
74
+ stopTimer();
66
75
  if (animationOn) {
67
76
  setState({
68
77
  currentIndex: 0,
69
- trigger: 'carousel'
78
+ trigger: "carousel"
70
79
  });
71
80
  timer.current = (0, _d3v.interval)(function () {
72
81
  setState(function (_ref2) {
@@ -74,7 +83,7 @@ var _default = exports["default"] = function _default(Component) {
74
83
  var tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
75
84
  return {
76
85
  currentIndex: tmp >= dataLength ? 0 : tmp,
77
- trigger: 'carousel'
86
+ trigger: "carousel"
78
87
  };
79
88
  });
80
89
  }, interval * 1000);
@@ -82,24 +91,24 @@ var _default = exports["default"] = function _default(Component) {
82
91
  timer.current = null;
83
92
  setState({
84
93
  currentIndex: null,
85
- trigger: ''
94
+ trigger: ""
86
95
  });
87
96
  }
88
97
  }, [animationOn, interval, dataLength]);
89
98
  (0, _react.useEffect)(function () {
90
99
  active && carousel && carousel();
91
100
  return function () {
92
- timer.current && timer.current.stop();
101
+ stopTimer();
93
102
  };
94
- }, [carousel, active]);
103
+ }, [carousel, active, stopTimer]);
95
104
  var onEvent = (0, _react.useCallback)(function (_ref3) {
96
105
  var currentIndex = _ref3.currentIndex,
97
106
  type = _ref3.type;
98
107
  switch (interactive) {
99
108
  case true:
100
- case 'click':
101
- if (type == 'onClick') {
102
- timer.current && timer.current.stop();
109
+ case "click":
110
+ if (type == "onClick") {
111
+ stopTimer();
103
112
  !hoverState.current && animationOn && carousel();
104
113
  setState(function (pre) {
105
114
  return {
@@ -109,14 +118,14 @@ var _default = exports["default"] = function _default(Component) {
109
118
  });
110
119
  }
111
120
  break;
112
- case 'hover':
113
- if (type == 'onMouseEnter') {
121
+ case "hover":
122
+ if (type == "onMouseEnter") {
114
123
  setState({
115
124
  trigger: type,
116
125
  currentIndex: currentIndex
117
126
  });
118
- timer.current && timer.current.stop();
119
- } else if (type == 'onMouseLeave') {
127
+ stopTimer();
128
+ } else if (type == "onMouseLeave") {
120
129
  !hoverState.current && animationOn && carousel();
121
130
  canCancel && setState(function (pre) {
122
131
  return {
@@ -127,9 +136,9 @@ var _default = exports["default"] = function _default(Component) {
127
136
  }
128
137
  break;
129
138
  case false:
130
- case '':
139
+ case "":
131
140
  break;
132
- case 'carousel':
141
+ case "carousel":
133
142
  default:
134
143
  setState({
135
144
  trigger: type,
@@ -137,29 +146,30 @@ var _default = exports["default"] = function _default(Component) {
137
146
  });
138
147
  break;
139
148
  }
140
- }, [interactive, canCancel, animationOn, carousel]);
149
+ }, [interactive, canCancel, animationOn, carousel, stopTimer]);
141
150
  var hoverEvent = (0, _react.useCallback)(function (isHover) {
142
151
  if (hoverStop) {
143
152
  if (isHover) {
144
153
  hoverState.current = true;
145
- timer.current && timer.current.stop();
154
+ stopTimer();
146
155
  } else {
147
156
  hoverState.current = false;
148
157
  if (animationOn) {
158
+ stopTimer();
149
159
  timer.current = (0, _d3v.interval)(function () {
150
160
  setState(function (_ref4) {
151
161
  var currentIndex = _ref4.currentIndex;
152
162
  var tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
153
163
  return {
154
164
  currentIndex: tmp >= dataLength ? 0 : tmp,
155
- trigger: 'carousel'
165
+ trigger: "carousel"
156
166
  };
157
167
  });
158
168
  }, interval * 1000);
159
169
  }
160
170
  }
161
171
  }
162
- }, [hoverStop, animationOn, carousel]);
172
+ }, [hoverStop, animationOn, interval, dataLength, stopTimer]);
163
173
  return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, rest, {
164
174
  state: state,
165
175
  onEvent: onEvent,
@@ -607,7 +607,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
607
607
  }))), tooltip && mousePos && mousePos.x != 0 && mousePos.y != 0 && tooltip.manual && /*#__PURE__*/_react["default"].createElement("div", {
608
608
  style: {
609
609
  position: "absolute",
610
- zIndex: 9999
610
+ zIndex: 9999,
611
+ pointerEvents: "none"
611
612
  }
612
613
  }, /*#__PURE__*/_react["default"].createElement(_PieTooltip.PieTooltip, {
613
614
  series: series,
@@ -774,7 +775,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
774
775
  }), tooltip && mousePos && mousePos.x != 0 && mousePos.y != 0 && tooltip.manual && /*#__PURE__*/_react["default"].createElement("div", {
775
776
  style: {
776
777
  position: "absolute",
777
- zIndex: 9999
778
+ zIndex: 9999,
779
+ pointerEvents: "none"
778
780
  }
779
781
  }, /*#__PURE__*/_react["default"].createElement(_PieTooltip.PieTooltip, {
780
782
  series: series,
@@ -1051,7 +1053,7 @@ var Label = function Label(_ref10) {
1051
1053
  })
1052
1054
  }), showValue && /*#__PURE__*/_react["default"].createElement("span", {
1053
1055
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
1054
- "color": valueSameColor ? pure : valueFont.color
1056
+ color: valueSameColor ? pure : valueFont.color
1055
1057
  })
1056
1058
  }, data.y, showSuffix && /*#__PURE__*/_react["default"].createElement("span", {
1057
1059
  style: {
@@ -1062,7 +1064,7 @@ var Label = function Label(_ref10) {
1062
1064
  }
1063
1065
  }, text)), showPercent && /*#__PURE__*/_react["default"].createElement("span", {
1064
1066
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(percentFont)), {}, {
1065
- "color": percentSameColor ? pure : percentFont.color
1067
+ color: percentSameColor ? pure : percentFont.color
1066
1068
  })
1067
1069
  }, (_showValue ? "(" : "") + percent + "%" + (_showValue ? ")" : "")))));
1068
1070
  }));
@@ -1210,7 +1212,7 @@ var RingLabel = function RingLabel(_ref12) {
1210
1212
  }), showValue && /*#__PURE__*/_react["default"].createElement("span", {
1211
1213
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
1212
1214
  transform: getTranslate(valueTranslate, x3 >= 0),
1213
- "color": valueSameColor ? pure : valueFont.color
1215
+ color: valueSameColor ? pure : valueFont.color
1214
1216
  })
1215
1217
  }, realData.y, showSuffix && /*#__PURE__*/_react["default"].createElement("span", {
1216
1218
  style: {
@@ -1222,7 +1224,7 @@ var RingLabel = function RingLabel(_ref12) {
1222
1224
  }, text)), showPercent && /*#__PURE__*/_react["default"].createElement("span", {
1223
1225
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(percentFont)), {}, {
1224
1226
  transform: getTranslate(percentTranslate, x3 >= 0),
1225
- "color": percentSameColor ? pure : percentFont.color
1227
+ color: percentSameColor ? pure : percentFont.color
1226
1228
  })
1227
1229
  }, (_showValue ? "(" : "") + percent + "%" + (_showValue ? ")" : "")))));
1228
1230
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.14",
3
+ "version": "1.8.16",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -5,8 +5,8 @@ import React, {
5
5
  useState,
6
6
  useCallback,
7
7
  useRef,
8
- } from 'react';
9
- import { interval as d3Interval, Timer } from 'd3v7';
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: 'carousel',
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: 'carousel'
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: 'carousel',
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
- timer.current && timer.current.stop();
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 'click':
96
- if (type == 'onClick') {
97
- timer.current && timer.current.stop();
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:pre.currentIndex==currentIndex && canCancel?-1:currentIndex,
103
- }
111
+ currentIndex:
112
+ pre.currentIndex == currentIndex && canCancel
113
+ ? -1
114
+ : currentIndex,
115
+ };
104
116
  });
105
117
  }
106
118
  break;
107
- case 'hover':
108
- if (type == 'onMouseEnter') {
119
+ case "hover":
120
+ if (type == "onMouseEnter") {
109
121
  setState({
110
- trigger:type,
122
+ trigger: type,
111
123
  currentIndex,
112
124
  });
113
- timer.current && timer.current.stop();
114
- } else if (type == 'onMouseLeave') {
125
+ stopTimer();
126
+ } else if (type == "onMouseLeave") {
115
127
  !hoverState.current && animationOn && carousel();
116
- canCancel && setState(pre => {
117
- return {
118
- trigger: "onMouseEnter",
119
- currentIndex:-1,
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 'carousel':
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((isHover:boolean)=>{
140
- if(hoverStop){
141
- if(isHover){
142
- hoverState.current = true;
143
- timer.current && timer.current.stop();
144
- }else{
145
- hoverState.current = false;
146
- if(animationOn){
147
- timer.current = d3Interval(() => {
148
- setState(({ currentIndex }) => {
149
- const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
150
- return {
151
- currentIndex: tmp >= dataLength ? 0 : tmp,
152
- trigger: 'carousel',
153
- };
154
- });
155
- }, interval * 1000);
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
- },[hoverStop, animationOn, carousel]);
174
+ },
175
+ [hoverStop, animationOn, interval, dataLength, stopTimer]
176
+ );
160
177
 
161
178
  return (
162
179
  <Component
@@ -512,7 +512,7 @@ const Component = memo(
512
512
  const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
513
513
  const [hoverData, setHoverData] = useState(null);
514
514
  const pieWarpEl = useRef(null);
515
- const domRef=useRef()
515
+ const domRef = useRef();
516
516
  return outerDecorate ? (
517
517
  <div ref={domRef}>
518
518
  <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
@@ -626,7 +626,13 @@ const Component = memo(
626
626
  mousePos.x != 0 &&
627
627
  mousePos.y != 0 &&
628
628
  tooltip.manual && (
629
- <div style={{ position: "absolute", zIndex: 9999 }}>
629
+ <div
630
+ style={{
631
+ position: "absolute",
632
+ zIndex: 9999,
633
+ pointerEvents: "none",
634
+ }}
635
+ >
630
636
  <PieTooltip
631
637
  series={series}
632
638
  domRef={domRef}
@@ -888,7 +894,13 @@ const Component = memo(
888
894
  mousePos.x != 0 &&
889
895
  mousePos.y != 0 &&
890
896
  tooltip.manual && (
891
- <div style={{ position: "absolute", zIndex: 9999 }}>
897
+ <div
898
+ style={{
899
+ position: "absolute",
900
+ zIndex: 9999,
901
+ pointerEvents: "none",
902
+ }}
903
+ >
892
904
  <PieTooltip
893
905
  series={series}
894
906
  domRef={domRef}
@@ -1097,7 +1109,7 @@ const Label = ({
1097
1109
  value: {
1098
1110
  show: showValue,
1099
1111
  font: valueFont,
1100
- sameColor:valueSameColor,
1112
+ sameColor: valueSameColor,
1101
1113
  suffix: {
1102
1114
  show: showSuffix,
1103
1115
  text,
@@ -1105,7 +1117,12 @@ const Label = ({
1105
1117
  translate: { x: suffixTranslateX, y: suffixTranslateY },
1106
1118
  },
1107
1119
  },
1108
- percent: { show: showPercent,sameColor:percentSameColor, font: percentFont, precision },
1120
+ percent: {
1121
+ show: showPercent,
1122
+ sameColor: percentSameColor,
1123
+ font: percentFont,
1124
+ precision,
1125
+ },
1109
1126
  },
1110
1127
  iosStyle: { isIOS, left, top },
1111
1128
  arcs,
@@ -1239,7 +1256,12 @@ const Label = ({
1239
1256
  ></TextOverflow>
1240
1257
  )}
1241
1258
  {showValue && (
1242
- <span style={{...getFontStyle(valueFont),"color":valueSameColor?pure:valueFont.color}}>
1259
+ <span
1260
+ style={{
1261
+ ...getFontStyle(valueFont),
1262
+ color: valueSameColor ? pure : valueFont.color,
1263
+ }}
1264
+ >
1243
1265
  {data.y}
1244
1266
  {showSuffix && (
1245
1267
  <span
@@ -1256,7 +1278,12 @@ const Label = ({
1256
1278
  </span>
1257
1279
  )}
1258
1280
  {showPercent && (
1259
- <span style={{...getFontStyle(percentFont),"color":percentSameColor?pure:percentFont.color}}>
1281
+ <span
1282
+ style={{
1283
+ ...getFontStyle(percentFont),
1284
+ color: percentSameColor ? pure : percentFont.color,
1285
+ }}
1286
+ >
1260
1287
  {(_showValue ? "(" : "") +
1261
1288
  percent +
1262
1289
  "%" +
@@ -1461,7 +1488,7 @@ const RingLabel = ({
1461
1488
  style={{
1462
1489
  ...getFontStyle(valueFont),
1463
1490
  transform: getTranslate(valueTranslate, x3 >= 0),
1464
- "color":valueSameColor?pure:valueFont.color
1491
+ color: valueSameColor ? pure : valueFont.color,
1465
1492
  }}
1466
1493
  >
1467
1494
  {realData.y}
@@ -1484,7 +1511,7 @@ const RingLabel = ({
1484
1511
  style={{
1485
1512
  ...getFontStyle(percentFont),
1486
1513
  transform: getTranslate(percentTranslate, x3 >= 0),
1487
- "color":percentSameColor?pure:percentFont.color
1514
+ color: percentSameColor ? pure : percentFont.color,
1488
1515
  }}
1489
1516
  >
1490
1517
  {(_showValue ? "(" : "") +