Tooltip.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Tooltip = void 0;
  6. var _react = _interopRequireWildcard(require("react"));
  7. var _DefaultTooltipContent = require("./DefaultTooltipContent");
  8. var _TooltipBoundingBox = require("./TooltipBoundingBox");
  9. var _Global = require("../util/Global");
  10. var _getUniqPayload = require("../util/payload/getUniqPayload");
  11. 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); }
  12. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
  13. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  14. 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; }
  15. 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) { _defineProperty(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; }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
  18. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  19. function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
  20. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  21. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  22. function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
  23. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  24. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  25. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  26. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  27. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  28. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
  29. * @fileOverview Tooltip
  30. */
  31. function defaultUniqBy(entry) {
  32. return entry.dataKey;
  33. }
  34. function renderContent(content, props) {
  35. if ( /*#__PURE__*/_react["default"].isValidElement(content)) {
  36. return /*#__PURE__*/_react["default"].cloneElement(content, props);
  37. }
  38. if (typeof content === 'function') {
  39. return /*#__PURE__*/_react["default"].createElement(content, props);
  40. }
  41. return /*#__PURE__*/_react["default"].createElement(_DefaultTooltipContent.DefaultTooltipContent, props);
  42. }
  43. var Tooltip = exports.Tooltip = /*#__PURE__*/function (_PureComponent) {
  44. function Tooltip() {
  45. _classCallCheck(this, Tooltip);
  46. return _callSuper(this, Tooltip, arguments);
  47. }
  48. _inherits(Tooltip, _PureComponent);
  49. return _createClass(Tooltip, [{
  50. key: "render",
  51. value: function render() {
  52. var _this = this;
  53. var _this$props = this.props,
  54. active = _this$props.active,
  55. allowEscapeViewBox = _this$props.allowEscapeViewBox,
  56. animationDuration = _this$props.animationDuration,
  57. animationEasing = _this$props.animationEasing,
  58. content = _this$props.content,
  59. coordinate = _this$props.coordinate,
  60. filterNull = _this$props.filterNull,
  61. isAnimationActive = _this$props.isAnimationActive,
  62. offset = _this$props.offset,
  63. payload = _this$props.payload,
  64. payloadUniqBy = _this$props.payloadUniqBy,
  65. position = _this$props.position,
  66. reverseDirection = _this$props.reverseDirection,
  67. useTranslate3d = _this$props.useTranslate3d,
  68. viewBox = _this$props.viewBox,
  69. wrapperStyle = _this$props.wrapperStyle;
  70. var finalPayload = payload !== null && payload !== void 0 ? payload : [];
  71. if (filterNull && finalPayload.length) {
  72. finalPayload = (0, _getUniqPayload.getUniqPayload)(payload.filter(function (entry) {
  73. return entry.value != null && (entry.hide !== true || _this.props.includeHidden);
  74. }), payloadUniqBy, defaultUniqBy);
  75. }
  76. var hasPayload = finalPayload.length > 0;
  77. return /*#__PURE__*/_react["default"].createElement(_TooltipBoundingBox.TooltipBoundingBox, {
  78. allowEscapeViewBox: allowEscapeViewBox,
  79. animationDuration: animationDuration,
  80. animationEasing: animationEasing,
  81. isAnimationActive: isAnimationActive,
  82. active: active,
  83. coordinate: coordinate,
  84. hasPayload: hasPayload,
  85. offset: offset,
  86. position: position,
  87. reverseDirection: reverseDirection,
  88. useTranslate3d: useTranslate3d,
  89. viewBox: viewBox,
  90. wrapperStyle: wrapperStyle
  91. }, renderContent(content, _objectSpread(_objectSpread({}, this.props), {}, {
  92. payload: finalPayload
  93. })));
  94. }
  95. }]);
  96. }(_react.PureComponent);
  97. _defineProperty(Tooltip, "displayName", 'Tooltip');
  98. _defineProperty(Tooltip, "defaultProps", {
  99. accessibilityLayer: false,
  100. allowEscapeViewBox: {
  101. x: false,
  102. y: false
  103. },
  104. animationDuration: 400,
  105. animationEasing: 'ease',
  106. contentStyle: {},
  107. coordinate: {
  108. x: 0,
  109. y: 0
  110. },
  111. cursor: true,
  112. cursorStyle: {},
  113. filterNull: true,
  114. isAnimationActive: !_Global.Global.isSsr,
  115. itemStyle: {},
  116. labelStyle: {},
  117. offset: 10,
  118. reverseDirection: {
  119. x: false,
  120. y: false
  121. },
  122. separator: ' : ',
  123. trigger: 'hover',
  124. useTranslate3d: false,
  125. viewBox: {
  126. x: 0,
  127. y: 0,
  128. height: 0,
  129. width: 0
  130. },
  131. wrapperStyle: {}
  132. });