| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.RadialBar = RadialBar;
|
|---|
| 7 | exports.computeRadialBarDataItems = computeRadialBarDataItems;
|
|---|
| 8 | exports.defaultRadialBarProps = void 0;
|
|---|
| 9 | var _react = _interopRequireWildcard(require("react"));
|
|---|
| 10 | var React = _react;
|
|---|
| 11 | var _clsx = require("clsx");
|
|---|
| 12 | var _RadialBarUtils = require("../util/RadialBarUtils");
|
|---|
| 13 | var _Layer = require("../container/Layer");
|
|---|
| 14 | var _ReactUtils = require("../util/ReactUtils");
|
|---|
| 15 | var _LabelList = require("../component/LabelList");
|
|---|
| 16 | var _Cell = require("../component/Cell");
|
|---|
| 17 | var _DataUtils = require("../util/DataUtils");
|
|---|
| 18 | var _ChartUtils = require("../util/ChartUtils");
|
|---|
| 19 | var _types = require("../util/types");
|
|---|
| 20 | var _tooltipContext = require("../context/tooltipContext");
|
|---|
| 21 | var _SetTooltipEntrySettings = require("../state/SetTooltipEntrySettings");
|
|---|
| 22 | var _radialBarSelectors = require("../state/selectors/radialBarSelectors");
|
|---|
| 23 | var _hooks = require("../state/hooks");
|
|---|
| 24 | var _tooltipSelectors = require("../state/selectors/tooltipSelectors");
|
|---|
| 25 | var _SetLegendPayload = require("../state/SetLegendPayload");
|
|---|
| 26 | var _useAnimationId = require("../util/useAnimationId");
|
|---|
| 27 | var _RegisterGraphicalItemId = require("../context/RegisterGraphicalItemId");
|
|---|
| 28 | var _SetGraphicalItem = require("../state/SetGraphicalItem");
|
|---|
| 29 | var _svgPropertiesNoEvents = require("../util/svgPropertiesNoEvents");
|
|---|
| 30 | var _JavascriptAnimate = require("../animation/JavascriptAnimate");
|
|---|
| 31 | var _resolveDefaultProps = require("../util/resolveDefaultProps");
|
|---|
| 32 | var _ZIndexLayer = require("../zIndex/ZIndexLayer");
|
|---|
| 33 | var _DefaultZIndexes = require("../zIndex/DefaultZIndexes");
|
|---|
| 34 | var _getZIndexFromUnknown = require("../zIndex/getZIndexFromUnknown");
|
|---|
| 35 | var _excluded = ["shape", "activeShape", "cornerRadius", "id"],
|
|---|
| 36 | _excluded2 = ["onMouseEnter", "onClick", "onMouseLeave"],
|
|---|
| 37 | _excluded3 = ["value", "background"];
|
|---|
| 38 | 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); }
|
|---|
| 39 | 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); }
|
|---|
| 40 | 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; }
|
|---|
| 41 | 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; }
|
|---|
| 42 | 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; }
|
|---|
| 43 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 44 | 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); }
|
|---|
| 45 | 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; }
|
|---|
| 46 | 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; }
|
|---|
| 47 | var STABLE_EMPTY_ARRAY = [];
|
|---|
| 48 | function RadialBarLabelListProvider(_ref) {
|
|---|
| 49 | var {
|
|---|
| 50 | showLabels,
|
|---|
| 51 | sectors,
|
|---|
| 52 | children
|
|---|
| 53 | } = _ref;
|
|---|
| 54 | var labelListEntries = sectors.map(sector => ({
|
|---|
| 55 | value: sector.value,
|
|---|
| 56 | payload: sector.payload,
|
|---|
| 57 | parentViewBox: undefined,
|
|---|
| 58 | clockWise: false,
|
|---|
| 59 | viewBox: {
|
|---|
| 60 | cx: sector.cx,
|
|---|
| 61 | cy: sector.cy,
|
|---|
| 62 | innerRadius: sector.innerRadius,
|
|---|
| 63 | outerRadius: sector.outerRadius,
|
|---|
| 64 | startAngle: sector.startAngle,
|
|---|
| 65 | endAngle: sector.endAngle,
|
|---|
| 66 | clockWise: false
|
|---|
| 67 | },
|
|---|
| 68 | fill: sector.fill
|
|---|
| 69 | }));
|
|---|
| 70 | return /*#__PURE__*/React.createElement(_LabelList.PolarLabelListContextProvider, {
|
|---|
| 71 | value: showLabels ? labelListEntries : undefined
|
|---|
| 72 | }, children);
|
|---|
| 73 | }
|
|---|
| 74 | function RadialBarSectors(_ref2) {
|
|---|
| 75 | var {
|
|---|
| 76 | sectors,
|
|---|
| 77 | allOtherRadialBarProps,
|
|---|
| 78 | showLabels
|
|---|
| 79 | } = _ref2;
|
|---|
| 80 | var {
|
|---|
| 81 | shape,
|
|---|
| 82 | activeShape,
|
|---|
| 83 | cornerRadius,
|
|---|
| 84 | id
|
|---|
| 85 | } = allOtherRadialBarProps,
|
|---|
| 86 | others = _objectWithoutProperties(allOtherRadialBarProps, _excluded);
|
|---|
| 87 | var baseProps = (0, _svgPropertiesNoEvents.svgPropertiesNoEvents)(others);
|
|---|
| 88 | var activeIndex = (0, _hooks.useAppSelector)(_tooltipSelectors.selectActiveTooltipIndex);
|
|---|
| 89 | var {
|
|---|
| 90 | onMouseEnter: onMouseEnterFromProps,
|
|---|
| 91 | onClick: onItemClickFromProps,
|
|---|
| 92 | onMouseLeave: onMouseLeaveFromProps
|
|---|
| 93 | } = allOtherRadialBarProps,
|
|---|
| 94 | restOfAllOtherProps = _objectWithoutProperties(allOtherRadialBarProps, _excluded2);
|
|---|
| 95 | var onMouseEnterFromContext = (0, _tooltipContext.useMouseEnterItemDispatch)(onMouseEnterFromProps, allOtherRadialBarProps.dataKey, id);
|
|---|
| 96 | var onMouseLeaveFromContext = (0, _tooltipContext.useMouseLeaveItemDispatch)(onMouseLeaveFromProps);
|
|---|
| 97 | var onClickFromContext = (0, _tooltipContext.useMouseClickItemDispatch)(onItemClickFromProps, allOtherRadialBarProps.dataKey, id);
|
|---|
| 98 | if (sectors == null) {
|
|---|
| 99 | return null;
|
|---|
| 100 | }
|
|---|
| 101 | return /*#__PURE__*/React.createElement(RadialBarLabelListProvider, {
|
|---|
| 102 | showLabels: showLabels,
|
|---|
| 103 | sectors: sectors
|
|---|
| 104 | }, sectors.map((entry, i) => {
|
|---|
| 105 | var isActive = activeShape && activeIndex === String(i);
|
|---|
| 106 | // @ts-expect-error the types need a bit of attention
|
|---|
| 107 | var onMouseEnter = onMouseEnterFromContext(entry, i);
|
|---|
| 108 | // @ts-expect-error the types need a bit of attention
|
|---|
| 109 | var onMouseLeave = onMouseLeaveFromContext(entry, i);
|
|---|
| 110 | // @ts-expect-error the types need a bit of attention
|
|---|
| 111 | var onClick = onClickFromContext(entry, i);
|
|---|
| 112 | var radialBarSectorProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, baseProps), {}, {
|
|---|
| 113 | cornerRadius: (0, _RadialBarUtils.parseCornerRadius)(cornerRadius)
|
|---|
| 114 | }, entry), (0, _types.adaptEventsOfChild)(restOfAllOtherProps, entry, i)), {}, {
|
|---|
| 115 | onMouseEnter,
|
|---|
| 116 | onMouseLeave,
|
|---|
| 117 | onClick,
|
|---|
| 118 | className: "recharts-radial-bar-sector ".concat(entry.className),
|
|---|
| 119 | forceCornerRadius: others.forceCornerRadius,
|
|---|
| 120 | cornerIsExternal: others.cornerIsExternal,
|
|---|
| 121 | isActive,
|
|---|
| 122 | option: isActive ? activeShape : shape
|
|---|
| 123 | });
|
|---|
| 124 | if (isActive) {
|
|---|
| 125 | return /*#__PURE__*/React.createElement(_ZIndexLayer.ZIndexLayer, {
|
|---|
| 126 | zIndex: _DefaultZIndexes.DefaultZIndexes.activeBar,
|
|---|
| 127 | key: "sector-".concat(entry.cx, "-").concat(entry.cy, "-").concat(entry.innerRadius, "-").concat(entry.outerRadius, "-").concat(entry.startAngle, "-").concat(entry.endAngle, "-").concat(i)
|
|---|
| 128 | }, /*#__PURE__*/React.createElement(_RadialBarUtils.RadialBarSector, radialBarSectorProps));
|
|---|
| 129 | }
|
|---|
| 130 | return /*#__PURE__*/React.createElement(_RadialBarUtils.RadialBarSector, _extends({
|
|---|
| 131 | key: "sector-".concat(entry.cx, "-").concat(entry.cy, "-").concat(entry.innerRadius, "-").concat(entry.outerRadius, "-").concat(entry.startAngle, "-").concat(entry.endAngle, "-").concat(i)
|
|---|
| 132 | }, radialBarSectorProps));
|
|---|
| 133 | }), /*#__PURE__*/React.createElement(_LabelList.LabelListFromLabelProp, {
|
|---|
| 134 | label: allOtherRadialBarProps.label
|
|---|
| 135 | }), allOtherRadialBarProps.children);
|
|---|
| 136 | }
|
|---|
| 137 | function SectorsWithAnimation(_ref3) {
|
|---|
| 138 | var {
|
|---|
| 139 | props,
|
|---|
| 140 | previousSectorsRef
|
|---|
| 141 | } = _ref3;
|
|---|
| 142 | var {
|
|---|
| 143 | sectors,
|
|---|
| 144 | isAnimationActive,
|
|---|
| 145 | animationBegin,
|
|---|
| 146 | animationDuration,
|
|---|
| 147 | animationEasing,
|
|---|
| 148 | onAnimationEnd,
|
|---|
| 149 | onAnimationStart
|
|---|
| 150 | } = props;
|
|---|
| 151 | var animationId = (0, _useAnimationId.useAnimationId)(props, 'recharts-radialbar-');
|
|---|
| 152 | var prevData = previousSectorsRef.current;
|
|---|
| 153 | var [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|---|
| 154 | var handleAnimationEnd = (0, _react.useCallback)(() => {
|
|---|
| 155 | if (typeof onAnimationEnd === 'function') {
|
|---|
| 156 | onAnimationEnd();
|
|---|
| 157 | }
|
|---|
| 158 | setIsAnimating(false);
|
|---|
| 159 | }, [onAnimationEnd]);
|
|---|
| 160 | var handleAnimationStart = (0, _react.useCallback)(() => {
|
|---|
| 161 | if (typeof onAnimationStart === 'function') {
|
|---|
| 162 | onAnimationStart();
|
|---|
| 163 | }
|
|---|
| 164 | setIsAnimating(true);
|
|---|
| 165 | }, [onAnimationStart]);
|
|---|
| 166 | return /*#__PURE__*/React.createElement(_JavascriptAnimate.JavascriptAnimate, {
|
|---|
| 167 | animationId: animationId,
|
|---|
| 168 | begin: animationBegin,
|
|---|
| 169 | duration: animationDuration,
|
|---|
| 170 | isActive: isAnimationActive,
|
|---|
| 171 | easing: animationEasing,
|
|---|
| 172 | onAnimationStart: handleAnimationStart,
|
|---|
| 173 | onAnimationEnd: handleAnimationEnd,
|
|---|
| 174 | key: animationId
|
|---|
| 175 | }, t => {
|
|---|
| 176 | var stepData = t === 1 ? sectors : (sectors !== null && sectors !== void 0 ? sectors : STABLE_EMPTY_ARRAY).map((entry, index) => {
|
|---|
| 177 | var prev = prevData && prevData[index];
|
|---|
| 178 | if (prev) {
|
|---|
| 179 | return _objectSpread(_objectSpread({}, entry), {}, {
|
|---|
| 180 | startAngle: (0, _DataUtils.interpolate)(prev.startAngle, entry.startAngle, t),
|
|---|
| 181 | endAngle: (0, _DataUtils.interpolate)(prev.endAngle, entry.endAngle, t)
|
|---|
| 182 | });
|
|---|
| 183 | }
|
|---|
| 184 | var {
|
|---|
| 185 | endAngle,
|
|---|
| 186 | startAngle
|
|---|
| 187 | } = entry;
|
|---|
| 188 | return _objectSpread(_objectSpread({}, entry), {}, {
|
|---|
| 189 | endAngle: (0, _DataUtils.interpolate)(startAngle, endAngle, t)
|
|---|
| 190 | });
|
|---|
| 191 | });
|
|---|
| 192 | if (t > 0) {
|
|---|
| 193 | // eslint-disable-next-line no-param-reassign
|
|---|
| 194 | previousSectorsRef.current = stepData !== null && stepData !== void 0 ? stepData : null;
|
|---|
| 195 | }
|
|---|
| 196 | return /*#__PURE__*/React.createElement(_Layer.Layer, null, /*#__PURE__*/React.createElement(RadialBarSectors, {
|
|---|
| 197 | sectors: stepData !== null && stepData !== void 0 ? stepData : STABLE_EMPTY_ARRAY,
|
|---|
| 198 | allOtherRadialBarProps: props,
|
|---|
| 199 | showLabels: !isAnimating
|
|---|
| 200 | }));
|
|---|
| 201 | });
|
|---|
| 202 | }
|
|---|
| 203 | function RenderSectors(props) {
|
|---|
| 204 | var previousSectorsRef = (0, _react.useRef)(null);
|
|---|
| 205 | return /*#__PURE__*/React.createElement(SectorsWithAnimation, {
|
|---|
| 206 | props: props,
|
|---|
| 207 | previousSectorsRef: previousSectorsRef
|
|---|
| 208 | });
|
|---|
| 209 | }
|
|---|
| 210 | function SetRadialBarPayloadLegend(props) {
|
|---|
| 211 | var legendPayload = (0, _hooks.useAppSelector)(state => (0, _radialBarSelectors.selectRadialBarLegendPayload)(state, props.legendType));
|
|---|
| 212 | return /*#__PURE__*/React.createElement(_SetLegendPayload.SetPolarLegendPayload, {
|
|---|
| 213 | legendPayload: legendPayload !== null && legendPayload !== void 0 ? legendPayload : []
|
|---|
| 214 | });
|
|---|
| 215 | }
|
|---|
| 216 | var SetRadialBarTooltipEntrySettings = /*#__PURE__*/React.memo(_ref4 => {
|
|---|
| 217 | var {
|
|---|
| 218 | dataKey,
|
|---|
| 219 | sectors,
|
|---|
| 220 | stroke,
|
|---|
| 221 | strokeWidth,
|
|---|
| 222 | name,
|
|---|
| 223 | hide,
|
|---|
| 224 | fill,
|
|---|
| 225 | tooltipType,
|
|---|
| 226 | id
|
|---|
| 227 | } = _ref4;
|
|---|
| 228 | var tooltipEntrySettings = {
|
|---|
| 229 | dataDefinedOnItem: sectors,
|
|---|
| 230 | getPosition: _DataUtils.noop,
|
|---|
| 231 | settings: {
|
|---|
| 232 | graphicalItemId: id,
|
|---|
| 233 | stroke,
|
|---|
| 234 | strokeWidth,
|
|---|
| 235 | fill,
|
|---|
| 236 | nameKey: undefined,
|
|---|
| 237 | // RadialBar does not have nameKey, why?
|
|---|
| 238 | dataKey,
|
|---|
| 239 | name: (0, _ChartUtils.getTooltipNameProp)(name, dataKey),
|
|---|
| 240 | hide,
|
|---|
| 241 | type: tooltipType,
|
|---|
| 242 | color: fill,
|
|---|
| 243 | unit: '' // Why does RadialBar not support unit?
|
|---|
| 244 | }
|
|---|
| 245 | };
|
|---|
| 246 | return /*#__PURE__*/React.createElement(_SetTooltipEntrySettings.SetTooltipEntrySettings, {
|
|---|
| 247 | tooltipEntrySettings: tooltipEntrySettings
|
|---|
| 248 | });
|
|---|
| 249 | });
|
|---|
| 250 | class RadialBarWithState extends _react.PureComponent {
|
|---|
| 251 | renderBackground(sectors) {
|
|---|
| 252 | if (sectors == null) {
|
|---|
| 253 | return null;
|
|---|
| 254 | }
|
|---|
| 255 | var {
|
|---|
| 256 | cornerRadius
|
|---|
| 257 | } = this.props;
|
|---|
| 258 | var backgroundProps = (0, _svgPropertiesNoEvents.svgPropertiesNoEventsFromUnknown)(this.props.background);
|
|---|
| 259 | return /*#__PURE__*/React.createElement(_ZIndexLayer.ZIndexLayer, {
|
|---|
| 260 | zIndex: (0, _getZIndexFromUnknown.getZIndexFromUnknown)(this.props.background, _DefaultZIndexes.DefaultZIndexes.barBackground)
|
|---|
| 261 | }, sectors.map((entry, i) => {
|
|---|
| 262 | var {
|
|---|
| 263 | value,
|
|---|
| 264 | background
|
|---|
| 265 | } = entry,
|
|---|
| 266 | rest = _objectWithoutProperties(entry, _excluded3);
|
|---|
| 267 | if (!background) {
|
|---|
| 268 | return null;
|
|---|
| 269 | }
|
|---|
| 270 | var props = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|---|
| 271 | cornerRadius: (0, _RadialBarUtils.parseCornerRadius)(cornerRadius)
|
|---|
| 272 | }, rest), {}, {
|
|---|
| 273 | // @ts-expect-error backgroundProps is contributing unknown props
|
|---|
| 274 | fill: '#eee'
|
|---|
| 275 | }, background), backgroundProps), (0, _types.adaptEventsOfChild)(this.props, entry, i)), {}, {
|
|---|
| 276 | index: i,
|
|---|
| 277 | className: (0, _clsx.clsx)('recharts-radial-bar-background-sector', String(backgroundProps === null || backgroundProps === void 0 ? void 0 : backgroundProps.className)),
|
|---|
| 278 | option: background,
|
|---|
| 279 | isActive: false
|
|---|
| 280 | });
|
|---|
| 281 | return /*#__PURE__*/React.createElement(_RadialBarUtils.RadialBarSector, _extends({
|
|---|
| 282 | key: "background-".concat(rest.cx, "-").concat(rest.cy, "-").concat(rest.innerRadius, "-").concat(rest.outerRadius, "-").concat(rest.startAngle, "-").concat(rest.endAngle, "-").concat(i)
|
|---|
| 283 | }, props));
|
|---|
| 284 | }));
|
|---|
| 285 | }
|
|---|
| 286 | render() {
|
|---|
| 287 | var {
|
|---|
| 288 | hide,
|
|---|
| 289 | sectors,
|
|---|
| 290 | className,
|
|---|
| 291 | background
|
|---|
| 292 | } = this.props;
|
|---|
| 293 | if (hide) {
|
|---|
| 294 | return null;
|
|---|
| 295 | }
|
|---|
| 296 | var layerClass = (0, _clsx.clsx)('recharts-area', className);
|
|---|
| 297 | return /*#__PURE__*/React.createElement(_ZIndexLayer.ZIndexLayer, {
|
|---|
| 298 | zIndex: this.props.zIndex
|
|---|
| 299 | }, /*#__PURE__*/React.createElement(_Layer.Layer, {
|
|---|
| 300 | className: layerClass
|
|---|
| 301 | }, background && /*#__PURE__*/React.createElement(_Layer.Layer, {
|
|---|
| 302 | className: "recharts-radial-bar-background"
|
|---|
| 303 | }, this.renderBackground(sectors)), /*#__PURE__*/React.createElement(_Layer.Layer, {
|
|---|
| 304 | className: "recharts-radial-bar-sectors"
|
|---|
| 305 | }, /*#__PURE__*/React.createElement(RenderSectors, this.props))));
|
|---|
| 306 | }
|
|---|
| 307 | }
|
|---|
| 308 | function RadialBarImpl(props) {
|
|---|
| 309 | var _useAppSelector;
|
|---|
| 310 | var cells = (0, _ReactUtils.findAllByType)(props.children, _Cell.Cell);
|
|---|
| 311 | var radialBarSettings = {
|
|---|
| 312 | data: undefined,
|
|---|
| 313 | hide: false,
|
|---|
| 314 | id: props.id,
|
|---|
| 315 | dataKey: props.dataKey,
|
|---|
| 316 | minPointSize: props.minPointSize,
|
|---|
| 317 | stackId: (0, _ChartUtils.getNormalizedStackId)(props.stackId),
|
|---|
| 318 | maxBarSize: props.maxBarSize,
|
|---|
| 319 | barSize: props.barSize,
|
|---|
| 320 | type: 'radialBar',
|
|---|
| 321 | angleAxisId: props.angleAxisId,
|
|---|
| 322 | radiusAxisId: props.radiusAxisId
|
|---|
| 323 | };
|
|---|
| 324 | var sectors = (_useAppSelector = (0, _hooks.useAppSelector)(state => (0, _radialBarSelectors.selectRadialBarSectors)(state, props.radiusAxisId, props.angleAxisId, radialBarSettings, cells))) !== null && _useAppSelector !== void 0 ? _useAppSelector : STABLE_EMPTY_ARRAY;
|
|---|
| 325 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetRadialBarTooltipEntrySettings, {
|
|---|
| 326 | dataKey: props.dataKey,
|
|---|
| 327 | sectors: sectors,
|
|---|
| 328 | stroke: props.stroke,
|
|---|
| 329 | strokeWidth: props.strokeWidth,
|
|---|
| 330 | name: props.name,
|
|---|
| 331 | hide: props.hide,
|
|---|
| 332 | fill: props.fill,
|
|---|
| 333 | tooltipType: props.tooltipType,
|
|---|
| 334 | id: props.id
|
|---|
| 335 | }), /*#__PURE__*/React.createElement(RadialBarWithState, _extends({}, props, {
|
|---|
| 336 | sectors: sectors
|
|---|
| 337 | })));
|
|---|
| 338 | }
|
|---|
| 339 | var defaultRadialBarProps = exports.defaultRadialBarProps = {
|
|---|
| 340 | angleAxisId: 0,
|
|---|
| 341 | animationBegin: 0,
|
|---|
| 342 | animationDuration: 1500,
|
|---|
| 343 | animationEasing: 'ease',
|
|---|
| 344 | background: false,
|
|---|
| 345 | cornerIsExternal: false,
|
|---|
| 346 | cornerRadius: 0,
|
|---|
| 347 | forceCornerRadius: false,
|
|---|
| 348 | hide: false,
|
|---|
| 349 | isAnimationActive: 'auto',
|
|---|
| 350 | label: false,
|
|---|
| 351 | legendType: 'rect',
|
|---|
| 352 | minPointSize: 0,
|
|---|
| 353 | radiusAxisId: 0,
|
|---|
| 354 | zIndex: _DefaultZIndexes.DefaultZIndexes.bar
|
|---|
| 355 | };
|
|---|
| 356 | function computeRadialBarDataItems(_ref5) {
|
|---|
| 357 | var {
|
|---|
| 358 | displayedData,
|
|---|
| 359 | stackedData,
|
|---|
| 360 | dataStartIndex,
|
|---|
| 361 | stackedDomain,
|
|---|
| 362 | dataKey,
|
|---|
| 363 | baseValue,
|
|---|
| 364 | layout,
|
|---|
| 365 | radiusAxis,
|
|---|
| 366 | radiusAxisTicks,
|
|---|
| 367 | bandSize,
|
|---|
| 368 | pos,
|
|---|
| 369 | angleAxis,
|
|---|
| 370 | minPointSize,
|
|---|
| 371 | cx,
|
|---|
| 372 | cy,
|
|---|
| 373 | angleAxisTicks,
|
|---|
| 374 | cells,
|
|---|
| 375 | startAngle: rootStartAngle,
|
|---|
| 376 | endAngle: rootEndAngle
|
|---|
| 377 | } = _ref5;
|
|---|
| 378 | if (angleAxisTicks == null || radiusAxisTicks == null) {
|
|---|
| 379 | return STABLE_EMPTY_ARRAY;
|
|---|
| 380 | }
|
|---|
| 381 | return (displayedData !== null && displayedData !== void 0 ? displayedData : []).map((entry, index) => {
|
|---|
| 382 | var value, innerRadius, outerRadius, startAngle, endAngle, backgroundSector;
|
|---|
| 383 | if (stackedData) {
|
|---|
| 384 | // @ts-expect-error truncateByDomain expects only numerical domain, but it can received categorical domain too
|
|---|
| 385 | value = (0, _ChartUtils.truncateByDomain)(stackedData[dataStartIndex + index], stackedDomain);
|
|---|
| 386 | } else {
|
|---|
| 387 | value = (0, _ChartUtils.getValueByDataKey)(entry, dataKey);
|
|---|
| 388 | if (!Array.isArray(value)) {
|
|---|
| 389 | value = [baseValue, value];
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 | if (layout === 'radial') {
|
|---|
| 393 | var _angleAxis$scale$map, _angleAxis$scale$map2;
|
|---|
| 394 | startAngle = (_angleAxis$scale$map = angleAxis.scale.map(value[0])) !== null && _angleAxis$scale$map !== void 0 ? _angleAxis$scale$map : rootStartAngle;
|
|---|
| 395 | endAngle = (_angleAxis$scale$map2 = angleAxis.scale.map(value[1])) !== null && _angleAxis$scale$map2 !== void 0 ? _angleAxis$scale$map2 : rootEndAngle;
|
|---|
| 396 | innerRadius = (0, _ChartUtils.getCateCoordinateOfBar)({
|
|---|
| 397 | axis: radiusAxis,
|
|---|
| 398 | ticks: radiusAxisTicks,
|
|---|
| 399 | bandSize,
|
|---|
| 400 | offset: pos.offset,
|
|---|
| 401 | entry,
|
|---|
| 402 | index
|
|---|
| 403 | });
|
|---|
| 404 | if (innerRadius != null && endAngle != null && startAngle != null) {
|
|---|
| 405 | outerRadius = innerRadius + pos.size;
|
|---|
| 406 | var deltaAngle = endAngle - startAngle;
|
|---|
| 407 | if (Math.abs(minPointSize) > 0 && Math.abs(deltaAngle) < Math.abs(minPointSize)) {
|
|---|
| 408 | var delta = (0, _DataUtils.mathSign)(deltaAngle || minPointSize) * (Math.abs(minPointSize) - Math.abs(deltaAngle));
|
|---|
| 409 | endAngle += delta;
|
|---|
| 410 | }
|
|---|
| 411 | backgroundSector = {
|
|---|
| 412 | background: {
|
|---|
| 413 | cx,
|
|---|
| 414 | cy,
|
|---|
| 415 | innerRadius,
|
|---|
| 416 | outerRadius,
|
|---|
| 417 | startAngle: rootStartAngle,
|
|---|
| 418 | endAngle: rootEndAngle
|
|---|
| 419 | }
|
|---|
| 420 | };
|
|---|
| 421 | }
|
|---|
| 422 | } else {
|
|---|
| 423 | innerRadius = radiusAxis.scale.map(value[0]);
|
|---|
| 424 | outerRadius = radiusAxis.scale.map(value[1]);
|
|---|
| 425 | startAngle = (0, _ChartUtils.getCateCoordinateOfBar)({
|
|---|
| 426 | axis: angleAxis,
|
|---|
| 427 | ticks: angleAxisTicks,
|
|---|
| 428 | bandSize,
|
|---|
| 429 | offset: pos.offset,
|
|---|
| 430 | entry,
|
|---|
| 431 | index
|
|---|
| 432 | });
|
|---|
| 433 | if (innerRadius != null && outerRadius != null && startAngle != null) {
|
|---|
| 434 | endAngle = startAngle + pos.size;
|
|---|
| 435 | var deltaRadius = outerRadius - innerRadius;
|
|---|
| 436 | if (Math.abs(minPointSize) > 0 && Math.abs(deltaRadius) < Math.abs(minPointSize)) {
|
|---|
| 437 | var _delta = (0, _DataUtils.mathSign)(deltaRadius || minPointSize) * (Math.abs(minPointSize) - Math.abs(deltaRadius));
|
|---|
| 438 | outerRadius += _delta;
|
|---|
| 439 | }
|
|---|
| 440 | }
|
|---|
| 441 | }
|
|---|
| 442 | return _objectSpread(_objectSpread(_objectSpread({}, entry), backgroundSector), {}, {
|
|---|
| 443 | payload: entry,
|
|---|
| 444 | value: stackedData ? value : value[1],
|
|---|
| 445 | cx,
|
|---|
| 446 | cy,
|
|---|
| 447 | innerRadius,
|
|---|
| 448 | outerRadius,
|
|---|
| 449 | startAngle,
|
|---|
| 450 | // @ts-expect-error endAngle is used before assigned (?)
|
|---|
| 451 | endAngle
|
|---|
| 452 | }, cells && cells[index] && cells[index].props);
|
|---|
| 453 | });
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | /**
|
|---|
| 457 | * @consumes PolarChartContext
|
|---|
| 458 | * @provides LabelListContext
|
|---|
| 459 | * @provides CellReader
|
|---|
| 460 | */
|
|---|
| 461 | function RadialBar(outsideProps) {
|
|---|
| 462 | var props = (0, _resolveDefaultProps.resolveDefaultProps)(outsideProps, defaultRadialBarProps);
|
|---|
| 463 | return /*#__PURE__*/React.createElement(_RegisterGraphicalItemId.RegisterGraphicalItemId, {
|
|---|
| 464 | id: props.id,
|
|---|
| 465 | type: "radialBar"
|
|---|
| 466 | }, id => {
|
|---|
| 467 | var _props$hide, _props$angleAxisId, _props$radiusAxisId;
|
|---|
| 468 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_SetGraphicalItem.SetPolarGraphicalItem, {
|
|---|
| 469 | type: "radialBar",
|
|---|
| 470 | id: id,
|
|---|
| 471 | data: undefined // why does RadialBar not allow data defined on the item?
|
|---|
| 472 | ,
|
|---|
| 473 | dataKey: props.dataKey,
|
|---|
| 474 | hide: (_props$hide = props.hide) !== null && _props$hide !== void 0 ? _props$hide : defaultRadialBarProps.hide,
|
|---|
| 475 | angleAxisId: (_props$angleAxisId = props.angleAxisId) !== null && _props$angleAxisId !== void 0 ? _props$angleAxisId : defaultRadialBarProps.angleAxisId,
|
|---|
| 476 | radiusAxisId: (_props$radiusAxisId = props.radiusAxisId) !== null && _props$radiusAxisId !== void 0 ? _props$radiusAxisId : defaultRadialBarProps.radiusAxisId,
|
|---|
| 477 | stackId: (0, _ChartUtils.getNormalizedStackId)(props.stackId),
|
|---|
| 478 | barSize: props.barSize,
|
|---|
| 479 | minPointSize: props.minPointSize,
|
|---|
| 480 | maxBarSize: props.maxBarSize
|
|---|
| 481 | }), /*#__PURE__*/React.createElement(SetRadialBarPayloadLegend, props), /*#__PURE__*/React.createElement(RadialBarImpl, _extends({}, props, {
|
|---|
| 482 | id: id
|
|---|
| 483 | })));
|
|---|
| 484 | });
|
|---|
| 485 | }
|
|---|
| 486 | RadialBar.displayName = 'RadialBar'; |
|---|