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