@easyv/charts 1.5.21 → 1.5.23

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.
@@ -103,6 +103,45 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
103
103
 
104
104
  document.addEventListener("mousemove", move);
105
105
  document.addEventListener("mouseup", up);
106
+ }; //左手手柄的移动端适配
107
+
108
+
109
+ var leftTouchStart = function leftTouchStart(e) {
110
+ var transform = ref.current.style.transform;
111
+ var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
112
+ var initX = 0;
113
+ var rightX = rawTranslateX + cBarWidth;
114
+ var startX = e.touches[0].clientX;
115
+ var currentX = 0;
116
+ var movementX = 0;
117
+
118
+ var move = function move(e) {
119
+ e.preventDefault();
120
+ currentX = e.touches[0].clientX;
121
+ movementX = currentX - startX;
122
+ startX = currentX;
123
+ initX = (0, _utils.mathR)(initX + movementX, [-rawTranslateX, rightX - rawTranslateX]);
124
+ setControlWidth(function (pre) {
125
+ var cWidth = pre.cWidth,
126
+ cBarWidth = pre.cBarWidth;
127
+ var nextBarWidth = (0, _utils.mathR)(cBarWidth - movementX, [1, rightX]);
128
+ return _objectSpread(_objectSpread({}, pre), {}, {
129
+ cBarWidth: nextBarWidth,
130
+ cPercent: nextBarWidth / cWidth,
131
+ cBarX: initX + rawTranslateX
132
+ });
133
+ });
134
+ };
135
+
136
+ var up = function up(e) {
137
+ document.removeEventListener("touchmove", move);
138
+ document.removeEventListener("touchend", up);
139
+ };
140
+
141
+ document.addEventListener("touchmove", move, {
142
+ passive: false
143
+ });
144
+ document.addEventListener("touchend", up);
106
145
  }; //滑块的鼠标按下操作
107
146
 
108
147
 
@@ -126,7 +165,36 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
126
165
  document.addEventListener("mousemove", mouseMoveHandle);
127
166
  document.addEventListener("mouseup", mouseUpHandle);
128
167
  setWorking(true);
129
- }; // //右手柄的鼠标按下逻辑
168
+ }; //移动端适配
169
+
170
+
171
+ var touchStart = function touchStart(e) {
172
+ var transform = ref.current.style.transform;
173
+ var startX = e.touches[0].clientX;
174
+ var currentX = 0;
175
+ var movementX = 0;
176
+ var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
177
+
178
+ var mouseMoveHandle = function mouseMoveHandle(e) {
179
+ e.preventDefault();
180
+ currentX = e.touches[0].clientX;
181
+ movementX += currentX - startX;
182
+ startX = currentX;
183
+ setX(movementX + rawTranslateX, true);
184
+ };
185
+
186
+ var mouseUpHandle = function mouseUpHandle(e) {
187
+ setWorking(false);
188
+ document.removeEventListener("touchmove", mouseMoveHandle);
189
+ document.removeEventListener("touchend", mouseUpHandle);
190
+ };
191
+
192
+ document.addEventListener("touchmove", mouseMoveHandle, {
193
+ passive: false
194
+ });
195
+ document.addEventListener("touchend", mouseUpHandle);
196
+ setWorking(true);
197
+ }; //右手柄的鼠标按下逻辑
130
198
 
131
199
 
132
200
  var rightDown = function rightDown() {
@@ -154,6 +222,42 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
154
222
 
155
223
  document.addEventListener("mousemove", move);
156
224
  document.addEventListener("mouseup", up);
225
+ }; //右手手柄的移动端适配
226
+
227
+
228
+ var rightTouchStart = function rightTouchStart(e) {
229
+ var transform = ref.current.style.transform;
230
+ var startX = e.touches[0].clientX;
231
+ var currentX = 0;
232
+ var movementX = 0;
233
+ var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
234
+
235
+ var move = function move(e) {
236
+ e.preventDefault();
237
+ currentX = e.touches[0].clientX;
238
+ movementX = currentX - startX;
239
+ startX = currentX;
240
+ setControlWidth(function (pre) {
241
+ var cWidth = pre.cWidth,
242
+ cBarWidth = pre.cBarWidth;
243
+ var maxWidth = cWidth - rawTranslateX;
244
+ var nextBarWidth = (0, _utils.mathR)(cBarWidth + movementX, [1, maxWidth]);
245
+ return _objectSpread(_objectSpread({}, pre), {}, {
246
+ cBarWidth: nextBarWidth,
247
+ cPercent: nextBarWidth / cWidth
248
+ });
249
+ });
250
+ };
251
+
252
+ var up = function up(e) {
253
+ document.removeEventListener("touchmove", move);
254
+ document.removeEventListener("touchend", up);
255
+ };
256
+
257
+ document.addEventListener("touchmove", move, {
258
+ passive: false
259
+ });
260
+ document.addEventListener("touchend", up);
157
261
  };
