| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.defaultTrapezoidProps = exports.Trapezoid = void 0;
|
|---|
| 7 | var _react = _interopRequireWildcard(require("react"));
|
|---|
| 8 | var React = _react;
|
|---|
| 9 | var _clsx = require("clsx");
|
|---|
| 10 | var _resolveDefaultProps = require("../util/resolveDefaultProps");
|
|---|
| 11 | var _JavascriptAnimate = require("../animation/JavascriptAnimate");
|
|---|
| 12 | var _useAnimationId = require("../util/useAnimationId");
|
|---|
| 13 | var _DataUtils = require("../util/DataUtils");
|
|---|
| 14 | var _util = require("../animation/util");
|
|---|
| 15 | var _svgPropertiesAndEvents = require("../util/svgPropertiesAndEvents");
|
|---|
| 16 | var _round = require("../util/round");
|
|---|
| 17 | var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|---|
| 18 | /**
|
|---|
| 19 | * @fileOverview Rectangle
|
|---|
| 20 | */
|
|---|
| 21 | function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|---|
| 22 | 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; }
|
|---|
| 23 | 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; }
|
|---|
| 24 | function _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; }
|
|---|
| 25 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 26 | 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); }
|
|---|
| 27 | function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|---|
| 28 | function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
|
|---|
| 29 | var getTrapezoidPath = (x, y, upperWidth, lowerWidth, height) => {
|
|---|
| 30 | var widthGap = upperWidth - lowerWidth;
|
|---|
| 31 | var path;
|
|---|
| 32 | path = (0, _round.roundTemplateLiteral)(_templateObject || (_templateObject = _taggedTemplateLiteral(["M ", ",", ""])), x, y);
|
|---|
| 33 | path += (0, _round.roundTemplateLiteral)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["L ", ",", ""])), x + upperWidth, y);
|
|---|
| 34 | path += (0, _round.roundTemplateLiteral)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["L ", ",", ""])), x + upperWidth - widthGap / 2, y + height);
|
|---|
| 35 | path += (0, _round.roundTemplateLiteral)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["L ", ",", ""])), x + upperWidth - widthGap / 2 - lowerWidth, y + height);
|
|---|
| 36 | path += (0, _round.roundTemplateLiteral)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["L ", ",", " Z"])), x, y);
|
|---|
| 37 | return path;
|
|---|
| 38 | };
|
|---|
| 39 | var defaultTrapezoidProps = exports.defaultTrapezoidProps = {
|
|---|
| 40 | x: 0,
|
|---|
| 41 | y: 0,
|
|---|
| 42 | upperWidth: 0,
|
|---|
| 43 | lowerWidth: 0,
|
|---|
| 44 | height: 0,
|
|---|
| 45 | isUpdateAnimationActive: false,
|
|---|
| 46 | animationBegin: 0,
|
|---|
| 47 | animationDuration: 1500,
|
|---|
| 48 | animationEasing: 'ease'
|
|---|
| 49 | };
|
|---|
| 50 | var Trapezoid = outsideProps => {
|
|---|
| 51 | var trapezoidProps = (0, _resolveDefaultProps.resolveDefaultProps)(outsideProps, defaultTrapezoidProps);
|
|---|
| 52 | var {
|
|---|
| 53 | x,
|
|---|
| 54 | y,
|
|---|
| 55 | upperWidth,
|
|---|
| 56 | lowerWidth,
|
|---|
| 57 | height,
|
|---|
| 58 | className
|
|---|
| 59 | } = trapezoidProps;
|
|---|
| 60 | var {
|
|---|
| 61 | animationEasing,
|
|---|
| 62 | animationDuration,
|
|---|
| 63 | animationBegin,
|
|---|
| 64 | isUpdateAnimationActive
|
|---|
| 65 | } = trapezoidProps;
|
|---|
| 66 | var pathRef = (0, _react.useRef)(null);
|
|---|
| 67 | var [totalLength, setTotalLength] = (0, _react.useState)(-1);
|
|---|
| 68 | var prevUpperWidthRef = (0, _react.useRef)(upperWidth);
|
|---|
| 69 | var prevLowerWidthRef = (0, _react.useRef)(lowerWidth);
|
|---|
| 70 | var prevHeightRef = (0, _react.useRef)(height);
|
|---|
| 71 | var prevXRef = (0, _react.useRef)(x);
|
|---|
| 72 | var prevYRef = (0, _react.useRef)(y);
|
|---|
| 73 | var animationId = (0, _useAnimationId.useAnimationId)(outsideProps, 'trapezoid-');
|
|---|
| 74 | (0, _react.useEffect)(() => {
|
|---|
| 75 | if (pathRef.current && pathRef.current.getTotalLength) {
|
|---|
| 76 | try {
|
|---|
| 77 | var pathTotalLength = pathRef.current.getTotalLength();
|
|---|
| 78 | if (pathTotalLength) {
|
|---|
| 79 | setTotalLength(pathTotalLength);
|
|---|
| 80 | }
|
|---|
| 81 | } catch (_unused) {
|
|---|
| 82 | // calculate total length error
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | }, []);
|
|---|
| 86 | if (x !== +x || y !== +y || upperWidth !== +upperWidth || lowerWidth !== +lowerWidth || height !== +height || upperWidth === 0 && lowerWidth === 0 || height === 0) {
|
|---|
| 87 | return null;
|
|---|
| 88 | }
|
|---|
| 89 | var layerClass = (0, _clsx.clsx)('recharts-trapezoid', className);
|
|---|
| 90 | if (!isUpdateAnimationActive) {
|
|---|
| 91 | return /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("path", _extends({}, (0, _svgPropertiesAndEvents.svgPropertiesAndEvents)(trapezoidProps), {
|
|---|
| 92 | className: layerClass,
|
|---|
| 93 | d: getTrapezoidPath(x, y, upperWidth, lowerWidth, height)
|
|---|
| 94 | })));
|
|---|
| 95 | }
|
|---|
| 96 | var prevUpperWidth = prevUpperWidthRef.current;
|
|---|
| 97 | var prevLowerWidth = prevLowerWidthRef.current;
|
|---|
| 98 | var prevHeight = prevHeightRef.current;
|
|---|
| 99 | var prevX = prevXRef.current;
|
|---|
| 100 | var prevY = prevYRef.current;
|
|---|
| 101 | var from = "0px ".concat(totalLength === -1 ? 1 : totalLength, "px");
|
|---|
| 102 | var to = "".concat(totalLength, "px 0px");
|
|---|
| 103 | var transition = (0, _util.getTransitionVal)(['strokeDasharray'], animationDuration, animationEasing);
|
|---|
| 104 | return /*#__PURE__*/React.createElement(_JavascriptAnimate.JavascriptAnimate, {
|
|---|
| 105 | animationId: animationId,
|
|---|
| 106 | key: animationId,
|
|---|
| 107 | canBegin: totalLength > 0,
|
|---|
| 108 | duration: animationDuration,
|
|---|
| 109 | easing: animationEasing,
|
|---|
| 110 | isActive: isUpdateAnimationActive,
|
|---|
| 111 | begin: animationBegin
|
|---|
| 112 | }, t => {
|
|---|
| 113 | var currUpperWidth = (0, _DataUtils.interpolate)(prevUpperWidth, upperWidth, t);
|
|---|
| 114 | var currLowerWidth = (0, _DataUtils.interpolate)(prevLowerWidth, lowerWidth, t);
|
|---|
| 115 | var currHeight = (0, _DataUtils.interpolate)(prevHeight, height, t);
|
|---|
| 116 | var currX = (0, _DataUtils.interpolate)(prevX, x, t);
|
|---|
| 117 | var currY = (0, _DataUtils.interpolate)(prevY, y, t);
|
|---|
| 118 | if (pathRef.current) {
|
|---|
| 119 | prevUpperWidthRef.current = currUpperWidth;
|
|---|
| 120 | prevLowerWidthRef.current = currLowerWidth;
|
|---|
| 121 | prevHeightRef.current = currHeight;
|
|---|
| 122 | prevXRef.current = currX;
|
|---|
| 123 | prevYRef.current = currY;
|
|---|
| 124 | }
|
|---|
| 125 | var animationStyle = t > 0 ? {
|
|---|
| 126 | transition,
|
|---|
| 127 | strokeDasharray: to
|
|---|
| 128 | } : {
|
|---|
| 129 | strokeDasharray: from
|
|---|
| 130 | };
|
|---|
| 131 | return /*#__PURE__*/React.createElement("path", _extends({}, (0, _svgPropertiesAndEvents.svgPropertiesAndEvents)(trapezoidProps), {
|
|---|
| 132 | className: layerClass,
|
|---|
| 133 | d: getTrapezoidPath(currX, currY, currUpperWidth, currLowerWidth, currHeight),
|
|---|
| 134 | ref: pathRef,
|
|---|
| 135 | style: _objectSpread(_objectSpread({}, animationStyle), trapezoidProps.style)
|
|---|
| 136 | }));
|
|---|
| 137 | });
|
|---|
| 138 | };
|
|---|
| 139 | exports.Trapezoid = Trapezoid; |
|---|