source: node_modules/recharts/es6/polar/PolarGrid.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: 9.0 KB
Line 
1var _excluded = ["gridType", "radialLines", "angleAxisId", "radiusAxisId", "cx", "cy", "innerRadius", "outerRadius", "polarAngles", "polarRadius", "zIndex"];
2function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
3function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4function _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); }
5function 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; }
6function _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; }
7function _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; }
8function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9function _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); }
10import { clsx } from 'clsx';
11import * as React from 'react';
12import { polarToCartesian } from '../util/PolarUtils';
13import { useAppSelector } from '../state/hooks';
14import { selectPolarGridAngles, selectPolarGridRadii } from '../state/selectors/polarGridSelectors';
15import { selectPolarViewBox } from '../state/selectors/polarAxisSelectors';
16import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
17import { ZIndexLayer } from '../zIndex/ZIndexLayer';
18import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
19import { resolveDefaultProps } from '../util/resolveDefaultProps';
20var getPolygonPath = (radius, cx, cy, polarAngles) => {
21 var path = '';
22 polarAngles.forEach((angle, i) => {
23 var point = polarToCartesian(cx, cy, radius, angle);
24 if (i) {
25 path += "L ".concat(point.x, ",").concat(point.y);
26 } else {
27 path += "M ".concat(point.x, ",").concat(point.y);
28 }
29 });
30 path += 'Z';
31 return path;
32};
33
34// Draw axis of radial line
35var PolarAngles = props => {
36 var {
37 cx,
38 cy,
39 innerRadius,
40 outerRadius,
41 polarAngles,
42 radialLines
43 } = props;
44 if (!polarAngles || !polarAngles.length || !radialLines) {
45 return null;
46 }
47 var polarAnglesProps = _objectSpread({
48 stroke: '#ccc'
49 }, svgPropertiesNoEvents(props));
50 return /*#__PURE__*/React.createElement("g", {
51 className: "recharts-polar-grid-angle"
52 }, polarAngles.map(entry => {
53 var start = polarToCartesian(cx, cy, innerRadius, entry);
54 var end = polarToCartesian(cx, cy, outerRadius, entry);
55 return /*#__PURE__*/React.createElement("line", _extends({
56 key: "line-".concat(entry)
57 }, polarAnglesProps, {
58 x1: start.x,
59 y1: start.y,
60 x2: end.x,
61 y2: end.y
62 }));
63 }));
64};
65
66// Draw concentric circles
67var ConcentricCircle = props => {
68 var {
69 cx,
70 cy,
71 radius
72 } = props;
73 var concentricCircleProps = _objectSpread({
74 stroke: '#ccc',
75 fill: 'none'
76 }, svgPropertiesNoEvents(props));
77 return (
78 /*#__PURE__*/
79 // @ts-expect-error wrong SVG element type
80 React.createElement("circle", _extends({}, concentricCircleProps, {
81 className: clsx('recharts-polar-grid-concentric-circle', props.className),
82 cx: cx,
83 cy: cy,
84 r: radius
85 }))
86 );
87};
88
89// Draw concentric polygons
90var ConcentricPolygon = props => {
91 var {
92 radius
93 } = props;
94 var concentricPolygonProps = _objectSpread({
95 stroke: '#ccc',
96 fill: 'none'
97 }, svgPropertiesNoEvents(props));
98 return /*#__PURE__*/React.createElement("path", _extends({}, concentricPolygonProps, {
99 className: clsx('recharts-polar-grid-concentric-polygon', props.className),
100 d: getPolygonPath(radius, props.cx, props.cy, props.polarAngles)
101 }));
102};
103
104// Draw concentric axis
105var ConcentricGridPath = props => {
106 var {
107 polarRadius,
108 gridType
109 } = props;
110 if (!polarRadius || !polarRadius.length) {
111 return null;
112 }
113 var maxPolarRadius = Math.max(...polarRadius);
114 var renderBackground = props.fill && props.fill !== 'none';
115 return /*#__PURE__*/React.createElement("g", {
116 className: "recharts-polar-grid-concentric"
117 }, renderBackground && gridType === 'circle' && /*#__PURE__*/React.createElement(ConcentricCircle, _extends({}, props, {
118 radius: maxPolarRadius
119 })), renderBackground && gridType !== 'circle' && /*#__PURE__*/React.createElement(ConcentricPolygon, _extends({}, props, {
120 radius: maxPolarRadius
121 })), polarRadius.map((entry, i) => {
122 var key = i;
123 if (gridType === 'circle') {
124 return /*#__PURE__*/React.createElement(ConcentricCircle, _extends({
125 key: key
126 }, props, {
127 fill: "none",
128 radius: entry
129 }));
130 }
131 return /*#__PURE__*/React.createElement(ConcentricPolygon, _extends({
132 key: key
133 }, props, {
134 fill: "none",
135 radius: entry
136 }));
137 }));
138};
139export var defaultPolarGridProps = {
140 angleAxisId: 0,
141 radiusAxisId: 0,
142 gridType: 'polygon',
143 radialLines: true,
144 zIndex: DefaultZIndexes.grid
145};
146
147/**
148 * @consumes PolarViewBoxContext
149 */
150export var PolarGrid = outsideProps => {
151 var _ref, _polarViewBox$cx, _ref2, _polarViewBox$cy, _ref3, _polarViewBox$innerRa, _ref4, _polarViewBox$outerRa;
152 var _resolveDefaultProps = resolveDefaultProps(outsideProps, defaultPolarGridProps),
153 {
154 gridType,
155 radialLines,
156 angleAxisId,
157 radiusAxisId,
158 cx: cxFromOutside,
159 cy: cyFromOutside,
160 innerRadius: innerRadiusFromOutside,
161 outerRadius: outerRadiusFromOutside,
162 polarAngles: polarAnglesInput,
163 polarRadius: polarRadiusInput,
164 zIndex
165 } = _resolveDefaultProps,
166 inputs = _objectWithoutProperties(_resolveDefaultProps, _excluded);
167 var polarViewBox = useAppSelector(selectPolarViewBox);
168 var polarAnglesFromRedux = useAppSelector(state => selectPolarGridAngles(state, angleAxisId));
169 var polarRadiiFromRedux = useAppSelector(state => selectPolarGridRadii(state, radiusAxisId));
170 var polarAngles = Array.isArray(polarAnglesInput) ? polarAnglesInput : polarAnglesFromRedux;
171 var polarRadius = Array.isArray(polarRadiusInput) ? polarRadiusInput : polarRadiiFromRedux;
172 if (polarAngles == null || polarRadius == null) {
173 return null;
174 }
175 var props = _objectSpread({
176 cx: (_ref = (_polarViewBox$cx = polarViewBox === null || polarViewBox === void 0 ? void 0 : polarViewBox.cx) !== null && _polarViewBox$cx !== void 0 ? _polarViewBox$cx : cxFromOutside) !== null && _ref !== void 0 ? _ref : 0,
177 cy: (_ref2 = (_polarViewBox$cy = polarViewBox === null || polarViewBox === void 0 ? void 0 : polarViewBox.cy) !== null && _polarViewBox$cy !== void 0 ? _polarViewBox$cy : cyFromOutside) !== null && _ref2 !== void 0 ? _ref2 : 0,
178 innerRadius: (_ref3 = (_polarViewBox$innerRa = polarViewBox === null || polarViewBox === void 0 ? void 0 : polarViewBox.innerRadius) !== null && _polarViewBox$innerRa !== void 0 ? _polarViewBox$innerRa : innerRadiusFromOutside) !== null && _ref3 !== void 0 ? _ref3 : 0,
179 outerRadius: (_ref4 = (_polarViewBox$outerRa = polarViewBox === null || polarViewBox === void 0 ? void 0 : polarViewBox.outerRadius) !== null && _polarViewBox$outerRa !== void 0 ? _polarViewBox$outerRa : outerRadiusFromOutside) !== null && _ref4 !== void 0 ? _ref4 : 0,
180 polarAngles,
181 polarRadius,
182 zIndex
183 }, inputs);
184 var {
185 outerRadius
186 } = props;
187 if (outerRadius <= 0) {
188 return null;
189 }
190 return /*#__PURE__*/React.createElement(ZIndexLayer, {
191 zIndex: props.zIndex
192 }, /*#__PURE__*/React.createElement("g", {
193 className: "recharts-polar-grid"
194 }, /*#__PURE__*/React.createElement(ConcentricGridPath, _extends({
195 gridType: gridType,
196 radialLines: radialLines
197 }, props, {
198 polarAngles: polarAngles,
199 polarRadius: polarRadius
200 })), /*#__PURE__*/React.createElement(PolarAngles, _extends({
201 gridType: gridType,
202 radialLines: radialLines
203 }, props, {
204 polarAngles: polarAngles,
205 polarRadius: polarRadius
206 }))));
207};
208PolarGrid.displayName = 'PolarGrid';
Note: See TracBrowser for help on using the repository browser.