@easyv/charts 1.9.20 → 1.9.21

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.
@@ -264,7 +264,7 @@ var Label = function Label(_ref5) {
264
264
  // y={y}
265
265
  ,
266
266
  style: {
267
- overflow: "visible"
267
+ overflow: "hidden"
268
268
  }
269
269
  }, /*#__PURE__*/_react["default"].createElement("div", {
270
270
  className: className,
@@ -334,14 +334,20 @@ 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;
337
+ paddingOuter = _ref6.paddingOuter,
338
+ controlEnd = _ref6.controlEnd,
339
+ start = _ref6.start;
338
340
  var _useContext = (0, _react.useContext)(_context.chartContext),
339
341
  width = _useContext.width,
340
342
  height = _useContext.height,
341
343
  isIOS = _useContext.isIOS;
342
344
  var cHeight = controlInfo.cHeight,
343
345
  isC = controlInfo.isC,
344
- cPercent = controlInfo.cPercent;
346
+ cPercent = controlInfo.cPercent,
347
+ cBarX = controlInfo.cBarX,
348
+ cWidth = controlInfo.cWidth,
349
+ cBarWidth = controlInfo.cBarWidth;
350
+ var clipPathIdRef = (0, _react.useRef)("axis-clip-".concat(orientation, "-").concat(axisType, "-").concat(Math.random().toString(36).substr(2, 9)));
345
351
  var x = orientation == "right" ? width : 0;
346
352
  var y = orientation == "bottom" ? height - cHeight : 0;
347
353
  var LabelWidth = 1;
@@ -444,6 +450,13 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
444
450
  }
445
451
  }
