| 1 | var _excluded = ["type"],
|
|---|
| 2 | _excluded2 = ["dangerouslySetInnerHTML", "ticks", "scale"],
|
|---|
| 3 | _excluded3 = ["id", "scale"];
|
|---|
| 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 | /**
|
|---|
| 13 | * @fileOverview X Axis
|
|---|
| 14 | */
|
|---|
| 15 | import * as React from 'react';
|
|---|
| 16 | import { useLayoutEffect, useMemo, useRef } from 'react';
|
|---|
| 17 | import { clsx } from 'clsx';
|
|---|
| 18 | import { CartesianAxis, defaultCartesianAxisProps } from './CartesianAxis';
|
|---|
| 19 | import { useAppDispatch, useAppSelector } from '../state/hooks';
|
|---|
| 20 | import { addXAxis, replaceXAxis, removeXAxis } from '../state/cartesianAxisSlice';
|
|---|
| 21 | import { implicitXAxis, selectTicksOfAxis, selectXAxisPosition, selectXAxisSettingsNoDefaults, selectXAxisSize } from '../state/selectors/axisSelectors';
|
|---|
| 22 | import { selectAxisViewBox } from '../state/selectors/selectChartOffsetInternal';
|
|---|
| 23 | import { useIsPanorama } from '../context/PanoramaContext';
|
|---|
| 24 | import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|---|
| 25 | import { axisPropsAreEqual } from '../util/axisPropsAreEqual';
|
|---|
| 26 | import { useCartesianChartLayout } from '../context/chartLayoutContext';
|
|---|
| 27 | import { getAxisTypeBasedOnLayout } from '../util/getAxisTypeBasedOnLayout';
|
|---|
| 28 | function SetXAxisSettings(props) {
|
|---|
| 29 | var dispatch = useAppDispatch();
|
|---|
| 30 | var prevSettingsRef = useRef(null);
|
|---|
| 31 | var layout = useCartesianChartLayout();
|
|---|
| 32 | var {
|
|---|
| 33 | type: typeFromProps
|
|---|
| 34 | } = props,
|
|---|
| 35 | restProps = _objectWithoutProperties(props, _excluded);
|
|---|
| 36 | var evaluatedType = getAxisTypeBasedOnLayout(layout, 'xAxis', typeFromProps);
|
|---|
| 37 | var settings = useMemo(() => {
|
|---|
| 38 | if (evaluatedType == null) {
|
|---|
| 39 | return undefined;
|
|---|
| 40 | }
|
|---|
| 41 | return _objectSpread(_objectSpread({}, restProps), {}, {
|
|---|
| 42 | type: evaluatedType
|
|---|
| 43 | });
|
|---|
| 44 | }, [restProps, evaluatedType]);
|
|---|
| 45 | useLayoutEffect(() => {
|
|---|
| 46 | if (settings == null) {
|
|---|
| 47 | return;
|
|---|
| 48 | }
|
|---|
| 49 | if (prevSettingsRef.current === null) {
|
|---|
| 50 | dispatch(addXAxis(settings));
|
|---|
| 51 | } else if (prevSettingsRef.current !== settings) {
|
|---|
| 52 | dispatch(replaceXAxis({
|
|---|
| 53 | prev: prevSettingsRef.current,
|
|---|
| 54 | next: settings
|
|---|
| 55 | }));
|
|---|
| 56 | }
|
|---|
| 57 | prevSettingsRef.current = settings;
|
|---|
| 58 | }, [settings, dispatch]);
|
|---|
| 59 | useLayoutEffect(() => {
|
|---|
| 60 | return () => {
|
|---|
| 61 | if (prevSettingsRef.current) {
|
|---|
| 62 | dispatch(removeXAxis(prevSettingsRef.current));
|
|---|
| 63 | prevSettingsRef.current = null;
|
|---|
| 64 | }
|
|---|
| 65 | };
|
|---|
| 66 | }, [dispatch]);
|
|---|
| 67 | return null;
|
|---|
| 68 | }
|
|---|
| 69 | var XAxisImpl = props => {
|
|---|
| 70 | var {
|
|---|
| 71 | xAxisId,
|
|---|
| 72 | className
|
|---|
| 73 | } = props;
|
|---|
| 74 | var viewBox = useAppSelector(selectAxisViewBox);
|
|---|
| 75 | var isPanorama = useIsPanorama();
|
|---|
| 76 | var axisType = 'xAxis';
|
|---|
| 77 | var cartesianTickItems = useAppSelector(state => selectTicksOfAxis(state, axisType, xAxisId, isPanorama));
|
|---|
| 78 | var axisSize = useAppSelector(state => selectXAxisSize(state, xAxisId));
|
|---|
| 79 | var position = useAppSelector(state => selectXAxisPosition(state, xAxisId));
|
|---|
| 80 | /*
|
|---|
| 81 | * Here we select settings from the store and prefer to use them instead of the actual props
|
|---|
| 82 | * so that the chart is consistent. If we used the props directly, some components will use axis settings
|
|---|
| 83 | * from state and some from props and because there is a render step between these two, they might be showing different things.
|
|---|
| 84 | * https://github.com/recharts/recharts/issues/6257
|
|---|
| 85 | */
|
|---|
| 86 | var synchronizedSettings = useAppSelector(state => selectXAxisSettingsNoDefaults(state, xAxisId));
|
|---|
| 87 | if (axisSize == null || position == null || synchronizedSettings == null) {
|
|---|
| 88 | return null;
|
|---|
| 89 | }
|
|---|
| 90 | var {
|
|---|
| 91 | dangerouslySetInnerHTML,
|
|---|
| 92 | ticks,
|
|---|
| 93 | scale: del
|
|---|
| 94 | } = props,
|
|---|
| 95 | allOtherProps = _objectWithoutProperties(props, _excluded2);
|
|---|
| 96 | var {
|
|---|
| 97 | id,
|
|---|
| 98 | scale: del2
|
|---|
| 99 | } = synchronizedSettings,
|
|---|
| 100 | restSynchronizedSettings = _objectWithoutProperties(synchronizedSettings, _excluded3);
|
|---|
| 101 | return /*#__PURE__*/React.createElement(CartesianAxis, _extends({}, allOtherProps, restSynchronizedSettings, {
|
|---|
| 102 | x: position.x,
|
|---|
| 103 | y: position.y,
|
|---|
| 104 | width: axisSize.width,
|
|---|
| 105 | height: axisSize.height,
|
|---|
| 106 | className: clsx("recharts-".concat(axisType, " ").concat(axisType), className),
|
|---|
| 107 | viewBox: viewBox,
|
|---|
| 108 | ticks: cartesianTickItems,
|
|---|
| 109 | axisType: axisType
|
|---|
| 110 | }));
|
|---|
| 111 | };
|
|---|
| 112 | export var xAxisDefaultProps = {
|
|---|
| 113 | allowDataOverflow: implicitXAxis.allowDataOverflow,
|
|---|
| 114 | allowDecimals: implicitXAxis.allowDecimals,
|
|---|
| 115 | allowDuplicatedCategory: implicitXAxis.allowDuplicatedCategory,
|
|---|
| 116 | angle: implicitXAxis.angle,
|
|---|
| 117 | axisLine: defaultCartesianAxisProps.axisLine,
|
|---|
| 118 | height: implicitXAxis.height,
|
|---|
| 119 | hide: false,
|
|---|
| 120 | includeHidden: implicitXAxis.includeHidden,
|
|---|
| 121 | interval: implicitXAxis.interval,
|
|---|
| 122 | label: false,
|
|---|
| 123 | minTickGap: implicitXAxis.minTickGap,
|
|---|
| 124 | mirror: implicitXAxis.mirror,
|
|---|
| 125 | orientation: implicitXAxis.orientation,
|
|---|
| 126 | padding: implicitXAxis.padding,
|
|---|
| 127 | reversed: implicitXAxis.reversed,
|
|---|
| 128 | scale: implicitXAxis.scale,
|
|---|
| 129 | tick: implicitXAxis.tick,
|
|---|
| 130 | tickCount: implicitXAxis.tickCount,
|
|---|
| 131 | tickLine: defaultCartesianAxisProps.tickLine,
|
|---|
| 132 | tickSize: defaultCartesianAxisProps.tickSize,
|
|---|
| 133 | type: implicitXAxis.type,
|
|---|
| 134 | xAxisId: 0
|
|---|
| 135 | };
|
|---|
| 136 | var XAxisSettingsDispatcher = outsideProps => {
|
|---|
| 137 | var props = resolveDefaultProps(outsideProps, xAxisDefaultProps);
|
|---|
| 138 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetXAxisSettings, {
|
|---|
| 139 | allowDataOverflow: props.allowDataOverflow,
|
|---|
| 140 | allowDecimals: props.allowDecimals,
|
|---|
| 141 | allowDuplicatedCategory: props.allowDuplicatedCategory,
|
|---|
| 142 | angle: props.angle,
|
|---|
| 143 | dataKey: props.dataKey,
|
|---|
| 144 | domain: props.domain,
|
|---|
| 145 | height: props.height,
|
|---|
| 146 | hide: props.hide,
|
|---|
| 147 | id: props.xAxisId,
|
|---|
| 148 | includeHidden: props.includeHidden,
|
|---|
| 149 | interval: props.interval,
|
|---|
| 150 | minTickGap: props.minTickGap,
|
|---|
| 151 | mirror: props.mirror,
|
|---|
| 152 | name: props.name,
|
|---|
| 153 | orientation: props.orientation,
|
|---|
| 154 | padding: props.padding,
|
|---|
| 155 | reversed: props.reversed,
|
|---|
| 156 | scale: props.scale,
|
|---|
| 157 | tick: props.tick,
|
|---|
| 158 | tickCount: props.tickCount,
|
|---|
| 159 | tickFormatter: props.tickFormatter,
|
|---|
| 160 | ticks: props.ticks,
|
|---|
| 161 | type: props.type,
|
|---|
| 162 | unit: props.unit
|
|---|
| 163 | }), /*#__PURE__*/React.createElement(XAxisImpl, props));
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | /**
|
|---|
| 167 | * @consumes CartesianViewBoxContext
|
|---|
| 168 | * @provides CartesianLabelContext
|
|---|
| 169 | */
|
|---|
| 170 | export var XAxis = /*#__PURE__*/React.memo(XAxisSettingsDispatcher, axisPropsAreEqual);
|
|---|
| 171 | XAxis.displayName = 'XAxis'; |
|---|