@easyv/charts 1.8.6 → 1.8.7

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.
@@ -64,6 +64,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
64
64
  active = _useState2[0],
65
65
  setActive = _useState2[1];
66
66
  var scaleRef = (0, _react.useRef)([1, 1]);
67
+ var domRef = (0, _react.useRef)();
67
68
  var triggerOnRelative = (0, _react.useCallback)(function (action, data) {
68
69
  if (!interaction) return;
69
70
  var callbacks = interaction.callbacks,
@@ -121,12 +122,16 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
121
122
  var data = checkData(originData);
122
123
  return /*#__PURE__*/_react["default"].createElement(_context.chartContext.Provider, {
123
124
  value: context
124
- }, type == 'pie' ? /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
125
+ }, type == 'pie' ? /*#__PURE__*/_react["default"].createElement("div", {
126
+ ref: domRef
127
+ }, /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
125
128
  id: id,
126
129
  config: config,
127
130
  data: data,
128
131
  active: active
129
- }, props)) : /*#__PURE__*/_react["default"].createElement(_.CartesianChart, (0, _extends2["default"])({
132
+ }, props, {
133
+ domRef: domRef
134
+ }))) : /*#__PURE__*/_react["default"].createElement(_.CartesianChart, (0, _extends2["default"])({
130
135
  id: id,
131
136
  config: config,
132
137
  data: data,
@@ -232,7 +232,8 @@ var getCircleScale = function getCircleScale() {
232
232
  }));
233
233
  };
234
234
  var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
235
- var width = _ref5.width,
235
+ var domRef = _ref5.domRef,
236
+ width = _ref5.width,
236
237
  height = _ref5.height,
237
238
  _ref5$config = _ref5.config,
238
239
  _ref5$config$chart = _ref5$config.chart,
@@ -305,7 +306,6 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
305
306
  });
306
307
  });
307
308
  var prevIndex = (0, _react.useRef)(null);
308
- var domRef = (0, _react.useRef)();
309
309
  var legendPrecision = legend.config.percent.precision;
310
310
  var _useContext = (0, _react.useContext)(_context.chartContext),
311
311
  id = _useContext.id,
@@ -519,9 +519,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
519
519
  hoverData = _useState6[0],
520
520
  setHoverData = _useState6[1];
521
521
  var pieWarpEl = (0, _react.useRef)(null);
522
- return outerDecorate ? /*#__PURE__*/_react["default"].createElement("div", {
523
- ref: domRef
524
- }, /*#__PURE__*/_react["default"].createElement(_.ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
522
+ return outerDecorate ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
525
523
  , {
526
524
  width: width,
527
525
  height: height,
@@ -618,7 +616,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
618
616
  y: maxRadius + marginTop
619
617
  },
620
618
  mousePos: mousePos,
621
- domRef: domRef.current ? domRef : null
619
+ domRef: domRef
622
620
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
623
621
  height: chartHeight,
624
622
  series: _arcs.map(function (arc) {
@@ -628,9 +626,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
628
626
  }),
629
627
  formatter: formatter,
630
628
  judge: judgeData
631
- }))) : /*#__PURE__*/_react["default"].createElement("div", {
632
- ref: domRef
633
- }, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
629
+ }))) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
634
630
  width: width,
635
631
  height: height,
636
632
  marginLeft: marginLeft,
@@ -785,7 +781,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
785
781
  y: maxRadius + marginTop
786
782
  },
787
783
  mousePos: mousePos,
788
- domRef: domRef.current ? domRef : null
784
+ domRef: domRef
789
785
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
790
786
  height: chartHeight,
