source: node_modules/recharts/lib/cartesian/YAxis.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 10.7 KB
RevLine 
[a762898]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.yAxisDefaultProps = exports.YAxis = void 0;
7var _react = _interopRequireWildcard(require("react"));
8var React = _react;
9var _clsx = require("clsx");
10var _CartesianAxis = require("./CartesianAxis");
11var _cartesianAxisSlice = require("../state/cartesianAxisSlice");
12var _hooks = require("../state/hooks");
13var _axisSelectors = require("../state/selectors/axisSelectors");
14var _selectChartOffsetInternal = require("../state/selectors/selectChartOffsetInternal");
15var _PanoramaContext = require("../context/PanoramaContext");
16var _Label = require("../component/Label");
17var _resolveDefaultProps = require("../util/resolveDefaultProps");
18var _axisPropsAreEqual = require("../util/axisPropsAreEqual");
19var _chartLayoutContext = require("../context/chartLayoutContext");
20var _getAxisTypeBasedOnLayout = require("../util/getAxisTypeBasedOnLayout");
21var _excluded = ["type"],
22 _excluded2 = ["dangerouslySetInnerHTML", "ticks", "scale"],
23 _excluded3 = ["id", "scale"];
24function _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); }
25function _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); }
26function 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; }
27function _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; }
28function _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; }
29function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
30function _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); }
31function _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; }
32function _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; }
33function SetYAxisSettings(props) {
34 var dispatch = (0, _hooks.useAppDispatch)();
35 var prevSettingsRef = (0, _react.useRef)(null);
36 var layout = (0, _chartLayoutContext.useCartesianChartLayout)();
37 var {
38 type: typeFromProps
39 } = props,
40 restProps = _objectWithoutProperties(props, _excluded);
41 var evaluatedType = (0, _getAxisTypeBasedOnLayout.getAxisTypeBasedOnLayout)(layout, 'yAxis', typeFromProps);
42 var settings = (0, _react.useMemo)(() => {
43 if (evaluatedType == null) {
44 return undefined;
45 }
46 return _objectSpread(_objectSpread({}, restProps), {}, {
47 type: evaluatedType
48 });
49 }, [evaluatedType, restProps]);
50 (0, _react.useLayoutEffect)(() => {
51 if (settings == null) {
52 return;
53 }
54 if (prevSettingsRef.current === null) {
55 dispatch((0, _cartesianAxisSlice.addYAxis)(settings));
56 } else if (prevSettingsRef.current !== settings) {
57 dispatch((0, _cartesianAxisSlice.replaceYAxis)({
58 prev: prevSettingsRef.current,
59 next: settings
60 }));
61 }
62 prevSettingsRef.current = settings;
63 }, [settings, dispatch]);
64 (0, _react.useLayoutEffect)(() => {
65 return () => {
66 if (prevSettingsRef.current) {
67 dispatch((0, _cartesianAxisSlice.removeYAxis)(prevSettingsRef.current));
68 prevSettingsRef.current = null;
69 }
70 };
71 }, [dispatch]);
72 return null;
73}
74function YAxisImpl(props) {
75 var {
76 yAxisId,
77 className,
78 width,
79 label
80 } = props;
81 var cartesianAxisRef = (0, _react.useRef)(null);
82 var labelRef = (0, _react.useRef)(null);
83 var viewBox = (0, _hooks.useAppSelector)(_selectChartOffsetInternal.selectAxisViewBox);
84 var isPanorama = (0, _PanoramaContext.useIsPanorama)();
85 var dispatch = (0, _hooks.useAppDispatch)();
86 var axisType = 'yAxis';
87 var axisSize = (0, _hooks.useAppSelector)(state => (0, _axisSelectors.selectYAxisSize)(state, yAxisId));
88 var position = (0, _hooks.useAppSelector)(state => (0, _axisSelectors.selectYAxisPosition)(state, yAxisId));
89 var cartesianTickItems = (0, _hooks.useAppSelector)(state => (0, _axisSelectors.selectTicksOfAxis)(state, axisType, yAxisId, isPanorama));
90 /*
91 * Here we select settings from the store and prefer to use them instead of the actual props
92 * so that the chart is consistent. If we used the props directly, some components will use axis settings
93 * from state and some from props and because there is a render step between these two, they might be showing different things.
94 * https://github.com/recharts/recharts/issues/6257
95 */
96 var synchronizedSettings = (0, _hooks.useAppSelector)(state => (0, _axisSelectors.selectYAxisSettingsNoDefaults)(state, yAxisId));
97 (0, _react.useLayoutEffect)(() => {
98 // No dynamic width calculation is done when width !== 'auto'
99 // or when a function/react element is used for label
100 if (width !== 'auto' || !axisSize || (0, _Label.isLabelContentAFunction)(label) || /*#__PURE__*/(0, _react.isValidElement)(label) || synchronizedSettings == null) {
101 return;
102 }
103 var axisComponent = cartesianAxisRef.current;
104 if (!axisComponent) {
105 return;
106 }
107 var updatedYAxisWidth = axisComponent.getCalculatedWidth();
108
109 // if the width has changed, dispatch an action to update the width
110 if (Math.round(axisSize.width) !== Math.round(updatedYAxisWidth)) {
111 dispatch((0, _cartesianAxisSlice.updateYAxisWidth)({
112 id: yAxisId,
113 width: updatedYAxisWidth
114 }));
115 }
116 }, [
117 // The dependency on cartesianAxisRef.current is not needed because useLayoutEffect will run after every render.
118 // The ref will be populated by then.
119 // To re-run this effect when ticks change, we can depend on the ticks array from the store.
120 cartesianTickItems, axisSize, dispatch, label, yAxisId, width, synchronizedSettings]);
121 if (axisSize == null || position == null || synchronizedSettings == null) {
122 return null;
123 }
124 var {
125 dangerouslySetInnerHTML,
126 ticks,
127 scale: del
128 } = props,
129 allOtherProps = _objectWithoutProperties(props, _excluded2);
130 var {
131 id,
132 scale: del2
133 } = synchronizedSettings,
134 restSynchronizedSettings = _objectWithoutProperties(synchronizedSettings, _excluded3);
135 return /*#__PURE__*/React.createElement(_CartesianAxis.CartesianAxis, _extends({}, allOtherProps, restSynchronizedSettings, {
136 ref: cartesianAxisRef,
137 labelRef: labelRef,
138 x: position.x,
139 y: position.y,
140 tickTextProps: width === 'auto' ? {
141 width: undefined
142 } : {
143 width
144 },
145 width: axisSize.width,
146 height: axisSize.height,
147 className: (0, _clsx.clsx)("recharts-".concat(axisType, " ").concat(axisType), className),
148 viewBox: viewBox,
149 ticks: cartesianTickItems,
150 axisType: axisType
151 }));
152}
153var yAxisDefaultProps = exports.yAxisDefaultProps = {
154 allowDataOverflow: _axisSelectors.implicitYAxis.allowDataOverflow,
155 allowDecimals: _axisSelectors.implicitYAxis.allowDecimals,
156 allowDuplicatedCategory: _axisSelectors.implicitYAxis.allowDuplicatedCategory,
157 angle: _axisSelectors.implicitYAxis.angle,
158 axisLine: _CartesianAxis.defaultCartesianAxisProps.axisLine,
159 hide: false,
160 includeHidden: _axisSelectors.implicitYAxis.includeHidden,
161 interval: _axisSelectors.implicitYAxis.interval,
162 label: false,
163 minTickGap: _axisSelectors.implicitYAxis.minTickGap,
164 mirror: _axisSelectors.implicitYAxis.mirror,
165 orientation: _axisSelectors.implicitYAxis.orientation,
166 padding: _axisSelectors.implicitYAxis.padding,
167 reversed: _axisSelectors.implicitYAxis.reversed,
168 scale: _axisSelectors.implicitYAxis.scale,
169 tick: _axisSelectors.implicitYAxis.tick,
170 tickCount: _axisSelectors.implicitYAxis.tickCount,
171 tickLine: _CartesianAxis.defaultCartesianAxisProps.tickLine,
172 tickSize: _CartesianAxis.defaultCartesianAxisProps.tickSize,
173 type: _axisSelectors.implicitYAxis.type,
174 width: _axisSelectors.implicitYAxis.width,
175 yAxisId: 0
176};
177var YAxisSettingsDispatcher = outsideProps => {
178 var props = (0, _resolveDefaultProps.resolveDefaultProps)(outsideProps, yAxisDefaultProps);
179 return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetYAxisSettings, {
180 interval: props.interval,
181 id: props.yAxisId,
182 scale: props.scale,
183 type: props.type,
184 domain: props.domain,
185 allowDataOverflow: props.allowDataOverflow,
186 dataKey: props.dataKey,
187 allowDuplicatedCategory: props.allowDuplicatedCategory,
188 allowDecimals: props.allowDecimals,
189 tickCount: props.tickCount,
190 padding: props.padding,
191 includeHidden: props.includeHidden,
192 reversed: props.reversed,
193 ticks: props.ticks,
194 width: props.width,
195 orientation: props.orientation,
196 mirror: props.mirror,
197 hide: props.hide,
198 unit: props.unit,
199 name: props.name,
200 angle: props.angle,
201 minTickGap: props.minTickGap,
202 tick: props.tick,
203 tickFormatter: props.tickFormatter
204 }), /*#__PURE__*/React.createElement(YAxisImpl, props));
205};
206
207/**
208 * @consumes CartesianViewBoxContext
209 * @provides CartesianLabelContext
210 */
211var YAxis = exports.YAxis = /*#__PURE__*/React.memo(YAxisSettingsDispatcher, _axisPropsAreEqual.axisPropsAreEqual);
212YAxis.displayName = 'YAxis';
Note: See TracBrowser for help on using the repository browser.