@solidports/recharts 0.1.0 → 0.1.1

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 (304) hide show
  1. package/dist/index.d.ts +40 -2
  2. package/dist/index.js +14238 -7174
  3. package/dist/{dev.js → index.jsx} +18367 -15900
  4. package/dist/server.js +48178 -0
  5. package/package.json +36 -19
  6. package/src/animation/AnimatedItems.tsx +0 -183
  7. package/src/animation/AnimationController.ts +0 -33
  8. package/src/animation/AnimationControllerImpl.ts +0 -36
  9. package/src/animation/AnimationHandle.ts +0 -307
  10. package/src/animation/CSSTransitionAnimate.tsx +0 -170
  11. package/src/animation/JavascriptAnimate.tsx +0 -119
  12. package/src/animation/easing.ts +0 -221
  13. package/src/animation/matchBy.ts +0 -164
  14. package/src/animation/timeoutController.ts +0 -70
  15. package/src/animation/useAnimationController.tsx +0 -34
  16. package/src/animation/useAnimationStartSnapshot.ts +0 -118
  17. package/src/animation/util.ts +0 -41
  18. package/src/cartesian/Area.tsx +0 -915
  19. package/src/cartesian/AreaRevealShape.tsx +0 -190
  20. package/src/cartesian/Bar.tsx +0 -1369
  21. package/src/cartesian/BarStack.tsx +0 -152
  22. package/src/cartesian/Brush.tsx +0 -951
  23. package/src/cartesian/CartesianAxis.tsx +0 -722
  24. package/src/cartesian/CartesianGrid.tsx +0 -711
  25. package/src/cartesian/ErrorBar.tsx +0 -361
  26. package/src/cartesian/Funnel.tsx +0 -803
  27. package/src/cartesian/GraphicalItemClipPath.tsx +0 -67
  28. package/src/cartesian/Line.tsx +0 -863
  29. package/src/cartesian/LineDrawShape.tsx +0 -89
  30. package/src/cartesian/ReferenceArea.tsx +0 -331
  31. package/src/cartesian/ReferenceDot.tsx +0 -304
  32. package/src/cartesian/ReferenceLine.tsx +0 -474
  33. package/src/cartesian/Scatter.tsx +0 -888
  34. package/src/cartesian/XAxis.tsx +0 -433
  35. package/src/cartesian/YAxis.tsx +0 -443
  36. package/src/cartesian/ZAxis.tsx +0 -155
  37. package/src/cartesian/cartesianPositionToCSSTranslate.tsx +0 -29
  38. package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +0 -21
  39. package/src/cartesian/getCartesianPosition.tsx +0 -267
  40. package/src/cartesian/getEquidistantTicks.ts +0 -144
  41. package/src/cartesian/getTicks.ts +0 -225
  42. package/src/cartesian/isOutsidePosition.ts +0 -15
  43. package/src/cartesian/useAnimatedLineLength.ts +0 -54
  44. package/src/chart/AreaChart.tsx +0 -29
  45. package/src/chart/BarChart.tsx +0 -29
  46. package/src/chart/CartesianChart.tsx +0 -131
  47. package/src/chart/CategoricalChart.tsx +0 -94
  48. package/src/chart/ComposedChart.tsx +0 -29
  49. package/src/chart/FunnelChart.tsx +0 -29
  50. package/src/chart/LineChart.tsx +0 -29
  51. package/src/chart/PieChart.tsx +0 -50
  52. package/src/chart/PolarChart.tsx +0 -164
  53. package/src/chart/RadarChart.tsx +0 -70
  54. package/src/chart/RadialBarChart.tsx +0 -46
  55. package/src/chart/RechartsWrapper.tsx +0 -551
  56. package/src/chart/Sankey.tsx +0 -1534
  57. package/src/chart/ScatterChart.tsx +0 -29
  58. package/src/chart/SunburstChart.tsx +0 -504
  59. package/src/chart/Treemap.tsx +0 -1223
  60. package/src/chart/createInitialRootProps.ts +0 -24
  61. package/src/chart/types.ts +0 -53
  62. package/src/component/ActivePoints.tsx +0 -144
  63. package/src/component/Cell.tsx +0 -37
  64. package/src/component/Cursor.tsx +0 -185
  65. package/src/component/Customized.tsx +0 -50
  66. package/src/component/DefaultLegendContent.tsx +0 -348
  67. package/src/component/DefaultTooltipContent.tsx +0 -224
  68. package/src/component/Dots.tsx +0 -157
  69. package/src/component/Label.tsx +0 -636
  70. package/src/component/LabelList.tsx +0 -375
  71. package/src/component/Legend.tsx +0 -512
  72. package/src/component/ResponsiveContainer.tsx +0 -348
  73. package/src/component/Text.tsx +0 -541
  74. package/src/component/Tooltip.tsx +0 -470
  75. package/src/component/TooltipBoundingBox.tsx +0 -146
  76. package/src/component/responsiveContainerUtils.ts +0 -134
  77. package/src/container/ClipPathProvider.tsx +0 -51
  78. package/src/container/Layer.tsx +0 -38
  79. package/src/container/RootSurface.tsx +0 -120
  80. package/src/container/Surface.tsx +0 -61
  81. package/src/context/CellsContext.tsx +0 -54
  82. package/src/context/ErrorBarContext.tsx +0 -146
  83. package/src/context/GraphicalItemChildrenScope.tsx +0 -18
  84. package/src/context/PanoramaContext.tsx +0 -9
  85. package/src/context/RegisterGraphicalItemId.tsx +0 -30
  86. package/src/context/accessibilityContext.tsx +0 -6
  87. package/src/context/brushUpdateContext.tsx +0 -9
  88. package/src/context/chartDataContext.tsx +0 -97
  89. package/src/context/chartLayoutContext.tsx +0 -201
  90. package/src/context/legendPayloadContext.tsx +0 -20
  91. package/src/context/legendPortalContext.tsx +0 -12
  92. package/src/context/tooltipContext.tsx +0 -89
  93. package/src/context/tooltipPortalContext.tsx +0 -12
  94. package/src/context/useTooltipAxis.ts +0 -22
  95. package/src/hooks.ts +0 -476
  96. package/src/index.ts +0 -280
  97. package/src/polar/Pie.tsx +0 -1360
  98. package/src/polar/PolarAngleAxis.tsx +0 -616
  99. package/src/polar/PolarGrid.tsx +0 -312
  100. package/src/polar/PolarRadiusAxis.tsx +0 -547
  101. package/src/polar/Radar.tsx +0 -734
  102. package/src/polar/RadialBar.tsx +0 -917
  103. package/src/polar/defaultPolarAngleAxisProps.tsx +0 -27
  104. package/src/polar/defaultPolarRadiusAxisProps.tsx +0 -25
  105. package/src/shape/Cross.tsx +0 -89
  106. package/src/shape/Curve.tsx +0 -343
  107. package/src/shape/Dot.tsx +0 -70
  108. package/src/shape/Polygon.tsx +0 -195
  109. package/src/shape/Rectangle.tsx +0 -470
  110. package/src/shape/Sector.tsx +0 -347
  111. package/src/shape/Symbols.tsx +0 -139
  112. package/src/shape/Trapezoid.tsx +0 -280
  113. package/src/state/RechartsStateContext.tsx +0 -12
  114. package/src/state/RechartsStateProvider.tsx +0 -87
  115. package/src/state/RechartsStoreContext.tsx +0 -25
  116. package/src/state/RechartsStoreProvider.tsx +0 -35
  117. package/src/state/ReportChartProps.tsx +0 -40
  118. package/src/state/ReportEventSettings.tsx +0 -30
  119. package/src/state/ReportMainChartProps.tsx +0 -61
  120. package/src/state/ReportPolarOptions.tsx +0 -35
  121. package/src/state/SetGraphicalItem.ts +0 -79
  122. package/src/state/SetLegendPayload.ts +0 -134
  123. package/src/state/SetTooltipEntrySettings.tsx +0 -72
  124. package/src/state/actions.ts +0 -464
  125. package/src/state/brushSlice.ts +0 -13
  126. package/src/state/cartesianAxisSlice.ts +0 -141
  127. package/src/state/chartDataSlice.ts +0 -50
  128. package/src/state/chartState.ts +0 -297
  129. package/src/state/errorBarSlice.ts +0 -29
  130. package/src/state/eventSettingsSlice.ts +0 -8
  131. package/src/state/events.ts +0 -76
  132. package/src/state/externalEventsMiddleware.ts +0 -255
  133. package/src/state/graphicalItemsSlice.ts +0 -74
  134. package/src/state/hooks/useChartSelectors.tsx +0 -45
  135. package/src/state/keyboardEventsMiddleware.ts +0 -228
  136. package/src/state/layoutSlice.ts +0 -21
  137. package/src/state/legendSlice.ts +0 -57
  138. package/src/state/mouseEventsMiddleware.ts +0 -185
  139. package/src/state/optionsSlice.ts +0 -47
  140. package/src/state/polarAxisSlice.ts +0 -10
  141. package/src/state/polarOptionsSlice.ts +0 -12
  142. package/src/state/rawData.ts +0 -26
  143. package/src/state/referenceElementsSlice.ts +0 -40
  144. package/src/state/renderedTicksSlice.ts +0 -15
  145. package/src/state/rootPropsSlice.ts +0 -47
  146. package/src/state/selectors/areaSelectors.ts +0 -240
  147. package/src/state/selectors/arrayEqualityCheck.ts +0 -29
  148. package/src/state/selectors/axisSelectors.ts +0 -2157
  149. package/src/state/selectors/barSelectors.ts +0 -310
  150. package/src/state/selectors/barStackSelectors.ts +0 -77
  151. package/src/state/selectors/brushSelectors.ts +0 -33
  152. package/src/state/selectors/chartSelector.ts +0 -185
  153. package/src/state/selectors/combiners/combineActiveLabel.ts +0 -16
  154. package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +0 -95
  155. package/src/state/selectors/combiners/combineAllBarPositions.ts +0 -122
  156. package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +0 -16
  157. package/src/state/selectors/combiners/combineBarPosition.ts +0 -23
  158. package/src/state/selectors/combiners/combineBarSizeList.ts +0 -80
  159. package/src/state/selectors/combiners/combineCheckedDomain.ts +0 -48
  160. package/src/state/selectors/combiners/combineConfiguredScale.ts +0 -111
  161. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +0 -45
  162. package/src/state/selectors/combiners/combineDisplayedStackedData.ts +0 -50
  163. package/src/state/selectors/combiners/combineInverseScaleFunction.ts +0 -16
  164. package/src/state/selectors/combiners/combineRealScaleType.ts +0 -44
  165. package/src/state/selectors/combiners/combineStackedData.ts +0 -27
  166. package/src/state/selectors/combiners/combineTooltipInteractionState.ts +0 -86
  167. package/src/state/selectors/combiners/combineTooltipPayload.ts +0 -205
  168. package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +0 -58
  169. package/src/state/selectors/containerSelectors.ts +0 -12
  170. package/src/state/selectors/dataSelectors.ts +0 -88
  171. package/src/state/selectors/funnelSelectors.ts +0 -75
  172. package/src/state/selectors/graphicalItemSelectors.ts +0 -30
  173. package/src/state/selectors/legendSelectors.ts +0 -29
  174. package/src/state/selectors/lineSelectors.ts +0 -134
  175. package/src/state/selectors/numberDomainEqualityCheck.ts +0 -14
  176. package/src/state/selectors/pickAxisId.ts +0 -5
  177. package/src/state/selectors/pickAxisType.ts +0 -3
  178. package/src/state/selectors/pieSelectors.ts +0 -97
  179. package/src/state/selectors/polarAxisSelectors.ts +0 -201
  180. package/src/state/selectors/polarGridSelectors.ts +0 -28
  181. package/src/state/selectors/polarScaleSelectors.ts +0 -133
  182. package/src/state/selectors/polarSelectors.ts +0 -219
  183. package/src/state/selectors/radarSelectors.ts +0 -191
  184. package/src/state/selectors/radialBarSelectors.ts +0 -435
  185. package/src/state/selectors/rootPropsSelectors.ts +0 -25
  186. package/src/state/selectors/scatterSelectors.ts +0 -96
  187. package/src/state/selectors/selectActivePropsFromChartPointer.ts +0 -26
  188. package/src/state/selectors/selectAllAxes.ts +0 -17
  189. package/src/state/selectors/selectChartOffset.ts +0 -16
  190. package/src/state/selectors/selectChartOffsetInternal.ts +0 -136
  191. package/src/state/selectors/selectLegendArea.ts +0 -20
  192. package/src/state/selectors/selectPlotArea.ts +0 -22
  193. package/src/state/selectors/selectTooltipAxisId.ts +0 -7
  194. package/src/state/selectors/selectTooltipAxisType.ts +0 -32
  195. package/src/state/selectors/selectTooltipEventType.ts +0 -48
  196. package/src/state/selectors/selectTooltipPayloadSearcher.ts +0 -6
  197. package/src/state/selectors/selectTooltipSettings.ts +0 -39
  198. package/src/state/selectors/selectTooltipState.ts +0 -8
  199. package/src/state/selectors/selectors.ts +0 -271
  200. package/src/state/selectors/tooltipSelectors.ts +0 -578
  201. package/src/state/selectors/touchSelectors.ts +0 -31
  202. package/src/state/store.ts +0 -29
  203. package/src/state/storeIdentity.ts +0 -9
  204. package/src/state/teardownWrite.ts +0 -10
  205. package/src/state/tooltipInteraction.ts +0 -23
  206. package/src/state/tooltipSlice.ts +0 -334
  207. package/src/state/touchEventsMiddleware.ts +0 -214
  208. package/src/state/types/AnimationSettings.ts +0 -20
  209. package/src/state/types/AreaSettings.ts +0 -14
  210. package/src/state/types/BarSettings.ts +0 -15
  211. package/src/state/types/LineSettings.ts +0 -9
  212. package/src/state/types/PieSettings.ts +0 -34
  213. package/src/state/types/RadarSettings.ts +0 -5
  214. package/src/state/types/RadialBarSettings.ts +0 -10
  215. package/src/state/types/ScatterSettings.ts +0 -12
  216. package/src/state/types/StackedGraphicalItem.ts +0 -34
  217. package/src/state/useChartState.ts +0 -17
  218. package/src/state/zIndexSlice.ts +0 -39
  219. package/src/synchronisation/syncSelectors.ts +0 -7
  220. package/src/synchronisation/types.ts +0 -44
  221. package/src/synchronisation/useChartSynchronisation.tsx +0 -404
  222. package/src/theme/RechartsTheme.ts +0 -16
  223. package/src/theme/RechartsThemeContext.ts +0 -19
  224. package/src/theme/darkTheme.ts +0 -13
  225. package/src/theme/graphicalItemIdentity.ts +0 -70
  226. package/src/theme/legacyTheme.ts +0 -17
  227. package/src/theme/lightTheme.ts +0 -13
  228. package/src/types.ts +0 -54
  229. package/src/util/ActiveShapeUtils.tsx +0 -162
  230. package/src/util/BarUtils.tsx +0 -62
  231. package/src/util/BarePortal.tsx +0 -50
  232. package/src/util/CamelCaseSVGAttrs.ts +0 -34
  233. package/src/util/CartesianUtils.ts +0 -48
  234. package/src/util/ChartUtils.ts +0 -802
  235. package/src/util/Constants.ts +0 -42
  236. package/src/util/CssPrefixUtils.ts +0 -20
  237. package/src/util/DOMUtils.ts +0 -129
  238. package/src/util/DataUtils.ts +0 -216
  239. package/src/util/Events.ts +0 -16
  240. package/src/util/FunnelUtils.tsx +0 -15
  241. package/src/util/Global.ts +0 -12
  242. package/src/util/IfOverflow.ts +0 -15
  243. package/src/util/LRUCache.ts +0 -41
  244. package/src/util/LogUtils.ts +0 -22
  245. package/src/util/PolarUtils.ts +0 -132
  246. package/src/util/RadialBarUtils.tsx +0 -24
  247. package/src/util/ReactUtils.ts +0 -95
  248. package/src/util/ReduceCSSCalc.ts +0 -187
  249. package/src/util/ScatterUtils.tsx +0 -52
  250. package/src/util/ShapeElementProps.tsx +0 -87
  251. package/src/util/TickUtils.ts +0 -60
  252. package/src/util/XAxisUtils.ts +0 -48
  253. package/src/util/YAxisUtils.ts +0 -48
  254. package/src/util/axisPropsAreEqual.ts +0 -48
  255. package/src/util/createCartesianCharts.tsx +0 -150
  256. package/src/util/createEventProxy.ts +0 -20
  257. package/src/util/createPolarCharts.tsx +0 -112
  258. package/src/util/cursor/getCursorPoints.ts +0 -46
  259. package/src/util/cursor/getCursorRectangle.ts +0 -28
  260. package/src/util/cursor/getRadialCursorPoints.ts +0 -32
  261. package/src/util/excludeEventProps.ts +0 -171
  262. package/src/util/getActiveCoordinate.ts +0 -213
  263. package/src/util/getAxisTypeBasedOnLayout.ts +0 -21
  264. package/src/util/getClassNameFromUnknown.ts +0 -6
  265. package/src/util/getEveryNth.ts +0 -27
  266. package/src/util/getRadiusAndStrokeWidthFromDot.ts +0 -35
  267. package/src/util/getRelativeCoordinate.ts +0 -80
  268. package/src/util/getSliced.ts +0 -13
  269. package/src/util/hoverDedupe.ts +0 -41
  270. package/src/util/isDomainSpecifiedByUser.ts +0 -219
  271. package/src/util/isWellBehavedNumber.ts +0 -7
  272. package/src/util/pathTotalLength.ts +0 -25
  273. package/src/util/payload/getUniqPayload.ts +0 -28
  274. package/src/util/propsAreEqual.ts +0 -121
  275. package/src/util/resolveDefaultProps.ts +0 -161
  276. package/src/util/round.ts +0 -32
  277. package/src/util/scale/CartesianScaleHelper.ts +0 -72
  278. package/src/util/scale/CustomScaleDefinition.ts +0 -81
  279. package/src/util/scale/RechartsScale.ts +0 -130
  280. package/src/util/scale/createCategoricalInverse.ts +0 -72
  281. package/src/util/scale/getNiceTickValues.ts +0 -311
  282. package/src/util/scale/index.ts +0 -2
  283. package/src/util/scale/util/arithmetic.ts +0 -54
  284. package/src/util/solid-1-compat.ts +0 -310
  285. package/src/util/solidJsxCamelAugment.d.ts +0 -84
  286. package/src/util/stacks/getStackSeriesIdentifier.ts +0 -21
  287. package/src/util/stacks/stackTypes.ts +0 -60
  288. package/src/util/structurallyEqual.ts +0 -31
  289. package/src/util/svgPropertiesAndEvents.ts +0 -53
  290. package/src/util/svgPropertiesNoEvents.ts +0 -571
  291. package/src/util/tooltip/translate.ts +0 -171
  292. package/src/util/typedDataKey.ts +0 -48
  293. package/src/util/types.ts +0 -1560
  294. package/src/util/useAnimationId.ts +0 -31
  295. package/src/util/useElementOffset.ts +0 -110
  296. package/src/util/useId.ts +0 -8
  297. package/src/util/usePrefersReducedMotion.ts +0 -48
  298. package/src/util/useReportScale.ts +0 -24
  299. package/src/util/useUniqueId.ts +0 -30
  300. package/src/zIndex/DefaultZIndexes.ts +0 -84
  301. package/src/zIndex/ZIndexLayer.tsx +0 -121
  302. package/src/zIndex/ZIndexPortal.tsx +0 -79
  303. package/src/zIndex/getZIndexFromUnknown.ts +0 -14
  304. package/src/zIndex/zIndexSelectors.ts +0 -48
