@easyv/charts 1.10.30 → 1.10.32

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.
@@ -44,6 +44,74 @@ 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();
47
115
  const tooltipRef = useRef(null);
48
116
  const [tooltipSize, setTooltipSize] = useState({
49
117
  width: 0,
@@ -53,22 +121,43 @@ export default memo(
53
121
  const translate3d = isVertical
54
122
  ? {
55
123
  ...translateTip,
56
- y: translateTip.y + position + marginTop,
124
+ y: translateTip.y / scaleY + position + marginTop / scaleY,
57
125
  }
58
126
  : {
59
127
  ...translateTip,
60
- x: translateTip.x + position + marginLeft,
128
+ x: translateTip.x / scaleX + position + marginLeft / scaleX,
61
129
  };
62
- if (!isVertical && translate3d.x + tooltipSize.width > width) {
130
+
131
+ if (
132
+ !isVertical &&
133
+ translate3d.x + tooltipSize.width / scaleX > width / scaleX
134
+ ) {
63
135
  const newPositon =
64
- position + marginLeft - tooltipSize.width - translateTip.x;
136
+ position +
137
+ marginLeft / scaleX -
138
+ tooltipSize.width / scaleX -
139
+ translateTip.x / scaleX;
65
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);
66
147
  }
67
- if (isVertical && translate3d.y + tooltipSize.height > height) {
148
+ if (
149
+ isVertical &&
150
+ translate3d.y + tooltipSize.height / scaleY > height / scaleY
151
+ ) {
68
152
  const newPositon =
69
- position + marginTop - tooltipSize.height - translateTip.y;
153
+ position +
154
+ marginTop / scaleY -
155
+ tooltipSize.height / scaleY -
156
+ translateTip.y / scaleY;
70
157
  translate3d.y =
71
- newPositon <= 0 ? newPositon : height - tooltipSize.height;
158
+ newPositon <= 0
159
+ ? newPositon
160
+ : height / scaleY - tooltipSize.height / scaleY;
72
161
  }
73
162
  return getTranslate3d(translate3d);
74
163
  }, [