solid-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.
Files changed (639) hide show
  1. package/NEXT_SESSION_PROMPT.md +114 -0
  2. package/package.json +28 -0
  3. package/src/animation/AnimatedItems.tsx +169 -0
  4. package/src/animation/AnimationController.ts +24 -0
  5. package/src/animation/AnimationControllerImpl.ts +37 -0
  6. package/src/animation/AnimationHandle.ts +273 -0
  7. package/src/animation/CSSTransitionAnimate.tsx +142 -0
  8. package/src/animation/JavascriptAnimate.tsx +107 -0
  9. package/src/animation/easing.ts +261 -0
  10. package/src/animation/matchBy.ts +211 -0
  11. package/src/animation/timeoutController.ts +51 -0
  12. package/src/animation/useAnimationController.tsx +31 -0
  13. package/src/animation/useAnimationStartSnapshot.ts +73 -0
  14. package/src/animation/util.ts +16 -0
  15. package/src/cartesian/Area.tsx +810 -0
  16. package/src/cartesian/AreaRevealShape.tsx +250 -0
  17. package/src/cartesian/Bar.tsx +1216 -0
  18. package/src/cartesian/BarStack.tsx +148 -0
  19. package/src/cartesian/Brush.tsx +653 -0
  20. package/src/cartesian/CartesianAxis.tsx +541 -0
  21. package/src/cartesian/CartesianGrid.tsx +605 -0
  22. package/src/cartesian/ErrorBar.tsx +319 -0
  23. package/src/cartesian/Funnel.tsx +594 -0
  24. package/src/cartesian/GraphicalItemClipPath.tsx +75 -0
  25. package/src/cartesian/Line.tsx +742 -0
  26. package/src/cartesian/LineDrawShape.tsx +190 -0
  27. package/src/cartesian/ReferenceArea.tsx +275 -0
  28. package/src/cartesian/ReferenceDot.tsx +286 -0
  29. package/src/cartesian/ReferenceLine.tsx +414 -0
  30. package/src/cartesian/RenderedTicksReporter.tsx +49 -0
  31. package/src/cartesian/Scatter.tsx +741 -0
  32. package/src/cartesian/XAxis.tsx +293 -0
  33. package/src/cartesian/YAxis.tsx +333 -0
  34. package/src/cartesian/ZAxis.tsx +80 -0
  35. package/src/cartesian/getCartesianPosition.ts +255 -0
  36. package/src/cartesian/getEquidistantTicks.ts +126 -0
  37. package/src/cartesian/getTicks.ts +225 -0
  38. package/src/cartesian/useAnimatedLineLength.ts +84 -0
  39. package/src/chart/AreaChart.tsx +30 -0
  40. package/src/chart/BarChart.tsx +27 -0
  41. package/src/chart/CartesianChart.tsx +91 -0
  42. package/src/chart/CategoricalChart.tsx +60 -0
  43. package/src/chart/ComposedChart.tsx +29 -0
  44. package/src/chart/FunnelChart.tsx +29 -0
  45. package/src/chart/LineChart.tsx +29 -0
  46. package/src/chart/PieChart.tsx +41 -0
  47. package/src/chart/PolarChart.tsx +97 -0
  48. package/src/chart/RadarChart.tsx +37 -0
  49. package/src/chart/RadialBarChart.tsx +39 -0
  50. package/src/chart/RechartsWrapper.tsx +486 -0
  51. package/src/chart/Sankey.tsx +992 -0
  52. package/src/chart/ScatterChart.tsx +29 -0
  53. package/src/chart/SunburstChart.tsx +394 -0
  54. package/src/chart/Treemap.tsx +874 -0
  55. package/src/chart/types.ts +37 -0
  56. package/src/component/ActivePoints.tsx +136 -0
  57. package/src/component/Cell.tsx +72 -0
  58. package/src/component/Cursor.tsx +249 -0
  59. package/src/component/Customized.tsx +8 -0
  60. package/src/component/DefaultLegendContent.tsx +205 -0
  61. package/src/component/DefaultTooltipContent.tsx +247 -0
  62. package/src/component/Dots.tsx +128 -0
  63. package/src/component/Label.tsx +507 -0
  64. package/src/component/LabelList.tsx +270 -0
  65. package/src/component/Legend.tsx +273 -0
  66. package/src/component/ResponsiveContainer.tsx +397 -0
  67. package/src/component/Text.tsx +436 -0
  68. package/src/component/Tooltip.tsx +309 -0
  69. package/src/component/TooltipBoundingBox.tsx +152 -0
  70. package/src/component/responsiveContainerUtils.ts +128 -0
  71. package/src/container/ClipPathProvider.tsx +40 -0
  72. package/src/container/Layer.tsx +38 -0
  73. package/src/container/RootSurface.tsx +124 -0
  74. package/src/container/Surface.tsx +70 -0
  75. package/src/context/ErrorBarContext.tsx +85 -0
  76. package/src/context/PanoramaContext.tsx +13 -0
  77. package/src/context/RegisterGraphicalItemId.tsx +41 -0
  78. package/src/context/accessibilityContext.tsx +10 -0
  79. package/src/context/brushUpdateContext.ts +14 -0
  80. package/src/context/chartDataContext.tsx +79 -0
  81. package/src/context/chartLayoutContext.tsx +158 -0
  82. package/src/context/legendPayloadContext.ts +11 -0
  83. package/src/context/legendPortalContext.ts +11 -0
  84. package/src/context/tooltipContext.ts +72 -0
  85. package/src/context/tooltipPortalContext.ts +14 -0
  86. package/src/context/useTooltipAxis.ts +24 -0
  87. package/src/hooks.ts +312 -0
  88. package/src/index.ts +288 -0
  89. package/src/polar/Pie.tsx +912 -0
  90. package/src/polar/PolarAngleAxis.tsx +494 -0
  91. package/src/polar/PolarGrid.tsx +269 -0
  92. package/src/polar/PolarRadiusAxis.tsx +422 -0
  93. package/src/polar/Radar.tsx +652 -0
  94. package/src/polar/RadialBar.tsx +767 -0
  95. package/src/polar/defaultPolarAngleAxisProps.tsx +33 -0
  96. package/src/polar/defaultPolarRadiusAxisProps.tsx +28 -0
  97. package/src/shape/Cross.tsx +83 -0
  98. package/src/shape/Curve.tsx +335 -0
  99. package/src/shape/Dot.tsx +49 -0
  100. package/src/shape/Polygon.tsx +168 -0
  101. package/src/shape/Rectangle.tsx +301 -0
  102. package/src/shape/Sector.tsx +304 -0
  103. package/src/shape/Symbols.tsx +144 -0
  104. package/src/shape/Trapezoid.tsx +228 -0
  105. package/src/state/RechartsReduxContext.tsx +8 -0
  106. package/src/state/RechartsStoreContext.ts +15 -0
  107. package/src/state/RechartsStoreProvider.tsx +27 -0
  108. package/src/state/ReportChartProps.tsx +19 -0
  109. package/src/state/ReportEventSettings.tsx +19 -0
  110. package/src/state/ReportMainChartProps.tsx +35 -0
  111. package/src/state/ReportPolarOptions.tsx +28 -0
  112. package/src/state/SetLegendPayload.ts +50 -0
  113. package/src/state/SetTooltipEntrySettings.tsx +46 -0
  114. package/src/state/brushSlice.ts +60 -0
  115. package/src/state/cartesianAxisSlice.ts +288 -0
  116. package/src/state/chartDataSlice.ts +115 -0
  117. package/src/state/errorBarSlice.ts +84 -0
  118. package/src/state/eventSettingsSlice.ts +41 -0
  119. package/src/state/externalEventsMiddleware.ts +136 -0
  120. package/src/state/graphicalItemsSlice.ts +162 -0
  121. package/src/state/hooks.ts +42 -0
  122. package/src/state/keyboardEventsMiddleware.ts +213 -0
  123. package/src/state/layoutSlice.ts +71 -0
  124. package/src/state/legendSlice.ts +107 -0
  125. package/src/state/mouseEventsMiddleware.ts +103 -0
  126. package/src/state/optionsSlice.ts +64 -0
  127. package/src/state/polarAxisSlice.ts +65 -0
  128. package/src/state/polarOptionsSlice.ts +54 -0
  129. package/src/state/reduxDevtoolsJsonStringifyReplacer.ts +15 -0
  130. package/src/state/referenceElementsSlice.ts +121 -0
  131. package/src/state/renderedTicksSlice.ts +61 -0
  132. package/src/state/rootPropsSlice.ts +70 -0
  133. package/src/state/selectors/areaSelectors.ts +169 -0
  134. package/src/state/selectors/arrayEqualityCheck.ts +8 -0
  135. package/src/state/selectors/axisSelectors.ts +2196 -0
  136. package/src/state/selectors/barSelectors.ts +319 -0
  137. package/src/state/selectors/barStackSelectors.ts +79 -0
  138. package/src/state/selectors/brushSelectors.ts +40 -0
  139. package/src/state/selectors/combiners/combineActiveLabel.ts +21 -0
  140. package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +93 -0
  141. package/src/state/selectors/combiners/combineAllBarPositions.ts +131 -0
  142. package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +17 -0
  143. package/src/state/selectors/combiners/combineBarPosition.ts +24 -0
  144. package/src/state/selectors/combiners/combineBarSizeList.ts +75 -0
  145. package/src/state/selectors/combiners/combineCheckedDomain.ts +49 -0
  146. package/src/state/selectors/combiners/combineConfiguredScale.ts +121 -0
  147. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +43 -0
  148. package/src/state/selectors/combiners/combineDisplayedStackedData.ts +50 -0
  149. package/src/state/selectors/combiners/combineInverseScaleFunction.ts +17 -0
  150. package/src/state/selectors/combiners/combineRealScaleType.ts +48 -0
  151. package/src/state/selectors/combiners/combineStackedData.ts +28 -0
  152. package/src/state/selectors/combiners/combineTooltipInteractionState.ts +86 -0
  153. package/src/state/selectors/combiners/combineTooltipPayload.ts +203 -0
  154. package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +45 -0
  155. package/src/state/selectors/containerSelectors.ts +12 -0
  156. package/src/state/selectors/dataSelectors.ts +90 -0
  157. package/src/state/selectors/funnelSelectors.ts +83 -0
  158. package/src/state/selectors/graphicalItemSelectors.ts +23 -0
  159. package/src/state/selectors/legendSelectors.ts +29 -0
  160. package/src/state/selectors/lineSelectors.ts +111 -0
  161. package/src/state/selectors/numberDomainEqualityCheck.ts +8 -0
  162. package/src/state/selectors/pickAxisId.ts +6 -0
  163. package/src/state/selectors/pickAxisType.ts +4 -0
  164. package/src/state/selectors/pieSelectors.ts +103 -0
  165. package/src/state/selectors/polarAxisSelectors.ts +202 -0
  166. package/src/state/selectors/polarGridSelectors.ts +24 -0
  167. package/src/state/selectors/polarScaleSelectors.ts +149 -0
  168. package/src/state/selectors/polarSelectors.ts +211 -0
  169. package/src/state/selectors/radarSelectors.ts +152 -0
  170. package/src/state/selectors/radialBarSelectors.ts +328 -0
  171. package/src/state/selectors/rootPropsSelectors.ts +36 -0
  172. package/src/state/selectors/scatterSelectors.ts +77 -0
  173. package/src/state/selectors/selectAllAxes.ts +10 -0
  174. package/src/state/selectors/selectChartOffset.ts +15 -0
  175. package/src/state/selectors/selectChartOffsetInternal.ts +111 -0
  176. package/src/state/selectors/selectPlotArea.ts +27 -0
  177. package/src/state/selectors/selectTooltipAxisId.ts +6 -0
  178. package/src/state/selectors/selectTooltipAxisType.ts +33 -0
  179. package/src/state/selectors/selectTooltipEventType.ts +45 -0
  180. package/src/state/selectors/selectTooltipPayloadSearcher.ts +7 -0
  181. package/src/state/selectors/selectTooltipSettings.ts +6 -0
  182. package/src/state/selectors/selectTooltipState.ts +5 -0
  183. package/src/state/selectors/tooltipSelectors.ts +690 -0
  184. package/src/state/selectors/touchSelectors.ts +29 -0
  185. package/src/state/store.ts +167 -0
  186. package/src/state/tooltipSlice.ts +289 -0
  187. package/src/state/types/AreaSettings.ts +17 -0
  188. package/src/state/types/BarSettings.ts +16 -0
  189. package/src/state/types/LineSettings.ts +12 -0
  190. package/src/state/types/PieSettings.ts +32 -0
  191. package/src/state/types/RadarSettings.ts +6 -0
  192. package/src/state/types/RadialBarSettings.ts +10 -0
  193. package/src/state/types/ScatterSettings.ts +13 -0
  194. package/src/state/types/StackedGraphicalItem.ts +33 -0
  195. package/src/state/unregisterOnCleanup.ts +26 -0
  196. package/src/state/zIndexSlice.ts +128 -0
  197. package/src/synchronisation/syncRegistry.ts +131 -0
  198. package/src/synchronisation/syncSelectors.ts +7 -0
  199. package/src/synchronisation/types.ts +42 -0
  200. package/src/synchronisation/useChartSynchronisation.tsx +372 -0
  201. package/src/types.ts +39 -0
  202. package/src/util/ActiveShapeUtils.tsx +80 -0
  203. package/src/util/BarUtils.tsx +74 -0
  204. package/src/util/CartesianUtils.ts +53 -0
  205. package/src/util/ChartUtils.ts +696 -0
  206. package/src/util/Constants.ts +42 -0
  207. package/src/util/CssPrefixUtils.ts +24 -0
  208. package/src/util/DOMUtils.ts +141 -0
  209. package/src/util/DataUtils.ts +205 -0
  210. package/src/util/FunnelUtils.tsx +37 -0
  211. package/src/util/Global.ts +15 -0
  212. package/src/util/IfOverflow.ts +17 -0
  213. package/src/util/LRUCache.ts +46 -0
  214. package/src/util/LogUtils.ts +26 -0
  215. package/src/util/PolarUtils.ts +134 -0
  216. package/src/util/RadialBarUtils.tsx +35 -0
  217. package/src/util/ReduceCSSCalc.ts +186 -0
  218. package/src/util/ShallowEqual.ts +43 -0
  219. package/src/util/TickUtils.ts +61 -0
  220. package/src/util/YAxisUtils.ts +49 -0
  221. package/src/util/adaptEventHandlers.ts +69 -0
  222. package/src/util/axisPropsAreEqual.ts +42 -0
  223. package/src/util/collectionUtils.ts +83 -0
  224. package/src/util/createCartesianCharts.tsx +101 -0
  225. package/src/util/createEventProxy.ts +24 -0
  226. package/src/util/createPolarCharts.tsx +86 -0
  227. package/src/util/cursor/getCursorPoints.ts +48 -0
  228. package/src/util/cursor/getCursorRectangle.ts +31 -0
  229. package/src/util/cursor/getRadialCursorPoints.ts +34 -0
  230. package/src/util/excludeEventProps.ts +172 -0
  231. package/src/util/getActiveCoordinate.ts +205 -0
  232. package/src/util/getAxisTypeBasedOnLayout.ts +21 -0
  233. package/src/util/getEveryNth.ts +30 -0
  234. package/src/util/getRadiusAndStrokeWidthFromDot.ts +35 -0
  235. package/src/util/getRelativeCoordinate.ts +84 -0
  236. package/src/util/getSliced.ts +21 -0
  237. package/src/util/isDomainSpecifiedByUser.ts +217 -0
  238. package/src/util/isWellBehavedNumber.ts +10 -0
  239. package/src/util/objectPath.ts +129 -0
  240. package/src/util/payload/getUniqPayload.ts +31 -0
  241. package/src/util/propsAreEqual.ts +137 -0
  242. package/src/util/resolveDefaultProps.tsx +8 -0
  243. package/src/util/round.ts +35 -0
  244. package/src/util/scale/CartesianScaleHelper.ts +72 -0
  245. package/src/util/scale/CustomScaleDefinition.ts +82 -0
  246. package/src/util/scale/RechartsScale.ts +131 -0
  247. package/src/util/scale/createCategoricalInverse.ts +83 -0
  248. package/src/util/scale/getNiceTickValues.ts +334 -0
  249. package/src/util/scale/index.ts +3 -0
  250. package/src/util/scale/util/DecimalLite.ts +194 -0
  251. package/src/util/scale/util/arithmetic.ts +56 -0
  252. package/src/util/stacks/getStackSeriesIdentifier.ts +20 -0
  253. package/src/util/stacks/stackTypes.ts +53 -0
  254. package/src/util/svgPropertiesAndEvents.ts +84 -0
  255. package/src/util/svgPropertiesNoEvents.ts +520 -0
  256. package/src/util/tooltip/translate.ts +179 -0
  257. package/src/util/typedDataKey.ts +8 -0
  258. package/src/util/types.ts +724 -0
  259. package/src/util/useAnimationId.tsx +31 -0
  260. package/src/util/useElementOffset.ts +164 -0
  261. package/src/util/useId.ts +20 -0
  262. package/src/util/usePrefersReducedMotion.ts +44 -0
  263. package/src/util/useUniqueId.ts +34 -0
  264. package/src/zIndex/DefaultZIndexes.tsx +87 -0
  265. package/src/zIndex/ZIndexLayer.tsx +126 -0
  266. package/src/zIndex/ZIndexPortal.tsx +69 -0
  267. package/src/zIndex/getZIndexFromUnknown.tsx +17 -0
  268. package/src/zIndex/zIndexSelectors.ts +46 -0
  269. package/test/_data.ts +408 -0
  270. package/test/animation/AnimationController.typed.spec.ts +53 -0
  271. package/test/animation/AnimationControllerImpl.spec.ts +271 -0
  272. package/test/animation/CSSTransitionAnimate.timing.spec.tsx +473 -0
  273. package/test/animation/JavascriptAnimate.spec.tsx +62 -0
  274. package/test/animation/RechartsAnimation.spec.ts +636 -0
  275. package/test/animation/easing.spec.ts +218 -0
  276. package/test/animation/legacyAnimationLengthChange.spec.tsx +803 -0
  277. package/test/animation/matchBy.spec.ts +467 -0
  278. package/test/animation/mockAnimationController.ts +40 -0
  279. package/test/animation/mockControllerAnimationManager.ts +143 -0
  280. package/test/animation/mockTimeoutController.ts +114 -0
  281. package/test/animation/timeoutController.spec.ts +138 -0
  282. package/test/animation/useAnimationStartSnapshot.spec.ts +147 -0
  283. package/test/animation/util.spec.ts +28 -0
  284. package/test/cartesian/Area.animation.spec.tsx +363 -0
  285. package/test/cartesian/Area.range.spec.tsx +54 -0
  286. package/test/cartesian/Area.spec.tsx +1202 -0
  287. package/test/cartesian/Area.stacked.render.spec.tsx +69 -0
  288. package/test/cartesian/Area.typed.spec.tsx +209 -0
  289. package/test/cartesian/Axis.integration.spec.tsx +158 -0
  290. package/test/cartesian/Bar/Bar.csstransition.spec.tsx +299 -0
  291. package/test/cartesian/Bar/Bar.spec.tsx +2314 -0
  292. package/test/cartesian/Bar/Bar.typed.spec.tsx +192 -0
  293. package/test/cartesian/Bar.animation.spec.tsx +426 -0
  294. package/test/cartesian/Bar.stackDomain.spec.tsx +66 -0
  295. package/test/cartesian/Bar.stacked.render.spec.tsx +53 -0
  296. package/test/cartesian/Bar.truncateByDomain.spec.tsx +237 -0
  297. package/test/cartesian/Bar.zeroDimensionFiltering.spec.tsx +336 -0
  298. package/test/cartesian/BarStack.spec.tsx +91 -0
  299. package/test/cartesian/Brush.keyboard.spec.tsx +88 -0
  300. package/test/cartesian/Brush.panorama.spec.tsx +41 -0
  301. package/test/cartesian/Brush.props.spec.tsx +63 -0
  302. package/test/cartesian/Brush.render.spec.tsx +117 -0
  303. package/test/cartesian/Brush.spec.tsx +522 -0
  304. package/test/cartesian/Brush.stacked.spec.tsx +221 -0
  305. package/test/cartesian/CartesianAxis.render.spec.tsx +50 -0
  306. package/test/cartesian/CartesianAxis.spec.tsx +396 -0
  307. package/test/cartesian/CartesianGrid.render.spec.tsx +39 -0
  308. package/test/cartesian/CartesianGrid.spec.tsx +2103 -0
  309. package/test/cartesian/ErrorBar.render.spec.tsx +69 -0
  310. package/test/cartesian/ErrorBar.spec.tsx +2414 -0
  311. package/test/cartesian/Funnel.animation.spec.tsx +241 -0
  312. package/test/cartesian/Funnel.spec.tsx +226 -0
  313. package/test/cartesian/Funnel.typed.spec.tsx +221 -0
  314. package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +627 -0
  315. package/test/cartesian/GraphicalItemClipPath.spec.tsx +427 -0
  316. package/test/cartesian/Line.animation.spec.tsx +643 -0
  317. package/test/cartesian/Line.sparseAnimationPath.spec.tsx +98 -0
  318. package/test/cartesian/Line.spec.tsx +471 -0
  319. package/test/cartesian/Line.typed.spec.tsx +152 -0
  320. package/test/cartesian/ReferenceArea.render.spec.tsx +63 -0
  321. package/test/cartesian/ReferenceArea.spec.tsx +663 -0
  322. package/test/cartesian/ReferenceArea.typed.spec.tsx +74 -0
  323. package/test/cartesian/ReferenceDot.render.spec.tsx +55 -0
  324. package/test/cartesian/ReferenceDot.spec.tsx +462 -0
  325. package/test/cartesian/ReferenceDot.typed.spec.tsx +76 -0
  326. package/test/cartesian/ReferenceLine/ReferenceLine.panorama.spec.tsx +184 -0
  327. package/test/cartesian/ReferenceLine/ReferenceLine.spec.tsx +744 -0
  328. package/test/cartesian/ReferenceLine/ReferenceLine.typed.spec.tsx +74 -0
  329. package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +399 -0
  330. package/test/cartesian/ReferenceLine.render.spec.tsx +134 -0
  331. package/test/cartesian/Scatter.animation.spec.tsx +381 -0
  332. package/test/cartesian/Scatter.render.spec.tsx +61 -0
  333. package/test/cartesian/Scatter.spec.tsx +406 -0
  334. package/test/cartesian/Scatter.typed.spec.tsx +153 -0
  335. package/test/cartesian/XAxis/XAxis.barSize.spec.tsx +336 -0
  336. package/test/cartesian/XAxis/XAxis.brush.spec.tsx +266 -0
  337. package/test/cartesian/XAxis/XAxis.categorydomain.spec.tsx +872 -0
  338. package/test/cartesian/XAxis/XAxis.dataKey.spec.tsx +86 -0
  339. package/test/cartesian/XAxis/XAxis.datatypes.spec.tsx +127 -0
  340. package/test/cartesian/XAxis/XAxis.hide.spec.tsx +106 -0
  341. package/test/cartesian/XAxis/XAxis.multiaxis.spec.tsx +336 -0
  342. package/test/cartesian/XAxis/XAxis.numberdomain.spec.tsx +1466 -0
  343. package/test/cartesian/XAxis/XAxis.padding.spec.tsx +758 -0
  344. package/test/cartesian/XAxis/XAxis.padding_clip.spec.tsx +65 -0
  345. package/test/cartesian/XAxis/XAxis.state.spec.tsx +355 -0
  346. package/test/cartesian/XAxis/XAxis.tick.spec.tsx +493 -0
  347. package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +233 -0
  348. package/test/cartesian/XAxis/XAxis.type.spec.tsx +107 -0
  349. package/test/cartesian/XAxis/XAxis.typed.spec.tsx +102 -0
  350. package/test/cartesian/XAxis/XAxis.vertical.spec.tsx +265 -0
  351. package/test/cartesian/XAxis.tickFormatter.spec.tsx +54 -0
  352. package/test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx +230 -0
  353. package/test/cartesian/YAxis/YAxis.7362.spec.tsx +104 -0
  354. package/test/cartesian/YAxis/YAxis.interval-zero.spec.tsx +88 -0
  355. package/test/cartesian/YAxis/YAxis.label.spec.tsx +219 -0
  356. package/test/cartesian/YAxis/YAxis.spec.tsx +1595 -0
  357. package/test/cartesian/YAxis/YAxis.tick.spec.tsx +428 -0
  358. package/test/cartesian/YAxis/YAxis.tickFormatter.spec.tsx +54 -0
  359. package/test/cartesian/YAxis/YAxis.ticks.spec.tsx +263 -0
  360. package/test/cartesian/YAxis/YAxis.type.spec.tsx +107 -0
  361. package/test/cartesian/YAxis/YAxis.typed.spec.tsx +102 -0
  362. package/test/cartesian/ZAxis.spec.tsx +300 -0
  363. package/test/cartesian/ZAxis.typed.spec.tsx +33 -0
  364. package/test/cartesian/__snapshots__/Brush.spec.tsx.snap +5 -0
  365. package/test/cartesian/axisLineAndStroke.spec.tsx +72 -0
  366. package/test/cartesian/getCartesianPosition.spec.ts +907 -0
  367. package/test/cartesian/getEquidistantTicks.spec.ts +88 -0
  368. package/test/cartesian/getTicks.spec.ts +378 -0
  369. package/test/cartesian/miscFeatureGaps.spec.tsx +89 -0
  370. package/test/cartesian/useAnimatedLineLength.spec.ts +168 -0
  371. package/test/chart/AccessibilityLayer.spec.tsx +569 -0
  372. package/test/chart/AccessibilityScans.spec.tsx +286 -0
  373. package/test/chart/AreaChart.spec.tsx +409 -0
  374. package/test/chart/AreaChart.stacked.spec.tsx +1407 -0
  375. package/test/chart/AreaChart.typed.spec.tsx +39 -0
  376. package/test/chart/BarChart.spec.tsx +3719 -0
  377. package/test/chart/BarChart.typed.spec.tsx +60 -0
  378. package/test/chart/CategoricalChart.spec.tsx +255 -0
  379. package/test/chart/ComposedChart.spec.tsx +199 -0
  380. package/test/chart/ComposedChart.typed.spec.tsx +39 -0
  381. package/test/chart/FunnelChart.spec.tsx +215 -0
  382. package/test/chart/FunnelChart.typed.spec.tsx +39 -0
  383. package/test/chart/LineChart.multiseries.spec.tsx +50 -0
  384. package/test/chart/LineChart.smoke.spec.tsx +50 -0
  385. package/test/chart/LineChart.spec.tsx +930 -0
  386. package/test/chart/LineChart.typed.spec.tsx +39 -0
  387. package/test/chart/NicheChartTooltip.spec.tsx +81 -0
  388. package/test/chart/PieChart.spec.tsx +793 -0
  389. package/test/chart/PieChart.typed.spec.tsx +39 -0
  390. package/test/chart/RadarChart.spec.tsx +530 -0
  391. package/test/chart/RadarChart.typed.spec.tsx +39 -0
  392. package/test/chart/RadialBarChart.5966.spec.tsx +48 -0
  393. package/test/chart/RadialBarChart.spec.tsx +679 -0
  394. package/test/chart/RadialBarChart.typed.spec.tsx +39 -0
  395. package/test/chart/RechartsWrapper.spec.tsx +83 -0
  396. package/test/chart/Sankey.content.spec.tsx +46 -0
  397. package/test/chart/Sankey.spec.tsx +952 -0
  398. package/test/chart/Sankey.typed.spec.tsx +29 -0
  399. package/test/chart/ScatterChart.spec.tsx +2613 -0
  400. package/test/chart/ScatterChart.typed.spec.tsx +39 -0
  401. package/test/chart/SunburstChart.spec.tsx +146 -0
  402. package/test/chart/Treemap.animation.spec.tsx +52 -0
  403. package/test/chart/Treemap.spec.tsx +1003 -0
  404. package/test/chart/Treemap.typed.spec.tsx +26 -0
  405. package/test/chart/chartEvents.spec.tsx +127 -0
  406. package/test/chart/responsive.spec.tsx +620 -0
  407. package/test/component/Cell.render.spec.tsx +155 -0
  408. package/test/component/Cell.spec.tsx +12 -0
  409. package/test/component/Cursor.spec.tsx +186 -0
  410. package/test/component/DefaultTooltipContent.spec.tsx +102 -0
  411. package/test/component/Label.render.spec.tsx +63 -0
  412. package/test/component/Label.spec.tsx +686 -0
  413. package/test/component/Label.typed.spec.tsx +46 -0
  414. package/test/component/LabelList.spec.tsx +188 -0
  415. package/test/component/Legend.itemSorter.spec.tsx +704 -0
  416. package/test/component/Legend.render.spec.tsx +92 -0
  417. package/test/component/Legend.spec.tsx +2213 -0
  418. package/test/component/Legend.typed.spec.tsx +22 -0
  419. package/test/component/ResponsiveContainer.spec.tsx +523 -0
  420. package/test/component/ResponsiveContainerDataTest.spec.tsx +51 -0
  421. package/test/component/Text.spec.tsx +415 -0
  422. package/test/component/Text.typed.spec.tsx +46 -0
  423. package/test/component/Tooltip/ActiveDot.spec.tsx +370 -0
  424. package/test/component/Tooltip/Tooltip.animation.spec.tsx +209 -0
  425. package/test/component/Tooltip/Tooltip.content.spec.tsx +128 -0
  426. package/test/component/Tooltip/Tooltip.formatter.spec.tsx +152 -0
  427. package/test/component/Tooltip/Tooltip.includeHidden.spec.tsx +79 -0
  428. package/test/component/Tooltip/Tooltip.multipleDataArrays.spec.tsx +165 -0
  429. package/test/component/Tooltip/Tooltip.offset.spec.tsx +113 -0
  430. package/test/component/Tooltip/Tooltip.state.spec.tsx +74 -0
  431. package/test/component/Tooltip/Tooltip.sync.spec.tsx +639 -0
  432. package/test/component/Tooltip/defaultIndex.spec.tsx +227 -0
  433. package/test/component/Tooltip/graphicalItem.formatter.spec.tsx +138 -0
  434. package/test/component/Tooltip/itemSorter.spec.tsx +2815 -0
  435. package/test/component/Tooltip/tooltipEventType.spec.tsx +344 -0
  436. package/test/component/Tooltip/tooltipMouseHoverSelectors.ts +41 -0
  437. package/test/component/Tooltip/tooltipTestHelpers.tsx +162 -0
  438. package/test/component/Tooltip.defaultIndex.spec.tsx +48 -0
  439. package/test/component/Tooltip.hover.spec.tsx +61 -0
  440. package/test/component/Tooltip.item.spec.tsx +54 -0
  441. package/test/component/Tooltip.keyboard.spec.tsx +51 -0
  442. package/test/component/Tooltip.payload.spec.tsx +1716 -0
  443. package/test/component/Tooltip.touch.spec.tsx +39 -0
  444. package/test/component/Tooltip.visibility.spec.tsx +1889 -0
  445. package/test/component/TooltipBoundingBox.spec.tsx +89 -0
  446. package/test/component/responsiveContainerUtils.spec.ts +205 -0
  447. package/test/container/ClipPath.spec.tsx +602 -0
  448. package/test/container/chartDimensions.spec.tsx +368 -0
  449. package/test/context/chartLayoutContext.spec.tsx +378 -0
  450. package/test/helper/ExpectAxisDomain.tsx +27 -0
  451. package/test/helper/assertNotNull.ts +6 -0
  452. package/test/helper/assertZIndexLayerOrder.ts +19 -0
  453. package/test/helper/createSelectorTestCase.tsx +176 -0
  454. package/test/helper/expectAnimatedPieAngles.ts +100 -0
  455. package/test/helper/expectAnimatedPiePaths.ts +78 -0
  456. package/test/helper/expectAreaCurve.ts +15 -0
  457. package/test/helper/expectAxisTicks.ts +48 -0
  458. package/test/helper/expectBars.ts +54 -0
  459. package/test/helper/expectFunctionReturning.ts +58 -0
  460. package/test/helper/expectLabel.ts +32 -0
  461. package/test/helper/expectLastCalledWith.ts +48 -0
  462. package/test/helper/expectLine.ts +20 -0
  463. package/test/helper/expectPieSectors.ts +80 -0
  464. package/test/helper/expectScale.ts +37 -0
  465. package/test/helper/expectScatterPoints.ts +52 -0
  466. package/test/helper/expectStackGroups.ts +144 -0
  467. package/test/helper/mockAxes.ts +22 -0
  468. package/test/helper/mockGetBoundingClientRect.ts +66 -0
  469. package/test/helper/mockHTMLElementProperty.ts +19 -0
  470. package/test/helper/mockTouchingElement.ts +27 -0
  471. package/test/helper/offsetHelpers.ts +19 -0
  472. package/test/helper/parameterizedTestCases.tsx +99 -0
  473. package/test/helper/produceState.ts +32 -0
  474. package/test/helper/render.ts +7 -0
  475. package/test/helper/selectorTestHelpers.tsx +63 -0
  476. package/test/helper/trim.spec.ts +35 -0
  477. package/test/helper/trim.ts +11 -0
  478. package/test/hooks/useActiveTooltipDataPoints.spec.tsx +358 -0
  479. package/test/hooks/useAxisDomain.spec.tsx +361 -0
  480. package/test/hooks/useAxisScale.spec.tsx +283 -0
  481. package/test/hooks/useAxisTicks.spec.tsx +130 -0
  482. package/test/hooks/useOffset.spec.tsx +248 -0
  483. package/test/hooks/useTooltipStateHooks.spec.tsx +109 -0
  484. package/test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx +135 -0
  485. package/test/polar/Pie/Pie.spec.tsx +784 -0
  486. package/test/polar/Pie/Pie.typed.spec.tsx +78 -0
  487. package/test/polar/Pie.animation.spec.tsx +529 -0
  488. package/test/polar/PieWithLegend.animation.spec.tsx +142 -0
  489. package/test/polar/PolarAngleAxis/PolarAngleAxis.events.spec.tsx +76 -0
  490. package/test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx +2079 -0
  491. package/test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx +102 -0
  492. package/test/polar/PolarAngleAxis.render.spec.tsx +79 -0
  493. package/test/polar/PolarGrid.render.spec.tsx +75 -0
  494. package/test/polar/PolarGrid.spec.tsx +918 -0
  495. package/test/polar/PolarLegendPerRow.render.spec.tsx +85 -0
  496. package/test/polar/PolarRadiusAxis.events.spec.tsx +65 -0
  497. package/test/polar/PolarRadiusAxis.render.spec.tsx +52 -0
  498. package/test/polar/PolarRadiusAxis.spec.tsx +991 -0
  499. package/test/polar/PolarRadiusAxis.typed.spec.tsx +84 -0
  500. package/test/polar/PolarTooltipLegend.render.spec.tsx +80 -0
  501. package/test/polar/Radar.animation.spec.tsx +570 -0
  502. package/test/polar/Radar.render.spec.tsx +71 -0
  503. package/test/polar/Radar.spec.tsx +265 -0
  504. package/test/polar/Radar.typed.spec.tsx +119 -0
  505. package/test/polar/RadialBar/RadialBar.spec.tsx +1521 -0
  506. package/test/polar/RadialBar/RadialBar.typed.spec.tsx +132 -0
  507. package/test/polar/RadialBar.animation.spec.tsx +375 -0
  508. package/test/polar/RadialBar.render.spec.tsx +66 -0
  509. package/test/polar/RadialBar.stacked.spec.tsx +57 -0
  510. package/test/setup.ts +84 -0
  511. package/test/shape/ActiveShape.spec.tsx +181 -0
  512. package/test/shape/Cross.spec.tsx +60 -0
  513. package/test/shape/Cross.typed.spec.tsx +26 -0
  514. package/test/shape/Curve.spec.tsx +368 -0
  515. package/test/shape/Curve.typed.spec.tsx +69 -0
  516. package/test/shape/Dot.spec.tsx +73 -0
  517. package/test/shape/Dot.typed.spec.tsx +30 -0
  518. package/test/shape/Polygon.spec.tsx +357 -0
  519. package/test/shape/Polygon.typed.spec.tsx +28 -0
  520. package/test/shape/Rectangle.animation.spec.tsx +451 -0
  521. package/test/shape/Rectangle.spec.tsx +68 -0
  522. package/test/shape/Rectangle.typed.spec.tsx +24 -0
  523. package/test/shape/Sector.spec.tsx +76 -0
  524. package/test/shape/Sector.typed.spec.tsx +24 -0
  525. package/test/shape/Symbols.spec.tsx +43 -0
  526. package/test/shape/Symbols.typed.spec.tsx +24 -0
  527. package/test/shape/Trapezoid.spec.tsx +50 -0
  528. package/test/shape/Trapezoid.typed.spec.tsx +24 -0
  529. package/test/shape/__snapshots__/Cross.spec.tsx.snap +62 -0
  530. package/test/shape/__snapshots__/Curve.spec.tsx.snap +460 -0
  531. package/test/shape/__snapshots__/Polygon.spec.tsx.snap +58 -0
  532. package/test/shape/__snapshots__/Rectangle.spec.tsx.snap +117 -0
  533. package/test/shape/__snapshots__/Sector.spec.tsx.snap +71 -0
  534. package/test/shape/__snapshots__/Trapezoid.spec.tsx.snap +64 -0
  535. package/test/state/chartDataSlice.spec.ts +53 -0
  536. package/test/state/externalEventsMiddleware.spec.ts +178 -0
  537. package/test/state/graphicalItemsSlice.spec.ts +92 -0
  538. package/test/state/hooks.spec.tsx +68 -0
  539. package/test/state/legendSlice.spec.ts +44 -0
  540. package/test/state/mouseEventsMiddleware.spec.ts +75 -0
  541. package/test/state/optionsSlice.spec.ts +19 -0
  542. package/test/state/reduxDevtoolsJsonStringifyReplacer.spec.ts +25 -0
  543. package/test/state/referenceElementsSlice.spec.ts +84 -0
  544. package/test/state/selectors/areaSelectors.spec.tsx +77 -0
  545. package/test/state/selectors/axisSelectors.spec.tsx +1418 -0
  546. package/test/state/selectors/barStackSelectors.spec.tsx +752 -0
  547. package/test/state/selectors/brushSelectors.spec.tsx +30 -0
  548. package/test/state/selectors/cartesianAxisSlice.spec.ts +96 -0
  549. package/test/state/selectors/combineNiceTicks.spec.ts +207 -0
  550. package/test/state/selectors/combiners/combineActiveTooltipIndex.spec.ts +61 -0
  551. package/test/state/selectors/combiners/combineAllBarPositions.spec.ts +39 -0
  552. package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +56 -0
  553. package/test/state/selectors/combiners/combineDisplayedStackedData.spec.ts +123 -0
  554. package/test/state/selectors/combiners/combineRealScaleType.spec.ts +80 -0
  555. package/test/state/selectors/containerSelectors.spec.tsx +168 -0
  556. package/test/state/selectors/dataSelectors.spec.tsx +136 -0
  557. package/test/state/selectors/legendSelectors.spec.tsx +113 -0
  558. package/test/state/selectors/lineSelectors.spec.tsx +60 -0
  559. package/test/state/selectors/pieSelectors.spec.tsx +72 -0
  560. package/test/state/selectors/radarSelectors.spec.tsx +496 -0
  561. package/test/state/selectors/rootPropsSelectors.spec.tsx +169 -0
  562. package/test/state/selectors/scatterSelectors.spec.tsx +47 -0
  563. package/test/state/selectors/selectActiveTooltipIndex.spec.tsx +234 -0
  564. package/test/state/selectors/selectAllAxes.spec.tsx +18 -0
  565. package/test/state/selectors/selectAxisDomain.spec.tsx +21 -0
  566. package/test/state/selectors/selectAxisDomainIncludingNiceTicks.spec.tsx +19 -0
  567. package/test/state/selectors/selectAxisRangeWithReverse.spec.tsx +22 -0
  568. package/test/state/selectors/selectAxisScale.spec.tsx +91 -0
  569. package/test/state/selectors/selectBarRectangles.stackOffset.spec.tsx +503 -0
  570. package/test/state/selectors/selectBaseAxis.spec.tsx +56 -0
  571. package/test/state/selectors/selectCartesianItemsSettings.spec.tsx +57 -0
  572. package/test/state/selectors/selectChartOffset.spec.tsx +26 -0
  573. package/test/state/selectors/selectDisplayedData.spec.tsx +282 -0
  574. package/test/state/selectors/selectIsTooltipActive.spec.tsx +231 -0
  575. package/test/state/selectors/selectNumericalDomain.spec.tsx +21 -0
  576. package/test/state/selectors/selectRealScaleType.spec.tsx +19 -0
  577. package/test/state/selectors/selectStackGroups.spec.tsx +322 -0
  578. package/test/state/selectors/selectXAxisPosition.spec.tsx +22 -0
  579. package/test/state/selectors/selectYAxisPosition.spec.tsx +22 -0
  580. package/test/state/selectors/selectors.spec.tsx +1613 -0
  581. package/test/state/throttling.spec.ts +200 -0
  582. package/test/state/zIndexSlice.spec.ts +85 -0
  583. package/test/synchronisation/useChartSynchronisation.spec.tsx +225 -0
  584. package/test/util/BarUtils.spec.ts +39 -0
  585. package/test/util/CartesianUtils/CartesianUtils.spec.ts +261 -0
  586. package/test/util/CartesianUtils/rectWithPoints.spec.ts +48 -0
  587. package/test/util/ChartUtils/ChartUtils.spec.ts +491 -0
  588. package/test/util/ChartUtils/appendOffsetOfLegend.spec.ts +136 -0
  589. package/test/util/ChartUtils/appendOffsetOfLegend.spec.tsx +133 -0
  590. package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +83 -0
  591. package/test/util/ChartUtils/getStackedData.spec.ts +416 -0
  592. package/test/util/ChartUtils/truncateByDomain.spec.ts +70 -0
  593. package/test/util/DataUtils.spec.ts +385 -0
  594. package/test/util/DomUtils.spec.tsx +117 -0
  595. package/test/util/FunnelUtils.spec.tsx +70 -0
  596. package/test/util/Global.spec.ts +11 -0
  597. package/test/util/LRUCache.spec.ts +81 -0
  598. package/test/util/LogUtils.spec.ts +45 -0
  599. package/test/util/PolarUtils.spec.ts +66 -0
  600. package/test/util/ReduceCssCalcPrototype.spec.ts +141 -0
  601. package/test/util/ShallowEqual.spec.ts +102 -0
  602. package/test/util/TickUtils.spec.ts +29 -0
  603. package/test/util/axisPropsAreEqual.spec.ts +93 -0
  604. package/test/util/createChartHelpers.spec.tsx +210 -0
  605. package/test/util/cursor/getCursorPoints.spec.ts +136 -0
  606. package/test/util/cursor/getCursorRectangle.spec.ts +50 -0
  607. package/test/util/cursor/getRadialCursorPoints.spec.ts +36 -0
  608. package/test/util/errorValue.spec.ts +69 -0
  609. package/test/util/getEveryNth.spec.ts +39 -0
  610. package/test/util/getRadiusAndStrokeWidthFromDot.spec.ts +51 -0
  611. package/test/util/getRelativeCoordinate.spec.ts +250 -0
  612. package/test/util/getSliced.spec.ts +45 -0
  613. package/test/util/isDomainSpecifiedByUser.spec.ts +207 -0
  614. package/test/util/isWellBehavedNumber.spec.ts +54 -0
  615. package/test/util/payload/getUniqPayload.spec.ts +56 -0
  616. package/test/util/propsAreEqual.spec.ts +75 -0
  617. package/test/util/round.spec.ts +112 -0
  618. package/test/util/scale/arithmetic.spec.ts +61 -0
  619. package/test/util/scale/createCategoricalInverse.spec.ts +84 -0
  620. package/test/util/scale/getNiceTickValues.spec.ts +421 -0
  621. package/test/util/scale/getTickValuesFixedDomain.spec.ts +155 -0
  622. package/test/util/svgPropertiesAndEvents.spec.tsx +206 -0
  623. package/test/util/svgPropertiesNoEvents.spec.tsx +228 -0
  624. package/test/util/tooltip/translate.spec.ts +396 -0
  625. package/test/util/useAnimationId.spec.tsx +59 -0
  626. package/test/util/useElementOffset.spec.tsx +173 -0
  627. package/test/util/usePrefersReducedMotion.spec.ts +54 -0
  628. package/test/util/useUniqueId.spec.ts +99 -0
  629. package/test/utils/diagnostics-allowlist.ts +18 -0
  630. package/test/utils/diagnostics.ts +58 -0
  631. package/test/zIndex/AllZIndexPortals.spec.tsx +83 -0
  632. package/test/zIndex/DefaultZIndexes.spec.ts +80 -0
  633. package/test/zIndex/DynamicZIndex.spec.tsx +102 -0
  634. package/test/zIndex/ZIndexLayer.portalOwner.spec.tsx +125 -0
  635. package/test/zIndex/componentZIndex.spec.tsx +255 -0
  636. package/test/zIndex/getZIndexFromUnknown.spec.ts +51 -0
  637. package/test/zIndex/multiChartZIndexIsolation.spec.tsx +90 -0
  638. package/test/zIndex/zIndexSelectors.spec.ts +172 -0
  639. package/tsconfig.json +11 -0
