@easyv/charts 1.8.4 → 1.8.6

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.
@@ -305,6 +305,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
305
305
  });
306
306
  });
307
307
  var prevIndex = (0, _react.useRef)(null);
308
+ var domRef = (0, _react.useRef)();
308
309
  var legendPrecision = legend.config.percent.precision;
309
310
  var _useContext = (0, _react.useContext)(_context.chartContext),
310
311
  id = _useContext.id,
@@ -518,7 +519,9 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
518
519
  hoverData = _useState6[0],
519
520
  setHoverData = _useState6[1];
520
521
  var pieWarpEl = (0, _react.useRef)(null);
521
- return outerDecorate ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
522
+ return outerDecorate ? /*#__PURE__*/_react["default"].createElement("div", {
523
+ ref: domRef
524
+ }, /*#__PURE__*/_react["default"].createElement(_.ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
522
525
  , {
523
526
  width: width,
524
527
  height: height,
@@ -614,7 +617,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
614
617
  x: halfChartWidth,
615
618
  y: maxRadius + marginTop
616
619
  },
617
- mousePos: mousePos
620
+ mousePos: mousePos,
621
+ domRef: domRef.current ? domRef : null
618
622
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
619
623
  height: chartHeight,
620
624
  series: _arcs.map(function (arc) {
@@ -624,7 +628,9 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
624
628
  }),
625
629
  formatter: formatter,
626
630
  judge: judgeData
627
- }))) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
631
+ }))) : /*#__PURE__*/_react["default"].createElement("div", {
632
+ ref: domRef
633
+ }, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
628
634
  width: width,
629
635
  height: height,
630
636
  marginLeft: marginLeft,
@@ -778,7 +784,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
778
784
  x: halfChartWidth,
779
785
  y: maxRadius + marginTop
780
786
  },
781
- mousePos: mousePos
787
+ mousePos: mousePos,
788
+ domRef: domRef.current ? domRef : null
782
789
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
783
790
  height: chartHeight,
