@easyv/charts 1.10.32 → 1.10.34

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.
@@ -46,6 +46,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
46
46
  _ref$config$layout$al = _ref$config$layout.alignment,
47
47
  alignment = _ref$config$layout$al === void 0 ? "right center" : _ref$config$layout$al,
48
48
  gridTemplateColumns = _ref$config$layout.gridTemplateColumns,
49
+ layoutType = _ref$config$layout.layoutType,
49
50
  _ref$config$layout$gr = _ref$config$layout.gridGap,
50
51
  gridColumnGap = _ref$config$layout$gr.gridColumnGap,
51
52
  gridRowGap = _ref$config$layout$gr.gridRowGap,
@@ -226,6 +227,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
226
227
  var isPieAdaptive = isPieChart && layoutMode === "Adaptive";
227
228
  var isPieFixedWidthGrid = isPieChart && (layoutMode === "FixedWidth" || (layoutMode == null || layoutMode === "") && LegendType == "FixedWidth");
228
229
  var isFixedWidth = isPieChart ? isPieFixedWidthGrid : LegendType == "FixedWidth";
230
+ var isAxisFixedWidth = !isPieChart && (LegendType == "FixedWidth" || rootLayoutMode === "FixedWidth" || layoutType === "FixedWidth");
229
231
  var isSideLegend = isPieAdaptive && isSidePlacement;
230
232
  var isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
231
233
  var fullWidth = (_ref4 = componentWidth !== null && componentWidth !== void 0 ? componentWidth : chartWidth) !== null && _ref4 !== void 0 ? _ref4 : 0;
@@ -429,6 +431,66 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
429
431
  })));
430
432
  })));
431
433
  }
