source: node_modules/recharts/es6/component/TooltipBoundingBox.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 5.1 KB
Line 
1function 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; }
2function _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; }
3function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5function _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); }
6import * as React from 'react';
7import { PureComponent } from 'react';
8import { getTooltipTranslate } from '../util/tooltip/translate';
9export class TooltipBoundingBox extends PureComponent {
10 constructor() {
11 super(...arguments);
12 _defineProperty(this, "state", {
13 dismissed: false,
14 dismissedAtCoordinate: {
15 x: 0,
16 y: 0
17 }
18 });
19 _defineProperty(this, "handleKeyDown", event => {
20 if (event.key === 'Escape') {
21 var _this$props$coordinat, _this$props$coordinat2, _this$props$coordinat3, _this$props$coordinat4;
22 this.setState({
23 dismissed: true,
24 dismissedAtCoordinate: {
25 x: (_this$props$coordinat = (_this$props$coordinat2 = this.props.coordinate) === null || _this$props$coordinat2 === void 0 ? void 0 : _this$props$coordinat2.x) !== null && _this$props$coordinat !== void 0 ? _this$props$coordinat : 0,
26 y: (_this$props$coordinat3 = (_this$props$coordinat4 = this.props.coordinate) === null || _this$props$coordinat4 === void 0 ? void 0 : _this$props$coordinat4.y) !== null && _this$props$coordinat3 !== void 0 ? _this$props$coordinat3 : 0
27 }
28 });
29 }
30 });
31 }
32 componentDidMount() {
33 document.addEventListener('keydown', this.handleKeyDown);
34 }
35 componentWillUnmount() {
36 document.removeEventListener('keydown', this.handleKeyDown);
37 }
38 componentDidUpdate() {
39 var _this$props$coordinat5, _this$props$coordinat6;
40 if (!this.state.dismissed) {
41 return;
42 }
43 if (((_this$props$coordinat5 = this.props.coordinate) === null || _this$props$coordinat5 === void 0 ? void 0 : _this$props$coordinat5.x) !== this.state.dismissedAtCoordinate.x || ((_this$props$coordinat6 = this.props.coordinate) === null || _this$props$coordinat6 === void 0 ? void 0 : _this$props$coordinat6.y) !== this.state.dismissedAtCoordinate.y) {
44 this.state.dismissed = false;
45 }
46 }
47 render() {
48 var {
49 active,
50 allowEscapeViewBox,
51 animationDuration,
52 animationEasing,
53 children,
54 coordinate,
55 hasPayload,
56 isAnimationActive,
57 offset,
58 position,
59 reverseDirection,
60 useTranslate3d,
61 viewBox,
62 wrapperStyle,
63 lastBoundingBox,
64 innerRef,
65 hasPortalFromProps
66 } = this.props;
67 var offsetLeft = typeof offset === 'number' ? offset : offset.x;
68 var offsetTop = typeof offset === 'number' ? offset : offset.y;
69 var {
70 cssClasses,
71 cssProperties
72 } = getTooltipTranslate({
73 allowEscapeViewBox,
74 coordinate,
75 offsetLeft,
76 offsetTop,
77 position,
78 reverseDirection,
79 tooltipBox: {
80 height: lastBoundingBox.height,
81 width: lastBoundingBox.width
82 },
83 useTranslate3d,
84 viewBox
85 });
86
87 // do not use absolute styles if the user has passed a custom portal prop
88 var positionStyles = hasPortalFromProps ? {} : _objectSpread(_objectSpread({
89 transition: isAnimationActive && active ? "transform ".concat(animationDuration, "ms ").concat(animationEasing) : undefined
90 }, cssProperties), {}, {
91 pointerEvents: 'none',
92 visibility: !this.state.dismissed && active && hasPayload ? 'visible' : 'hidden',
93 position: 'absolute',
94 top: 0,
95 left: 0
96 });
97 var outerStyle = _objectSpread(_objectSpread({}, positionStyles), {}, {
98 visibility: !this.state.dismissed && active && hasPayload ? 'visible' : 'hidden'
99 }, wrapperStyle);
100 return (
101 /*#__PURE__*/
102 // This element allow listening to the `Escape` key. See https://github.com/recharts/recharts/pull/2925
103 React.createElement("div", {
104 // @ts-expect-error typescript library does not recognize xmlns attribute, but it's required for an HTML chunk inside SVG.
105 xmlns: "http://www.w3.org/1999/xhtml",
106 tabIndex: -1,
107 className: cssClasses,
108 style: outerStyle,
109 ref: innerRef
110 }, children)
111 );
112 }
113}
Note: See TracBrowser for help on using the repository browser.