source: node_modules/recharts/lib/shape/Sector.js@ ba17441

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

Added visualizations

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