@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octanejs/recharts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Recharts for the octane renderer — reuses recharts' framework-agnostic core (Redux Toolkit state, reselect, d3 via victory-vendor) and swaps the React layer for octane's hooks.",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Dominic Gannaway",
|
|
9
|
+
"email": "dg@domgan.com"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/octanejs/octane.git",
|
|
17
|
+
"directory": "packages/recharts"
|
|
18
|
+
},
|
|
19
|
+
"main": "src/index.ts",
|
|
20
|
+
"module": "src/index.ts",
|
|
21
|
+
"types": "src/index.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"src",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@reduxjs/toolkit": "^2.9.0",
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
|
+
"decimal.js-light": "^2.5.1",
|
|
33
|
+
"es-toolkit": "^1.39.3",
|
|
34
|
+
"eventemitter3": "^5.0.1",
|
|
35
|
+
"immer": "^11.1.8",
|
|
36
|
+
"reselect": "5.2.0",
|
|
37
|
+
"tiny-invariant": "^1.3.3",
|
|
38
|
+
"victory-vendor": "^37.0.2",
|
|
39
|
+
"@octanejs/redux": "0.1.0",
|
|
40
|
+
"octane": "0.1.3"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tsrx/react": "^0.2.37",
|
|
44
|
+
"esbuild": "^0.28.1",
|
|
45
|
+
"react": "^19.2.0",
|
|
46
|
+
"react-dom": "^19.2.0",
|
|
47
|
+
"recharts": "3.9.2",
|
|
48
|
+
"vitest": "^4.1.9"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Port of animation/AnimatedItems.tsx — the reusable enter/update/exit
|
|
2
|
+
// animation wrapper for array-based chart data (Bar, Line, Area, Pie, …).
|
|
3
|
+
import { useCallback, useState } from 'octane';
|
|
4
|
+
import { JavascriptAnimate } from './JavascriptAnimate.tsrx';
|
|
5
|
+
import { useAnimationId } from '../util/useAnimationId.ts';
|
|
6
|
+
import { matchAnimationItems, matchByIndex } from './matchBy';
|
|
7
|
+
import { useAnimationStartSnapshot } from './useAnimationStartSnapshot.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tracks animation state and provides callbacks for animation start/end.
|
|
11
|
+
*/
|
|
12
|
+
export function useAnimationCallbacks(onAnimationStart, onAnimationEnd) {
|
|
13
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
14
|
+
const handleAnimationStart = useCallback(() => {
|
|
15
|
+
if (typeof onAnimationStart === 'function') {
|
|
16
|
+
onAnimationStart();
|
|
17
|
+
}
|
|
18
|
+
setIsAnimating(true);
|
|
19
|
+
}, [onAnimationStart]);
|
|
20
|
+
const handleAnimationEnd = useCallback(() => {
|
|
21
|
+
if (typeof onAnimationEnd === 'function') {
|
|
22
|
+
onAnimationEnd();
|
|
23
|
+
}
|
|
24
|
+
setIsAnimating(false);
|
|
25
|
+
}, [onAnimationEnd]);
|
|
26
|
+
return {
|
|
27
|
+
isAnimating,
|
|
28
|
+
handleAnimationStart,
|
|
29
|
+
handleAnimationEnd,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function AnimatedItems(props) {
|
|
34
|
+
const {
|
|
35
|
+
animationInput,
|
|
36
|
+
animationIdPrefix,
|
|
37
|
+
items,
|
|
38
|
+
previousItemsRef,
|
|
39
|
+
isAnimationActive,
|
|
40
|
+
animationBegin,
|
|
41
|
+
animationDuration,
|
|
42
|
+
animationEasing,
|
|
43
|
+
onAnimationStart,
|
|
44
|
+
onAnimationEnd,
|
|
45
|
+
animationInterpolateFn,
|
|
46
|
+
animationMatchBy,
|
|
47
|
+
shouldUpdatePreviousRef,
|
|
48
|
+
children,
|
|
49
|
+
layout,
|
|
50
|
+
} = props;
|
|
51
|
+
const animationId = useAnimationId(animationInput, animationIdPrefix);
|
|
52
|
+
const animationStartItems = useAnimationStartSnapshot(animationId, previousItemsRef);
|
|
53
|
+
const rawPrevItems = animationStartItems.startValue ?? null;
|
|
54
|
+
const animationItems = matchAnimationItems(rawPrevItems, items, animationMatchBy ?? matchByIndex);
|
|
55
|
+
return <JavascriptAnimate
|
|
56
|
+
animationId={animationId}
|
|
57
|
+
begin={animationBegin}
|
|
58
|
+
duration={animationDuration}
|
|
59
|
+
isActive={isAnimationActive}
|
|
60
|
+
easing={animationEasing}
|
|
61
|
+
onAnimationEnd={onAnimationEnd}
|
|
62
|
+
onAnimationStart={onAnimationStart}
|
|
63
|
+
key={animationId}
|
|
64
|
+
>
|
|
65
|
+
{(animationElapsedTime) => {
|
|
66
|
+
const isEntrance = rawPrevItems == null;
|
|
67
|
+
const stepData =
|
|
68
|
+
items == null
|
|
69
|
+
? items
|
|
70
|
+
: animationInterpolateFn(animationItems, animationElapsedTime, layout);
|
|
71
|
+
const canUpdate =
|
|
72
|
+
shouldUpdatePreviousRef
|
|
73
|
+
? shouldUpdatePreviousRef(animationElapsedTime)
|
|
74
|
+
: animationElapsedTime > 0;
|
|
75
|
+
animationStartItems.syncStepValue(stepData, animationElapsedTime, canUpdate);
|
|
76
|
+
if (stepData == null) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return children(stepData, animationElapsedTime, isEntrance);
|
|
80
|
+
}}
|
|
81
|
+
</JavascriptAnimate>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/AnimationControllerImpl.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
/**
|
|
4
|
+
* JavaScript animations require trigger and repaint as soon as possible,
|
|
5
|
+
* so this class uses the timeoutController to trigger updates as quickly as the controller allows.
|
|
6
|
+
*
|
|
7
|
+
* JavaScript animation progress is represented as a stream of values. The exact type depends on the animationHandle type.
|
|
8
|
+
* Each individual consumer is then responsible for mapping those values onto a React component.
|
|
9
|
+
*/
|
|
10
|
+
export var animationControllerImpl = (timeoutController, animationHandle, listener) => {
|
|
11
|
+
var cancellable;
|
|
12
|
+
var nextUpdate = (now) => {
|
|
13
|
+
var timeRemaining = animationHandle.tick(now);
|
|
14
|
+
if (animationHandle.getState() === 'active') {
|
|
15
|
+
listener(animationHandle.getInterpolated());
|
|
16
|
+
if (animationHandle.getProgress() === 1) {
|
|
17
|
+
animationHandle.complete();
|
|
18
|
+
cancellable = undefined;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
cancellable = timeoutController.setTimeout(nextUpdate, timeRemaining);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
cancellable = timeoutController.setTimeout(nextUpdate, timeRemaining);
|
|
25
|
+
};
|
|
26
|
+
cancellable = timeoutController.setTimeout(nextUpdate, 0);
|
|
27
|
+
return () => {
|
|
28
|
+
var _cancellable;
|
|
29
|
+
return (_cancellable = cancellable) === null || _cancellable === void 0
|
|
30
|
+
? void 0
|
|
31
|
+
: _cancellable();
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/animation/AnimationHandle.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
function _defineProperty(e, r, t) {
|
|
4
|
+
return (
|
|
5
|
+
(r = _toPropertyKey(r)) in e
|
|
6
|
+
? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 })
|
|
7
|
+
: (e[r] = t),
|
|
8
|
+
e
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function _toPropertyKey(t) {
|
|
12
|
+
var i = _toPrimitive(t, 'string');
|
|
13
|
+
return 'symbol' == typeof i ? i : i + '';
|
|
14
|
+
}
|
|
15
|
+
function _toPrimitive(t, r) {
|
|
16
|
+
if ('object' != typeof t || !t) return t;
|
|
17
|
+
var e = t[Symbol.toPrimitive];
|
|
18
|
+
if (void 0 !== e) {
|
|
19
|
+
var i = e.call(t, r || 'default');
|
|
20
|
+
if ('object' != typeof i) return i;
|
|
21
|
+
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
22
|
+
}
|
|
23
|
+
return ('string' === r ? String : Number)(t);
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line max-classes-per-file
|
|
26
|
+
import { interpolate } from '../util/DataUtils';
|
|
27
|
+
var INIT = 'init';
|
|
28
|
+
var PENDING = 'pending';
|
|
29
|
+
var ACTIVE = 'active';
|
|
30
|
+
var COMPLETED = 'completed';
|
|
31
|
+
function duration(time) {
|
|
32
|
+
return Math.max(0, time);
|
|
33
|
+
}
|
|
34
|
+
class RechartsAnimation {
|
|
35
|
+
/**
|
|
36
|
+
* Returns the absolute time after the animationBegin delay has been completed,
|
|
37
|
+
* and when the animationDuration started ticking.
|
|
38
|
+
*/
|
|
39
|
+
getAnimationStartedTime() {
|
|
40
|
+
return this.animationStartedTime;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the absolute time of when the animation began - now it will wait for {animationBegin} ms before the transition starts
|
|
45
|
+
*/
|
|
46
|
+
getBeginStartedTime() {
|
|
47
|
+
return this.beginStartedTime;
|
|
48
|
+
}
|
|
49
|
+
constructor(param) {
|
|
50
|
+
var _param$onAnimationSta;
|
|
51
|
+
_defineProperty(this, 'state', INIT);
|
|
52
|
+
this.animationId = param.animationId;
|
|
53
|
+
this.onAnimationEnd = param.onAnimationEnd;
|
|
54
|
+
this.animationDuration = duration(param.animationDuration);
|
|
55
|
+
this.animationBegin = duration(param.animationBegin);
|
|
56
|
+
this.progress = 0;
|
|
57
|
+
this.from = param.from;
|
|
58
|
+
this.to = param.to;
|
|
59
|
+
this.easing = param.easing;
|
|
60
|
+
// Mimic what the previous animationManager was doing - call onAnimationStart immediately and synchronously
|
|
61
|
+
(_param$onAnimationSta = param.onAnimationStart) === null ||
|
|
62
|
+
_param$onAnimationSta === void 0 ||
|
|
63
|
+
_param$onAnimationSta.call(param);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the state machine current state
|
|
67
|
+
* - `init`: animation had just been created. It immediately calls `onAnimationStart`
|
|
68
|
+
* - `pending`: animation is now paused for `animationBegin` milliseconds until the transition begins
|
|
69
|
+
* - `active`: animation is transitioning items on screen
|
|
70
|
+
* - `completed`: animation has completed its transition and executed `onAnimationEnd`.
|
|
71
|
+
* This state is final and the animation is no longer allowed to transition to other states.
|
|
72
|
+
*/
|
|
73
|
+
getState() {
|
|
74
|
+
return this.state;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns the easing input or function
|
|
79
|
+
*/
|
|
80
|
+
getEasing() {
|
|
81
|
+
return this.easing;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the configuration - the duration of the transition.
|
|
86
|
+
* Does not change in time, does not change when state changes, this is a static value.
|
|
87
|
+
*/
|
|
88
|
+
getAnimationDuration() {
|
|
89
|
+
return this.animationDuration;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sets the current time of the animation. The animation sets its internal state and progress accordingly.
|
|
94
|
+
* This is current, absolute time; not additive!
|
|
95
|
+
* This allows you to essentially "travel back in time" based on the value you pass in here.
|
|
96
|
+
*
|
|
97
|
+
* Returns the (relative) time remaining until the current activity is over.
|
|
98
|
+
* Meaning: if the state is in a middle of a delay, returns the time left until the delay is finished.
|
|
99
|
+
* If the state is in the middle of a transition, returns time left until that transition is complete.
|
|
100
|
+
* This is useful because it's the same number you can take and put into setTimeout(fn, X)
|
|
101
|
+
* as that's how much time we need to wait until the next state transition happens.
|
|
102
|
+
*/
|
|
103
|
+
tick(now) {
|
|
104
|
+
if (this.getState() === INIT) {
|
|
105
|
+
this.state = PENDING;
|
|
106
|
+
this.beginStartedTime = now;
|
|
107
|
+
return this.animationBegin;
|
|
108
|
+
}
|
|
109
|
+
if (this.getState() === PENDING) {
|
|
110
|
+
if (this.beginStartedTime == null) {
|
|
111
|
+
throw new Error();
|
|
112
|
+
}
|
|
113
|
+
var _timeElapsed = now - this.beginStartedTime;
|
|
114
|
+
if (_timeElapsed >= this.animationBegin) {
|
|
115
|
+
this.state = ACTIVE;
|
|
116
|
+
this.animationStartedTime = now;
|
|
117
|
+
// The state flipped just now so the elapsed time is zero
|
|
118
|
+
return this.nextAnimationUpdate(0);
|
|
119
|
+
}
|
|
120
|
+
return duration(this.animationBegin - _timeElapsed);
|
|
121
|
+
}
|
|
122
|
+
if (this.getState() === ACTIVE) {
|
|
123
|
+
if (this.animationStartedTime == null) {
|
|
124
|
+
throw new Error();
|
|
125
|
+
}
|
|
126
|
+
var _timeElapsed2 = now - this.animationStartedTime;
|
|
127
|
+
this.setProgress(_timeElapsed2 / this.animationDuration);
|
|
128
|
+
return this.nextAnimationUpdate(_timeElapsed2);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// state === COMPLETED, nothing interesting is going to happen
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
setProgress(newProgress) {
|
|
135
|
+
this.progress = Math.min(1, Math.max(0, newProgress));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns an abstract "progress" which is number between 0 and 1 which shows the distance of transition.
|
|
140
|
+
* This progress depends on the animation state:
|
|
141
|
+
* - `init`: 0
|
|
142
|
+
* - `pending`: 0
|
|
143
|
+
* - `active`: transitioning between [0, 1] based on the time elapsed
|
|
144
|
+
* - `completed`: 1
|
|
145
|
+
*
|
|
146
|
+
* The progress is hard-capped to be between 0 and 1 (inclusive) to avoid overshooting caused by coarse timers.
|
|
147
|
+
* For this reason, the easing function must be applied _after_ this animation state,
|
|
148
|
+
* so that one has a chance to construct dynamic "overshoot" animations.
|
|
149
|
+
*
|
|
150
|
+
* The progress is linear with time.
|
|
151
|
+
* If you wish for easing, use `getInterpolated()` instead.
|
|
152
|
+
*/
|
|
153
|
+
getProgress() {
|
|
154
|
+
return this.progress;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Completes the animation. Completed animation:
|
|
159
|
+
* - cannot be manipulated anymore
|
|
160
|
+
* - its progress is set to 1
|
|
161
|
+
* - tick function doesn't do anything
|
|
162
|
+
* - getState() always returns 'completed'
|
|
163
|
+
*/
|
|
164
|
+
complete() {
|
|
165
|
+
this.progress = 1;
|
|
166
|
+
if (this.state === 'active') {
|
|
167
|
+
var _this$onAnimationEnd;
|
|
168
|
+
// Do not call callbacks if the animation was interrupted before it even started!
|
|
169
|
+
(_this$onAnimationEnd = this.onAnimationEnd) === null ||
|
|
170
|
+
_this$onAnimationEnd === void 0 ||
|
|
171
|
+
_this$onAnimationEnd.call(this);
|
|
172
|
+
}
|
|
173
|
+
this.state = COMPLETED;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Returns the starting value of the animation.
|
|
178
|
+
* Does not include progress, easing, interpolation, none of that - just the static starting value
|
|
179
|
+
*/
|
|
180
|
+
getFrom() {
|
|
181
|
+
return this.from;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns the end value of the animation.
|
|
186
|
+
* Does not include progress, easing, interpolation, none of that - just the static end value
|
|
187
|
+
*/
|
|
188
|
+
getTo() {
|
|
189
|
+
return this.to;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Unique identifier of an animation
|
|
194
|
+
*/
|
|
195
|
+
getAnimationId() {
|
|
196
|
+
return this.animationId;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Returns the configuration - the duration of delay in between animation initialization, and transition.
|
|
201
|
+
* Does not change in time, does not change when state changes, this is a static value.
|
|
202
|
+
*/
|
|
203
|
+
getAnimationBegin() {
|
|
204
|
+
return this.animationBegin;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns value of the transition at the current time.
|
|
209
|
+
* The exact details differ based on the animation type
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Returns the duration of time of when the controller should ask for the next update
|
|
214
|
+
*/
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Animation handle representing a Javascript-based animation.
|
|
219
|
+
* This animation requires one render cycle for each frame, and it calls setTimeout as quickly as possible
|
|
220
|
+
*
|
|
221
|
+
* @since 3.9
|
|
222
|
+
*/
|
|
223
|
+
export class JavascriptAnimation extends RechartsAnimation {
|
|
224
|
+
// eslint-disable-next-line class-methods-use-this
|
|
225
|
+
nextAnimationUpdate() {
|
|
226
|
+
/*
|
|
227
|
+
* JavaScript-based animations have to update as soon as possible,
|
|
228
|
+
* so we return 0 here to indicate that the next update should be scheduled immediately
|
|
229
|
+
* and it should trigger render on every occasion.
|
|
230
|
+
*/
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Returns value of the animation after its easing function had been applied.
|
|
236
|
+
* This value, unlike getProgress(), can escape the [0..1] range
|
|
237
|
+
* because this is entirely within the easing function control. Spring typically does this.
|
|
238
|
+
*/
|
|
239
|
+
getInterpolated() {
|
|
240
|
+
return this.easing(interpolate(this.getFrom(), this.getTo(), this.getProgress()));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Animation handle representing a CSS transition.
|
|
246
|
+
* This animation requires only one render, and the actual transition is then handled by the browser.
|
|
247
|
+
*
|
|
248
|
+
* @since 3.9
|
|
249
|
+
*/
|
|
250
|
+
export class CSSTransitionAnimation extends RechartsAnimation {
|
|
251
|
+
nextAnimationUpdate(timeElapsed) {
|
|
252
|
+
/**
|
|
253
|
+
* CSS transitions do not need DOM updates past the initial render
|
|
254
|
+
* so here we just instruct the controller to wait until the animation duration is over.
|
|
255
|
+
*/
|
|
256
|
+
return duration(this.animationDuration - timeElapsed);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Returns the final value of the animation (the `to`).
|
|
261
|
+
*
|
|
262
|
+
* CSS transitions leave both interpolation and easing to the browser,
|
|
263
|
+
* so all we need to do here is return the final state
|
|
264
|
+
* and let browser handle the rest.
|
|
265
|
+
*/
|
|
266
|
+
getInterpolated() {
|
|
267
|
+
return this.getTo();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Recharts animation state machine.
|
|
273
|
+
*
|
|
274
|
+
* Possible transitions are:
|
|
275
|
+
* - `init`: starting state - `onAnimationStart` executes
|
|
276
|
+
* - `init` to `pending` - `animationBegin` duration begins
|
|
277
|
+
* - `pending` to `active` - `animationDuration` duration begins, timer ticks decide the progress
|
|
278
|
+
* - `active` to `completed` - `onAnimationEnd` executes
|
|
279
|
+
*
|
|
280
|
+
* The state always moves in this direction, cannot move backwards.
|
|
281
|
+
*
|
|
282
|
+
* The animation queue is static and consists of four elements:
|
|
283
|
+
* - `onAnimationStart`: function that is called when the animation is created
|
|
284
|
+
* - `animationBegin`: delay between `onAnimationStart` and the transition
|
|
285
|
+
* - the transition itself, takes `animationDuration` ms to finish
|
|
286
|
+
* - `onAnimationEnd`: function that is called when the animation is moving from `active` to `completed`
|
|
287
|
+
*
|
|
288
|
+
* @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
|
|
289
|
+
*
|
|
290
|
+
* @since 3.9
|
|
291
|
+
*/
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Port of animation/JavascriptAnimate.tsx — the render-prop animation driver:
|
|
2
|
+
// `children(t)` with t progressing 0→1 through the (vendored) animation core.
|
|
3
|
+
// `isActive={false}` renders a single synchronous `children(1)` — the static
|
|
4
|
+
// path Phases 0–4 ride; the live rAF path works through the same vendored
|
|
5
|
+
// controller.
|
|
6
|
+
import { useEffect, useState } from 'octane';
|
|
7
|
+
import { noop } from '../util/DataUtils';
|
|
8
|
+
import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|
9
|
+
import { createEasingFunction } from './easing';
|
|
10
|
+
import { useAnimationController } from './useAnimationController.ts';
|
|
11
|
+
import { Global } from '../util/Global';
|
|
12
|
+
import { usePrefersReducedMotion } from '../util/usePrefersReducedMotion.ts';
|
|
13
|
+
import { JavascriptAnimation } from './AnimationHandle';
|
|
14
|
+
import { RequestAnimationFrameTimeoutController } from './timeoutController';
|
|
15
|
+
|
|
16
|
+
const defaultJavascriptAnimateProps = {
|
|
17
|
+
begin: 0,
|
|
18
|
+
duration: 1000,
|
|
19
|
+
easing: 'ease',
|
|
20
|
+
isActive: true,
|
|
21
|
+
canBegin: true,
|
|
22
|
+
onAnimationEnd: () => {},
|
|
23
|
+
onAnimationStart: () => {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const from = 0;
|
|
27
|
+
const to = 1;
|
|
28
|
+
|
|
29
|
+
export function JavascriptAnimate(outsideProps) {
|
|
30
|
+
const props = resolveDefaultProps(outsideProps, defaultJavascriptAnimateProps);
|
|
31
|
+
const {
|
|
32
|
+
animationId,
|
|
33
|
+
isActive: isActiveProp,
|
|
34
|
+
canBegin,
|
|
35
|
+
duration,
|
|
36
|
+
easing,
|
|
37
|
+
begin,
|
|
38
|
+
onAnimationEnd,
|
|
39
|
+
onAnimationStart,
|
|
40
|
+
children,
|
|
41
|
+
} = props;
|
|
42
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
43
|
+
const isActive =
|
|
44
|
+
isActiveProp === 'auto' ? !Global.isSsr && !prefersReducedMotion : isActiveProp;
|
|
45
|
+
const animationController = useAnimationController(props.animationController);
|
|
46
|
+
const [style, setStyle] = useState(isActive ? from : to);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!isActive) {
|
|
49
|
+
setStyle(to);
|
|
50
|
+
}
|
|
51
|
+
}, [isActive]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const easingFunction = createEasingFunction(easing);
|
|
54
|
+
if (!isActive || !canBegin || easingFunction == null) {
|
|
55
|
+
return noop;
|
|
56
|
+
}
|
|
57
|
+
const timeoutController = new RequestAnimationFrameTimeoutController();
|
|
58
|
+
const animation = new JavascriptAnimation({
|
|
59
|
+
animationId,
|
|
60
|
+
easing: easingFunction,
|
|
61
|
+
animationDuration: duration,
|
|
62
|
+
animationBegin: begin,
|
|
63
|
+
onAnimationStart,
|
|
64
|
+
onAnimationEnd,
|
|
65
|
+
from,
|
|
66
|
+
to,
|
|
67
|
+
});
|
|
68
|
+
return animationController(timeoutController, animation, setStyle);
|
|
69
|
+
}, [
|
|
70
|
+
animationController,
|
|
71
|
+
animationId,
|
|
72
|
+
isActive,
|
|
73
|
+
canBegin,
|
|
74
|
+
duration,
|
|
75
|
+
easing,
|
|
76
|
+
begin,
|
|
77
|
+
onAnimationStart,
|
|
78
|
+
onAnimationEnd,
|
|
79
|
+
]);
|
|
80
|
+
return children(Number(style));
|
|
81
|
+
}
|