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