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