package/package.json CHANGED
@@ -1,16 +1,11 @@
1
1
  {
2
2
  "author": "Lovro Žagar",
3
3
  "bugs": "https://github.com/lovrozagar/solidports/issues",
4
- "dependencies": {
5
- "clsx": "2.1.1",
6
- "decimal.js-light": "2.5.1",
7
- "es-toolkit": "1.49.0",
8
- "eventemitter3": "5.0.4",
9
- "tiny-invariant": "1.3.3",
10
- "victory-vendor": "37.3.6"
11
- },
12
4
  "description": "SolidJS 1:1 port of Recharts charting library",
13
5
  "devDependencies": {
6
+ "@babel/core": "7.29.7",
7
+ "@babel/preset-typescript": "7.29.7",
8
+ "@solidjs/babel-plugin": "2.0.0-rc.13",
14
9
  "@solidjs/signals": "2.0.0-rc.13",
15
10
  "@solidjs/testing-library": "1.0.0-beta.3",
16
11
  "@solidjs/vite-plugin": "3.0.0-next.47",
@@ -19,12 +14,18 @@
19
14
  "@testing-library/jest-dom": "6.9.1",
20
15
  "@types/bun": "latest",
21
16
  "@types/node": "26.1.1",
17
+ "clsx": "2.1.1",
18
+ "decimal.js-light": "2.5.1",
19
+ "es-toolkit": "1.49.0",
20
+ "esbuild": "0.28.2",
21
+ "eventemitter3": "5.0.4",
22
22
  "jsdom": "29.1.1",
23
23
  "solid-js": "2.0.0-rc.13",
24
+ "tiny-invariant": "1.3.3",
24
25
  "ts-morph": "28.0.0",
25
26
  "tsup": "8.5.1",
26
- "tsup-preset-solid": "2.2.0",
27
27
  "typescript": "7.0.2",
28
+ "victory-vendor": "37.3.6",
28
29
  "vitest": "4.1.10",
29
30
  "vitest-axe": "0.1.0"
30
31
  },
@@ -34,13 +35,29 @@
34
35
  "exports": {
35
36
  ".": {
36
37
  "types": "./dist/index.d.ts",
37
- "solid": "./src/index.ts",
38
- "import": "./dist/index.js"
39
- }
38
+ "solid": "./dist/index.jsx",
39
+ "worker": {
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/server.js"
42
+ },
43
+ "deno": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/server.js"
46
+ },
47
+ "node": {
48
+ "types": "./dist/index.d.ts",
49
+ "default": "./dist/server.js"
50
+ },
51
+ "browser": {
52
+ "types": "./dist/index.d.ts",
53
+ "default": "./dist/index.js"
54
+ },
55
+ "default": "./dist/index.js"
56
+ },
57
+ "./package.json": "./package.json"
40
58
  },
