@octanejs/recharts 0.1.41 → 0.1.42

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.
Files changed (375) hide show
  1. package/{LICENSE → LICENSE.recharts} +3 -2
  2. package/README.md +12 -0
  3. package/package.json +10 -9
  4. package/src/animation/AnimatedItems.tsrx +36 -3
  5. package/src/animation/AnimationController.ts +17 -65
  6. package/src/animation/{AnimationControllerImpl.js → AnimationControllerImpl.ts} +19 -12
  7. package/src/animation/{AnimationHandle.js → AnimationHandle.ts} +82 -65
  8. package/src/animation/CSSTransitionAnimate.tsrx +3 -2
  9. package/src/animation/JavascriptAnimate.tsrx +18 -2
  10. package/src/animation/easing.ts +235 -0
  11. package/src/animation/{matchBy.js → matchBy.ts} +76 -120
  12. package/src/animation/timeoutController.ts +71 -0
  13. package/src/animation/useAnimationController.ts +4 -1
  14. package/src/animation/useAnimationStartSnapshot.ts +3 -3
  15. package/src/animation/util.ts +12 -0
  16. package/src/cartesian/Area.tsrx +33 -31
  17. package/src/cartesian/AreaRevealShape.tsrx +4 -3
  18. package/src/cartesian/Bar.ts +1 -0
  19. package/src/cartesian/Bar.tsrx +293 -39
  20. package/src/cartesian/BarStack.tsrx +31 -9
  21. package/src/cartesian/CartesianAxis.tsrx +154 -22
  22. package/src/cartesian/CartesianGrid.tsrx +5 -6
  23. package/src/cartesian/ErrorBar.tsrx +9 -8
  24. package/src/cartesian/Funnel.tsrx +40 -37
  25. package/src/cartesian/GraphicalItemClipPath.tsrx +11 -4
  26. package/src/cartesian/Line.ts +1 -0
  27. package/src/cartesian/Line.tsrx +206 -28
  28. package/src/cartesian/LineDrawShape.tsrx +23 -10
  29. package/src/cartesian/ReferenceLine.tsrx +8 -8
  30. package/src/cartesian/Scatter.tsrx +61 -66
  31. package/src/cartesian/XAxis.tsrx +78 -9
  32. package/src/cartesian/YAxis.tsrx +85 -12
  33. package/src/cartesian/getCartesianPosition.ts +265 -0
  34. package/src/cartesian/getEquidistantTicks.ts +144 -0
  35. package/src/cartesian/getTicks.ts +221 -0
  36. package/src/chart/AreaChart.tsrx +5 -1
  37. package/src/chart/BarChart.tsrx +8 -2
  38. package/src/chart/CartesianChart.tsrx +17 -4
  39. package/src/chart/CategoricalChart.tsrx +4 -1
  40. package/src/chart/ComposedChart.tsrx +5 -1
  41. package/src/chart/FunnelChart.tsrx +5 -1
  42. package/src/chart/LineChart.tsrx +8 -2
  43. package/src/chart/PieChart.tsrx +6 -2
  44. package/src/chart/PolarChart.tsrx +5 -4
  45. package/src/chart/RadarChart.tsrx +6 -2
  46. package/src/chart/RadialBarChart.tsrx +6 -2
  47. package/src/chart/RechartsWrapper.tsrx +57 -21
  48. package/src/chart/Sankey.tsrx +89 -91
  49. package/src/chart/ScatterChart.tsrx +5 -1
  50. package/src/chart/SunburstChart.tsrx +21 -14
  51. package/src/chart/types.ts +0 -1
  52. package/src/component/ActivePoints.tsrx +30 -5
  53. package/src/component/Cell.ts +19 -1
  54. package/src/component/Cursor.tsrx +11 -10
  55. package/src/component/DefaultLegendContent.tsrx +15 -10
  56. package/src/component/DefaultTooltipContent.tsrx +11 -9
  57. package/src/component/Dots.tsrx +37 -6
  58. package/src/component/Label.tsrx +99 -19
  59. package/src/component/LabelList.tsrx +54 -5
  60. package/src/component/Legend.tsrx +9 -5
  61. package/src/component/ResponsiveContainer.tsrx +13 -10
  62. package/src/component/Text.tsrx +95 -32
  63. package/src/component/Tooltip.tsrx +11 -10
  64. package/src/component/TooltipBoundingBox.tsrx +4 -5
  65. package/src/component/{responsiveContainerUtils.js → responsiveContainerUtils.ts} +59 -36
  66. package/src/container/ClipPathProvider.tsrx +6 -2
  67. package/src/container/Layer.tsrx +8 -1
  68. package/src/container/RootSurface.tsrx +15 -4
  69. package/src/container/Surface.tsrx +15 -1
  70. package/src/context/CellsContext.ts +6 -5
  71. package/src/context/ErrorBarContext.tsrx +23 -4
  72. package/src/context/RegisterGraphicalItemId.tsrx +10 -2
  73. package/src/context/accessibilityContext.ts +5 -0
  74. package/src/context/brushUpdateContext.ts +11 -0
  75. package/src/context/chartDataContext.ts +5 -4
  76. package/src/context/chartLayoutContext.ts +22 -8
  77. package/src/context/legendPayloadContext.tsrx +1 -1
  78. package/src/context/tooltipContext.ts +83 -0
  79. package/src/{hooks.js → hooks.ts} +88 -66
  80. package/src/index.ts +37 -37
  81. package/src/legacy-props.ts +129 -0
  82. package/src/polar/Pie.tsrx +91 -69
  83. package/src/polar/PolarAngleAxis.tsrx +47 -47
  84. package/src/polar/PolarGrid.tsrx +7 -6
  85. package/src/polar/PolarRadiusAxis.tsrx +29 -21
  86. package/src/polar/Radar.tsrx +26 -19
  87. package/src/polar/RadialBar.tsrx +59 -42
  88. package/src/polar/{defaultPolarAngleAxisProps.js → defaultPolarAngleAxisProps.ts} +6 -6
  89. package/src/polar/{defaultPolarRadiusAxisProps.js → defaultPolarRadiusAxisProps.ts} +5 -4
  90. package/src/shape/Cross.tsrx +14 -2
  91. package/src/shape/Curve.tsrx +111 -23
  92. package/src/shape/Dot.tsrx +12 -1
  93. package/src/shape/Polygon.tsrx +28 -6
  94. package/src/shape/Rectangle.tsrx +30 -3
  95. package/src/shape/Sector.tsrx +48 -6
  96. package/src/shape/Symbols.tsrx +24 -6
  97. package/src/shape/Trapezoid.tsrx +33 -3
  98. package/src/state/RechartsStoreProvider.tsrx +11 -2
  99. package/src/state/ReportChartProps.ts +2 -2
  100. package/src/state/ReportMainChartProps.ts +2 -1
  101. package/src/state/SetGraphicalItem.ts +6 -4
  102. package/src/state/SetLegendPayload.ts +7 -4
  103. package/src/state/SetTooltipEntrySettings.ts +5 -2
  104. package/src/state/brushSlice.ts +40 -0
  105. package/src/state/cartesianAxisSlice.ts +291 -0
  106. package/src/state/chartDataSlice.ts +87 -0
  107. package/src/state/errorBarSlice.ts +78 -0
  108. package/src/state/eventSettingsSlice.ts +30 -0
  109. package/src/state/{externalEventsMiddleware.js → externalEventsMiddleware.ts} +55 -34
  110. package/src/state/graphicalItemsSlice.ts +180 -0
  111. package/src/state/{keyboardEventsMiddleware.js → keyboardEventsMiddleware.ts} +72 -57
  112. package/src/state/layoutSlice.ts +50 -0
  113. package/src/state/legendSlice.ts +109 -0
  114. package/src/state/{mouseEventsMiddleware.js → mouseEventsMiddleware.ts} +45 -35
  115. package/src/state/optionsSlice.ts +65 -0
  116. package/src/state/polarAxisSlice.ts +42 -0
  117. package/src/state/polarOptionsSlice.ts +43 -0
  118. package/src/state/reduxDevtoolsJsonStringifyReplacer.ts +13 -0
  119. package/src/state/referenceElementsSlice.ts +100 -0
  120. package/src/state/renderedTicksSlice.ts +60 -0
  121. package/src/state/rootPropsSlice.ts +72 -0
  122. package/src/state/selectors/areaSelectors.ts +1 -2
  123. package/src/state/selectors/{arrayEqualityCheck.js → arrayEqualityCheck.ts} +4 -5
  124. package/src/state/selectors/axisSelectors.ts +2502 -0
  125. package/src/state/selectors/barSelectors.ts +373 -0
  126. package/src/state/selectors/barStackSelectors.ts +99 -0
  127. package/src/state/selectors/brushSelectors.ts +28 -0
  128. package/src/state/selectors/combiners/combineActiveLabel.ts +16 -0
  129. package/src/state/selectors/combiners/{combineActiveTooltipIndex.js → combineActiveTooltipIndex.ts} +45 -23
  130. package/src/state/selectors/combiners/combineAllBarPositions.ts +130 -0
  131. package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +16 -0
  132. package/src/state/selectors/combiners/combineBarPosition.ts +23 -0
  133. package/src/state/selectors/combiners/combineBarSizeList.ts +79 -0
  134. package/src/state/selectors/combiners/{combineCheckedDomain.js → combineCheckedDomain.ts} +9 -6
  135. package/src/state/selectors/combiners/combineConfiguredScale.ts +100 -0
  136. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +46 -0
  137. package/src/state/selectors/combiners/{combineDisplayedStackedData.js → combineDisplayedStackedData.ts} +23 -19
  138. package/src/state/selectors/combiners/combineInverseScaleFunction.ts +16 -0
  139. package/src/state/selectors/combiners/{combineRealScaleType.js → combineRealScaleType.ts} +16 -8
  140. package/src/state/selectors/combiners/combineStackedData.ts +27 -0
  141. package/src/state/selectors/combiners/combineTooltipInteractionState.ts +86 -0
  142. package/src/state/selectors/combiners/combineTooltipPayload.ts +201 -0
  143. package/src/state/selectors/combiners/{combineTooltipPayloadConfigurations.js → combineTooltipPayloadConfigurations.ts} +17 -18
  144. package/src/state/selectors/containerSelectors.ts +12 -0
  145. package/src/state/selectors/{dataSelectors.js → dataSelectors.ts} +43 -41
  146. package/src/state/selectors/funnelSelectors.ts +5 -5
  147. package/src/state/selectors/graphicalItemSelectors.ts +22 -0
  148. package/src/state/selectors/legendSelectors.ts +25 -0
  149. package/src/state/selectors/lineSelectors.ts +159 -0
  150. package/src/state/selectors/numberDomainEqualityCheck.ts +15 -0
  151. package/src/state/selectors/pickAxisId.ts +6 -0
  152. package/src/state/selectors/pickAxisType.ts +4 -0
  153. package/src/state/selectors/pieSelectors.ts +14 -13
  154. package/src/state/selectors/polarAxisSelectors.ts +223 -0
  155. package/src/state/selectors/polarSelectors.ts +1 -1
  156. package/src/state/selectors/radarSelectors.ts +1 -1
  157. package/src/state/selectors/radialBarSelectors.ts +17 -16
  158. package/src/state/selectors/rootPropsSelectors.ts +26 -0
  159. package/src/state/selectors/scatterSelectors.ts +11 -10
  160. package/src/state/selectors/{selectActivePropsFromChartPointer.js → selectActivePropsFromChartPointer.ts} +11 -4
  161. package/src/state/selectors/selectAllAxes.ts +20 -0
  162. package/src/state/selectors/selectChartOffset.ts +17 -0
  163. package/src/state/selectors/selectChartOffsetInternal.ts +147 -0
  164. package/src/state/selectors/{selectPlotArea.js → selectPlotArea.ts} +4 -3
  165. package/src/state/selectors/selectTooltipAxisId.ts +6 -0
  166. package/src/state/selectors/{selectTooltipAxisType.js → selectTooltipAxisType.ts} +10 -4
  167. package/src/state/selectors/selectTooltipEventType.ts +39 -0
  168. package/src/state/selectors/selectTooltipPayloadSearcher.ts +6 -0
  169. package/src/state/selectors/selectTooltipSettings.ts +6 -0
  170. package/src/state/selectors/selectTooltipState.ts +5 -0
  171. package/src/state/selectors/selectors.ts +315 -0
  172. package/src/state/selectors/tooltipSelectors.ts +611 -0
  173. package/src/state/selectors/touchSelectors.ts +52 -0
  174. package/src/state/{store.js → store.ts} +46 -36
  175. package/src/state/tooltipSlice.ts +507 -0
  176. package/src/state/{touchEventsMiddleware.js → touchEventsMiddleware.ts} +54 -42
  177. package/src/state/types/AreaSettings.ts +15 -0
  178. package/src/state/types/BarSettings.ts +15 -0
  179. package/src/state/types/LineSettings.ts +10 -0
  180. package/src/state/types/PieSettings.ts +32 -0
  181. package/src/state/types/RadarSettings.ts +6 -0
  182. package/src/state/types/RadialBarSettings.ts +10 -0
  183. package/src/state/types/ScatterSettings.ts +13 -0
  184. package/src/state/types/StackedGraphicalItem.ts +34 -0
  185. package/src/state/zIndexSlice.ts +137 -0
  186. package/src/synchronisation/syncSelectors.ts +7 -0
  187. package/src/synchronisation/types.ts +42 -0
  188. package/src/synchronisation/useChartSynchronisation.tsrx +26 -11
  189. package/src/types.ts +55 -0
  190. package/src/util/ActiveShapeUtils.tsrx +34 -10
  191. package/src/util/BarUtils.tsrx +43 -3
  192. package/src/util/{CartesianUtils.js → CartesianUtils.ts} +22 -39
  193. package/src/util/ChartUtils.ts +759 -0
  194. package/src/util/{Constants.js → Constants.ts} +6 -6
  195. package/src/util/DOMUtils.ts +135 -0
  196. package/src/util/{DataUtils.js → DataUtils.ts} +120 -47
  197. package/src/util/Events.ts +22 -0
  198. package/src/util/FunnelUtils.tsrx +3 -3
  199. package/src/util/Global.ts +13 -0
  200. package/src/util/IfOverflow.ts +16 -0
  201. package/src/util/LRUCache.ts +42 -0
  202. package/src/util/{LogUtils.js → LogUtils.ts} +7 -12
  203. package/src/util/OctaneTypes.ts +51 -0
  204. package/src/util/PolarUtils.ts +132 -0
  205. package/src/util/RadialBarUtils.tsrx +3 -3
  206. package/src/util/ReduceCSSCalc.ts +186 -0
  207. package/src/util/ScatterUtils.tsrx +9 -7
  208. package/src/util/{TickUtils.js → TickUtils.ts} +30 -13
  209. package/src/util/{YAxisUtils.js → YAxisUtils.ts} +27 -17
  210. package/src/util/axisPropsAreEqual.ts +49 -0
  211. package/src/util/createEventProxy.ts +20 -0
  212. package/src/util/{excludeEventProps.js → excludeEventProps.ts} +8 -6
  213. package/src/util/getActiveCoordinate.ts +210 -0
  214. package/src/util/{getAxisTypeBasedOnLayout.js → getAxisTypeBasedOnLayout.ts} +7 -3
  215. package/src/util/getClassNameFromUnknown.ts +7 -0
  216. package/src/util/{getEveryNth.js → getEveryNth.ts} +5 -6
  217. package/src/util/getRadiusAndStrokeWidthFromDot.ts +31 -0
  218. package/src/util/{getRelativeCoordinate.js → getRelativeCoordinate.ts} +26 -9
  219. package/src/util/getSliced.ts +14 -0
  220. package/src/util/{isDomainSpecifiedByUser.js → isDomainSpecifiedByUser.ts} +46 -100
  221. package/src/util/isWellBehavedNumber.ts +8 -0
  222. package/src/util/payload/getUniqPayload.ts +1 -1
  223. package/src/util/{propsAreEqual.js → propsAreEqual.ts} +10 -8
  224. package/src/util/{resolveDefaultProps.js → resolveDefaultProps.ts} +35 -57
  225. package/src/util/round.ts +33 -0
  226. package/src/util/scale/CustomScaleDefinition.ts +82 -0
  227. package/src/util/scale/RechartsScale.ts +131 -0
  228. package/src/util/scale/{createCategoricalInverse.js → createCategoricalInverse.ts} +24 -29
  229. package/src/util/scale/{getNiceTickValues.js → getNiceTickValues.ts} +125 -146
  230. package/src/util/scale/index.ts +2 -0
  231. package/src/util/scale/util/{arithmetic.js → arithmetic.ts} +12 -8
  232. package/src/util/stacks/getStackSeriesIdentifier.ts +21 -0
  233. package/src/util/stacks/stackTypes.ts +58 -0
  234. package/src/util/{svgPropertiesNoEvents.js → svgPropertiesNoEvents.ts} +52 -27
  235. package/src/util/tooltip/translate.ts +2 -1
  236. package/src/util/typedDataKey.ts +49 -0
  237. package/src/util/types.ts +1265 -7
  238. package/src/util/{useUniqueId.js → useUniqueId.ts} +9 -5
  239. package/src/zIndex/{DefaultZIndexes.js → DefaultZIndexes.ts} +13 -4
  240. package/src/zIndex/ZIndexLayer.tsrx +13 -4
  241. package/src/zIndex/ZIndexPortal.tsrx +14 -4
  242. package/src/zIndex/{getZIndexFromUnknown.js → getZIndexFromUnknown.ts} +3 -3
  243. package/src/zIndex/{zIndexSelectors.js → zIndexSelectors.ts} +17 -11
  244. package/src/animation/easing.js +0 -193
  245. package/src/animation/timeoutController.js +0 -49
  246. package/src/animation/util.js +0 -11
  247. package/src/cartesian/Area.tsrx.d.ts +0 -340
  248. package/src/cartesian/Bar.tsrx.d.ts +0 -4
  249. package/src/cartesian/BarStack.tsrx.d.ts +0 -6
  250. package/src/cartesian/CartesianAxis.tsrx.d.ts +0 -3
  251. package/src/cartesian/CartesianGrid.tsrx.d.ts +0 -219
  252. package/src/cartesian/ErrorBar.tsrx.d.ts +0 -131
  253. package/src/cartesian/Funnel.tsrx.d.ts +0 -274
  254. package/src/cartesian/Line.tsrx.d.ts +0 -4
  255. package/src/cartesian/LineDrawShape.tsrx.d.ts +0 -2
  256. package/src/cartesian/ReferenceLine.tsrx.d.ts +0 -178
  257. package/src/cartesian/Scatter.tsrx.d.ts +0 -351
  258. package/src/cartesian/XAxis.tsrx.d.ts +0 -3
  259. package/src/cartesian/YAxis.tsrx.d.ts +0 -3
  260. package/src/cartesian/ZAxis.tsrx.d.ts +0 -102
  261. package/src/cartesian/getCartesianPosition.js +0 -277
  262. package/src/cartesian/getEquidistantTicks.js +0 -133
  263. package/src/cartesian/getTicks.js +0 -280
  264. package/src/chart/AreaChart.tsrx.d.ts +0 -12
  265. package/src/chart/BarChart.tsrx.d.ts +0 -2
  266. package/src/chart/CartesianChart.tsrx.d.ts +0 -10
  267. package/src/chart/ComposedChart.tsrx.d.ts +0 -12
  268. package/src/chart/FunnelChart.tsrx.d.ts +0 -12
  269. package/src/chart/LineChart.tsrx.d.ts +0 -2
  270. package/src/chart/PieChart.tsrx.d.ts +0 -31
  271. package/src/chart/RadarChart.tsrx.d.ts +0 -31
  272. package/src/chart/RadialBarChart.tsrx.d.ts +0 -31
  273. package/src/chart/Sankey.tsrx.d.ts +0 -253
  274. package/src/chart/ScatterChart.tsrx.d.ts +0 -12
  275. package/src/chart/SunburstChart.tsrx.d.ts +0 -146
  276. package/src/component/DefaultLegendContent.tsrx.d.ts +0 -125
  277. package/src/component/DefaultTooltipContent.tsrx.d.ts +0 -87
  278. package/src/component/Label.tsrx.d.ts +0 -12
  279. package/src/component/LabelList.tsrx.d.ts +0 -8
  280. package/src/component/Legend.tsrx.d.ts +0 -88
  281. package/src/component/ResponsiveContainer.tsrx.d.ts +0 -81
  282. package/src/component/Text.tsrx.d.ts +0 -9
  283. package/src/component/Tooltip.tsrx.d.ts +0 -246
  284. package/src/container/Layer.tsrx.d.ts +0 -6
  285. package/src/container/Surface.tsrx.d.ts +0 -12
  286. package/src/context/accessibilityContext.js +0 -10
  287. package/src/context/tooltipContext.js +0 -55
  288. package/src/index.d.ts +0 -281
  289. package/src/polar/Pie.tsrx.d.ts +0 -436
  290. package/src/polar/PolarAngleAxis.tsrx.d.ts +0 -215
  291. package/src/polar/PolarGrid.tsrx.d.ts +0 -117
  292. package/src/polar/PolarRadiusAxis.tsrx.d.ts +0 -209
  293. package/src/polar/Radar.tsrx.d.ts +0 -215
  294. package/src/polar/RadialBar.tsrx.d.ts +0 -340
  295. package/src/shape/Cross.tsrx.d.ts +0 -12
  296. package/src/shape/Curve.tsrx.d.ts +0 -42
  297. package/src/shape/Dot.tsrx.d.ts +0 -9
  298. package/src/shape/Polygon.tsrx.d.ts +0 -13
  299. package/src/shape/Rectangle.tsrx.d.ts +0 -31
  300. package/src/shape/Sector.tsrx.d.ts +0 -29
  301. package/src/shape/Symbols.tsrx.d.ts +0 -15
  302. package/src/shape/Trapezoid.tsrx.d.ts +0 -29
  303. package/src/state/brushSlice.js +0 -36
  304. package/src/state/cartesianAxisSlice.js +0 -256
  305. package/src/state/chartDataSlice.js +0 -67
  306. package/src/state/errorBarSlice.js +0 -53
  307. package/src/state/eventSettingsSlice.js +0 -25
  308. package/src/state/graphicalItemsSlice.js +0 -91
  309. package/src/state/layoutSlice.js +0 -57
  310. package/src/state/legendSlice.js +0 -83
  311. package/src/state/optionsSlice.js +0 -45
  312. package/src/state/polarAxisSlice.js +0 -33
  313. package/src/state/polarOptionsSlice.js +0 -26
  314. package/src/state/reduxDevtoolsJsonStringifyReplacer.js +0 -14
  315. package/src/state/referenceElementsSlice.js +0 -51
  316. package/src/state/renderedTicksSlice.js +0 -41
  317. package/src/state/rootPropsSlice.js +0 -48
  318. package/src/state/selectors/axisSelectors.js +0 -2113
  319. package/src/state/selectors/barSelectors.js +0 -263
  320. package/src/state/selectors/barStackSelectors.js +0 -65
  321. package/src/state/selectors/brushSelectors.js +0 -21
  322. package/src/state/selectors/combiners/combineActiveLabel.js +0 -18
  323. package/src/state/selectors/combiners/combineAllBarPositions.js +0 -169
  324. package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +0 -11
  325. package/src/state/selectors/combiners/combineBarPosition.js +0 -17
  326. package/src/state/selectors/combiners/combineBarSizeList.js +0 -115
  327. package/src/state/selectors/combiners/combineConfiguredScale.js +0 -46
  328. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +0 -48
  329. package/src/state/selectors/combiners/combineInverseScaleFunction.js +0 -12
  330. package/src/state/selectors/combiners/combineStackedData.js +0 -22
  331. package/src/state/selectors/combiners/combineTooltipInteractionState.js +0 -121
  332. package/src/state/selectors/combiners/combineTooltipPayload.js +0 -248
  333. package/src/state/selectors/containerSelectors.js +0 -6
  334. package/src/state/selectors/graphicalItemSelectors.js +0 -25
  335. package/src/state/selectors/legendSelectors.js +0 -18
  336. package/src/state/selectors/lineSelectors.js +0 -106
  337. package/src/state/selectors/numberDomainEqualityCheck.js +0 -11
  338. package/src/state/selectors/pickAxisId.js +0 -3
  339. package/src/state/selectors/pickAxisType.js +0 -3
  340. package/src/state/selectors/polarAxisSelectors.js +0 -237
  341. package/src/state/selectors/rootPropsSelectors.js +0 -13
  342. package/src/state/selectors/selectAllAxes.js +0 -15
  343. package/src/state/selectors/selectChartOffset.js +0 -12
  344. package/src/state/selectors/selectChartOffsetInternal.js +0 -174
  345. package/src/state/selectors/selectTooltipAxisId.js +0 -3
  346. package/src/state/selectors/selectTooltipEventType.js +0 -27
  347. package/src/state/selectors/selectTooltipPayloadSearcher.js +0 -3
  348. package/src/state/selectors/selectTooltipSettings.js +0 -3
  349. package/src/state/selectors/selectTooltipState.js +0 -3
  350. package/src/state/selectors/selectors.js +0 -222
  351. package/src/state/selectors/tooltipSelectors.js +0 -471
  352. package/src/state/selectors/touchSelectors.js +0 -31
  353. package/src/state/tooltipSlice.js +0 -237
  354. package/src/state/types/StackedGraphicalItem.js +0 -18
  355. package/src/state/zIndexSlice.js +0 -167
  356. package/src/synchronisation/syncSelectors.js +0 -5
  357. package/src/util/ChartUtils.js +0 -630
  358. package/src/util/DOMUtils.js +0 -180
  359. package/src/util/Events.js +0 -7
  360. package/src/util/Global.js +0 -13
  361. package/src/util/LRUCache.js +0 -58
  362. package/src/util/PolarUtils.js +0 -190
  363. package/src/util/ReduceCSSCalc.js +0 -260
  364. package/src/util/axisPropsAreEqual.js +0 -63
  365. package/src/util/createEventProxy.js +0 -18
  366. package/src/util/getActiveCoordinate.js +0 -253
  367. package/src/util/getClassNameFromUnknown.js +0 -8
  368. package/src/util/getRadiusAndStrokeWidthFromDot.js +0 -28
  369. package/src/util/getSliced.js +0 -11
  370. package/src/util/isWellBehavedNumber.js +0 -8
  371. package/src/util/round.js +0 -39
  372. package/src/util/scale/RechartsScale.js +0 -68
  373. package/src/util/scale/index.js +0 -3
  374. package/src/util/stacks/getStackSeriesIdentifier.js +0 -10
  375. package/src/zIndex/ZIndexLayer.tsrx.d.ts +0 -2
