@easyv/charts 1.9.22 → 1.9.24

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.
@@ -227,7 +227,7 @@ var Label = function Label(_ref5) {
227
227
  events = _ref5$events === void 0 ? defaultEvent : _ref5$events,
228
228
  _ref5$config = _ref5.config,
229
229
  show = _ref5$config.show,
230
- labelNum = _ref5$config.labelNum,
230
+ adaptive = _ref5$config.adaptive,
231
231
  style = _ref5$config.style,
232
232
  _ref5$config$translat = _ref5$config.translate,
233
233
  translateX = _ref5$config$translat.x,
@@ -280,7 +280,7 @@ var Label = function Label(_ref5) {
280
280
  cursor: "pointer",
281
281
  transform: "translate(".concat(x + (isIOS ? iosX : 0), "px, ").concat(y + (isIOS ? iosY : 0), "px)") // 用 transform 定位
282
282
  })
283
- }, labelNum == "Fixed" ? /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
283
+ }, !adaptive ? /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
284
284
  ShowType: "normal",
285
285
  type: textOverflow,
286
286
  speed: speed,
@@ -334,23 +334,18 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
334
334
  clipAxisRange = _ref6.clipAxisRange,
335
335
  controlInfo = _ref6.controlInfo,
336
336
  rawTicks = _ref6.rawTicks,
337
- paddingOuter = _ref6.paddingOuter,
338
- controlEnd = _ref6.controlEnd,
339
- start = _ref6.start;
337
+ paddingOuter = _ref6.paddingOuter;
340
338
  var _useContext = (0, _react.useContext)(_context.chartContext),
341
339
  width = _useContext.width,
342
340
  height = _useContext.height,
343
341
  isIOS = _useContext.isIOS;
344
342
  var cHeight = controlInfo.cHeight,
345
343
  isC = controlInfo.isC,
346
- cPercent = controlInfo.cPercent,
347
- cBarX = controlInfo.cBarX,
348
- cWidth = controlInfo.cWidth,
349
- cBarWidth = controlInfo.cBarWidth;
344
+ cPercent = controlInfo.cPercent;
350
345
  var x = orientation == "right" ? width : 0;
351
346
  var y = orientation == "bottom" ? height - cHeight : 0;
352
347
  var LabelWidth = 1;
353
- if (label.labelNum == "Fixed") {
348
+ if (!label.adaptive && label.appearance) {
354
349
  LabelWidth = label.appearance.width;
355
350
  } else {
356
351
  if (allTicks.length && typeof allTicks[0] == "string") {
@@ -358,7 +353,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
358
353
  }
359
354
  }
360
355
  var LabelNum = Math.floor(width / (isC ? cPercent : 1) * (1 - paddingOuter) / LabelWidth);
361
- var ticks = label.labelNum == "Fixed" ? tickss : getEvenlySpacedElements(allTicks, LabelNum < allTicks.length ? LabelNum > allTicks.length / 2 ? Math.ceil(allTicks.length / 2) : LabelNum : allTicks.length, label.showLast);
356
+ var ticks = !label.adaptive ? tickss : getEvenlySpacedElements(allTicks, LabelNum < allTicks.length ? LabelNum > allTicks.length / 2 ? Math.ceil(allTicks.length / 2) : LabelNum : allTicks.length, label.showLast);
362
357
  if (!(on && ticks.length > 0)) return null;
363
358
 
364
359
  //数据抽取逻辑
@@ -449,13 +444,6 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
449
444
  }
450
445
  }
451
446
  function drawLabel() {
452
- // 在 drawLabel 内部重新计算 translateX,确保使用最新的 controlInfo
453
- var labelTranslateX = 0;
454
- if (isC && isIOS && axisType === "x" && controlEnd !== undefined && start !== undefined) {
455
- var percent = cBarX / (cWidth - cBarWidth);
456
- var validPercent = isNaN(percent) ? 1 : percent;
457
- labelTranslateX = -(controlEnd + start / cPercent - width) * validPercent;
458
- }
459
447
  var draw = function draw(ticks, scaler) {
460
448
  return ticks.map(function (tick, index) {
461
449
  var coordinate = scaler(tick);
@@ -476,7 +464,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
476
464
  coordinate: coordinate,
477
465
  iosTrans: {
478
466
  isIOS: isIOS,
479
- x: marginLeft + x + (isIOS && isC && axisType === "x" ? labelTranslateX : 0),
467
+ x: marginLeft + x,
480
468
  y: marginTop + y
481
469
  },
482
470
  config: label,
@@ -579,7 +579,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
579
579
  },
580
580
  dataUnit: dataUnit
581
581
  }, config, {
582
- key: index
582
+ key: index,
583
+ clipX: clipX
583
584
  }));
