@easyv/charts 1.10.32 → 1.10.33

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.
@@ -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.33",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -44,74 +44,6 @@ export default memo(
44
44
  auto,
45
45
  manual,
46
46
  }) => {
47
- const getBigScreenScale = () => {
48
- // 优先使用全局提供的方法
49
- if (typeof window.getScreenScale === "function") {
50
- try {
51
- const result = window.getScreenScale();
52
- if (Array.isArray(result) && result.length >= 6) {
53
- return result;
54
- }
55
- } catch (e) {
56
- console.error("调用全局 getScreenScale 出错:", e);
57
- }
58
- }
59
-
60
- // 获取容器元素
61
- const bigscreenDom = document.getElementById("bigscreen-container");
62
-
63
- // 元素不存在时的处理
64
- if (!bigscreenDom) {
65
- return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
66
- }
67
-
68
- // 确保元素可见(未被隐藏)
69
- const isVisible =
70
- window.getComputedStyle(bigscreenDom).display !== "none" &&
71
- window.getComputedStyle(bigscreenDom).visibility !== "hidden";
72
- if (!isVisible) {
73
- return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
74
- }
75
-
76
- // 获取元素的布局矩形(最可靠的尺寸获取方式)
77
- const rect = bigscreenDom.getBoundingClientRect();
78
-
79
- // 提取基础尺寸(从布局矩形获取,不受样式影响)
80
- const screenWidth = rect.width || window.innerWidth;
81
- const screenHeight = rect.height || window.innerHeight;
82
- const screenLeft = rect.left || 0;
83
- const screenTop = rect.top || 0;
84
-
85
- // 处理缩放
86
- let scaleX = 1;
87
- let scaleY = 1;
88
-
89
- try {
90
- const computedStyle = window.getComputedStyle(bigscreenDom);
91
- const transform = computedStyle.transform;
92
-
93
- if (transform && transform !== "none") {
94
- // 解析 transform matrix
95
- const matrix = new DOMMatrix(transform);
96
- scaleX = matrix.a; // 缩放X因子
97
- scaleY = matrix.d; // 缩放Y因子
98
- }
99
- } catch (e) {
100
- console.error("解析缩放样式出错:", e);
101
- }
102
-
103
- // 最终返回值(确保不会有undefined)
104
- const result = [
105
- isNaN(scaleX) ? 1 : scaleX,
106
- isNaN(scaleY) ? 1 : scaleY,
107
- isNaN(screenWidth) ? window.innerWidth : screenWidth,
108
- isNaN(screenHeight) ? window.innerHeight : screenHeight,
109
- isNaN(screenLeft) ? 0 : screenLeft,
110
- isNaN(screenTop) ? 0 : screenTop,
111
- ];
112
- return result;
113
- };
114
- const [scaleX, scaleY] = getBigScreenScale();
115
47
  const tooltipRef = useRef(null);
116
48
  const [tooltipSize, setTooltipSize] = useState({
117
49
  width: 0,
@@ -121,46 +53,35 @@ export default memo(
121
53
  const translate3d = isVertical
122
54
  ? {
123
55
  ...translateTip,
124
- y: translateTip.y / scaleY + position + marginTop / scaleY,
56
+ y: translateTip.y + position + marginTop,
125
57
  }
126
58
  : {
127
59
  ...translateTip,
128
- x: translateTip.x / scaleX + position + marginLeft / scaleX,
60
+ x: translateTip.x + position + marginLeft,
129
61
  };
130
-
131
- if (
132
- !isVertical &&
133
- translate3d.x + tooltipSize.width / scaleX > width / scaleX
134
- ) {
135
- const newPositon =
136
- position +
137
- marginLeft / scaleX -
138
- tooltipSize.width / scaleX -
139
- translateTip.x / scaleX;
140
- translate3d.x = newPositon >= 0 ? newPositon : 0;
141
- console.log("translate3d", translate3d);
142
- console.log("scale", scaleX, scaleY);
143
- console.log("width", width, height);
144
- console.log("position", position, marginLeft, marginTop);
145
- console.log("tooltipSize", tooltipSize);
146
- console.log("translateTip", translateTip);
62
+ if (!isVertical && translate3d.x + tooltipSize.width > width) {
63
+ translate3d.x =
64
+ position + marginLeft - tooltipSize.width - translateTip.x;
65
+ translate3d.x = translate3d.x >= 0 ? translate3d.x : 0;
66
+ translate3d.x =
67
+ translate3d.x + tooltipSize.width > width
68
+ ? width - tooltipSize.width
69
+ : translate3d.x;
70
+ translate3d.x = translate3d.x >= 0 ? translate3d.x : 0;
147
71
  }
148
- if (
149
- isVertical &&
150
- translate3d.y + tooltipSize.height / scaleY > height / scaleY
151
- ) {
152
- const newPositon =
153
- position +
154
- marginTop / scaleY -
155
- tooltipSize.height / scaleY -
156
- translateTip.y / scaleY;
72
+ if (isVertical && translate3d.y + tooltipSize.height > height) {
73
+ translate3d.y =
74
+ position + marginTop - tooltipSize.height - translateTip.y;
75
+ translate3d.y = translate3d.y >= 0 ? translate3d.y : 0;
157
76
  translate3d.y =
158
- newPositon <= 0
159
- ? newPositon
160
- : height / scaleY - tooltipSize.height / scaleY;
77
+ translate3d.y + tooltipSize.height > height
78
+ ? height - tooltipSize.height
79
+ : translate3d.y;
80
+ translate3d.y = translate3d.y >= 0 ? translate3d.y : 0;
161
81
  }
162
82
  return getTranslate3d(translate3d);
163
83
  }, [
84
+ isVertical,
164
85
  width,
165
86
  height,
166
87
  marginLeft,
@@ -171,10 +92,9 @@ export default memo(
171
92
  ]);
172
93
  useEffect(() => {
173
94
  if (tooltipRef.current && (manual || auto)) {
174
- const rect = tooltipRef.current.getBoundingClientRect();
175
95
  setTooltipSize({
176
- width: rect.width,
177
- height: rect.height,
96
+ width: tooltipRef.current.offsetWidth,
97
+ height: tooltipRef.current.offsetHeight,
178
98
  });
179
99
  }
180
100
  }, [manual, auto, formatter, data, series, x]);