@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,193 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/easing.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
export var ACCURACY = 1e-4;
|
|
4
|
+
var cubicBezierFactor = (c1, c2) => [0, 3 * c1, 3 * c2 - 6 * c1, 3 * c1 - 3 * c2 + 1];
|
|
5
|
+
var evaluatePolynomial = (params, animationElapsedTime) =>
|
|
6
|
+
params.map((param, i) => param * animationElapsedTime ** i).reduce((pre, curr) => pre + curr);
|
|
7
|
+
var cubicBezier = (c1, c2) => (animationElapsedTime) => {
|
|
8
|
+
var params = cubicBezierFactor(c1, c2);
|
|
9
|
+
return evaluatePolynomial(params, animationElapsedTime);
|
|
10
|
+
};
|
|
11
|
+
var derivativeCubicBezier = (c1, c2) => (animationElapsedTime) => {
|
|
12
|
+
var params = cubicBezierFactor(c1, c2);
|
|
13
|
+
var newParams = [...params.map((param, i) => param * i).slice(1), 0];
|
|
14
|
+
return evaluatePolynomial(newParams, animationElapsedTime);
|
|
15
|
+
};
|
|
16
|
+
var parseCubicBezier = (easing) => {
|
|
17
|
+
var _easingParts$;
|
|
18
|
+
var easingParts = easing.split('(');
|
|
19
|
+
if (easingParts.length !== 2 || easingParts[0] !== 'cubic-bezier') {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
var numbers =
|
|
23
|
+
(_easingParts$ = easingParts[1]) === null ||
|
|
24
|
+
_easingParts$ === void 0 ||
|
|
25
|
+
(_easingParts$ = _easingParts$.split(')')[0]) === null ||
|
|
26
|
+
_easingParts$ === void 0
|
|
27
|
+
? void 0
|
|
28
|
+
: _easingParts$.split(',');
|
|
29
|
+
if (numbers == null || numbers.length !== 4) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
var coords = numbers.map((x) => parseFloat(x));
|
|
33
|
+
return [coords[0], coords[1], coords[2], coords[3]];
|
|
34
|
+
};
|
|
35
|
+
var getBezierCoordinates = function getBezierCoordinates() {
|
|
36
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
37
|
+
args[_key] = arguments[_key];
|
|
38
|
+
}
|
|
39
|
+
if (args.length === 1) {
|
|
40
|
+
switch (args[0]) {
|
|
41
|
+
case 'linear':
|
|
42
|
+
return [0.0, 0.0, 1.0, 1.0];
|
|
43
|
+
case 'ease':
|
|
44
|
+
return [0.25, 0.1, 0.25, 1.0];
|
|
45
|
+
case 'ease-in':
|
|
46
|
+
return [0.42, 0.0, 1.0, 1.0];
|
|
47
|
+
case 'ease-out':
|
|
48
|
+
return [0.42, 0.0, 0.58, 1.0];
|
|
49
|
+
case 'ease-in-out':
|
|
50
|
+
return [0.0, 0.0, 0.58, 1.0];
|
|
51
|
+
default: {
|
|
52
|
+
var easing = parseCubicBezier(args[0]);
|
|
53
|
+
if (easing) {
|
|
54
|
+
return easing;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (args.length === 4) {
|
|
60
|
+
return args;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Fallback for invalid inputs. The previous implementation was buggy and would lead to NaN.
|
|
64
|
+
// Returning linear easing is a safe default.
|
|
65
|
+
return [0.0, 0.0, 1.0, 1.0];
|
|
66
|
+
};
|
|
67
|
+
var createBezierEasing = (x1, y1, x2, y2) => {
|
|
68
|
+
var curveX = cubicBezier(x1, x2);
|
|
69
|
+
var curveY = cubicBezier(y1, y2);
|
|
70
|
+
var derCurveX = derivativeCubicBezier(x1, x2);
|
|
71
|
+
var rangeValue = (value) => {
|
|
72
|
+
if (value > 1) {
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
if (value < 0) {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
};
|
|
80
|
+
var bezier = (_animationElapsedTime) => {
|
|
81
|
+
var animationElapsedTime = _animationElapsedTime > 1 ? 1 : _animationElapsedTime;
|
|
82
|
+
var x = animationElapsedTime;
|
|
83
|
+
for (var i = 0; i < 8; ++i) {
|
|
84
|
+
var evalT = curveX(x) - animationElapsedTime;
|
|
85
|
+
var derVal = derCurveX(x);
|
|
86
|
+
if (Math.abs(evalT - animationElapsedTime) < ACCURACY || derVal < ACCURACY) {
|
|
87
|
+
return curveY(x);
|
|
88
|
+
}
|
|
89
|
+
x = rangeValue(x - evalT / derVal);
|
|
90
|
+
}
|
|
91
|
+
return curveY(x);
|
|
92
|
+
};
|
|
93
|
+
bezier.isStepper = false;
|
|
94
|
+
return bezier;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// calculate cubic-bezier using Newton's method
|
|
98
|
+
export var configBezier = function configBezier() {
|
|
99
|
+
return createBezierEasing(...getBezierCoordinates(...arguments));
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Creates a performance-optimized, progress-based spring easing function.
|
|
103
|
+
* It pre-calculates ("bakes") spring physics frames upfront based on a fixed duration,
|
|
104
|
+
* then returns a pure, lightweight function mapping progress (0 to 1) to the animated position.
|
|
105
|
+
* This approach is ideal for low-power devices because it removes heavy physics math from the frame loop.
|
|
106
|
+
*/
|
|
107
|
+
export var createSpringEasing = function createSpringEasing() {
|
|
108
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
109
|
+
var _config$stiff = config.stiff,
|
|
110
|
+
stiff = _config$stiff === void 0 ? 100 : _config$stiff,
|
|
111
|
+
_config$damping = config.damping,
|
|
112
|
+
damping = _config$damping === void 0 ? 8 : _config$damping,
|
|
113
|
+
_config$dt = config.dt,
|
|
114
|
+
dt = _config$dt === void 0 ? 16.67 : _config$dt;
|
|
115
|
+
var destX = 1;
|
|
116
|
+
var positions = [0];
|
|
117
|
+
var currX = 0;
|
|
118
|
+
var currV = 0;
|
|
119
|
+
|
|
120
|
+
// Safety valve to prevent accidental infinite loops if physics config is extreme
|
|
121
|
+
var maxIterations = 10000;
|
|
122
|
+
var iterations = 0;
|
|
123
|
+
|
|
124
|
+
// 1. Run the simulation until the spring completely stops moving
|
|
125
|
+
while (iterations < maxIterations) {
|
|
126
|
+
var FSpring = -(currX - destX) * stiff;
|
|
127
|
+
var FDamping = currV * damping;
|
|
128
|
+
currV += ((FSpring - FDamping) * dt) / 1000;
|
|
129
|
+
currX += (currV * dt) / 1000;
|
|
130
|
+
positions.push(currX);
|
|
131
|
+
|
|
132
|
+
// Stop only when position is essentially at 1.0 AND bounce velocity has died down
|
|
133
|
+
if (Math.abs(currX - destX) < ACCURACY && Math.abs(currV) < ACCURACY) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
iterations++;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Force the absolute final element to be exactly 1.0 for a perfect finish
|
|
140
|
+
positions[positions.length - 1] = destX;
|
|
141
|
+
var maxIndex = positions.length - 1;
|
|
142
|
+
|
|
143
|
+
// 2. The ultra-smooth runtime function mapping your 0..1 progress
|
|
144
|
+
return (t) => {
|
|
145
|
+
var _positions$index, _positions, _positions$index2;
|
|
146
|
+
if (t <= 0) return 0;
|
|
147
|
+
if (t >= 1) return destX;
|
|
148
|
+
|
|
149
|
+
// Scale t (0..1) proportionally across our entire pre-calculated array
|
|
150
|
+
var exactFrame = t * maxIndex;
|
|
151
|
+
var index = Math.floor(exactFrame);
|
|
152
|
+
var fraction = exactFrame - index;
|
|
153
|
+
|
|
154
|
+
// Blend between the two closest frames
|
|
155
|
+
return (
|
|
156
|
+
((_positions$index = positions[index]) !== null && _positions$index !== void 0
|
|
157
|
+
? _positions$index
|
|
158
|
+
: 0) +
|
|
159
|
+
(((_positions = positions[index + 1]) !== null && _positions !== void 0 ? _positions : 0) -
|
|
160
|
+
((_positions$index2 = positions[index]) !== null && _positions$index2 !== void 0
|
|
161
|
+
? _positions$index2
|
|
162
|
+
: 0)) *
|
|
163
|
+
fraction
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @inline
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
export var createEasingFunction = (easing) => {
|
|
173
|
+
if (typeof easing === 'string') {
|
|
174
|
+
switch (easing) {
|
|
175
|
+
case 'ease':
|
|
176
|
+
case 'ease-in-out':
|
|
177
|
+
case 'ease-out':
|
|
178
|
+
case 'ease-in':
|
|
179
|
+
case 'linear':
|
|
180
|
+
return configBezier(easing);
|
|
181
|
+
case 'spring':
|
|
182
|
+
return createSpringEasing();
|
|
183
|
+
default:
|
|
184
|
+
if (easing.split('(')[0] === 'cubic-bezier') {
|
|
185
|
+
return configBezier(easing);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (typeof easing === 'function') {
|
|
190
|
+
return easing;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/matchBy.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
function _slicedToArray(r, e) {
|
|
4
|
+
return (
|
|
5
|
+
_arrayWithHoles(r) ||
|
|
6
|
+
_iterableToArrayLimit(r, e) ||
|
|
7
|
+
_unsupportedIterableToArray(r, e) ||
|
|
8
|
+
_nonIterableRest()
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function _nonIterableRest() {
|
|
12
|
+
throw new TypeError(
|
|
13
|
+
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function _unsupportedIterableToArray(r, a) {
|
|
17
|
+
if (r) {
|
|
18
|
+
if ('string' == typeof r) return _arrayLikeToArray(r, a);
|
|
19
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
20
|
+
return (
|
|
21
|
+
'Object' === t && r.constructor && (t = r.constructor.name),
|
|
22
|
+
'Map' === t || 'Set' === t
|
|
23
|
+
? Array.from(r)
|
|
24
|
+
: 'Arguments' === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
|
|
25
|
+
? _arrayLikeToArray(r, a)
|
|
26
|
+
: void 0
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function _arrayLikeToArray(r, a) {
|
|
31
|
+
(null == a || a > r.length) && (a = r.length);
|
|
32
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
function _iterableToArrayLimit(r, l) {
|
|
36
|
+
var t =
|
|
37
|
+
null == r ? null : ('undefined' != typeof Symbol && r[Symbol.iterator]) || r['@@iterator'];
|
|
38
|
+
if (null != t) {
|
|
39
|
+
var e,
|
|
40
|
+
n,
|
|
41
|
+
i,
|
|
42
|
+
u,
|
|
43
|
+
a = [],
|
|
44
|
+
f = !0,
|
|
45
|
+
o = !1;
|
|
46
|
+
try {
|
|
47
|
+
if (((i = (t = t.call(r)).next), 0 === l)) {
|
|
48
|
+
if (Object(t) !== t) return;
|
|
49
|
+
f = !1;
|
|
50
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
51
|
+
} catch (r) {
|
|
52
|
+
((o = !0), (n = r));
|
|
53
|
+
} finally {
|
|
54
|
+
try {
|
|
55
|
+
if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) return;
|
|
56
|
+
} finally {
|
|
57
|
+
if (o) throw n;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return a;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function _arrayWithHoles(r) {
|
|
64
|
+
if (Array.isArray(r)) return r;
|
|
65
|
+
}
|
|
66
|
+
import { getValueByDataKey } from '../util/ChartUtils';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A tagged union describing the status of an item during animation.
|
|
70
|
+
*
|
|
71
|
+
* - `matched`: item exists in both previous and next data — interpolate between positions
|
|
72
|
+
* - `added`: item is new (no previous position) — animate in
|
|
73
|
+
* - `removed`: item was in previous data but not in next — animate out
|
|
74
|
+
*
|
|
75
|
+
* @since 3.9
|
|
76
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A function that extracts a key from an animation item for matching purposes.
|
|
81
|
+
* Items in the previous and next arrays that return the same key are considered
|
|
82
|
+
* the same logical item and will animate between their positions.
|
|
83
|
+
*
|
|
84
|
+
* @param item The chart item (e.g., a bar rectangle, a line point, a pie sector)
|
|
85
|
+
* @param index The index of the item in the array
|
|
86
|
+
* @returns A string or number key, or null if the item cannot be matched
|
|
87
|
+
*
|
|
88
|
+
* @since 3.9
|
|
89
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The union of all accepted `animationMatchBy` prop values:
|
|
94
|
+
* a built-in sentinel string, or a custom matching function.
|
|
95
|
+
*
|
|
96
|
+
* @since 3.9
|
|
97
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Match animation items by their array index (the default behavior).
|
|
102
|
+
*
|
|
103
|
+
* Previous items are paired with next items based on their position
|
|
104
|
+
* in the array, with proportional stretching when array lengths differ.
|
|
105
|
+
* When going from 5 to 15 items, each old point "covers" approximately 3 new points;
|
|
106
|
+
* when shrinking, some old points are skipped.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { matchByIndex } from 'recharts';
|
|
110
|
+
* <Line animationMatchBy={matchByIndex} />
|
|
111
|
+
*
|
|
112
|
+
* @since 3.9
|
|
113
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
114
|
+
*/
|
|
115
|
+
export var matchByIndex = 'index';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Match animation items sequentially: previous item 0 pairs with next item 0,
|
|
119
|
+
* previous item 1 pairs with next item 1, and so on. When the new array is longer,
|
|
120
|
+
* the extra items have no match and animate in from their default position.
|
|
121
|
+
* When the new array is shorter, the ancient items are simply dropped.
|
|
122
|
+
*
|
|
123
|
+
* This is useful when new data is appended at the end of the array, and you want
|
|
124
|
+
* existing points to stay in place while new points animate in.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* import { matchAppend } from 'recharts';
|
|
128
|
+
* <Line animationMatchBy={matchAppend} />
|
|
129
|
+
*
|
|
130
|
+
* @since 3.9
|
|
131
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
132
|
+
*/
|
|
133
|
+
export var matchAppend = 'append';
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create a matching function that pairs items by a data key from their payload.
|
|
137
|
+
*
|
|
138
|
+
* Useful for time-series or streaming charts where new data points are added
|
|
139
|
+
* to one end and old points are removed from the other. This ensures existing
|
|
140
|
+
* points animate smoothly to their new positions instead of shifting by index.
|
|
141
|
+
*
|
|
142
|
+
* @param dataKey The key to look up in each item's payload (e.g., 'timestamp', 'date', 'id')
|
|
143
|
+
* @returns An AnimationMatchBy function that can be passed to the animationMatchBy prop
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* import { matchByDataKey } from 'recharts';
|
|
147
|
+
* <Line animationMatchBy={matchByDataKey('timestamp')} />
|
|
148
|
+
* <Bar animationMatchBy={matchByDataKey('name')} />
|
|
149
|
+
* <Pie animationMatchBy={matchByDataKey('id')} />
|
|
150
|
+
*
|
|
151
|
+
* @since 3.9
|
|
152
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
|
|
153
|
+
*/
|
|
154
|
+
export function matchByDataKey(dataKey) {
|
|
155
|
+
return (item) => {
|
|
156
|
+
if (item.payload == null || typeof item.payload !== 'object') return null;
|
|
157
|
+
var value = getValueByDataKey(item.payload, dataKey);
|
|
158
|
+
if (value == null) return null;
|
|
159
|
+
if (typeof value === 'string' || typeof value === 'number') return value;
|
|
160
|
+
return JSON.stringify(value);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function tagAlignedItems(alignedPrevItems, nextItems) {
|
|
164
|
+
var removedPrevItems = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
165
|
+
var tagged = [];
|
|
166
|
+
/*
|
|
167
|
+
* We put removed points at the start because we assume that a typical chart animates right-to-left
|
|
168
|
+
* and the removed points will disappear from the left edge and outside the plot area.
|
|
169
|
+
* If you chart behaves differently you may want to customize your matching function.
|
|
170
|
+
*/
|
|
171
|
+
for (var prev of removedPrevItems) {
|
|
172
|
+
tagged.push({
|
|
173
|
+
status: 'removed',
|
|
174
|
+
prev,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
for (var i = 0; i < nextItems.length; i++) {
|
|
178
|
+
// This function intentionally pairs by array index. The strategy-specific functions above are
|
|
179
|
+
// responsible for producing an alignedPrevItems array whose indices already correspond to nextItems.
|
|
180
|
+
var _prev = alignedPrevItems[i];
|
|
181
|
+
var next = nextItems[i];
|
|
182
|
+
if (_prev != null) {
|
|
183
|
+
tagged.push({
|
|
184
|
+
status: 'matched',
|
|
185
|
+
prev: _prev,
|
|
186
|
+
next,
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
tagged.push({
|
|
190
|
+
status: 'added',
|
|
191
|
+
next,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return tagged;
|
|
196
|
+
}
|
|
197
|
+
function matchByIndexImpl(prevItems, nextItems) {
|
|
198
|
+
var factor = prevItems.length / nextItems.length;
|
|
199
|
+
var alignedPrevItems = nextItems.map((_, i) => prevItems[Math.floor(i * factor)]);
|
|
200
|
+
return tagAlignedItems(alignedPrevItems, nextItems);
|
|
201
|
+
}
|
|
202
|
+
function matchAppendImpl(prevItems, nextItems) {
|
|
203
|
+
var alignedPrevItems = nextItems.map((_, i) => prevItems[i]);
|
|
204
|
+
return tagAlignedItems(alignedPrevItems, nextItems);
|
|
205
|
+
}
|
|
206
|
+
function buildPrevKeyMap(prevItems, matchBy) {
|
|
207
|
+
var prevMap = new Map();
|
|
208
|
+
for (var i = 0; i < prevItems.length; i++) {
|
|
209
|
+
var _item = prevItems[i];
|
|
210
|
+
if (_item == null) continue;
|
|
211
|
+
var key = matchBy(_item, i);
|
|
212
|
+
if (key != null && !prevMap.has(key)) {
|
|
213
|
+
prevMap.set(key, _item);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return prevMap;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Match previous items to next items by key, and include removed items explicitly.
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
function matchByKey(prevItems, nextItems, matchBy) {
|
|
225
|
+
var prevMap = buildPrevKeyMap(prevItems, matchBy);
|
|
226
|
+
|
|
227
|
+
// Track which prev keys were matched
|
|
228
|
+
var matchedKeys = new Set();
|
|
229
|
+
var alignedPrevItems = nextItems.map((next, i) => {
|
|
230
|
+
var key = matchBy(next, i);
|
|
231
|
+
if (key != null) {
|
|
232
|
+
var prev = prevMap.get(key);
|
|
233
|
+
if (prev !== undefined) {
|
|
234
|
+
matchedKeys.add(key);
|
|
235
|
+
return prev;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Removed = prev items whose keys were not matched to any next item
|
|
242
|
+
var removedPrevItems = [];
|
|
243
|
+
for (var _ref3 of prevMap) {
|
|
244
|
+
var _ref2 = _slicedToArray(_ref3, 2);
|
|
245
|
+
var key = _ref2[0];
|
|
246
|
+
var _item2 = _ref2[1];
|
|
247
|
+
if (!matchedKeys.has(key)) {
|
|
248
|
+
removedPrevItems.push(_item2);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return tagAlignedItems(alignedPrevItems, nextItems, removedPrevItems);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Match previous items to next items using the given matching strategy and return tagged animation items.
|
|
256
|
+
*
|
|
257
|
+
* On first render, all next items are returned as `{ status: 'added' }`.
|
|
258
|
+
* For key-based matching, unmatched previous items are appended as `{ status: 'removed' }`.
|
|
259
|
+
*
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
export function matchAnimationItems(prevItems, nextItems, matchBy) {
|
|
263
|
+
if (nextItems == null) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
if (prevItems == null) {
|
|
267
|
+
return nextItems.map((next) => ({
|
|
268
|
+
status: 'added',
|
|
269
|
+
next,
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
if (matchBy === matchByIndex) {
|
|
273
|
+
return matchByIndexImpl(prevItems, nextItems);
|
|
274
|
+
}
|
|
275
|
+
if (matchBy === matchAppend) {
|
|
276
|
+
return matchAppendImpl(prevItems, nextItems);
|
|
277
|
+
}
|
|
278
|
+
return matchByKey(prevItems, nextItems, matchBy);
|
|
279
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/timeoutController.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
/**
|
|
4
|
+
* Callback type for the timeout function.
|
|
5
|
+
* Receives current time as an argument.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A function that, when called, cancels the timeout.
|
|
10
|
+
*
|
|
11
|
+
* @since 3.9
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* TimeoutController is responsible for controlling the movement of time.
|
|
16
|
+
* Think of it as a clock.
|
|
17
|
+
*
|
|
18
|
+
* Recharts default implementation uses requestAnimationFrame which works great in a browser.
|
|
19
|
+
* You may choose to override this which is especially useful if you want to control animations.
|
|
20
|
+
*
|
|
21
|
+
* Why would you want to do this?
|
|
22
|
+
* - unit tests
|
|
23
|
+
* - animations based on something other than time: UI controls, page scroll, mouse movement ...
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
|
|
26
|
+
*
|
|
27
|
+
* @since 3.9
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export class RequestAnimationFrameTimeoutController {
|
|
31
|
+
setTimeout(callback) {
|
|
32
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
33
|
+
var startTime = performance.now();
|
|
34
|
+
var requestId = null;
|
|
35
|
+
var executeCallback = (now) => {
|
|
36
|
+
if (now - startTime >= delay) {
|
|
37
|
+
callback(now);
|
|
38
|
+
} else {
|
|
39
|
+
requestId = requestAnimationFrame(executeCallback);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
requestId = requestAnimationFrame(executeCallback);
|
|
43
|
+
return () => {
|
|
44
|
+
if (requestId != null) {
|
|
45
|
+
cancelAnimationFrame(requestId);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Port of animation/useAnimationController.tsx — context override point for
|
|
2
|
+
// the animation driver (tests inject a mock controller; the default ticks on
|
|
3
|
+
// requestAnimationFrame).
|
|
4
|
+
import { createContext, useContext, useMemo } from 'octane';
|
|
5
|
+
import { animationControllerImpl } from './AnimationControllerImpl';
|
|
6
|
+
|
|
7
|
+
const AnimationControllerContext = createContext(animationControllerImpl);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Allows overriding the default AnimationController that Recharts uses
|
|
11
|
+
* internally to drive animations.
|
|
12
|
+
* @since 3.9
|
|
13
|
+
*/
|
|
14
|
+
export const AnimationControllerProvider = AnimationControllerContext.Provider;
|
|
15
|
+
|
|
16
|
+
export function useAnimationController(animationControllerFromProps: unknown) {
|
|
17
|
+
const animationControllerFromContext = useContext(AnimationControllerContext);
|
|
18
|
+
return useMemo(
|
|
19
|
+
() => animationControllerFromProps ?? animationControllerFromContext,
|
|
20
|
+
[animationControllerFromProps, animationControllerFromContext],
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Port of animation/useAnimationStartSnapshot.ts — interruption-safe animation
|
|
2
|
+
// snapshots: `startValue` is frozen per animation cycle; the live "latest
|
|
3
|
+
// visible frame" ref is only writable after the new cycle's t=0 handshake.
|
|
4
|
+
import { useCallback, useRef } from 'octane';
|
|
5
|
+
|
|
6
|
+
export function useAnimationStartSnapshot(
|
|
7
|
+
animationInput: unknown,
|
|
8
|
+
previousValueRef: { current: any },
|
|
9
|
+
) {
|
|
10
|
+
// Identity of the animation cycle currently being served.
|
|
11
|
+
const previousAnimationInputRef = useRef(animationInput);
|
|
12
|
+
// Frozen start-of-cycle value used for interpolation.
|
|
13
|
+
const startValueRef = useRef(previousValueRef.current);
|
|
14
|
+
// Blocks live-ref writes until the new animation renders its own t=0 frame.
|
|
15
|
+
const isReadyToCommitRef = useRef(true);
|
|
16
|
+
if (previousAnimationInputRef.current !== animationInput) {
|
|
17
|
+
// New animation cycle: capture exactly one frozen starting snapshot.
|
|
18
|
+
previousAnimationInputRef.current = animationInput;
|
|
19
|
+
startValueRef.current = previousValueRef.current;
|
|
20
|
+
isReadyToCommitRef.current = false;
|
|
21
|
+
}
|
|
22
|
+
const syncStepValue = useCallback(
|
|
23
|
+
(stepValue: any, animationElapsedTime: number, canCommit = true) => {
|
|
24
|
+
if (animationElapsedTime === 0) {
|
|
25
|
+
// t=0 handshake: the new animation has rendered its starting frame.
|
|
26
|
+
isReadyToCommitRef.current = true;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (animationElapsedTime === 1) {
|
|
30
|
+
// Keep the frozen snapshot aligned with the fully completed geometry.
|
|
31
|
+
startValueRef.current = stepValue;
|
|
32
|
+
}
|
|
33
|
+
if (animationElapsedTime > 0 && isReadyToCommitRef.current && canCommit) {
|
|
34
|
+
previousValueRef.current = stepValue;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[previousValueRef],
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
startValue: startValueRef.current,
|
|
41
|
+
syncStepValue,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/util.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
/*
|
|
4
|
+
* @description: convert camel case to dash case
|
|
5
|
+
* string => string
|
|
6
|
+
*/
|
|
7
|
+
export var getDashCase = (name) => name.replace(/([A-Z])/g, (v) => '-'.concat(v.toLowerCase()));
|
|
8
|
+
export var getTransitionVal = (props, duration, easing) =>
|
|
9
|
+
props
|
|
10
|
+
.map((prop) => ''.concat(getDashCase(prop), ' ').concat(duration, 'ms ').concat(easing))
|
|
11
|
+
.join(',');
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Extensionless-resolution shim: vendored modules (state/selectors/
|
|
2
|
+
// barSelectors.js) import `computeBarRectangles` from '../../cartesian/Bar' —
|
|
3
|
+
// this .ts entry forwards to the .tsrx implementation.
|
|
4
|
+
export { Bar, computeBarRectangles, defaultBarProps } from './Bar.tsrx';
|