Tooltip.js 7.6 KB

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