41
59
  "files": [
42
60
  "dist",
43
- "src",
44
61
  "README.md",
45
62
  "LICENSE",
46
63
  "NOTICE"
@@ -56,12 +73,13 @@
56
73
  "data-visualization"
57
74
  ],
58
75
  "license": "MIT",
59
- "main": "./dist/index.js",
76
+ "main": "./dist/server.js",
60
77
  "module": "./dist/index.js",
61
78
  "name": "@solidports/recharts",
62
79
  "peerDependencies": {
63
- "@solidjs/web": ">=2.0.0-rc.13",
64
- "solid-js": ">=2.0.0-rc.13"
80
+ "@solidjs/signals": "^2.0.0-rc.13",
81
+ "@solidjs/web": "^2.0.0-rc.13",
82
+ "solid-js": "^2.0.0-rc.13"
65
83
  },
66
84
  "publishConfig": {
67
85
  "access": "public"
@@ -72,9 +90,8 @@
72
90
  "directory": "packages/recharts"
73
91
  },
74
92
  "scripts": {
75
- "build": "tsup",
93
+ "build": "node scripts/build.mjs",
76
94
  "check": "bun run typecheck && bun run lint && bun run test",
77
- "dev": "tsup --watch",
78
95
  "lint": "oxlint src test",
79
96
  "lint:fix": "oxlint --fix src test",
80
97
  "parity": "bun scripts/parity-audit.ts",
@@ -94,5 +111,5 @@
94
111
  "sideEffects": false,
95
112
  "type": "module",
96
113
  "types": "./dist/index.d.ts",
97
- "version": "0.1.0"
114
+ "version": "0.1.1"
98
115
  }