@@ -0,0 +1,235 @@
1
+ // Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
2
+ export const ACCURACY = 1e-4;
3
+
4
+ const cubicBezierFactor = (c1: number, c2: number) => [
5
+ 0,
6
+ 3 * c1,
7
+ 3 * c2 - 6 * c1,
8
+ 3 * c1 - 3 * c2 + 1,
9
+ ];
10
+
11
+ const evaluatePolynomial = (params: ReadonlyArray<number>, animationElapsedTime: number) =>
12
+ params.map((param, i) => param * animationElapsedTime ** i).reduce((pre, curr) => pre + curr);
13
+
14
+ const cubicBezier = (c1: number, c2: number) => (animationElapsedTime: number) => {
15
+ const params = cubicBezierFactor(c1, c2);
16
+
17
+ return evaluatePolynomial(params, animationElapsedTime);
18
+ };
19
+
20
+ const derivativeCubicBezier = (c1: number, c2: number) => (animationElapsedTime: number) => {
21
+ const params = cubicBezierFactor(c1, c2);
22
+ const newParams = [...params.map((param, i) => param * i).slice(1), 0];
23
+
24
+ return evaluatePolynomial(newParams, animationElapsedTime);
25
+ };
26
+
27
+ type CubicBezierTemplate = `cubic-bezier(${number},${number},${number},${number})`;
28
+
29
+ export type NamedBezier =
30
+ 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | CubicBezierTemplate;
31
+
32
+ type BezierInput = [NamedBezier] | [number, number, number, number];
33
+
34
+ export type BezierEasingFunction = {
35
+ isStepper: false;
36
+ (animationElapsedTime: number): number;
37
+ };
38
+
39
+ const parseCubicBezier = (easing: string): [number, number, number, number] | null => {
40
+ const easingParts = easing.split('(');
41
+ if (easingParts.length !== 2 || easingParts[0] !== 'cubic-bezier') {
42
+ return null;
43
+ }
44
+ const numbers = easingParts[1]?.split(')')[0]?.split(',');
45
+ if (numbers == null || numbers.length !== 4) {
46
+ return null;
47
+ }
48
+ const coords = numbers.map((x: string) => parseFloat(x));
49
+ return [coords[0]!, coords[1]!, coords[2]!, coords[3]!];
50
+ };
51
+
52
+ const getBezierCoordinates = (...args: BezierInput): [number, number, number, number] => {
53
+ if (args.length === 1) {
54
+ switch (args[0]) {
55
+ case 'linear':
56
+ return [0.0, 0.0, 1.0, 1.0];
57
+ case 'ease':
58
+ return [0.25, 0.1, 0.25, 1.0];
59
+ case 'ease-in':
60
+ return [0.42, 0.0, 1.0, 1.0];
61
+ case 'ease-out':
62
+ return [0.42, 0.0, 0.58, 1.0];
63
+ case 'ease-in-out':
64
+ return [0.0, 0.0, 0.58, 1.0];
65
+ default: {
66
+ const easing = parseCubicBezier(args[0]);
67
+ if (easing) {
68
+ return easing;
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ if (args.length === 4) {
75
+ return args;
76
+ }
77
+
78
+ // Fallback for invalid inputs. The previous implementation was buggy and would lead to NaN.
79
+ // Returning linear easing is a safe default.
80
+ return [0.0, 0.0, 1.0, 1.0];
81
+ };
82
+
83
+ const createBezierEasing = (
84
+ x1: number,
85
+ y1: number,
86
+ x2: number,
87
+ y2: number,
88
+ ): BezierEasingFunction => {
89
+ const curveX = cubicBezier(x1, x2);
90
+ const curveY = cubicBezier(y1, y2);
91
+ const derCurveX = derivativeCubicBezier(x1, x2);
92
+ const rangeValue = (value: number): number => {
93
+ if (value > 1) {
94
+ return 1;
95
+ }
96
+ if (value < 0) {
97
+ return 0;
98
+ }
99
+
100
+ return value;
101
+ };
102
+
103
+ const bezier = (_animationElapsedTime: number) => {
104
+ const animationElapsedTime = _animationElapsedTime > 1 ? 1 : _animationElapsedTime;
105
+ let x = animationElapsedTime;
106
+
107
+ for (let i = 0; i < 8; ++i) {
108
+ const evalT = curveX(x) - animationElapsedTime;
109
+ const derVal = derCurveX(x);
110
+
111
+ if (Math.abs(evalT - animationElapsedTime) < ACCURACY || derVal < ACCURACY) {
112
+ return curveY(x);
113
+ }
114
+
115
+ x = rangeValue(x - evalT / derVal);
116
+ }
117
+
118
+ return curveY(x);
119
+ };
120
+
121
+ bezier.isStepper = false as const;
122
+
123
+ return bezier;
124
+ };
125
+
126
+ // calculate cubic-bezier using Newton's method
127
+ export const configBezier = (...args: BezierInput): BezierEasingFunction => {
128
+ return createBezierEasing(...getBezierCoordinates(...args));
129
+ };
130
+
131
+ type SpringInput = {
132
+ /**
133
+ * The stiffness coefficient of the spring.
134
+ * Higher values create a more forceful, faster pull towards the target.
135
+ */
136
+ stiff?: number;
137
+ /**
138
+ * The damping coefficient (friction/resistance).
139
+ * Higher values reduce bounciness and stop oscillation sooner. Lower values create more bounce.
140
+ */
141
+ damping?: number;
142
+ /**
143
+ * The physics simulation time step in milliseconds.
144
+ * Determines the granularity of the baked frames. 16.67ms roughly equals a 60fps frame delta.
145
+ */
146
+ dt?: number;
147
+ };
148
+
149
+ /**
150
+ * Creates a performance-optimized, progress-based spring easing function.
151
+ * It pre-calculates ("bakes") spring physics frames upfront based on a fixed duration,
152
+ * then returns a pure, lightweight function mapping progress (0 to 1) to the animated position.
153
+ * This approach is ideal for low-power devices because it removes heavy physics math from the frame loop.
154
+ */
155
+ export const createSpringEasing = (config: SpringInput = {}): EasingFunction => {
156
+ const { stiff = 100, damping = 8, dt = 16.67 } = config;
157
+ const destX = 1;
158
+
159
+ const positions: number[] = [0];
160
+ let currX = 0;
161
+ let currV = 0;
162
+
163
+ // Safety valve to prevent accidental infinite loops if physics config is extreme
164
+ const maxIterations = 10000;
165
+ let iterations = 0;
166
+
167
+ // 1. Run the simulation until the spring completely stops moving
168
+ while (iterations < maxIterations) {
169
+ const FSpring = -(currX - destX) * stiff;
170
+ const FDamping = currV * damping;
171
+
172
+ currV += ((FSpring - FDamping) * dt) / 1000;
173
+ currX += (currV * dt) / 1000;
174
+
175
+ positions.push(currX);
176
+
177
+ // Stop only when position is essentially at 1.0 AND bounce velocity has died down
178
+ if (Math.abs(currX - destX) < ACCURACY && Math.abs(currV) < ACCURACY) {
179
+ break;
180
+ }
181
+ iterations++;
182
+ }
183
+
184
+ // Force the absolute final element to be exactly 1.0 for a perfect finish
185
+ positions[positions.length - 1] = destX;
186
+ const maxIndex = positions.length - 1;
187
+
188
+ // 2. The ultra-smooth runtime function mapping your 0..1 progress
189
+ return (t: number): number => {
190
+ if (t <= 0) return 0;
191
+ if (t >= 1) return destX;
192
+
193
+ // Scale t (0..1) proportionally across our entire pre-calculated array
194
+ const exactFrame = t * maxIndex;
195
+ const index = Math.floor(exactFrame);
196
+ const fraction = exactFrame - index;
197
+
198
+ // Blend between the two closest frames
199
+ return (
200
+ (positions[index] ?? 0) + ((positions[index + 1] ?? 0) - (positions[index] ?? 0)) * fraction
201
+ );
202
+ };
203
+ };
204
+
205
+ export type EasingFunction = (t: number) => number;
206
+
207
+ /**
208
+ * @inline
209
+ */
210
+ export type EasingInput = NamedBezier | 'spring' | EasingFunction;
211
+
212
+ export const createEasingFunction = (easing: EasingInput): EasingFunction | null => {
213
+ if (typeof easing === 'string') {
214
+ switch (easing) {
215
+ case 'ease':
216
+ case 'ease-in-out':
217
+ case 'ease-out':
218
+ case 'ease-in':
219
+ case 'linear':
220
+ return configBezier(easing);
221
+ case 'spring':
222
+ return createSpringEasing();
223
+ default:
224
+ if (easing.split('(')[0] === 'cubic-bezier') {
225
+ return configBezier(easing);
226
+ }
227
+ }
228
+ }
229
+
230
+ if (typeof easing === 'function') {
231
+ return easing;
232
+ }
233
+
234
+ return null;
235
+ };
@@ -1,68 +1,5 @@
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
- }
1
+ // Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
2
+ import { DataKey } from '../util/types';
66
3
  import { getValueByDataKey } from '../util/ChartUtils';
67
4
 
68
5
  /**
@@ -75,6 +12,10 @@ import { getValueByDataKey } from '../util/ChartUtils';
75
12
  * @since 3.9
76
13
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
77
14
  */
15
+ export type AnimationItem<T> =
16
+ | { readonly status: 'matched'; readonly prev: T; readonly next: T }
17
+ | { readonly status: 'added'; readonly next: T }
18
+ | { readonly status: 'removed'; readonly prev: T };
78
19
 
79
20
  /**
80
21
  * A function that extracts a key from an animation item for matching purposes.
@@ -88,6 +29,7 @@ import { getValueByDataKey } from '../util/ChartUtils';
88
29
  * @since 3.9
89
30
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
90
31
  */
32
+ export type AnimationMatchBy<T> = (item: T, index: number) => string | number | null;
91
33
 
92
34
  /**
93
35
  * The union of all accepted `animationMatchBy` prop values:
@@ -96,6 +38,8 @@ import { getValueByDataKey } from '../util/ChartUtils';
96
38
  * @since 3.9
97
39
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
98
40
  */
41
+ export type AnimationMatchByProp<T> =
42
+ typeof matchByIndex | typeof matchAppend | AnimationMatchBy<T>;
99
43
 
100
44
  /**
101
45
  * Match animation items by their array index (the default behavior).
@@ -112,7 +56,7 @@ import { getValueByDataKey } from '../util/ChartUtils';
112
56
  * @since 3.9
113
57
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
114
58
  */
115
- export var matchByIndex = 'index';
59
+ export const matchByIndex = 'index' as const;
116
60
 
117
61
  /**
118
62
  * Match animation items sequentially: previous item 0 pairs with next item 0,
@@ -130,7 +74,7 @@ export var matchByIndex = 'index';
130
74
  * @since 3.9
131
75
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
132
76
  */
133
- export var matchAppend = 'append';
77
+ export const matchAppend = 'append' as const;
134
78
 
135
79
  /**
136
80
  * Create a matching function that pairs items by a data key from their payload.
@@ -151,66 +95,74 @@ export var matchAppend = 'append';
151
95
  * @since 3.9
152
96
  * @see {@link https://recharts.github.io/en-US/guide/animations Animation guide}
153
97
  */
154
- export function matchByDataKey(dataKey) {
155
- return (item) => {
98
+ export function matchByDataKey(
99
+ dataKey: DataKey<Record<string, unknown>>,
100
+ ): AnimationMatchBy<{ payload?: unknown }> {
101
+ return (item: { payload?: unknown }): string | number | null => {
156
102
  if (item.payload == null || typeof item.payload !== 'object') return null;
157
- var value = getValueByDataKey(item.payload, dataKey);
103
+ const value = getValueByDataKey(item.payload as Record<string, unknown>, dataKey);
158
104
  if (value == null) return null;
159
105
  if (typeof value === 'string' || typeof value === 'number') return value;
160
106
  return JSON.stringify(value);
161
107
  };
162
108
  }
163
- function tagAlignedItems(alignedPrevItems, nextItems) {
164
- var removedPrevItems = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
165
- var tagged = [];
109
+
110
+ function tagAlignedItems<T>(
111
+ alignedPrevItems: ReadonlyArray<T | undefined>,
112
+ nextItems: ReadonlyArray<T>,
113
+ removedPrevItems: ReadonlyArray<T> = [],
114
+ ): ReadonlyArray<AnimationItem<T>> {
115
+ const tagged: AnimationItem<T>[] = [];
166
116
  /*
167
117
  * We put removed points at the start because we assume that a typical chart animates right-to-left
168
118
  * and the removed points will disappear from the left edge and outside the plot area.
169
119
  * If you chart behaves differently you may want to customize your matching function.
170
120
  */
171
- for (var prev of removedPrevItems) {
172
- tagged.push({
173
- status: 'removed',
174
- prev,
175
- });
121
+ for (const prev of removedPrevItems) {
122
+ tagged.push({ status: 'removed', prev });
176
123
  }
177
- for (var i = 0; i < nextItems.length; i++) {
124
+ for (let i = 0; i < nextItems.length; i++) {
178
125
  // This function intentionally pairs by array index. The strategy-specific functions above are
179
126
  // 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
- });
127
+ const prev = alignedPrevItems[i];
128
+ const next = nextItems[i]!;
129
+ if (prev != null) {
130
+ tagged.push({ status: 'matched', prev, next });
188
131
  } else {
189
- tagged.push({
190
- status: 'added',
191
- next,
192
- });
132
+ tagged.push({ status: 'added', next });
193
133
  }
194
134
  }
195
135
  return tagged;
196
136
  }
197
- function matchByIndexImpl(prevItems, nextItems) {
198
- var factor = prevItems.length / nextItems.length;
199
- var alignedPrevItems = nextItems.map((_, i) => prevItems[Math.floor(i * factor)]);
137
+
138
+ function matchByIndexImpl<T>(
139
+ prevItems: ReadonlyArray<T>,
140
+ nextItems: ReadonlyArray<T>,
141
+ ): ReadonlyArray<AnimationItem<T>> {
142
+ const factor = prevItems.length / nextItems.length;
143
+ const alignedPrevItems = nextItems.map((_, i) => prevItems[Math.floor(i * factor)]);
200
144
  return tagAlignedItems(alignedPrevItems, nextItems);
201
145
  }
202
- function matchAppendImpl(prevItems, nextItems) {
203
- var alignedPrevItems = nextItems.map((_, i) => prevItems[i]);
146
+
147
+ function matchAppendImpl<T>(
148
+ prevItems: ReadonlyArray<T>,
149
+ nextItems: ReadonlyArray<T>,
150
+ ): ReadonlyArray<AnimationItem<T>> {
151
+ const alignedPrevItems = nextItems.map((_, i) => prevItems[i]);
204
152
  return tagAlignedItems(alignedPrevItems, nextItems);
205
153
  }
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);
154
+
155
+ function buildPrevKeyMap<T>(
156
+ prevItems: ReadonlyArray<T>,
157
+ matchBy: AnimationMatchBy<T>,
158
+ ): ReadonlyMap<string | number, T> {
159
+ const prevMap = new Map<string | number, T>();
160
+ for (let i = 0; i < prevItems.length; i++) {
161
+ const item = prevItems[i];
162
+ if (item == null) continue;
163
+ const key = matchBy(item, i);
212
164
  if (key != null && !prevMap.has(key)) {
213
- prevMap.set(key, _item);
165
+ prevMap.set(key, item);
214
166
  }
215
167
  }
216
168
  return prevMap;
@@ -221,15 +173,20 @@ function buildPrevKeyMap(prevItems, matchBy) {
221
173
  *
222
174
  * @internal
223
175
  */
224
- function matchByKey(prevItems, nextItems, matchBy) {
225
- var prevMap = buildPrevKeyMap(prevItems, matchBy);
176
+ function matchByKey<T>(
177
+ prevItems: ReadonlyArray<T>,
178
+ nextItems: ReadonlyArray<T>,
179
+ matchBy: AnimationMatchBy<T>,
180
+ ): ReadonlyArray<AnimationItem<T>> {
181
+ const prevMap = buildPrevKeyMap(prevItems, matchBy);
226
182
 
227
183
  // Track which prev keys were matched
228
- var matchedKeys = new Set();
229
- var alignedPrevItems = nextItems.map((next, i) => {
230
- var key = matchBy(next, i);
184
+ const matchedKeys = new Set<string | number>();
185
+
186
+ const alignedPrevItems = nextItems.map((next, i) => {
187
+ const key = matchBy(next, i);
231
188
  if (key != null) {
232
- var prev = prevMap.get(key);
189
+ const prev = prevMap.get(key);
233
190
  if (prev !== undefined) {
234
191
  matchedKeys.add(key);
235
192
  return prev;
@@ -239,15 +196,13 @@ function matchByKey(prevItems, nextItems, matchBy) {
239
196
  });
240
197
 
241
198
  // 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];
199
+ const removedPrevItems: T[] = [];
200
+ for (const [key, item] of prevMap) {
247
201
  if (!matchedKeys.has(key)) {
248
- removedPrevItems.push(_item2);
202
+ removedPrevItems.push(item);
249
203
  }
250
204
  }
205
+
251
206
  return tagAlignedItems(alignedPrevItems, nextItems, removedPrevItems);
252
207
  }
253
208
 
@@ -259,15 +214,16 @@ function matchByKey(prevItems, nextItems, matchBy) {
259
214
  *
260
215
  * @internal
261
216
  */
262
- export function matchAnimationItems(prevItems, nextItems, matchBy) {
217
+ export function matchAnimationItems<T>(
218
+ prevItems: ReadonlyArray<T> | null,
219
+ nextItems: ReadonlyArray<T> | undefined,
220
+ matchBy: AnimationMatchByProp<T>,
221
+ ): ReadonlyArray<AnimationItem<T>> | null {
263
222
  if (nextItems == null) {
264
223
  return null;
265
224
  }
266
225
  if (prevItems == null) {
267
- return nextItems.map((next) => ({
268
- status: 'added',
269
- next,
270
- }));
226
+ return nextItems.map((next) => ({ status: 'added', next }));
271
227
  }
272
228
  if (matchBy === matchByIndex) {
273
229
  return matchByIndexImpl(prevItems, nextItems);
@@ -0,0 +1,71 @@
1
+ // Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
2
+ /**
3
+ * Callback type for the timeout function.
4
+ * Receives current time as an argument.
5
+ */
6
+ export type CallbackType = (now: number) => void;
7
+
8
+ /**
9
+ * A function that, when called, cancels the timeout.
10
+ *
11
+ * @since 3.9
12
+ */
13
+ export type CancelableTimeout = () => void;
14
+
15
+ /**
16
+ * TimeoutController is responsible for controlling the movement of time.
17
+ * Think of it as a clock.
18
+ *
19
+ * Recharts default implementation uses requestAnimationFrame which works great in a browser.
20
+ * You may choose to override this which is especially useful if you want to control animations.
21
+ *
22
+ * Why would you want to do this?
23
+ * - unit tests
24
+ * - animations based on something other than time: UI controls, page scroll, mouse movement ...
25
+ *
26
+ * @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
27
+ *
28
+ * @since 3.9
29
+ */
30
+ export interface TimeoutController {
31
+ /**
32
+ * Sets a timeout that executes a callback after a specified delay.
33
+ * Allows setting multiple timeouts and provides a way to cancel them independently.
34
+ *
35
+ * Note that this one function has two different time systems!
36
+ * The input (delay - parameter of setTimeout)
37
+ * - is relative
38
+ * - it means "wait for this long"
39
+ * -
40
+ *
41
+ * The output (now - parameter of the callback) is absolute; it means "this is the time now"
42
+ *
43
+ * @param callback - The function to execute after the delay. Receives the current absolute time in milliseconds as an argument.
44
+ * @param delay (optional) - The duration of time in milliseconds to wait before executing the callback. Defaults to 0.
45
+ */
46
+ setTimeout(callback: CallbackType, delay?: number): CancelableTimeout;
47
+ }
48
+
49
+ export class RequestAnimationFrameTimeoutController implements TimeoutController {
50
+ setTimeout(callback: CallbackType, delay: number = 0): CancelableTimeout {
51
+ const startTime = performance.now();
52
+
53
+ let requestId: number | null = null;
54
+
55
+ const executeCallback = (now: number): void => {
56
+ if (now - startTime >= delay) {
57
+ callback(now);
58
+ } else {
59
+ requestId = requestAnimationFrame(executeCallback);
60
+ }
61
+ };
62
+
63
+ requestId = requestAnimationFrame(executeCallback);
64
+
65
+ return () => {
66
+ if (requestId != null) {
67
+ cancelAnimationFrame(requestId);
68
+ }
69
+ };
70
+ }
71
+ }
@@ -3,6 +3,7 @@
3
3
  // requestAnimationFrame).
4
4
  import { createContext, useContext, useMemo } from 'octane';
5
5
  import { animationControllerImpl } from './AnimationControllerImpl';
6
+ import type { AnimationController } from './AnimationController';
6
7
 
7
8
  const AnimationControllerContext = createContext(animationControllerImpl);
8
9
 
@@ -13,7 +14,9 @@ const AnimationControllerContext = createContext(animationControllerImpl);
13
14
  */
14
15
  export const AnimationControllerProvider = AnimationControllerContext.Provider;
15
16
 
16
- export function useAnimationController(animationControllerFromProps: unknown) {
17
+ export function useAnimationController(
18
+ animationControllerFromProps?: AnimationController,
19
+ ): AnimationController {
17
20
  const animationControllerFromContext = useContext(AnimationControllerContext);
18
21
  return useMemo(
19
22
  () => animationControllerFromProps ?? animationControllerFromContext,
@@ -3,9 +3,9 @@
3
3
  // visible frame" ref is only writable after the new cycle's t=0 handshake.
4
4
  import { useCallback, useRef } from 'octane';
5
5
 
6
- export function useAnimationStartSnapshot(
6
+ export function useAnimationStartSnapshot<T>(
7
7
  animationInput: unknown,
8
- previousValueRef: { current: any },
8
+ previousValueRef: { current: T },
9
9
  ) {
10
10
  // Identity of the animation cycle currently being served.
11
11
  const previousAnimationInputRef = useRef(animationInput);
@@ -20,7 +20,7 @@ export function useAnimationStartSnapshot(
20
20
  isReadyToCommitRef.current = false;
21
21
  }
22
22
  const syncStepValue = useCallback(
23
- (stepValue: any, animationElapsedTime: number, canCommit = true) => {
23
+ (stepValue: T, animationElapsedTime: number, canCommit = true) => {
24
24
  if (animationElapsedTime === 0) {
25
25
  // t=0 handshake: the new animation has rendered its starting frame.
26
26
  isReadyToCommitRef.current = true;
@@ -0,0 +1,12 @@
1
+ // Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
2
+ /*
3
+ * @description: convert camel case to dash case
4
+ * string => string
5
+ */
6
+ export const getDashCase = (name: string) => name.replace(/([A-Z])/g, (v) => `-${v.toLowerCase()}`);
7
+
8
+ export const getTransitionVal = (
9
+ props: ReadonlyArray<string>,
10
+ duration: string | number,
11
+ easing: string,
12
+ ): string => props.map((prop) => `${getDashCase(prop)} ${duration}ms ${easing}`).join(',');