158
262
 
159
263
  return /*#__PURE__*/_react["default"].createElement("div", {
@@ -188,16 +292,19 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
188
292
  style: _objectSpread(_objectSpread({}, controllerStyle), {}, {
189
293
  transform: "translateX(-6px)"
190
294
  }),
191
- onMouseDown: leftDown
295
+ onMouseDown: leftDown,
296
+ onTouchStart: leftTouchStart
192
297
  }), /*#__PURE__*/_react["default"].createElement("div", {
193
298
  style: dragStyle,
194
299
  onMouseDown: down,
300
+ onTouchStart: touchStart,
195
301
  ref: barRef
196
302
  }), /*#__PURE__*/_react["default"].createElement("div", {
197
303
  style: _objectSpread(_objectSpread({}, controllerStyle), {}, {
198
304
  transform: "translateX(6px)"
199
305
  }),
200
- onMouseDown: rightDown
306
+ onMouseDown: rightDown,
307
+ onTouchStart: rightTouchStart
201
308
  })));
202
309
  }));
203
310
 
@@ -286,6 +286,9 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
286
286
  _ref5$config$chart$le2 = _ref5$config$chart$le.formatter,
287
287
  formatter = _ref5$config$chart$le2 === void 0 ? _formatter.pieLegendFormatter : _ref5$config$chart$le2,
288
288
  legend = (0, _objectWithoutProperties2["default"])(_ref5$config$chart$le, _excluded3),
289
+ _ref5$config$chart$an = _ref5$config$chart.animation,
290
+ ringDuration = _ref5$config$chart$an.ringDuration,
291
+ labelDuration = _ref5$config$chart$an.labelDuration,
289
292
  _ref5$config$chart$ma = _ref5$config$chart.margin,
290
293
  marginLeft = _ref5$config$chart$ma.marginLeft,
291
294
  marginTop = _ref5$config$chart$ma.marginTop,
@@ -597,6 +600,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
597
600
  ref: pieWarpEl
598
601
  }, /*#__PURE__*/_react["default"].createElement("g", {
599
602
  style: {
603
+ "--labelDuration": labelDuration + "ms",
604
+ "--ringDuration": ringDuration + "ms",
600
605
  transition: "transform ease-in-out 0.3s",
601
606
  transform: "translate(" + halfChartWidth + "px, " + halfChartHeight + "px) rotate(" + rotate_ + "deg)"
602
607
  }
@@ -627,7 +632,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
627
632
  style: {
628
633
  strokeDasharray: "".concat(dashLength, ",").concat(2 * dashLength),
629
634
  strokeDashoffset: dashLength,
630
- animationDelay: "".concat(index * 2000, "ms")
635
+ animationDelay: "".concat(index * ringDuration, "ms")
631
636
  },
632
637
  "data-index": index,
633
638
  onClick: onClick,
@@ -657,7 +662,9 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
657
662
  })));