@@ -1,183 +0,0 @@
1
- import { createEffect, createMemo, createSignal, Show, untrack } from "solid-js"
2
- import type { Accessor } from "solid-js"
3
- import type { JSX } from "@solidjs/web"
4
- import { JavascriptAnimate } from "./JavascriptAnimate"
5
- import type { EasingInput } from "./easing"
6
- import { useAnimationId } from "../util/useAnimationId"
7
- import { matchAnimationItems, matchByIndex } from "./matchBy"
8
- import type { AnimationItem, AnimationMatchByProp } from "./matchBy"
9
- import { useAnimationStartSnapshot } from "./useAnimationStartSnapshot"
10
- import type { CartesianLayout, PolarLayout } from "../util/types"
11
- import type { AnimationInterpolateFn } from "../state/types/AnimationSettings"
12
-
13
- export type { AnimationInterpolateFn }
14
-
15
- /**
16
- * Tracks animation state and provides callbacks for animation start/end.
17
- *
18
- * @param onAnimationStart optional callback to call when animation starts
19
- * @param onAnimationEnd optional callback to call when animation ends
20
- */
21
- export function useAnimationCallbacks(
22
- onAnimationStart: Accessor<(() => void) | undefined> = () => undefined,
23
- onAnimationEnd: Accessor<(() => void) | undefined> = () => undefined,
24
- ): {
25
- isAnimating: Accessor<boolean>
26
- handleAnimationStart: () => void
27
- handleAnimationEnd: () => void
28
- } {
29
- const [isAnimating, setIsAnimating] = createSignal(false)
30
-
31
- const handleAnimationStart = () => {
32
- const callback = untrack(onAnimationStart)
33
- if (typeof callback === "function") {
34
- callback()
35
- }
36
- setIsAnimating(true)
37
- }
38
-
39
- const handleAnimationEnd = () => {
40
- const callback = untrack(onAnimationEnd)
41
- if (typeof callback === "function") {
42
- callback()
43
- }
44
- setIsAnimating(false)
45
- }
46
-
47
- return { handleAnimationEnd, handleAnimationStart, isAnimating }
48
- }
49
-
50
- export type AnimatedItemsProps<ItemType, LayoutType extends CartesianLayout | PolarLayout> = {
51
- /**
52
- * Opaque input to detect when a new animation should start.
53
- * When this value changes, a new animation begins.
54
- */
55
- animationInput: unknown
56
- /** Prefix for the generated animation ID */
57
- animationIdPrefix: string
58
- /** The target items to animate towards */
59
- items: ReadonlyArray<ItemType> | undefined
60
- /** Ref holding previous items — used to detect first render vs data update */
61
- previousItemsRef: { current: ReadonlyArray<ItemType> | null | undefined }
62
- /** Whether animation is active */
63
- isAnimationActive: boolean | "auto"
64
- /** Delay in ms before animation begins */
65
- animationBegin: number
66
- /** Duration of animation in ms */
67
- animationDuration: number
68
- /** Easing function or named easing */
69
- animationEasing: EasingInput
70
- /** Called when the animation begins */
71
- onAnimationStart?: () => void
72
- /** Called when the animation completes */
73
- onAnimationEnd?: () => void
74
- /** The interpolation function — either the default or user-provided */
75
- animationInterpolateFn: AnimationInterpolateFn<ItemType, LayoutType>
76
- /**
77
- * Strategy for matching previous items to next items during animation.
78
- *
79
- * - `matchByIndex` (default): match by array index with proportional stretching
80
- * - `matchAppend`: match 1:1 by index, extras animate in as new
81
- * - A function `(item, index) => key`: match by the returned key value
82
- */
83
- animationMatchBy?: AnimationMatchByProp<ItemType>
84
- /**
85
- * Optional guard for updating previousItemsRef. Default: `(animationElapsedTime) => animationElapsedTime > 0`.
86
- * Line uses `(animationElapsedTime) => animationElapsedTime > 0 && totalLength > 0` to avoid updating before SVG path is measured.
87
- */
88
- shouldUpdatePreviousRef?: (animationElapsedTime: number) => boolean
89
- /**
90
- * Render with interpolated items and animation state. Invoked once; the
91
- * accessors update in place on every animation frame.
92
- *
93
- * @param items The interpolated items at the current animation frame
94
- * @param animationElapsedTime The normalized time (0-1), useful for additional animation effects
95
- * @param isEntrance Whether this is the first render (entrance animation) or a data update animation.
96
- */
97
- children: (
98
- items: Accessor<ReadonlyArray<ItemType>>,
99
- animationElapsedTime: Accessor<number>,
100
- isEntrance: Accessor<boolean>,
101
- ) => JSX.Element
102
- layout: LayoutType
103
- }
104
-
105
- /**
106
- * A reusable animation wrapper for array-based chart data.
107
- *
108
- * Encapsulates the common animation pattern shared by Bar, Scatter, Funnel, Pie,
109
- * Radar, RadialBar, Area, and Line:
110
- * 1. Track previous items in a ref
111
- * 2. Wrap in JavascriptAnimate
112
- * 3. Update ref when animationElapsedTime > 0
113
- *
114
- * @since 3.9
115
- */
116
- export function AnimatedItems<ItemType, LayoutType extends CartesianLayout | PolarLayout>(
117
- props: AnimatedItemsProps<ItemType, LayoutType>,
118
- ) {
119
- const animationId = useAnimationId(
120
- () => props.animationInput,
121
- untrack(() => props.animationIdPrefix),
122
- )
123
- const animationStartItems = useAnimationStartSnapshot(
124
- animationId,
125
- /* eslint-disable-next-line solid/reactivity -- the ref box is a stable mutable container owned by the caller */
126
- props.previousItemsRef,
127
- )
128
- /* Memoized so per-frame reads do not re-run the caller's selector chain. */
129
- const items = createMemo(() => props.items)
130
- const animationItems = createMemo<ReadonlyArray<AnimationItem<ItemType>> | null>(() =>
131
- matchAnimationItems(
132
- animationStartItems.frozenStartValue() ?? null,
133
- items(),
134
- props.animationMatchBy ?? matchByIndex,
135
- ),
136
- )
137
-
138
- return (
139
- <JavascriptAnimate
140
- animationId={animationId()}
141
- begin={props.animationBegin}
142
- duration={props.animationDuration}
143
- isActive={props.isAnimationActive}
144
- easing={props.animationEasing}
145
- onAnimationEnd={props.onAnimationEnd}
146
- onAnimationStart={props.onAnimationStart}
147
- >
148
- {(animationElapsedTime: Accessor<number>) => {
149
- /* Fixed per render like upstream: a lazy read (e.g. on hover) would see the
150
- unpublished t=1 refresh. */
151
- const isEntrance = createMemo(() => animationStartItems.startValue() == null)
152
- const stepData = createMemo(() => {
153
- const current = items()
154
- if (current == null) {
155
- return current
156
- }
157
- return props.animationInterpolateFn(animationItems(), animationElapsedTime(), props.layout)
158
- })
159
- createEffect(
160
- () => {
161
- const t = animationElapsedTime()
162
- const step = stepData()
163
- const canUpdate =
164
- props.shouldUpdatePreviousRef != null ? props.shouldUpdatePreviousRef(t) : t > 0
165
- return { canUpdate, step, t }
166
- },
167
- ({ canUpdate, step, t }) => {
168
- animationStartItems.syncStepValue(step ?? null, t, canUpdate)
169
- },
170
- )
171
- return (
172
- <Show when={stepData() != null}>
173
- {props.children(
174
- () => stepData() as ReadonlyArray<ItemType>,
175
- animationElapsedTime,
176
- isEntrance,
177
- )}
178
- </Show>
179
- )
180
- }}
181
- </JavascriptAnimate>
182
- )
183
- }
@@ -1,33 +0,0 @@
1
- import type { CancelableTimeout, TimeoutController } from "./timeoutController"
2
- import type { AnimationHandle } from "./AnimationHandle"
3
-
4
- /**
5
- * It's actually always the case that JavaScript-based animations produce numbers,
6
- * and CSS transition-based animations always produce strings,
7
- * but it's so much easier to just have them together than to deal with all the generics.
8
- *
9
- * @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
10
- *
11
- * @since 3.9
12
- */
13
- export type OnAnimationStateUpdate = (newState: number | string) => void
14
-
15
- /**
16
- * AnimationController accepts the animation state machine (= RechartsAnimation) plus a timeout controller,
17
- * and manages the animation by calling the tick method of the animation state machine at the right time.
18
- *
19
- * One controller is only responsible for one animation. Every new animation will create a new controller.
20
- *
21
- * The animation state machine is responsible for calculating the animation progress
22
- * and calling the onAnimationStart and onAnimationEnd callbacks at the right time,
23
- * while the AnimationController is responsible for calling the tick method of the animation state machine.
24
- *
25
- * @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
26
- *
27
- * @since 3.9
28
- */
29
- export type AnimationController = (
30
- timeoutController: TimeoutController,
31
- animationHandle: AnimationHandle,
32
- listener: OnAnimationStateUpdate,
33
- ) => CancelableTimeout
@@ -1,36 +0,0 @@
1
- import type { AnimationController, OnAnimationStateUpdate } from "./AnimationController"
2
- import type { AnimationHandle } from "./AnimationHandle"
3
- import type { CancelableTimeout, TimeoutController } from "./timeoutController"
4
-
5
- /**
6
- * JavaScript animations require trigger and repaint as soon as possible,
7
- * so this class uses the timeoutController to trigger updates as quickly as the controller allows.
8
- *
9
- * JavaScript animation progress is represented as a stream of values. The exact type depends on the animationHandle type.
10
- * Each individual consumer is then responsible for mapping those values onto a React component.
11
- */
12
- export const animationControllerImpl: AnimationController = (
13
- timeoutController: TimeoutController,
14
- animationHandle: AnimationHandle,
15
- listener: OnAnimationStateUpdate,
16
- ): CancelableTimeout => {
17
- let cancellable: CancelableTimeout | undefined
18
- const nextUpdate = (now: number) => {
19
- const timeRemaining = animationHandle.tick(now)
20
- if (animationHandle.getState() === "active") {
21
- listener(animationHandle.getInterpolated())
22
- if (animationHandle.getProgress() === 1) {
23
- animationHandle.complete()
24
- cancellable = undefined
25
- return
26
- }
27
- cancellable = timeoutController.setTimeout(nextUpdate, timeRemaining)
28
- return
29
- }
30
- cancellable = timeoutController.setTimeout(nextUpdate, timeRemaining)
31
- }
32
-
33
- cancellable = timeoutController.setTimeout(nextUpdate, 0)
34
-
35
- return () => cancellable?.()
36
- }
@@ -1,307 +0,0 @@
1
- // eslint-disable-next-line max-classes-per-file
2
- import { interpolate } from "../util/DataUtils"
3
- import type { EasingFunction, NamedBezier } from "./easing"
4
-
5
- const INIT = "init" as const
6
- const PENDING = "pending" as const
7
- const ACTIVE = "active" as const
8
- const COMPLETED = "completed" as const
9
-
10
- export type AnimationState = typeof INIT | typeof PENDING | typeof ACTIVE | typeof COMPLETED
11
-
12
- type AnimationStateCallback = () => void
13
-
14
- function duration(time: number): number {
15
- return Math.max(0, time)
16
- }
17
-
18
- abstract class RechartsAnimation<T, E> {
19
- /**
20
- * Returns the absolute time after the animationBegin delay has been completed,
21
- * and when the animationDuration started ticking.
22
- */
23
- public getAnimationStartedTime(): number | undefined {
24
- return this.animationStartedTime
25
- }
26
-
27
- /**
28
- * Returns the absolute time of when the animation began - now it will wait for {animationBegin} ms before the transition starts
29
- */
30
- public getBeginStartedTime(): number | undefined {
31
- return this.beginStartedTime
32
- }
33
-
34
- private readonly onAnimationEnd: undefined | AnimationStateCallback
35
-
36
- private progress: number
37
-
38
- private animationStartedTime: number | undefined
39
-
40
- private beginStartedTime: number | undefined
41
-
42
- protected readonly animationDuration: number
43
-
44
- private readonly animationBegin: number
45
-
46
- private readonly from: T
47
-
48
- private readonly to: T
49
-
50
- protected readonly easing: E
51
-
52
- private readonly animationId: string
53
-
54
- constructor(param: {
55
- animationId: string
56
- onAnimationStart: undefined | AnimationStateCallback
57
- onAnimationEnd: undefined | AnimationStateCallback
58
- animationDuration: number
59
- animationBegin: number
60
- from: T
61
- to: T
62
- easing: E
63
- }) {
64
- this.animationId = param.animationId
65
- this.onAnimationEnd = param.onAnimationEnd
66
- this.animationDuration = duration(param.animationDuration)
67
- this.animationBegin = duration(param.animationBegin)
68
- this.progress = 0
69
- this.from = param.from
70
- this.to = param.to
71
- this.easing = param.easing
72
- // Mimic what the previous animationManager was doing - call onAnimationStart immediately and synchronously
73
- param.onAnimationStart?.()
74
- }
75
-
76
- private state: AnimationState = INIT
77
-
78
- /**
79
- * Returns the state machine current state
80
- * - `init`: animation had just been created. It immediately calls `onAnimationStart`
81
- * - `pending`: animation is now paused for `animationBegin` milliseconds until the transition begins
82
- * - `active`: animation is transitioning items on screen
83
- * - `completed`: animation has completed its transition and executed `onAnimationEnd`.
84
- * This state is final and the animation is no longer allowed to transition to other states.
85
- */
86
- public getState() {
87
- return this.state
88
- }
89
-
90
- /**
91
- * Returns the easing input or function
92
- */
93
- public getEasing(): E {
94
- return this.easing
95
- }
96
-
97
- /**
98
- * Returns the configuration - the duration of the transition.
99
- * Does not change in time, does not change when state changes, this is a static value.
100
- */
101
- public getAnimationDuration(): number {
102
- return this.animationDuration
103
- }
104
-
105
- /**
106
- * Sets the current time of the animation. The animation sets its internal state and progress accordingly.
107
- * This is current, absolute time; not additive!
108
- * This allows you to essentially "travel back in time" based on the value you pass in here.
109
- *
110
- * Returns the (relative) time remaining until the current activity is over.
111
- * Meaning: if the state is in a middle of a delay, returns the time left until the delay is finished.
112
- * If the state is in the middle of a transition, returns time left until that transition is complete.
113
- * This is useful because it's the same number you can take and put into setTimeout(fn, X)
114
- * as that's how much time we need to wait until the next state transition happens.
115
- */
116
- public tick(now: number): number {
117
- if (this.getState() === INIT) {
118
- this.state = PENDING
119
- this.beginStartedTime = now
120
- return this.animationBegin
121
- }
122
-
123
- if (this.getState() === PENDING) {
124
- if (this.beginStartedTime == null) {
125
- throw new Error("@solidports/recharts: pending animation has no begin time")
126
- }
127
- const timeElapsed = now - this.beginStartedTime
128
- if (timeElapsed >= this.animationBegin) {
129
- this.state = ACTIVE
130
- this.animationStartedTime = now
131
- // The state flipped just now so the elapsed time is zero
132
- return this.nextAnimationUpdate(0)
133
- }
134
- return duration(this.animationBegin - timeElapsed)
135
- }
136
-
137
- if (this.getState() === ACTIVE) {
138
- if (this.animationStartedTime == null) {
139
- throw new Error("@solidports/recharts: active animation has no start time")
140
- }
141
- const timeElapsed = now - this.animationStartedTime
142
- this.setProgress(timeElapsed / this.animationDuration)
143
- return this.nextAnimationUpdate(timeElapsed)
144
- }
145
-
146
- // state === COMPLETED, nothing interesting is going to happen
147
- return 0
148
- }
149
-
150
- private setProgress(newProgress: number) {
151
- this.progress = Math.min(1, Math.max(0, newProgress))
152
- }
153
-
154
- /**
155
- * Returns an abstract "progress" which is number between 0 and 1 which shows the distance of transition.
156
- * This progress depends on the animation state:
157
- * - `init`: 0
158
- * - `pending`: 0
159
- * - `active`: transitioning between [0, 1] based on the time elapsed
160
- * - `completed`: 1
161
- *
162
- * The progress is hard-capped to be between 0 and 1 (inclusive) to avoid overshooting caused by coarse timers.
163
- * For this reason, the easing function must be applied _after_ this animation state,
164
- * so that one has a chance to construct dynamic "overshoot" animations.
165
- *
166
- * The progress is linear with time.
167
- * If you wish for easing, use `getInterpolated()` instead.
168
- */
169
- public getProgress(): number {
170
- return this.progress
171
- }
172
-
173
- /**
174
- * Completes the animation. Completed animation:
175
- * - cannot be manipulated anymore
176
- * - its progress is set to 1
177
- * - tick function doesn't do anything
178
- * - getState() always returns 'completed'
179
- */
180
- public complete() {
181
- this.progress = 1
182
- if (this.state === "active") {
183
- // Do not call callbacks if the animation was interrupted before it even started!
184
- this.onAnimationEnd?.()
185
- }
186
- this.state = COMPLETED
187
- }
188
-
189
- /**
190
- * Returns the starting value of the animation.
191
- * Does not include progress, easing, interpolation, none of that - just the static starting value
192
- */
193
- public getFrom() {
194
- return this.from
195
- }
196
-
197
- /**
198
- * Returns the end value of the animation.
199
- * Does not include progress, easing, interpolation, none of that - just the static end value
200
- */
201
- public getTo() {
202
- return this.to
203
- }
204
-
205
- /**
206
- * Unique identifier of an animation
207
- */
208
- public getAnimationId(): string {
209
- return this.animationId
210
- }
211
-
212
- /**
213
- * Returns the configuration - the duration of delay in between animation initialization, and transition.
214
- * Does not change in time, does not change when state changes, this is a static value.
215
- */
216
- getAnimationBegin(): number {
217
- return this.animationBegin
218
- }
219
-
220
- /**
221
- * Returns value of the transition at the current time.
222
- * The exact details differ based on the animation type
223
- */
224
- public abstract getInterpolated(): T
225
-
226
- /**
227
- * Returns the duration of time of when the controller should ask for the next update
228
- */
229
- protected abstract nextAnimationUpdate(timeElapsed: number): number
230
- }
231
-
232
- /**
233
- * Animation handle representing a Javascript-based animation.
234
- * This animation requires one render cycle for each frame, and it calls setTimeout as quickly as possible
235
- *
236
- * @since 3.9
237
- */
238
- export class JavascriptAnimation extends RechartsAnimation<number, EasingFunction> {
239
- // eslint-disable-next-line class-methods-use-this
240
- protected nextAnimationUpdate(): number {
241
- /*
242
- * JavaScript-based animations have to update as soon as possible,
243
- * so we return 0 here to indicate that the next update should be scheduled immediately
244
- * and it should trigger render on every occasion.
245
- */
246
- return 0
247
- }
248
-
249
- /**
250
- * Returns value of the animation after its easing function had been applied.
251
- * This value, unlike getProgress(), can escape the [0..1] range
252
- * because this is entirely within the easing function control. Spring typically does this.
253
- */
254
- public getInterpolated(): number {
255
- return this.easing(interpolate(this.getFrom(), this.getTo(), this.getProgress()))
256
- }
257
- }
258
-
259
- /**
260
- * Animation handle representing a CSS transition.
261
- * This animation requires only one render, and the actual transition is then handled by the browser.
262
- *
263
- * @since 3.9
264
- */
265
- export class CSSTransitionAnimation extends RechartsAnimation<string, NamedBezier> {
266
- protected nextAnimationUpdate(timeElapsed: number): number {
267
- /**
268
- * CSS transitions do not need DOM updates past the initial render
269
- * so here we just instruct the controller to wait until the animation duration is over.
270
- */
271
- return duration(this.animationDuration - timeElapsed)
272
- }
273
-
274
- /**
275
- * Returns the final value of the animation (the `to`).
276
- *
277
- * CSS transitions leave both interpolation and easing to the browser,
278
- * so all we need to do here is return the final state
279
- * and let browser handle the rest.
280
- */
281
- public getInterpolated(): string {
282
- return this.getTo()
283
- }
284
- }
285
-
286
- /**
287
- * Recharts animation state machine.
288
- *
289
- * Possible transitions are:
290
- * - `init`: starting state - `onAnimationStart` executes
291
- * - `init` to `pending` - `animationBegin` duration begins
292
- * - `pending` to `active` - `animationDuration` duration begins, timer ticks decide the progress
293
- * - `active` to `completed` - `onAnimationEnd` executes
294
- *
295
- * The state always moves in this direction, cannot move backwards.
296
- *
297
- * The animation queue is static and consists of four elements:
298
- * - `onAnimationStart`: function that is called when the animation is created
299
- * - `animationBegin`: delay between `onAnimationStart` and the transition
300
- * - the transition itself, takes `animationDuration` ms to finish
301
- * - `onAnimationEnd`: function that is called when the animation is moving from `active` to `completed`
302
- *
303
- * @see {@link https://recharts.github.io/en-US/guide/animations/ Animation guide}
304
- *
305
- * @since 3.9
306
- */
307
- export type AnimationHandle = JavascriptAnimation | CSSTransitionAnimation