@easyv/charts 1.8.5 → 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,10 +232,9 @@ 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
- left = _ref5.left,
238
- top = _ref5.top,
239
238
  _ref5$config = _ref5.config,
240
239
  _ref5$config$chart = _ref5$config.chart,
241
240
  label = _ref5$config$chart.label,
@@ -301,12 +300,6 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
301
300
  hoverEvent = _ref5.hoverEvent,
302
301
  _ref5$data = _ref5.data,
303
302
  originData = _ref5$data === void 0 ? [] : _ref5$data;
304
- var attribute = {
305
- width: width,
306
- height: height,
307
- top: top,
308
- left: left
309
- };
310
303
  var data = originData.map(function (d) {
311
304
  return _objectSpread(_objectSpread({}, d), {}, {
312
305
  y: d.y < 0 ? 0 : d.y
@@ -622,8 +615,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
622
615
  x: halfChartWidth,
623
616
  y: maxRadius + marginTop
624
617
  },
625
- attribute: attribute,
626
- mousePos: mousePos
618
+ mousePos: mousePos,
619
+ domRef: domRef
627
620
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
628
621
  height: chartHeight,
629
622
  series: _arcs.map(function (arc) {
@@ -788,7 +781,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
788
781
  y: maxRadius + marginTop
789
782
  },
790
783
  mousePos: mousePos,
791
- attribute: attribute
784
+ domRef: domRef
792
785
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
793
786
  height: chartHeight,
794
787
  series: _arcs.map(function (arc) {
@@ -17,7 +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
- attribute = props.attribute,
20
+ domRef = props.domRef,
21
21
  pieCenter = props.pieCenter,
22
22
  _props$config$tip = props.config.tip,
23
23
  _props$config$tip$dat = _props$config$tip.data,
@@ -43,6 +43,7 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
43
43
  translateTip = _props$config$tip.translate,
44
44
  data = props.data,
45
45
  series = props.series;
46
+ var screenRef = domRef.current.getBoundingClientRect();
46
47
  var Item = function Item() {
47
48
  var _data$data = data.data,
48
49
  s = _data$data.s,
@@ -166,10 +167,10 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
166
167
  // const _mouseX = mouseX / scaleX
167
168
  // const _mouseY = mouseY / scaleY
168
169
  var tipPosMap = {
169
- rightTop: "translate(".concat((attribute.left + tipWidth) / scaleX + mouseX - screenLeft + translateTip.x > screenWidth ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,\n\t\t\t").concat((attribute.top - tipHeight) / scaleY + mouseY - screenTop + translateTip.y < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
170
- leftTop: "translate(".concat((attribute.left - tipWidth) / scaleX + mouseX - screenLeft + translateTip.x < 0 ? mouseX + translateTip.x : mouseX - tipWidth - translateTip.x, "px,\n\t\t\t").concat((attribute.top - tipHeight) / scaleY + mouseY - screenTop + translateTip.y < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
171
- leftBottom: "translate(".concat((attribute.left - tipWidth) / scaleX + mouseX - screenLeft + translateTip.x < 0 ? mouseX + translateTip.x : mouseX - tipWidth - translateTip.x, "px,\n\t\t\t").concat((attribute.top + tipHeight) / scaleY + mouseY - screenTop + translateTip.y > screenHeight ? mouseY - tipHeight - translateTip.y : mouseY + translateTip.y, "px)"),
172
- rightBottom: "translate(".concat((attribute.left + tipWidth) / scaleX + mouseX - screenLeft + translateTip.x > screenWidth ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,\n\t\t\t").concat((attribute.top + tipHeight) / scaleY + mouseY - screenTop + translateTip.y > screenHeight ? mouseY - tipHeight - translateTip.y : 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)")
173
174
  };
174
175
  if (mouseX < centerX && mouseY < centerY) {
175
176
  return tipPosMap.leftTop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.5",
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,10 +247,9 @@ 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
- left,
253
- top,
254
253
  config: {
255
254
  chart: {
256
255
  label,
@@ -292,7 +291,6 @@ const Component = memo(
292
291
  hoverEvent,
293
292
  data: originData = [],
294
293
  }) => {
295
- const attribute={width,height,top,left}
296
294
  const data = originData.map((d) => ({ ...d, y: d.y < 0 ? 0 : d.y }));
297
295
  const prevIndex = useRef(null);
298
296
  const { precision: legendPrecision } = legend.config.percent;
@@ -637,8 +635,8 @@ const Component = memo(
637
635
  x: halfChartWidth,
638
636
  y: maxRadius + marginTop,
639
637
  }}
640
- attribute={attribute}
641
638
  mousePos={mousePos}
639
+ domRef={domRef}
642
640
  />
643
641
  </div>
644
642
  )}
@@ -900,7 +898,7 @@ const Component = memo(
900
898
  y: maxRadius + marginTop,
901
899
  }}
902
900
  mousePos={mousePos}
903
- attribute={attribute}
901
+ domRef={domRef}
904
902
  />
905
903
  </div>
906
904
  )}
@@ -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,attribute,
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,92 +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
- }
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
+ };
146
158
 
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()
159
- // const _mouseX = mouseX / scaleX
160
- // const _mouseY = mouseY / scaleY
160
+ const _mouseX = mouseX / scaleX
161
+ const _mouseY = mouseY / scaleY
161
162
  const tipPosMap = {
162
- rightTop: `translate(${(attribute.left+tipWidth)/scaleX+mouseX-screenLeft+translateTip.x>screenWidth?mouseX -tipWidth- translateTip.x: mouseX + translateTip.x}px,
163
- ${(attribute.top-tipHeight)/scaleY+mouseY-screenTop+translateTip.y<0?mouseY + translateTip.y: mouseY - tipHeight - translateTip.y}px)`,
164
- leftTop: `translate(${(attribute.left-tipWidth)/scaleX+mouseX-screenLeft+translateTip.x<0?mouseX+translateTip.x: mouseX - tipWidth - translateTip.x}px,
165
- ${(attribute.top-tipHeight)/scaleY+mouseY-screenTop+translateTip.y<0?mouseY + translateTip.y: mouseY - tipHeight - translateTip.y}px)`,
166
- leftBottom: `translate(${(attribute.left-tipWidth)/scaleX+mouseX-screenLeft+translateTip.x<0?mouseX+translateTip.x: mouseX - tipWidth - translateTip.x}px,
167
- ${(attribute.top+tipHeight)/scaleY+mouseY-screenTop+translateTip.y>screenHeight? mouseY- tipHeight- translateTip.y: mouseY + translateTip.y}px)`,
168
- rightBottom: `translate(${(attribute.left+tipWidth)/scaleX+mouseX-screenLeft+translateTip.x>screenWidth?mouseX -tipWidth- translateTip.x:mouseX + translateTip.x}px,
169
- ${(attribute.top+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)`,
170
171
  }
171
- if (mouseX < centerX && mouseY < centerY) {
172
+ if (_mouseX < centerX && _mouseY < centerY) {
172
173
  return tipPosMap.leftTop
173
- } else if (mouseX > centerX && mouseY < centerY) {
174
+ } else if (_mouseX > centerX && _mouseY < centerY) {
174
175
  return tipPosMap.rightTop
175
- } else if (mouseX >= centerX && mouseY >= centerY) {
176
+ } else if (_mouseX >= centerX && _mouseY >= centerY) {
176
177
  return tipPosMap.rightBottom
177
178
  } else {
178
179
  return tipPosMap.leftBottom