658
663
  }), label && /*#__PURE__*/_react["default"].createElement(RingLabel, {
659
664
  config: _objectSpread(_objectSpread({}, label), {}, {
660
- maxRadius: maxRadius + 2
665
+ maxRadius: maxRadius + 2,
666
+ ringDuration: ringDuration,
667
+ labelDuration: labelDuration
661
668
  }),
662
669
  iosStyle: {
663
670
  isIOS: isIOS,
@@ -1073,7 +1080,7 @@ var Label = function Label(_ref10) {
1073
1080
  }, /*#__PURE__*/_react["default"].createElement("path", {
1074
1081
  className: animation ? _piechartModule["default"]["label-line"] : "",
1075
1082
  style: {
1076
- animationDelay: "".concat(animation ? (actualIndex + 1) * 2000 - 800 : 0, "ms")
1083
+ animationDelay: "".concat(animation ? (actualIndex + 1) * ringDuration - labelDuration : 0, "ms")
1077
1084
  },
1078
1085
  d: "M" + x1 + ", " + y1 + "L" + x2 + ", " + y2 + "L" + x3 + ", " + y2,
1079
1086
  stroke: lineColor ? lineColor : type == "pure" ? pure : stops[0].color,
@@ -1124,6 +1131,8 @@ var Label = function Label(_ref10) {
1124
1131
 
1125
1132
  var RingLabel = function RingLabel(_ref12) {
1126
1133
  var _ref12$config = _ref12.config,
1134
+ ringDuration = _ref12$config.ringDuration,
1135
+ labelDuration = _ref12$config.labelDuration,
1127
1136
  _ref12$config$maxRadi = _ref12$config.maxRadius,
1128
1137
  maxRadius = _ref12$config$maxRadi === void 0 ? 0 : _ref12$config$maxRadi,
1129
1138
  lineLength = _ref12$config.lineLength,
@@ -1219,7 +1228,7 @@ var RingLabel = function RingLabel(_ref12) {
1219
1228
  }, /*#__PURE__*/_react["default"].createElement("path", {
1220
1229
  className: _piechartModule["default"]["label-line"],
1221
1230
  style: {
1222
- animationDelay: "".concat((actualIndex + 1) * 2000 - 800, "ms")
1231
+ animationDelay: "".concat((actualIndex + 1) * ringDuration - labelDuration, "ms")
1223
1232
  },
1224
1233
  d: "M" + x1 + ", " + y1 + "L" + x2 + ", " + y2 + "L" + x3 + ", " + y2,
1225
1234
  stroke: lineColor ? lineColor : type == "pure" ? pure : stops[0].color,
@@ -1241,7 +1250,7 @@ var RingLabel = function RingLabel(_ref12) {
1241
1250
  whiteSpace: "nowrap",
1242
1251
  "float": x3 >= 0 ? "left" : "right",
1243
1252
  width: "max-content",
1244
- animationDelay: "".concat((actualIndex + 1) * 2000 - 800, "ms"),
1253
+ animationDelay: "".concat((actualIndex + 1) * ringDuration - labelDuration, "ms"),
1245
1254
  display: "flex",
1246
1255
  alignItems: "center"
1247
1256
  }
@@ -1,27 +1,27 @@
1
1
  /*甜甜圈图专用css*/
2
2
  .label-line {
3
- stroke-dasharray: 100;
4
- stroke-dashoffset: 100;
5
- animation: dash 800ms ease forwards;
6
- }
3
+ stroke-dasharray: 100;
4
+ stroke-dashoffset: 100;
5
+ animation: dash var(--labelDuration) ease forwards;
6
+ }
7
7
 
8
- .label-text {
9
- opacity: 0;
10
- animation: show 800ms ease forwards;
8
+ .label-text {
9
+ opacity: 0;
10
+ animation: show var(--labelDuration) ease forwards;
11
+ }
12
+
13
+ .inner-arc {
14
+ animation: dash var(--ringDuration) ease forwards;
15
+ }
16
+
17
+ @keyframes dash {
18
+ 100% {
19
+ stroke-dashoffset: 0%;
11
20
  }
12
-
13
- .inner-arc {
14
- animation: dash 2s ease forwards;
21
+ }
22
+
23
+ @keyframes show {
24
+ 100% {
25
+ opacity: 1;
15
26
  }
16
-
17
- @keyframes dash {
18
- 100% {
19
- stroke-dashoffset: 0%;
20
- }
21
- }
22
-
23
- @keyframes show {
24
- 100% {
25
- opacity: 1;
26
- }
27
- }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.5.21",
3
+ "version": "1.5.23",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -64,6 +64,39 @@ export default memo(forwardRef((props, ref) => {
64
64
  document.addEventListener("mousemove",move);
65
65
  document.addEventListener("mouseup",up);
66
66
  }
67
+ //左手手柄的移动端适配
68
+ const leftTouchStart = (e)=>{
69
+ const transform = ref.current.style.transform;
70
+ let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
71
+ let initX = 0;
72
+ const rightX = rawTranslateX+cBarWidth;
73
+ let startX = e.touches[0].clientX;
74
+ let currentX = 0;
75
+ let movementX = 0;
76
+ const move = (e)=>{
77
+ e.preventDefault();
78
+ currentX = e.touches[0].clientX;
79
+ movementX = currentX - startX;
80
+ startX = currentX;
81
+ initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
82
+ setControlWidth((pre)=>{
83
+ const { cWidth, cBarWidth } = pre;
84
+ const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
85
+ return {
86
+ ...pre,
87
+ cBarWidth:nextBarWidth,
88
+ cPercent:nextBarWidth/cWidth,
89
+ cBarX:initX+rawTranslateX
90
+ }
91
+ });
92
+ }
93
+ const up = (e) => {
94
+ document.removeEventListener("touchmove", move);
95
+ document.removeEventListener("touchend", up);
96
+ };
97
+ document.addEventListener("touchmove", move, {passive:false});
98
+ document.addEventListener("touchend", up);
99
+ }
67
100
  //滑块的鼠标按下操作
68
101
  const down=()=>{
69
102
  const transform = ref.current.style.transform;
@@ -83,7 +116,30 @@ export default memo(forwardRef((props, ref) => {
83
116
  document.addEventListener("mouseup", mouseUpHandle);
84
117
  setWorking(true);
85
118
  }
86
- // //右手柄的鼠标按下逻辑
119
+ //移动端适配
120
+ const touchStart=(e)=>{
121
+ const transform = ref.current.style.transform;
122
+ let startX = e.touches[0].clientX;
123
+ let currentX = 0;
124
+ let movementX = 0;
125
+ let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
126
+ const mouseMoveHandle = (e)=>{
127
+ e.preventDefault();
128
+ currentX = e.touches[0].clientX;
129
+ movementX += currentX - startX;
130
+ startX = currentX;
131
+ setX(movementX + rawTranslateX, true);
132
+ }
133
+ const mouseUpHandle = (e) => {
134
+ setWorking(false);
135
+ document.removeEventListener("touchmove", mouseMoveHandle);
136
+ document.removeEventListener("touchend", mouseUpHandle);
137
+ };
138
+ document.addEventListener("touchmove", mouseMoveHandle, {passive:false});
139
+ document.addEventListener("touchend", mouseUpHandle);
140
+ setWorking(true);
141
+ }
142
+ //右手柄的鼠标按下逻辑
87
143
  const rightDown=()=>{
88
144
  const transform = ref.current.style.transform;
89
145
  let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
@@ -107,6 +163,36 @@ export default memo(forwardRef((props, ref) => {
107
163
  document.addEventListener("mousemove",move);
108
164
  document.addEventListener("mouseup",up);
109
165
  }
166
+ //右手手柄的移动端适配
167
+ const rightTouchStart = (e)=>{
168
+ const transform = ref.current.style.transform;
169
+ let startX = e.touches[0].clientX;
170
+ let currentX = 0;
171
+ let movementX = 0;
172
+ let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
173
+ const move = (e)=>{
174
+ e.preventDefault();
175
+ currentX = e.touches[0].clientX;
176
+ movementX = currentX - startX;
177
+ startX = currentX;
178
+ setControlWidth((pre)=>{
179
+ const { cWidth, cBarWidth } = pre;
180
+ const maxWidth = cWidth-rawTranslateX;
181
+ const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
182
+ return {
183
+ ...pre,
184
+ cBarWidth:nextBarWidth,
185
+ cPercent:nextBarWidth/cWidth
186
+ }
187
+ });
188
+ }
189
+ const up = (e) => {
190
+ document.removeEventListener("touchmove", move);
191
+ document.removeEventListener("touchend", up);
192
+ };
193
+ document.addEventListener("touchmove", move, {passive:false});
194
+ document.addEventListener("touchend", up);
195
+ }
110
196
  return (
111
197
  <div
112
198
  style={{
@@ -140,9 +226,9 @@ export default memo(forwardRef((props, ref) => {
140
226
  </svg>
141
227
  {/* 控制条 */}
142
228
  <div ref={ref} style={barStyle}>
143
- <div style={{...controllerStyle,transform:"translateX(-6px)"}} onMouseDown={leftDown}></div>
144
- <div style={dragStyle} onMouseDown={down} ref={barRef}></div>
145
- <div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown}></div>
229
+ <div style={{...controllerStyle,transform:"translateX(-6px)"}} onMouseDown={leftDown} onTouchStart={leftTouchStart}></div>
230
+ <div style={dragStyle} onMouseDown={down} onTouchStart={touchStart} ref={barRef}></div>
231
+ <div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown} onTouchStart={rightTouchStart}></div>
146
232
  </div>
147
233
  </div>
148
234
  );
@@ -254,6 +254,7 @@ const Component = memo(
254
254
  },
255
255
  label,
256
256
  legend: { formatter = legendFormatter, ...legend },
257
+ animation: { ringDuration, labelDuration },
257
258
  margin: { marginLeft, marginTop },
258
259
  },
259
260
  fan: {
@@ -523,6 +524,8 @@ const Component = memo(
523
524
  >
524
525
  <g
525
526
  style={{
527
+ "--labelDuration":labelDuration+"ms",
528
+ "--ringDuration":ringDuration+"ms",
526
529
  transition: "transform ease-in-out 0.3s",
527
530
  transform:
528
531
  "translate(" +
@@ -564,7 +567,7 @@ const Component = memo(
564
567
  style={{
565
568
  strokeDasharray: `${dashLength},${2 * dashLength}`,
566
569
  strokeDashoffset: dashLength,
567
- animationDelay: `${index * 2000}ms`,
570
+ animationDelay: `${index * ringDuration}ms`,
568
571
  }}
569
572
  data-index={index}
570
573
  onClick={onClick}
@@ -601,7 +604,7 @@ const Component = memo(
601
604
  )}
602
605
  {label && (
603
606
  <RingLabel
604
- config={{ ...label, maxRadius: maxRadius + 2 }}
607
+ config={{ ...label, maxRadius: maxRadius + 2, ringDuration, labelDuration }}
605
608
  iosStyle={{isIOS, left:halfChartWidth+marginLeft, top:halfChartHeight+marginTop}}
606
609
  arcs={_arcs}
607
610
  judge={judgeData}
@@ -1137,7 +1140,7 @@ const Label = ({
1137
1140
  className={animation ? ringCss["label-line"] : ""}
1138
1141
  style={{
1139
1142
  animationDelay: `${
1140
- animation ? (actualIndex + 1) * 2000 - 800 : 0
1143
+ animation ? (actualIndex + 1) * ringDuration - labelDuration : 0
1141
1144
  }ms`,
1142
1145
  }}
1143
1146
  d={
@@ -1234,6 +1237,8 @@ const Label = ({
1234
1237
 
1235
1238
  const RingLabel = ({
1236
1239
  config: {
1240
+ ringDuration,
1241
+ labelDuration,
1237
1242
  maxRadius = 0,
1238
1243
  lineLength,
1239
1244
  lineColor,
@@ -1321,7 +1326,7 @@ const RingLabel = ({
1321
1326
  <path
1322
1327
  className={ringCss["label-line"]}
1323
1328
  style={{
1324
- animationDelay: `${(actualIndex + 1) * 2000 - 800}ms`,
1329
+ animationDelay: `${(actualIndex + 1) * ringDuration - labelDuration}ms`,
1325
1330
  }}
1326
1331
  d={
1327
1332
  "M" +
@@ -1361,7 +1366,7 @@ const RingLabel = ({
1361
1366
  whiteSpace: "nowrap",
1362
1367
  float: x3 >= 0 ? "left" : "right",
1363
1368
  width: "max-content",
1364
- animationDelay: `${(actualIndex + 1) * 2000 - 800}ms`,
1369
+ animationDelay: `${(actualIndex + 1) * ringDuration - labelDuration}ms`,
1365
1370
  display:"flex",
1366
1371
  alignItems:"center"
1367
1372
  }}
@@ -1,27 +1,27 @@
1
1
  /*甜甜圈图专用css*/
2
2
  .label-line {
3
- stroke-dasharray: 100;
4
- stroke-dashoffset: 100;
5
- animation: dash 800ms ease forwards;
6
- }
3
+ stroke-dasharray: 100;
4
+ stroke-dashoffset: 100;
5
+ animation: dash var(--labelDuration) ease forwards;
6
+ }
7
7
 
8
- .label-text {
9
- opacity: 0;
10
- animation: show 800ms ease forwards;
8
+ .label-text {
9
+ opacity: 0;
10
+ animation: show var(--labelDuration) ease forwards;
11
+ }
12
+
13
+ .inner-arc {
14
+ animation: dash var(--ringDuration) ease forwards;
15
+ }
16
+
17
+ @keyframes dash {
18
+ 100% {
19
+ stroke-dashoffset: 0%;
11
20
  }
12
-
13
- .inner-arc {
14
- animation: dash 2s ease forwards;
21
+ }
22
+
23
+ @keyframes show {
24
+ 100% {
25
+ opacity: 1;
15
26
  }
16
-
17
- @keyframes dash {
18
- 100% {
19
- stroke-dashoffset: 0%;
20
- }
21
- }
22
-
23
- @keyframes show {
24
- 100% {
25
- opacity: 1;
26
- }
27
- }
27
+ }