@easyv/charts 1.9.25 → 1.9.27

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.
@@ -248,7 +248,7 @@ var Label = function Label(_ref5) {
248
248
  showType: config.showType
249
249
  }
250
250
  }));
251
- var _getLayout = getLayout(orientation, rotate),
251
+ var _getLayout = getLayout(orientation, adaptive ? 0 : rotate),
252
252
  transform = _getLayout.transform,
253
253
  directionX = _getLayout.directionX,
254
254
  directionY = _getLayout.directionY;
@@ -293,10 +293,9 @@ var Label = function Label(_ref5) {
293
293
  }
294
294
  }) : /*#__PURE__*/_react["default"].createElement("span", {
295
295
  style: {
296
- width: LabelWidth,
296
+ display: "inline-block",
297
297
  transform: transform,
298
- justifyContent: "flex-start",
299
- display: "block",
298
+ position: "absolute",
300
299
  top: translateY,
301
300
  left: translateX
302
301
  }
@@ -43,7 +43,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
43
43
  onMouseMove: onMouseMove,
44
44
  ref: ref,
45
45
  style: _objectSpread({
46
- overflow: "hidden",
46
+ overflow: "visible",
47
47
  position: "absolute",
48
48
  width: width,
49
49
  height: height
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
10
  var _react = require("react");
10
11
  var _utils = require("../utils");
11
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -41,9 +42,6 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
41
42
  bgColor = _ref$config$tip.bgColor,
42
43
  image = _ref$config$tip.image,
43
44
  margin = _ref$config$tip.margin,
44
- _ref$config$tip$size = _ref$config$tip.size,
45
- tipWidth = _ref$config$tip$size.width,
46
- tipHeight = _ref$config$tip$size.height,
47
45
  translateTip = _ref$config$tip.translate,
48
46
  formatter = _ref.formatter,
49
47
  isVertical = _ref.isVertical,
@@ -51,32 +49,57 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
51
49
  height = _ref.height,
52
50
  auto = _ref.auto,
53
51
  manual = _ref.manual;
52
+ var tooltipRef = (0, _react.useRef)(null);
53
+ var _useState = (0, _react.useState)({
54
+ width: 0,
55
+ height: 0
56
+ }),
57
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
58
+ tooltipSize = _useState2[0],
59
+ setTooltipSize = _useState2[1];
54
60
  var tipPosition = (0, _react.useMemo)(function () {
55
61
  var translate3d = isVertical ? _objectSpread(_objectSpread({}, translateTip), {}, {
56
62
  y: translateTip.y + position + marginTop
57
63
  }) : _objectSpread(_objectSpread({}, translateTip), {}, {
58
64
  x: translateTip.x + position + marginLeft
59
65
  });
60
- if (!isVertical && translate3d.x + tipWidth > width) {
61
- var newPositon = position + marginLeft - tipWidth - translateTip.x;
66
+ if (!isVertical && translate3d.x + tooltipSize.width > width) {
67
+ var newPositon = position + marginLeft - tooltipSize.width - translateTip.x;
62
68
  translate3d.x = newPositon >= 0 ? newPositon : 0;
63
69
  }
64
- if (isVertical && translate3d.y + tipHeight > height) {
65
- var _newPositon = position + marginTop - tipHeight - translateTip.y;
66
- translate3d.y = _newPositon <= 0 ? _newPositon : height - tipHeight;
70
+ if (isVertical && translate3d.y + tooltipSize.height > height) {
71
+ var _newPositon = position + marginTop - tooltipSize.height - translateTip.y;
72
+ translate3d.y = _newPositon <= 0 ? _newPositon : height - tooltipSize.height;
67
73
  }
68
74
  return (0, _utils.getTranslate3d)(translate3d);
69
- }, [width, height, marginLeft, marginTop, position, tipWidth, tipHeight, translateTip]);
75
+ }, [width, height, marginLeft, marginTop, position, tooltipSize, translateTip]);
76
+ (0, _react.useEffect)(function () {
77
+ if (tooltipRef.current && (manual || auto)) {
78
+ var rect = tooltipRef.current.getBoundingClientRect();
79
+ setTooltipSize({
80
+ width: rect.width,
81
+ height: rect.height
82
+ });
83
+ }
84
+ }, [manual, auto, formatter, data, series, x]);
70
85
  return manual || auto ? /*#__PURE__*/React.createElement("div", {
86
+ ref: tooltipRef,
71
87
  className: "__easyv-tooltip",
72
- style: _objectSpread({
88
+ style: _objectSpread(_objectSpread({
73
89
  pointerEvents: "none",
74
90
  transform: tipPosition,
75
- width: tipWidth,
76
- minHeight: tipHeight,
91
+ display: "inline-block",
92
+ position: "absolute",
93
+ margin: 0,
94
+ boxSizing: "border-box",
77
95
  padding: (0, _utils.getMargin)(margin),
78
96
  background: bgType == "image" ? image ? "50% 50% / 100% 100% no-repeat url(" + window.appConfig.ASSETS_URL + image + ")" : "transparent" : bgColor
79
- }, (0, _utils.getFontStyle)(font))
97
+ }, (0, _utils.getFontStyle)(font)), {}, {
98
+ width: "fit-content",
99
+ maxWidth: "none",
100
+ overflow: "visible",
101
+ zIndex: 9999
102
+ })
80
103
  }, formatter ? formatter({
81
104
  series: series,
82
105
  x: {
@@ -93,7 +116,9 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
93
116
  flexDirection: "column",
94
117
  justifyContent: "space-between",
95
118
  gap: gap,
96
- height: "100%"
119
+ height: "100%",
120
+ width: "auto",
121
+ maxWidth: "none"
97
122
  }
98
123
  }, /*#__PURE__*/React.createElement("div", {
99
124
  style: _objectSpread({
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.PieTooltip = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _utils = require("../utils");
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
@@ -37,13 +37,32 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
37
37
  precision = _props$config$tip$dat3.precision,
38
38
  image = _props$config$tip.image,
39
39
  margin = _props$config$tip.margin,
40
- _props$config$tip$siz = _props$config$tip.size,
41
- tipWidth = _props$config$tip$siz.width,
42
- tipHeight = _props$config$tip$siz.height,
43
40
  translateTip = _props$config$tip.translate,
44
41
  data = props.data,
45
42
  series = props.series;
43
+ var tooltipRef = (0, _react.useRef)(null);
44
+ // 存储tooltip的实际宽高
45
+ var _useState = (0, _react.useState)({
46
+ width: 0,
47
+ height: 0
48
+ }),
49
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
50
+ tooltipSize = _useState2[0],
51
+ setTooltipSize = _useState2[1];
46
52
  var screenRef = domRef.current.getBoundingClientRect();
53
+ (0, _react.useEffect)(function () {
54
+ if (tooltipRef.current && mousePos) {
55
+ try {
56
+ var rect = tooltipRef.current.getBoundingClientRect();
57
+ setTooltipSize({
58
+ width: rect.width,
59
+ height: rect.height
60
+ });
61
+ } catch (e) {
62
+ console.error("获取tooltip尺寸失败:", e);
63
+ }
64
+ }
65
+ }, [mousePos, data, series, lineHeight, iconSize]);
47
66
  var Item = function Item() {
48
67
  var _data$data = data.data,
49
68
  s = _data$data.s,
@@ -61,7 +80,7 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
61
80
  suffixTranslate = suffix.translate;
62
81
  return /*#__PURE__*/_react["default"].createElement("span", {
63
82
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(suffiixFont)), {}, {
64
- display: "inline-block",
83
+ // display: "inline-block",
65
84
  transform: (0, _utils.getTranslate3d)(suffixTranslate)
66
85
  })
67
86
  }, content);
@@ -71,7 +90,8 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
71
90
  style: {
72
91
  display: "flex",
73
92
  justifyContent: "space-between",
74
- lineHeight: lineHeight + "px"
93
+ lineHeight: lineHeight + "px",
94
+ alignItems: "center"
75
95
  }
76
96
  }, /*#__PURE__*/_react["default"].createElement("span", {
77
97
  style: {
@@ -88,9 +108,13 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
88
108
  }), /*#__PURE__*/_react["default"].createElement("span", {
89
109
  style: (0, _utils.getFontStyle)(name)
90
110
  }, displayName || s)), valueIsShow && /*#__PURE__*/_react["default"].createElement("span", {
91
- style: (0, _utils.getFontStyle)(valueFont)
111
+ style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
112
+ marginLeft: "10px"
113
+ })
92
114
  }, y, valueSuffixIsShow && renderSuffix(valueSuffix)), percentageIsShow && /*#__PURE__*/_react["default"].createElement("span", {
93
- style: (0, _utils.getFontStyle)(percentageFont)
115
+ style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(percentageFont)), {}, {
116
+ marginLeft: "10px"
117
+ })
94
118
  }, Number(percent).toFixed(precision), percentageSuffixIsShow && renderSuffix(percentageSuffix)));
95
119
  };
96
120
  var getBigScreenScale = function getBigScreenScale() {
@@ -165,10 +189,10 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
165
189
  centerY = pieCenter.y;
166
190
  var getTipPos = function getTipPos() {
167
191
  var tipPosMap = {
168
- rightTop: "translate(".concat((screenRef.x + translateTip.x + tipWidth) / scaleX + mouseX - screenLeft / scaleX > screenWidth / scaleX ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,").concat((screenRef.y - translateTip.y - tipHeight) / scaleY + mouseY - screenTop / scaleY < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
169
- leftTop: "translate(".concat((screenRef.x - translateTip.x - tipWidth) / scaleX + mouseX - screenLeft / scaleX < 0 ? mouseX + translateTip.x : mouseX - translateTip.x - tipWidth, "px,").concat((screenRef.y - translateTip.y - tipHeight) / scaleY + mouseY - screenTop / scaleY < 0 ? mouseY + translateTip.y : mouseY - tipHeight - translateTip.y, "px)"),
170
- leftBottom: "translate(".concat((screenRef.x - translateTip.x - tipWidth) / scaleX + mouseX - screenLeft / scaleX < 0 ? mouseX + translateTip.x : mouseX - translateTip.x - tipWidth, "px,").concat((screenRef.y + translateTip.y + tipHeight) / scaleY + mouseY - screenTop / scaleY > screenHeight / scaleY ? mouseY - translateTip.y - tipHeight : mouseY + translateTip.y, "px)"),
171
- rightBottom: "translate(".concat((screenRef.x + translateTip.x + tipWidth) / scaleX + mouseX - screenLeft / scaleX > screenWidth / scaleX ? mouseX - tipWidth - translateTip.x : mouseX + translateTip.x, "px,").concat((screenRef.y + translateTip.y + tipHeight) / scaleY + mouseY - screenTop / scaleY > screenHeight / scaleY ? mouseY - translateTip.y - tipHeight : mouseY + translateTip.y, "px)")
192
+ rightTop: "translate(".concat((screenRef.x + translateTip.x + tooltipSize.width) / scaleX + mouseX - screenLeft / scaleX > screenWidth / scaleX ? mouseX - tooltipSize.width - translateTip.x : mouseX + translateTip.x, "px,").concat((screenRef.y - translateTip.y - tooltipSize.height) / scaleY + mouseY - screenTop / scaleY < 0 ? mouseY + translateTip.y : mouseY - tooltipSize.height - translateTip.y, "px)"),
193
+ leftTop: "translate(".concat((screenRef.x - translateTip.x - tooltipSize.width) / scaleX + mouseX - screenLeft / scaleX < 0 ? mouseX + translateTip.x : mouseX - translateTip.x - tooltipSize.width, "px,").concat((screenRef.y - translateTip.y - tooltipSize.height) / scaleY + mouseY - screenTop / scaleY < 0 ? mouseY + translateTip.y : mouseY - tooltipSize.height - translateTip.y, "px)"),
194
+ leftBottom: "translate(".concat((screenRef.x - translateTip.x - tooltipSize.width) / scaleX + mouseX - screenLeft / scaleX < 0 ? mouseX + translateTip.x : mouseX - translateTip.x - tooltipSize.width, "px,").concat((screenRef.y + translateTip.y + tooltipSize.height) / scaleY + mouseY - screenTop / scaleY > screenHeight / scaleY ? mouseY - translateTip.y - tooltipSize.height : mouseY + translateTip.y, "px)"),
195
+ rightBottom: "translate(".concat((screenRef.x + translateTip.x + tooltipSize.width) / scaleX + mouseX - screenLeft / scaleX > screenWidth / scaleX ? mouseX - tooltipSize.width - translateTip.x : mouseX + translateTip.x, "px,").concat((screenRef.y + translateTip.y + tooltipSize.height) / scaleY + mouseY - screenTop / scaleY > screenHeight / scaleY ? mouseY - translateTip.y - tooltipSize.height : mouseY + translateTip.y, "px)")
172
196
  };
173
197
  if (mouseX < centerX && mouseY < centerY) {
174
198
  return tipPosMap.leftTop;
@@ -181,20 +205,22 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
181
205
  }
182
206
  };
183
207
  return /*#__PURE__*/_react["default"].createElement("div", {
208
+ ref: tooltipRef,
184
209
  className: "__easyv-tooltip",
185
210
  style: {
186
211
  pointerEvents: "none",
187
212
  transform: getTipPos(mousePos, pieCenter),
188
- width: tipWidth,
189
- height: tipHeight,
213
+ boxSizing: "border-box",
190
214
  padding: (0, _utils.getMargin)(margin),
191
- background: image ? "50% 50% / 100% 100% no-repeat url(" + window.appConfig.ASSETS_URL + image + ")" : "rgba(48, 55, 66, 0.85)"
215
+ background: image ? "50% 50% / 100% 100% no-repeat url(" + window.appConfig.ASSETS_URL + image + ")" : "rgba(48, 55, 66, 0.85)",
216
+ overflow: "hidden"
192
217
  }
193
218
  }, /*#__PURE__*/_react["default"].createElement("dl", {
194
219
  style: {
195
220
  display: "flex",
196
221
  flexDirection: "column",
197
222
  justifyContent: "space-between",
223
+ margin: 0,
198
224
  height: "100%"
199
225
  }
200
226
  }, Item()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.9.25",
3
+ "version": "1.9.27",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -55,4 +55,4 @@
55
55
  "commit": true
56
56
  }
57
57
  }
58
- }
58
+ }
@@ -226,7 +226,7 @@ type LabelType = {
226
226
  events?: Function;
227
227
  config: {
228
228
  show: boolean;
229
- adaptive:boolean;
229
+ adaptive: boolean;
230
230
  translate: Translate;
231
231
  font: Font;
232
232
  textAlign: TextAlign;
@@ -291,7 +291,10 @@ const Label: (
291
291
  ...config,
292
292
  format: { type: config.format, showType: config.showType },
293
293
  });
294
- const { transform, directionX, directionY } = getLayout(orientation, rotate);
294
+ const { transform, directionX, directionY } = getLayout(
295
+ orientation,
296
+ adaptive ? 0 : rotate
297
+ );
295
298
  const isVertical = orientation == "left" || orientation == "right";
296
299
 
297
300
  const x =
@@ -344,10 +347,9 @@ const Label: (
344
347
  ) : (
345
348
  <span
346
349
  style={{
347
- width: LabelWidth,
350
+ display: "inline-block",
348
351
  transform,
349
- justifyContent: "flex-start",
350
- display: "block",
352
+ position: "absolute",
351
353
  top: translateY,
352
354
  left: translateX,
353
355
  }}
@@ -396,7 +398,7 @@ export default memo(
396
398
  const x = orientation == "right" ? width : 0;
397
399
  const y = orientation == "bottom" ? height - cHeight : 0;
398
400
  let LabelWidth = 1;
399
- if (!label.adaptive&&label.appearance) {
401
+ if (!label.adaptive && label.appearance) {
400
402
  LabelWidth = label.appearance.width;
401
403
  } else {
402
404
  if (allTicks.length && typeof allTicks[0] == "string") {
@@ -406,18 +408,17 @@ export default memo(
406
408
  const LabelNum = Math.floor(
407
409
  ((width / (isC ? cPercent : 1)) * (1 - paddingOuter)) / LabelWidth
408
410
  );
409
- const ticks: any =
410
- !label.adaptive
411
- ? tickss
412
- : getEvenlySpacedElements(
413
- allTicks,
414
- LabelNum < allTicks.length
415
- ? LabelNum > allTicks.length / 2
416
- ? Math.ceil(allTicks.length / 2)
417
- : LabelNum
418
- : allTicks.length,
419
- label.showLast
420
- );
411
+ const ticks: any = !label.adaptive
412
+ ? tickss
413
+ : getEvenlySpacedElements(
414
+ allTicks,
415
+ LabelNum < allTicks.length
416
+ ? LabelNum > allTicks.length / 2
417
+ ? Math.ceil(allTicks.length / 2)
418
+ : LabelNum
419
+ : allTicks.length,
420
+ label.showLast
421
+ );
421
422
  if (!(on && ticks.length > 0)) return null;
422
423
 
423
424
  //数据抽取逻辑
@@ -348,8 +348,9 @@ const Chart = memo(
348
348
  setClipX(-translateX);
349
349
  const isVertical = axisX.direction === "vertical";
350
350
  const coreOffset = isVertical ? marginRight : isIOS ? marginLeft : 0;
351
- seriesEl.current.style.transform = `translate(${translateX + coreOffset
352
- }px,${marginTop}px)`;
351
+ seriesEl.current.style.transform = `translate(${
352
+ translateX + coreOffset
353
+ }px,${marginTop}px)`;
353
354
  axisElList.current[2].style.transform = `translate(${translateX}px,${0}px)`;
354
355
  }
355
356
  }, [controlInfo]);
@@ -458,8 +459,8 @@ const Chart = memo(
458
459
  const controlChartTooltipData =
459
460
  ctlXName && originData.filter((d) => d.x === ctlXName);
460
461
  const bodyWidth = isVertical
461
- ? xLineRange + 100 + marginRight + marginLeft
462
- : xLineRange,
462
+ ? xLineRange + 100 + marginRight + marginLeft
463
+ : xLineRange,
463
464
  bodyHeight = isVertical
464
465
  ? yLineRange
465
466
  : yLineRange + marginTop + marginBottom;
@@ -724,7 +725,7 @@ const Chart = memo(
724
725
  ctlX -
725
726
  marginLeft -
726
727
  (axisX.controlEnd + axisX.start / cPercent - chartWidth) *
727
- curControlPercent.current
728
+ curControlPercent.current
728
729
  }
729
730
  marginLeft={marginLeft}
730
731
  marginTop={marginTop}
@@ -54,7 +54,7 @@ export default memo(
54
54
  onMouseMove={onMouseMove}
55
55
  ref={ref}
56
56
  style={{
57
- overflow: "hidden",
57
+ overflow: "visible",
58
58
  position: "absolute",
59
59
  width,
60
60
  height,
@@ -1,4 +1,4 @@
1
- import React, { memo } from "react";
1
+ import React, { memo, useRef, useState, useEffect } from "react";
2
2
  import {
3
3
  getFontStyle,
4
4
  getMargin,
@@ -34,14 +34,33 @@ export const PieTooltip = memo((props) => {
34
34
  },
35
35
  image,
36
36
  margin,
37
- size: { width: tipWidth, height: tipHeight },
37
+ // size: { width: tooltipSize.width, height: tooltipSize.height },
38
38
  translate: translateTip,
39
39
  },
40
40
  },
41
41
  data,
42
42
  series,
43
43
  } = props;
44
+ const tooltipRef = useRef(null);
45
+ // 存储tooltip的实际宽高
46
+ const [tooltipSize, setTooltipSize] = useState({
47
+ width: 0,
48
+ height: 0,
49
+ });
44
50
  const screenRef = domRef.current.getBoundingClientRect();
51
+ useEffect(() => {
52
+ if (tooltipRef.current && mousePos) {
53
+ try {
54
+ const rect = tooltipRef.current.getBoundingClientRect();
55
+ setTooltipSize({
56
+ width: rect.width,
57
+ height: rect.height,
58
+ });
59
+ } catch (e) {
60
+ console.error("获取tooltip尺寸失败:", e);
61
+ }
62
+ }
63
+ }, [mousePos, data, series, lineHeight, iconSize]);
45
64
  const Item = () => {
46
65
  const {
47
66
  data: { s, y },
@@ -57,7 +76,7 @@ export const PieTooltip = memo((props) => {
57
76
  <span
58
77
  style={{
59
78
  ...getFontStyle(suffiixFont),
60
- display: "inline-block",
79
+ // display: "inline-block",
61
80
  transform: getTranslate3d(suffixTranslate),
62
81
  }}
63
82
  >
@@ -73,6 +92,7 @@ export const PieTooltip = memo((props) => {
73
92
  display: "flex",
74
93
  justifyContent: "space-between",
75
94
  lineHeight: lineHeight + "px",
95
+ alignItems: "center",
76
96
  }}
77
97
  >
78
98
  <span
@@ -93,13 +113,13 @@ export const PieTooltip = memo((props) => {
93
113
  <span style={getFontStyle(name)}>{displayName || s}</span>
94
114
  </span>
95
115
  {valueIsShow && (
96
- <span style={getFontStyle(valueFont)}>
116
+ <span style={{ ...getFontStyle(valueFont), marginLeft: "10px" }}>
97
117
  {y}
98
118
  {valueSuffixIsShow && renderSuffix(valueSuffix)}
99
119
  </span>
100
120
  )}
101
121
  {percentageIsShow && (
102
- <span style={getFontStyle(percentageFont)}>
122
+ <span style={{ ...getFontStyle(percentageFont), marginLeft: "10px" }}>
103
123
  {Number(percent).toFixed(precision)}
104
124
  {percentageSuffixIsShow && renderSuffix(percentageSuffix)}
105
125
  </span>
@@ -183,63 +203,63 @@ export const PieTooltip = memo((props) => {
183
203
  const getTipPos = () => {
184
204
  const tipPosMap = {
185
205
  rightTop: `translate(${
186
- (screenRef.x + translateTip.x + tipWidth) / scaleX +
206
+ (screenRef.x + translateTip.x + tooltipSize.width) / scaleX +
187
207
  mouseX -
188
208
  screenLeft / scaleX >
189
209
  screenWidth / scaleX
190
- ? mouseX - tipWidth - translateTip.x
210
+ ? mouseX - tooltipSize.width - translateTip.x
191
211
  : mouseX + translateTip.x
192
212
  }px,${
193
- (screenRef.y - translateTip.y - tipHeight) / scaleY +
213
+ (screenRef.y - translateTip.y - tooltipSize.height) / scaleY +
194
214
  mouseY -
195
215
  screenTop / scaleY <
196
216
  0
197
217
  ? mouseY + translateTip.y
198
- : mouseY - tipHeight - translateTip.y
218
+ : mouseY - tooltipSize.height - translateTip.y
199
219
  }px)`,
200
220
  leftTop: `translate(${
201
- (screenRef.x - translateTip.x - tipWidth) / scaleX +
221
+ (screenRef.x - translateTip.x - tooltipSize.width) / scaleX +
202
222
  mouseX -
203
223
  screenLeft / scaleX <
204
224
  0
205
225
  ? mouseX + translateTip.x
206
- : mouseX - translateTip.x - tipWidth
226
+ : mouseX - translateTip.x - tooltipSize.width
207
227
  }px,${
208
- (screenRef.y - translateTip.y - tipHeight) / scaleY +
228
+ (screenRef.y - translateTip.y - tooltipSize.height) / scaleY +
209
229
  mouseY -
210
230
  screenTop / scaleY <
211
231
  0
212
232
  ? mouseY + translateTip.y
213
- : mouseY - tipHeight - translateTip.y
233
+ : mouseY - tooltipSize.height - translateTip.y
214
234
  }px)`,
215
235
  leftBottom: `translate(${
216
- (screenRef.x - translateTip.x - tipWidth) / scaleX +
236
+ (screenRef.x - translateTip.x - tooltipSize.width) / scaleX +
217
237
  mouseX -
218
238
  screenLeft / scaleX <
219
239
  0
220
240
  ? mouseX + translateTip.x
221
- : mouseX - translateTip.x - tipWidth
241
+ : mouseX - translateTip.x - tooltipSize.width
222
242
  }px,${
223
- (screenRef.y + translateTip.y + tipHeight) / scaleY +
243
+ (screenRef.y + translateTip.y + tooltipSize.height) / scaleY +
224
244
  mouseY -
225
245
  screenTop / scaleY >
226
246
  screenHeight / scaleY
227
- ? mouseY - translateTip.y - tipHeight
247
+ ? mouseY - translateTip.y - tooltipSize.height
228
248
  : mouseY + translateTip.y
229
249
  }px)`,
230
250
  rightBottom: `translate(${
231
- (screenRef.x + translateTip.x + tipWidth) / scaleX +
251
+ (screenRef.x + translateTip.x + tooltipSize.width) / scaleX +
232
252
  mouseX -
233
253
  screenLeft / scaleX >
234
254
  screenWidth / scaleX
235
- ? mouseX - tipWidth - translateTip.x
255
+ ? mouseX - tooltipSize.width - translateTip.x
236
256
  : mouseX + translateTip.x
237
257
  }px,${
238
- (screenRef.y + translateTip.y + tipHeight) / scaleY +
258
+ (screenRef.y + translateTip.y + tooltipSize.height) / scaleY +
239
259
  mouseY -
240
260
  screenTop / scaleY >
241
261
  screenHeight / scaleY
242
- ? mouseY - translateTip.y - tipHeight
262
+ ? mouseY - translateTip.y - tooltipSize.height
243
263
  : mouseY + translateTip.y
244
264
  }px)`,
245
265
  };
@@ -256,12 +276,12 @@ export const PieTooltip = memo((props) => {
256
276
 
257
277
  return (
258
278
  <div
279
+ ref={tooltipRef}
259
280
  className="__easyv-tooltip"
260
281
  style={{
261
282
  pointerEvents: "none",
262
283
  transform: getTipPos(mousePos, pieCenter),
263
- width: tipWidth,
264
- height: tipHeight,
284
+ boxSizing: "border-box",
265
285
  padding: getMargin(margin),
266
286
  background: image
267
287
  ? "50% 50% / 100% 100% no-repeat url(" +
@@ -269,6 +289,7 @@ export const PieTooltip = memo((props) => {
269
289
  image +
270
290
  ")"
271
291
  : "rgba(48, 55, 66, 0.85)",
292
+ overflow: "hidden",
272
293
  }}
273
294
  >
274
295
  <dl
@@ -276,6 +297,7 @@ export const PieTooltip = memo((props) => {
276
297
  display: "flex",
277
298
  flexDirection: "column",
278
299
  justifyContent: "space-between",
300
+ margin: 0,
279
301
  height: "100%",
280
302
  }}
281
303
  >
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 提示框
3
3
  */
4
- import { memo, useMemo } from "react";
4
+ import { memo, useMemo, useRef, useEffect, useState } from "react";
5
5
  import { getFontStyle, getMargin, getTranslate3d } from "../utils";
6
6
  import { getIcon } from "../utils";
7
7
  export default memo(
@@ -32,7 +32,6 @@ export default memo(
32
32
  bgColor,
33
33
  image,
34
34
  margin,
35
- size: { width: tipWidth, height: tipHeight },
36
35
  translate: translateTip,
37
36
  },
38
37
  },
@@ -43,6 +42,11 @@ export default memo(
43
42
  auto,
44
43
  manual,
45
44
  }) => {
45
+ const tooltipRef = useRef(null);
46
+ const [tooltipSize, setTooltipSize] = useState({
47
+ width: 0,
48
+ height: 0,
49
+ });
46
50
  const tipPosition = useMemo(() => {
47
51
  const translate3d = isVertical
48
52
  ? {
@@ -53,13 +57,16 @@ export default memo(
53
57
  ...translateTip,
54
58
  x: translateTip.x + position + marginLeft,
55
59
  };
56
- if (!isVertical && translate3d.x + tipWidth > width) {
57
- const newPositon = position + marginLeft - tipWidth - translateTip.x;
60
+ if (!isVertical && translate3d.x + tooltipSize.width > width) {
61
+ const newPositon =
62
+ position + marginLeft - tooltipSize.width - translateTip.x;
58
63
  translate3d.x = newPositon >= 0 ? newPositon : 0;
59
64
  }
60
- if (isVertical && translate3d.y + tipHeight > height) {
61
- const newPositon = position + marginTop - tipHeight - translateTip.y;
62
- translate3d.y = newPositon <= 0 ? newPositon : height - tipHeight;
65
+ if (isVertical && translate3d.y + tooltipSize.height > height) {
66
+ const newPositon =
67
+ position + marginTop - tooltipSize.height - translateTip.y;
68
+ translate3d.y =
69
+ newPositon <= 0 ? newPositon : height - tooltipSize.height;
63
70
  }
64
71
  return getTranslate3d(translate3d);
65
72
  }, [
@@ -68,18 +75,29 @@ export default memo(
68
75
  marginLeft,
69
76
  marginTop,
70
77
  position,
71
- tipWidth,
72
- tipHeight,
78
+ tooltipSize,
73
79
  translateTip,
74
80
  ]);
81
+ useEffect(() => {
82
+ if (tooltipRef.current && (manual || auto)) {
83
+ const rect = tooltipRef.current.getBoundingClientRect();
84
+ setTooltipSize({
85
+ width: rect.width,
86
+ height: rect.height,
87
+ });
88
+ }
89
+ }, [manual, auto, formatter, data, series, x]);
75
90
  return manual || auto ? (
76
91
  <div
92
+ ref={tooltipRef}
77
93
  className="__easyv-tooltip"
78
94
  style={{
79
95
  pointerEvents: "none",
80
96
  transform: tipPosition,
81
- width: tipWidth,
82
- minHeight: tipHeight,
97
+ display: "inline-block",
98
+ position: "absolute",
99
+ margin: 0,
100
+ boxSizing: "border-box",
83
101
  padding: getMargin(margin),
84
102
  background:
85
103
  bgType == "image"
@@ -91,6 +109,10 @@ export default memo(
91
109
  : "transparent"
92
110
  : bgColor,
93
111
  ...getFontStyle(font),
112
+ width: "fit-content",
113
+ maxWidth: "none",
114
+ overflow: "visible",
115
+ zIndex: 9999,
94
116
  }}
95
117
  >
96
118
  {formatter ? (
@@ -107,6 +129,8 @@ export default memo(
107
129
  justifyContent: "space-between",
108
130
  gap,
109
131
  height: "100%",
132
+ width: "auto",
133
+ maxWidth: "none",
110
134
  }}
111
135
  >
112
136
  <div