@@ -0,0 +1,992 @@
1
+ // Ported from recharts 3.8.1 src/chart/Sankey.tsx (commit 7a23854).
2
+ //
3
+ // A flow diagram: nodes (Rectangles) connected by value-weighted link ribbons
4
+ // (cubic-Bézier paths). The layout (computeData) is recharts' custom iterative
5
+ // relaxation — getNodesTree assigns depth/x, updateYOfTree sizes by value,
6
+ // resolveCollisions + relax{Left,Right} settle the y positions, updateYOfLinks
7
+ // stacks link endpoints — ported verbatim (the in-place mutation operates on the
8
+ // working copies the maps create, so it stays local). Self-contained — owns its store.
9
+ // Includes the v3.9.1 layout fixes: updateDepthOfTargets prunes non-growing depth
10
+ // recursion (52a2a89) and resolveNodeLinkCollisions nudges nodes out of
11
+ // skipped-depth link bands (0663afe).
12
+ //
13
+ // Solid deviations: `resolveDefaultProps`→`merge`; `useAppDispatch`→`useAppStore`;
14
+ // `RegisterGraphicalItemId`→`useUniqueId`; es-toolkit `maxBy`/`sumBy`/`get`→inline;
15
+ // the layout output is flattened into node/link prop arrays rendered by a single
16
+ // `<For>` each (For-item reads → no STRICT_READ). Custom function-form node/link
17
+ // renderers ARE wired (element form is N/A — no cloneElement). `nameKey` resolves
18
+ // through getValueByDataKey in the payload searcher (reference parity).
19
+ // NON-GAPS: the reference Sankey has NO animation and hardcodes responsive={false}
20
+ // on its wrapper (ResponsiveContainer sizing flows via the wrapper context).
21
+ import { createEffect, createMemo, For, merge, Show } from "solid-js";
22
+ import type { JSX } from "@solidjs/web";
23
+ import { Surface } from "../container/Surface";
24
+ import { Layer } from "../container/Layer";
25
+ import { Rectangle } from "../shape/Rectangle";
26
+ import { RechartsWrapper } from "./RechartsWrapper";
27
+ import { RechartsStoreProvider } from "../state/RechartsStoreProvider";
28
+ import { ReportChartMargin, useChartHeight, useChartWidth } from "../context/chartLayoutContext";
29
+ import { ReportEventSettings } from "../state/ReportEventSettings";
30
+ import { SetTooltipEntrySettings } from "../state/SetTooltipEntrySettings";
31
+ import { useAppStore } from "../state/hooks";
32
+ import { useUniqueId } from "../util/useUniqueId";
33
+ import { isNotNil } from "../util/DataUtils";
34
+ import { getValueByDataKey } from "../util/ChartUtils";
35
+ import type { ChartOptions } from "../state/optionsSlice";
36
+ import type {
37
+ TooltipIndex,
38
+ TooltipPayloadConfiguration,
39
+ TooltipPayloadSearcher,
40
+ } from "../state/tooltipSlice";
41
+ import type { RechartsRootState } from "../state/store";
42
+ import type {
43
+ Coordinate,
44
+ DataKey,
45
+ EventThrottlingProps,
46
+ Margin,
47
+ MousePointer,
48
+ Percent,
49
+ } from "../util/types";
50
+
51
+ // ---- Types ----
52
+ interface LinkDataItem {
53
+ source: number;
54
+ target: number;
55
+ value: number;
56
+ }
57
+ interface LinkDataItemDy extends LinkDataItem {
58
+ dy: number;
59
+ sy?: number;
60
+ ty?: number;
61
+ }
62
+
63
+ export interface SankeyNode {
64
+ dx: number;
65
+ dy: number;
66
+ name: string;
67
+ value: number;
68
+ x: number;
69
+ y: number;
70
+ depth: number;
71
+ targetNodes: number[];
72
+ targetLinks: number[];
73
+ sourceNodes: number[];
74
+ sourceLinks: number[];
75
+ [k: string]: unknown;
76
+ }
77
+
78
+ export interface SankeyLink {
79
+ target: number;
80
+ source: number;
81
+ value: number;
82
+ sy: number;
83
+ dy: number;
84
+ ty: number;
85
+ }
86
+
87
+ export interface SankeyData {
88
+ nodes: ReadonlyArray<{ name?: string; [k: string]: unknown }>;
89
+ links: LinkDataItem[];
90
+ }
91
+
92
+ export interface NodeProps {
93
+ x: number;
94
+ y: number;
95
+ width: number;
96
+ height: number;
97
+ index: number;
98
+ payload: SankeyNode;
99
+ }
100
+
101
+ export interface LinkProps {
102
+ sourceX: number;
103
+ targetX: number;
104
+ sourceY: number;
105
+ targetY: number;
106
+ sourceControlX: number;
107
+ targetControlX: number;
108
+ sourceRelativeY: number;
109
+ targetRelativeY: number;
110
+ linkWidth: number;
111
+ index: number;
112
+ // payload is the link with source/target replaced by the resolved node objects.
113
+ payload: {
114
+ source: SankeyNode;
115
+ target: SankeyNode;
116
+ value: number;
117
+ dy: number;
118
+ sy?: number;
119
+ ty?: number;
120
+ };
121
+ }
122
+
123
+ export type SankeyNodeProps = NodeProps;
124
+ export type SankeyLinkProps = LinkProps;
125
+ export type SankeyElementType = "node" | "link";
126
+
127
+ /**
128
+ * The type of the Sankey `node` prop — recharts parity name. Upstream also accepts
129
+ * a ReactElement / props-object form; the Solid port supports the function form.
130
+ */
131
+ export type SankeyNodeOptions = (props: NodeProps) => JSX.Element;
132
+
133
+ type SankeyVerticalAlign = "justify" | "top";
134
+ type SankeyHorizontalAlign = "left" | "justify";
135
+
136
+ const isObj = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v != null;
137
+ const isArr = (v: unknown): v is ReadonlyArray<unknown> => Array.isArray(v);
138
+
139
+ // ---- Pure layout (ported verbatim) ----
140
+ const interpolationGenerator = (a: number, b: number) => {
141
+ const ka = +a;
142
+ const kb = b - ka;
143
+ return (t: number) => ka + kb * t;
144
+ };
145
+ const centerY = (node: SankeyNode): number => node.y + node.dy / 2;
146
+
147
+ const cubicValue = (
148
+ start: number,
149
+ control1: number,
150
+ control2: number,
151
+ end: number,
152
+ t: number,
153
+ ): number => {
154
+ const inverseT = 1 - t;
155
+ return (
156
+ inverseT ** 3 * start +
157
+ 3 * inverseT ** 2 * t * control1 +
158
+ 3 * inverseT * t ** 2 * control2 +
159
+ t ** 3 * end
160
+ );
161
+ };
162
+ const getValue = (entry: { value?: number } | undefined): number => (entry && entry.value) || 0;
163
+ const getSumOfIds = (links: ReadonlyArray<LinkDataItem>, ids: number[]): number =>
164
+ ids.reduce((result, id) => result + getValue(links[id]), 0);
165
+ const sumBy = <T,>(arr: ReadonlyArray<T>, fn: (x: T) => number): number =>
166
+ arr.reduce((s, x) => s + fn(x), 0);
167
+
168
+ const getSumWithWeightedSource = (
169
+ tree: ReadonlyArray<SankeyNode>,
170
+ links: ReadonlyArray<LinkDataItemDy>,
171
+ ids: number[],
172
+ ): number =>
173
+ ids.reduce((result, id) => {
174
+ const link = links[id];
175
+ if (link == null) {
176
+ return result;
177
+ }
178
+ const sourceNode = tree[link.source];
179
+ if (sourceNode == null) {
180
+ return result;
181
+ }
182
+ return result + centerY(sourceNode) * getValue(links[id]);
183
+ }, 0);
184
+
185
+ const getSumWithWeightedTarget = (
186
+ tree: ReadonlyArray<SankeyNode>,
187
+ links: ReadonlyArray<LinkDataItemDy>,
188
+ ids: ReadonlyArray<number>,
189
+ ): number =>
190
+ ids.reduce((result, id) => {
191
+ const link = links[id];
192
+ if (link == null) {
193
+ return result;
194
+ }
195
+ const targetNode = tree[link.target];
196
+ if (targetNode == null) {
197
+ return result;
198
+ }
199
+ return result + centerY(targetNode) * getValue(links[id]);
200
+ }, 0);
201
+
202
+ const ascendingY = (a: { y: number }, b: { y: number }): number => a.y - b.y;
203
+
204
+ const searchTargetsAndSources = (links: LinkDataItem[], id: number) => {
205
+ const sourceNodes: number[] = [];
206
+ const sourceLinks: number[] = [];
207
+ const targetNodes: number[] = [];
208
+ const targetLinks: number[] = [];
209
+ for (let i = 0, len = links.length; i < len; i++) {
210
+ const link = links[i];
211
+ if (link?.source === id) {
212
+ targetNodes.push(link.target);
213
+ targetLinks.push(i);
214
+ }
215
+ if (link?.target === id) {
216
+ sourceNodes.push(link.source);
217
+ sourceLinks.push(i);
218
+ }
219
+ }
220
+ return { sourceNodes, sourceLinks, targetLinks, targetNodes };
221
+ };
222
+
223
+ const updateDepthOfTargets = (tree: SankeyNode[], curNode: SankeyNode): void => {
224
+ const { targetNodes } = curNode;
225
+ for (let i = 0, len = targetNodes.length; i < len; i++) {
226
+ const targetNode = targetNodes[i];
227
+ if (targetNode == null) {
228
+ continue;
229
+ }
230
+ const target = tree[targetNode];
231
+ if (target) {
232
+ const newDepth = curNode.depth + 1;
233
+ /*
234
+ * Only recurse when the depth grows. Depth is the longest path to a node, so once it stops
235
+ * increasing the subtree is already up to date; without this guard every path through the
236
+ * graph is walked separately, which explodes combinatorially on dense graphs.
237
+ */
238
+ if (newDepth > target.depth) {
239
+ target.depth = newDepth;
240
+ updateDepthOfTargets(tree, target);
241
+ }
242
+ }
243
+ }
244
+ };
245
+
246
+ const getNodesTree = (
247
+ { nodes, links }: SankeyData,
248
+ width: number,
249
+ nodeWidth: number,
250
+ align: SankeyHorizontalAlign,
251
+ ): { tree: SankeyNode[]; maxDepth: number } => {
252
+ const tree: SankeyNode[] = nodes.map((entry, index): SankeyNode => {
253
+ const result = searchTargetsAndSources(links, index);
254
+ return {
255
+ ...entry,
256
+ ...result,
257
+ name: typeof entry.name === "string" ? entry.name : "",
258
+ x: 0,
259
+ y: 0,
260
+ dx: 0,
261
+ dy: 0,
262
+ value: Math.max(
263
+ getSumOfIds(links, result.sourceLinks),
264
+ getSumOfIds(links, result.targetLinks),
265
+ ),
266
+ depth: 0,
267
+ };
268
+ });
269
+ for (let i = 0, len = tree.length; i < len; i++) {
270
+ const node = tree[i];
271
+ if (node != null && !node.sourceNodes.length) {
272
+ updateDepthOfTargets(tree, node);
273
+ }
274
+ }
275
+ const maxDepth = tree.reduce((m, e) => (e.depth > m ? e.depth : m), 0);
276
+ if (maxDepth >= 1) {
277
+ const childWidth = (width - nodeWidth) / maxDepth;
278
+ for (let i = 0, len = tree.length; i < len; i++) {
279
+ const node = tree[i];
280
+ if (node == null) {
281
+ continue;
282
+ }
283
+ if (!node.targetNodes.length && align === "justify") {
284
+ node.depth = maxDepth;
285
+ }
286
+ node.x = node.depth * childWidth;
287
+ node.dx = nodeWidth;
288
+ }
289
+ }
290
+ return { tree, maxDepth };
291
+ };
292
+
293
+ const getDepthTree = (tree: SankeyNode[]): SankeyNode[][] => {
294
+ const result: SankeyNode[][] = [];
295
+ for (let i = 0, len = tree.length; i < len; i++) {
296
+ const node = tree[i];
297
+ if (node == null) {
298
+ continue;
299
+ }
300
+ if (!result[node.depth]) {
301
+ result[node.depth] = [];
302
+ }
303
+ result[node.depth]?.push(node);
304
+ }
305
+ return result;
306
+ };
307
+
308
+ const updateYOfTree = (
309
+ depthTree: SankeyNode[][],
310
+ height: number,
311
+ nodePadding: number,
312
+ links: ReadonlyArray<LinkDataItem>,
313
+ verticalAlign: SankeyVerticalAlign,
314
+ ): LinkDataItemDy[] => {
315
+ let yRatio = Math.min(
316
+ ...depthTree.map((nodes) => {
317
+ const sum = sumBy(nodes, getValue);
318
+ return sum === 0 ? Infinity : (height - (nodes.length - 1) * nodePadding) / sum;
319
+ }),
320
+ );
321
+ if (yRatio === Infinity) {
322
+ yRatio = 0;
323
+ }
324
+ for (let d = 0, maxDepth = depthTree.length; d < maxDepth; d++) {
325
+ const nodes = depthTree[d];
326
+ if (nodes == null) {
327
+ continue;
328
+ }
329
+ if (verticalAlign === "top") {
330
+ let currentY = 0;
331
+ for (const node of nodes) {
332
+ node.dy = node.value * yRatio;
333
+ node.y = currentY;
334
+ currentY += node.dy + nodePadding;
335
+ }
336
+ } else {
337
+ for (let i = 0, len = nodes.length; i < len; i++) {
338
+ const node = nodes[i];
339
+ if (node == null) {
340
+ continue;
341
+ }
342
+ node.y = i;
343
+ node.dy = node.value * yRatio;
344
+ }
345
+ }
346
+ }
347
+ return links.map((link): LinkDataItemDy => ({ ...link, dy: getValue(link) * yRatio }));
348
+ };
349
+
350
+ const resolveCollisions = (
351
+ depthTree: SankeyNode[][],
352
+ height: number,
353
+ nodePadding: number,
354
+ sort = true,
355
+ ): void => {
356
+ for (const nodes of depthTree) {
357
+ if (nodes == null) {
358
+ continue;
359
+ }
360
+ const n = nodes.length;
361
+ if (sort) {
362
+ nodes.sort(ascendingY);
363
+ }
364
+ let y0 = 0;
365
+ for (let j = 0; j < n; j++) {
366
+ const node = nodes[j];
367
+ if (node == null) {
368
+ continue;
369
+ }
370
+ const dy = y0 - node.y;
371
+ if (dy > 0) {
372
+ node.y += dy;
373
+ }
374
+ y0 = node.y + node.dy + nodePadding;
375
+ }
376
+ y0 = height + nodePadding;
377
+ for (let j = n - 1; j >= 0; j--) {
378
+ const node = nodes[j];
379
+ if (node == null) {
380
+ continue;
381
+ }
382
+ const dy = node.y + node.dy + nodePadding - y0;
383
+ if (dy > 0) {
384
+ node.y -= dy;
385
+ y0 = node.y;
386
+ } else {
387
+ break;
388
+ }
389
+ }
390
+ }
391
+ };
392
+
393
+ const relaxLeftToRight = (
394
+ tree: ReadonlyArray<SankeyNode>,
395
+ depthTree: SankeyNode[][],
396
+ links: ReadonlyArray<LinkDataItemDy>,
397
+ alpha: number,
398
+ ): void => {
399
+ for (const nodes of depthTree) {
400
+ if (nodes == null) {
401
+ continue;
402
+ }
403
+ for (const node of nodes) {
404
+ if (node.sourceLinks.length) {
405
+ const sourceSum = getSumOfIds(links, node.sourceLinks);
406
+ const weightedSum = getSumWithWeightedSource(tree, links, node.sourceLinks);
407
+ const y = sourceSum === 0 ? centerY(node) : weightedSum / sourceSum;
408
+ node.y += (y - centerY(node)) * alpha;
409
+ }
410
+ }
411
+ }
412
+ };
413
+
414
+ const relaxRightToLeft = (
415
+ tree: ReadonlyArray<SankeyNode>,
416
+ depthTree: SankeyNode[][],
417
+ links: ReadonlyArray<LinkDataItemDy>,
418
+ alpha: number,
419
+ ): void => {
420
+ for (let i = depthTree.length - 1; i >= 0; i--) {
421
+ const nodes = depthTree[i];
422
+ if (nodes == null) {
423
+ continue;
424
+ }
425
+ for (const node of nodes) {
426
+ if (node.targetLinks.length) {
427
+ const targetSum = getSumOfIds(links, node.targetLinks);
428
+ const weightedSum = getSumWithWeightedTarget(tree, links, node.targetLinks);
429
+ const y = targetSum === 0 ? centerY(node) : weightedSum / targetSum;
430
+ node.y += (y - centerY(node)) * alpha;
431
+ }
432
+ }
433
+ }
434
+ };
435
+
436
+ const updateYOfLinks = (tree: SankeyNode[], links: LinkDataItemDy[]): void => {
437
+ for (const node of tree) {
438
+ let sy = 0;
439
+ let ty = 0;
440
+ node.targetLinks.sort(
441
+ (a, b) => (tree[links[a]?.target ?? -1]?.y ?? 0) - (tree[links[b]?.target ?? -1]?.y ?? 0),
442
+ );
443
+ node.sourceLinks.sort(
444
+ (a, b) => (tree[links[a]?.source ?? -1]?.y ?? 0) - (tree[links[b]?.source ?? -1]?.y ?? 0),
445
+ );
446
+ for (const targetLink of node.targetLinks) {
447
+ const link = links[targetLink];
448
+ if (link) {
449
+ link.sy = sy;
450
+ sy += link.dy;
451
+ }
452
+ }
453
+ for (const sourceLink of node.sourceLinks) {
454
+ const link = links[sourceLink];
455
+ if (link) {
456
+ link.ty = ty;
457
+ ty += link.dy;
458
+ }
459
+ }
460
+ }
461
+ };
462
+
463
+ const getLinkYAtX = (
464
+ sourceNode: SankeyNode,
465
+ targetNode: SankeyNode,
466
+ link: LinkDataItemDy,
467
+ x: number,
468
+ ): number => {
469
+ const sourceX = sourceNode.x + sourceNode.dx;
470
+ const targetX = targetNode.x;
471
+ const progress = targetX === sourceX ? 0 : (x - sourceX) / (targetX - sourceX);
472
+ const boundedProgress = Math.min(Math.max(progress, 0), 1);
473
+ const sourceY = sourceNode.y + (link.sy ?? 0) + link.dy / 2;
474
+ const targetY = targetNode.y + (link.ty ?? 0) + link.dy / 2;
475
+
476
+ return cubicValue(sourceY, sourceY, targetY, targetY, boundedProgress);
477
+ };
478
+
479
+ const resolveNodeLinkCollisions = (
480
+ tree: SankeyNode[],
481
+ depthTree: SankeyNode[][],
482
+ links: LinkDataItemDy[],
483
+ height: number,
484
+ nodePadding: number,
485
+ ): void => {
486
+ const depthByNode = new Map<SankeyNode, number>();
487
+
488
+ for (let depth = 0; depth < depthTree.length; depth++) {
489
+ const nodes = depthTree[depth];
490
+ if (nodes == null) {
491
+ continue;
492
+ }
493
+
494
+ for (const node of nodes) {
495
+ depthByNode.set(node, depth);
496
+ }
497
+ }
498
+
499
+ for (let depth = 0; depth < depthTree.length; depth++) {
500
+ const nodes = depthTree[depth];
501
+ if (nodes == null || nodes.length === 0) {
502
+ continue;
503
+ }
504
+
505
+ const depthX = nodes[0] == null ? undefined : nodes[0].x + nodes[0].dx / 2;
506
+ if (depthX == null) {
507
+ continue;
508
+ }
509
+
510
+ const fixedObstacles = links.flatMap((link) => {
511
+ const sourceNode = tree[link.source];
512
+ const targetNode = tree[link.target];
513
+ if (sourceNode == null || targetNode == null) {
514
+ return [];
515
+ }
516
+
517
+ const sourceDepth = depthByNode.get(sourceNode);
518
+ const targetDepth = depthByNode.get(targetNode);
519
+ if (sourceDepth == null || targetDepth == null) {
520
+ return [];
521
+ }
522
+
523
+ if (
524
+ depth <= Math.min(sourceDepth, targetDepth) ||
525
+ depth >= Math.max(sourceDepth, targetDepth)
526
+ ) {
527
+ return [];
528
+ }
529
+
530
+ const y = getLinkYAtX(sourceNode, targetNode, link, depthX) - link.dy / 2;
531
+ return [{ y, dy: link.dy, fixed: true as const }];
532
+ });
533
+
534
+ const containedNodeObstacles = fixedObstacles.filter((obstacle) =>
535
+ nodes.some((node) => node.y >= obstacle.y && node.y + node.dy <= obstacle.y + obstacle.dy),
536
+ );
537
+
538
+ if (containedNodeObstacles.length === 0) {
539
+ continue;
540
+ }
541
+
542
+ type CollisionItem =
543
+ | { node: SankeyNode; fixed: false }
544
+ | { y: number; dy: number; fixed: true };
545
+ const getItemY = (item: CollisionItem): number => (item.fixed ? item.y : item.node.y);
546
+ const getItemHeight = (item: CollisionItem): number => (item.fixed ? item.dy : item.node.dy);
547
+ let items: CollisionItem[] = [
548
+ ...nodes.map((node) => ({ node, fixed: false as const })),
549
+ ...containedNodeObstacles,
550
+ ].sort((a, b) => getItemY(a) - getItemY(b));
551
+
552
+ let nextY = 0;
553
+ for (const item of items) {
554
+ if (item.fixed) {
555
+ nextY = Math.max(nextY, item.y + item.dy + nodePadding);
556
+ continue;
557
+ }
558
+
559
+ if (item.node.y < nextY) {
560
+ item.node.y = nextY;
561
+ }
562
+ nextY = item.node.y + item.node.dy + nodePadding;
563
+ }
564
+
565
+ items = items.sort((a, b) => getItemY(a) - getItemY(b));
566
+
567
+ let previousY = height + nodePadding;
568
+ for (let i = items.length - 1; i >= 0; i--) {
569
+ const item = items[i];
570
+ if (item == null) {
571
+ continue;
572
+ }
573
+
574
+ if (item.fixed) {
575
+ previousY = Math.min(previousY, item.y - nodePadding);
576
+ continue;
577
+ }
578
+
579
+ // This backward pass only keeps moved nodes within the chart bounds.
580
+ // It intentionally does not iterate again against fixed obstacles above,
581
+ // because this fix is scoped to the fully-contained skipped-depth case.
582
+ const dy = item.node.y + getItemHeight(item) + nodePadding - previousY;
583
+ if (dy > 0) {
584
+ item.node.y -= dy;
585
+ }
586
+ previousY = item.node.y;
587
+ }
588
+ }
589
+ };
590
+
591
+ export const computeData = ({
592
+ data,
593
+ width,
594
+ height,
595
+ iterations,
596
+ nodeWidth,
597
+ nodePadding,
598
+ sort,
599
+ verticalAlign,
600
+ align,
601
+ }: {
602
+ data: SankeyData;
603
+ width: number;
604
+ height: number;
605
+ iterations: number;
606
+ nodeWidth: number;
607
+ nodePadding: number;
608
+ sort: boolean;
609
+ verticalAlign: SankeyVerticalAlign;
610
+ align: SankeyHorizontalAlign;
611
+ }): { nodes: SankeyNode[]; links: LinkDataItemDy[] } => {
612
+ const { links } = data;
613
+ const { tree } = getNodesTree(data, width, nodeWidth, align);
614
+ const depthTree = getDepthTree(tree);
615
+ const linksWithDy = updateYOfTree(depthTree, height, nodePadding, links, verticalAlign);
616
+ resolveCollisions(depthTree, height, nodePadding, sort);
617
+ if (verticalAlign === "justify") {
618
+ let alpha = 1;
619
+ for (let i = 1; i <= iterations; i++) {
620
+ relaxRightToLeft(tree, depthTree, linksWithDy, (alpha *= 0.99));
621
+ resolveCollisions(depthTree, height, nodePadding, sort);
622
+ relaxLeftToRight(tree, depthTree, linksWithDy, alpha);
623
+ resolveCollisions(depthTree, height, nodePadding, sort);
624
+ }
625
+ }
626
+ updateYOfLinks(tree, linksWithDy);
627
+ resolveNodeLinkCollisions(tree, depthTree, linksWithDy, height, nodePadding);
628
+ updateYOfLinks(tree, linksWithDy);
629
+ return { nodes: tree, links: linksWithDy };
630
+ };
631
+
632
+ const buildLinkProps = (
633
+ link: LinkDataItemDy,
634
+ nodes: ReadonlyArray<SankeyNode>,
635
+ left: number,
636
+ top: number,
637
+ i: number,
638
+ linkCurvature: number,
639
+ ): LinkProps | undefined => {
640
+ const sourceNode = nodes[link.source];
641
+ const targetNode = nodes[link.target];
642
+ if (sourceNode == null || targetNode == null) {
643
+ return undefined;
644
+ }
645
+ const linkWidth = link.dy;
646
+ const sourceRelativeY = link.sy ?? 0;
647
+ const targetRelativeY = link.ty ?? 0;
648
+ const sourceX = sourceNode.x + sourceNode.dx + left;
649
+ const targetX = targetNode.x + left;
650
+ const interp = interpolationGenerator(sourceX, targetX);
651
+ return {
652
+ sourceX,
653
+ targetX,
654
+ sourceY: sourceNode.y + sourceRelativeY + linkWidth / 2 + top,
655
+ targetY: targetNode.y + targetRelativeY + linkWidth / 2 + top,
656
+ sourceControlX: interp(linkCurvature),
657
+ targetControlX: interp(1 - linkCurvature),
658
+ sourceRelativeY,
659
+ targetRelativeY,
660
+ linkWidth,
661
+ index: i,
662
+ payload: { ...link, source: sourceNode, target: targetNode },
663
+ };
664
+ };
665
+
666
+ const buildNodeProps = (node: SankeyNode, left: number, top: number, i: number): NodeProps => ({
667
+ x: node.x + left,
668
+ y: node.y + top,
669
+ width: node.dx,
670
+ height: node.dy,
671
+ index: i,
672
+ payload: node,
673
+ });
674
+
675
+ // activeIndex is `node-{i}` / `link-{i}`; resolve against the stored computed data.
676
+ export const sankeyPayloadSearcher: TooltipPayloadSearcher = (
677
+ _data: unknown,
678
+ activeIndex: TooltipIndex,
679
+ computedData?: unknown,
680
+ nameKey?: DataKey<unknown>,
681
+ ): unknown => {
682
+ if (activeIndex == null || typeof activeIndex !== "string") {
683
+ return undefined;
684
+ }
685
+ if (!isObj(computedData)) {
686
+ return undefined;
687
+ }
688
+ const [targetType, index] = activeIndex.split("-");
689
+ const arr =
690
+ targetType === "node"
691
+ ? computedData.nodes
692
+ : targetType === "link"
693
+ ? computedData.links
694
+ : undefined;
695
+ const item = isArr(arr) ? arr[Number(index)] : undefined;
696
+ if (!isObj(item) || !isObj(item.payload)) {
697
+ return undefined;
698
+ }
699
+ const payload = item.payload;
700
+ // Shape the result as {payload, name, value} so combineTooltipPayload can read
701
+ // `value` (dataKey) and `name` — names resolve through the user's `nameKey`
702
+ // (reference getPayloadOfTooltip: getValueByDataKey(payload, nameKey, '')),
703
+ // falling back to "name" when no nameKey reaches the searcher.
704
+ const resolveName = (target: unknown): unknown =>
705
+ getValueByDataKey(target, nameKey ?? "name", "");
706
+ if (targetType === "node") {
707
+ return { payload, name: resolveName(payload), value: payload.value };
708
+ }
709
+ const source = isObj(payload.source) ? resolveName(payload.source) : undefined;
710
+ const target = isObj(payload.target) ? resolveName(payload.target) : undefined;
711
+ return { payload, name: `${String(source)} - ${String(target)}`, value: payload.value };
712
+ };
713
+
714
+ export interface SankeyProps extends EventThrottlingProps {
715
+ class?: string;
716
+ data: SankeyData;
717
+ width?: number | Percent;
718
+ height?: number | Percent;
719
+ responsive?: boolean;
720
+ nameKey?: DataKey<unknown>;
721
+ dataKey?: DataKey<unknown>;
722
+ nodePadding?: number;
723
+ nodeWidth?: number;
724
+ linkCurvature?: number;
725
+ iterations?: number;
726
+ margin?: Partial<Margin>;
727
+ sort?: boolean;
728
+ align?: SankeyHorizontalAlign;
729
+ verticalAlign?: SankeyVerticalAlign;
730
+ /** Custom node renderer (function form). Receives the laid-out node props. */
731
+ node?: SankeyNodeOptions;
732
+ /** Custom link renderer (function form). Receives the laid-out link props. */
733
+ link?: (props: LinkProps) => JSX.Element;
734
+ onMouseEnter?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MousePointer) => void;
735
+ onMouseLeave?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MousePointer) => void;
736
+ onClick?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MousePointer) => void;
737
+ // Accepted (from the SVG container in recharts) but intentionally not wired —
738
+ // the Sankey only dispatches enter/leave/click on nodes and links.
739
+ onMouseMove?: (e: MousePointer) => void;
740
+ onTouchMove?: (e: TouchEvent) => void;
741
+ onTouchEnd?: (e: TouchEvent) => void;
742
+ children?: JSX.Element;
743
+ id?: string;
744
+ }
745
+
746
+ export const sankeyDefaultProps = {
747
+ align: "justify",
748
+ dataKey: "value",
749
+ iterations: 32,
750
+ linkCurvature: 0.5,
751
+ margin: { top: 5, right: 5, bottom: 5, left: 5 },
752
+ nameKey: "name",
753
+ nodePadding: 10,
754
+ nodeWidth: 10,
755
+ sort: true,
756
+ verticalAlign: "justify",
757
+ responsive: false,
758
+ } as const satisfies Partial<SankeyProps>;
759
+
760
+ const sankeyOptions: ChartOptions = {
761
+ chartName: "Sankey",
762
+ defaultTooltipEventType: "item",
763
+ validateTooltipEventTypes: ["item"],
764
+ tooltipPayloadSearcher: sankeyPayloadSearcher,
765
+ eventEmitter: undefined,
766
+ };
767
+
768
+ const SankeyImpl = (props: SankeyProps & { id: string }): JSX.Element => {
769
+ const store = useAppStore();
770
+ const merged = merge(sankeyDefaultProps, props);
771
+ const width = useChartWidth();
772
+ const height = useChartHeight();
773
+
774
+ const dims = (): { width: number; height: number } | undefined => {
775
+ const w = width();
776
+ const h = height();
777
+ return w != null && h != null && w > 0 && h > 0 ? { width: w, height: h } : undefined;
778
+ };
779
+
780
+ const computed = createMemo<{ nodes: NodeProps[]; links: LinkProps[] }>(() => {
781
+ const d = dims();
782
+ const data = merged.data;
783
+ if (d == null || data == null || !data.links || !data.nodes) {
784
+ return { nodes: [], links: [] };
785
+ }
786
+ const margin = merged.margin;
787
+ const contentWidth = d.width - (margin.left ?? 0) - (margin.right ?? 0);
788
+ const contentHeight = d.height - (margin.top ?? 0) - (margin.bottom ?? 0);
789
+ const layout = computeData({
790
+ data,
791
+ width: contentWidth,
792
+ height: contentHeight,
793
+ iterations: merged.iterations,
794
+ nodeWidth: merged.nodeWidth,
795
+ nodePadding: merged.nodePadding,
796
+ sort: merged.sort,
797
+ verticalAlign: merged.verticalAlign,
798
+ align: merged.align,
799
+ });
800
+ const top = margin.top ?? 0;
801
+ const left = margin.left ?? 0;
802
+ const links = layout.links
803
+ .map((l, i) => buildLinkProps(l, layout.nodes, left, top, i, merged.linkCurvature))
804
+ .filter(isNotNil);
805
+ const nodes = layout.nodes.map((n, i) => buildNodeProps(n, left, top, i));
806
+ return { nodes, links };
807
+ });
808
+
809
+ // Publish the computed data so the tooltip searcher can resolve node-/link-N.
810
+ createEffect(
811
+ () => ({ nodes: computed().nodes, links: computed().links }),
812
+ (cd) => store?.actions.chartData.setComputedData(cd),
813
+ );
814
+
815
+ const dispatchEnter = (index: TooltipIndex, coord: Coordinate): void => {
816
+ store?.actions.tooltip.setActiveMouseOverItemIndex({
817
+ activeIndex: index,
818
+ activeDataKey: merged.dataKey,
819
+ activeCoordinate: coord,
820
+ activeGraphicalItemId: props.id,
821
+ });
822
+ };
823
+ const dispatchClick = (index: TooltipIndex, coord: Coordinate): void => {
824
+ store?.actions.tooltip.setActiveClickItemIndex({
825
+ activeIndex: index,
826
+ activeDataKey: merged.dataKey,
827
+ activeCoordinate: coord,
828
+ activeGraphicalItemId: props.id,
829
+ });
830
+ };
831
+
832
+ const tooltipConfig = createMemo<TooltipPayloadConfiguration>(() => ({
833
+ dataDefinedOnItem: merged.data,
834
+ getPosition: (index) => {
835
+ const key = String(index);
836
+ const nodes = computed().nodes;
837
+ const node = nodes.find((n) => `node-${n.index}` === key) ?? nodes[Number(key)];
838
+ if (node == null) {
839
+ return undefined;
840
+ }
841
+ return { x: node.x + node.width / 2, y: node.y + node.height / 2 };
842
+ },
843
+ settings: {
844
+ stroke: undefined,
845
+ strokeWidth: undefined,
846
+ fill: "#0088fe",
847
+ nameKey: merged.nameKey,
848
+ dataKey: merged.dataKey,
849
+ name: undefined,
850
+ hide: false,
851
+ type: undefined,
852
+ color: "#0088fe",
853
+ unit: "",
854
+ graphicalItemId: props.id,
855
+ },
856
+ }));
857
+
858
+ const layerClass = (): string =>
859
+ ["recharts-sankey", merged.class].filter((c): c is string => Boolean(c)).join(" ");
860
+
861
+ return (
862
+ <Show when={dims()}>
863
+ {(d) => (
864
+ <Surface width={d().width} height={d().height}>
865
+ <Layer class={layerClass()}>
866
+ <Layer class="recharts-sankey-links">
867
+ <For each={computed().links}>
868
+ {(lp) => {
869
+ const coord: Coordinate = {
870
+ x: (lp.sourceX + lp.targetX) / 2,
871
+ y: (lp.sourceY + lp.targetY) / 2,
872
+ };
873
+ const onMouseEnter = (e: MousePointer): void => {
874
+ merged.onMouseEnter?.(lp, "link", e);
875
+ dispatchEnter(`link-${lp.index}`, coord);
876
+ };
877
+ const onMouseLeave = (e: MousePointer): void => {
878
+ merged.onMouseLeave?.(lp, "link", e);
879
+ store?.actions.tooltip.mouseLeaveItem();
880
+ };
881
+ const onClick = (e: MousePointer): void => {
882
+ merged.onClick?.(lp, "link", e);
883
+ dispatchClick(`link-${lp.index}`, coord);
884
+ };
885
+ return typeof merged.link === "function" ? (
886
+ <g
887
+ class="recharts-sankey-link"
888
+ onMouseEnter={onMouseEnter}
889
+ onMouseLeave={onMouseLeave}
890
+ onClick={onClick}
891
+ >
892
+ {merged.link(lp)}
893
+ </g>
894
+ ) : (
895
+ <path
896
+ class="recharts-sankey-link"
897
+ d={`M${lp.sourceX},${lp.sourceY}C${lp.sourceControlX},${lp.sourceY} ${lp.targetControlX},${lp.targetY} ${lp.targetX},${lp.targetY}`}
898
+ fill="none"
899
+ stroke="#333"
900
+ stroke-width={lp.linkWidth}
901
+ stroke-opacity="0.2"
902
+ onMouseEnter={onMouseEnter}
903
+ onMouseLeave={onMouseLeave}
904
+ onClick={onClick}
905
+ />
906
+ );
907
+ }}
908
+ </For>
909
+ </Layer>
910
+ <Layer class="recharts-sankey-nodes">
911
+ <For each={computed().nodes}>
912
+ {(np) => {
913
+ const coord: Coordinate = {
914
+ x: np.x + np.width / 2,
915
+ y: np.y + np.height / 2,
916
+ };
917
+ const onMouseEnter = (e: MousePointer): void => {
918
+ merged.onMouseEnter?.(np, "node", e);
919
+ dispatchEnter(`node-${np.index}`, coord);
920
+ };
921
+ const onMouseLeave = (e: MousePointer): void => {
922
+ merged.onMouseLeave?.(np, "node", e);
923
+ store?.actions.tooltip.mouseLeaveItem();
924
+ };
925
+ const onClick = (e: MousePointer): void => {
926
+ merged.onClick?.(np, "node", e);
927
+ dispatchClick(`node-${np.index}`, coord);
928
+ };
929
+ // Custom function-form node: render its output inside an
930
+ // event-handling <g> (events stay on the wrapper, mirroring recharts).
931
+ return typeof merged.node === "function" ? (
932
+ <g
933
+ class="recharts-sankey-node"
934
+ onMouseEnter={onMouseEnter}
935
+ onMouseLeave={onMouseLeave}
936
+ onClick={onClick}
937
+ >
938
+ {merged.node(np)}
939
+ </g>
940
+ ) : (
941
+ <Rectangle
942
+ class="recharts-sankey-node"
943
+ fill="#0088fe"
944
+ fill-opacity="0.8"
945
+ x={np.x}
946
+ y={np.y}
947
+ width={np.width}
948
+ height={np.height}
949
+ onMouseEnter={onMouseEnter}
950
+ onMouseLeave={onMouseLeave}
951
+ onClick={onClick}
952
+ />
953
+ );
954
+ }}
955
+ </For>
956
+ </Layer>
957
+ </Layer>
958
+ <SetTooltipEntrySettings tooltipEntrySettings={tooltipConfig()} />
959
+ {merged.children}
960
+ </Surface>
961
+ )}
962
+ </Show>
963
+ );
964
+ };
965
+
966
+ /**
967
+ * A flow diagram: value-weighted ribbons connect nodes laid out by an iterative
968
+ * relaxation, conveying how quantities split and merge across stages.
969
+ */
970
+ export const Sankey = (props: SankeyProps): JSX.Element => {
971
+ const id = useUniqueId("recharts-sankey", props.id);
972
+ const margin = (): Partial<Margin> => props.margin ?? sankeyDefaultProps.margin;
973
+ return (
974
+ <RechartsStoreProvider
975
+ preloadedState={{ options: sankeyOptions } satisfies Partial<RechartsRootState>}
976
+ >
977
+ <ReportChartMargin margin={margin()} />
978
+ <ReportEventSettings
979
+ throttleDelay={props.throttleDelay}
980
+ throttledEvents={props.throttledEvents}
981
+ />
982
+ <RechartsWrapper
983
+ class={props.class}
984
+ width={props.width}
985
+ height={props.height}
986
+ responsive={props.responsive ?? false}
987
+ >
988
+ <SankeyImpl {...props} id={id} />
989
+ </RechartsWrapper>
990
+ </RechartsStoreProvider>
991
+ );
992
+ };