| [a762898] | 1 | var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|---|
| 2 | 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); }
|
|---|
| 3 | function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
|
|---|
| 4 | import * as React from 'react';
|
|---|
| 5 | import { clsx } from 'clsx';
|
|---|
| 6 | import { polarToCartesian, RADIAN } from '../util/PolarUtils';
|
|---|
| 7 | import { getPercentValue, mathSign } from '../util/DataUtils';
|
|---|
| 8 | import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|---|
| 9 | import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents';
|
|---|
| 10 | import { roundTemplateLiteral } from '../util/round';
|
|---|
| 11 | var getDeltaAngle = (startAngle, endAngle) => {
|
|---|
| 12 | var sign = mathSign(endAngle - startAngle);
|
|---|
| 13 | var deltaAngle = Math.min(Math.abs(endAngle - startAngle), 359.999);
|
|---|
| 14 | return sign * deltaAngle;
|
|---|
| 15 | };
|
|---|
| 16 | var getTangentCircle = _ref => {
|
|---|
| 17 | var {
|
|---|
| 18 | cx,
|
|---|
| 19 | cy,
|
|---|
| 20 | radius,
|
|---|
| 21 | angle,
|
|---|
| 22 | sign,
|
|---|
| 23 | isExternal,
|
|---|
| 24 | cornerRadius,
|
|---|
| 25 | cornerIsExternal
|
|---|
| 26 | } = _ref;
|
|---|
| 27 | var centerRadius = cornerRadius * (isExternal ? 1 : -1) + radius;
|
|---|
| 28 | var theta = Math.asin(cornerRadius / centerRadius) / RADIAN;
|
|---|
| 29 | var centerAngle = cornerIsExternal ? angle : angle + sign * theta;
|
|---|
| 30 | var center = polarToCartesian(cx, cy, centerRadius, centerAngle);
|
|---|
| 31 | // The coordinate of point which is tangent to the circle
|
|---|
| 32 | var circleTangency = polarToCartesian(cx, cy, radius, centerAngle);
|
|---|
| 33 | // The coordinate of point which is tangent to the radius line
|
|---|
| 34 | var lineTangencyAngle = cornerIsExternal ? angle - sign * theta : angle;
|
|---|
| 35 | var lineTangency = polarToCartesian(cx, cy, centerRadius * Math.cos(theta * RADIAN), lineTangencyAngle);
|
|---|
| 36 | return {
|
|---|
| 37 | center,
|
|---|
| 38 | circleTangency,
|
|---|
| 39 | lineTangency,
|
|---|
| 40 | theta
|
|---|
| 41 | };
|
|---|
| 42 | };
|
|---|
| 43 | var getSectorPath = _ref2 => {
|
|---|
| 44 | var {
|
|---|
| 45 | cx,
|
|---|
| 46 | cy,
|
|---|
| 47 | innerRadius,
|
|---|
| 48 | outerRadius,
|
|---|
| 49 | startAngle,
|
|---|
| 50 | endAngle
|
|---|
| 51 | } = _ref2;
|
|---|
| 52 | var angle = getDeltaAngle(startAngle, endAngle);
|
|---|
| 53 |
|
|---|
| 54 | // When the angle of sector equals to 360, star point and end point coincide
|
|---|
| 55 | var tempEndAngle = startAngle + angle;
|
|---|
| 56 | var outerStartPoint = polarToCartesian(cx, cy, outerRadius, startAngle);
|
|---|
| 57 | var outerEndPoint = polarToCartesian(cx, cy, outerRadius, tempEndAngle);
|
|---|
| 58 | var path = roundTemplateLiteral(_templateObject || (_templateObject = _taggedTemplateLiteral(["M ", ",", "\n A ", ",", ",0,\n ", ",", ",\n ", ",", "\n "])), outerStartPoint.x, outerStartPoint.y, outerRadius, outerRadius, +(Math.abs(angle) > 180), +(startAngle > tempEndAngle), outerEndPoint.x, outerEndPoint.y);
|
|---|
| 59 | if (innerRadius > 0) {
|
|---|
| 60 | var innerStartPoint = polarToCartesian(cx, cy, innerRadius, startAngle);
|
|---|
| 61 | var innerEndPoint = polarToCartesian(cx, cy, innerRadius, tempEndAngle);
|
|---|
| 62 | path += roundTemplateLiteral(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["L ", ",", "\n A ", ",", ",0,\n ", ",", ",\n ", ",", " Z"])), innerEndPoint.x, innerEndPoint.y, innerRadius, innerRadius, +(Math.abs(angle) > 180), +(startAngle <= tempEndAngle), innerStartPoint.x, innerStartPoint.y);
|
|---|
| 63 | } else {
|
|---|
| 64 | path += roundTemplateLiteral(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["L ", ",", " Z"])), cx, cy);
|
|---|
| 65 | }
|
|---|
| 66 | return path;
|
|---|
| 67 | };
|
|---|
| 68 | var getSectorWithCorner = _ref3 => {
|
|---|
| 69 | var {
|
|---|
| 70 | cx,
|
|---|
| 71 | cy,
|
|---|
| 72 | innerRadius,
|
|---|
| 73 | outerRadius,
|
|---|
| 74 | cornerRadius,
|
|---|
| 75 | forceCornerRadius,
|
|---|
| 76 | cornerIsExternal,
|
|---|
| 77 | startAngle,
|
|---|
| 78 | endAngle
|
|---|
| 79 | } = _ref3;
|
|---|
| 80 | var sign = mathSign(endAngle - startAngle);
|
|---|
| 81 | var {
|
|---|
| 82 | circleTangency: soct,
|
|---|
| 83 | lineTangency: solt,
|
|---|
| 84 | theta: sot
|
|---|
| 85 | } = getTangentCircle({
|
|---|
| 86 | cx,
|
|---|
| 87 | cy,
|
|---|
| 88 | radius: outerRadius,
|
|---|
| 89 | angle: startAngle,
|
|---|
| 90 | sign,
|
|---|
| 91 | cornerRadius,
|
|---|
| 92 | cornerIsExternal
|
|---|
| 93 | });
|
|---|
| 94 | var {
|
|---|
| 95 | circleTangency: eoct,
|
|---|
| 96 | lineTangency: eolt,
|
|---|
| 97 | theta: eot
|
|---|
| 98 | } = getTangentCircle({
|
|---|
| 99 | cx,
|
|---|
| 100 | cy,
|
|---|
| 101 | radius: outerRadius,
|
|---|
| 102 | angle: endAngle,
|
|---|
| 103 | sign: -sign,
|
|---|
| 104 | cornerRadius,
|
|---|
| 105 | cornerIsExternal
|
|---|
| 106 | });
|
|---|
| 107 | var outerArcAngle = cornerIsExternal ? Math.abs(startAngle - endAngle) : Math.abs(startAngle - endAngle) - sot - eot;
|
|---|
| 108 | if (outerArcAngle < 0) {
|
|---|
| 109 | if (forceCornerRadius) {
|
|---|
| 110 | return roundTemplateLiteral(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["M ", ",", "\n a", ",", ",0,0,1,", ",0\n a", ",", ",0,0,1,", ",0\n "])), solt.x, solt.y, cornerRadius, cornerRadius, cornerRadius * 2, cornerRadius, cornerRadius, -cornerRadius * 2);
|
|---|
| 111 | }
|
|---|
| 112 | return getSectorPath({
|
|---|
| 113 | cx,
|
|---|
| 114 | cy,
|
|---|
| 115 | innerRadius,
|
|---|
| 116 | outerRadius,
|
|---|
| 117 | startAngle,
|
|---|
| 118 | endAngle
|
|---|
| 119 | });
|
|---|
| 120 | }
|
|---|
| 121 | var path = roundTemplateLiteral(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["M ", ",", "\n A", ",", ",0,0,", ",", ",", "\n A", ",", ",0,", ",", ",", ",", "\n A", ",", ",0,0,", ",", ",", "\n "])), solt.x, solt.y, cornerRadius, cornerRadius, +(sign < 0), soct.x, soct.y, outerRadius, outerRadius, +(outerArcAngle > 180), +(sign < 0), eoct.x, eoct.y, cornerRadius, cornerRadius, +(sign < 0), eolt.x, eolt.y);
|
|---|
| 122 | if (innerRadius > 0) {
|
|---|
| 123 | var {
|
|---|
| 124 | circleTangency: sict,
|
|---|
| 125 | lineTangency: silt,
|
|---|
| 126 | theta: sit
|
|---|
| 127 | } = getTangentCircle({
|
|---|
| 128 | cx,
|
|---|
| 129 | cy,
|
|---|
| 130 | radius: innerRadius,
|
|---|
| 131 | angle: startAngle,
|
|---|
| 132 | sign,
|
|---|
| 133 | isExternal: true,
|
|---|
| 134 | cornerRadius,
|
|---|
| 135 | cornerIsExternal
|
|---|
| 136 | });
|
|---|
| 137 | var {
|
|---|
| 138 | circleTangency: eict,
|
|---|
| 139 | lineTangency: eilt,
|
|---|
| 140 | theta: eit
|
|---|
| 141 | } = getTangentCircle({
|
|---|
| 142 | cx,
|
|---|
| 143 | cy,
|
|---|
| 144 | radius: innerRadius,
|
|---|
| 145 | angle: endAngle,
|
|---|
| 146 | sign: -sign,
|
|---|
| 147 | isExternal: true,
|
|---|
| 148 | cornerRadius,
|
|---|
| 149 | cornerIsExternal
|
|---|
| 150 | });
|
|---|
| 151 | var innerArcAngle = cornerIsExternal ? Math.abs(startAngle - endAngle) : Math.abs(startAngle - endAngle) - sit - eit;
|
|---|
| 152 | if (innerArcAngle < 0 && cornerRadius === 0) {
|
|---|
| 153 | return "".concat(path, "L").concat(cx, ",").concat(cy, "Z");
|
|---|
| 154 | }
|
|---|
| 155 | path += roundTemplateLiteral(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["L", ",", "\n A", ",", ",0,0,", ",", ",", "\n A", ",", ",0,", ",", ",", ",", "\n A", ",", ",0,0,", ",", ",", "Z"])), eilt.x, eilt.y, cornerRadius, cornerRadius, +(sign < 0), eict.x, eict.y, innerRadius, innerRadius, +(innerArcAngle > 180), +(sign > 0), sict.x, sict.y, cornerRadius, cornerRadius, +(sign < 0), silt.x, silt.y);
|
|---|
| 156 | } else {
|
|---|
| 157 | path += roundTemplateLiteral(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["L", ",", "Z"])), cx, cy);
|
|---|
| 158 | }
|
|---|
| 159 | return path;
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | /**
|
|---|
| 163 | * SVG cx, cy are `string | number | undefined`, but internally we use `number` so let's
|
|---|
| 164 | * override the types here.
|
|---|
| 165 | */
|
|---|
| 166 |
|
|---|
| 167 | export var defaultSectorProps = {
|
|---|
| 168 | cx: 0,
|
|---|
| 169 | cy: 0,
|
|---|
| 170 | innerRadius: 0,
|
|---|
| 171 | outerRadius: 0,
|
|---|
| 172 | startAngle: 0,
|
|---|
| 173 | endAngle: 0,
|
|---|
| 174 | cornerRadius: 0,
|
|---|
| 175 | forceCornerRadius: false,
|
|---|
| 176 | cornerIsExternal: false
|
|---|
| 177 | };
|
|---|
| 178 | export var Sector = sectorProps => {
|
|---|
| 179 | var props = resolveDefaultProps(sectorProps, defaultSectorProps);
|
|---|
| 180 | var {
|
|---|
| 181 | cx,
|
|---|
| 182 | cy,
|
|---|
| 183 | innerRadius,
|
|---|
| 184 | outerRadius,
|
|---|
| 185 | cornerRadius,
|
|---|
| 186 | forceCornerRadius,
|
|---|
| 187 | cornerIsExternal,
|
|---|
| 188 | startAngle,
|
|---|
| 189 | endAngle,
|
|---|
| 190 | className
|
|---|
| 191 | } = props;
|
|---|
| 192 | if (outerRadius < innerRadius || startAngle === endAngle) {
|
|---|
| 193 | return null;
|
|---|
| 194 | }
|
|---|
| 195 | var layerClass = clsx('recharts-sector', className);
|
|---|
| 196 | var deltaRadius = outerRadius - innerRadius;
|
|---|
| 197 | var cr = getPercentValue(cornerRadius, deltaRadius, 0, true);
|
|---|
| 198 | var path;
|
|---|
| 199 | if (cr > 0 && Math.abs(startAngle - endAngle) < 360) {
|
|---|
| 200 | path = getSectorWithCorner({
|
|---|
| 201 | cx,
|
|---|
| 202 | cy,
|
|---|
| 203 | innerRadius,
|
|---|
| 204 | outerRadius,
|
|---|
| 205 | cornerRadius: Math.min(cr, deltaRadius / 2),
|
|---|
| 206 | forceCornerRadius,
|
|---|
| 207 | cornerIsExternal,
|
|---|
| 208 | startAngle,
|
|---|
| 209 | endAngle
|
|---|
| 210 | });
|
|---|
| 211 | } else {
|
|---|
| 212 | path = getSectorPath({
|
|---|
| 213 | cx,
|
|---|
| 214 | cy,
|
|---|
| 215 | innerRadius,
|
|---|
| 216 | outerRadius,
|
|---|
| 217 | startAngle,
|
|---|
| 218 | endAngle
|
|---|
| 219 | });
|
|---|
| 220 | }
|
|---|
| 221 | return /*#__PURE__*/React.createElement("path", _extends({}, svgPropertiesAndEvents(props), {
|
|---|
| 222 | className: layerClass,
|
|---|
| 223 | d: path
|
|---|
| 224 | }));
|
|---|
| 225 | }; |
|---|