source: node_modules/recharts/es6/cartesian/YAxis.js@ ba17441

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

Added visualizations

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