791
787
  series: _arcs.map(function (arc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -47,6 +47,7 @@ const Chart = memo(
47
47
  const chartHeight = height - marginTop - marginBottom;
48
48
  const [active, setActive] = useState(true);
49
49
  const scaleRef = useRef([1,1]);
50
+ const domRef=useRef()
50
51
  const triggerOnRelative = useCallback(
51
52
  (action,data) => {
52
53
  if (!interaction) return;
@@ -115,7 +116,7 @@ const Chart = memo(
115
116
  return (
116
117
  <chartContext.Provider value={context}>
117
118
  {type == 'pie' ? (
118
- <PieChart id={id} config={config} data={data} active={active} {...props} />
119
+ <div ref={domRef}><PieChart id={id} config={config} data={data} active={active} {...props} domRef={domRef} /></div>
119
120
  ) : (
120
121
  <CartesianChart id={id} config={config} data={data} active={active} {...props} />
121
122
  )}
@@ -247,6 +247,7 @@ const getCircleScale = ({ count, color, width, length } = tick, radius) => {
247
247
 
248
248
  const Component = memo(
249
249
  ({
250
+ domRef,
250
251
  width,
251
252
  height,
252
253
  config: {
@@ -292,7 +293,6 @@ const Component = memo(
292
293
  }) => {
293
294
  const data = originData.map((d) => ({ ...d, y: d.y < 0 ? 0 : d.y }));
294
295
  const prevIndex = useRef(null);
295
- const domRef=useRef()
296
296
  const { precision: legendPrecision } = legend.config.percent;
297
297
  const {
298
298
  id,
@@ -514,7 +514,7 @@ const Component = memo(
514
514
  const [hoverData, setHoverData] = useState(null);
515
515
  const pieWarpEl = useRef(null);
516
516
  return outerDecorate ? (
517
- <div ref={domRef}>
517
+ <>
518
518
  <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
519
519
  width={width}
520
520
  height={height}
@@ -636,7 +636,7 @@ const Component = memo(
636
636
  y: maxRadius + marginTop,
637
637
  }}
638
638
  mousePos={mousePos}
639
- domRef={domRef.current ? domRef : null}
639
+ domRef={domRef}
640
640
  />
641
641
  </div>
642
642
  )}
@@ -650,9 +650,9 @@ const Component = memo(
650
650
  formatter={formatter}
651
651
  judge={judgeData}
652
652
  />
653
- </div>
653
+ </>
654
654
  ) : (
655
- <div ref={domRef}>
655
+ <>
656
656
  <ChartContainer
657
657
  width={width}
658
658
  height={height}
@@ -898,7 +898,7 @@ const Component = memo(
898
898
  y: maxRadius + marginTop,
899
899
  }}
900
900
  mousePos={mousePos}
901
- domRef={domRef.current ? domRef : null}
901
+ domRef={domRef}
902
902
  />
903
903
  </div>
904
904
  )}
@@ -912,7 +912,7 @@ const Component = memo(
912
912
  formatter={formatter}
913
913
  judge={judgeData}
914
914
  />
915
- </div>
915
+ </>
916
916
  );
917
917
  }
918
918
  );
@@ -87,93 +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
- // 优先使用全局提供的方法
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
- };
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
158
 
159
159
  const [scaleX, scaleY,screenWidth,screenHeight,screenLeft,screenTop] = getBigscreenScale()
160
- // const _mouseX = mouseX / scaleX
161
- // const _mouseY = mouseY / scaleY
160
+ const _mouseX = mouseX / scaleX
161
+ const _mouseY = mouseY / scaleY
162
162
  const tipPosMap = {
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)`,
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
171
  }
172
- if (mouseX < centerX && mouseY < centerY) {
172
+ if (_mouseX < centerX && _mouseY < centerY) {
173
173
  return tipPosMap.leftTop
174
- } else if (mouseX > centerX && mouseY < centerY) {
174
+ } else if (_mouseX > centerX && _mouseY < centerY) {
175
175
  return tipPosMap.rightTop
176
- } else if (mouseX >= centerX && mouseY >= centerY) {
176
+ } else if (_mouseX >= centerX && _mouseY >= centerY) {
177
177
  return tipPosMap.rightBottom
178
178
  } else {
179
179
  return tipPosMap.leftBottom