584
585
  }), showTooltip && !control && zIndex == "bottom" && /*#__PURE__*/_react["default"].createElement(_.Indicator, (0, _extends2["default"])({}, indicator, {
585
586
  manual: true,
@@ -596,7 +597,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
596
597
  ref: seriesEl,
597
598
  style: {
598
599
  overflow: "visible",
599
- // 保留原有样式,clipPath会接管裁剪
600
600
  position: "absolute",
601
601
  transform: isVertical ? "translate(".concat(marginRight, "px,").concat(isIOS ? marginTop : 0, "px)") : "translate(".concat(isIOS ? marginLeft : 0, "px,").concat(marginTop, "px)")
602
602
  }
@@ -29,7 +29,9 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
29
29
  height = _props$props$control.height,
30
30
  color = _props$props$control.color,
31
31
  gap = _props$props$control.gap,
32
- dragColor = _props$props$control.drag.color,
32
+ _props$props$control$ = _props$props$control.drag,
33
+ dragColor = _props$props$control$.color,
34
+ enableStretch = _props$props$control$.enableStretch,
33
35
  left = _props$props$control.margin.left,
34
36
  _props$props$controlI = _props$props.controlInfo,
35
37
  cWidth = _props$props$controlI.cWidth,
@@ -60,13 +62,14 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
60
62
  width: 12,
61
63
  height: height,
62
64
  padding: "0 5px",
63
- cursor: "col-resize",
65
+ cursor: enableStretch ? "col-resize" : "auto",
64
66
  background: "rgb(2, 176, 249)",
65
67
  WebkitBackgroundClip: "content-box"
66
68
  };
67
69
 
68
70
  //左手柄的鼠标按下逻辑
69
71
  var leftDown = function leftDown() {
72
+ if (!enableStretch) return;
70
73
  var transform = ref.current.style.transform;
71
74
  var initX = 0;
72
75
  var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
@@ -95,6 +98,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
95
98
  };
96
99
  //左手手柄的移动端适配
97
100
  var leftTouchStart = function leftTouchStart(e) {
101
+ if (!enableStretch) return;
98
102
  var transform = ref.current.style.transform;
99
103
  var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
100
104
  var initX = 0;
@@ -174,6 +178,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
174
178
  };
175
179
  //右手柄的鼠标按下逻辑
176
180
  var rightDown = function rightDown() {
181
+ if (!enableStretch) return;
177
182
  var transform = ref.current.style.transform;
178
183
  var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
179
184
  var move = function move(e) {
@@ -199,6 +204,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
199
204
  };
200
205
  //右手手柄的移动端适配
201
206
  var rightTouchStart = function rightTouchStart(e) {
207
+ if (!enableStretch) return;
202
208
  var transform = ref.current.style.transform;
203
209
  var startX = e.touches[0].clientX;
204
210
  var currentX = 0;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.9.22",
3
+ "version": "1.9.24",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "make": "babel src -d lib --extensions .ts,.tsx,.js,.jsx && cp -r src/css lib",
8
+ "watch": "cp -r src/css lib && babel --watch src -d lib --extensions .ts,.tsx,.js,.jsx",
8
9
  "prepare": "husky install"
9
10
  },
10
11
  "keywords": [],
@@ -54,4 +55,4 @@
54
55
  "commit": true
55
56
  }
56
57
  }
57
- }
58
+ }
@@ -226,7 +226,7 @@ type LabelType = {
226
226
  events?: Function;
227
227
  config: {
228
228
  show: boolean;
229
- labelNum: string;
229
+ adaptive:boolean;
230
230
  translate: Translate;
231
231
  font: Font;
232
232
  textAlign: TextAlign;
@@ -277,7 +277,7 @@ const Label: (
277
277
  events = defaultEvent,
278
278
  config: {
279
279
  show,
280
- labelNum,
280
+ adaptive,
281
281
  style,
282
282
  translate: { x: translateX, y: translateY },
283
283
  font,
@@ -323,7 +323,7 @@ const Label: (
323
323
  }px)`, // 用 transform 定位
324
324
  }}
325
325
  >
326
- {labelNum == "Fixed" ? (
326
+ {!adaptive ? (
327
327
  <TextOverflow
328
328
  ShowType="normal"
329
329
  type={textOverflow}
@@ -388,19 +388,15 @@ export default memo(
388
388
  controlInfo,
389
389
  rawTicks,
390
390
  paddingOuter,
391
- // 从展开的 config 中获取控制图相关属性
392
- controlEnd,
393
- start,
394
391
  }: any,
395
392
  ref
396
393
  ) => {
397
394
  const { width, height, isIOS } = useContext(chartContext);
398
- const { cHeight, isC, cPercent, cBarX, cWidth, cBarWidth } = controlInfo;
395
+ const { cHeight, isC, cPercent } = controlInfo;
399
396
  const x = orientation == "right" ? width : 0;
400
397
  const y = orientation == "bottom" ? height - cHeight : 0;
401
-
402
398
  let LabelWidth = 1;
403
- if (label.labelNum == "Fixed") {
399
+ if (!label.adaptive&&label.appearance) {
404
400
  LabelWidth = label.appearance.width;
405
401
  } else {
406
402
  if (allTicks.length && typeof allTicks[0] == "string") {
@@ -411,7 +407,7 @@ export default memo(
411
407
  ((width / (isC ? cPercent : 1)) * (1 - paddingOuter)) / LabelWidth
412
408
  );
413
409
  const ticks: any =
414
- label.labelNum == "Fixed"
410
+ !label.adaptive
415
411
  ? tickss
416
412
  : getEvenlySpacedElements(
417
413
  allTicks,
@@ -547,21 +543,6 @@ export default memo(
547
543
  }
548
544
  }
549
545
  function drawLabel() {
550
- // 在 drawLabel 内部重新计算 translateX,确保使用最新的 controlInfo
551
- let labelTranslateX = 0;
552
- if (
553
- isC &&
554
- isIOS &&
555
- axisType === "x" &&
556
- controlEnd !== undefined &&
557
- start !== undefined
558
- ) {
559
- const percent = cBarX / (cWidth - cBarWidth);
560
- const validPercent = isNaN(percent) ? 1 : percent;
561
- labelTranslateX =
562
- -(controlEnd + start / cPercent - width) * validPercent;
563
- }
564
-
565
546
  const draw = (ticks: any, scaler: any) => {
566
547
  return ticks.map((tick: string, index: number) => {
567
548
  const coordinate = scaler(tick);
@@ -590,16 +571,7 @@ export default memo(
590
571
  className="__easyv-label"
591
572
  orientation={orientation}
592
573
  coordinate={coordinate}
593
- iosTrans={{
594
- isIOS,
595
- x:
596
- marginLeft +
597
- x +
598
- (isIOS && isC && axisType === "x"
599
- ? labelTranslateX
600
- : 0),
601
- y: marginTop + y,
602
- }}
574
+ iosTrans={{ isIOS, x: marginLeft + x, y: marginTop + y }}
603
575
  config={label}
604
576
  label={tick}
605
577
  tickSize={_tickSize}
@@ -348,9 +348,8 @@ const Chart = memo(
348
348
  setClipX(-translateX);
349
349
  const isVertical = axisX.direction === "vertical";
350
350
  const coreOffset = isVertical ? marginRight : isIOS ? marginLeft : 0;
351
- seriesEl.current.style.transform = `translate(${
352
- translateX + coreOffset
353
- }px,${marginTop}px)`;
351
+ seriesEl.current.style.transform = `translate(${translateX + coreOffset
352
+ }px,${marginTop}px)`;
354
353
  axisElList.current[2].style.transform = `translate(${translateX}px,${0}px)`;
355
354
  }
356
355
  }, [controlInfo]);
@@ -459,8 +458,8 @@ const Chart = memo(
459
458
  const controlChartTooltipData =
460
459
  ctlXName && originData.filter((d) => d.x === ctlXName);
461
460
  const bodyWidth = isVertical
462
- ? xLineRange + 100 + marginRight + marginLeft
463
- : xLineRange,
461
+ ? xLineRange + 100 + marginRight + marginLeft
462
+ : xLineRange,
464
463
  bodyHeight = isVertical
465
464
  ? yLineRange
466
465
  : yLineRange + marginTop + marginBottom;
@@ -512,7 +511,6 @@ const Chart = memo(
512
511
  style={{ ...style, position: "absolute" }}
513
512
  width={width}
514
513
  height={height}
515
-
516
514
  marginLeft={marginLeft}
517
515
  marginTop={marginTop}
518
516
  onMouseEnter={() => {
@@ -569,6 +567,7 @@ const Chart = memo(
569
567
  dataUnit={dataUnit}
570
568
  {...config}
571
569
  key={index}
570
+ clipX={clipX}
572
571
  />
573
572
  );
574
573
  })}
@@ -595,7 +594,7 @@ const Chart = memo(
595
594
  height="100%"
596
595
  ref={seriesEl}
597
596
  style={{
598
- overflow: "visible", // 保留原有样式,clipPath会接管裁剪
597
+ overflow: "visible",
599
598
  position: "absolute",
600
599
  transform: isVertical
601
600
  ? `translate(${marginRight}px,${isIOS ? marginTop : 0}px)`
@@ -725,7 +724,7 @@ const Chart = memo(
725
724
  ctlX -
726
725
  marginLeft -
727
726
  (axisX.controlEnd + axisX.start / cPercent - chartWidth) *
728
- curControlPercent.current
727
+ curControlPercent.current
729
728
  }
730
729
  marginLeft={marginLeft}
731
730
  marginTop={marginTop}
@@ -13,7 +13,7 @@ export default memo(
13
13
  height,
14
14
  color,
15
15
  gap,
16
- drag: { color: dragColor },
16
+ drag: { color: dragColor, enableStretch },
17
17
  margin: { left },
18
18
  },
19
19
  controlInfo: { cWidth, cBarWidth },
@@ -46,17 +46,19 @@ export default memo(
46
46
  width: 12,
47
47
  height,
48
48
  padding: "0 5px",
49
- cursor: "col-resize",
49
+ cursor: enableStretch ? "col-resize" : "auto",
50
50
  background: "rgb(2, 176, 249)",
51
- WebkitBackgroundClip: "content-box",
51
+ WebkitBackgroundClip: "content-box"
52
52
  };
53
53
 
54
54
  //左手柄的鼠标按下逻辑
55
55
  const leftDown = () => {
56
+ if (!enableStretch) return;
57
+
56
58
  const transform = ref.current.style.transform;
57
59
  let initX = 0;
58
60
  let rawTranslateX = parseFloat(
59
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
61
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
60
62
  );
61
63
  const rightX = rawTranslateX + cBarWidth;
62
64
  const move = (e) => {
@@ -86,9 +88,11 @@ export default memo(
86
88
  };
87
89
  //左手手柄的移动端适配
88
90
  const leftTouchStart = (e) => {
91
+ if (!enableStretch) return;
92
+
89
93
  const transform = ref.current.style.transform;
90
94
  let rawTranslateX = parseFloat(
91
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
95
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
92
96
  );
93
97
  let initX = 0;
94
98
  const rightX = rawTranslateX + cBarWidth;
@@ -127,7 +131,7 @@ export default memo(
127
131
  const transform = ref.current.style.transform;
128
132
  let movementX = 0;
129
133
  let rawTranslateX = parseFloat(
130
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
134
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
131
135
  );
132
136
  const mouseMoveHandle = (e) => {
133
137
  //当前位移的距离
@@ -150,7 +154,7 @@ export default memo(
150
154
  let currentX = 0;
151
155
  let movementX = 0;
152
156
  let rawTranslateX = parseFloat(
153
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
157
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
154
158
  );
155
159
  const mouseMoveHandle = (e) => {
156
160
  e.preventDefault();
@@ -172,9 +176,11 @@ export default memo(
172
176
  };
173
177
  //右手柄的鼠标按下逻辑
174
178
  const rightDown = () => {
179
+ if (!enableStretch) return;
180
+
175
181
  const transform = ref.current.style.transform;
176
182
  let rawTranslateX = parseFloat(
177
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
183
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
178
184
  );
179
185
  const move = (e) => {
180
186
  const { movementX: ex } = e;
@@ -199,12 +205,14 @@ export default memo(
199
205
  };
200
206
  //右手手柄的移动端适配
201
207
  const rightTouchStart = (e) => {
208
+ if (!enableStretch) return;
209
+
202
210
  const transform = ref.current.style.transform;
203
211
  let startX = e.touches[0].clientX;
204
212
  let currentX = 0;
205
213
  let movementX = 0;
206
214
  let rawTranslateX = parseFloat(
207
- transform ? transform.match(/\d+\.*\d*/)[0] : 0
215
+ transform ? transform.match(/\d+\.*\d*/)[0] : 0,
208
216
  );
209
217
  const move = (e) => {
210
218
  e.preventDefault();
@@ -229,6 +237,7 @@ export default memo(
229
237
  document.addEventListener("touchmove", move, { passive: false });
230
238
  document.addEventListener("touchend", up);
231
239
  };
240
+
232
241
  return (
233
242
  <div
234
243
  style={{
@@ -265,6 +274,7 @@ export default memo(
265
274
  );
266
275
  })}
267
276
  </svg>
277
+
268
278
  {/* 控制条 */}
269
279
  <div ref={ref} style={barStyle}>
270
280
  <div
@@ -286,5 +296,5 @@ export default memo(
286
296
  </div>
287
297
  </div>
288
298
  );
289
- })
299
+ }),
290
300
  );