@octanejs/recharts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
|
@@ -0,0 +1,2113 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/selectors/axisSelectors.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
// Sanctioned deviation: es-toolkit compat imports normalized to the ESM barrel
|
|
4
|
+
// ('es-toolkit/compat') — the per-function subpaths are CJS-only and break
|
|
5
|
+
// consumers that compile this binding from source (vite dev prebundle).
|
|
6
|
+
function ownKeys(e, r) {
|
|
7
|
+
var t = Object.keys(e);
|
|
8
|
+
if (Object.getOwnPropertySymbols) {
|
|
9
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
10
|
+
(r &&
|
|
11
|
+
(o = o.filter(function (r) {
|
|
12
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
13
|
+
})),
|
|
14
|
+
t.push.apply(t, o));
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
}
|
|
18
|
+
function _objectSpread(e) {
|
|
19
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
20
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
21
|
+
r % 2
|
|
22
|
+
? ownKeys(Object(t), !0).forEach(function (r) {
|
|
23
|
+
_defineProperty(e, r, t[r]);
|
|
24
|
+
})
|
|
25
|
+
: Object.getOwnPropertyDescriptors
|
|
26
|
+
? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
|
|
27
|
+
: ownKeys(Object(t)).forEach(function (r) {
|
|
28
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return e;
|
|
32
|
+
}
|
|
33
|
+
function _defineProperty(e, r, t) {
|
|
34
|
+
return (
|
|
35
|
+
(r = _toPropertyKey(r)) in e
|
|
36
|
+
? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 })
|
|
37
|
+
: (e[r] = t),
|
|
38
|
+
e
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
function _toPropertyKey(t) {
|
|
42
|
+
var i = _toPrimitive(t, 'string');
|
|
43
|
+
return 'symbol' == typeof i ? i : i + '';
|
|
44
|
+
}
|
|
45
|
+
function _toPrimitive(t, r) {
|
|
46
|
+
if ('object' != typeof t || !t) return t;
|
|
47
|
+
var e = t[Symbol.toPrimitive];
|
|
48
|
+
if (void 0 !== e) {
|
|
49
|
+
var i = e.call(t, r || 'default');
|
|
50
|
+
if ('object' != typeof i) return i;
|
|
51
|
+
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
52
|
+
}
|
|
53
|
+
return ('string' === r ? String : Number)(t);
|
|
54
|
+
}
|
|
55
|
+
function _slicedToArray(r, e) {
|
|
56
|
+
return (
|
|
57
|
+
_arrayWithHoles(r) ||
|
|
58
|
+
_iterableToArrayLimit(r, e) ||
|
|
59
|
+
_unsupportedIterableToArray(r, e) ||
|
|
60
|
+
_nonIterableRest()
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function _nonIterableRest() {
|
|
64
|
+
throw new TypeError(
|
|
65
|
+
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function _unsupportedIterableToArray(r, a) {
|
|
69
|
+
if (r) {
|
|
70
|
+
if ('string' == typeof r) return _arrayLikeToArray(r, a);
|
|
71
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
72
|
+
return (
|
|
73
|
+
'Object' === t && r.constructor && (t = r.constructor.name),
|
|
74
|
+
'Map' === t || 'Set' === t
|
|
75
|
+
? Array.from(r)
|
|
76
|
+
: 'Arguments' === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
|
|
77
|
+
? _arrayLikeToArray(r, a)
|
|
78
|
+
: void 0
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function _arrayLikeToArray(r, a) {
|
|
83
|
+
(null == a || a > r.length) && (a = r.length);
|
|
84
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
85
|
+
return n;
|
|
86
|
+
}
|
|
87
|
+
function _iterableToArrayLimit(r, l) {
|
|
88
|
+
var t =
|
|
89
|
+
null == r ? null : ('undefined' != typeof Symbol && r[Symbol.iterator]) || r['@@iterator'];
|
|
90
|
+
if (null != t) {
|
|
91
|
+
var e,
|
|
92
|
+
n,
|
|
93
|
+
i,
|
|
94
|
+
u,
|
|
95
|
+
a = [],
|
|
96
|
+
f = !0,
|
|
97
|
+
o = !1;
|
|
98
|
+
try {
|
|
99
|
+
if (((i = (t = t.call(r)).next), 0 === l)) {
|
|
100
|
+
if (Object(t) !== t) return;
|
|
101
|
+
f = !1;
|
|
102
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
103
|
+
} catch (r) {
|
|
104
|
+
((o = !0), (n = r));
|
|
105
|
+
} finally {
|
|
106
|
+
try {
|
|
107
|
+
if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) return;
|
|
108
|
+
} finally {
|
|
109
|
+
if (o) throw n;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return a;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function _arrayWithHoles(r) {
|
|
116
|
+
if (Array.isArray(r)) return r;
|
|
117
|
+
}
|
|
118
|
+
import { createSelector } from 'reselect';
|
|
119
|
+
import { range } from 'es-toolkit/compat';
|
|
120
|
+
import { selectChartLayout } from '../../context/chartLayoutContext';
|
|
121
|
+
import {
|
|
122
|
+
getDomainOfStackGroups,
|
|
123
|
+
getStackedData,
|
|
124
|
+
getValueByDataKey,
|
|
125
|
+
isCategoricalAxis,
|
|
126
|
+
} from '../../util/ChartUtils';
|
|
127
|
+
import {
|
|
128
|
+
selectChartDataWithIndexes,
|
|
129
|
+
selectChartDataWithIndexesIfNotInPanoramaPosition4,
|
|
130
|
+
selectChartDataSliceIfNotInPanorama,
|
|
131
|
+
} from './dataSelectors';
|
|
132
|
+
import {
|
|
133
|
+
isWellFormedNumberDomain,
|
|
134
|
+
numericalDomainSpecifiedWithoutRequiringData,
|
|
135
|
+
parseNumericalUserDomain,
|
|
136
|
+
} from '../../util/isDomainSpecifiedByUser';
|
|
137
|
+
import {
|
|
138
|
+
getPercentValue,
|
|
139
|
+
hasDuplicate,
|
|
140
|
+
isNan,
|
|
141
|
+
isNotNil,
|
|
142
|
+
isNumOrStr,
|
|
143
|
+
mathSign,
|
|
144
|
+
} from '../../util/DataUtils';
|
|
145
|
+
import { isWellBehavedNumber } from '../../util/isWellBehavedNumber';
|
|
146
|
+
import { getNiceTickValues, getTickValuesFixedDomain } from '../../util/scale';
|
|
147
|
+
import { selectChartHeight, selectChartWidth } from './containerSelectors';
|
|
148
|
+
import { selectAllXAxes, selectAllYAxes } from './selectAllAxes';
|
|
149
|
+
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
|
|
150
|
+
import { selectBrushDimensions, selectBrushSettings } from './brushSelectors';
|
|
151
|
+
import {
|
|
152
|
+
selectBarCategoryGap,
|
|
153
|
+
selectChartName,
|
|
154
|
+
selectReverseStackOrder,
|
|
155
|
+
selectStackOffsetType,
|
|
156
|
+
} from './rootPropsSelectors';
|
|
157
|
+
import {
|
|
158
|
+
selectAngleAxis,
|
|
159
|
+
selectAngleAxisRange,
|
|
160
|
+
selectRadiusAxis,
|
|
161
|
+
selectRadiusAxisRange,
|
|
162
|
+
} from './polarAxisSelectors';
|
|
163
|
+
import { pickAxisType } from './pickAxisType';
|
|
164
|
+
import { pickAxisId } from './pickAxisId';
|
|
165
|
+
import { combineAxisRangeWithReverse } from './combiners/combineAxisRangeWithReverse';
|
|
166
|
+
import { DEFAULT_Y_AXIS_WIDTH } from '../../util/Constants';
|
|
167
|
+
import { getStackSeriesIdentifier } from '../../util/stacks/getStackSeriesIdentifier';
|
|
168
|
+
import { combineDisplayedStackedData } from './combiners/combineDisplayedStackedData';
|
|
169
|
+
import { isStacked } from '../types/StackedGraphicalItem';
|
|
170
|
+
import { numberDomainEqualityCheck } from './numberDomainEqualityCheck';
|
|
171
|
+
import { emptyArraysAreEqualCheck } from './arrayEqualityCheck';
|
|
172
|
+
import { selectTooltipAxisType } from './selectTooltipAxisType';
|
|
173
|
+
import { selectTooltipAxisId } from './selectTooltipAxisId';
|
|
174
|
+
import { rechartsScaleFactory } from '../../util/scale/RechartsScale';
|
|
175
|
+
import { combineCheckedDomain } from './combiners/combineCheckedDomain';
|
|
176
|
+
import { combineConfiguredScale } from './combiners/combineConfiguredScale';
|
|
177
|
+
import { combineRealScaleType } from './combiners/combineRealScaleType';
|
|
178
|
+
import { createCategoricalInverse } from '../../util/scale/createCategoricalInverse';
|
|
179
|
+
import { combineInverseScaleFunction } from './combiners/combineInverseScaleFunction';
|
|
180
|
+
export var defaultNumericDomain = [0, 'auto'];
|
|
181
|
+
/**
|
|
182
|
+
* If an axis is not explicitly defined as an element,
|
|
183
|
+
* we still need to render something in the chart and we need
|
|
184
|
+
* some object to hold the domain and default settings.
|
|
185
|
+
*/
|
|
186
|
+
export var implicitXAxis = {
|
|
187
|
+
allowDataOverflow: false,
|
|
188
|
+
allowDecimals: true,
|
|
189
|
+
allowDuplicatedCategory: true,
|
|
190
|
+
angle: 0,
|
|
191
|
+
dataKey: undefined,
|
|
192
|
+
domain: undefined,
|
|
193
|
+
height: 30,
|
|
194
|
+
hide: true,
|
|
195
|
+
id: 0,
|
|
196
|
+
includeHidden: false,
|
|
197
|
+
interval: 'preserveEnd',
|
|
198
|
+
minTickGap: 5,
|
|
199
|
+
mirror: false,
|
|
200
|
+
name: undefined,
|
|
201
|
+
orientation: 'bottom',
|
|
202
|
+
padding: {
|
|
203
|
+
left: 0,
|
|
204
|
+
right: 0,
|
|
205
|
+
},
|
|
206
|
+
reversed: false,
|
|
207
|
+
scale: 'auto',
|
|
208
|
+
tick: true,
|
|
209
|
+
tickCount: 5,
|
|
210
|
+
tickFormatter: undefined,
|
|
211
|
+
ticks: undefined,
|
|
212
|
+
type: 'category',
|
|
213
|
+
unit: undefined,
|
|
214
|
+
niceTicks: 'auto',
|
|
215
|
+
};
|
|
216
|
+
export var selectXAxisSettingsNoDefaults = (state, axisId) => {
|
|
217
|
+
return state.cartesianAxis.xAxis[axisId];
|
|
218
|
+
};
|
|
219
|
+
export var selectXAxisSettings = (state, axisId) => {
|
|
220
|
+
var axis = selectXAxisSettingsNoDefaults(state, axisId);
|
|
221
|
+
if (axis == null) {
|
|
222
|
+
return implicitXAxis;
|
|
223
|
+
}
|
|
224
|
+
return axis;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* If an axis is not explicitly defined as an element,
|
|
229
|
+
* we still need to render something in the chart and we need
|
|
230
|
+
* some object to hold the domain and default settings.
|
|
231
|
+
*/
|
|
232
|
+
export var implicitYAxis = {
|
|
233
|
+
allowDataOverflow: false,
|
|
234
|
+
allowDecimals: true,
|
|
235
|
+
allowDuplicatedCategory: true,
|
|
236
|
+
angle: 0,
|
|
237
|
+
dataKey: undefined,
|
|
238
|
+
domain: defaultNumericDomain,
|
|
239
|
+
hide: true,
|
|
240
|
+
id: 0,
|
|
241
|
+
includeHidden: false,
|
|
242
|
+
interval: 'preserveEnd',
|
|
243
|
+
minTickGap: 5,
|
|
244
|
+
mirror: false,
|
|
245
|
+
name: undefined,
|
|
246
|
+
orientation: 'left',
|
|
247
|
+
padding: {
|
|
248
|
+
top: 0,
|
|
249
|
+
bottom: 0,
|
|
250
|
+
},
|
|
251
|
+
reversed: false,
|
|
252
|
+
scale: 'auto',
|
|
253
|
+
tick: true,
|
|
254
|
+
tickCount: 5,
|
|
255
|
+
tickFormatter: undefined,
|
|
256
|
+
ticks: undefined,
|
|
257
|
+
type: 'number',
|
|
258
|
+
unit: undefined,
|
|
259
|
+
niceTicks: 'auto',
|
|
260
|
+
width: DEFAULT_Y_AXIS_WIDTH,
|
|
261
|
+
};
|
|
262
|
+
export var selectYAxisSettingsNoDefaults = (state, axisId) => {
|
|
263
|
+
return state.cartesianAxis.yAxis[axisId];
|
|
264
|
+
};
|
|
265
|
+
export var selectYAxisSettings = (state, axisId) => {
|
|
266
|
+
var axis = selectYAxisSettingsNoDefaults(state, axisId);
|
|
267
|
+
if (axis == null) {
|
|
268
|
+
return implicitYAxis;
|
|
269
|
+
}
|
|
270
|
+
return axis;
|
|
271
|
+
};
|
|
272
|
+
export var implicitZAxis = {
|
|
273
|
+
domain: [0, 'auto'],
|
|
274
|
+
includeHidden: false,
|
|
275
|
+
reversed: false,
|
|
276
|
+
allowDataOverflow: false,
|
|
277
|
+
allowDuplicatedCategory: false,
|
|
278
|
+
dataKey: undefined,
|
|
279
|
+
id: 0,
|
|
280
|
+
name: '',
|
|
281
|
+
range: [64, 64],
|
|
282
|
+
scale: 'auto',
|
|
283
|
+
type: 'number',
|
|
284
|
+
unit: '',
|
|
285
|
+
};
|
|
286
|
+
export var selectZAxisSettings = (state, axisId) => {
|
|
287
|
+
var axis = state.cartesianAxis.zAxis[axisId];
|
|
288
|
+
if (axis == null) {
|
|
289
|
+
return implicitZAxis;
|
|
290
|
+
}
|
|
291
|
+
return axis;
|
|
292
|
+
};
|
|
293
|
+
export var selectBaseAxis = (state, axisType, axisId) => {
|
|
294
|
+
switch (axisType) {
|
|
295
|
+
case 'xAxis': {
|
|
296
|
+
return selectXAxisSettings(state, axisId);
|
|
297
|
+
}
|
|
298
|
+
case 'yAxis': {
|
|
299
|
+
return selectYAxisSettings(state, axisId);
|
|
300
|
+
}
|
|
301
|
+
case 'zAxis': {
|
|
302
|
+
return selectZAxisSettings(state, axisId);
|
|
303
|
+
}
|
|
304
|
+
case 'angleAxis': {
|
|
305
|
+
return selectAngleAxis(state, axisId);
|
|
306
|
+
}
|
|
307
|
+
case 'radiusAxis': {
|
|
308
|
+
return selectRadiusAxis(state, axisId);
|
|
309
|
+
}
|
|
310
|
+
default:
|
|
311
|
+
throw new Error('Unexpected axis type: '.concat(axisType));
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
var selectCartesianAxisSettings = (state, axisType, axisId) => {
|
|
315
|
+
switch (axisType) {
|
|
316
|
+
case 'xAxis': {
|
|
317
|
+
return selectXAxisSettings(state, axisId);
|
|
318
|
+
}
|
|
319
|
+
case 'yAxis': {
|
|
320
|
+
return selectYAxisSettings(state, axisId);
|
|
321
|
+
}
|
|
322
|
+
default:
|
|
323
|
+
throw new Error('Unexpected axis type: '.concat(axisType));
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Selects either an X or Y axis. Doesn't work with Z axis - for that, instead use selectBaseAxis.
|
|
329
|
+
* @param state Root state
|
|
330
|
+
* @param axisType xAxis | yAxis
|
|
331
|
+
* @param axisId xAxisId | yAxisId
|
|
332
|
+
* @returns axis settings object
|
|
333
|
+
*/
|
|
334
|
+
export var selectRenderableAxisSettings = (state, axisType, axisId) => {
|
|
335
|
+
switch (axisType) {
|
|
336
|
+
case 'xAxis': {
|
|
337
|
+
return selectXAxisSettings(state, axisId);
|
|
338
|
+
}
|
|
339
|
+
case 'yAxis': {
|
|
340
|
+
return selectYAxisSettings(state, axisId);
|
|
341
|
+
}
|
|
342
|
+
case 'angleAxis': {
|
|
343
|
+
return selectAngleAxis(state, axisId);
|
|
344
|
+
}
|
|
345
|
+
case 'radiusAxis': {
|
|
346
|
+
return selectRadiusAxis(state, axisId);
|
|
347
|
+
}
|
|
348
|
+
default:
|
|
349
|
+
throw new Error('Unexpected axis type: '.concat(axisType));
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @param state RechartsRootState
|
|
355
|
+
* @return boolean true if there is at least one Bar or RadialBar
|
|
356
|
+
*/
|
|
357
|
+
export var selectHasBar = (state) =>
|
|
358
|
+
state.graphicalItems.cartesianItems.some((item) => item.type === 'bar') ||
|
|
359
|
+
state.graphicalItems.polarItems.some((item) => item.type === 'radialBar');
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Filters CartesianGraphicalItemSettings by the relevant axis ID
|
|
363
|
+
* @param axisType 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'angleAxis'
|
|
364
|
+
* @param axisId from props, defaults to 0
|
|
365
|
+
*
|
|
366
|
+
* @returns Predicate function that return true for CartesianGraphicalItemSettings that are relevant to the specified axis
|
|
367
|
+
*/
|
|
368
|
+
export function itemAxisPredicate(axisType, axisId) {
|
|
369
|
+
return (item) => {
|
|
370
|
+
switch (axisType) {
|
|
371
|
+
case 'xAxis':
|
|
372
|
+
// 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
|
|
373
|
+
return 'xAxisId' in item && item.xAxisId === axisId;
|
|
374
|
+
case 'yAxis':
|
|
375
|
+
return 'yAxisId' in item && item.yAxisId === axisId;
|
|
376
|
+
case 'zAxis':
|
|
377
|
+
return 'zAxisId' in item && item.zAxisId === axisId;
|
|
378
|
+
case 'angleAxis':
|
|
379
|
+
return 'angleAxisId' in item && item.angleAxisId === axisId;
|
|
380
|
+
case 'radiusAxis':
|
|
381
|
+
return 'radiusAxisId' in item && item.radiusAxisId === axisId;
|
|
382
|
+
default:
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// TODO appears there is a bug where this selector is called from polar context, find and fix it.
|
|
389
|
+
export var selectUnfilteredCartesianItems = (state) => state.graphicalItems.cartesianItems;
|
|
390
|
+
var selectAxisPredicate = createSelector([pickAxisType, pickAxisId], itemAxisPredicate);
|
|
391
|
+
export var combineGraphicalItemsSettings = (graphicalItems, axisSettings, axisPredicate) =>
|
|
392
|
+
graphicalItems.filter(axisPredicate).filter((item) => {
|
|
393
|
+
if (
|
|
394
|
+
(axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.includeHidden) ===
|
|
395
|
+
true
|
|
396
|
+
) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
return !item.hide;
|
|
400
|
+
});
|
|
401
|
+
export var selectCartesianItemsSettings = createSelector(
|
|
402
|
+
[selectUnfilteredCartesianItems, selectBaseAxis, selectAxisPredicate],
|
|
403
|
+
combineGraphicalItemsSettings,
|
|
404
|
+
{
|
|
405
|
+
memoizeOptions: {
|
|
406
|
+
resultEqualityCheck: emptyArraysAreEqualCheck,
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
);
|
|
410
|
+
export var selectStackedCartesianItemsSettings = createSelector(
|
|
411
|
+
[selectCartesianItemsSettings],
|
|
412
|
+
(cartesianItems) => {
|
|
413
|
+
return cartesianItems
|
|
414
|
+
.filter((item) => item.type === 'area' || item.type === 'bar')
|
|
415
|
+
.filter(isStacked);
|
|
416
|
+
},
|
|
417
|
+
);
|
|
418
|
+
export var filterGraphicalNotStackedItems = (cartesianItems) =>
|
|
419
|
+
cartesianItems.filter((item) => !('stackId' in item) || item.stackId === undefined);
|
|
420
|
+
var selectCartesianItemsSettingsExceptStacked = createSelector(
|
|
421
|
+
[selectCartesianItemsSettings],
|
|
422
|
+
filterGraphicalNotStackedItems,
|
|
423
|
+
);
|
|
424
|
+
export var combineGraphicalItemsData = (cartesianItems) =>
|
|
425
|
+
cartesianItems
|
|
426
|
+
.map((item) => item.data)
|
|
427
|
+
.filter(Boolean)
|
|
428
|
+
.flat(1);
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Returns true if at least one graphical item does not define its own `data` prop
|
|
432
|
+
* and therefore relies on the chart-level data.
|
|
433
|
+
* This is used to decide whether to merge chart-level data into the axis domain calculation.
|
|
434
|
+
*/
|
|
435
|
+
export var selectAnyCartesianItemsUsesChartData = createSelector(
|
|
436
|
+
[selectCartesianItemsSettings],
|
|
437
|
+
(items) => items.some((item) => !item.data),
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* This is a "cheap" selector - it returns the data but doesn't iterate them, so it is not sensitive on the array length.
|
|
442
|
+
* Also does not apply dataKey yet.
|
|
443
|
+
* @param state RechartsRootState
|
|
444
|
+
* @returns data defined on the chart graphical items, such as Line or Scatter or Pie, and filtered with appropriate dataKey
|
|
445
|
+
*/
|
|
446
|
+
export var selectCartesianGraphicalItemsData = createSelector(
|
|
447
|
+
[selectCartesianItemsSettings],
|
|
448
|
+
combineGraphicalItemsData,
|
|
449
|
+
{
|
|
450
|
+
memoizeOptions: {
|
|
451
|
+
resultEqualityCheck: emptyArraysAreEqualCheck,
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
);
|
|
455
|
+
export var combineDisplayedData = (graphicalItemsData, _ref) => {
|
|
456
|
+
var _ref$chartData = _ref.chartData,
|
|
457
|
+
chartData = _ref$chartData === void 0 ? [] : _ref$chartData,
|
|
458
|
+
dataStartIndex = _ref.dataStartIndex,
|
|
459
|
+
dataEndIndex = _ref.dataEndIndex;
|
|
460
|
+
if (graphicalItemsData.length > 0) {
|
|
461
|
+
/*
|
|
462
|
+
* There is no slicing when data is defined on graphical items. Why?
|
|
463
|
+
* Because Brush ignores data defined on graphical items,
|
|
464
|
+
* and does not render.
|
|
465
|
+
* So Brush will never show up in a Scatter chart for example.
|
|
466
|
+
* This is something we will need to fix.
|
|
467
|
+
*
|
|
468
|
+
* Now, when the root chart data is not defined, the dataEndIndex is 0,
|
|
469
|
+
* which means the itemsData will be sliced to an empty array anyway.
|
|
470
|
+
* But that's an implementation detail, and we can fix that too.
|
|
471
|
+
*
|
|
472
|
+
* Also, in absence of Axis dataKey, we use the dataKey from each item, respectively.
|
|
473
|
+
* This is the usual pattern for numerical axis, that is the one where bars go up:
|
|
474
|
+
* users don't specify any dataKey by default and expect the axis to "just match the data".
|
|
475
|
+
*/
|
|
476
|
+
return graphicalItemsData;
|
|
477
|
+
}
|
|
478
|
+
return chartData.slice(dataStartIndex, dataEndIndex + 1);
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* This selector will return all data there is in the chart: graphical items, chart root, all together.
|
|
483
|
+
* Useful for figuring out an axis domain (because that needs to know of everything),
|
|
484
|
+
* not useful for rendering individual graphical elements (because they need to know which data is theirs and which is not).
|
|
485
|
+
*
|
|
486
|
+
* This function will discard the original indexes, so it is also not useful for anything that depends on ordering.
|
|
487
|
+
*/
|
|
488
|
+
export var selectDisplayedData = createSelector(
|
|
489
|
+
[selectCartesianGraphicalItemsData, selectChartDataWithIndexesIfNotInPanoramaPosition4],
|
|
490
|
+
combineDisplayedData,
|
|
491
|
+
);
|
|
492
|
+
export var combineAppliedValues = (data, axisSettings, items) => {
|
|
493
|
+
if ((axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null) {
|
|
494
|
+
return data.map((item) => ({
|
|
495
|
+
value: getValueByDataKey(item, axisSettings.dataKey),
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
if (items.length > 0) {
|
|
499
|
+
return items
|
|
500
|
+
.map((item) => item.dataKey)
|
|
501
|
+
.flatMap((dataKey) =>
|
|
502
|
+
data.map((entry) => ({
|
|
503
|
+
value: getValueByDataKey(entry, dataKey),
|
|
504
|
+
})),
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
return data.map((entry) => ({
|
|
508
|
+
value: entry,
|
|
509
|
+
}));
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Computes applied values from graphical items data plus, when needed, chart-level data.
|
|
514
|
+
*
|
|
515
|
+
* When at least one graphical item has no own `data` (it relies on chart root data) AND the axis has a `dataKey`,
|
|
516
|
+
* AND there are other items that do have their own data (meaning `displayedData` only contains graphical items data,
|
|
517
|
+
* not chart root data), we also include chart root data values so the axis domain covers all categories,
|
|
518
|
+
* including those only present in the chart root data but not in any graphical item's own data.
|
|
519
|
+
*
|
|
520
|
+
* Values from chart root data that don't match the axis dataKey (undefined) are excluded.
|
|
521
|
+
*/
|
|
522
|
+
export var combineAllAppliedValues = (
|
|
523
|
+
displayedData,
|
|
524
|
+
axisSettings,
|
|
525
|
+
items,
|
|
526
|
+
_ref2,
|
|
527
|
+
anyItemUsesChartData,
|
|
528
|
+
graphicalItemsData,
|
|
529
|
+
) => {
|
|
530
|
+
var _ref2$chartData = _ref2.chartData,
|
|
531
|
+
chartData = _ref2$chartData === void 0 ? [] : _ref2$chartData,
|
|
532
|
+
dataStartIndex = _ref2.dataStartIndex,
|
|
533
|
+
dataEndIndex = _ref2.dataEndIndex;
|
|
534
|
+
var appliedValues = combineAppliedValues(displayedData, axisSettings, items);
|
|
535
|
+
if (
|
|
536
|
+
anyItemUsesChartData &&
|
|
537
|
+
(axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null &&
|
|
538
|
+
graphicalItemsData.length > 0
|
|
539
|
+
) {
|
|
540
|
+
var chartDataSlice = chartData.slice(dataStartIndex, dataEndIndex + 1);
|
|
541
|
+
var chartAppliedValues = chartDataSlice
|
|
542
|
+
.map((item) => ({
|
|
543
|
+
value: getValueByDataKey(item, axisSettings.dataKey),
|
|
544
|
+
}))
|
|
545
|
+
.filter((av) => av.value != null);
|
|
546
|
+
return [...chartAppliedValues, ...appliedValues];
|
|
547
|
+
}
|
|
548
|
+
return appliedValues;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* This selector will return all values with the appropriate dataKey applied on them.
|
|
553
|
+
* Which dataKey is appropriate depends on where it is defined.
|
|
554
|
+
*
|
|
555
|
+
* This is an expensive selector - it will iterate all data and compute their value using the provided dataKey.
|
|
556
|
+
*/
|
|
557
|
+
export var selectAllAppliedValues = createSelector(
|
|
558
|
+
[
|
|
559
|
+
selectDisplayedData,
|
|
560
|
+
selectBaseAxis,
|
|
561
|
+
selectCartesianItemsSettings,
|
|
562
|
+
selectChartDataWithIndexesIfNotInPanoramaPosition4,
|
|
563
|
+
selectAnyCartesianItemsUsesChartData,
|
|
564
|
+
selectCartesianGraphicalItemsData,
|
|
565
|
+
],
|
|
566
|
+
combineAllAppliedValues,
|
|
567
|
+
);
|
|
568
|
+
function makeNumber(val) {
|
|
569
|
+
if (isNumOrStr(val) || val instanceof Date) {
|
|
570
|
+
var n = Number(val);
|
|
571
|
+
if (isWellBehavedNumber(n)) {
|
|
572
|
+
return n;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
function makeDomain(val) {
|
|
578
|
+
if (Array.isArray(val)) {
|
|
579
|
+
var attempt = [makeNumber(val[0]), makeNumber(val[1])];
|
|
580
|
+
if (isWellFormedNumberDomain(attempt)) {
|
|
581
|
+
return attempt;
|
|
582
|
+
}
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
var n = makeNumber(val);
|
|
586
|
+
if (n == null) {
|
|
587
|
+
return undefined;
|
|
588
|
+
}
|
|
589
|
+
return [n, n];
|
|
590
|
+
}
|
|
591
|
+
function onlyAllowNumbers(data) {
|
|
592
|
+
return data.map(makeNumber).filter(isNotNil);
|
|
593
|
+
}
|
|
594
|
+
function sortBy(a, b) {
|
|
595
|
+
var aNum = makeNumber(a);
|
|
596
|
+
var bNum = makeNumber(b);
|
|
597
|
+
if (aNum == null && bNum == null) {
|
|
598
|
+
return 0;
|
|
599
|
+
}
|
|
600
|
+
if (aNum == null) {
|
|
601
|
+
return -1;
|
|
602
|
+
}
|
|
603
|
+
if (bNum == null) {
|
|
604
|
+
return 1;
|
|
605
|
+
}
|
|
606
|
+
return aNum - bNum;
|
|
607
|
+
}
|
|
608
|
+
export var selectSortedDataPoints = createSelector([selectAllAppliedValues], (appliedData) => {
|
|
609
|
+
return appliedData === null || appliedData === void 0
|
|
610
|
+
? void 0
|
|
611
|
+
: appliedData.map((item) => item.value).sort(sortBy);
|
|
612
|
+
});
|
|
613
|
+
export function isErrorBarRelevantForAxisType(axisType, errorBar) {
|
|
614
|
+
switch (axisType) {
|
|
615
|
+
case 'xAxis':
|
|
616
|
+
return errorBar.direction === 'x';
|
|
617
|
+
case 'yAxis':
|
|
618
|
+
return errorBar.direction === 'y';
|
|
619
|
+
default:
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* @param entry One item in the 'data' array. Could be anything really - this is defined externally. This is the raw, before dataKey application
|
|
625
|
+
* @param appliedValue This is the result of applying the 'main' dataKey on the `entry`.
|
|
626
|
+
* @param relevantErrorBars Error bars that are relevant for the current axis and layout and all that.
|
|
627
|
+
* @return either undefined or an array of ErrorValue
|
|
628
|
+
*/
|
|
629
|
+
export function getErrorDomainByDataKey(entry, appliedValue, relevantErrorBars) {
|
|
630
|
+
if (!relevantErrorBars) {
|
|
631
|
+
return [];
|
|
632
|
+
}
|
|
633
|
+
if (!relevantErrorBars.length) {
|
|
634
|
+
return [];
|
|
635
|
+
}
|
|
636
|
+
var appliedNumericValue;
|
|
637
|
+
if (typeof appliedValue === 'number' && !isNan(appliedValue)) {
|
|
638
|
+
appliedNumericValue = appliedValue;
|
|
639
|
+
} else if (Array.isArray(appliedValue)) {
|
|
640
|
+
var numericRangeValues = onlyAllowNumbers(appliedValue);
|
|
641
|
+
if (numericRangeValues.length > 0) {
|
|
642
|
+
appliedNumericValue = Math.max(...numericRangeValues);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (appliedNumericValue == null) {
|
|
646
|
+
return [];
|
|
647
|
+
}
|
|
648
|
+
return onlyAllowNumbers(
|
|
649
|
+
relevantErrorBars.flatMap((eb) => {
|
|
650
|
+
var errorValue = getValueByDataKey(entry, eb.dataKey);
|
|
651
|
+
var lowBound, highBound;
|
|
652
|
+
if (Array.isArray(errorValue)) {
|
|
653
|
+
var _errorValue = _slicedToArray(errorValue, 2);
|
|
654
|
+
lowBound = _errorValue[0];
|
|
655
|
+
highBound = _errorValue[1];
|
|
656
|
+
} else {
|
|
657
|
+
lowBound = highBound = errorValue;
|
|
658
|
+
}
|
|
659
|
+
if (!isWellBehavedNumber(lowBound) || !isWellBehavedNumber(highBound)) {
|
|
660
|
+
return undefined;
|
|
661
|
+
}
|
|
662
|
+
return [appliedNumericValue - lowBound, appliedNumericValue + highBound];
|
|
663
|
+
}),
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
export var selectTooltipAxis = (state) => {
|
|
667
|
+
var axisType = selectTooltipAxisType(state);
|
|
668
|
+
var axisId = selectTooltipAxisId(state);
|
|
669
|
+
return selectRenderableAxisSettings(state, axisType, axisId);
|
|
670
|
+
};
|
|
671
|
+
export var selectTooltipAxisDataKey = createSelector([selectTooltipAxis], (axis) =>
|
|
672
|
+
axis === null || axis === void 0 ? void 0 : axis.dataKey,
|
|
673
|
+
);
|
|
674
|
+
export var selectDisplayedStackedData = createSelector(
|
|
675
|
+
[
|
|
676
|
+
selectStackedCartesianItemsSettings,
|
|
677
|
+
selectChartDataWithIndexesIfNotInPanoramaPosition4,
|
|
678
|
+
selectTooltipAxis,
|
|
679
|
+
],
|
|
680
|
+
combineDisplayedStackedData,
|
|
681
|
+
);
|
|
682
|
+
export var combineStackGroups = (displayedData, items, stackOffsetType, reverseStackOrder) => {
|
|
683
|
+
var initialItemsGroups = {};
|
|
684
|
+
var itemsGroup = items.reduce((acc, item) => {
|
|
685
|
+
if (item.stackId == null) {
|
|
686
|
+
return acc;
|
|
687
|
+
}
|
|
688
|
+
var stack = acc[item.stackId];
|
|
689
|
+
if (stack == null) {
|
|
690
|
+
stack = [];
|
|
691
|
+
}
|
|
692
|
+
stack.push(item);
|
|
693
|
+
acc[item.stackId] = stack;
|
|
694
|
+
return acc;
|
|
695
|
+
}, initialItemsGroups);
|
|
696
|
+
return Object.fromEntries(
|
|
697
|
+
Object.entries(itemsGroup).map((_ref3) => {
|
|
698
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
699
|
+
stackId = _ref4[0],
|
|
700
|
+
graphicalItems = _ref4[1];
|
|
701
|
+
var orderedGraphicalItems = reverseStackOrder
|
|
702
|
+
? [...graphicalItems].reverse()
|
|
703
|
+
: graphicalItems;
|
|
704
|
+
var dataKeys = orderedGraphicalItems.map(getStackSeriesIdentifier);
|
|
705
|
+
return [
|
|
706
|
+
stackId,
|
|
707
|
+
{
|
|
708
|
+
// @ts-expect-error getStackedData requires that the input is array of objects, Recharts does not test for that
|
|
709
|
+
stackedData: getStackedData(displayedData, dataKeys, stackOffsetType),
|
|
710
|
+
graphicalItems: orderedGraphicalItems,
|
|
711
|
+
},
|
|
712
|
+
];
|
|
713
|
+
}),
|
|
714
|
+
);
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Stack groups are groups of graphical items that stack on each other.
|
|
719
|
+
* Stack is a function of axis type (X, Y), axis ID, and stack ID.
|
|
720
|
+
* Graphical items that do not have a stack ID are not going to be present in stack groups.
|
|
721
|
+
*/
|
|
722
|
+
export var selectStackGroups = createSelector(
|
|
723
|
+
[
|
|
724
|
+
selectDisplayedStackedData,
|
|
725
|
+
selectStackedCartesianItemsSettings,
|
|
726
|
+
selectStackOffsetType,
|
|
727
|
+
selectReverseStackOrder,
|
|
728
|
+
],
|
|
729
|
+
combineStackGroups,
|
|
730
|
+
);
|
|
731
|
+
export var combineDomainOfStackGroups = (
|
|
732
|
+
stackGroups,
|
|
733
|
+
_ref5,
|
|
734
|
+
axisType,
|
|
735
|
+
domainFromUserPreference,
|
|
736
|
+
) => {
|
|
737
|
+
var dataStartIndex = _ref5.dataStartIndex,
|
|
738
|
+
dataEndIndex = _ref5.dataEndIndex;
|
|
739
|
+
if (domainFromUserPreference != null) {
|
|
740
|
+
// User has specified a domain, so we respect that and we can skip computing anything else
|
|
741
|
+
return undefined;
|
|
742
|
+
}
|
|
743
|
+
if (axisType === 'zAxis') {
|
|
744
|
+
// ZAxis ignores stacks
|
|
745
|
+
return undefined;
|
|
746
|
+
}
|
|
747
|
+
return getDomainOfStackGroups(stackGroups, dataStartIndex, dataEndIndex);
|
|
748
|
+
};
|
|
749
|
+
var selectAllowsDataOverflow = createSelector(
|
|
750
|
+
[selectBaseAxis],
|
|
751
|
+
(axisSettings) => axisSettings.allowDataOverflow,
|
|
752
|
+
);
|
|
753
|
+
export var getDomainDefinition = (axisSettings) => {
|
|
754
|
+
var _axisSettings$domain;
|
|
755
|
+
if (axisSettings == null || !('domain' in axisSettings)) {
|
|
756
|
+
return defaultNumericDomain;
|
|
757
|
+
}
|
|
758
|
+
if (axisSettings.domain != null) {
|
|
759
|
+
return axisSettings.domain;
|
|
760
|
+
}
|
|
761
|
+
if ('ticks' in axisSettings && axisSettings.ticks != null) {
|
|
762
|
+
if (axisSettings.type === 'number') {
|
|
763
|
+
var allValues = onlyAllowNumbers(axisSettings.ticks);
|
|
764
|
+
return [Math.min(...allValues), Math.max(...allValues)];
|
|
765
|
+
}
|
|
766
|
+
if (axisSettings.type === 'category') {
|
|
767
|
+
return axisSettings.ticks.map(String);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return (_axisSettings$domain =
|
|
771
|
+
axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.domain) !== null &&
|
|
772
|
+
_axisSettings$domain !== void 0
|
|
773
|
+
? _axisSettings$domain
|
|
774
|
+
: defaultNumericDomain;
|
|
775
|
+
};
|
|
776
|
+
export var selectDomainDefinition = createSelector([selectBaseAxis], getDomainDefinition);
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Under certain circumstances, we can determine the domain without looking at the data at all.
|
|
780
|
+
* This is the case when the domain is explicitly specified as numbers, or when it is specified
|
|
781
|
+
* as 'auto' or 'dataMin'/'dataMax' and data overflow is not allowed.
|
|
782
|
+
*
|
|
783
|
+
* In that case, this function will return the domain, otherwise it returns undefined.
|
|
784
|
+
*
|
|
785
|
+
* This is an optimization to avoid unnecessary data processing.
|
|
786
|
+
* @param state
|
|
787
|
+
* @param axisType
|
|
788
|
+
* @param axisId
|
|
789
|
+
* @param isPanorama
|
|
790
|
+
*/
|
|
791
|
+
export var selectDomainFromUserPreference = createSelector(
|
|
792
|
+
[selectDomainDefinition, selectAllowsDataOverflow],
|
|
793
|
+
numericalDomainSpecifiedWithoutRequiringData,
|
|
794
|
+
);
|
|
795
|
+
export var selectDomainOfStackGroups = createSelector(
|
|
796
|
+
[selectStackGroups, selectChartDataWithIndexes, pickAxisType, selectDomainFromUserPreference],
|
|
797
|
+
combineDomainOfStackGroups,
|
|
798
|
+
{
|
|
799
|
+
memoizeOptions: {
|
|
800
|
+
resultEqualityCheck: numberDomainEqualityCheck,
|
|
801
|
+
},
|
|
802
|
+
},
|
|
803
|
+
);
|
|
804
|
+
export var selectAllErrorBarSettings = (state) => state.errorBars;
|
|
805
|
+
var combineRelevantErrorBarSettings = (cartesianItemsSettings, allErrorBarSettings, axisType) => {
|
|
806
|
+
return cartesianItemsSettings
|
|
807
|
+
.flatMap((item) => {
|
|
808
|
+
return allErrorBarSettings[item.id];
|
|
809
|
+
})
|
|
810
|
+
.filter(Boolean)
|
|
811
|
+
.filter((e) => {
|
|
812
|
+
return isErrorBarRelevantForAxisType(axisType, e);
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
export var mergeDomains = function mergeDomains() {
|
|
816
|
+
for (var _len = arguments.length, domains = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
817
|
+
domains[_key] = arguments[_key];
|
|
818
|
+
}
|
|
819
|
+
var allDomains = domains.filter(Boolean);
|
|
820
|
+
if (allDomains.length === 0) {
|
|
821
|
+
return undefined;
|
|
822
|
+
}
|
|
823
|
+
var allValues = allDomains.flat();
|
|
824
|
+
var min = Math.min(...allValues);
|
|
825
|
+
var max = Math.max(...allValues);
|
|
826
|
+
return [min, max];
|
|
827
|
+
};
|
|
828
|
+
export var combineDomainOfAllAppliedNumericalValuesIncludingErrorValues =
|
|
829
|
+
function combineDomainOfAllAppliedNumericalValuesIncludingErrorValues(
|
|
830
|
+
displayedData,
|
|
831
|
+
axisSettings,
|
|
832
|
+
items,
|
|
833
|
+
errorBars,
|
|
834
|
+
axisType,
|
|
835
|
+
) {
|
|
836
|
+
var chartDataSlice = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
837
|
+
var lowerEnd, upperEnd;
|
|
838
|
+
if (items.length > 0) {
|
|
839
|
+
/*
|
|
840
|
+
* Iterate item-first so each item can use its own `data` prop when present,
|
|
841
|
+
* falling back to the chart-level data slice for items that rely on it.
|
|
842
|
+
* This ensures that mixing items with and without own data (e.g. Bar reading
|
|
843
|
+
* chart-level data alongside a Scatter with its own outlier data) produces a
|
|
844
|
+
* domain that covers all values from all sources.
|
|
845
|
+
*/
|
|
846
|
+
items.forEach((item) => {
|
|
847
|
+
var _errorBars$item$id;
|
|
848
|
+
var itemData = item.data != null ? [...item.data] : chartDataSlice;
|
|
849
|
+
var relevantErrorBars =
|
|
850
|
+
(_errorBars$item$id = errorBars[item.id]) === null || _errorBars$item$id === void 0
|
|
851
|
+
? void 0
|
|
852
|
+
: _errorBars$item$id.filter((errorBar) =>
|
|
853
|
+
isErrorBarRelevantForAxisType(axisType, errorBar),
|
|
854
|
+
);
|
|
855
|
+
itemData.forEach((entry) => {
|
|
856
|
+
var _axisSettings$dataKey;
|
|
857
|
+
var valueByDataKey = getValueByDataKey(
|
|
858
|
+
entry,
|
|
859
|
+
(_axisSettings$dataKey = axisSettings.dataKey) !== null &&
|
|
860
|
+
_axisSettings$dataKey !== void 0
|
|
861
|
+
? _axisSettings$dataKey
|
|
862
|
+
: item.dataKey,
|
|
863
|
+
);
|
|
864
|
+
var errorDomain = getErrorDomainByDataKey(entry, valueByDataKey, relevantErrorBars);
|
|
865
|
+
if (errorDomain.length >= 2) {
|
|
866
|
+
var localLower = Math.min(...errorDomain);
|
|
867
|
+
var localUpper = Math.max(...errorDomain);
|
|
868
|
+
if (lowerEnd == null || localLower < lowerEnd) {
|
|
869
|
+
lowerEnd = localLower;
|
|
870
|
+
}
|
|
871
|
+
if (upperEnd == null || localUpper > upperEnd) {
|
|
872
|
+
upperEnd = localUpper;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
var dataValueDomain = makeDomain(valueByDataKey);
|
|
876
|
+
if (dataValueDomain != null) {
|
|
877
|
+
lowerEnd =
|
|
878
|
+
lowerEnd == null ? dataValueDomain[0] : Math.min(lowerEnd, dataValueDomain[0]);
|
|
879
|
+
upperEnd =
|
|
880
|
+
upperEnd == null ? dataValueDomain[1] : Math.max(upperEnd, dataValueDomain[1]);
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
if (
|
|
886
|
+
(axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null &&
|
|
887
|
+
items.length === 0
|
|
888
|
+
) {
|
|
889
|
+
// When there are no items, fall back to the displayed data (chart-level or graphical item data).
|
|
890
|
+
displayedData.forEach((item) => {
|
|
891
|
+
var dataValueDomain = makeDomain(getValueByDataKey(item, axisSettings.dataKey));
|
|
892
|
+
if (dataValueDomain != null) {
|
|
893
|
+
lowerEnd = lowerEnd == null ? dataValueDomain[0] : Math.min(lowerEnd, dataValueDomain[0]);
|
|
894
|
+
upperEnd = upperEnd == null ? dataValueDomain[1] : Math.max(upperEnd, dataValueDomain[1]);
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
if (isWellBehavedNumber(lowerEnd) && isWellBehavedNumber(upperEnd)) {
|
|
899
|
+
return [lowerEnd, upperEnd];
|
|
900
|
+
}
|
|
901
|
+
return undefined;
|
|
902
|
+
};
|
|
903
|
+
var selectDomainOfAllAppliedNumericalValuesIncludingErrorValues = createSelector(
|
|
904
|
+
[
|
|
905
|
+
selectDisplayedData,
|
|
906
|
+
selectBaseAxis,
|
|
907
|
+
selectCartesianItemsSettingsExceptStacked,
|
|
908
|
+
selectAllErrorBarSettings,
|
|
909
|
+
pickAxisType,
|
|
910
|
+
selectChartDataSliceIfNotInPanorama,
|
|
911
|
+
],
|
|
912
|
+
combineDomainOfAllAppliedNumericalValuesIncludingErrorValues,
|
|
913
|
+
{
|
|
914
|
+
memoizeOptions: {
|
|
915
|
+
resultEqualityCheck: numberDomainEqualityCheck,
|
|
916
|
+
},
|
|
917
|
+
},
|
|
918
|
+
);
|
|
919
|
+
function onlyAllowNumbersAndStringsAndDates(item) {
|
|
920
|
+
var value = item.value;
|
|
921
|
+
if (isNumOrStr(value) || value instanceof Date) {
|
|
922
|
+
return value;
|
|
923
|
+
}
|
|
924
|
+
return undefined;
|
|
925
|
+
}
|
|
926
|
+
var computeDomainOfTypeCategory = (allDataSquished, axisSettings, isCategorical) => {
|
|
927
|
+
var categoricalDomain = allDataSquished
|
|
928
|
+
.map(onlyAllowNumbersAndStringsAndDates)
|
|
929
|
+
.filter((v) => v != null);
|
|
930
|
+
if (
|
|
931
|
+
isCategorical &&
|
|
932
|
+
(axisSettings.dataKey == null ||
|
|
933
|
+
(axisSettings.allowDuplicatedCategory && hasDuplicate(categoricalDomain)))
|
|
934
|
+
) {
|
|
935
|
+
/*
|
|
936
|
+
* 1. In an absence of dataKey, Recharts will use array indexes as its categorical domain
|
|
937
|
+
* 2. When category axis has duplicated text, serial numbers are used to generate scale
|
|
938
|
+
*/
|
|
939
|
+
return range(0, allDataSquished.length);
|
|
940
|
+
}
|
|
941
|
+
if (axisSettings.allowDuplicatedCategory) {
|
|
942
|
+
return categoricalDomain;
|
|
943
|
+
}
|
|
944
|
+
return Array.from(new Set(categoricalDomain));
|
|
945
|
+
};
|
|
946
|
+
export var selectReferenceDots = (state) => state.referenceElements.dots;
|
|
947
|
+
export var filterReferenceElements = (elements, axisType, axisId) => {
|
|
948
|
+
return elements
|
|
949
|
+
.filter((el) => el.ifOverflow === 'extendDomain')
|
|
950
|
+
.filter((el) => {
|
|
951
|
+
if (axisType === 'xAxis') {
|
|
952
|
+
return el.xAxisId === axisId;
|
|
953
|
+
}
|
|
954
|
+
return el.yAxisId === axisId;
|
|
955
|
+
});
|
|
956
|
+
};
|
|
957
|
+
export var selectReferenceDotsByAxis = createSelector(
|
|
958
|
+
[selectReferenceDots, pickAxisType, pickAxisId],
|
|
959
|
+
filterReferenceElements,
|
|
960
|
+
);
|
|
961
|
+
export var selectReferenceAreas = (state) => state.referenceElements.areas;
|
|
962
|
+
export var selectReferenceAreasByAxis = createSelector(
|
|
963
|
+
[selectReferenceAreas, pickAxisType, pickAxisId],
|
|
964
|
+
filterReferenceElements,
|
|
965
|
+
);
|
|
966
|
+
export var selectReferenceLines = (state) => state.referenceElements.lines;
|
|
967
|
+
export var selectReferenceLinesByAxis = createSelector(
|
|
968
|
+
[selectReferenceLines, pickAxisType, pickAxisId],
|
|
969
|
+
filterReferenceElements,
|
|
970
|
+
);
|
|
971
|
+
export var combineDotsDomain = (dots, axisType) => {
|
|
972
|
+
if (dots == null) {
|
|
973
|
+
return undefined;
|
|
974
|
+
}
|
|
975
|
+
var allCoords = onlyAllowNumbers(dots.map((dot) => (axisType === 'xAxis' ? dot.x : dot.y)));
|
|
976
|
+
if (allCoords.length === 0) {
|
|
977
|
+
return undefined;
|
|
978
|
+
}
|
|
979
|
+
return [Math.min(...allCoords), Math.max(...allCoords)];
|
|
980
|
+
};
|
|
981
|
+
var selectReferenceDotsDomain = createSelector(
|
|
982
|
+
selectReferenceDotsByAxis,
|
|
983
|
+
pickAxisType,
|
|
984
|
+
combineDotsDomain,
|
|
985
|
+
);
|
|
986
|
+
export var combineAreasDomain = (areas, axisType) => {
|
|
987
|
+
if (areas == null) {
|
|
988
|
+
return undefined;
|
|
989
|
+
}
|
|
990
|
+
var allCoords = onlyAllowNumbers(
|
|
991
|
+
areas.flatMap((area) => [
|
|
992
|
+
axisType === 'xAxis' ? area.x1 : area.y1,
|
|
993
|
+
axisType === 'xAxis' ? area.x2 : area.y2,
|
|
994
|
+
]),
|
|
995
|
+
);
|
|
996
|
+
if (allCoords.length === 0) {
|
|
997
|
+
return undefined;
|
|
998
|
+
}
|
|
999
|
+
return [Math.min(...allCoords), Math.max(...allCoords)];
|
|
1000
|
+
};
|
|
1001
|
+
var selectReferenceAreasDomain = createSelector(
|
|
1002
|
+
[selectReferenceAreasByAxis, pickAxisType],
|
|
1003
|
+
combineAreasDomain,
|
|
1004
|
+
);
|
|
1005
|
+
function extractXCoordinates(line) {
|
|
1006
|
+
var _line$segment;
|
|
1007
|
+
if (line.x != null) {
|
|
1008
|
+
return onlyAllowNumbers([line.x]);
|
|
1009
|
+
}
|
|
1010
|
+
var segmentCoordinates =
|
|
1011
|
+
(_line$segment = line.segment) === null || _line$segment === void 0
|
|
1012
|
+
? void 0
|
|
1013
|
+
: _line$segment.map((s) => s.x);
|
|
1014
|
+
if (segmentCoordinates == null || segmentCoordinates.length === 0) {
|
|
1015
|
+
return [];
|
|
1016
|
+
}
|
|
1017
|
+
return onlyAllowNumbers(segmentCoordinates);
|
|
1018
|
+
}
|
|
1019
|
+
function extractYCoordinates(line) {
|
|
1020
|
+
var _line$segment2;
|
|
1021
|
+
if (line.y != null) {
|
|
1022
|
+
return onlyAllowNumbers([line.y]);
|
|
1023
|
+
}
|
|
1024
|
+
var segmentCoordinates =
|
|
1025
|
+
(_line$segment2 = line.segment) === null || _line$segment2 === void 0
|
|
1026
|
+
? void 0
|
|
1027
|
+
: _line$segment2.map((s) => s.y);
|
|
1028
|
+
if (segmentCoordinates == null || segmentCoordinates.length === 0) {
|
|
1029
|
+
return [];
|
|
1030
|
+
}
|
|
1031
|
+
return onlyAllowNumbers(segmentCoordinates);
|
|
1032
|
+
}
|
|
1033
|
+
export var combineLinesDomain = (lines, axisType) => {
|
|
1034
|
+
if (lines == null) {
|
|
1035
|
+
return undefined;
|
|
1036
|
+
}
|
|
1037
|
+
var allCoords = lines.flatMap((line) =>
|
|
1038
|
+
axisType === 'xAxis' ? extractXCoordinates(line) : extractYCoordinates(line),
|
|
1039
|
+
);
|
|
1040
|
+
if (allCoords.length === 0) {
|
|
1041
|
+
return undefined;
|
|
1042
|
+
}
|
|
1043
|
+
return [Math.min(...allCoords), Math.max(...allCoords)];
|
|
1044
|
+
};
|
|
1045
|
+
var selectReferenceLinesDomain = createSelector(
|
|
1046
|
+
[selectReferenceLinesByAxis, pickAxisType],
|
|
1047
|
+
combineLinesDomain,
|
|
1048
|
+
);
|
|
1049
|
+
var selectReferenceElementsDomain = createSelector(
|
|
1050
|
+
selectReferenceDotsDomain,
|
|
1051
|
+
selectReferenceLinesDomain,
|
|
1052
|
+
selectReferenceAreasDomain,
|
|
1053
|
+
(dotsDomain, linesDomain, areasDomain) => {
|
|
1054
|
+
return mergeDomains(dotsDomain, areasDomain, linesDomain);
|
|
1055
|
+
},
|
|
1056
|
+
);
|
|
1057
|
+
export var combineNumericalDomain = (
|
|
1058
|
+
axisSettings,
|
|
1059
|
+
domainDefinition,
|
|
1060
|
+
domainFromUserPreference,
|
|
1061
|
+
domainOfStackGroups,
|
|
1062
|
+
dataAndErrorBarsDomain,
|
|
1063
|
+
referenceElementsDomain,
|
|
1064
|
+
layout,
|
|
1065
|
+
axisType,
|
|
1066
|
+
numericTicksDomain,
|
|
1067
|
+
) => {
|
|
1068
|
+
if (domainFromUserPreference != null) {
|
|
1069
|
+
// We're done! No need to compute anything else.
|
|
1070
|
+
return domainFromUserPreference;
|
|
1071
|
+
}
|
|
1072
|
+
var shouldIncludeDomainOfStackGroups =
|
|
1073
|
+
(layout === 'vertical' && axisType === 'xAxis') ||
|
|
1074
|
+
(layout === 'horizontal' && axisType === 'yAxis');
|
|
1075
|
+
var mergedDomains = shouldIncludeDomainOfStackGroups
|
|
1076
|
+
? mergeDomains(domainOfStackGroups, referenceElementsDomain, dataAndErrorBarsDomain)
|
|
1077
|
+
: mergeDomains(referenceElementsDomain, dataAndErrorBarsDomain);
|
|
1078
|
+
var parsedDomain = parseNumericalUserDomain(
|
|
1079
|
+
domainDefinition,
|
|
1080
|
+
mergedDomains,
|
|
1081
|
+
axisSettings.allowDataOverflow,
|
|
1082
|
+
);
|
|
1083
|
+
if (parsedDomain != null) {
|
|
1084
|
+
return parsedDomain;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/*
|
|
1088
|
+
* https://github.com/recharts/recharts/issues/7362
|
|
1089
|
+
* The user-provided domain could not be resolved without data - it's a function
|
|
1090
|
+
* bound or one of 'auto'/'dataMin'/'dataMax' - and there is no data domain to
|
|
1091
|
+
* resolve it from: empty or all-null data, and no domain-extending reference
|
|
1092
|
+
* elements (only reference dots/lines/areas with ifOverflow="extendDomain"
|
|
1093
|
+
* contribute to mergedDomains). If the
|
|
1094
|
+
* axis opted into data overflow and supplied an explicit numeric `ticks` array,
|
|
1095
|
+
* fall back to the ticks' [min, max] extent so the explicit tick ladder still
|
|
1096
|
+
* renders, mirroring what a literal numeric domain already does.
|
|
1097
|
+
*/
|
|
1098
|
+
if (axisSettings.allowDataOverflow && mergedDomains == null && numericTicksDomain != null) {
|
|
1099
|
+
return numericTicksDomain;
|
|
1100
|
+
}
|
|
1101
|
+
return parsedDomain;
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* https://github.com/recharts/recharts/issues/7362
|
|
1106
|
+
* Derives the [min, max] extent of an axis's explicit numeric `ticks`. Used by
|
|
1107
|
+
* {@link combineNumericalDomain} as a last-resort domain when a non-literal domain
|
|
1108
|
+
* cannot be resolved without data. Returns undefined for non-number axes, or when
|
|
1109
|
+
* no numeric ticks were supplied.
|
|
1110
|
+
*/
|
|
1111
|
+
export var combineNumericTicksDomain = (axisSettings) => {
|
|
1112
|
+
if (
|
|
1113
|
+
axisSettings == null ||
|
|
1114
|
+
axisSettings.type !== 'number' ||
|
|
1115
|
+
!('ticks' in axisSettings) ||
|
|
1116
|
+
axisSettings.ticks == null
|
|
1117
|
+
) {
|
|
1118
|
+
return undefined;
|
|
1119
|
+
}
|
|
1120
|
+
var numericTicks = onlyAllowNumbers(axisSettings.ticks);
|
|
1121
|
+
if (numericTicks.length === 0) {
|
|
1122
|
+
return undefined;
|
|
1123
|
+
}
|
|
1124
|
+
return [Math.min(...numericTicks), Math.max(...numericTicks)];
|
|
1125
|
+
};
|
|
1126
|
+
export var selectNumericTicksDomain = createSelector([selectBaseAxis], combineNumericTicksDomain, {
|
|
1127
|
+
memoizeOptions: {
|
|
1128
|
+
resultEqualityCheck: numberDomainEqualityCheck,
|
|
1129
|
+
},
|
|
1130
|
+
});
|
|
1131
|
+
export var selectNumericalDomain = createSelector(
|
|
1132
|
+
[
|
|
1133
|
+
selectBaseAxis,
|
|
1134
|
+
selectDomainDefinition,
|
|
1135
|
+
selectDomainFromUserPreference,
|
|
1136
|
+
selectDomainOfStackGroups,
|
|
1137
|
+
selectDomainOfAllAppliedNumericalValuesIncludingErrorValues,
|
|
1138
|
+
selectReferenceElementsDomain,
|
|
1139
|
+
selectChartLayout,
|
|
1140
|
+
pickAxisType,
|
|
1141
|
+
selectNumericTicksDomain,
|
|
1142
|
+
],
|
|
1143
|
+
combineNumericalDomain,
|
|
1144
|
+
{
|
|
1145
|
+
memoizeOptions: {
|
|
1146
|
+
resultEqualityCheck: numberDomainEqualityCheck,
|
|
1147
|
+
},
|
|
1148
|
+
},
|
|
1149
|
+
);
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Expand by design maps everything between 0 and 1,
|
|
1153
|
+
* there is nothing to compute.
|
|
1154
|
+
* See https://d3js.org/d3-shape/stack#stack-offsets
|
|
1155
|
+
*/
|
|
1156
|
+
var expandDomain = [0, 1];
|
|
1157
|
+
export var combineAxisDomain = (
|
|
1158
|
+
axisSettings,
|
|
1159
|
+
layout,
|
|
1160
|
+
displayedData,
|
|
1161
|
+
allAppliedValues,
|
|
1162
|
+
stackOffsetType,
|
|
1163
|
+
axisType,
|
|
1164
|
+
numericalDomain,
|
|
1165
|
+
) => {
|
|
1166
|
+
if (
|
|
1167
|
+
(axisSettings == null || displayedData == null || displayedData.length === 0) &&
|
|
1168
|
+
numericalDomain === undefined
|
|
1169
|
+
) {
|
|
1170
|
+
return undefined;
|
|
1171
|
+
}
|
|
1172
|
+
var dataKey = axisSettings.dataKey,
|
|
1173
|
+
type = axisSettings.type;
|
|
1174
|
+
var isCategorical = isCategoricalAxis(layout, axisType);
|
|
1175
|
+
if (isCategorical && dataKey == null) {
|
|
1176
|
+
var _displayedData$length;
|
|
1177
|
+
return range(
|
|
1178
|
+
0,
|
|
1179
|
+
(_displayedData$length =
|
|
1180
|
+
displayedData === null || displayedData === void 0 ? void 0 : displayedData.length) !==
|
|
1181
|
+
null && _displayedData$length !== void 0
|
|
1182
|
+
? _displayedData$length
|
|
1183
|
+
: 0,
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
if (type === 'category') {
|
|
1187
|
+
return computeDomainOfTypeCategory(allAppliedValues, axisSettings, isCategorical);
|
|
1188
|
+
}
|
|
1189
|
+
if (stackOffsetType === 'expand' && !isCategorical) {
|
|
1190
|
+
return expandDomain;
|
|
1191
|
+
}
|
|
1192
|
+
return numericalDomain;
|
|
1193
|
+
};
|
|
1194
|
+
export var selectAxisDomain = createSelector(
|
|
1195
|
+
[
|
|
1196
|
+
selectBaseAxis,
|
|
1197
|
+
selectChartLayout,
|
|
1198
|
+
selectDisplayedData,
|
|
1199
|
+
selectAllAppliedValues,
|
|
1200
|
+
selectStackOffsetType,
|
|
1201
|
+
pickAxisType,
|
|
1202
|
+
selectNumericalDomain,
|
|
1203
|
+
],
|
|
1204
|
+
combineAxisDomain,
|
|
1205
|
+
);
|
|
1206
|
+
export var selectRealScaleType = createSelector(
|
|
1207
|
+
[selectBaseAxis, selectHasBar, selectChartName],
|
|
1208
|
+
combineRealScaleType,
|
|
1209
|
+
);
|
|
1210
|
+
export var combineNiceTicks = (axisDomain, axisSettings, realScaleType) => {
|
|
1211
|
+
var niceTicks = axisSettings.niceTicks;
|
|
1212
|
+
if (niceTicks === 'none') {
|
|
1213
|
+
return undefined;
|
|
1214
|
+
}
|
|
1215
|
+
var domainDefinition = getDomainDefinition(axisSettings);
|
|
1216
|
+
var hasDomainAutoKeyword =
|
|
1217
|
+
Array.isArray(domainDefinition) &&
|
|
1218
|
+
(domainDefinition[0] === 'auto' || domainDefinition[1] === 'auto');
|
|
1219
|
+
if (
|
|
1220
|
+
(niceTicks === 'snap125' || niceTicks === 'adaptive') &&
|
|
1221
|
+
axisSettings != null &&
|
|
1222
|
+
axisSettings.tickCount &&
|
|
1223
|
+
isWellFormedNumberDomain(axisDomain)
|
|
1224
|
+
) {
|
|
1225
|
+
if (hasDomainAutoKeyword) {
|
|
1226
|
+
return getNiceTickValues(
|
|
1227
|
+
axisDomain,
|
|
1228
|
+
axisSettings.tickCount,
|
|
1229
|
+
axisSettings.allowDecimals,
|
|
1230
|
+
niceTicks,
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (axisSettings.type === 'number') {
|
|
1234
|
+
return getTickValuesFixedDomain(
|
|
1235
|
+
axisDomain,
|
|
1236
|
+
axisSettings.tickCount,
|
|
1237
|
+
axisSettings.allowDecimals,
|
|
1238
|
+
niceTicks,
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (
|
|
1243
|
+
niceTicks === 'auto' &&
|
|
1244
|
+
realScaleType === 'linear' &&
|
|
1245
|
+
axisSettings != null &&
|
|
1246
|
+
axisSettings.tickCount
|
|
1247
|
+
) {
|
|
1248
|
+
// Current magic-selector behaviour: apply nice ticks when the domain contains
|
|
1249
|
+
// an 'auto' keyword (may extend the domain), or for any fixed number-type axis.
|
|
1250
|
+
// Always uses the space-efficient algorithm (adaptive).
|
|
1251
|
+
if (hasDomainAutoKeyword && isWellFormedNumberDomain(axisDomain)) {
|
|
1252
|
+
return getNiceTickValues(
|
|
1253
|
+
axisDomain,
|
|
1254
|
+
axisSettings.tickCount,
|
|
1255
|
+
axisSettings.allowDecimals,
|
|
1256
|
+
'adaptive',
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
if (axisSettings.type === 'number' && isWellFormedNumberDomain(axisDomain)) {
|
|
1260
|
+
return getTickValuesFixedDomain(
|
|
1261
|
+
axisDomain,
|
|
1262
|
+
axisSettings.tickCount,
|
|
1263
|
+
axisSettings.allowDecimals,
|
|
1264
|
+
'adaptive',
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return undefined;
|
|
1269
|
+
};
|
|
1270
|
+
export var selectNiceTicks = createSelector(
|
|
1271
|
+
[selectAxisDomain, selectRenderableAxisSettings, selectRealScaleType],
|
|
1272
|
+
combineNiceTicks,
|
|
1273
|
+
);
|
|
1274
|
+
export var combineAxisDomainWithNiceTicks = (axisSettings, domain, niceTicks, axisType) => {
|
|
1275
|
+
if (
|
|
1276
|
+
/*
|
|
1277
|
+
* Angle axis for some reason uses nice ticks when rendering axis tick labels,
|
|
1278
|
+
* but doesn't use nice ticks for extending domain like all the other axes do.
|
|
1279
|
+
* Not really sure why? Is there a good reason,
|
|
1280
|
+
* or is it just because someone added support for nice ticks to the other axes and forgot this one?
|
|
1281
|
+
*/
|
|
1282
|
+
axisType !== 'angleAxis' &&
|
|
1283
|
+
(axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.type) === 'number' &&
|
|
1284
|
+
isWellFormedNumberDomain(domain) &&
|
|
1285
|
+
Array.isArray(niceTicks) &&
|
|
1286
|
+
niceTicks.length > 0
|
|
1287
|
+
) {
|
|
1288
|
+
var _niceTicks$, _niceTicks;
|
|
1289
|
+
var minFromDomain = domain[0];
|
|
1290
|
+
var minFromTicks =
|
|
1291
|
+
(_niceTicks$ = niceTicks[0]) !== null && _niceTicks$ !== void 0 ? _niceTicks$ : 0;
|
|
1292
|
+
var maxFromDomain = domain[1];
|
|
1293
|
+
var maxFromTicks =
|
|
1294
|
+
(_niceTicks = niceTicks[niceTicks.length - 1]) !== null && _niceTicks !== void 0
|
|
1295
|
+
? _niceTicks
|
|
1296
|
+
: 0;
|
|
1297
|
+
return [Math.min(minFromDomain, minFromTicks), Math.max(maxFromDomain, maxFromTicks)];
|
|
1298
|
+
}
|
|
1299
|
+
return domain;
|
|
1300
|
+
};
|
|
1301
|
+
export var selectAxisDomainIncludingNiceTicks = createSelector(
|
|
1302
|
+
[selectBaseAxis, selectAxisDomain, selectNiceTicks, pickAxisType],
|
|
1303
|
+
combineAxisDomainWithNiceTicks,
|
|
1304
|
+
);
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* Returns the smallest gap, between two numbers in the data, as a ratio of the whole range (max - min).
|
|
1308
|
+
* Ignores domain provided by user and only considers domain from data.
|
|
1309
|
+
*
|
|
1310
|
+
* The result is a number between 0 and 1.
|
|
1311
|
+
*/
|
|
1312
|
+
export var selectSmallestDistanceBetweenValues = createSelector(
|
|
1313
|
+
selectAllAppliedValues,
|
|
1314
|
+
selectBaseAxis,
|
|
1315
|
+
(allDataSquished, axisSettings) => {
|
|
1316
|
+
if (!axisSettings || axisSettings.type !== 'number') {
|
|
1317
|
+
return undefined;
|
|
1318
|
+
}
|
|
1319
|
+
var smallestDistanceBetweenValues = Infinity;
|
|
1320
|
+
var sortedValues = Array.from(onlyAllowNumbers(allDataSquished.map((d) => d.value))).sort(
|
|
1321
|
+
(a, b) => a - b,
|
|
1322
|
+
);
|
|
1323
|
+
var first = sortedValues[0];
|
|
1324
|
+
var last = sortedValues[sortedValues.length - 1];
|
|
1325
|
+
if (first == null || last == null) {
|
|
1326
|
+
return Infinity;
|
|
1327
|
+
}
|
|
1328
|
+
var diff = last - first;
|
|
1329
|
+
if (diff === 0) {
|
|
1330
|
+
return Infinity;
|
|
1331
|
+
}
|
|
1332
|
+
// Only do n - 1 distance calculations because there's only n - 1 distances between n values.
|
|
1333
|
+
for (var i = 0; i < sortedValues.length - 1; i++) {
|
|
1334
|
+
var curr = sortedValues[i];
|
|
1335
|
+
var next = sortedValues[i + 1];
|
|
1336
|
+
if (curr == null || next == null) {
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
var distance = next - curr;
|
|
1340
|
+
smallestDistanceBetweenValues = Math.min(smallestDistanceBetweenValues, distance);
|
|
1341
|
+
}
|
|
1342
|
+
return smallestDistanceBetweenValues / diff;
|
|
1343
|
+
},
|
|
1344
|
+
);
|
|
1345
|
+
var selectCalculatedPadding = createSelector(
|
|
1346
|
+
selectSmallestDistanceBetweenValues,
|
|
1347
|
+
selectChartLayout,
|
|
1348
|
+
selectBarCategoryGap,
|
|
1349
|
+
selectChartOffsetInternal,
|
|
1350
|
+
(_1, _2, _3, _4, padding) => padding,
|
|
1351
|
+
(smallestDistanceInPercent, layout, barCategoryGap, offset, padding) => {
|
|
1352
|
+
if (!isWellBehavedNumber(smallestDistanceInPercent)) {
|
|
1353
|
+
return 0;
|
|
1354
|
+
}
|
|
1355
|
+
var rangeWidth = layout === 'vertical' ? offset.height : offset.width;
|
|
1356
|
+
if (padding === 'gap') {
|
|
1357
|
+
return (smallestDistanceInPercent * rangeWidth) / 2;
|
|
1358
|
+
}
|
|
1359
|
+
if (padding === 'no-gap') {
|
|
1360
|
+
var gap = getPercentValue(barCategoryGap, smallestDistanceInPercent * rangeWidth);
|
|
1361
|
+
var halfBand = (smallestDistanceInPercent * rangeWidth) / 2;
|
|
1362
|
+
return halfBand - gap - ((halfBand - gap) / rangeWidth) * gap;
|
|
1363
|
+
}
|
|
1364
|
+
return 0;
|
|
1365
|
+
},
|
|
1366
|
+
);
|
|
1367
|
+
export var selectCalculatedXAxisPadding = (state, axisId, isPanorama) => {
|
|
1368
|
+
var xAxisSettings = selectXAxisSettings(state, axisId);
|
|
1369
|
+
if (xAxisSettings == null || typeof xAxisSettings.padding !== 'string') {
|
|
1370
|
+
return 0;
|
|
1371
|
+
}
|
|
1372
|
+
return selectCalculatedPadding(state, 'xAxis', axisId, isPanorama, xAxisSettings.padding);
|
|
1373
|
+
};
|
|
1374
|
+
export var selectCalculatedYAxisPadding = (state, axisId, isPanorama) => {
|
|
1375
|
+
var yAxisSettings = selectYAxisSettings(state, axisId);
|
|
1376
|
+
if (yAxisSettings == null || typeof yAxisSettings.padding !== 'string') {
|
|
1377
|
+
return 0;
|
|
1378
|
+
}
|
|
1379
|
+
return selectCalculatedPadding(state, 'yAxis', axisId, isPanorama, yAxisSettings.padding);
|
|
1380
|
+
};
|
|
1381
|
+
var selectXAxisPadding = createSelector(
|
|
1382
|
+
selectXAxisSettings,
|
|
1383
|
+
selectCalculatedXAxisPadding,
|
|
1384
|
+
(xAxisSettings, calculated) => {
|
|
1385
|
+
var _padding$left, _padding$right;
|
|
1386
|
+
if (xAxisSettings == null) {
|
|
1387
|
+
return {
|
|
1388
|
+
left: 0,
|
|
1389
|
+
right: 0,
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
var padding = xAxisSettings.padding;
|
|
1393
|
+
if (typeof padding === 'string') {
|
|
1394
|
+
return {
|
|
1395
|
+
left: calculated,
|
|
1396
|
+
right: calculated,
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
return {
|
|
1400
|
+
left:
|
|
1401
|
+
((_padding$left = padding.left) !== null && _padding$left !== void 0 ? _padding$left : 0) +
|
|
1402
|
+
calculated,
|
|
1403
|
+
right:
|
|
1404
|
+
((_padding$right = padding.right) !== null && _padding$right !== void 0
|
|
1405
|
+
? _padding$right
|
|
1406
|
+
: 0) + calculated,
|
|
1407
|
+
};
|
|
1408
|
+
},
|
|
1409
|
+
);
|
|
1410
|
+
var selectYAxisPadding = createSelector(
|
|
1411
|
+
selectYAxisSettings,
|
|
1412
|
+
selectCalculatedYAxisPadding,
|
|
1413
|
+
(yAxisSettings, calculated) => {
|
|
1414
|
+
var _padding$top, _padding$bottom;
|
|
1415
|
+
if (yAxisSettings == null) {
|
|
1416
|
+
return {
|
|
1417
|
+
top: 0,
|
|
1418
|
+
bottom: 0,
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
var padding = yAxisSettings.padding;
|
|
1422
|
+
if (typeof padding === 'string') {
|
|
1423
|
+
return {
|
|
1424
|
+
top: calculated,
|
|
1425
|
+
bottom: calculated,
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
return {
|
|
1429
|
+
top:
|
|
1430
|
+
((_padding$top = padding.top) !== null && _padding$top !== void 0 ? _padding$top : 0) +
|
|
1431
|
+
calculated,
|
|
1432
|
+
bottom:
|
|
1433
|
+
((_padding$bottom = padding.bottom) !== null && _padding$bottom !== void 0
|
|
1434
|
+
? _padding$bottom
|
|
1435
|
+
: 0) + calculated,
|
|
1436
|
+
};
|
|
1437
|
+
},
|
|
1438
|
+
);
|
|
1439
|
+
export var selectXAxisRange = createSelector(
|
|
1440
|
+
[
|
|
1441
|
+
selectChartOffsetInternal,
|
|
1442
|
+
selectXAxisPadding,
|
|
1443
|
+
selectBrushDimensions,
|
|
1444
|
+
selectBrushSettings,
|
|
1445
|
+
(_state, _axisId, isPanorama) => isPanorama,
|
|
1446
|
+
],
|
|
1447
|
+
(offset, padding, brushDimensions, _ref6, isPanorama) => {
|
|
1448
|
+
var brushPadding = _ref6.padding;
|
|
1449
|
+
if (isPanorama) {
|
|
1450
|
+
return [brushPadding.left, brushDimensions.width - brushPadding.right];
|
|
1451
|
+
}
|
|
1452
|
+
return [offset.left + padding.left, offset.left + offset.width - padding.right];
|
|
1453
|
+
},
|
|
1454
|
+
);
|
|
1455
|
+
export var selectYAxisRange = createSelector(
|
|
1456
|
+
[
|
|
1457
|
+
selectChartOffsetInternal,
|
|
1458
|
+
selectChartLayout,
|
|
1459
|
+
selectYAxisPadding,
|
|
1460
|
+
selectBrushDimensions,
|
|
1461
|
+
selectBrushSettings,
|
|
1462
|
+
(_state, _axisId, isPanorama) => isPanorama,
|
|
1463
|
+
],
|
|
1464
|
+
(offset, layout, padding, brushDimensions, _ref7, isPanorama) => {
|
|
1465
|
+
var brushPadding = _ref7.padding;
|
|
1466
|
+
if (isPanorama) {
|
|
1467
|
+
return [brushDimensions.height - brushPadding.bottom, brushPadding.top];
|
|
1468
|
+
}
|
|
1469
|
+
if (layout === 'horizontal') {
|
|
1470
|
+
return [offset.top + offset.height - padding.bottom, offset.top + padding.top];
|
|
1471
|
+
}
|
|
1472
|
+
return [offset.top + padding.top, offset.top + offset.height - padding.bottom];
|
|
1473
|
+
},
|
|
1474
|
+
);
|
|
1475
|
+
export var selectAxisRange = (state, axisType, axisId, isPanorama) => {
|
|
1476
|
+
var _selectZAxisSettings;
|
|
1477
|
+
switch (axisType) {
|
|
1478
|
+
case 'xAxis':
|
|
1479
|
+
return selectXAxisRange(state, axisId, isPanorama);
|
|
1480
|
+
case 'yAxis':
|
|
1481
|
+
return selectYAxisRange(state, axisId, isPanorama);
|
|
1482
|
+
case 'zAxis':
|
|
1483
|
+
return (_selectZAxisSettings = selectZAxisSettings(state, axisId)) === null ||
|
|
1484
|
+
_selectZAxisSettings === void 0
|
|
1485
|
+
? void 0
|
|
1486
|
+
: _selectZAxisSettings.range;
|
|
1487
|
+
case 'angleAxis':
|
|
1488
|
+
return selectAngleAxisRange(state);
|
|
1489
|
+
case 'radiusAxis':
|
|
1490
|
+
return selectRadiusAxisRange(state, axisId);
|
|
1491
|
+
default:
|
|
1492
|
+
return undefined;
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
export var selectAxisRangeWithReverse = createSelector(
|
|
1496
|
+
[selectBaseAxis, selectAxisRange],
|
|
1497
|
+
combineAxisRangeWithReverse,
|
|
1498
|
+
);
|
|
1499
|
+
export var selectCheckedAxisDomain = createSelector(
|
|
1500
|
+
[selectRealScaleType, selectAxisDomainIncludingNiceTicks],
|
|
1501
|
+
combineCheckedDomain,
|
|
1502
|
+
);
|
|
1503
|
+
var selectConfiguredScale = createSelector(
|
|
1504
|
+
[selectBaseAxis, selectRealScaleType, selectCheckedAxisDomain, selectAxisRangeWithReverse],
|
|
1505
|
+
combineConfiguredScale,
|
|
1506
|
+
);
|
|
1507
|
+
export var combineCategoricalDomain = (layout, appliedValues, axis, axisType) => {
|
|
1508
|
+
if (axis == null || axis.dataKey == null) {
|
|
1509
|
+
return undefined;
|
|
1510
|
+
}
|
|
1511
|
+
var type = axis.type,
|
|
1512
|
+
scale = axis.scale;
|
|
1513
|
+
var isCategorical = isCategoricalAxis(layout, axisType);
|
|
1514
|
+
if (isCategorical && (type === 'number' || scale !== 'auto')) {
|
|
1515
|
+
return appliedValues.map((d) => d.value);
|
|
1516
|
+
}
|
|
1517
|
+
return undefined;
|
|
1518
|
+
};
|
|
1519
|
+
export var selectCategoricalDomain = createSelector(
|
|
1520
|
+
[selectChartLayout, selectAllAppliedValues, selectRenderableAxisSettings, pickAxisType],
|
|
1521
|
+
combineCategoricalDomain,
|
|
1522
|
+
);
|
|
1523
|
+
export var selectAxisScale = createSelector([selectConfiguredScale], rechartsScaleFactory);
|
|
1524
|
+
export var selectAxisInverseScale = createSelector(
|
|
1525
|
+
[selectConfiguredScale],
|
|
1526
|
+
combineInverseScaleFunction,
|
|
1527
|
+
);
|
|
1528
|
+
export var selectAxisInverseDataSnapScale = createSelector(
|
|
1529
|
+
[selectConfiguredScale, selectSortedDataPoints],
|
|
1530
|
+
createCategoricalInverse,
|
|
1531
|
+
);
|
|
1532
|
+
export var selectErrorBarsSettings = createSelector(
|
|
1533
|
+
[selectCartesianItemsSettings, selectAllErrorBarSettings, pickAxisType],
|
|
1534
|
+
combineRelevantErrorBarSettings,
|
|
1535
|
+
);
|
|
1536
|
+
function compareIds(a, b) {
|
|
1537
|
+
if (a.id < b.id) {
|
|
1538
|
+
return -1;
|
|
1539
|
+
}
|
|
1540
|
+
if (a.id > b.id) {
|
|
1541
|
+
return 1;
|
|
1542
|
+
}
|
|
1543
|
+
return 0;
|
|
1544
|
+
}
|
|
1545
|
+
var pickAxisOrientation = (_state, orientation) => orientation;
|
|
1546
|
+
var pickMirror = (_state, _orientation, mirror) => mirror;
|
|
1547
|
+
var selectAllXAxesWithOffsetType = createSelector(
|
|
1548
|
+
selectAllXAxes,
|
|
1549
|
+
pickAxisOrientation,
|
|
1550
|
+
pickMirror,
|
|
1551
|
+
(allAxes, orientation, mirror) =>
|
|
1552
|
+
allAxes
|
|
1553
|
+
.filter((axis) => axis.orientation === orientation)
|
|
1554
|
+
.filter((axis) => axis.mirror === mirror)
|
|
1555
|
+
.sort(compareIds),
|
|
1556
|
+
);
|
|
1557
|
+
var selectAllYAxesWithOffsetType = createSelector(
|
|
1558
|
+
selectAllYAxes,
|
|
1559
|
+
pickAxisOrientation,
|
|
1560
|
+
pickMirror,
|
|
1561
|
+
(allAxes, orientation, mirror) =>
|
|
1562
|
+
allAxes
|
|
1563
|
+
.filter((axis) => axis.orientation === orientation)
|
|
1564
|
+
.filter((axis) => axis.mirror === mirror)
|
|
1565
|
+
.sort(compareIds),
|
|
1566
|
+
);
|
|
1567
|
+
var getXAxisSize = (offset, axisSettings) => {
|
|
1568
|
+
return {
|
|
1569
|
+
width: offset.width,
|
|
1570
|
+
height: axisSettings.height,
|
|
1571
|
+
};
|
|
1572
|
+
};
|
|
1573
|
+
var getYAxisSize = (offset, axisSettings) => {
|
|
1574
|
+
var width = typeof axisSettings.width === 'number' ? axisSettings.width : DEFAULT_Y_AXIS_WIDTH;
|
|
1575
|
+
return {
|
|
1576
|
+
width,
|
|
1577
|
+
height: offset.height,
|
|
1578
|
+
};
|
|
1579
|
+
};
|
|
1580
|
+
export var selectXAxisSize = createSelector(
|
|
1581
|
+
selectChartOffsetInternal,
|
|
1582
|
+
selectXAxisSettings,
|
|
1583
|
+
getXAxisSize,
|
|
1584
|
+
);
|
|
1585
|
+
var combineXAxisPositionStartingPoint = (offset, orientation, chartHeight) => {
|
|
1586
|
+
switch (orientation) {
|
|
1587
|
+
case 'top':
|
|
1588
|
+
return offset.top;
|
|
1589
|
+
case 'bottom':
|
|
1590
|
+
return chartHeight - offset.bottom;
|
|
1591
|
+
default:
|
|
1592
|
+
return 0;
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
var combineYAxisPositionStartingPoint = (offset, orientation, chartWidth) => {
|
|
1596
|
+
switch (orientation) {
|
|
1597
|
+
case 'left':
|
|
1598
|
+
return offset.left;
|
|
1599
|
+
case 'right':
|
|
1600
|
+
return chartWidth - offset.right;
|
|
1601
|
+
default:
|
|
1602
|
+
return 0;
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
export var selectAllXAxesOffsetSteps = createSelector(
|
|
1606
|
+
selectChartHeight,
|
|
1607
|
+
selectChartOffsetInternal,
|
|
1608
|
+
selectAllXAxesWithOffsetType,
|
|
1609
|
+
pickAxisOrientation,
|
|
1610
|
+
pickMirror,
|
|
1611
|
+
(chartHeight, offset, allAxesWithSameOffsetType, orientation, mirror) => {
|
|
1612
|
+
var steps = {};
|
|
1613
|
+
var position;
|
|
1614
|
+
allAxesWithSameOffsetType.forEach((axis) => {
|
|
1615
|
+
var axisSize = getXAxisSize(offset, axis);
|
|
1616
|
+
if (position == null) {
|
|
1617
|
+
position = combineXAxisPositionStartingPoint(offset, orientation, chartHeight);
|
|
1618
|
+
}
|
|
1619
|
+
var needSpace = (orientation === 'top' && !mirror) || (orientation === 'bottom' && mirror);
|
|
1620
|
+
steps[axis.id] = position - Number(needSpace) * axisSize.height;
|
|
1621
|
+
position += (needSpace ? -1 : 1) * axisSize.height;
|
|
1622
|
+
});
|
|
1623
|
+
return steps;
|
|
1624
|
+
},
|
|
1625
|
+
);
|
|
1626
|
+
export var selectAllYAxesOffsetSteps = createSelector(
|
|
1627
|
+
selectChartWidth,
|
|
1628
|
+
selectChartOffsetInternal,
|
|
1629
|
+
selectAllYAxesWithOffsetType,
|
|
1630
|
+
pickAxisOrientation,
|
|
1631
|
+
pickMirror,
|
|
1632
|
+
(chartWidth, offset, allAxesWithSameOffsetType, orientation, mirror) => {
|
|
1633
|
+
var steps = {};
|
|
1634
|
+
var position;
|
|
1635
|
+
allAxesWithSameOffsetType.forEach((axis) => {
|
|
1636
|
+
var axisSize = getYAxisSize(offset, axis);
|
|
1637
|
+
if (position == null) {
|
|
1638
|
+
position = combineYAxisPositionStartingPoint(offset, orientation, chartWidth);
|
|
1639
|
+
}
|
|
1640
|
+
var needSpace = (orientation === 'left' && !mirror) || (orientation === 'right' && mirror);
|
|
1641
|
+
steps[axis.id] = position - Number(needSpace) * axisSize.width;
|
|
1642
|
+
position += (needSpace ? -1 : 1) * axisSize.width;
|
|
1643
|
+
});
|
|
1644
|
+
return steps;
|
|
1645
|
+
},
|
|
1646
|
+
);
|
|
1647
|
+
var selectXAxisOffsetSteps = (state, axisId) => {
|
|
1648
|
+
var axisSettings = selectXAxisSettings(state, axisId);
|
|
1649
|
+
if (axisSettings == null) {
|
|
1650
|
+
return undefined;
|
|
1651
|
+
}
|
|
1652
|
+
return selectAllXAxesOffsetSteps(state, axisSettings.orientation, axisSettings.mirror);
|
|
1653
|
+
};
|
|
1654
|
+
export var selectXAxisPosition = createSelector(
|
|
1655
|
+
[selectChartOffsetInternal, selectXAxisSettings, selectXAxisOffsetSteps, (_, axisId) => axisId],
|
|
1656
|
+
(offset, axisSettings, allSteps, axisId) => {
|
|
1657
|
+
if (axisSettings == null) {
|
|
1658
|
+
return undefined;
|
|
1659
|
+
}
|
|
1660
|
+
var stepOfThisAxis = allSteps === null || allSteps === void 0 ? void 0 : allSteps[axisId];
|
|
1661
|
+
if (stepOfThisAxis == null) {
|
|
1662
|
+
return {
|
|
1663
|
+
x: offset.left,
|
|
1664
|
+
y: 0,
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
return {
|
|
1668
|
+
x: offset.left,
|
|
1669
|
+
y: stepOfThisAxis,
|
|
1670
|
+
};
|
|
1671
|
+
},
|
|
1672
|
+
);
|
|
1673
|
+
var selectYAxisOffsetSteps = (state, axisId) => {
|
|
1674
|
+
var axisSettings = selectYAxisSettings(state, axisId);
|
|
1675
|
+
if (axisSettings == null) {
|
|
1676
|
+
return undefined;
|
|
1677
|
+
}
|
|
1678
|
+
return selectAllYAxesOffsetSteps(state, axisSettings.orientation, axisSettings.mirror);
|
|
1679
|
+
};
|
|
1680
|
+
export var selectYAxisPosition = createSelector(
|
|
1681
|
+
[selectChartOffsetInternal, selectYAxisSettings, selectYAxisOffsetSteps, (_, axisId) => axisId],
|
|
1682
|
+
(offset, axisSettings, allSteps, axisId) => {
|
|
1683
|
+
if (axisSettings == null) {
|
|
1684
|
+
return undefined;
|
|
1685
|
+
}
|
|
1686
|
+
var stepOfThisAxis = allSteps === null || allSteps === void 0 ? void 0 : allSteps[axisId];
|
|
1687
|
+
if (stepOfThisAxis == null) {
|
|
1688
|
+
return {
|
|
1689
|
+
x: 0,
|
|
1690
|
+
y: offset.top,
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
x: stepOfThisAxis,
|
|
1695
|
+
y: offset.top,
|
|
1696
|
+
};
|
|
1697
|
+
},
|
|
1698
|
+
);
|
|
1699
|
+
export var selectYAxisSize = createSelector(
|
|
1700
|
+
selectChartOffsetInternal,
|
|
1701
|
+
selectYAxisSettings,
|
|
1702
|
+
(offset, axisSettings) => {
|
|
1703
|
+
var width = typeof axisSettings.width === 'number' ? axisSettings.width : DEFAULT_Y_AXIS_WIDTH;
|
|
1704
|
+
return {
|
|
1705
|
+
width,
|
|
1706
|
+
height: offset.height,
|
|
1707
|
+
};
|
|
1708
|
+
},
|
|
1709
|
+
);
|
|
1710
|
+
export var selectCartesianAxisSize = (state, axisType, axisId) => {
|
|
1711
|
+
switch (axisType) {
|
|
1712
|
+
case 'xAxis': {
|
|
1713
|
+
return selectXAxisSize(state, axisId).width;
|
|
1714
|
+
}
|
|
1715
|
+
case 'yAxis': {
|
|
1716
|
+
return selectYAxisSize(state, axisId).height;
|
|
1717
|
+
}
|
|
1718
|
+
default: {
|
|
1719
|
+
return undefined;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
export var combineDuplicateDomain = (chartLayout, appliedValues, axis, axisType) => {
|
|
1724
|
+
if (axis == null) {
|
|
1725
|
+
return undefined;
|
|
1726
|
+
}
|
|
1727
|
+
var allowDuplicatedCategory = axis.allowDuplicatedCategory,
|
|
1728
|
+
type = axis.type,
|
|
1729
|
+
dataKey = axis.dataKey;
|
|
1730
|
+
var isCategorical = isCategoricalAxis(chartLayout, axisType);
|
|
1731
|
+
var allData = appliedValues.map((av) => av.value);
|
|
1732
|
+
var validData = allData.filter((v) => v != null);
|
|
1733
|
+
if (
|
|
1734
|
+
dataKey &&
|
|
1735
|
+
isCategorical &&
|
|
1736
|
+
type === 'category' &&
|
|
1737
|
+
allowDuplicatedCategory &&
|
|
1738
|
+
hasDuplicate(validData)
|
|
1739
|
+
) {
|
|
1740
|
+
return allData;
|
|
1741
|
+
}
|
|
1742
|
+
return undefined;
|
|
1743
|
+
};
|
|
1744
|
+
export var selectDuplicateDomain = createSelector(
|
|
1745
|
+
[selectChartLayout, selectAllAppliedValues, selectBaseAxis, pickAxisType],
|
|
1746
|
+
combineDuplicateDomain,
|
|
1747
|
+
);
|
|
1748
|
+
export var selectAxisPropsNeededForCartesianGridTicksGenerator = createSelector(
|
|
1749
|
+
[
|
|
1750
|
+
selectChartLayout,
|
|
1751
|
+
selectCartesianAxisSettings,
|
|
1752
|
+
selectRealScaleType,
|
|
1753
|
+
selectAxisScale,
|
|
1754
|
+
selectDuplicateDomain,
|
|
1755
|
+
selectCategoricalDomain,
|
|
1756
|
+
selectAxisRange,
|
|
1757
|
+
selectNiceTicks,
|
|
1758
|
+
pickAxisType,
|
|
1759
|
+
],
|
|
1760
|
+
(
|
|
1761
|
+
layout,
|
|
1762
|
+
axis,
|
|
1763
|
+
realScaleType,
|
|
1764
|
+
scale,
|
|
1765
|
+
duplicateDomain,
|
|
1766
|
+
categoricalDomain,
|
|
1767
|
+
axisRange,
|
|
1768
|
+
niceTicks,
|
|
1769
|
+
axisType,
|
|
1770
|
+
) => {
|
|
1771
|
+
if (axis == null) {
|
|
1772
|
+
return undefined;
|
|
1773
|
+
}
|
|
1774
|
+
var isCategorical = isCategoricalAxis(layout, axisType);
|
|
1775
|
+
return {
|
|
1776
|
+
angle: axis.angle,
|
|
1777
|
+
interval: axis.interval,
|
|
1778
|
+
minTickGap: axis.minTickGap,
|
|
1779
|
+
orientation: axis.orientation,
|
|
1780
|
+
tick: axis.tick,
|
|
1781
|
+
tickCount: axis.tickCount,
|
|
1782
|
+
tickFormatter: axis.tickFormatter,
|
|
1783
|
+
ticks: axis.ticks,
|
|
1784
|
+
type: axis.type,
|
|
1785
|
+
unit: axis.unit,
|
|
1786
|
+
axisType,
|
|
1787
|
+
categoricalDomain,
|
|
1788
|
+
duplicateDomain,
|
|
1789
|
+
isCategorical,
|
|
1790
|
+
niceTicks,
|
|
1791
|
+
range: axisRange,
|
|
1792
|
+
realScaleType,
|
|
1793
|
+
scale,
|
|
1794
|
+
};
|
|
1795
|
+
},
|
|
1796
|
+
);
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Of on four almost identical implementations of tick generation.
|
|
1800
|
+
* The four horsemen of tick generation are:
|
|
1801
|
+
* - {@link selectTooltipAxisTicks}
|
|
1802
|
+
* - {@link combineAxisTicks}
|
|
1803
|
+
* - {@link getTicksOfAxis}.
|
|
1804
|
+
* - {@link combineGraphicalItemTicks}
|
|
1805
|
+
*/
|
|
1806
|
+
export var combineAxisTicks = (
|
|
1807
|
+
layout,
|
|
1808
|
+
axis,
|
|
1809
|
+
realScaleType,
|
|
1810
|
+
scale,
|
|
1811
|
+
niceTicks,
|
|
1812
|
+
axisRange,
|
|
1813
|
+
duplicateDomain,
|
|
1814
|
+
categoricalDomain,
|
|
1815
|
+
axisType,
|
|
1816
|
+
) => {
|
|
1817
|
+
if (axis == null || scale == null) {
|
|
1818
|
+
return undefined;
|
|
1819
|
+
}
|
|
1820
|
+
var isCategorical = isCategoricalAxis(layout, axisType);
|
|
1821
|
+
var type = axis.type,
|
|
1822
|
+
ticks = axis.ticks,
|
|
1823
|
+
tickCount = axis.tickCount;
|
|
1824
|
+
var offsetForBand =
|
|
1825
|
+
// @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?
|
|
1826
|
+
realScaleType === 'scaleBand' && typeof scale.bandwidth === 'function'
|
|
1827
|
+
? scale.bandwidth() / 2
|
|
1828
|
+
: 2;
|
|
1829
|
+
var offset = type === 'category' && scale.bandwidth ? scale.bandwidth() / offsetForBand : 0;
|
|
1830
|
+
offset =
|
|
1831
|
+
axisType === 'angleAxis' && axisRange != null && axisRange.length >= 2
|
|
1832
|
+
? mathSign(axisRange[0] - axisRange[1]) * 2 * offset
|
|
1833
|
+
: offset;
|
|
1834
|
+
|
|
1835
|
+
// The ticks set by user should only affect the ticks adjacent to axis line
|
|
1836
|
+
var ticksOrNiceTicks = ticks || niceTicks;
|
|
1837
|
+
if (ticksOrNiceTicks) {
|
|
1838
|
+
return ticksOrNiceTicks
|
|
1839
|
+
.map((entry, index) => {
|
|
1840
|
+
var scaleContent = duplicateDomain ? duplicateDomain.indexOf(entry) : entry;
|
|
1841
|
+
var scaled = scale.map(scaleContent);
|
|
1842
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1843
|
+
return null;
|
|
1844
|
+
}
|
|
1845
|
+
return {
|
|
1846
|
+
index,
|
|
1847
|
+
coordinate: scaled + offset,
|
|
1848
|
+
value: entry,
|
|
1849
|
+
offset,
|
|
1850
|
+
};
|
|
1851
|
+
})
|
|
1852
|
+
.filter(isNotNil);
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
// When axis is a categorical axis, but the type of axis is not number and scale is not "auto"
|
|
1856
|
+
// For type='number' with linear scale (where niceTicks are available), skip this branch
|
|
1857
|
+
// so ticks are evenly spaced instead of placed at data positions (GitHub issue #4271)
|
|
1858
|
+
if (isCategorical && categoricalDomain) {
|
|
1859
|
+
return categoricalDomain
|
|
1860
|
+
.map((entry, index) => {
|
|
1861
|
+
var scaled = scale.map(entry);
|
|
1862
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1863
|
+
return null;
|
|
1864
|
+
}
|
|
1865
|
+
return {
|
|
1866
|
+
coordinate: scaled + offset,
|
|
1867
|
+
value: entry,
|
|
1868
|
+
index,
|
|
1869
|
+
offset,
|
|
1870
|
+
};
|
|
1871
|
+
})
|
|
1872
|
+
.filter(isNotNil);
|
|
1873
|
+
}
|
|
1874
|
+
if (scale.ticks) {
|
|
1875
|
+
return scale
|
|
1876
|
+
.ticks(tickCount)
|
|
1877
|
+
.map((entry, index) => {
|
|
1878
|
+
var scaled = scale.map(entry);
|
|
1879
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1880
|
+
return null;
|
|
1881
|
+
}
|
|
1882
|
+
return {
|
|
1883
|
+
coordinate: scaled + offset,
|
|
1884
|
+
value: entry,
|
|
1885
|
+
index,
|
|
1886
|
+
offset,
|
|
1887
|
+
};
|
|
1888
|
+
})
|
|
1889
|
+
.filter(isNotNil);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
// When axis has duplicated text, serial numbers are used to generate scale
|
|
1893
|
+
return scale
|
|
1894
|
+
.domain()
|
|
1895
|
+
.map((entry, index) => {
|
|
1896
|
+
var scaled = scale.map(entry);
|
|
1897
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1898
|
+
return null;
|
|
1899
|
+
}
|
|
1900
|
+
return {
|
|
1901
|
+
coordinate: scaled + offset,
|
|
1902
|
+
// @ts-expect-error can't use Date as index
|
|
1903
|
+
value: duplicateDomain ? duplicateDomain[entry] : entry,
|
|
1904
|
+
index,
|
|
1905
|
+
offset,
|
|
1906
|
+
};
|
|
1907
|
+
})
|
|
1908
|
+
.filter(isNotNil);
|
|
1909
|
+
};
|
|
1910
|
+
export var selectTicksOfAxis = createSelector(
|
|
1911
|
+
[
|
|
1912
|
+
selectChartLayout,
|
|
1913
|
+
selectRenderableAxisSettings,
|
|
1914
|
+
selectRealScaleType,
|
|
1915
|
+
selectAxisScale,
|
|
1916
|
+
selectNiceTicks,
|
|
1917
|
+
selectAxisRange,
|
|
1918
|
+
selectDuplicateDomain,
|
|
1919
|
+
selectCategoricalDomain,
|
|
1920
|
+
pickAxisType,
|
|
1921
|
+
],
|
|
1922
|
+
combineAxisTicks,
|
|
1923
|
+
);
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Of on four almost identical implementations of tick generation.
|
|
1927
|
+
* The four horsemen of tick generation are:
|
|
1928
|
+
* - {@link selectTooltipAxisTicks}
|
|
1929
|
+
* - {@link combineAxisTicks}
|
|
1930
|
+
* - {@link getTicksOfAxis}.
|
|
1931
|
+
* - {@link combineGraphicalItemTicks}
|
|
1932
|
+
*/
|
|
1933
|
+
export var combineGraphicalItemTicks = (
|
|
1934
|
+
layout,
|
|
1935
|
+
axis,
|
|
1936
|
+
scale,
|
|
1937
|
+
axisRange,
|
|
1938
|
+
duplicateDomain,
|
|
1939
|
+
categoricalDomain,
|
|
1940
|
+
axisType,
|
|
1941
|
+
) => {
|
|
1942
|
+
if (axis == null || scale == null || axisRange == null || axisRange[0] === axisRange[1]) {
|
|
1943
|
+
return undefined;
|
|
1944
|
+
}
|
|
1945
|
+
var isCategorical = isCategoricalAxis(layout, axisType);
|
|
1946
|
+
var tickCount = axis.tickCount;
|
|
1947
|
+
var offset = 0;
|
|
1948
|
+
offset =
|
|
1949
|
+
axisType === 'angleAxis' &&
|
|
1950
|
+
(axisRange === null || axisRange === void 0 ? void 0 : axisRange.length) >= 2
|
|
1951
|
+
? mathSign(axisRange[0] - axisRange[1]) * 2 * offset
|
|
1952
|
+
: offset;
|
|
1953
|
+
|
|
1954
|
+
// When axis is a categorical axis, but the type of axis is number or the scale of axis is not "auto"
|
|
1955
|
+
if (isCategorical && categoricalDomain) {
|
|
1956
|
+
return categoricalDomain
|
|
1957
|
+
.map((entry, index) => {
|
|
1958
|
+
var scaled = scale.map(entry);
|
|
1959
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1960
|
+
return null;
|
|
1961
|
+
}
|
|
1962
|
+
return {
|
|
1963
|
+
coordinate: scaled + offset,
|
|
1964
|
+
value: entry,
|
|
1965
|
+
index,
|
|
1966
|
+
offset,
|
|
1967
|
+
};
|
|
1968
|
+
})
|
|
1969
|
+
.filter(isNotNil);
|
|
1970
|
+
}
|
|
1971
|
+
if (scale.ticks) {
|
|
1972
|
+
return scale
|
|
1973
|
+
.ticks(tickCount)
|
|
1974
|
+
.map((entry, index) => {
|
|
1975
|
+
var scaled = scale.map(entry);
|
|
1976
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1977
|
+
return null;
|
|
1978
|
+
}
|
|
1979
|
+
return {
|
|
1980
|
+
coordinate: scaled + offset,
|
|
1981
|
+
value: entry,
|
|
1982
|
+
index,
|
|
1983
|
+
offset,
|
|
1984
|
+
};
|
|
1985
|
+
})
|
|
1986
|
+
.filter(isNotNil);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// When axis has duplicated text, serial numbers are used to generate scale
|
|
1990
|
+
return scale
|
|
1991
|
+
.domain()
|
|
1992
|
+
.map((entry, index) => {
|
|
1993
|
+
var scaled = scale.map(entry);
|
|
1994
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
1995
|
+
return null;
|
|
1996
|
+
}
|
|
1997
|
+
return {
|
|
1998
|
+
coordinate: scaled + offset,
|
|
1999
|
+
// @ts-expect-error can't use unknown as index
|
|
2000
|
+
value: duplicateDomain ? duplicateDomain[entry] : entry,
|
|
2001
|
+
index,
|
|
2002
|
+
offset,
|
|
2003
|
+
};
|
|
2004
|
+
})
|
|
2005
|
+
.filter(isNotNil);
|
|
2006
|
+
};
|
|
2007
|
+
export var selectTicksOfGraphicalItem = createSelector(
|
|
2008
|
+
[
|
|
2009
|
+
selectChartLayout,
|
|
2010
|
+
selectRenderableAxisSettings,
|
|
2011
|
+
selectAxisScale,
|
|
2012
|
+
selectAxisRange,
|
|
2013
|
+
selectDuplicateDomain,
|
|
2014
|
+
selectCategoricalDomain,
|
|
2015
|
+
pickAxisType,
|
|
2016
|
+
],
|
|
2017
|
+
combineGraphicalItemTicks,
|
|
2018
|
+
);
|
|
2019
|
+
|
|
2020
|
+
/**
|
|
2021
|
+
* This is the internal representation of an axis along with its scale function.
|
|
2022
|
+
* Here we have already computed the scale function for the axis,
|
|
2023
|
+
* and replaced the union type of scale (string | function) with just the function type.
|
|
2024
|
+
*/
|
|
2025
|
+
|
|
2026
|
+
export var selectAxisWithScale = createSelector(selectBaseAxis, selectAxisScale, (axis, scale) => {
|
|
2027
|
+
if (axis == null || scale == null) {
|
|
2028
|
+
return undefined;
|
|
2029
|
+
}
|
|
2030
|
+
return _objectSpread(
|
|
2031
|
+
_objectSpread({}, axis),
|
|
2032
|
+
{},
|
|
2033
|
+
{
|
|
2034
|
+
scale,
|
|
2035
|
+
},
|
|
2036
|
+
);
|
|
2037
|
+
});
|
|
2038
|
+
var selectZAxisConfiguredScale = createSelector(
|
|
2039
|
+
[selectBaseAxis, selectRealScaleType, selectAxisDomain, selectAxisRangeWithReverse],
|
|
2040
|
+
combineConfiguredScale,
|
|
2041
|
+
);
|
|
2042
|
+
var selectZAxisScale = createSelector([selectZAxisConfiguredScale], rechartsScaleFactory);
|
|
2043
|
+
export var selectZAxisWithScale = createSelector(
|
|
2044
|
+
(state, _axisType, axisId) => selectZAxisSettings(state, axisId),
|
|
2045
|
+
selectZAxisScale,
|
|
2046
|
+
(axis, scale) => {
|
|
2047
|
+
if (axis == null || scale == null) {
|
|
2048
|
+
return undefined;
|
|
2049
|
+
}
|
|
2050
|
+
return _objectSpread(
|
|
2051
|
+
_objectSpread({}, axis),
|
|
2052
|
+
{},
|
|
2053
|
+
{
|
|
2054
|
+
scale,
|
|
2055
|
+
},
|
|
2056
|
+
);
|
|
2057
|
+
},
|
|
2058
|
+
);
|
|
2059
|
+
|
|
2060
|
+
/**
|
|
2061
|
+
* We are also going to need to implement polar chart directions if we want to support keyboard controls for those.
|
|
2062
|
+
*/
|
|
2063
|
+
|
|
2064
|
+
export var selectChartDirection = createSelector(
|
|
2065
|
+
[selectChartLayout, selectAllXAxes, selectAllYAxes],
|
|
2066
|
+
(layout, allXAxes, allYAxes) => {
|
|
2067
|
+
switch (layout) {
|
|
2068
|
+
case 'horizontal': {
|
|
2069
|
+
return allXAxes.some((axis) => axis.reversed) ? 'right-to-left' : 'left-to-right';
|
|
2070
|
+
}
|
|
2071
|
+
case 'vertical': {
|
|
2072
|
+
return allYAxes.some((axis) => axis.reversed) ? 'bottom-to-top' : 'top-to-bottom';
|
|
2073
|
+
}
|
|
2074
|
+
// TODO: make this better. For now, right arrow triggers "forward", left arrow "back"
|
|
2075
|
+
// however, the tooltip moves an unintuitive direction because of how the indices are rendered
|
|
2076
|
+
case 'centric':
|
|
2077
|
+
case 'radial': {
|
|
2078
|
+
return 'left-to-right';
|
|
2079
|
+
}
|
|
2080
|
+
default: {
|
|
2081
|
+
return undefined;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
},
|
|
2085
|
+
);
|
|
2086
|
+
export var selectRenderedTicksOfAxis = (state, axisType, axisId) => {
|
|
2087
|
+
var _state$renderedTicks$;
|
|
2088
|
+
return (_state$renderedTicks$ = state.renderedTicks[axisType]) === null ||
|
|
2089
|
+
_state$renderedTicks$ === void 0
|
|
2090
|
+
? void 0
|
|
2091
|
+
: _state$renderedTicks$[axisId];
|
|
2092
|
+
};
|
|
2093
|
+
export var selectAxisInverseTickSnapScale = createSelector([selectRenderedTicksOfAxis], (ticks) => {
|
|
2094
|
+
if (!ticks || ticks.length === 0) {
|
|
2095
|
+
return undefined;
|
|
2096
|
+
}
|
|
2097
|
+
return (pixelValue) => {
|
|
2098
|
+
var _closestTick;
|
|
2099
|
+
// Find the tick with the closest coordinate to pixelValue
|
|
2100
|
+
var minDistance = Infinity;
|
|
2101
|
+
var closestTick = ticks[0];
|
|
2102
|
+
for (var tick of ticks) {
|
|
2103
|
+
var distance = Math.abs(tick.coordinate - pixelValue);
|
|
2104
|
+
if (distance < minDistance) {
|
|
2105
|
+
minDistance = distance;
|
|
2106
|
+
closestTick = tick;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return (_closestTick = closestTick) === null || _closestTick === void 0
|
|
2110
|
+
? void 0
|
|
2111
|
+
: _closestTick.value;
|
|
2112
|
+
};
|
|
2113
|
+
});
|