434
+ if (isAxisFixedWidth) {
435
+ var axisLegendTextWidth = normalizeCssSize(maxWidth);
436
+ var axisGridColumns = Math.min(Math.max(1, Number(gridTemplateColumns) || 1), length);
437
+ return /*#__PURE__*/_react["default"].createElement("div", {
438
+ className: "__easyv-legend-wrapper",
439
+ style: _objectSpread(_objectSpread({
440
+ position: "absolute",
441
+ display: "flex"
442
+ }, getPosition(position, _alignment, x, y)), {}, {
443
+ height: loopHeight,
444
+ overflowY: loop.show ? "scroll" : "auto"
445
+ }),
446
+ ref: ref_container
447
+ }, /*#__PURE__*/_react["default"].createElement("ul", {
448
+ style: {
449
+ display: "grid",
450
+ gridGap: gridRowGap + "px " + gridColumnGap + "px",
451
+ gridTemplateColumns: "repeat(" + axisGridColumns + ", 1fr)"
452
+ }
453
+ }, _series.map(function (series, i) {
454
+ var _series$config3;
455
+ var type = series.type,
456
+ name = series.name,
457
+ displayName = series.displayName,
458
+ fieldName = series.fieldName,
459
+ icon = series.icon,
460
+ selected = series.selected,
461
+ index = series.index;
462
+ var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config3 = series.config) === null || _series$config3 === void 0 || (_series$config3 = _series$config3.line) === null || _series$config3 === void 0 ? void 0 : _series$config3.type);
463
+ return /*#__PURE__*/_react["default"].createElement("li", {
464
+ key: i,
465
+ onClick: onClick(fieldName),
466
+ "data-name": displayName || name,
467
+ "data-index": index,
468
+ style: {
469
+ display: "flex",
470
+ opacity: selected === false ? opacity / 100 : 1,
471
+ alignItems: "center",
472
+ cursor: "pointer",
473
+ gap: _icon.gap
474
+ }
475
+ }, /*#__PURE__*/_react["default"].createElement("span", {
476
+ style: _objectSpread(_objectSpread({}, _icon), {}, {
477
+ flexShrink: 0
478
+ })
479
+ }), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
480
+ type: textOverflow,
481
+ value: displayName || name,
482
+ style: _objectSpread(_objectSpread({}, font), {}, {
483
+ width: axisLegendTextWidth,
484
+ minWidth: axisLegendTextWidth,
485
+ flexShrink: 0,
486
+ boxSizing: "border-box",
487
+ fontStyle: italic ? "italic" : "normal",
488
+ fontWeight: bold ? "bold" : "normal"
489
+ }),
490
+ speed: speed
491
+ }));
492
+ })));
493
+ }
432
494
  return isFixedWidth ? /*#__PURE__*/_react["default"].createElement("div", {
433
495
  className: "__easyv-legend-wrapper",
434
496
  style: _objectSpread(_objectSpread({
@@ -448,7 +510,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
448
510
  gridTemplateColumns: isPieTopBottomFixedMultiCol ? "repeat(".concat(fixedColumnsPerRow, ", max-content)") : "repeat(".concat(fixedColumnsPerRow, ", minmax(0, 1fr))")
449
511
  }
450
512
  }, _series.map(function (series, i) {
451
- var _series$config3;
513
+ var _series$config4;
452
514
  var type = series.type,
453
515
  name = series.name,
454
516
  displayName = series.displayName,
@@ -456,7 +518,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
456
518
  icon = series.icon,
457
519
  selected = series.selected,
458
520
  index = series.index;
459
- var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config3 = series.config) === null || _series$config3 === void 0 || (_series$config3 = _series$config3.line) === null || _series$config3 === void 0 ? void 0 : _series$config3.type);
521
+ var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config4 = series.config) === null || _series$config4 === void 0 || (_series$config4 = _series$config4.line) === null || _series$config4 === void 0 ? void 0 : _series$config4.type);
460
522
  return /*#__PURE__*/_react["default"].createElement("li", {
461
523
  key: i,
462
524
  onClick: onClick(fieldName),
@@ -506,7 +568,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
506
568
  }
507
569
  }, _series.map(function (series, i) {
508
570
  if (Math.floor(i / columnsPerRow) == indexs) {
509
- var _series$config4;
571
+ var _series$config5;
510
572
  var type = series.type,
511
573
  name = series.name,
512
574
  displayName = series.displayName,
@@ -514,7 +576,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
514
576
  icon = series.icon,
515
577
  selected = series.selected,
516
578
  index = series.index;
517
- var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config4 = series.config) === null || _series$config4 === void 0 || (_series$config4 = _series$config4.line) === null || _series$config4 === void 0 ? void 0 : _series$config4.type);
579
+ var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config5 = series.config) === null || _series$config5 === void 0 || (_series$config5 = _series$config5.line) === null || _series$config5 === void 0 ? void 0 : _series$config5.type);
518
580
  return /*#__PURE__*/_react["default"].createElement("li", {
519
581
  key: i,
520
582
  onClick: onClick(fieldName),
@@ -554,7 +616,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
554
616
  gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px")
555
617
  }
556
618
  }, _series.map(function (series, i) {
557
- var _series$config5;
619
+ var _series$config6;
558
620
  var type = series.type,
559
621
  name = series.name,
560
622
  displayName = series.displayName,
@@ -562,7 +624,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
562
624
  icon = series.icon,
563
625
  selected = series.selected,
564
626
  index = series.index;
565
- var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config5 = series.config) === null || _series$config5 === void 0 || (_series$config5 = _series$config5.line) === null || _series$config5 === void 0 ? void 0 : _series$config5.type);
627
+ var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config6 = series.config) === null || _series$config6 === void 0 || (_series$config6 = _series$config6.line) === null || _series$config6 === void 0 ? void 0 : _series$config6.type);
566
628
  return /*#__PURE__*/_react["default"].createElement("li", {
567
629
  key: i,
568
630
  onClick: onClick(fieldName),
@@ -597,6 +659,17 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
597
659
  }));
598
660
  })));
599
661
  });