784
791
  series: _arcs.map(function (arc) {
@@ -17,6 +17,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
18
  var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (props) {
19
19
  var mousePos = props.mousePos,
20
+ domRef = props.domRef,
20
21
  pieCenter = props.pieCenter,
21
22
  _props$config$tip = props.config.tip,
22
23
  _props$config$tip$dat = _props$config$tip.data,
@@ -42,6 +43,7 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
42
43
  translateTip = _props$config$tip.translate,
43
44
  data = props.data,
44
45
  series = props.series;
46
+ var screenRef = domRef.current.getBoundingClientRect();
45
47
  var Item = function Item() {
46
48
  var _data$data = data.data,
47
49
  s = _data$data.s,
@@ -97,45 +99,84 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
97
99
  centerY = pieCenter.y;
98
100
  var getTipPos = function getTipPos() {
99
101
  var getBigscreenScale = function getBigscreenScale() {
100
- if (window.getScreenScale) {
101
- return window.getScreenScale();
102
- } else {
103
- var bigscreenDom = document.getElementById('bigscreen-container');
104
- if (!bigscreenDom) return [1, 1];
105
- var transform = bigscreenDom.style.transform;
106
- if (!transform) return [1, 1];
107
- var match = transform.match(/scale\(([^)]+)\)/);
108
- if (match) {
109
- var scaleMatch = match[1].split(',');
110
- var _scaleX = scaleMatch[0];
111
- var _scaleY = scaleMatch[1];
112
- if (_scaleY) {
113
- return [Number(_scaleX), Number(_scaleY)];
114
- } else {
115
- return [Number(_scaleX), Number(_scaleX)];
102
+ // 优先使用全局提供的方法
103
+ if (typeof window.getScreenScale === 'function') {
104
+ try {
105
+ var _result = window.getScreenScale();
106
+ if (Array.isArray(_result) && _result.length >= 6) {
107
+ return _result;
116
108
  }
117
- } else {
118
- return [1, 1];
109
+ } catch (e) {
110
+ console.error('调用全局 getScreenScale 出错:', e);
119
111
  }
120
112
  }
113
+
114
+ // 获取容器元素
115
+ var bigscreenDom = document.getElementById('bigscreen-container');
116
+
117
+ // 元素不存在时的处理
118
+ if (!bigscreenDom) {
119
+ console.warn('未找到 bigscreen-container 元素,使用视口尺寸');
120
+ return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
121
+ }
122
+
123
+ // 确保元素可见(未被隐藏)
124
+ var isVisible = window.getComputedStyle(bigscreenDom).display !== 'none' && window.getComputedStyle(bigscreenDom).visibility !== 'hidden';
125
+ if (!isVisible) {
126
+ console.warn('bigscreen-container 元素不可见,使用视口尺寸');
127
+ return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
128
+ }
129
+
130
+ // 获取元素的布局矩形(最可靠的尺寸获取方式)
131
+ var rect = bigscreenDom.getBoundingClientRect();
132
+
133
+ // 提取基础尺寸(从布局矩形获取,不受样式影响)
134
+ var screenWidth = rect.width || window.innerWidth;
135
+ var screenHeight = rect.height || window.innerHeight;
136
+ var screenLeft = rect.left || 0;
137
+ var screenTop = rect.top || 0;
138
+
139
+ // 处理缩放
140
+ var scaleX = 1;
141
+ var scaleY = 1;
142
+ try {
143
+ var computedStyle = window.getComputedStyle(bigscreenDom);
144
+ var transform = computedStyle.transform;
145
+ if (transform && transform !== 'none') {
146
+ // 解析 transform matrix
147
+ var matrix = new DOMMatrix(transform);
148
+ scaleX = matrix.a; // 缩放X因子
149
+ scaleY = matrix.d; // 缩放Y因子
150
+ }
151
+ } catch (e) {
152
+ console.error('解析缩放样式出错:', e);
153
+ }
154
+
155
+ // 最终返回值(确保不会有undefined)
156
+ 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];
157
+ return result;
121
158
  };
122
159
  var _getBigscreenScale = getBigscreenScale(),
123
- _getBigscreenScale2 = (0, _slicedToArray2["default"])(_getBigscreenScale, 2),
160
+ _getBigscreenScale2 = (0, _slicedToArray2["default"])(_getBigscreenScale, 6),
124
161
  scaleX = _getBigscreenScale2[0],
125
- scaleY = _getBigscreenScale2[1];
126
- var _mouseX = mouseX / scaleX;
127
- var _mouseY = mouseY / scaleY;
162
+ scaleY = _getBigscreenScale2[1],
163
+ screenWidth = _getBigscreenScale2[2],
164
+ screenHeight = _getBigscreenScale2[3],
165
+ screenLeft = _getBigscreenScale2[4],
166
+ screenTop = _getBigscreenScale2[5];
167
+ // const _mouseX = mouseX / scaleX
168
+ // const _mouseY = mouseY / scaleY
128
169
  var tipPosMap = {
129
- rightTop: "translate(".concat(_mouseX + translateTip.x, "px,").concat(_mouseY - tipHeight - translateTip.y, "px)"),
130
- leftTop: "translate(".concat(_mouseX - tipWidth - translateTip.x, "px,").concat(_mouseY - tipHeight - translateTip.y, "px)"),
131
- leftBottom: "translate(".concat(_mouseX - tipWidth - translateTip.x, "px,").concat(_mouseY + translateTip.y, "px)"),
132
- rightBottom: "translate(".concat(_mouseX + translateTip.x, "px,").concat(_mouseY + translateTip.y, "px)")
170
+ rightTop: "translate(".concat((screenRef.x + tipWidth) / scaleX + mouseX - screenLeft + translateTip.x > screenWidth ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,\n ").concat((screenRef.y - tipHeight) / scaleY + mouseY - screenTop + translateTip.y < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
171
+ leftTop: "translate(".concat((screenRef.x - tipWidth) / scaleX + mouseX - screenLeft + translateTip.x < 0 ? mouseX + translateTip.x : mouseX - tipWidth - translateTip.x, "px,\n ").concat((screenRef.y - tipHeight) / scaleY + mouseY - screenTop + translateTip.y < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
172
+ leftBottom: "translate(".concat((screenRef.x - tipWidth) / scaleX + mouseX - screenLeft + translateTip.x < 0 ? mouseX + translateTip.x : mouseX - tipWidth - translateTip.x, "px,\n ").concat((screenRef.y + tipHeight) / scaleY + mouseY - screenTop + translateTip.y > screenHeight ? mouseY - tipHeight - translateTip.y : mouseY + translateTip.y, "px)"),
173
+ rightBottom: "translate(".concat((screenRef.x + tipWidth) / scaleX + mouseX - screenLeft + translateTip.x > screenWidth ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,\n ").concat((screenRef.y + tipHeight) / scaleY + mouseY - screenTop + translateTip.y > screenHeight ? mouseY - tipHeight - translateTip.y : mouseY + translateTip.y, "px)")
133
174
  };
134
- if (_mouseX < centerX && _mouseY < centerY) {
175
+ if (mouseX < centerX && mouseY < centerY) {
135
176
  return tipPosMap.leftTop;
136
- } else if (_mouseX > centerX && _mouseY < centerY) {
177
+ } else if (mouseX > centerX && mouseY < centerY) {
137
178
  return tipPosMap.rightTop;
138
- } else if (_mouseX >= centerX && _mouseY >= centerY) {
179
+ } else if (mouseX >= centerX && mouseY >= centerY) {
139
180
  return tipPosMap.rightBottom;
140
181
  } else {
141
182
  return tipPosMap.leftBottom;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -292,6 +292,7 @@ const Component = memo(
292
292
  }) => {
293
293
  const data = originData.map((d) => ({ ...d, y: d.y < 0 ? 0 : d.y }));
294
294
  const prevIndex = useRef(null);
295
+ const domRef=useRef()
295
296
  const { precision: legendPrecision } = legend.config.percent;
296
297
  const {
297
298
  id,
@@ -513,7 +514,7 @@ const Component = memo(
513
514
  const [hoverData, setHoverData] = useState(null);
514
515
  const pieWarpEl = useRef(null);
515
516
  return outerDecorate ? (
516
- <>
517
+ <div ref={domRef}>
517
518
  <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
518
519
  width={width}
519
520
  height={height}
@@ -635,6 +636,7 @@ const Component = memo(
635
636
  y: maxRadius + marginTop,
636
637
  }}
637
638
  mousePos={mousePos}
639
+ domRef={domRef.current ? domRef : null}
638
640
  />
639
641
  </div>
640
642
  )}
@@ -648,9 +650,9 @@ const Component = memo(
648
650
  formatter={formatter}
649
651
  judge={judgeData}
650
652
  />
651
- </>
653
+ </div>
652
654
  ) : (
653
- <>
655
+ <div ref={domRef}>
654
656
  <ChartContainer
655
657
  width={width}
656
658
  height={height}
@@ -896,6 +898,7 @@ const Component = memo(
896
898
  y: maxRadius + marginTop,
897
899
  }}
898
900
  mousePos={mousePos}
901
+ domRef={domRef.current ? domRef : null}
899
902
  />
900
903
  </div>
901
904
  )}
@@ -909,7 +912,7 @@ const Component = memo(
909
912
  formatter={formatter}
910
913
  judge={judgeData}
911
914
  />
912
- </>
915
+ </div>
913
916
  );
914
917
  }
915
918
  );
@@ -3,7 +3,7 @@ import { getFontStyle, getMargin, getTranslate3d, getTranslate2d, getIcon } from
3
3
 
4
4
 
5
5
  export const PieTooltip = memo((props) => {
6
- const { mousePos,
6
+ const { mousePos,domRef,
7
7
  pieCenter,
8
8
  config: {
9
9
  tip: {
@@ -19,7 +19,7 @@ export const PieTooltip = memo((props) => {
19
19
  },
20
20
  data,
21
21
  series } = props
22
-
22
+ const screenRef = domRef.current.getBoundingClientRect();
23
23
  const Item = () => {
24
24
  const { data: { s, y }, percent } = data
25
25
  const { type, icon, displayName } = [...series.values()].find(
@@ -87,43 +87,93 @@ export const PieTooltip = memo((props) => {
87
87
  const { x: centerX, y: centerY } = pieCenter
88
88
  const getTipPos = () => {
89
89
 
90
- const getBigscreenScale = () => {
91
- if (window.getScreenScale) {
92
- return window.getScreenScale()
93
- } else {
94
- const bigscreenDom = document.getElementById('bigscreen-container')
95
- if (!bigscreenDom) return [1, 1]
96
- const transform = bigscreenDom.style.transform
97
- if (!transform) return [1, 1]
98
- let match = transform.match(/scale\(([^)]+)\)/)
99
- if (match) {
100
- const scaleMatch = match[1].split(',')
101
- let scaleX = scaleMatch[0];
102
- let scaleY = scaleMatch[1];
103
- if (scaleY) {
104
- return [Number(scaleX), Number(scaleY)]
105
- } else {
106
- return [Number(scaleX), Number(scaleX)]
107
- }
108
- } else {
109
- return [1, 1]
110
- }
111
- }
112
- }
113
- const [scaleX, scaleY] = getBigscreenScale()
114
- const _mouseX = mouseX / scaleX
115
- const _mouseY = mouseY / scaleY
90
+ const getBigscreenScale = () => {
91
+ // 优先使用全局提供的方法
92
+ if (typeof window.getScreenScale === 'function') {
93
+ try {
94
+ const result = window.getScreenScale();
95
+ if (Array.isArray(result) && result.length >= 6) {
96
+ return result;
97
+ }
98
+ } catch (e) {
99
+ console.error('调用全局 getScreenScale 出错:', e);
100
+ }
101
+ }
102
+
103
+ // 获取容器元素
104
+ const bigscreenDom = document.getElementById('bigscreen-container');
105
+
106
+ // 元素不存在时的处理
107
+ if (!bigscreenDom) {
108
+ console.warn('未找到 bigscreen-container 元素,使用视口尺寸');
109
+ return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
110
+ }
111
+
112
+ // 确保元素可见(未被隐藏)
113
+ const isVisible = window.getComputedStyle(bigscreenDom).display !== 'none'
114
+ && window.getComputedStyle(bigscreenDom).visibility !== 'hidden';
115
+ if (!isVisible) {
116
+ console.warn('bigscreen-container 元素不可见,使用视口尺寸');
117
+ return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
118
+ }
119
+
120
+ // 获取元素的布局矩形(最可靠的尺寸获取方式)
121
+ const rect = bigscreenDom.getBoundingClientRect();
122
+
123
+ // 提取基础尺寸(从布局矩形获取,不受样式影响)
124
+ const screenWidth = rect.width || window.innerWidth;
125
+ const screenHeight = rect.height || window.innerHeight;
126
+ const screenLeft = rect.left || 0;
127
+ const screenTop = rect.top || 0;
128
+
129
+ // 处理缩放
130
+ let scaleX = 1;
131
+ let scaleY = 1;
132
+
133
+ try {
134
+ const computedStyle = window.getComputedStyle(bigscreenDom);
135
+ const transform = computedStyle.transform;
136
+
137
+ if (transform && transform !== 'none') {
138
+ // 解析 transform matrix
139
+ const matrix = new DOMMatrix(transform);
140
+ scaleX = matrix.a; // 缩放X因子
141
+ scaleY = matrix.d; // 缩放Y因子
142
+ }
143
+ } catch (e) {
144
+ console.error('解析缩放样式出错:', e);
145
+ }
146
+
147
+ // 最终返回值(确保不会有undefined)
148
+ const result = [
149
+ isNaN(scaleX) ? 1 : scaleX,
150
+ isNaN(scaleY) ? 1 : scaleY,
151
+ isNaN(screenWidth) ? window.innerWidth : screenWidth,
152
+ isNaN(screenHeight) ? window.innerHeight : screenHeight,
153
+ isNaN(screenLeft) ? 0 : screenLeft,
154
+ isNaN(screenTop) ? 0 : screenTop
155
+ ];
156
+ return result;
157
+ };
158
+
159
+ const [scaleX, scaleY,screenWidth,screenHeight,screenLeft,screenTop] = getBigscreenScale()
160
+ // const _mouseX = mouseX / scaleX
161
+ // const _mouseY = mouseY / scaleY
116
162
  const tipPosMap = {
117
- rightTop: `translate(${_mouseX + translateTip.x}px,${_mouseY - tipHeight - translateTip.y}px)`,
118
- leftTop: `translate(${_mouseX - tipWidth - translateTip.x}px,${_mouseY - tipHeight - translateTip.y}px)`,
119
- leftBottom: `translate(${_mouseX - tipWidth - translateTip.x}px,${_mouseY + translateTip.y}px)`,
120
- rightBottom: `translate(${_mouseX + translateTip.x}px,${(_mouseY + translateTip.y)}px)`,
121
- }
122
- if (_mouseX < centerX && _mouseY < centerY) {
163
+ rightTop: `translate(${(screenRef.x+tipWidth)/scaleX+mouseX-screenLeft+translateTip.x>screenWidth?mouseX -tipWidth- translateTip.x: mouseX + translateTip.x}px,
164
+ ${(screenRef.y-tipHeight)/scaleY+mouseY-screenTop+translateTip.y<0?mouseY + translateTip.y: mouseY - tipHeight - translateTip.y}px)`,
165
+ leftTop: `translate(${(screenRef.x-tipWidth)/scaleX+mouseX-screenLeft+translateTip.x<0?mouseX+translateTip.x: mouseX - tipWidth - translateTip.x}px,
166
+ ${(screenRef.y-tipHeight)/scaleY+mouseY-screenTop+translateTip.y<0?mouseY + translateTip.y: mouseY - tipHeight - translateTip.y}px)`,
167
+ leftBottom: `translate(${(screenRef.x-tipWidth)/scaleX+mouseX-screenLeft+translateTip.x<0?mouseX+translateTip.x: mouseX - tipWidth - translateTip.x}px,
168
+ ${(screenRef.y+tipHeight)/scaleY+mouseY-screenTop+translateTip.y>screenHeight? mouseY- tipHeight- translateTip.y: mouseY + translateTip.y}px)`,
169
+ rightBottom: `translate(${(screenRef.x+tipWidth)/scaleX+mouseX-screenLeft+translateTip.x>screenWidth?mouseX -tipWidth- translateTip.x:mouseX + translateTip.x}px,
170
+ ${(screenRef.y+tipHeight)/scaleY+mouseY-screenTop+translateTip.y>screenHeight? mouseY- tipHeight- translateTip.y: mouseY + translateTip.y}px)`,
171
+ }
172
+ if (mouseX < centerX && mouseY < centerY) {
123
173
  return tipPosMap.leftTop
124
- } else if (_mouseX > centerX && _mouseY < centerY) {
174
+ } else if (mouseX > centerX && mouseY < centerY) {
125
175
  return tipPosMap.rightTop
126
- } else if (_mouseX >= centerX && _mouseY >= centerY) {
176
+ } else if (mouseX >= centerX && mouseY >= centerY) {
127
177
  return tipPosMap.rightBottom
128
178
  } else {
129
179
  return tipPosMap.leftBottom