446
452
  function drawLabel() {
453
+ // 在 drawLabel 内部重新计算 translateX,确保使用最新的 controlInfo
454
+ var labelTranslateX = 0;
455
+ if (isC && isIOS && axisType === "x" && controlEnd !== undefined && start !== undefined) {
456
+ var percent = cBarX / (cWidth - cBarWidth);
457
+ var validPercent = isNaN(percent) ? 1 : percent;
458
+ labelTranslateX = -(controlEnd + start / cPercent - width) * validPercent;
459
+ }
447
460
  var draw = function draw(ticks, scaler) {
448
461
  return ticks.map(function (tick, index) {
449
462
  var coordinate = scaler(tick);
@@ -464,7 +477,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
464
477
  coordinate: coordinate,
465
478
  iosTrans: {
466
479
  isIOS: isIOS,
467
- x: marginLeft + x,
480
+ x: marginLeft + x + (isIOS && isC && axisType === "x" ? labelTranslateX : 0),
468
481
  y: marginTop + y
469
482
  },
470
483
  config: label,
@@ -537,10 +550,20 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
537
550
  }), tickLine && drawAxisTickLine()))), /*#__PURE__*/_react["default"].createElement("svg", {
538
551
  width: width,
539
552
  style: {
540
- overflow: axisType === "x" && isC ? "hidden" : "visible"
553
+ overflow: "hidden"
541
554
  }
542
- }, /*#__PURE__*/_react["default"].createElement("g", {
543
- transform: "translate(" + x + ", " + y + ")"
555
+ }, axisType === "x" && isC || isIOS && axisType === "x" ? /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement("clipPath", {
556
+ id: clipPathIdRef.current,
557
+ clipPathUnits: "userSpaceOnUse"
558
+ }, /*#__PURE__*/_react["default"].createElement("rect", {
559
+ x: "0",
560
+ y: "0",
561
+ width: xLineRange,
562
+ height: height + 200,
563
+ fill: "transparent"
564
+ }))) : null, /*#__PURE__*/_react["default"].createElement("g", {
565
+ transform: "translate(" + x + ", " + y + ")",
566
+ clipPath: axisType === "x" && isC || isIOS && axisType === "x" ? "url(#".concat(clipPathIdRef.current, ")") : undefined
544
567
  }, /*#__PURE__*/_react["default"].createElement("g", {
545
568
  ref: ref
546
569
  }, label && gridLine && drawLabel(), isC && /*#__PURE__*/_react["default"].createElement(AxisLine, {
@@ -127,6 +127,10 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
127
127
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
128
128
  controlInfo = _useState6[0],
129
129
  setControlInfo = _useState6[1];
130
+ var _useState7 = (0, _react.useState)(0),
131
+ _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
132
+ clipX = _useState8[0],
133
+ setClipX = _useState8[1];
130
134
  var cWidth = controlInfo.cWidth,
131
135
  cHeight = controlInfo.cHeight,
132
136
  cBarWidth = controlInfo.cBarWidth,
@@ -166,10 +170,10 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
166
170
  })
167
171
  };
168
172
  };
169
- var _useState7 = (0, _react.useState)(initCtlTip),
170
- _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
171
- ctlTip = _useState8[0],
172
- setCtlTip = _useState8[1]; //控制图的提示框
173
+ var _useState9 = (0, _react.useState)(initCtlTip),
174
+ _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
175
+ ctlTip = _useState10[0],
176
+ setCtlTip = _useState10[1]; //控制图的提示框
173
177
 
174
178
  (0, _react.useEffect)(function () {
175
179
  var handleAction = function handleAction(e) {
@@ -352,7 +356,10 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
352
356
  percent = isNaN(percent) ? 1 : percent;
353
357
  var translateX = -(controlEnd + start / cPercent - chartWidth) * percent;
354
358
  curControlPercent.current = percent;
355
- // seriesEl.current.style.transform = `translate(${translateX}px,${marginTop}px)`;
359
+ setClipX(-translateX);
360
+ var _isVertical = axisX.direction === "vertical";
361
+ var coreOffset = _isVertical ? marginRight : isIOS ? marginLeft : 0;
362
+ seriesEl.current.style.transform = "translate(".concat(translateX + coreOffset, "px,").concat(marginTop, "px)");
356
363
  axisElList.current[2].style.transform = "translate(".concat(translateX, "px,", 0, "px)");
357
364
  }
358
365
  }, [controlInfo]);
@@ -596,7 +603,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
596
603
  }, /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement("clipPath", {
597
604
  id: "chart-clip-".concat(id)
598
605
  }, /*#__PURE__*/_react["default"].createElement("rect", {
599
- x: "0",
606
+ x: clipX,
600
607
  y: "0",
601
608
  width: xLineRange,
602
609
  height: yLineRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.9.20",
3
+ "version": "1.9.21",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@ import React, {
9
9
  CSSProperties,
10
10
  MouseEventHandler,
11
11
  forwardRef,
12
+ useRef,
12
13
  } from "react";
13
14
  import { getTickCoord, getGridCoord, getFontStyle } from "../utils";
14
15
  import { chartContext } from "../context";
@@ -307,7 +308,7 @@ const Label: (
307
308
  height="100%"
308
309
  // x={x}
309
310
  // y={y}
310
- style={{ overflow: "visible" }}
311
+ style={{ overflow: "hidden" }}
311
312
  >
312
313
  <div
313
314
  className={className}
@@ -388,13 +389,22 @@ export default memo(
388
389
  controlInfo,
389
390
  rawTicks,
390
391
  paddingOuter,
392
+ // 从展开的 config 中获取控制图相关属性
393
+ controlEnd,
394
+ start,
391
395
  }: any,
392
396
  ref
393
397
  ) => {
394
398
  const { width, height, isIOS } = useContext(chartContext);
395
- const { cHeight, isC, cPercent } = controlInfo;
399
+ const { cHeight, isC, cPercent, cBarX, cWidth, cBarWidth } = controlInfo;
400
+ const clipPathIdRef = useRef(
401
+ `axis-clip-${orientation}-${axisType}-${Math.random()
402
+ .toString(36)
403
+ .substr(2, 9)}`
404
+ );
396
405
  const x = orientation == "right" ? width : 0;
397
406
  const y = orientation == "bottom" ? height - cHeight : 0;
407
+
398
408
  let LabelWidth = 1;
399
409
  if (label.labelNum == "Fixed") {
400
410
  LabelWidth = label.appearance.width;
@@ -543,6 +553,21 @@ export default memo(
543
553
  }
544
554
  }
545
555
  function drawLabel() {
556
+ // 在 drawLabel 内部重新计算 translateX,确保使用最新的 controlInfo
557
+ let labelTranslateX = 0;
558
+ if (
559
+ isC &&
560
+ isIOS &&
561
+ axisType === "x" &&
562
+ controlEnd !== undefined &&
563
+ start !== undefined
564
+ ) {
565
+ const percent = cBarX / (cWidth - cBarWidth);
566
+ const validPercent = isNaN(percent) ? 1 : percent;
567
+ labelTranslateX =
568
+ -(controlEnd + start / cPercent - width) * validPercent;
569
+ }
570
+
546
571
  const draw = (ticks: any, scaler: any) => {
547
572
  return ticks.map((tick: string, index: number) => {
548
573
  const coordinate = scaler(tick);
@@ -571,7 +596,16 @@ export default memo(
571
596
  className="__easyv-label"
572
597
  orientation={orientation}
573
598
  coordinate={coordinate}
574
- iosTrans={{ isIOS, x: marginLeft + x, y: marginTop + y }}
599
+ iosTrans={{
600
+ isIOS,
601
+ x:
602
+ marginLeft +
603
+ x +
604
+ (isIOS && isC && axisType === "x"
605
+ ? labelTranslateX
606
+ : 0),
607
+ y: marginTop + y,
608
+ }}
575
609
  config={label}
576
610
  label={tick}
577
611
  tickSize={_tickSize}
@@ -680,10 +714,34 @@ export default memo(
680
714
  <svg
681
715
  width={width}
682
716
  style={{
683
- overflow: axisType === "x" && isC ? "hidden" : "visible",
717
+ overflow: "hidden",
684
718
  }}
685
719
  >
686
- <g transform={"translate(" + x + ", " + y + ")"}>
720
+ {/* 定义裁剪路径:用于iOS端超出隐藏 */}
721
+ {(axisType === "x" && isC) || (isIOS && axisType === "x") ? (
722
+ <defs>
723
+ <clipPath
724
+ id={clipPathIdRef.current}
725
+ clipPathUnits="userSpaceOnUse"
726
+ >
727
+ <rect
728
+ x="0"
729
+ y="0"
730
+ width={xLineRange}
731
+ height={height + 200}
732
+ fill="transparent"
733
+ />
734
+ </clipPath>
735
+ </defs>
736
+ ) : null}
737
+ <g
738
+ transform={"translate(" + x + ", " + y + ")"}
739
+ clipPath={
740
+ (axisType === "x" && isC) || (isIOS && axisType === "x")
741
+ ? `url(#${clipPathIdRef.current})`
742
+ : undefined
743
+ }
744
+ >
687
745
  {/* 用于控制图 */}
688
746
  <g ref={ref as any}>
689
747
  {label && gridLine && drawLabel()}
@@ -115,6 +115,7 @@ const Chart = memo(
115
115
  cPercent: dragPercent,
116
116
  cBarX: controlX,
117
117
  });
118
+ const [clipX, setClipX] = useState(0);
118
119
  const { cWidth, cHeight, cBarWidth, cPercent, cBarX } = controlInfo;
119
120
 
120
121
  yLineRange -= cHeight;
@@ -344,7 +345,12 @@ const Chart = memo(
344
345
  const translateX =
345
346
  -(controlEnd + start / cPercent - chartWidth) * percent;
346
347
  curControlPercent.current = percent;
347
- // seriesEl.current.style.transform = `translate(${translateX}px,${marginTop}px)`;
348
+ setClipX(-translateX);
349
+ const isVertical = axisX.direction === "vertical";
350
+ const coreOffset = isVertical ? marginRight : isIOS ? marginLeft : 0;
351
+ seriesEl.current.style.transform = `translate(${
352
+ translateX + coreOffset
353
+ }px,${marginTop}px)`;
348
354
  axisElList.current[2].style.transform = `translate(${translateX}px,${0}px)`;
349
355
  }
350
356
  }, [controlInfo]);
@@ -583,7 +589,6 @@ const Chart = memo(
583
589
  : `translateY(${-marginTop}px)`,
584
590
  }}
585
591
  >
586
- {/* 关键修改1:添加clipPath定义,限定裁剪区域 */}
587
592
  <svg
588
593
  width="100%"
589
594
  height="100%"
@@ -600,7 +605,7 @@ const Chart = memo(
600
605
  <defs>
601
606
  <clipPath id={`chart-clip-${id}`}>
602
607
  <rect
603
- x="0"
608
+ x={clipX}
604
609
  y="0"
605
610
  width={xLineRange}
606
611
  height={yLineRange}
@@ -610,6 +615,7 @@ const Chart = memo(
610
615
  </defs>
611
616
 
612
617
  {/* 关键修改2:将所有图表内容包裹在g标签中,并应用clipPath */}
618
+ {/* <g> */}
613
619
  <g clipPath={`url(#chart-clip-${id})`}>
614
620
  {/* 控制图指示器部分 */}
615
621
  <g>