662
+ var normalizeCssSize = function normalizeCssSize(value) {
663
+ if (value == null || value === "") return value;
664
+ if (typeof value === "number" && Number.isFinite(value)) {
665
+ return "".concat(value, "px");
666
+ }
667
+ var str = String(value).trim();
668
+ if (/^-?\d+(\.\d+)?$/.test(str)) {
669
+ return "".concat(str, "px");
670
+ }
671
+ return str;
672
+ };
600
673
  var getPosition = function getPosition(position, alignment) {
601
674
  var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
602
675
  var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
@@ -27,8 +27,8 @@ var _excluded = ["startAngle", "endAngle", "antiClockwise"],
27
27
  _excluded2 = ["padAngle", "innerRadius", "outerRadius", "cornerRadius", "startAngle", "endAngle"],
28
28
  _excluded3 = ["formatter"],
29
29
  _excluded4 = ["startAngle", "endAngle"];
30
- /**
31
- * 饼环图
30
+ /**
31
+ * 饼环图
32
32
  */
33
33
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
34
34
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
@@ -51,66 +51,6 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
51
51
  height = _ref.height,
52
52
  auto = _ref.auto,
53
53
  manual = _ref.manual;
54
- var getBigScreenScale = function getBigScreenScale() {
55
- // 优先使用全局提供的方法
56
- if (typeof window.getScreenScale === "function") {
57
- try {
58
- var _result = window.getScreenScale();
59
- if (Array.isArray(_result) && _result.length >= 6) {
60
- return _result;
61
- }
62
- } catch (e) {
63
- console.error("调用全局 getScreenScale 出错:", e);
64
- }
65
- }
66
-
67
- // 获取容器元素
68
- var bigscreenDom = document.getElementById("bigscreen-container");
69
-
70
- // 元素不存在时的处理
71
- if (!bigscreenDom) {
72
- return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
73
- }
74
-
75
- // 确保元素可见(未被隐藏)
76
- var isVisible = window.getComputedStyle(bigscreenDom).display !== "none" && window.getComputedStyle(bigscreenDom).visibility !== "hidden";
77
- if (!isVisible) {
78
- return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
79
- }
80
-
81
- // 获取元素的布局矩形(最可靠的尺寸获取方式)
82
- var rect = bigscreenDom.getBoundingClientRect();
83
-
84
- // 提取基础尺寸(从布局矩形获取,不受样式影响)
85
- var screenWidth = rect.width || window.innerWidth;
86
- var screenHeight = rect.height || window.innerHeight;
87
- var screenLeft = rect.left || 0;
88
- var screenTop = rect.top || 0;
89
-
90
- // 处理缩放
91
- var scaleX = 1;
92
- var scaleY = 1;
93
- try {
94
- var computedStyle = window.getComputedStyle(bigscreenDom);
95
- var transform = computedStyle.transform;
96
- if (transform && transform !== "none") {
97
- // 解析 transform matrix
98
- var matrix = new DOMMatrix(transform);
99
- scaleX = matrix.a; // 缩放X因子
100
- scaleY = matrix.d; // 缩放Y因子
101
- }
102
- } catch (e) {
103
- console.error("解析缩放样式出错:", e);
104
- }
105
-
106
- // 最终返回值(确保不会有undefined)
107
- var result = [isNaN(scaleX) ? 1 : scaleX, isNaN(scaleY) ? 1 : scaleY, isNaN(screenWidth) ? window.innerWidth : screenWidth, isNaN(screenHeight) ? window.innerHeight : screenHeight, isNaN(screenLeft) ? 0 : screenLeft, isNaN(screenTop) ? 0 : screenTop];
108
- return result;
109
- };
110
- var _getBigScreenScale = getBigScreenScale(),
111
- _getBigScreenScale2 = (0, _slicedToArray2["default"])(_getBigScreenScale, 2),
112
- scaleX = _getBigScreenScale2[0],
113
- scaleY = _getBigScreenScale2[1];
114
54
  var tooltipRef = (0, _react.useRef)(null);
115
55
  var _useState = (0, _react.useState)({
116
56
  width: 0,
@@ -121,32 +61,29 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
121
61
  setTooltipSize = _useState2[1];
122
62
  var tipPosition = (0, _react.useMemo)(function () {
123
63
  var translate3d = isVertical ? _objectSpread(_objectSpread({}, translateTip), {}, {
124
- y: translateTip.y / scaleY + position + marginTop / scaleY
64
+ y: translateTip.y + position + marginTop
125
65
  }) : _objectSpread(_objectSpread({}, translateTip), {}, {
126
- x: translateTip.x / scaleX + position + marginLeft / scaleX
66
+ x: translateTip.x + position + marginLeft
127
67
  });
128
- if (!isVertical && translate3d.x + tooltipSize.width / scaleX > width / scaleX) {
129
- var newPositon = position + marginLeft / scaleX - tooltipSize.width / scaleX - translateTip.x / scaleX;
130
- translate3d.x = newPositon >= 0 ? newPositon : 0;
131
- console.log("translate3d", translate3d);
132
- console.log("scale", scaleX, scaleY);
133
- console.log("width", width, height);
134
- console.log("position", position, marginLeft, marginTop);
135
- console.log("tooltipSize", tooltipSize);
136
- console.log("translateTip", translateTip);
68
+ if (!isVertical && translate3d.x + tooltipSize.width > width) {
69
+ translate3d.x = position + marginLeft - tooltipSize.width - translateTip.x;
70
+ translate3d.x = translate3d.x >= 0 ? translate3d.x : 0;
71
+ translate3d.x = translate3d.x + tooltipSize.width > width ? width - tooltipSize.width : translate3d.x;
72
+ translate3d.x = translate3d.x >= 0 ? translate3d.x : 0;
137
73
  }
138
- if (isVertical && translate3d.y + tooltipSize.height / scaleY > height / scaleY) {
139
- var _newPositon = position + marginTop / scaleY - tooltipSize.height / scaleY - translateTip.y / scaleY;
140
- translate3d.y = _newPositon <= 0 ? _newPositon : height / scaleY - tooltipSize.height / scaleY;
74
+ if (isVertical && translate3d.y + tooltipSize.height > height) {
75
+ translate3d.y = position + marginTop - tooltipSize.height - translateTip.y;
76
+ translate3d.y = translate3d.y >= 0 ? translate3d.y : 0;
77
+ translate3d.y = translate3d.y + tooltipSize.height > height ? height - tooltipSize.height : translate3d.y;
78
+ translate3d.y = translate3d.y >= 0 ? translate3d.y : 0;
141
79
  }
142
80
  return (0, _utils.getTranslate3d)(translate3d);
143
- }, [width, height, marginLeft, marginTop, position, tooltipSize, translateTip]);
81
+ }, [isVertical, width, height, marginLeft, marginTop, position, tooltipSize, translateTip]);
144
82
  (0, _react.useEffect)(function () {
145
83
  if (tooltipRef.current && (manual || auto)) {
146
- var rect = tooltipRef.current.getBoundingClientRect();
147
84
  setTooltipSize({
148
- width: rect.width,
149
- height: rect.height
85
+ width: tooltipRef.current.offsetWidth,
86
+ height: tooltipRef.current.offsetHeight
150
87
  });
151
88
  }
152
89
  }, [manual, auto, formatter, data, series, x]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.10.32",
3
+ "version": "1.10.34",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -55,4 +55,4 @@
55
55
  "commit": true
56
56
  }
57
57
  }
58
- }
58
+ }
@@ -29,6 +29,7 @@ export default memo(
29
29
  layout: {
30
30
  alignment = "right center",
31
31
  gridTemplateColumns,
32
+ layoutType,
32
33
  gridGap: { gridColumnGap, gridRowGap },
33
34
  translate: { x, y },
34
35
  },
@@ -247,6 +248,11 @@ export default memo(
247
248
  const isFixedWidth = isPieChart
248
249
  ? isPieFixedWidthGrid
249
250
  : LegendType == "FixedWidth";
251
+ const isAxisFixedWidth =
252
+ !isPieChart &&
253
+ (LegendType == "FixedWidth" ||
254
+ rootLayoutMode === "FixedWidth" ||
255
+ layoutType === "FixedWidth");
250
256
  const isSideLegend = isPieAdaptive && isSidePlacement;
251
257
  const isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
252
258
  const fullWidth = componentWidth ?? chartWidth ?? 0;
@@ -507,6 +513,79 @@ export default memo(
507
513
  );
508
514
  }
509
515
 
516
+ if (isAxisFixedWidth) {
517
+ const axisLegendTextWidth = normalizeCssSize(maxWidth);
518
+ const axisGridColumns = Math.min(
519
+ Math.max(1, Number(gridTemplateColumns) || 1),
520
+ length,
521
+ );
522
+ return (
523
+ <div
524
+ className="__easyv-legend-wrapper"
525
+ style={{
526
+ position: "absolute",
527
+ display: "flex",
528
+ ...getPosition(position, _alignment, x, y),
529
+ height: loopHeight,
530
+ overflowY: loop.show ? "scroll" : "auto",
531
+ }}
532
+ ref={ref_container}
533
+ >
534
+ <ul
535
+ style={{
536
+ display: "grid",
537
+ gridGap: gridRowGap + "px " + gridColumnGap + "px",
538
+ gridTemplateColumns: "repeat(" + axisGridColumns + ", 1fr)",
539
+ }}
540
+ >
541
+ {_series.map((series, i) => {
542
+ const {
543
+ type,
544
+ name,
545
+ displayName,
546
+ fieldName,
547
+ icon,
548
+ selected,
549
+ index,
550
+ } = series;
551
+ const _icon = getIcon(type, icon, series?.config?.line?.type);
552
+ return (
553
+ <li
554
+ key={i}
555
+ onClick={onClick(fieldName)}
556
+ data-name={displayName || name}
557
+ data-index={index}
558
+ style={{
559
+ display: "flex",
560
+ opacity: selected === false ? opacity / 100 : 1,
561
+ alignItems: "center",
562
+ cursor: "pointer",
563
+ gap: _icon.gap,
564
+ }}
565
+ >
566
+ <span style={{ ..._icon, flexShrink: 0 }} />
567
+ <TextOverflow
568
+ type={textOverflow}
569
+ value={displayName || name}
570
+ style={{
571
+ ...font,
572
+ width: axisLegendTextWidth,
573
+ minWidth: axisLegendTextWidth,
574
+ flexShrink: 0,
575
+ boxSizing: "border-box",
576
+ fontStyle: italic ? "italic" : "normal",
577
+ fontWeight: bold ? "bold" : "normal",
578
+ }}
579
+ speed={speed}
580
+ />
581
+ </li>
582
+ );
583
+ })}
584
+ </ul>
585
+ </div>
586
+ );
587
+ }
588
+
510
589
  return isFixedWidth ? (
511
590
  <div
512
591
  className="__easyv-legend-wrapper"
@@ -723,6 +802,18 @@ export default memo(
723
802
  },
724
803
  );
725
804
 
805
+ const normalizeCssSize = (value) => {
806
+ if (value == null || value === "") return value;
807
+ if (typeof value === "number" && Number.isFinite(value)) {
808
+ return `${value}px`;
809
+ }
810
+ const str = String(value).trim();
811
+ if (/^-?\d+(\.\d+)?$/.test(str)) {
812
+ return `${str}px`;
813
+ }
814
+ return str;
815
+ };
816
+
726
817
  const getPosition = (position, alignment, x = 0, y = 0) => {
727
818
  switch (position) {
728
819
  case "top":