| [a762898] | 1 | var _excluded = ["type"],
|
|---|
| 2 | _excluded2 = ["cx", "cy", "angle", "axisLine"],
|
|---|
| 3 | _excluded3 = ["angle", "tickFormatter", "stroke", "tick"];
|
|---|
| 4 | 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); }
|
|---|
| 5 | 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; }
|
|---|
| 6 | 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; }
|
|---|
| 7 | 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; }
|
|---|
| 8 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 9 | 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); }
|
|---|
| 10 | 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; }
|
|---|
| 11 | 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; }
|
|---|
| 12 | import * as React from 'react';
|
|---|
| 13 | import { useEffect, useMemo } from 'react';
|
|---|
| 14 | import maxBy from 'es-toolkit/compat/maxBy';
|
|---|
| 15 | import minBy from 'es-toolkit/compat/minBy';
|
|---|
| 16 | import { clsx } from 'clsx';
|
|---|
| 17 | import { Text } from '../component/Text';
|
|---|
| 18 | import { PolarLabelContextProvider, PolarLabelFromLabelProp } from '../component/Label';
|
|---|
| 19 | import { Layer } from '../container/Layer';
|
|---|
| 20 | import { polarToCartesian } from '../util/PolarUtils';
|
|---|
| 21 | import { adaptEventsOfChild } from '../util/types';
|
|---|
| 22 | import { addRadiusAxis, removeRadiusAxis } from '../state/polarAxisSlice';
|
|---|
| 23 | import { useAppDispatch, useAppSelector } from '../state/hooks';
|
|---|
| 24 | import { selectPolarAxisScale, selectPolarAxisTicks } from '../state/selectors/polarScaleSelectors';
|
|---|
| 25 | import { selectPolarViewBox } from '../state/selectors/polarAxisSelectors';
|
|---|
| 26 | import { defaultPolarRadiusAxisProps } from './defaultPolarRadiusAxisProps';
|
|---|
| 27 | import { svgPropertiesNoEvents, svgPropertiesNoEventsFromUnknown } from '../util/svgPropertiesNoEvents';
|
|---|
| 28 | import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|---|
| 29 | import { ZIndexLayer } from '../zIndex/ZIndexLayer';
|
|---|
| 30 | import { usePolarChartLayout } from '../context/chartLayoutContext';
|
|---|
| 31 | import { noop } from '../util/DataUtils';
|
|---|
| 32 | import { getAxisTypeBasedOnLayout } from '../util/getAxisTypeBasedOnLayout';
|
|---|
| 33 | import { getClassNameFromUnknown } from '../util/getClassNameFromUnknown';
|
|---|
| 34 | var AXIS_TYPE = 'radiusAxis';
|
|---|
| 35 | function SetRadiusAxisSettings(props) {
|
|---|
| 36 | var dispatch = useAppDispatch();
|
|---|
| 37 | var layout = usePolarChartLayout();
|
|---|
| 38 | var settings = useMemo(() => {
|
|---|
| 39 | var {
|
|---|
| 40 | type: typeFromProps
|
|---|
| 41 | } = props,
|
|---|
| 42 | rest = _objectWithoutProperties(props, _excluded);
|
|---|
| 43 | var evaluatedType = getAxisTypeBasedOnLayout(layout, 'radiusAxis', typeFromProps);
|
|---|
| 44 | if (evaluatedType == null) {
|
|---|
| 45 | return undefined;
|
|---|
| 46 | }
|
|---|
| 47 | return _objectSpread(_objectSpread({}, rest), {}, {
|
|---|
| 48 | type: evaluatedType
|
|---|
| 49 | });
|
|---|
| 50 | }, [props, layout]);
|
|---|
| 51 | useEffect(() => {
|
|---|
| 52 | if (settings == null) {
|
|---|
| 53 | return noop;
|
|---|
| 54 | }
|
|---|
| 55 | dispatch(addRadiusAxis(settings));
|
|---|
| 56 | return () => {
|
|---|
| 57 | dispatch(removeRadiusAxis(settings));
|
|---|
| 58 | };
|
|---|
| 59 | }, [dispatch, settings]);
|
|---|
| 60 | return null;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /**
|
|---|
| 64 | * Calculate the coordinate of tick
|
|---|
| 65 | * @param coordinate The radius of tick
|
|---|
| 66 | * @param angle from props
|
|---|
| 67 | * @param cx from chart
|
|---|
| 68 | * @param cy from chart
|
|---|
| 69 | * @return (x, y)
|
|---|
| 70 | */
|
|---|
| 71 | var getTickValueCoord = (_ref, angle, cx, cy) => {
|
|---|
| 72 | var {
|
|---|
| 73 | coordinate
|
|---|
| 74 | } = _ref;
|
|---|
| 75 | return polarToCartesian(cx, cy, coordinate, angle);
|
|---|
| 76 | };
|
|---|
| 77 | var getTickTextAnchor = orientation => {
|
|---|
| 78 | var textAnchor;
|
|---|
| 79 | switch (orientation) {
|
|---|
| 80 | case 'left':
|
|---|
| 81 | textAnchor = 'end';
|
|---|
| 82 | break;
|
|---|
| 83 | case 'right':
|
|---|
| 84 | textAnchor = 'start';
|
|---|
| 85 | break;
|
|---|
| 86 | default:
|
|---|
| 87 | textAnchor = 'middle';
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 | return textAnchor;
|
|---|
| 91 | };
|
|---|
| 92 | var getViewBox = (angle, cx, cy, ticks) => {
|
|---|
| 93 | var maxRadiusTick = maxBy(ticks, entry => entry.coordinate || 0);
|
|---|
| 94 | var minRadiusTick = minBy(ticks, entry => entry.coordinate || 0);
|
|---|
| 95 | return {
|
|---|
| 96 | cx,
|
|---|
| 97 | cy,
|
|---|
| 98 | startAngle: angle,
|
|---|
| 99 | endAngle: angle,
|
|---|
| 100 | innerRadius: (minRadiusTick === null || minRadiusTick === void 0 ? void 0 : minRadiusTick.coordinate) || 0,
|
|---|
| 101 | outerRadius: (maxRadiusTick === null || maxRadiusTick === void 0 ? void 0 : maxRadiusTick.coordinate) || 0,
|
|---|
| 102 | clockWise: false
|
|---|
| 103 | };
|
|---|
| 104 | };
|
|---|
| 105 | var renderAxisLine = (props, ticks) => {
|
|---|
| 106 | var {
|
|---|
| 107 | cx,
|
|---|
| 108 | cy,
|
|---|
| 109 | angle,
|
|---|
| 110 | axisLine
|
|---|
| 111 | } = props,
|
|---|
| 112 | others = _objectWithoutProperties(props, _excluded2);
|
|---|
| 113 | var extent = ticks.reduce((result, entry) => [Math.min(result[0], entry.coordinate), Math.max(result[1], entry.coordinate)], [Infinity, -Infinity]);
|
|---|
| 114 | var point0 = polarToCartesian(cx, cy, extent[0], angle);
|
|---|
| 115 | var point1 = polarToCartesian(cx, cy, extent[1], angle);
|
|---|
| 116 | var axisLineProps = _objectSpread(_objectSpread(_objectSpread({}, svgPropertiesNoEvents(others)), {}, {
|
|---|
| 117 | fill: 'none'
|
|---|
| 118 | }, svgPropertiesNoEvents(axisLine)), {}, {
|
|---|
| 119 | x1: point0.x,
|
|---|
| 120 | y1: point0.y,
|
|---|
| 121 | x2: point1.x,
|
|---|
| 122 | y2: point1.y
|
|---|
| 123 | });
|
|---|
| 124 |
|
|---|
| 125 | // @ts-expect-error wrong SVG element type
|
|---|
| 126 | return /*#__PURE__*/React.createElement("line", _extends({
|
|---|
| 127 | className: "recharts-polar-radius-axis-line"
|
|---|
| 128 | }, axisLineProps));
|
|---|
| 129 | };
|
|---|
| 130 | var renderTickItem = (option, tickProps, value) => {
|
|---|
| 131 | var tickItem;
|
|---|
| 132 | if (/*#__PURE__*/React.isValidElement(option)) {
|
|---|
| 133 | tickItem = /*#__PURE__*/React.cloneElement(option, tickProps);
|
|---|
| 134 | } else if (typeof option === 'function') {
|
|---|
| 135 | tickItem = option(tickProps);
|
|---|
| 136 | } else {
|
|---|
| 137 | tickItem = /*#__PURE__*/React.createElement(Text, _extends({}, tickProps, {
|
|---|
| 138 | className: "recharts-polar-radius-axis-tick-value"
|
|---|
| 139 | }), value);
|
|---|
| 140 | }
|
|---|
| 141 | return tickItem;
|
|---|
| 142 | };
|
|---|
| 143 | var renderTicks = (props, ticks) => {
|
|---|
| 144 | var {
|
|---|
| 145 | angle,
|
|---|
| 146 | tickFormatter,
|
|---|
| 147 | stroke,
|
|---|
| 148 | tick
|
|---|
| 149 | } = props,
|
|---|
| 150 | others = _objectWithoutProperties(props, _excluded3);
|
|---|
| 151 | var textAnchor = getTickTextAnchor(props.orientation);
|
|---|
| 152 | var axisProps = svgPropertiesNoEvents(others);
|
|---|
| 153 | var customTickProps = svgPropertiesNoEventsFromUnknown(tick);
|
|---|
| 154 | var items = ticks.map((entry, i) => {
|
|---|
| 155 | var coord = getTickValueCoord(entry, props.angle, props.cx, props.cy);
|
|---|
| 156 | var tickProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|---|
| 157 | textAnchor,
|
|---|
| 158 | transform: "rotate(".concat(90 - angle, ", ").concat(coord.x, ", ").concat(coord.y, ")")
|
|---|
| 159 | }, axisProps), {}, {
|
|---|
| 160 | stroke: 'none',
|
|---|
| 161 | fill: stroke
|
|---|
| 162 | }, customTickProps), {}, {
|
|---|
| 163 | index: i
|
|---|
| 164 | }, coord), {}, {
|
|---|
| 165 | payload: entry
|
|---|
| 166 | });
|
|---|
| 167 | return /*#__PURE__*/React.createElement(Layer, _extends({
|
|---|
| 168 | className: clsx('recharts-polar-radius-axis-tick', getClassNameFromUnknown(tick)),
|
|---|
| 169 | key: "tick-".concat(entry.coordinate)
|
|---|
| 170 | }, adaptEventsOfChild(props, entry, i)), renderTickItem(tick, tickProps, tickFormatter ? tickFormatter(entry.value, i) : entry.value));
|
|---|
| 171 | });
|
|---|
| 172 | return /*#__PURE__*/React.createElement(Layer, {
|
|---|
| 173 | className: "recharts-polar-radius-axis-ticks"
|
|---|
| 174 | }, items);
|
|---|
| 175 | };
|
|---|
| 176 | export var PolarRadiusAxisWrapper = defaultsAndInputs => {
|
|---|
| 177 | var {
|
|---|
| 178 | radiusAxisId
|
|---|
| 179 | } = defaultsAndInputs;
|
|---|
| 180 | var viewBox = useAppSelector(selectPolarViewBox);
|
|---|
| 181 | var scale = useAppSelector(state => selectPolarAxisScale(state, 'radiusAxis', radiusAxisId));
|
|---|
| 182 | var ticks = useAppSelector(state => selectPolarAxisTicks(state, 'radiusAxis', radiusAxisId, false));
|
|---|
| 183 | if (viewBox == null || !ticks || !ticks.length || scale == null) {
|
|---|
| 184 | return null;
|
|---|
| 185 | }
|
|---|
| 186 | var props = _objectSpread(_objectSpread({}, defaultsAndInputs), {}, {
|
|---|
| 187 | scale
|
|---|
| 188 | }, viewBox);
|
|---|
| 189 | var {
|
|---|
| 190 | tick,
|
|---|
| 191 | axisLine
|
|---|
| 192 | } = props;
|
|---|
| 193 | return /*#__PURE__*/React.createElement(ZIndexLayer, {
|
|---|
| 194 | zIndex: props.zIndex
|
|---|
| 195 | }, /*#__PURE__*/React.createElement(Layer, {
|
|---|
| 196 | className: clsx('recharts-polar-radius-axis', AXIS_TYPE, props.className)
|
|---|
| 197 | }, axisLine && renderAxisLine(props, ticks), tick && renderTicks(props, ticks), /*#__PURE__*/React.createElement(PolarLabelContextProvider, getViewBox(props.angle, props.cx, props.cy, ticks), /*#__PURE__*/React.createElement(PolarLabelFromLabelProp, {
|
|---|
| 198 | label: props.label
|
|---|
| 199 | }), props.children)));
|
|---|
| 200 | };
|
|---|
| 201 |
|
|---|
| 202 | /**
|
|---|
| 203 | * @provides PolarLabelContext
|
|---|
| 204 | * @consumes PolarViewBoxContext
|
|---|
| 205 | */
|
|---|
| 206 | export function PolarRadiusAxis(outsideProps) {
|
|---|
| 207 | var props = resolveDefaultProps(outsideProps, defaultPolarRadiusAxisProps);
|
|---|
| 208 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetRadiusAxisSettings, {
|
|---|
| 209 | domain: props.domain,
|
|---|
| 210 | id: props.radiusAxisId,
|
|---|
| 211 | scale: props.scale,
|
|---|
| 212 | type: props.type,
|
|---|
| 213 | dataKey: props.dataKey,
|
|---|
| 214 | unit: undefined,
|
|---|
| 215 | name: props.name,
|
|---|
| 216 | allowDuplicatedCategory: props.allowDuplicatedCategory,
|
|---|
| 217 | allowDataOverflow: props.allowDataOverflow,
|
|---|
| 218 | reversed: props.reversed,
|
|---|
| 219 | includeHidden: props.includeHidden,
|
|---|
| 220 | allowDecimals: props.allowDecimals
|
|---|
| 221 | // @ts-expect-error the type does not match. Is RadiusAxis really expecting what it says?
|
|---|
| 222 | ,
|
|---|
| 223 | ticks: props.ticks,
|
|---|
| 224 | tickCount: props.tickCount,
|
|---|
| 225 | tick: props.tick
|
|---|
| 226 | }), /*#__PURE__*/React.createElement(PolarRadiusAxisWrapper, props));
|
|---|
| 227 | }
|
|---|
| 228 | PolarRadiusAxis.displayName = 'PolarRadiusAxis'; |
|---|