source: node_modules/recharts/lib/state/selectors/axisSelectors.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: 62.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.combineRealScaleType = exports.combineNumericalDomain = exports.combineNiceTicks = exports.combineLinesDomain = exports.combineGraphicalItemsSettings = exports.combineGraphicalItemsData = exports.combineGraphicalItemTicks = exports.combineDuplicateDomain = exports.combineDotsDomain = exports.combineDomainOfStackGroups = exports.combineDomainOfAllAppliedNumericalValuesIncludingErrorValues = exports.combineDisplayedData = exports.combineCategoricalDomain = exports.combineAxisTicks = exports.combineAxisDomainWithNiceTicks = exports.combineAxisDomain = exports.combineAreasDomain = exports.combineAppliedValues = void 0;
7exports.combineScaleFunction = combineScaleFunction;
8exports.getDomainDefinition = exports.filterReferenceElements = exports.filterGraphicalNotStackedItems = exports.defaultNumericDomain = exports.combineYAxisRange = exports.combineXAxisRange = exports.combineStackGroups = void 0;
9exports.getErrorDomainByDataKey = getErrorDomainByDataKey;
10exports.implicitZAxis = exports.implicitYAxis = exports.implicitXAxis = void 0;
11exports.isErrorBarRelevantForAxisType = isErrorBarRelevantForAxisType;
12exports.itemAxisPredicate = itemAxisPredicate;
13exports.selectZAxisWithScale = exports.selectZAxisSettings = exports.selectYAxisSize = exports.selectYAxisSettingsNoDefaults = exports.selectYAxisSettings = exports.selectYAxisPosition = exports.selectXAxisSize = exports.selectXAxisSettingsNoDefaults = exports.selectXAxisSettings = exports.selectXAxisPosition = exports.selectUnfilteredCartesianItems = exports.selectTooltipAxisDataKey = exports.selectTooltipAxis = exports.selectTicksOfGraphicalItem = exports.selectTicksOfAxis = exports.selectStackedCartesianItemsSettings = exports.selectStackGroups = exports.selectSmallestDistanceBetweenValues = exports.selectRenderableAxisSettings = exports.selectReferenceLinesByAxis = exports.selectReferenceLines = exports.selectReferenceDotsByAxis = exports.selectReferenceDots = exports.selectReferenceAreasByAxis = exports.selectReferenceAreas = exports.selectRealScaleType = exports.selectNumericalDomain = exports.selectNiceTicks = exports.selectHasBar = exports.selectErrorBarsSettings = exports.selectDuplicateDomain = exports.selectDomainOfStackGroups = exports.selectDomainFromUserPreference = exports.selectDomainDefinition = exports.selectDisplayedStackedData = exports.selectDisplayedData = exports.selectChartDirection = exports.selectCategoricalDomain = exports.selectCartesianItemsSettings = exports.selectCartesianGraphicalItemsData = exports.selectCartesianAxisSize = exports.selectCalculatedYAxisPadding = exports.selectCalculatedXAxisPadding = exports.selectBaseAxis = exports.selectAxisWithScale = exports.selectAxisScale = exports.selectAxisRangeWithReverse = exports.selectAxisRange = exports.selectAxisPropsNeededForCartesianGridTicksGenerator = exports.selectAxisDomainIncludingNiceTicks = exports.selectAxisDomain = exports.selectAllYAxesOffsetSteps = exports.selectAllXAxesOffsetSteps = exports.selectAllErrorBarSettings = exports.selectAllAppliedValues = exports.mergeDomains = void 0;
14var _reselect = require("reselect");
15var _range = _interopRequireDefault(require("es-toolkit/compat/range"));
16var d3Scales = _interopRequireWildcard(require("victory-vendor/d3-scale"));
17var _chartLayoutContext = require("../../context/chartLayoutContext");
18var _ChartUtils = require("../../util/ChartUtils");
19var _dataSelectors = require("./dataSelectors");
20var _isDomainSpecifiedByUser = require("../../util/isDomainSpecifiedByUser");
21var _DataUtils = require("../../util/DataUtils");
22var _isWellBehavedNumber = require("../../util/isWellBehavedNumber");
23var _scale = require("../../util/scale");
24var _containerSelectors = require("./containerSelectors");
25var _selectAllAxes = require("./selectAllAxes");
26var _selectChartOffsetInternal = require("./selectChartOffsetInternal");
27var _brushSelectors = require("./brushSelectors");
28var _rootPropsSelectors = require("./rootPropsSelectors");
29var _polarAxisSelectors = require("./polarAxisSelectors");
30var _pickAxisType = require("./pickAxisType");
31var _pickAxisId = require("./pickAxisId");
32var _combineAxisRangeWithReverse = require("./combiners/combineAxisRangeWithReverse");
33var _Constants = require("../../util/Constants");
34var _getStackSeriesIdentifier = require("../../util/stacks/getStackSeriesIdentifier");
35var _combineDisplayedStackedData = require("./combiners/combineDisplayedStackedData");
36var _StackedGraphicalItem = require("../types/StackedGraphicalItem");
37var _numberDomainEqualityCheck = require("./numberDomainEqualityCheck");
38var _arrayEqualityCheck = require("./arrayEqualityCheck");
39var _selectTooltipAxisType = require("./selectTooltipAxisType");
40var _selectTooltipAxisId = require("./selectTooltipAxisId");
41var _RechartsScale = require("../../util/scale/RechartsScale");
42var _combineCheckedDomain = require("./combiners/combineCheckedDomain");
43function _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); }
44function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
45function 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; }
46function _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; }
47function _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; }
48function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
49function _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); }
50var defaultNumericDomain = exports.defaultNumericDomain = [0, 'auto'];
51/**
52 * If an axis is not explicitly defined as an element,
53 * we still need to render something in the chart and we need
54 * some object to hold the domain and default settings.
55 */
56var implicitXAxis = exports.implicitXAxis = {
57 allowDataOverflow: false,
58 allowDecimals: true,
59 allowDuplicatedCategory: true,
60 angle: 0,
61 dataKey: undefined,
62 domain: undefined,
63 height: 30,
64 hide: true,
65 id: 0,
66 includeHidden: false,
67 interval: 'preserveEnd',
68 minTickGap: 5,
69 mirror: false,
70 name: undefined,
71 orientation: 'bottom',
72 padding: {
73 left: 0,
74 right: 0
75 },
76 reversed: false,
77 scale: 'auto',
78 tick: true,
79 tickCount: 5,
80 tickFormatter: undefined,
81 ticks: undefined,
82 type: 'category',
83 unit: undefined
84};
85var selectXAxisSettingsNoDefaults = (state, axisId) => {
86 return state.cartesianAxis.xAxis[axisId];
87};
88exports.selectXAxisSettingsNoDefaults = selectXAxisSettingsNoDefaults;
89var selectXAxisSettings = (state, axisId) => {
90 var axis = selectXAxisSettingsNoDefaults(state, axisId);
91 if (axis == null) {
92 return implicitXAxis;
93 }
94 return axis;
95};
96
97/**
98 * If an axis is not explicitly defined as an element,
99 * we still need to render something in the chart and we need
100 * some object to hold the domain and default settings.
101 */
102exports.selectXAxisSettings = selectXAxisSettings;
103var implicitYAxis = exports.implicitYAxis = {
104 allowDataOverflow: false,
105 allowDecimals: true,
106 allowDuplicatedCategory: true,
107 angle: 0,
108 dataKey: undefined,
109 domain: defaultNumericDomain,
110 hide: true,
111 id: 0,
112 includeHidden: false,
113 interval: 'preserveEnd',
114 minTickGap: 5,
115 mirror: false,
116 name: undefined,
117 orientation: 'left',
118 padding: {
119 top: 0,
120 bottom: 0
121 },
122 reversed: false,
123 scale: 'auto',
124 tick: true,
125 tickCount: 5,
126 tickFormatter: undefined,
127 ticks: undefined,
128 type: 'number',
129 unit: undefined,
130 width: _Constants.DEFAULT_Y_AXIS_WIDTH
131};
132var selectYAxisSettingsNoDefaults = (state, axisId) => {
133 return state.cartesianAxis.yAxis[axisId];
134};
135exports.selectYAxisSettingsNoDefaults = selectYAxisSettingsNoDefaults;
136var selectYAxisSettings = (state, axisId) => {
137 var axis = selectYAxisSettingsNoDefaults(state, axisId);
138 if (axis == null) {
139 return implicitYAxis;
140 }
141 return axis;
142};
143exports.selectYAxisSettings = selectYAxisSettings;
144var implicitZAxis = exports.implicitZAxis = {
145 domain: [0, 'auto'],
146 includeHidden: false,
147 reversed: false,
148 allowDataOverflow: false,
149 allowDuplicatedCategory: false,
150 dataKey: undefined,
151 id: 0,
152 name: '',
153 range: [64, 64],
154 scale: 'auto',
155 type: 'number',
156 unit: ''
157};
158var selectZAxisSettings = (state, axisId) => {
159 var axis = state.cartesianAxis.zAxis[axisId];
160 if (axis == null) {
161 return implicitZAxis;
162 }
163 return axis;
164};
165exports.selectZAxisSettings = selectZAxisSettings;
166var selectBaseAxis = (state, axisType, axisId) => {
167 switch (axisType) {
168 case 'xAxis':
169 {
170 return selectXAxisSettings(state, axisId);
171 }
172 case 'yAxis':
173 {
174 return selectYAxisSettings(state, axisId);
175 }
176 case 'zAxis':
177 {
178 return selectZAxisSettings(state, axisId);
179 }
180 case 'angleAxis':
181 {
182 return (0, _polarAxisSelectors.selectAngleAxis)(state, axisId);
183 }
184 case 'radiusAxis':
185 {
186 return (0, _polarAxisSelectors.selectRadiusAxis)(state, axisId);
187 }
188 default:
189 throw new Error("Unexpected axis type: ".concat(axisType));
190 }
191};
192exports.selectBaseAxis = selectBaseAxis;
193var selectCartesianAxisSettings = (state, axisType, axisId) => {
194 switch (axisType) {
195 case 'xAxis':
196 {
197 return selectXAxisSettings(state, axisId);
198 }
199 case 'yAxis':
200 {
201 return selectYAxisSettings(state, axisId);
202 }
203 default:
204 throw new Error("Unexpected axis type: ".concat(axisType));
205 }
206};
207
208/**
209 * Selects either an X or Y axis. Doesn't work with Z axis - for that, instead use selectBaseAxis.
210 * @param state Root state
211 * @param axisType xAxis | yAxis
212 * @param axisId xAxisId | yAxisId
213 * @returns axis settings object
214 */
215var selectRenderableAxisSettings = (state, axisType, axisId) => {
216 switch (axisType) {
217 case 'xAxis':
218 {
219 return selectXAxisSettings(state, axisId);
220 }
221 case 'yAxis':
222 {
223 return selectYAxisSettings(state, axisId);
224 }
225 case 'angleAxis':
226 {
227 return (0, _polarAxisSelectors.selectAngleAxis)(state, axisId);
228 }
229 case 'radiusAxis':
230 {
231 return (0, _polarAxisSelectors.selectRadiusAxis)(state, axisId);
232 }
233 default:
234 throw new Error("Unexpected axis type: ".concat(axisType));
235 }
236};
237
238/**
239 * @param state RechartsRootState
240 * @return boolean true if there is at least one Bar or RadialBar
241 */
242exports.selectRenderableAxisSettings = selectRenderableAxisSettings;
243var selectHasBar = state => state.graphicalItems.cartesianItems.some(item => item.type === 'bar') || state.graphicalItems.polarItems.some(item => item.type === 'radialBar');
244
245/**
246 * Filters CartesianGraphicalItemSettings by the relevant axis ID
247 * @param axisType 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'angleAxis'
248 * @param axisId from props, defaults to 0
249 *
250 * @returns Predicate function that return true for CartesianGraphicalItemSettings that are relevant to the specified axis
251 */
252exports.selectHasBar = selectHasBar;
253function itemAxisPredicate(axisType, axisId) {
254 return item => {
255 switch (axisType) {
256 case 'xAxis':
257 // This is sensitive to the data type, as 0 !== '0'. I wonder if we should be more flexible. How does 2.x branch behave? TODO write test for that
258 return 'xAxisId' in item && item.xAxisId === axisId;
259 case 'yAxis':
260 return 'yAxisId' in item && item.yAxisId === axisId;
261 case 'zAxis':
262 return 'zAxisId' in item && item.zAxisId === axisId;
263 case 'angleAxis':
264 return 'angleAxisId' in item && item.angleAxisId === axisId;
265 case 'radiusAxis':
266 return 'radiusAxisId' in item && item.radiusAxisId === axisId;
267 default:
268 return false;
269 }
270 };
271}
272
273// TODO appears there is a bug where this selector is called from polar context, find and fix it.
274var selectUnfilteredCartesianItems = state => state.graphicalItems.cartesianItems;
275exports.selectUnfilteredCartesianItems = selectUnfilteredCartesianItems;
276var selectAxisPredicate = (0, _reselect.createSelector)([_pickAxisType.pickAxisType, _pickAxisId.pickAxisId], itemAxisPredicate);
277var combineGraphicalItemsSettings = (graphicalItems, axisSettings, axisPredicate) => graphicalItems.filter(axisPredicate).filter(item => {
278 if ((axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.includeHidden) === true) {
279 return true;
280 }
281 return !item.hide;
282});
283exports.combineGraphicalItemsSettings = combineGraphicalItemsSettings;
284var selectCartesianItemsSettings = exports.selectCartesianItemsSettings = (0, _reselect.createSelector)([selectUnfilteredCartesianItems, selectBaseAxis, selectAxisPredicate], combineGraphicalItemsSettings, {
285 memoizeOptions: {
286 resultEqualityCheck: _arrayEqualityCheck.emptyArraysAreEqualCheck
287 }
288});
289var selectStackedCartesianItemsSettings = exports.selectStackedCartesianItemsSettings = (0, _reselect.createSelector)([selectCartesianItemsSettings], cartesianItems => {
290 return cartesianItems.filter(item => item.type === 'area' || item.type === 'bar').filter(_StackedGraphicalItem.isStacked);
291});
292var filterGraphicalNotStackedItems = cartesianItems => cartesianItems.filter(item => !('stackId' in item) || item.stackId === undefined);
293exports.filterGraphicalNotStackedItems = filterGraphicalNotStackedItems;
294var selectCartesianItemsSettingsExceptStacked = (0, _reselect.createSelector)([selectCartesianItemsSettings], filterGraphicalNotStackedItems);
295var combineGraphicalItemsData = cartesianItems => cartesianItems.map(item => item.data).filter(Boolean).flat(1);
296
297/**
298 * This is a "cheap" selector - it returns the data but doesn't iterate them, so it is not sensitive on the array length.
299 * Also does not apply dataKey yet.
300 * @param state RechartsRootState
301 * @returns data defined on the chart graphical items, such as Line or Scatter or Pie, and filtered with appropriate dataKey
302 */
303exports.combineGraphicalItemsData = combineGraphicalItemsData;
304var selectCartesianGraphicalItemsData = exports.selectCartesianGraphicalItemsData = (0, _reselect.createSelector)([selectCartesianItemsSettings], combineGraphicalItemsData, {
305 memoizeOptions: {
306 resultEqualityCheck: _arrayEqualityCheck.emptyArraysAreEqualCheck
307 }
308});
309var combineDisplayedData = (graphicalItemsData, _ref) => {
310 var {
311 chartData = [],
312 dataStartIndex,
313 dataEndIndex
314 } = _ref;
315 if (graphicalItemsData.length > 0) {
316 /*
317 * There is no slicing when data is defined on graphical items. Why?
318 * Because Brush ignores data defined on graphical items,
319 * and does not render.
320 * So Brush will never show up in a Scatter chart for example.
321 * This is something we will need to fix.
322 *
323 * Now, when the root chart data is not defined, the dataEndIndex is 0,
324 * which means the itemsData will be sliced to an empty array anyway.
325 * But that's an implementation detail, and we can fix that too.
326 *
327 * Also, in absence of Axis dataKey, we use the dataKey from each item, respectively.
328 * This is the usual pattern for numerical axis, that is the one where bars go up:
329 * users don't specify any dataKey by default and expect the axis to "just match the data".
330 */
331 return graphicalItemsData;
332 }
333 return chartData.slice(dataStartIndex, dataEndIndex + 1);
334};
335
336/**
337 * This selector will return all data there is in the chart: graphical items, chart root, all together.
338 * Useful for figuring out an axis domain (because that needs to know of everything),
339 * not useful for rendering individual graphical elements (because they need to know which data is theirs and which is not).
340 *
341 * This function will discard the original indexes, so it is also not useful for anything that depends on ordering.
342 */
343exports.combineDisplayedData = combineDisplayedData;
344var selectDisplayedData = exports.selectDisplayedData = (0, _reselect.createSelector)([selectCartesianGraphicalItemsData, _dataSelectors.selectChartDataWithIndexesIfNotInPanoramaPosition4], combineDisplayedData);
345var combineAppliedValues = (data, axisSettings, items) => {
346 if ((axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null) {
347 return data.map(item => ({
348 value: (0, _ChartUtils.getValueByDataKey)(item, axisSettings.dataKey)
349 }));
350 }
351 if (items.length > 0) {
352 return items.map(item => item.dataKey).flatMap(dataKey => data.map(entry => ({
353 value: (0, _ChartUtils.getValueByDataKey)(entry, dataKey)
354 })));
355 }
356 return data.map(entry => ({
357 value: entry
358 }));
359};
360
361/**
362 * This selector will return all values with the appropriate dataKey applied on them.
363 * Which dataKey is appropriate depends on where it is defined.
364 *
365 * This is an expensive selector - it will iterate all data and compute their value using the provided dataKey.
366 */
367exports.combineAppliedValues = combineAppliedValues;
368var selectAllAppliedValues = exports.selectAllAppliedValues = (0, _reselect.createSelector)([selectDisplayedData, selectBaseAxis, selectCartesianItemsSettings], combineAppliedValues);
369function isErrorBarRelevantForAxisType(axisType, errorBar) {
370 switch (axisType) {
371 case 'xAxis':
372 return errorBar.direction === 'x';
373 case 'yAxis':
374 return errorBar.direction === 'y';
375 default:
376 return false;
377 }
378}
379function makeNumber(val) {
380 if ((0, _DataUtils.isNumOrStr)(val) || val instanceof Date) {
381 var n = Number(val);
382 if ((0, _isWellBehavedNumber.isWellBehavedNumber)(n)) {
383 return n;
384 }
385 }
386 return undefined;
387}
388function makeDomain(val) {
389 if (Array.isArray(val)) {
390 var attempt = [makeNumber(val[0]), makeNumber(val[1])];
391 if ((0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(attempt)) {
392 return attempt;
393 }
394 return undefined;
395 }
396 var n = makeNumber(val);
397 if (n == null) {
398 return undefined;
399 }
400 return [n, n];
401}
402function onlyAllowNumbers(data) {
403 return data.map(makeNumber).filter(_DataUtils.isNotNil);
404}
405
406/**
407 * @param entry One item in the 'data' array. Could be anything really - this is defined externally. This is the raw, before dataKey application
408 * @param appliedValue This is the result of applying the 'main' dataKey on the `entry`.
409 * @param relevantErrorBars Error bars that are relevant for the current axis and layout and all that.
410 * @return either undefined or an array of ErrorValue
411 */
412function getErrorDomainByDataKey(entry, appliedValue, relevantErrorBars) {
413 if (!relevantErrorBars || typeof appliedValue !== 'number' || (0, _DataUtils.isNan)(appliedValue)) {
414 return [];
415 }
416 if (!relevantErrorBars.length) {
417 return [];
418 }
419 return onlyAllowNumbers(relevantErrorBars.flatMap(eb => {
420 var errorValue = (0, _ChartUtils.getValueByDataKey)(entry, eb.dataKey);
421 var lowBound, highBound;
422 if (Array.isArray(errorValue)) {
423 [lowBound, highBound] = errorValue;
424 } else {
425 lowBound = highBound = errorValue;
426 }
427 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(lowBound) || !(0, _isWellBehavedNumber.isWellBehavedNumber)(highBound)) {
428 return undefined;
429 }
430 return [appliedValue - lowBound, appliedValue + highBound];
431 }));
432}
433var selectTooltipAxis = state => {
434 var axisType = (0, _selectTooltipAxisType.selectTooltipAxisType)(state);
435 var axisId = (0, _selectTooltipAxisId.selectTooltipAxisId)(state);
436 return selectRenderableAxisSettings(state, axisType, axisId);
437};
438exports.selectTooltipAxis = selectTooltipAxis;
439var selectTooltipAxisDataKey = exports.selectTooltipAxisDataKey = (0, _reselect.createSelector)([selectTooltipAxis], axis => axis === null || axis === void 0 ? void 0 : axis.dataKey);
440var selectDisplayedStackedData = exports.selectDisplayedStackedData = (0, _reselect.createSelector)([selectStackedCartesianItemsSettings, _dataSelectors.selectChartDataWithIndexesIfNotInPanoramaPosition4, selectTooltipAxis], _combineDisplayedStackedData.combineDisplayedStackedData);
441var combineStackGroups = (displayedData, items, stackOffsetType, reverseStackOrder) => {
442 var initialItemsGroups = {};
443 var itemsGroup = items.reduce((acc, item) => {
444 if (item.stackId == null) {
445 return acc;
446 }
447 var stack = acc[item.stackId];
448 if (stack == null) {
449 stack = [];
450 }
451 stack.push(item);
452 acc[item.stackId] = stack;
453 return acc;
454 }, initialItemsGroups);
455 return Object.fromEntries(Object.entries(itemsGroup).map(_ref2 => {
456 var [stackId, graphicalItems] = _ref2;
457 var orderedGraphicalItems = reverseStackOrder ? [...graphicalItems].reverse() : graphicalItems;
458 var dataKeys = orderedGraphicalItems.map(_getStackSeriesIdentifier.getStackSeriesIdentifier);
459 return [stackId, {
460 // @ts-expect-error getStackedData requires that the input is array of objects, Recharts does not test for that
461 stackedData: (0, _ChartUtils.getStackedData)(displayedData, dataKeys, stackOffsetType),
462 graphicalItems: orderedGraphicalItems
463 }];
464 }));
465};
466
467/**
468 * Stack groups are groups of graphical items that stack on each other.
469 * Stack is a function of axis type (X, Y), axis ID, and stack ID.
470 * Graphical items that do not have a stack ID are not going to be present in stack groups.
471 */
472exports.combineStackGroups = combineStackGroups;
473var selectStackGroups = exports.selectStackGroups = (0, _reselect.createSelector)([selectDisplayedStackedData, selectStackedCartesianItemsSettings, _rootPropsSelectors.selectStackOffsetType, _rootPropsSelectors.selectReverseStackOrder], combineStackGroups);
474var combineDomainOfStackGroups = (stackGroups, _ref3, axisType, domainFromUserPreference) => {
475 var {
476 dataStartIndex,
477 dataEndIndex
478 } = _ref3;
479 if (domainFromUserPreference != null) {
480 // User has specified a domain, so we respect that and we can skip computing anything else
481 return undefined;
482 }
483 if (axisType === 'zAxis') {
484 // ZAxis ignores stacks
485 return undefined;
486 }
487 var domainOfStackGroups = (0, _ChartUtils.getDomainOfStackGroups)(stackGroups, dataStartIndex, dataEndIndex);
488 if (domainOfStackGroups != null && domainOfStackGroups[0] === 0 && domainOfStackGroups[1] === 0) {
489 return undefined;
490 }
491 return domainOfStackGroups;
492};
493exports.combineDomainOfStackGroups = combineDomainOfStackGroups;
494var selectAllowsDataOverflow = (0, _reselect.createSelector)([selectBaseAxis], axisSettings => axisSettings.allowDataOverflow);
495var getDomainDefinition = axisSettings => {
496 var _axisSettings$domain;
497 if (axisSettings == null || !('domain' in axisSettings)) {
498 return defaultNumericDomain;
499 }
500 if (axisSettings.domain != null) {
501 return axisSettings.domain;
502 }
503 if ('ticks' in axisSettings && axisSettings.ticks != null) {
504 if (axisSettings.type === 'number') {
505 var allValues = onlyAllowNumbers(axisSettings.ticks);
506 return [Math.min(...allValues), Math.max(...allValues)];
507 }
508 if (axisSettings.type === 'category') {
509 return axisSettings.ticks.map(String);
510 }
511 }
512 return (_axisSettings$domain = axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.domain) !== null && _axisSettings$domain !== void 0 ? _axisSettings$domain : defaultNumericDomain;
513};
514exports.getDomainDefinition = getDomainDefinition;
515var selectDomainDefinition = exports.selectDomainDefinition = (0, _reselect.createSelector)([selectBaseAxis], getDomainDefinition);
516
517/**
518 * Under certain circumstances, we can determine the domain without looking at the data at all.
519 * This is the case when the domain is explicitly specified as numbers, or when it is specified
520 * as 'auto' or 'dataMin'/'dataMax' and data overflow is not allowed.
521 *
522 * In that case, this function will return the domain, otherwise it returns undefined.
523 *
524 * This is an optimization to avoid unnecessary data processing.
525 * @param state
526 * @param axisType
527 * @param axisId
528 * @param isPanorama
529 */
530var selectDomainFromUserPreference = exports.selectDomainFromUserPreference = (0, _reselect.createSelector)([selectDomainDefinition, selectAllowsDataOverflow], _isDomainSpecifiedByUser.numericalDomainSpecifiedWithoutRequiringData);
531var selectDomainOfStackGroups = exports.selectDomainOfStackGroups = (0, _reselect.createSelector)([selectStackGroups, _dataSelectors.selectChartDataWithIndexes, _pickAxisType.pickAxisType, selectDomainFromUserPreference], combineDomainOfStackGroups, {
532 memoizeOptions: {
533 resultEqualityCheck: _numberDomainEqualityCheck.numberDomainEqualityCheck
534 }
535});
536var selectAllErrorBarSettings = state => state.errorBars;
537exports.selectAllErrorBarSettings = selectAllErrorBarSettings;
538var combineRelevantErrorBarSettings = (cartesianItemsSettings, allErrorBarSettings, axisType) => {
539 return cartesianItemsSettings.flatMap(item => {
540 return allErrorBarSettings[item.id];
541 }).filter(Boolean).filter(e => {
542 return isErrorBarRelevantForAxisType(axisType, e);
543 });
544};
545var mergeDomains = exports.mergeDomains = function mergeDomains() {
546 for (var _len = arguments.length, domains = new Array(_len), _key = 0; _key < _len; _key++) {
547 domains[_key] = arguments[_key];
548 }
549 var allDomains = domains.filter(Boolean);
550 if (allDomains.length === 0) {
551 return undefined;
552 }
553 var allValues = allDomains.flat();
554 var min = Math.min(...allValues);
555 var max = Math.max(...allValues);
556 return [min, max];
557};
558var combineDomainOfAllAppliedNumericalValuesIncludingErrorValues = (data, axisSettings, items, errorBars, axisType) => {
559 var lowerEnd, upperEnd;
560 if (items.length > 0) {
561 data.forEach(entry => {
562 items.forEach(item => {
563 var _errorBars$item$id, _axisSettings$dataKey;
564 var relevantErrorBars = (_errorBars$item$id = errorBars[item.id]) === null || _errorBars$item$id === void 0 ? void 0 : _errorBars$item$id.filter(errorBar => isErrorBarRelevantForAxisType(axisType, errorBar));
565 var valueByDataKey = (0, _ChartUtils.getValueByDataKey)(entry, (_axisSettings$dataKey = axisSettings.dataKey) !== null && _axisSettings$dataKey !== void 0 ? _axisSettings$dataKey : item.dataKey);
566 var errorDomain = getErrorDomainByDataKey(entry, valueByDataKey, relevantErrorBars);
567 if (errorDomain.length >= 2) {
568 var localLower = Math.min(...errorDomain);
569 var localUpper = Math.max(...errorDomain);
570 if (lowerEnd == null || localLower < lowerEnd) {
571 lowerEnd = localLower;
572 }
573 if (upperEnd == null || localUpper > upperEnd) {
574 upperEnd = localUpper;
575 }
576 }
577 var dataValueDomain = makeDomain(valueByDataKey);
578 if (dataValueDomain != null) {
579 lowerEnd = lowerEnd == null ? dataValueDomain[0] : Math.min(lowerEnd, dataValueDomain[0]);
580 upperEnd = upperEnd == null ? dataValueDomain[1] : Math.max(upperEnd, dataValueDomain[1]);
581 }
582 });
583 });
584 }
585 if ((axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null) {
586 data.forEach(item => {
587 var dataValueDomain = makeDomain((0, _ChartUtils.getValueByDataKey)(item, axisSettings.dataKey));
588 if (dataValueDomain != null) {
589 lowerEnd = lowerEnd == null ? dataValueDomain[0] : Math.min(lowerEnd, dataValueDomain[0]);
590 upperEnd = upperEnd == null ? dataValueDomain[1] : Math.max(upperEnd, dataValueDomain[1]);
591 }
592 });
593 }
594 if ((0, _isWellBehavedNumber.isWellBehavedNumber)(lowerEnd) && (0, _isWellBehavedNumber.isWellBehavedNumber)(upperEnd)) {
595 return [lowerEnd, upperEnd];
596 }
597 return undefined;
598};
599exports.combineDomainOfAllAppliedNumericalValuesIncludingErrorValues = combineDomainOfAllAppliedNumericalValuesIncludingErrorValues;
600var selectDomainOfAllAppliedNumericalValuesIncludingErrorValues = (0, _reselect.createSelector)([selectDisplayedData, selectBaseAxis, selectCartesianItemsSettingsExceptStacked, selectAllErrorBarSettings, _pickAxisType.pickAxisType], combineDomainOfAllAppliedNumericalValuesIncludingErrorValues, {
601 memoizeOptions: {
602 resultEqualityCheck: _numberDomainEqualityCheck.numberDomainEqualityCheck
603 }
604});
605function onlyAllowNumbersAndStringsAndDates(item) {
606 var {
607 value
608 } = item;
609 if ((0, _DataUtils.isNumOrStr)(value) || value instanceof Date) {
610 return value;
611 }
612 return undefined;
613}
614var computeDomainOfTypeCategory = (allDataSquished, axisSettings, isCategorical) => {
615 var categoricalDomain = allDataSquished.map(onlyAllowNumbersAndStringsAndDates).filter(v => v != null);
616 if (isCategorical && (axisSettings.dataKey == null || axisSettings.allowDuplicatedCategory && (0, _DataUtils.hasDuplicate)(categoricalDomain))) {
617 /*
618 * 1. In an absence of dataKey, Recharts will use array indexes as its categorical domain
619 * 2. When category axis has duplicated text, serial numbers are used to generate scale
620 */
621 return (0, _range.default)(0, allDataSquished.length);
622 }
623 if (axisSettings.allowDuplicatedCategory) {
624 return categoricalDomain;
625 }
626 return Array.from(new Set(categoricalDomain));
627};
628var selectReferenceDots = state => state.referenceElements.dots;
629exports.selectReferenceDots = selectReferenceDots;
630var filterReferenceElements = (elements, axisType, axisId) => {
631 return elements.filter(el => el.ifOverflow === 'extendDomain').filter(el => {
632 if (axisType === 'xAxis') {
633 return el.xAxisId === axisId;
634 }
635 return el.yAxisId === axisId;
636 });
637};
638exports.filterReferenceElements = filterReferenceElements;
639var selectReferenceDotsByAxis = exports.selectReferenceDotsByAxis = (0, _reselect.createSelector)([selectReferenceDots, _pickAxisType.pickAxisType, _pickAxisId.pickAxisId], filterReferenceElements);
640var selectReferenceAreas = state => state.referenceElements.areas;
641exports.selectReferenceAreas = selectReferenceAreas;
642var selectReferenceAreasByAxis = exports.selectReferenceAreasByAxis = (0, _reselect.createSelector)([selectReferenceAreas, _pickAxisType.pickAxisType, _pickAxisId.pickAxisId], filterReferenceElements);
643var selectReferenceLines = state => state.referenceElements.lines;
644exports.selectReferenceLines = selectReferenceLines;
645var selectReferenceLinesByAxis = exports.selectReferenceLinesByAxis = (0, _reselect.createSelector)([selectReferenceLines, _pickAxisType.pickAxisType, _pickAxisId.pickAxisId], filterReferenceElements);
646var combineDotsDomain = (dots, axisType) => {
647 if (dots == null) {
648 return undefined;
649 }
650 var allCoords = onlyAllowNumbers(dots.map(dot => axisType === 'xAxis' ? dot.x : dot.y));
651 if (allCoords.length === 0) {
652 return undefined;
653 }
654 return [Math.min(...allCoords), Math.max(...allCoords)];
655};
656exports.combineDotsDomain = combineDotsDomain;
657var selectReferenceDotsDomain = (0, _reselect.createSelector)(selectReferenceDotsByAxis, _pickAxisType.pickAxisType, combineDotsDomain);
658var combineAreasDomain = (areas, axisType) => {
659 if (areas == null) {
660 return undefined;
661 }
662 var allCoords = onlyAllowNumbers(areas.flatMap(area => [axisType === 'xAxis' ? area.x1 : area.y1, axisType === 'xAxis' ? area.x2 : area.y2]));
663 if (allCoords.length === 0) {
664 return undefined;
665 }
666 return [Math.min(...allCoords), Math.max(...allCoords)];
667};
668exports.combineAreasDomain = combineAreasDomain;
669var selectReferenceAreasDomain = (0, _reselect.createSelector)([selectReferenceAreasByAxis, _pickAxisType.pickAxisType], combineAreasDomain);
670function extractXCoordinates(line) {
671 var _line$segment;
672 if (line.x != null) {
673 return onlyAllowNumbers([line.x]);
674 }
675 var segmentCoordinates = (_line$segment = line.segment) === null || _line$segment === void 0 ? void 0 : _line$segment.map(s => s.x);
676 if (segmentCoordinates == null || segmentCoordinates.length === 0) {
677 return [];
678 }
679 return onlyAllowNumbers(segmentCoordinates);
680}
681function extractYCoordinates(line) {
682 var _line$segment2;
683 if (line.y != null) {
684 return onlyAllowNumbers([line.y]);
685 }
686 var segmentCoordinates = (_line$segment2 = line.segment) === null || _line$segment2 === void 0 ? void 0 : _line$segment2.map(s => s.y);
687 if (segmentCoordinates == null || segmentCoordinates.length === 0) {
688 return [];
689 }
690 return onlyAllowNumbers(segmentCoordinates);
691}
692var combineLinesDomain = (lines, axisType) => {
693 if (lines == null) {
694 return undefined;
695 }
696 var allCoords = lines.flatMap(line => axisType === 'xAxis' ? extractXCoordinates(line) : extractYCoordinates(line));
697 if (allCoords.length === 0) {
698 return undefined;
699 }
700 return [Math.min(...allCoords), Math.max(...allCoords)];
701};
702exports.combineLinesDomain = combineLinesDomain;
703var selectReferenceLinesDomain = (0, _reselect.createSelector)([selectReferenceLinesByAxis, _pickAxisType.pickAxisType], combineLinesDomain);
704var selectReferenceElementsDomain = (0, _reselect.createSelector)(selectReferenceDotsDomain, selectReferenceLinesDomain, selectReferenceAreasDomain, (dotsDomain, linesDomain, areasDomain) => {
705 return mergeDomains(dotsDomain, areasDomain, linesDomain);
706});
707var combineNumericalDomain = (axisSettings, domainDefinition, domainFromUserPreference, domainOfStackGroups, dataAndErrorBarsDomain, referenceElementsDomain, layout, axisType) => {
708 if (domainFromUserPreference != null) {
709 // We're done! No need to compute anything else.
710 return domainFromUserPreference;
711 }
712 var shouldIncludeDomainOfStackGroups = layout === 'vertical' && axisType === 'xAxis' || layout === 'horizontal' && axisType === 'yAxis';
713 var mergedDomains = shouldIncludeDomainOfStackGroups ? mergeDomains(domainOfStackGroups, referenceElementsDomain, dataAndErrorBarsDomain) : mergeDomains(referenceElementsDomain, dataAndErrorBarsDomain);
714 return (0, _isDomainSpecifiedByUser.parseNumericalUserDomain)(domainDefinition, mergedDomains, axisSettings.allowDataOverflow);
715};
716exports.combineNumericalDomain = combineNumericalDomain;
717var selectNumericalDomain = exports.selectNumericalDomain = (0, _reselect.createSelector)([selectBaseAxis, selectDomainDefinition, selectDomainFromUserPreference, selectDomainOfStackGroups, selectDomainOfAllAppliedNumericalValuesIncludingErrorValues, selectReferenceElementsDomain, _chartLayoutContext.selectChartLayout, _pickAxisType.pickAxisType], combineNumericalDomain, {
718 memoizeOptions: {
719 resultEqualityCheck: _numberDomainEqualityCheck.numberDomainEqualityCheck
720 }
721});
722
723/**
724 * Expand by design maps everything between 0 and 1,
725 * there is nothing to compute.
726 * See https://d3js.org/d3-shape/stack#stack-offsets
727 */
728var expandDomain = [0, 1];
729var combineAxisDomain = (axisSettings, layout, displayedData, allAppliedValues, stackOffsetType, axisType, numericalDomain) => {
730 if ((axisSettings == null || displayedData == null || displayedData.length === 0) && numericalDomain === undefined) {
731 return undefined;
732 }
733 var {
734 dataKey,
735 type
736 } = axisSettings;
737 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, axisType);
738 if (isCategorical && dataKey == null) {
739 var _displayedData$length;
740 return (0, _range.default)(0, (_displayedData$length = displayedData === null || displayedData === void 0 ? void 0 : displayedData.length) !== null && _displayedData$length !== void 0 ? _displayedData$length : 0);
741 }
742 if (type === 'category') {
743 return computeDomainOfTypeCategory(allAppliedValues, axisSettings, isCategorical);
744 }
745 if (stackOffsetType === 'expand') {
746 return expandDomain;
747 }
748 return numericalDomain;
749};
750exports.combineAxisDomain = combineAxisDomain;
751var selectAxisDomain = exports.selectAxisDomain = (0, _reselect.createSelector)([selectBaseAxis, _chartLayoutContext.selectChartLayout, selectDisplayedData, selectAllAppliedValues, _rootPropsSelectors.selectStackOffsetType, _pickAxisType.pickAxisType, selectNumericalDomain], combineAxisDomain);
752function isSupportedScaleName(name) {
753 return name in d3Scales;
754}
755var combineRealScaleType = (axisConfig, hasBar, chartType) => {
756 if (axisConfig == null) {
757 return undefined;
758 }
759 var {
760 scale,
761 type
762 } = axisConfig;
763 if (scale === 'auto') {
764 if (type === 'category' && chartType && (chartType.indexOf('LineChart') >= 0 || chartType.indexOf('AreaChart') >= 0 || chartType.indexOf('ComposedChart') >= 0 && !hasBar)) {
765 return 'point';
766 }
767 if (type === 'category') {
768 return 'band';
769 }
770 return 'linear';
771 }
772 if (typeof scale === 'string') {
773 var name = "scale".concat((0, _DataUtils.upperFirst)(scale));
774 return isSupportedScaleName(name) ? name : 'point';
775 }
776 return undefined;
777};
778exports.combineRealScaleType = combineRealScaleType;
779var selectRealScaleType = exports.selectRealScaleType = (0, _reselect.createSelector)([selectBaseAxis, selectHasBar, _rootPropsSelectors.selectChartName], combineRealScaleType);
780function combineScaleFunction(axis, realScaleType, axisDomain, axisRange) {
781 if (axisDomain == null || axisRange == null) {
782 return undefined;
783 }
784 if (typeof axis.scale === 'function') {
785 return (0, _RechartsScale.rechartsScaleFactory)(axis.scale, axisDomain, axisRange);
786 }
787 return (0, _RechartsScale.rechartsScaleFactory)(realScaleType, axisDomain, axisRange);
788}
789var combineNiceTicks = (axisDomain, axisSettings, realScaleType) => {
790 var domainDefinition = getDomainDefinition(axisSettings);
791 if (realScaleType !== 'auto' && realScaleType !== 'linear') {
792 return undefined;
793 }
794 if (axisSettings != null && axisSettings.tickCount && Array.isArray(domainDefinition) && (domainDefinition[0] === 'auto' || domainDefinition[1] === 'auto') && (0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(axisDomain)) {
795 return (0, _scale.getNiceTickValues)(axisDomain, axisSettings.tickCount, axisSettings.allowDecimals);
796 }
797 if (axisSettings != null && axisSettings.tickCount && axisSettings.type === 'number' && (0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(axisDomain)) {
798 return (0, _scale.getTickValuesFixedDomain)(axisDomain, axisSettings.tickCount, axisSettings.allowDecimals);
799 }
800 return undefined;
801};
802exports.combineNiceTicks = combineNiceTicks;
803var selectNiceTicks = exports.selectNiceTicks = (0, _reselect.createSelector)([selectAxisDomain, selectRenderableAxisSettings, selectRealScaleType], combineNiceTicks);
804var combineAxisDomainWithNiceTicks = (axisSettings, domain, niceTicks, axisType) => {
805 if (
806 /*
807 * Angle axis for some reason uses nice ticks when rendering axis tick labels,
808 * but doesn't use nice ticks for extending domain like all the other axes do.
809 * Not really sure why? Is there a good reason,
810 * or is it just because someone added support for nice ticks to the other axes and forgot this one?
811 */
812 axisType !== 'angleAxis' && (axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.type) === 'number' && (0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(domain) && Array.isArray(niceTicks) && niceTicks.length > 0) {
813 var _niceTicks$, _niceTicks;
814 var minFromDomain = domain[0];
815 var minFromTicks = (_niceTicks$ = niceTicks[0]) !== null && _niceTicks$ !== void 0 ? _niceTicks$ : 0;
816 var maxFromDomain = domain[1];
817 var maxFromTicks = (_niceTicks = niceTicks[niceTicks.length - 1]) !== null && _niceTicks !== void 0 ? _niceTicks : 0;
818 return [Math.min(minFromDomain, minFromTicks), Math.max(maxFromDomain, maxFromTicks)];
819 }
820 return domain;
821};
822exports.combineAxisDomainWithNiceTicks = combineAxisDomainWithNiceTicks;
823var selectAxisDomainIncludingNiceTicks = exports.selectAxisDomainIncludingNiceTicks = (0, _reselect.createSelector)([selectBaseAxis, selectAxisDomain, selectNiceTicks, _pickAxisType.pickAxisType], combineAxisDomainWithNiceTicks);
824
825/**
826 * Returns the smallest gap, between two numbers in the data, as a ratio of the whole range (max - min).
827 * Ignores domain provided by user and only considers domain from data.
828 *
829 * The result is a number between 0 and 1.
830 */
831var selectSmallestDistanceBetweenValues = exports.selectSmallestDistanceBetweenValues = (0, _reselect.createSelector)(selectAllAppliedValues, selectBaseAxis, (allDataSquished, axisSettings) => {
832 if (!axisSettings || axisSettings.type !== 'number') {
833 return undefined;
834 }
835 var smallestDistanceBetweenValues = Infinity;
836 var sortedValues = Array.from(onlyAllowNumbers(allDataSquished.map(d => d.value))).sort((a, b) => a - b);
837 var first = sortedValues[0];
838 var last = sortedValues[sortedValues.length - 1];
839 if (first == null || last == null) {
840 return Infinity;
841 }
842 var diff = last - first;
843 if (diff === 0) {
844 return Infinity;
845 }
846 // Only do n - 1 distance calculations because there's only n - 1 distances between n values.
847 for (var i = 0; i < sortedValues.length - 1; i++) {
848 var curr = sortedValues[i];
849 var next = sortedValues[i + 1];
850 if (curr == null || next == null) {
851 continue;
852 }
853 var distance = next - curr;
854 smallestDistanceBetweenValues = Math.min(smallestDistanceBetweenValues, distance);
855 }
856 return smallestDistanceBetweenValues / diff;
857});
858var selectCalculatedPadding = (0, _reselect.createSelector)(selectSmallestDistanceBetweenValues, _chartLayoutContext.selectChartLayout, _rootPropsSelectors.selectBarCategoryGap, _selectChartOffsetInternal.selectChartOffsetInternal, (_1, _2, _3, _4, padding) => padding, (smallestDistanceInPercent, layout, barCategoryGap, offset, padding) => {
859 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(smallestDistanceInPercent)) {
860 return 0;
861 }
862 var rangeWidth = layout === 'vertical' ? offset.height : offset.width;
863 if (padding === 'gap') {
864 return smallestDistanceInPercent * rangeWidth / 2;
865 }
866 if (padding === 'no-gap') {
867 var gap = (0, _DataUtils.getPercentValue)(barCategoryGap, smallestDistanceInPercent * rangeWidth);
868 var halfBand = smallestDistanceInPercent * rangeWidth / 2;
869 return halfBand - gap - (halfBand - gap) / rangeWidth * gap;
870 }
871 return 0;
872});
873var selectCalculatedXAxisPadding = (state, axisId, isPanorama) => {
874 var xAxisSettings = selectXAxisSettings(state, axisId);
875 if (xAxisSettings == null || typeof xAxisSettings.padding !== 'string') {
876 return 0;
877 }
878 return selectCalculatedPadding(state, 'xAxis', axisId, isPanorama, xAxisSettings.padding);
879};
880exports.selectCalculatedXAxisPadding = selectCalculatedXAxisPadding;
881var selectCalculatedYAxisPadding = (state, axisId, isPanorama) => {
882 var yAxisSettings = selectYAxisSettings(state, axisId);
883 if (yAxisSettings == null || typeof yAxisSettings.padding !== 'string') {
884 return 0;
885 }
886 return selectCalculatedPadding(state, 'yAxis', axisId, isPanorama, yAxisSettings.padding);
887};
888exports.selectCalculatedYAxisPadding = selectCalculatedYAxisPadding;
889var selectXAxisPadding = (0, _reselect.createSelector)(selectXAxisSettings, selectCalculatedXAxisPadding, (xAxisSettings, calculated) => {
890 var _padding$left, _padding$right;
891 if (xAxisSettings == null) {
892 return {
893 left: 0,
894 right: 0
895 };
896 }
897 var {
898 padding
899 } = xAxisSettings;
900 if (typeof padding === 'string') {
901 return {
902 left: calculated,
903 right: calculated
904 };
905 }
906 return {
907 left: ((_padding$left = padding.left) !== null && _padding$left !== void 0 ? _padding$left : 0) + calculated,
908 right: ((_padding$right = padding.right) !== null && _padding$right !== void 0 ? _padding$right : 0) + calculated
909 };
910});
911var selectYAxisPadding = (0, _reselect.createSelector)(selectYAxisSettings, selectCalculatedYAxisPadding, (yAxisSettings, calculated) => {
912 var _padding$top, _padding$bottom;
913 if (yAxisSettings == null) {
914 return {
915 top: 0,
916 bottom: 0
917 };
918 }
919 var {
920 padding
921 } = yAxisSettings;
922 if (typeof padding === 'string') {
923 return {
924 top: calculated,
925 bottom: calculated
926 };
927 }
928 return {
929 top: ((_padding$top = padding.top) !== null && _padding$top !== void 0 ? _padding$top : 0) + calculated,
930 bottom: ((_padding$bottom = padding.bottom) !== null && _padding$bottom !== void 0 ? _padding$bottom : 0) + calculated
931 };
932});
933var combineXAxisRange = exports.combineXAxisRange = (0, _reselect.createSelector)([_selectChartOffsetInternal.selectChartOffsetInternal, selectXAxisPadding, _brushSelectors.selectBrushDimensions, _brushSelectors.selectBrushSettings, (_state, _axisId, isPanorama) => isPanorama], (offset, padding, brushDimensions, _ref4, isPanorama) => {
934 var {
935 padding: brushPadding
936 } = _ref4;
937 if (isPanorama) {
938 return [brushPadding.left, brushDimensions.width - brushPadding.right];
939 }
940 return [offset.left + padding.left, offset.left + offset.width - padding.right];
941});
942var combineYAxisRange = exports.combineYAxisRange = (0, _reselect.createSelector)([_selectChartOffsetInternal.selectChartOffsetInternal, _chartLayoutContext.selectChartLayout, selectYAxisPadding, _brushSelectors.selectBrushDimensions, _brushSelectors.selectBrushSettings, (_state, _axisId, isPanorama) => isPanorama], (offset, layout, padding, brushDimensions, _ref5, isPanorama) => {
943 var {
944 padding: brushPadding
945 } = _ref5;
946 if (isPanorama) {
947 return [brushDimensions.height - brushPadding.bottom, brushPadding.top];
948 }
949 if (layout === 'horizontal') {
950 return [offset.top + offset.height - padding.bottom, offset.top + padding.top];
951 }
952 return [offset.top + padding.top, offset.top + offset.height - padding.bottom];
953});
954var selectAxisRange = (state, axisType, axisId, isPanorama) => {
955 var _selectZAxisSettings;
956 switch (axisType) {
957 case 'xAxis':
958 return combineXAxisRange(state, axisId, isPanorama);
959 case 'yAxis':
960 return combineYAxisRange(state, axisId, isPanorama);
961 case 'zAxis':
962 return (_selectZAxisSettings = selectZAxisSettings(state, axisId)) === null || _selectZAxisSettings === void 0 ? void 0 : _selectZAxisSettings.range;
963 case 'angleAxis':
964 return (0, _polarAxisSelectors.selectAngleAxisRange)(state);
965 case 'radiusAxis':
966 return (0, _polarAxisSelectors.selectRadiusAxisRange)(state, axisId);
967 default:
968 return undefined;
969 }
970};
971exports.selectAxisRange = selectAxisRange;
972var selectAxisRangeWithReverse = exports.selectAxisRangeWithReverse = (0, _reselect.createSelector)([selectBaseAxis, selectAxisRange], _combineAxisRangeWithReverse.combineAxisRangeWithReverse);
973var selectCheckedAxisDomain = (0, _reselect.createSelector)([selectRealScaleType, selectAxisDomainIncludingNiceTicks], _combineCheckedDomain.combineCheckedDomain);
974var selectAxisScale = exports.selectAxisScale = (0, _reselect.createSelector)([selectBaseAxis, selectRealScaleType, selectCheckedAxisDomain, selectAxisRangeWithReverse], combineScaleFunction);
975var selectErrorBarsSettings = exports.selectErrorBarsSettings = (0, _reselect.createSelector)([selectCartesianItemsSettings, selectAllErrorBarSettings, _pickAxisType.pickAxisType], combineRelevantErrorBarSettings);
976function compareIds(a, b) {
977 if (a.id < b.id) {
978 return -1;
979 }
980 if (a.id > b.id) {
981 return 1;
982 }
983 return 0;
984}
985var pickAxisOrientation = (_state, orientation) => orientation;
986var pickMirror = (_state, _orientation, mirror) => mirror;
987var selectAllXAxesWithOffsetType = (0, _reselect.createSelector)(_selectAllAxes.selectAllXAxes, pickAxisOrientation, pickMirror, (allAxes, orientation, mirror) => allAxes.filter(axis => axis.orientation === orientation).filter(axis => axis.mirror === mirror).sort(compareIds));
988var selectAllYAxesWithOffsetType = (0, _reselect.createSelector)(_selectAllAxes.selectAllYAxes, pickAxisOrientation, pickMirror, (allAxes, orientation, mirror) => allAxes.filter(axis => axis.orientation === orientation).filter(axis => axis.mirror === mirror).sort(compareIds));
989var getXAxisSize = (offset, axisSettings) => {
990 return {
991 width: offset.width,
992 height: axisSettings.height
993 };
994};
995var getYAxisSize = (offset, axisSettings) => {
996 var width = typeof axisSettings.width === 'number' ? axisSettings.width : _Constants.DEFAULT_Y_AXIS_WIDTH;
997 return {
998 width,
999 height: offset.height
1000 };
1001};
1002var selectXAxisSize = exports.selectXAxisSize = (0, _reselect.createSelector)(_selectChartOffsetInternal.selectChartOffsetInternal, selectXAxisSettings, getXAxisSize);
1003var combineXAxisPositionStartingPoint = (offset, orientation, chartHeight) => {
1004 switch (orientation) {
1005 case 'top':
1006 return offset.top;
1007 case 'bottom':
1008 return chartHeight - offset.bottom;
1009 default:
1010 return 0;
1011 }
1012};
1013var combineYAxisPositionStartingPoint = (offset, orientation, chartWidth) => {
1014 switch (orientation) {
1015 case 'left':
1016 return offset.left;
1017 case 'right':
1018 return chartWidth - offset.right;
1019 default:
1020 return 0;
1021 }
1022};
1023var selectAllXAxesOffsetSteps = exports.selectAllXAxesOffsetSteps = (0, _reselect.createSelector)(_containerSelectors.selectChartHeight, _selectChartOffsetInternal.selectChartOffsetInternal, selectAllXAxesWithOffsetType, pickAxisOrientation, pickMirror, (chartHeight, offset, allAxesWithSameOffsetType, orientation, mirror) => {
1024 var steps = {};
1025 var position;
1026 allAxesWithSameOffsetType.forEach(axis => {
1027 var axisSize = getXAxisSize(offset, axis);
1028 if (position == null) {
1029 position = combineXAxisPositionStartingPoint(offset, orientation, chartHeight);
1030 }
1031 var needSpace = orientation === 'top' && !mirror || orientation === 'bottom' && mirror;
1032 steps[axis.id] = position - Number(needSpace) * axisSize.height;
1033 position += (needSpace ? -1 : 1) * axisSize.height;
1034 });
1035 return steps;
1036});
1037var selectAllYAxesOffsetSteps = exports.selectAllYAxesOffsetSteps = (0, _reselect.createSelector)(_containerSelectors.selectChartWidth, _selectChartOffsetInternal.selectChartOffsetInternal, selectAllYAxesWithOffsetType, pickAxisOrientation, pickMirror, (chartWidth, offset, allAxesWithSameOffsetType, orientation, mirror) => {
1038 var steps = {};
1039 var position;
1040 allAxesWithSameOffsetType.forEach(axis => {
1041 var axisSize = getYAxisSize(offset, axis);
1042 if (position == null) {
1043 position = combineYAxisPositionStartingPoint(offset, orientation, chartWidth);
1044 }
1045 var needSpace = orientation === 'left' && !mirror || orientation === 'right' && mirror;
1046 steps[axis.id] = position - Number(needSpace) * axisSize.width;
1047 position += (needSpace ? -1 : 1) * axisSize.width;
1048 });
1049 return steps;
1050});
1051var selectXAxisOffsetSteps = (state, axisId) => {
1052 var axisSettings = selectXAxisSettings(state, axisId);
1053 if (axisSettings == null) {
1054 return undefined;
1055 }
1056 return selectAllXAxesOffsetSteps(state, axisSettings.orientation, axisSettings.mirror);
1057};
1058var selectXAxisPosition = exports.selectXAxisPosition = (0, _reselect.createSelector)([_selectChartOffsetInternal.selectChartOffsetInternal, selectXAxisSettings, selectXAxisOffsetSteps, (_, axisId) => axisId], (offset, axisSettings, allSteps, axisId) => {
1059 if (axisSettings == null) {
1060 return undefined;
1061 }
1062 var stepOfThisAxis = allSteps === null || allSteps === void 0 ? void 0 : allSteps[axisId];
1063 if (stepOfThisAxis == null) {
1064 return {
1065 x: offset.left,
1066 y: 0
1067 };
1068 }
1069 return {
1070 x: offset.left,
1071 y: stepOfThisAxis
1072 };
1073});
1074var selectYAxisOffsetSteps = (state, axisId) => {
1075 var axisSettings = selectYAxisSettings(state, axisId);
1076 if (axisSettings == null) {
1077 return undefined;
1078 }
1079 return selectAllYAxesOffsetSteps(state, axisSettings.orientation, axisSettings.mirror);
1080};
1081var selectYAxisPosition = exports.selectYAxisPosition = (0, _reselect.createSelector)([_selectChartOffsetInternal.selectChartOffsetInternal, selectYAxisSettings, selectYAxisOffsetSteps, (_, axisId) => axisId], (offset, axisSettings, allSteps, axisId) => {
1082 if (axisSettings == null) {
1083 return undefined;
1084 }
1085 var stepOfThisAxis = allSteps === null || allSteps === void 0 ? void 0 : allSteps[axisId];
1086 if (stepOfThisAxis == null) {
1087 return {
1088 x: 0,
1089 y: offset.top
1090 };
1091 }
1092 return {
1093 x: stepOfThisAxis,
1094 y: offset.top
1095 };
1096});
1097var selectYAxisSize = exports.selectYAxisSize = (0, _reselect.createSelector)(_selectChartOffsetInternal.selectChartOffsetInternal, selectYAxisSettings, (offset, axisSettings) => {
1098 var width = typeof axisSettings.width === 'number' ? axisSettings.width : _Constants.DEFAULT_Y_AXIS_WIDTH;
1099 return {
1100 width,
1101 height: offset.height
1102 };
1103});
1104var selectCartesianAxisSize = (state, axisType, axisId) => {
1105 switch (axisType) {
1106 case 'xAxis':
1107 {
1108 return selectXAxisSize(state, axisId).width;
1109 }
1110 case 'yAxis':
1111 {
1112 return selectYAxisSize(state, axisId).height;
1113 }
1114 default:
1115 {
1116 return undefined;
1117 }
1118 }
1119};
1120exports.selectCartesianAxisSize = selectCartesianAxisSize;
1121var combineDuplicateDomain = (chartLayout, appliedValues, axis, axisType) => {
1122 if (axis == null) {
1123 return undefined;
1124 }
1125 var {
1126 allowDuplicatedCategory,
1127 type,
1128 dataKey
1129 } = axis;
1130 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(chartLayout, axisType);
1131 var allData = appliedValues.map(av => av.value);
1132 if (dataKey && isCategorical && type === 'category' && allowDuplicatedCategory && (0, _DataUtils.hasDuplicate)(allData)) {
1133 return allData;
1134 }
1135 return undefined;
1136};
1137exports.combineDuplicateDomain = combineDuplicateDomain;
1138var selectDuplicateDomain = exports.selectDuplicateDomain = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectAllAppliedValues, selectBaseAxis, _pickAxisType.pickAxisType], combineDuplicateDomain);
1139var combineCategoricalDomain = (layout, appliedValues, axis, axisType) => {
1140 if (axis == null || axis.dataKey == null) {
1141 return undefined;
1142 }
1143 var {
1144 type,
1145 scale
1146 } = axis;
1147 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, axisType);
1148 if (isCategorical && (type === 'number' || scale !== 'auto')) {
1149 return appliedValues.map(d => d.value);
1150 }
1151 return undefined;
1152};
1153exports.combineCategoricalDomain = combineCategoricalDomain;
1154var selectCategoricalDomain = exports.selectCategoricalDomain = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectAllAppliedValues, selectRenderableAxisSettings, _pickAxisType.pickAxisType], combineCategoricalDomain);
1155var selectAxisPropsNeededForCartesianGridTicksGenerator = exports.selectAxisPropsNeededForCartesianGridTicksGenerator = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectCartesianAxisSettings, selectRealScaleType, selectAxisScale, selectDuplicateDomain, selectCategoricalDomain, selectAxisRange, selectNiceTicks, _pickAxisType.pickAxisType], (layout, axis, realScaleType, scale, duplicateDomain, categoricalDomain, axisRange, niceTicks, axisType) => {
1156 if (axis == null) {
1157 return undefined;
1158 }
1159 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, axisType);
1160 return {
1161 angle: axis.angle,
1162 interval: axis.interval,
1163 minTickGap: axis.minTickGap,
1164 orientation: axis.orientation,
1165 tick: axis.tick,
1166 tickCount: axis.tickCount,
1167 tickFormatter: axis.tickFormatter,
1168 ticks: axis.ticks,
1169 type: axis.type,
1170 unit: axis.unit,
1171 axisType,
1172 categoricalDomain,
1173 duplicateDomain,
1174 isCategorical,
1175 niceTicks,
1176 range: axisRange,
1177 realScaleType,
1178 scale
1179 };
1180});
1181
1182/**
1183 * Of on four almost identical implementations of tick generation.
1184 * The four horsemen of tick generation are:
1185 * - {@link selectTooltipAxisTicks}
1186 * - {@link combineAxisTicks}
1187 * - {@link getTicksOfAxis}.
1188 * - {@link combineGraphicalItemTicks}
1189 */
1190var combineAxisTicks = (layout, axis, realScaleType, scale, niceTicks, axisRange, duplicateDomain, categoricalDomain, axisType) => {
1191 if (axis == null || scale == null) {
1192 return undefined;
1193 }
1194 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, axisType);
1195 var {
1196 type,
1197 ticks,
1198 tickCount
1199 } = axis;
1200 var offsetForBand =
1201 // @ts-expect-error This is testing for `scaleBand` but for band axis the type is reported as `band` so this looks like a dead code with a workaround elsewhere?
1202 realScaleType === 'scaleBand' && typeof scale.bandwidth === 'function' ? scale.bandwidth() / 2 : 2;
1203 var offset = type === 'category' && scale.bandwidth ? scale.bandwidth() / offsetForBand : 0;
1204 offset = axisType === 'angleAxis' && axisRange != null && axisRange.length >= 2 ? (0, _DataUtils.mathSign)(axisRange[0] - axisRange[1]) * 2 * offset : offset;
1205
1206 // The ticks set by user should only affect the ticks adjacent to axis line
1207 var ticksOrNiceTicks = ticks || niceTicks;
1208 if (ticksOrNiceTicks) {
1209 return ticksOrNiceTicks.map((entry, index) => {
1210 var scaleContent = duplicateDomain ? duplicateDomain.indexOf(entry) : entry;
1211 var scaled = scale.map(scaleContent);
1212 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1213 return null;
1214 }
1215 return {
1216 index,
1217 coordinate: scaled + offset,
1218 value: entry,
1219 offset
1220 };
1221 }).filter(_DataUtils.isNotNil);
1222 }
1223
1224 // When axis is a categorical axis, but the type of axis is number or the scale of axis is not "auto"
1225 if (isCategorical && categoricalDomain) {
1226 return categoricalDomain.map((entry, index) => {
1227 var scaled = scale.map(entry);
1228 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1229 return null;
1230 }
1231 return {
1232 coordinate: scaled + offset,
1233 value: entry,
1234 index,
1235 offset
1236 };
1237 }).filter(_DataUtils.isNotNil);
1238 }
1239 if (scale.ticks) {
1240 return scale.ticks(tickCount).map((entry, index) => {
1241 var scaled = scale.map(entry);
1242 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1243 return null;
1244 }
1245 return {
1246 coordinate: scaled + offset,
1247 value: entry,
1248 index,
1249 offset
1250 };
1251 }).filter(_DataUtils.isNotNil);
1252 }
1253
1254 // When axis has duplicated text, serial numbers are used to generate scale
1255 return scale.domain().map((entry, index) => {
1256 var scaled = scale.map(entry);
1257 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1258 return null;
1259 }
1260 return {
1261 coordinate: scaled + offset,
1262 // @ts-expect-error can't use Date as index
1263 value: duplicateDomain ? duplicateDomain[entry] : entry,
1264 index,
1265 offset
1266 };
1267 }).filter(_DataUtils.isNotNil);
1268};
1269exports.combineAxisTicks = combineAxisTicks;
1270var selectTicksOfAxis = exports.selectTicksOfAxis = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectRenderableAxisSettings, selectRealScaleType, selectAxisScale, selectNiceTicks, selectAxisRange, selectDuplicateDomain, selectCategoricalDomain, _pickAxisType.pickAxisType], combineAxisTicks);
1271
1272/**
1273 * Of on four almost identical implementations of tick generation.
1274 * The four horsemen of tick generation are:
1275 * - {@link selectTooltipAxisTicks}
1276 * - {@link combineAxisTicks}
1277 * - {@link getTicksOfAxis}.
1278 * - {@link combineGraphicalItemTicks}
1279 */
1280var combineGraphicalItemTicks = (layout, axis, scale, axisRange, duplicateDomain, categoricalDomain, axisType) => {
1281 if (axis == null || scale == null || axisRange == null || axisRange[0] === axisRange[1]) {
1282 return undefined;
1283 }
1284 var isCategorical = (0, _ChartUtils.isCategoricalAxis)(layout, axisType);
1285 var {
1286 tickCount
1287 } = axis;
1288 var offset = 0;
1289 offset = axisType === 'angleAxis' && (axisRange === null || axisRange === void 0 ? void 0 : axisRange.length) >= 2 ? (0, _DataUtils.mathSign)(axisRange[0] - axisRange[1]) * 2 * offset : offset;
1290
1291 // When axis is a categorical axis, but the type of axis is number or the scale of axis is not "auto"
1292 if (isCategorical && categoricalDomain) {
1293 return categoricalDomain.map((entry, index) => {
1294 var scaled = scale.map(entry);
1295 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1296 return null;
1297 }
1298 return {
1299 coordinate: scaled + offset,
1300 value: entry,
1301 index,
1302 offset
1303 };
1304 }).filter(_DataUtils.isNotNil);
1305 }
1306 if (scale.ticks) {
1307 return scale.ticks(tickCount).map((entry, index) => {
1308 var scaled = scale.map(entry);
1309 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1310 return null;
1311 }
1312 return {
1313 coordinate: scaled + offset,
1314 value: entry,
1315 index,
1316 offset
1317 };
1318 }).filter(_DataUtils.isNotNil);
1319 }
1320
1321 // When axis has duplicated text, serial numbers are used to generate scale
1322 return scale.domain().map((entry, index) => {
1323 var scaled = scale.map(entry);
1324 if (!(0, _isWellBehavedNumber.isWellBehavedNumber)(scaled)) {
1325 return null;
1326 }
1327 return {
1328 coordinate: scaled + offset,
1329 // @ts-expect-error can't use unknown as index
1330 value: duplicateDomain ? duplicateDomain[entry] : entry,
1331 index,
1332 offset
1333 };
1334 }).filter(_DataUtils.isNotNil);
1335};
1336exports.combineGraphicalItemTicks = combineGraphicalItemTicks;
1337var selectTicksOfGraphicalItem = exports.selectTicksOfGraphicalItem = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, selectRenderableAxisSettings, selectAxisScale, selectAxisRange, selectDuplicateDomain, selectCategoricalDomain, _pickAxisType.pickAxisType], combineGraphicalItemTicks);
1338
1339/**
1340 * This is the internal representation of an axis along with its scale function.
1341 * Here we have already computed the scale function for the axis,
1342 * and replaced the union type of scale (string | function) with just the function type.
1343 */
1344
1345var selectAxisWithScale = exports.selectAxisWithScale = (0, _reselect.createSelector)(selectBaseAxis, selectAxisScale, (axis, scale) => {
1346 if (axis == null || scale == null) {
1347 return undefined;
1348 }
1349 return _objectSpread(_objectSpread({}, axis), {}, {
1350 scale
1351 });
1352});
1353var selectZAxisScale = (0, _reselect.createSelector)([selectBaseAxis, selectRealScaleType, selectAxisDomain, selectAxisRangeWithReverse], combineScaleFunction);
1354var selectZAxisWithScale = exports.selectZAxisWithScale = (0, _reselect.createSelector)((state, _axisType, axisId) => selectZAxisSettings(state, axisId), selectZAxisScale, (axis, scale) => {
1355 if (axis == null || scale == null) {
1356 return undefined;
1357 }
1358 return _objectSpread(_objectSpread({}, axis), {}, {
1359 scale
1360 });
1361});
1362
1363/**
1364 * We are also going to need to implement polar chart directions if we want to support keyboard controls for those.
1365 */
1366
1367var selectChartDirection = exports.selectChartDirection = (0, _reselect.createSelector)([_chartLayoutContext.selectChartLayout, _selectAllAxes.selectAllXAxes, _selectAllAxes.selectAllYAxes], (layout, allXAxes, allYAxes) => {
1368 switch (layout) {
1369 case 'horizontal':
1370 {
1371 return allXAxes.some(axis => axis.reversed) ? 'right-to-left' : 'left-to-right';
1372 }
1373 case 'vertical':
1374 {
1375 return allYAxes.some(axis => axis.reversed) ? 'bottom-to-top' : 'top-to-bottom';
1376 }
1377 // TODO: make this better. For now, right arrow triggers "forward", left arrow "back"
1378 // however, the tooltip moves an unintuitive direction because of how the indices are rendered
1379 case 'centric':
1380 case 'radial':
1381 {
1382 return 'left-to-right';
1383 }
1384 default:
1385 {
1386 return undefined;
1387 }
1388 }
1389});
Note: See TracBrowser for help on using the repository browser.