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,2314 @@
1
+ // Port of recharts 3.8.1 test/cartesian/Bar/Bar.spec.tsx (commit 7a23854).
2
+ // Ported: geometry, barSize, maxBarSize, label, minPointSize, background, id/clip,
3
+ // legendType, events, stacked tooltip/activeBar (#5124), background zIndex,
4
+ // activeBar+null data, ScatterChart matrix, state integration.
5
+ // Deferred: full unsupported-chart matrix.
6
+ // label spy call-count is data.length (not ×2 — no React StrictMode double-mount).
7
+ import { createEffect, createSignal, flush, omit, Show } from "solid-js";
8
+ import type { JSX } from "@solidjs/web";
9
+ import { afterEach, beforeEach, describe, expect, it, test, vi } from "vitest";
10
+ import {
11
+ Bar,
12
+ BarChart,
13
+ BarProps,
14
+ DefaultZIndexes,
15
+ Legend,
16
+ Tooltip,
17
+ type LegendType,
18
+ XAxis,
19
+ YAxis,
20
+ } from "../../../src";
21
+ import type { CartesianGraphicalItemSettings } from "../../../src/state/graphicalItemsSlice";
22
+ import { useAppSelector } from "../../../src/state/hooks";
23
+ import { BarSettings } from "../../../src/state/types/BarSettings";
24
+ import { fireEvent, render } from "../../helper/render";
25
+ import { assertZIndexLayerOrder } from "../../helper/assertZIndexLayerOrder";
26
+ import { expectActiveBars, expectBars, getAllBarPaths, getAllBars } from "../../helper/expectBars";
27
+ import { expectLabels } from "../../helper/expectLabel";
28
+ import { svgPropertiesAndEvents } from "../../../src/util/svgPropertiesAndEvents";
29
+ import type { Props as LabelProps } from "../../../src/component/Label";
30
+ import { expectLastCalledWith } from "../../helper/expectLastCalledWith";
31
+ import { assertNotNull } from "../../helper/assertNotNull";
32
+ import {
33
+ BarChartCase,
34
+ chartsWhereBarMustNotRender,
35
+ ComposedChartCase,
36
+ type CartesianChartTestCase,
37
+ } from "../../helper/parameterizedTestCases";
38
+ import { createSelectorTestCase } from "../../helper/createSelectorTestCase";
39
+ import {
40
+ expectTooltipCoordinate,
41
+ expectTooltipPayload,
42
+ showTooltipOnCoordinate,
43
+ } from "../../component/Tooltip/tooltipTestHelpers";
44
+ import {
45
+ selectActiveTooltipDataKey,
46
+ selectActiveTooltipIndex,
47
+ selectTooltipAxisTicks,
48
+ } from "../../../src/state/selectors/tooltipSelectors";
49
+ import { barChartMouseHoverTooltipSelector } from "../../component/Tooltip/tooltipMouseHoverSelectors";
50
+ import { mockGetBoundingClientRect } from "../../helper/mockGetBoundingClientRect";
51
+ import { noInteraction, type TooltipState } from "../../../src/state/tooltipSlice";
52
+
53
+ // Ported from vendor/recharts-reference/test/vitest.setup.ts — scoped to Bar specs
54
+ // so activeBar rAF staging is synchronous via vi.runOnlyPendingTimers().
55
+ beforeEach(() => {
56
+ vi.useFakeTimers({
57
+ toFake: ["requestAnimationFrame", "cancelAnimationFrame"],
58
+ });
59
+ });
60
+
61
+ afterEach(() => {
62
+ vi.clearAllTimers();
63
+ });
64
+
65
+ const chartsThatSupportBar: ReadonlyArray<CartesianChartTestCase> = [
66
+ ComposedChartCase,
67
+ BarChartCase,
68
+ ];
69
+
70
+ const chartsThatDoNotSupportBar = chartsWhereBarMustNotRender(chartsThatSupportBar);
71
+
72
+ const data = [
73
+ { x: 10, y: 50, width: 20, height: 50, value: 100, label: "test1" },
74
+ { x: 50, y: 50, width: 20, height: 50, value: 200, label: "test2" },
75
+ { x: 90, y: 50, width: 20, height: 50, value: 300, label: "test3" },
76
+ { x: 130, y: 50, width: 20, height: 50, value: 400, label: "test4" },
77
+ { x: 170, y: 50, width: 20, height: 50, value: 500, label: "test5" },
78
+ ];
79
+
80
+ function renderChart(ui: () => JSX.Element): { container: HTMLElement } {
81
+ const result = render(ui);
82
+ flush();
83
+ flush();
84
+ flush();
85
+ return result;
86
+ }
87
+
88
+ describe.each(chartsThatSupportBar)("<Bar /> as a child of $testName", ({ ChartElement }) => {
89
+ it(`should render rectangles in horizontal Bar`, () => {
90
+ const { container } = renderChart(() => (
91
+ <ChartElement layout="horizontal" data={data}>
92
+ <Bar isAnimationActive={false} dataKey="value" />
93
+ </ChartElement>
94
+ ));
95
+
96
+ expectBars(container, [
97
+ {
98
+ d: "M 14.8,413.3333 h 78 v 81.6667 h -78 Z",
99
+ height: "81.6667",
100
+ radius: "0",
101
+ width: "78",
102
+ x: "14.8",
103
+ y: "413.3333",
104
+ },
105
+ {
106
+ d: "M 112.8,331.6667 h 78 v 163.3333 h -78 Z",
107
+ height: "163.3333",
108
+ radius: "0",
109
+ width: "78",
110
+ x: "112.8",
111
+ y: "331.6667",
112
+ },
113
+ {
114
+ d: "M 210.8,250 h 78 v 245 h -78 Z",
115
+ height: "245",
116
+ radius: "0",
117
+ width: "78",
118
+ x: "210.8",
119
+ y: "250",
120
+ },
121
+ {
122
+ d: "M 308.8,168.3333 h 78 v 326.6667 h -78 Z",
123
+ height: "326.6667",
124
+ radius: "0",
125
+ width: "78",
126
+ x: "308.8",
127
+ y: "168.3333",
128
+ },
129
+ {
130
+ d: "M 406.8,86.6667 h 78 v 408.3333 h -78 Z",
131
+ height: "408.3333",
132
+ radius: "0",
133
+ width: "78",
134
+ x: "406.8",
135
+ y: "86.6667",
136
+ },
137
+ ]);
138
+ });
139
+
140
+ it(`should render rounded rectangles when radius is set`, () => {
141
+ const { container } = renderChart(() => (
142
+ <ChartElement layout="horizontal" data={data}>
143
+ <Bar isAnimationActive={false} dataKey="value" radius={8} />
144
+ </ChartElement>
145
+ ));
146
+
147
+ const paths = container.querySelectorAll(
148
+ ".recharts-bar .recharts-bar-rectangle path.recharts-rectangle",
149
+ );
150
+ expect(paths.length).toBe(5);
151
+ paths.forEach((p) => {
152
+ expect(p.getAttribute("radius")).toBe("8");
153
+ // A rounded bar replaces the straight `h/v` corners with arc commands.
154
+ expect(p.getAttribute("d")).toContain("A 8,8");
155
+ });
156
+ });
157
+
158
+ it(`should render rectangles when wrapped in custom Component`, () => {
159
+ const MyBar = (props: BarProps) => <Bar {...props} />;
160
+ const { container } = renderChart(() => (
161
+ <ChartElement layout="horizontal" data={data}>
162
+ <MyBar isAnimationActive={false} dataKey="value" />
163
+ </ChartElement>
164
+ ));
165
+
166
+ expectBars(container, [
167
+ {
168
+ d: "M 14.8,413.3333 h 78 v 81.6667 h -78 Z",
169
+ height: "81.6667",
170
+ radius: "0",
171
+ width: "78",
172
+ x: "14.8",
173
+ y: "413.3333",
174
+ },
175
+ {
176
+ d: "M 112.8,331.6667 h 78 v 163.3333 h -78 Z",
177
+ height: "163.3333",
178
+ radius: "0",
179
+ width: "78",
180
+ x: "112.8",
181
+ y: "331.6667",
182
+ },
183
+ {
184
+ d: "M 210.8,250 h 78 v 245 h -78 Z",
185
+ height: "245",
186
+ radius: "0",
187
+ width: "78",
188
+ x: "210.8",
189
+ y: "250",
190
+ },
191
+ {
192
+ d: "M 308.8,168.3333 h 78 v 326.6667 h -78 Z",
193
+ height: "326.6667",
194
+ radius: "0",
195
+ width: "78",
196
+ x: "308.8",
197
+ y: "168.3333",
198
+ },
199
+ {
200
+ d: "M 406.8,86.6667 h 78 v 408.3333 h -78 Z",
201
+ height: "408.3333",
202
+ radius: "0",
203
+ width: "78",
204
+ x: "406.8",
205
+ y: "86.6667",
206
+ },
207
+ ]);
208
+ });
209
+
210
+ it(`should render rectangles in vertical Bar`, () => {
211
+ const { container } = renderChart(() => (
212
+ <ChartElement layout="vertical" data={data}>
213
+ <YAxis type="category" />
214
+ <XAxis type="number" />
215
+ <Bar isAnimationActive={false} dataKey="value" />
216
+ </ChartElement>
217
+ ));
218
+
219
+ expectBars(container, [
220
+ {
221
+ x: "65",
222
+ y: "14.2",
223
+ width: "71.6667",
224
+ height: "74",
225
+ radius: "0",
226
+ d: "M 65,14.2 h 71.6667 v 74 h -71.6667 Z",
227
+ },
228
+ {
229
+ x: "65",
230
+ y: "106.2",
231
+ width: "143.3333",
232
+ height: "74",
233
+ radius: "0",
234
+ d: "M 65,106.2 h 143.3333 v 74 h -143.3333 Z",
235
+ },
236
+ {
237
+ x: "65",
238
+ y: "198.2",
239
+ width: "215",
240
+ height: "74",
241
+ radius: "0",
242
+ d: "M 65,198.2 h 215 v 74 h -215 Z",
243
+ },
244
+ {
245
+ x: "65",
246
+ y: "290.2",
247
+ width: "286.6667",
248
+ height: "74",
249
+ radius: "0",
250
+ d: "M 65,290.2 h 286.6667 v 74 h -286.6667 Z",
251
+ },
252
+ {
253
+ x: "65",
254
+ y: "382.2",
255
+ width: "358.3333",
256
+ height: "74",
257
+ radius: "0",
258
+ d: "M 65,382.2 h 358.3333 v 74 h -358.3333 Z",
259
+ },
260
+ ]);
261
+ });
262
+
263
+ it("Don't render any rectangle when data is empty", () => {
264
+ const { container } = renderChart(() => (
265
+ <ChartElement data={[]}>
266
+ <Bar dataKey="value" />
267
+ </ChartElement>
268
+ ));
269
+
270
+ expectBars(container, []);
271
+ });
272
+
273
+ describe("with explicit ID prop", () => {
274
+ it("should pass id prop to an element in the DOM", () => {
275
+ const { container } = renderChart(() => (
276
+ <ChartElement layout="horizontal" data={data}>
277
+ <Bar isAnimationActive={false} dataKey="value" id="test-bar-id" />
278
+ <XAxis allowDataOverflow />
279
+ </ChartElement>
280
+ ));
281
+
282
+ const bar = container.querySelector("#test-bar-id");
283
+ assertNotNull(bar);
284
+ expect(bar.tagName).toBe("g");
285
+ expect(bar.classList.value).toBe("recharts-layer recharts-bar");
286
+ });
287
+
288
+ it("should set the ID on the clipPath, if it needs clipping", () => {
289
+ const { container } = renderChart(() => (
290
+ <ChartElement layout="horizontal" data={data}>
291
+ <Bar isAnimationActive={false} dataKey="value" id="test-bar-id" />
292
+ <XAxis allowDataOverflow />
293
+ </ChartElement>
294
+ ));
295
+
296
+ const clipPath = container.querySelector("#clipPath-test-bar-id");
297
+ assertNotNull(clipPath);
298
+ expect(clipPath.tagName).toBe("clipPath");
299
+ });
300
+ });
301
+
302
+ describe("barSize", () => {
303
+ it("should make bars wider in horizontal chart", () => {
304
+ const barSize = 79;
305
+ const { container } = renderChart(() => (
306
+ <ChartElement layout="horizontal" data={data}>
307
+ <Bar isAnimationActive={false} dataKey="value" barSize={barSize} />
308
+ </ChartElement>
309
+ ));
310
+
311
+ expectBars(container, [
312
+ {
313
+ x: "15",
314
+ y: "413.3333",
315
+ width: "79",
316
+ height: "81.6667",
317
+ radius: "0",
318
+ d: "M 15,413.3333 h 79 v 81.6667 h -79 Z",
319
+ },
320
+ {
321
+ x: "113",
322
+ y: "331.6667",
323
+ width: "79",
324
+ height: "163.3333",
325
+ radius: "0",
326
+ d: "M 113,331.6667 h 79 v 163.3333 h -79 Z",
327
+ },
328
+ {
329
+ x: "211",
330
+ y: "250",
331
+ width: "79",
332
+ height: "245",
333
+ radius: "0",
334
+ d: "M 211,250 h 79 v 245 h -79 Z",
335
+ },
336
+ {
337
+ x: "309",
338
+ y: "168.3333",
339
+ width: "79",
340
+ height: "326.6667",
341
+ radius: "0",
342
+ d: "M 309,168.3333 h 79 v 326.6667 h -79 Z",
343
+ },
344
+ {
345
+ x: "407",
346
+ y: "86.6667",
347
+ width: "79",
348
+ height: "408.3333",
349
+ radius: "0",
350
+ d: "M 407,86.6667 h 79 v 408.3333 h -79 Z",
351
+ },
352
+ ]);
353
+ });
354
+
355
+ it("should make bars narrower in horizontal chart", () => {
356
+ const barSize = 77;
357
+ const { container } = renderChart(() => (
358
+ <ChartElement layout="horizontal" data={data}>
359
+ <Bar isAnimationActive={false} dataKey="value" barSize={barSize} />
360
+ </ChartElement>
361
+ ));
362
+
363
+ expectBars(container, [
364
+ {
365
+ x: "16",
366
+ y: "413.3333",
367
+ width: "77",
368
+ height: "81.6667",
369
+ radius: "0",
370
+ d: "M 16,413.3333 h 77 v 81.6667 h -77 Z",
371
+ },
372
+ {
373
+ x: "114",
374
+ y: "331.6667",
375
+ width: "77",
376
+ height: "163.3333",
377
+ radius: "0",
378
+ d: "M 114,331.6667 h 77 v 163.3333 h -77 Z",
379
+ },
380
+ {
381
+ x: "212",
382
+ y: "250",
383
+ width: "77",
384
+ height: "245",
385
+ radius: "0",
386
+ d: "M 212,250 h 77 v 245 h -77 Z",
387
+ },
388
+ {
389
+ x: "310",
390
+ y: "168.3333",
391
+ width: "77",
392
+ height: "326.6667",
393
+ radius: "0",
394
+ d: "M 310,168.3333 h 77 v 326.6667 h -77 Z",
395
+ },
396
+ {
397
+ x: "408",
398
+ y: "86.6667",
399
+ width: "77",
400
+ height: "408.3333",
401
+ radius: "0",
402
+ d: "M 408,86.6667 h 77 v 408.3333 h -77 Z",
403
+ },
404
+ ]);
405
+ });
406
+
407
+ it("should make bars taller in vertical chart", () => {
408
+ const barSize = 74;
409
+ const { container } = renderChart(() => (
410
+ <ChartElement layout="vertical" data={data}>
411
+ <YAxis type="category" />
412
+ <XAxis type="number" />
413
+ <Bar isAnimationActive={false} dataKey="value" barSize={barSize} />
414
+ </ChartElement>
415
+ ));
416
+
417
+ expectBars(container, [
418
+ {
419
+ d: "M 65,14 h 71.6667 v 74 h -71.6667 Z",
420
+ height: "74",
421
+ radius: "0",
422
+ width: "71.6667",
423
+ x: "65",
424
+ y: "14",
425
+ },
426
+ {
427
+ d: "M 65,106 h 143.3333 v 74 h -143.3333 Z",
428
+ height: "74",
429
+ radius: "0",
430
+ width: "143.3333",
431
+ x: "65",
432
+ y: "106",
433
+ },
434
+ {
435
+ d: "M 65,198 h 215 v 74 h -215 Z",
436
+ height: "74",
437
+ radius: "0",
438
+ width: "215",
439
+ x: "65",
440
+ y: "198",
441
+ },
442
+ {
443
+ d: "M 65,290 h 286.6667 v 74 h -286.6667 Z",
444
+ height: "74",
445
+ radius: "0",
446
+ width: "286.6667",
447
+ x: "65",
448
+ y: "290",
449
+ },
450
+ {
451
+ d: "M 65,382 h 358.3333 v 74 h -358.3333 Z",
452
+ height: "74",
453
+ radius: "0",
454
+ width: "358.3333",
455
+ x: "65",
456
+ y: "382",
457
+ },
458
+ ]);
459
+ });
460
+
461
+ it("should make bars shorter in vertical chart", () => {
462
+ const barSize = 72;
463
+ const { container } = renderChart(() => (
464
+ <ChartElement layout="vertical" data={data}>
465
+ <YAxis type="category" />
466
+ <XAxis type="number" />
467
+ <Bar isAnimationActive={false} dataKey="value" barSize={barSize} />
468
+ </ChartElement>
469
+ ));
470
+
471
+ expectBars(container, [
472
+ {
473
+ d: "M 65,15 h 71.6667 v 72 h -71.6667 Z",
474
+ height: "72",
475
+ radius: "0",
476
+ width: "71.6667",
477
+ x: "65",
478
+ y: "15",
479
+ },
480
+ {
481
+ d: "M 65,107 h 143.3333 v 72 h -143.3333 Z",
482
+ height: "72",
483
+ radius: "0",
484
+ width: "143.3333",
485
+ x: "65",
486
+ y: "107",
487
+ },
488
+ {
489
+ d: "M 65,199 h 215 v 72 h -215 Z",
490
+ height: "72",
491
+ radius: "0",
492
+ width: "215",
493
+ x: "65",
494
+ y: "199",
495
+ },
496
+ {
497
+ d: "M 65,291 h 286.6667 v 72 h -286.6667 Z",
498
+ height: "72",
499
+ radius: "0",
500
+ width: "286.6667",
501
+ x: "65",
502
+ y: "291",
503
+ },
504
+ {
505
+ d: "M 65,383 h 358.3333 v 72 h -358.3333 Z",
506
+ height: "72",
507
+ radius: "0",
508
+ width: "358.3333",
509
+ x: "65",
510
+ y: "383",
511
+ },
512
+ ]);
513
+ });
514
+ });
515
+
516
+ describe("maxBarSize", () => {
517
+ it("should do nothing if bars are already smaller than the maxBarSize", () => {
518
+ const { container } = renderChart(() => (
519
+ <ChartElement layout="horizontal" data={data}>
520
+ <Bar isAnimationActive={false} dataKey="value" maxBarSize={79} />
521
+ </ChartElement>
522
+ ));
523
+
524
+ expectBars(container, [
525
+ {
526
+ d: "M 14.8,413.3333 h 78 v 81.6667 h -78 Z",
527
+ height: "81.6667",
528
+ radius: "0",
529
+ width: "78",
530
+ x: "14.8",
531
+ y: "413.3333",
532
+ },
533
+ {
534
+ d: "M 112.8,331.6667 h 78 v 163.3333 h -78 Z",
535
+ height: "163.3333",
536
+ radius: "0",
537
+ width: "78",
538
+ x: "112.8",
539
+ y: "331.6667",
540
+ },
541
+ {
542
+ d: "M 210.8,250 h 78 v 245 h -78 Z",
543
+ height: "245",
544
+ radius: "0",
545
+ width: "78",
546
+ x: "210.8",
547
+ y: "250",
548
+ },
549
+ {
550
+ d: "M 308.8,168.3333 h 78 v 326.6667 h -78 Z",
551
+ height: "326.6667",
552
+ radius: "0",
553
+ width: "78",
554
+ x: "308.8",
555
+ y: "168.3333",
556
+ },
557
+ {
558
+ d: "M 406.8,86.6667 h 78 v 408.3333 h -78 Z",
559
+ height: "408.3333",
560
+ radius: "0",
561
+ width: "78",
562
+ x: "406.8",
563
+ y: "86.6667",
564
+ },
565
+ ]);
566
+ });
567
+
568
+ it("should change all bars width when bars are larger than the maxBarSize", () => {
569
+ const maxBarSize = 77;
570
+ const { container } = renderChart(() => (
571
+ <ChartElement layout="horizontal" data={data}>
572
+ <Bar isAnimationActive={false} dataKey="value" maxBarSize={maxBarSize} />
573
+ </ChartElement>
574
+ ));
575
+
576
+ expectBars(container, [
577
+ {
578
+ d: "M 15.3,413.3333 h 77 v 81.6667 h -77 Z",
579
+ height: "81.6667",
580
+ radius: "0",
581
+ width: String(maxBarSize),
582
+ x: "15.3",
583
+ y: "413.3333",
584
+ },
585
+ {
586
+ d: "M 113.3,331.6667 h 77 v 163.3333 h -77 Z",
587
+ height: "163.3333",
588
+ radius: "0",
589
+ width: String(maxBarSize),
590
+ x: "113.3",
591
+ y: "331.6667",
592
+ },
593
+ {
594
+ d: "M 211.3,250 h 77 v 245 h -77 Z",
595
+ height: "245",
596
+ radius: "0",
597
+ width: String(maxBarSize),
598
+ x: "211.3",
599
+ y: "250",
600
+ },
601
+ {
602
+ d: "M 309.3,168.3333 h 77 v 326.6667 h -77 Z",
603
+ height: "326.6667",
604
+ radius: "0",
605
+ width: String(maxBarSize),
606
+ x: "309.3",
607
+ y: "168.3333",
608
+ },
609
+ {
610
+ d: "M 407.3,86.6667 h 77 v 408.3333 h -77 Z",
611
+ height: "408.3333",
612
+ radius: "0",
613
+ width: String(maxBarSize),
614
+ x: "407.3",
615
+ y: "86.6667",
616
+ },
617
+ ]);
618
+ });
619
+
620
+ it("should do nothing if barSize is set", () => {
621
+ const maxBarSize = 77;
622
+ const { container } = renderChart(() => (
623
+ <ChartElement layout="horizontal" data={data}>
624
+ <Bar
625
+ isAnimationActive={false}
626
+ dataKey="value"
627
+ maxBarSize={maxBarSize}
628
+ barSize={maxBarSize + 5}
629
+ />
630
+ </ChartElement>
631
+ ));
632
+
633
+ expectBars(container, [
634
+ {
635
+ d: "M 13,413.3333 h 82 v 81.6667 h -82 Z",
636
+ height: "81.6667",
637
+ radius: "0",
638
+ width: "82",
639
+ x: "13",
640
+ y: "413.3333",
641
+ },
642
+ {
643
+ d: "M 111,331.6667 h 82 v 163.3333 h -82 Z",
644
+ height: "163.3333",
645
+ radius: "0",
646
+ width: "82",
647
+ x: "111",
648
+ y: "331.6667",
649
+ },
650
+ {
651
+ d: "M 209,250 h 82 v 245 h -82 Z",
652
+ height: "245",
653
+ radius: "0",
654
+ width: "82",
655
+ x: "209",
656
+ y: "250",
657
+ },
658
+ {
659
+ d: "M 307,168.3333 h 82 v 326.6667 h -82 Z",
660
+ height: "326.6667",
661
+ radius: "0",
662
+ width: "82",
663
+ x: "307",
664
+ y: "168.3333",
665
+ },
666
+ {
667
+ d: "M 405,86.6667 h 82 v 408.3333 h -82 Z",
668
+ height: "408.3333",
669
+ radius: "0",
670
+ width: "82",
671
+ x: "405",
672
+ y: "86.6667",
673
+ },
674
+ ]);
675
+ });
676
+
677
+ it("should do nothing in vertical chart if all bars are smaller than the maxBarSize", () => {
678
+ const { container } = renderChart(() => (
679
+ <ChartElement layout="vertical" data={data}>
680
+ <YAxis type="category" />
681
+ <XAxis type="number" />
682
+ <Bar isAnimationActive={false} dataKey="value" maxBarSize={74} />
683
+ </ChartElement>
684
+ ));
685
+
686
+ expectBars(container, [
687
+ {
688
+ x: "65",
689
+ y: "14.2",
690
+ width: "71.6667",
691
+ height: "74",
692
+ radius: "0",
693
+ d: "M 65,14.2 h 71.6667 v 74 h -71.6667 Z",
694
+ },
695
+ {
696
+ x: "65",
697
+ y: "106.2",
698
+ width: "143.3333",
699
+ height: "74",
700
+ radius: "0",
701
+ d: "M 65,106.2 h 143.3333 v 74 h -143.3333 Z",
702
+ },
703
+ {
704
+ x: "65",
705
+ y: "198.2",
706
+ width: "215",
707
+ height: "74",
708
+ radius: "0",
709
+ d: "M 65,198.2 h 215 v 74 h -215 Z",
710
+ },
711
+ {
712
+ x: "65",
713
+ y: "290.2",
714
+ width: "286.6667",
715
+ height: "74",
716
+ radius: "0",
717
+ d: "M 65,290.2 h 286.6667 v 74 h -286.6667 Z",
718
+ },
719
+ {
720
+ x: "65",
721
+ y: "382.2",
722
+ width: "358.3333",
723
+ height: "74",
724
+ radius: "0",
725
+ d: "M 65,382.2 h 358.3333 v 74 h -358.3333 Z",
726
+ },
727
+ ]);
728
+ });
729
+
730
+ it("should change all bars height in vertical chart if all bars are larger than the maxBarSize", () => {
731
+ const maxBarSize = 72;
732
+ const { container } = renderChart(() => (
733
+ <ChartElement layout="vertical" data={data}>
734
+ <YAxis type="category" />
735
+ <XAxis type="number" />
736
+ <Bar isAnimationActive={false} dataKey="value" maxBarSize={maxBarSize} />
737
+ </ChartElement>
738
+ ));
739
+
740
+ expectBars(container, [
741
+ {
742
+ x: "65",
743
+ y: "15.2",
744
+ width: "71.6667",
745
+ height: "72",
746
+ radius: "0",
747
+ d: "M 65,15.2 h 71.6667 v 72 h -71.6667 Z",
748
+ },
749
+ {
750
+ x: "65",
751
+ y: "107.2",
752
+ width: "143.3333",
753
+ height: "72",
754
+ radius: "0",
755
+ d: "M 65,107.2 h 143.3333 v 72 h -143.3333 Z",
756
+ },
757
+ {
758
+ x: "65",
759
+ y: "199.2",
760
+ width: "215",
761
+ height: "72",
762
+ radius: "0",
763
+ d: "M 65,199.2 h 215 v 72 h -215 Z",
764
+ },
765
+ {
766
+ x: "65",
767
+ y: "291.2",
768
+ width: "286.6667",
769
+ height: "72",
770
+ radius: "0",
771
+ d: "M 65,291.2 h 286.6667 v 72 h -286.6667 Z",
772
+ },
773
+ {
774
+ x: "65",
775
+ y: "383.2",
776
+ width: "358.3333",
777
+ height: "72",
778
+ radius: "0",
779
+ d: "M 65,383.2 h 358.3333 v 72 h -358.3333 Z",
780
+ },
781
+ ]);
782
+ });
783
+
784
+ it("should do nothing if barSize is set in vertical chart", () => {
785
+ const maxBarSize = 72;
786
+ const { container } = renderChart(() => (
787
+ <ChartElement layout="vertical" data={data}>
788
+ <YAxis type="category" />
789
+ <XAxis type="number" />
790
+ <Bar
791
+ isAnimationActive={false}
792
+ dataKey="value"
793
+ maxBarSize={maxBarSize}
794
+ barSize={maxBarSize + 7}
795
+ />
796
+ </ChartElement>
797
+ ));
798
+
799
+ expectBars(container, [
800
+ {
801
+ x: "65",
802
+ y: "12",
803
+ width: "71.6667",
804
+ height: "79",
805
+ radius: "0",
806
+ d: "M 65,12 h 71.6667 v 79 h -71.6667 Z",
807
+ },
808
+ {
809
+ x: "65",
810
+ y: "104",
811
+ width: "143.3333",
812
+ height: "79",
813
+ radius: "0",
814
+ d: "M 65,104 h 143.3333 v 79 h -143.3333 Z",
815
+ },
816
+ {
817
+ x: "65",
818
+ y: "196",
819
+ width: "215",
820
+ height: "79",
821
+ radius: "0",
822
+ d: "M 65,196 h 215 v 79 h -215 Z",
823
+ },
824
+ {
825
+ x: "65",
826
+ y: "288",
827
+ width: "286.6667",
828
+ height: "79",
829
+ radius: "0",
830
+ d: "M 65,288 h 286.6667 v 79 h -286.6667 Z",
831
+ },
832
+ {
833
+ x: "65",
834
+ y: "380",
835
+ width: "358.3333",
836
+ height: "79",
837
+ radius: "0",
838
+ d: "M 65,380 h 358.3333 v 79 h -358.3333 Z",
839
+ },
840
+ ]);
841
+ });
842
+ });
843
+
844
+ describe("label", () => {
845
+ describe("as boolean", () => {
846
+ it("should draw default labels when label = true", () => {
847
+ const { container } = renderChart(() => (
848
+ <ChartElement data={data}>
849
+ <Bar isAnimationActive={false} label dataKey="value" />
850
+ </ChartElement>
851
+ ));
852
+
853
+ const labels = container.querySelectorAll(".recharts-text.recharts-label");
854
+ expect(labels).toHaveLength(data.length);
855
+ labels.forEach((l) => {
856
+ expect(l).toHaveAttribute("x", expect.any(String));
857
+ expect(l).toHaveAttribute("y", expect.any(String));
858
+ expect(l).toHaveAttribute("height", expect.any(String));
859
+ expect(l).toHaveAttribute("offset", "5");
860
+ expect(l).toHaveAttribute("text-anchor", "middle");
861
+ expect(l).toHaveAttribute("width", "78");
862
+ expect(l).toHaveAttribute("fill", "#808080");
863
+ });
864
+ });
865
+
866
+ it("should not draw labels while animating", () => {
867
+ const { container } = render(() => (
868
+ <ChartElement data={data}>
869
+ <Bar isAnimationActive label dataKey="value" />
870
+ </ChartElement>
871
+ ));
872
+ flush();
873
+
874
+ const labels = container.querySelectorAll(".recharts-text.recharts-label");
875
+ expect(labels).toHaveLength(0);
876
+ });
877
+
878
+ it("should not draw labels when label = false", () => {
879
+ const { container } = renderChart(() => (
880
+ <ChartElement data={data}>
881
+ <Bar isAnimationActive={false} label={false} dataKey="value" />
882
+ </ChartElement>
883
+ ));
884
+
885
+ const labels = container.querySelectorAll(".recharts-text.recharts-label");
886
+ expect(labels).toHaveLength(0);
887
+ });
888
+ });
889
+
890
+ describe("as svg properties object", () => {
891
+ it("should draw labels and add extra props from the object", () => {
892
+ const { container } = renderChart(() => (
893
+ <ChartElement data={data}>
894
+ <Bar
895
+ isAnimationActive={false}
896
+ label={
897
+ {
898
+ fill: "red",
899
+ elevation: 9,
900
+ } as never
901
+ }
902
+ dataKey="value"
903
+ />
904
+ </ChartElement>
905
+ ));
906
+
907
+ expectLabels(container, [
908
+ {
909
+ height: "81.66666666666669",
910
+ offset: "5",
911
+ textContent: "100",
912
+ width: "78",
913
+ x: "53.8",
914
+ y: "454.16666666666663",
915
+ },
916
+ {
917
+ height: "163.33333333333326",
918
+ offset: "5",
919
+ textContent: "200",
920
+ width: "78",
921
+ x: "151.8",
922
+ y: "413.33333333333337",
923
+ },
924
+ {
925
+ height: "245",
926
+ offset: "5",
927
+ textContent: "300",
928
+ width: "78",
929
+ x: "249.8",
930
+ y: "372.5",
931
+ },
932
+ {
933
+ height: "326.66666666666663",
934
+ offset: "5",
935
+ textContent: "400",
936
+ width: "78",
937
+ x: "347.8",
938
+ y: "331.6666666666667",
939
+ },
940
+ {
941
+ height: "408.33333333333337",
942
+ offset: "5",
943
+ textContent: "500",
944
+ width: "78",
945
+ x: "445.8",
946
+ y: "290.83333333333337",
947
+ },
948
+ ]);
949
+ });
950
+
951
+ it("should overwrite the recharts-label className but keep recharts-text className", () => {
952
+ const { container } = renderChart(() => (
953
+ <ChartElement data={data}>
954
+ <Bar
955
+ isAnimationActive={false}
956
+ label={{
957
+ class: "my-test-class",
958
+ }}
959
+ dataKey="value"
960
+ />
961
+ </ChartElement>
962
+ ));
963
+
964
+ const labels = container.querySelectorAll(".recharts-text.recharts-label");
965
+ expect(labels).toHaveLength(0);
966
+ const customLabels = container.querySelectorAll(".my-test-class");
967
+ expect(customLabels).toHaveLength(data.length);
968
+ customLabels.forEach((l) => {
969
+ expect(l).toHaveAttribute("class", "recharts-text my-test-class");
970
+ });
971
+ });
972
+ });
973
+
974
+ describe("as function", () => {
975
+ it("should pass props to the label function", () => {
976
+ const spy = vi.fn().mockReturnValue(null);
977
+ renderChart(() => (
978
+ <ChartElement data={data}>
979
+ <Bar isAnimationActive={false} label={spy} dataKey="value" />
980
+ </ChartElement>
981
+ ));
982
+
983
+ expect(spy).toHaveBeenCalledTimes(data.length);
984
+ // Solid has no StrictMode double-mount; assert the first label call (recharts
985
+ // checks the last of 2×data.length calls after React StrictMode remount).
986
+ expect(spy).toHaveBeenNthCalledWith(1, {
987
+ angle: 0,
988
+ height: expect.any(Number),
989
+ index: expect.any(Number),
990
+ offset: 5,
991
+ parentViewBox: {
992
+ height: expect.any(Number),
993
+ width: expect.any(Number),
994
+ x: expect.any(Number),
995
+ y: expect.any(Number),
996
+ },
997
+ textBreakAll: false,
998
+ position: "middle",
999
+ value: expect.any(Number),
1000
+ viewBox: {
1001
+ height: expect.any(Number),
1002
+ width: expect.any(Number),
1003
+ lowerWidth: expect.any(Number),
1004
+ upperWidth: expect.any(Number),
1005
+ x: expect.any(Number),
1006
+ y: 413.3333333333333,
1007
+ },
1008
+ width: expect.any(Number),
1009
+ x: expect.any(Number),
1010
+ y: expect.any(Number),
1011
+ zIndex: 0,
1012
+ });
1013
+ });
1014
+
1015
+ it("should render what the label function returned", () => {
1016
+ const labelFn = () => <g class="my-mock-class" />;
1017
+ const { container } = renderChart(() => (
1018
+ <ChartElement data={data}>
1019
+ <Bar isAnimationActive={false} label={labelFn} dataKey="value" />
1020
+ </ChartElement>
1021
+ ));
1022
+
1023
+ const labels = container.querySelectorAll(".my-mock-class");
1024
+ expect(labels).toHaveLength(data.length);
1025
+ labels.forEach((l) => {
1026
+ expect.soft(l).not.toHaveAttribute("x");
1027
+ expect.soft(l).not.toHaveAttribute("y");
1028
+ expect.soft(l).not.toHaveAttribute("height");
1029
+ expect.soft(l).not.toHaveAttribute("offset");
1030
+ expect.soft(l).not.toHaveAttribute("text-anchor");
1031
+ expect.soft(l).not.toHaveAttribute("width");
1032
+ expect.soft(l).not.toHaveAttribute("fill");
1033
+ });
1034
+ });
1035
+ });
1036
+
1037
+ describe("as a custom Element", () => {
1038
+ it(`should render what the function returned, and then inject extra sneaky props in it
1039
+ - but not all of them, and not the same as in the other ways of rendering labels`, () => {
1040
+ // Solid 2 has no cloneElement; a pre-created `<g />` is an opaque object.
1041
+ // Behavioral parity: render fn spreads entry attrs onto the template class.
1042
+ const MyLabel = (labelProps: LabelProps) => (
1043
+ <g
1044
+ class="my-mock-class"
1045
+ {...svgPropertiesAndEvents(
1046
+ omit(
1047
+ labelProps as Record<string, unknown>,
1048
+ "content",
1049
+ "viewBox",
1050
+ "formatter",
1051
+ "value",
1052
+ "children",
1053
+ "position",
1054
+ "angle",
1055
+ "textBreakAll",
1056
+ "index",
1057
+ "id",
1058
+ "zIndex",
1059
+ "parentViewBox",
1060
+ "class",
1061
+ ),
1062
+ )}
1063
+ />
1064
+ );
1065
+ const { container } = renderChart(() => (
1066
+ <ChartElement data={data}>
1067
+ <Bar isAnimationActive={false} label={MyLabel} dataKey="value" />
1068
+ </ChartElement>
1069
+ ));
1070
+
1071
+ expectLabels(
1072
+ container,
1073
+ [
1074
+ {
1075
+ height: "81.66666666666669",
1076
+ offset: "5",
1077
+ textContent: "",
1078
+ width: "78",
1079
+ x: "14.8",
1080
+ y: "413.3333333333333",
1081
+ },
1082
+ {
1083
+ height: "163.33333333333326",
1084
+ offset: "5",
1085
+ textContent: "",
1086
+ width: "78",
1087
+ x: "112.8",
1088
+ y: "331.66666666666674",
1089
+ },
1090
+ {
1091
+ height: "245",
1092
+ offset: "5",
1093
+ textContent: "",
1094
+ width: "78",
1095
+ x: "210.8",
1096
+ y: "250",
1097
+ },
1098
+ {
1099
+ height: "326.66666666666663",
1100
+ offset: "5",
1101
+ textContent: "",
1102
+ width: "78",
1103
+ x: "308.8",
1104
+ y: "168.33333333333337",
1105
+ },
1106
+ {
1107
+ height: "408.33333333333337",
1108
+ offset: "5",
1109
+ textContent: "",
1110
+ width: "78",
1111
+ x: "406.8",
1112
+ y: "86.66666666666666",
1113
+ },
1114
+ ],
1115
+ ".my-mock-class",
1116
+ );
1117
+ });
1118
+ });
1119
+ });
1120
+
1121
+ describe("minPointSize", () => {
1122
+ const highLowData = [
1123
+ { name: "test1", value: 10000 },
1124
+ { name: "test2", value: 0 },
1125
+ { name: "test3", value: 1 },
1126
+ ];
1127
+
1128
+ it("should pass props to the minPointSize function", () => {
1129
+ const spy = vi.fn().mockImplementation(() => 5);
1130
+ renderChart(() => (
1131
+ <ChartElement data={highLowData}>
1132
+ <XAxis dataKey="name" />
1133
+ <YAxis />
1134
+ <Bar isAnimationActive={false} minPointSize={spy} dataKey="value" />
1135
+ </ChartElement>
1136
+ ));
1137
+
1138
+ expect(spy).toBeCalledWith(expect.any(Number), expect.any(Number));
1139
+ });
1140
+
1141
+ it("should ignore 0 value bars when minPointSize is undefined, and render the small bars really really small", () => {
1142
+ const { container } = renderChart(() => (
1143
+ <ChartElement data={highLowData}>
1144
+ <XAxis dataKey="name" />
1145
+ <Bar isAnimationActive={false} dataKey="value" />
1146
+ </ChartElement>
1147
+ ));
1148
+
1149
+ expectBars(container, [
1150
+ {
1151
+ x: "21.3333",
1152
+ y: "5",
1153
+ width: "131",
1154
+ height: "460",
1155
+ radius: "0",
1156
+ d: "M 21.3333,5 h 131 v 460 h -131 Z",
1157
+ },
1158
+ {
1159
+ x: "348",
1160
+ y: "464.954",
1161
+ width: "131",
1162
+ height: "0.046",
1163
+ radius: "0",
1164
+ d: "M 348,464.954 h 131 v 0.046 h -131 Z",
1165
+ },
1166
+ ]);
1167
+ });
1168
+
1169
+ it("should assign minimum height to low value bars if minPointSize is a number", () => {
1170
+ const { container } = renderChart(() => (
1171
+ <ChartElement data={highLowData}>
1172
+ <XAxis dataKey="name" />
1173
+ <YAxis />
1174
+ <Bar isAnimationActive={false} minPointSize={5} dataKey="value" />
1175
+ </ChartElement>
1176
+ ));
1177
+
1178
+ expectBars(container, [
1179
+ {
1180
+ x: "79.3333",
1181
+ y: "5",
1182
+ width: "115",
1183
+ height: "460",
1184
+ radius: "0",
1185
+ d: "M 79.3333,5 h 115 v 460 h -115 Z",
1186
+ },
1187
+ {
1188
+ x: "222.6667",
1189
+ y: "460",
1190
+ width: "115",
1191
+ height: "5",
1192
+ radius: "0",
1193
+ d: "M 222.6667,460 h 115 v 5 h -115 Z",
1194
+ },
1195
+ {
1196
+ x: "366",
1197
+ y: "460",
1198
+ width: "115",
1199
+ height: "5",
1200
+ radius: "0",
1201
+ d: "M 366,460 h 115 v 5 h -115 Z",
1202
+ },
1203
+ ]);
1204
+ });
1205
+
1206
+ it("should assign minimum width, in a vertical chart", () => {
1207
+ const { container } = renderChart(() => (
1208
+ <ChartElement data={highLowData} layout="vertical">
1209
+ <XAxis dataKey="value" type="number" />
1210
+ <YAxis dataKey="name" type="category" />
1211
+ <Bar isAnimationActive={false} minPointSize={5} dataKey="value" />
1212
+ </ChartElement>
1213
+ ));
1214
+
1215
+ expectBars(container, [
1216
+ {
1217
+ x: "65",
1218
+ y: "20.3333",
1219
+ width: "430",
1220
+ height: "123",
1221
+ radius: "0",
1222
+ d: "M 65,20.3333 h 430 v 123 h -430 Z",
1223
+ },
1224
+ {
1225
+ x: "65",
1226
+ y: "173.6667",
1227
+ width: "5",
1228
+ height: "123",
1229
+ radius: "0",
1230
+ d: "M 65,173.6667 h 5 v 123 h -5 Z",
1231
+ },
1232
+ {
1233
+ x: "65",
1234
+ y: "327",
1235
+ width: "5",
1236
+ height: "123",
1237
+ radius: "0",
1238
+ d: "M 65,327 h 5 v 123 h -5 Z",
1239
+ },
1240
+ ]);
1241
+ });
1242
+
1243
+ it("should render with varying minPointSize as per function results", () => {
1244
+ const { container } = renderChart(() => (
1245
+ <ChartElement data={highLowData}>
1246
+ <XAxis dataKey="name" />
1247
+ <YAxis />
1248
+ <Bar
1249
+ isAnimationActive={false}
1250
+ minPointSize={(value: number | undefined | null) =>
1251
+ value != null && value > 0 ? 2 : 0
1252
+ }
1253
+ dataKey="value"
1254
+ />
1255
+ </ChartElement>
1256
+ ));
1257
+
1258
+ expectBars(container, [
1259
+ {
1260
+ x: "79.3333",
1261
+ y: "5",
1262
+ width: "115",
1263
+ height: "460",
1264
+ radius: "0",
1265
+ d: "M 79.3333,5 h 115 v 460 h -115 Z",
1266
+ },
1267
+ {
1268
+ x: "366",
1269
+ y: "463",
1270
+ width: "115",
1271
+ height: "2",
1272
+ radius: "0",
1273
+ d: "M 366,463 h 115 v 2 h -115 Z",
1274
+ },
1275
+ ]);
1276
+ });
1277
+ });
1278
+
1279
+ describe("With background", () => {
1280
+ const composedDataWithBackground = [
1281
+ {
1282
+ x: 10,
1283
+ y: 50,
1284
+ width: 20,
1285
+ height: 20,
1286
+ value: 40,
1287
+ label: "test",
1288
+ background: { x: 10, y: 50, width: 20, height: 50 },
1289
+ },
1290
+ {
1291
+ x: 50,
1292
+ y: 50,
1293
+ width: 20,
1294
+ height: 50,
1295
+ value: 100,
1296
+ label: "test",
1297
+ background: { x: 50, y: 50, width: 20, height: 50 },
1298
+ },
1299
+ ];
1300
+
1301
+ it("Will create a background Rectangle with the passed in props", () => {
1302
+ const { container } = renderChart(() => (
1303
+ <ChartElement data={composedDataWithBackground}>
1304
+ <Bar background={{ fill: "#000" }} dataKey="value" />
1305
+ </ChartElement>
1306
+ ));
1307
+
1308
+ expect(container.querySelectorAll(".recharts-bar-background-rectangle")).toHaveLength(
1309
+ composedDataWithBackground.length,
1310
+ );
1311
+
1312
+ expectBars(container, []);
1313
+ });
1314
+
1315
+ it("Will accept a function for the background prop", () => {
1316
+ const className = "test-custom-background";
1317
+ const backgroundComponent = () => {
1318
+ return <g class={className} />;
1319
+ };
1320
+ const { container } = renderChart(() => (
1321
+ <ChartElement data={composedDataWithBackground}>
1322
+ <Bar background={backgroundComponent} dataKey="value" />
1323
+ </ChartElement>
1324
+ ));
1325
+
1326
+ expect(container.querySelectorAll(`.${className}`)).toHaveLength(
1327
+ composedDataWithBackground.length,
1328
+ );
1329
+ });
1330
+
1331
+ it("should pass props to the custom background function", () => {
1332
+ const expectedProps = {
1333
+ class: "recharts-bar-background-rectangle",
1334
+ dataKey: "value",
1335
+ fill: "#eee",
1336
+ height: 490,
1337
+ index: expect.any(Number),
1338
+ isActive: false,
1339
+ label: "test",
1340
+ onMouseEnter: expect.any(Function),
1341
+ onMouseLeave: expect.any(Function),
1342
+ onClick: expect.any(Function),
1343
+ originalDataIndex: expect.any(Number),
1344
+ payload: {
1345
+ background: {
1346
+ height: 50,
1347
+ width: 20,
1348
+ x: expect.any(Number),
1349
+ y: 50,
1350
+ },
1351
+ height: expect.any(Number),
1352
+ label: "test",
1353
+ value: expect.any(Number),
1354
+ width: 20,
1355
+ x: expect.any(Number),
1356
+ y: 50,
1357
+ },
1358
+ stackedBarStart: expect.any(Number),
1359
+ width: 196,
1360
+ x: expect.any(Number),
1361
+ y: 5,
1362
+ parentViewBox: {
1363
+ height: expect.any(Number),
1364
+ width: expect.any(Number),
1365
+ x: expect.any(Number),
1366
+ y: expect.any(Number),
1367
+ },
1368
+ };
1369
+ const backgroundComponent = (props: unknown) => {
1370
+ expect.soft(props).toEqual(expectedProps);
1371
+ return <></>;
1372
+ };
1373
+ renderChart(() => (
1374
+ <ChartElement data={composedDataWithBackground}>
1375
+ <Bar background={backgroundComponent} dataKey="value" />
1376
+ </ChartElement>
1377
+ ));
1378
+ });
1379
+ });
1380
+
1381
+ describe("state integration", () => {
1382
+ it("should report its props to redux state, and remove them when removed from DOM", () => {
1383
+ const spy = vi.fn();
1384
+ const [showBar, setShowBar] = createSignal(true);
1385
+
1386
+ const Comp = (): null => {
1387
+ const cartesianItems = useAppSelector((state) => state.graphicalItems.cartesianItems);
1388
+ createEffect(
1389
+ () => cartesianItems(),
1390
+ (items) => spy(items),
1391
+ );
1392
+ return null;
1393
+ };
1394
+
1395
+ renderChart(() => (
1396
+ <ChartElement data={data}>
1397
+ <Show when={showBar()}>
1398
+ <Bar
1399
+ dataKey="value"
1400
+ xAxisId={7}
1401
+ yAxisId={9}
1402
+ stackId="q"
1403
+ hide
1404
+ minPointSize={3}
1405
+ maxBarSize={90}
1406
+ barSize={13}
1407
+ />
1408
+ </Show>
1409
+ <Comp />
1410
+ </ChartElement>
1411
+ ));
1412
+
1413
+ const expected: ReadonlyArray<BarSettings> = [
1414
+ {
1415
+ id: expect.stringMatching("^recharts-bar-[:a-z0-9]+$"),
1416
+ isPanorama: false,
1417
+ type: "bar",
1418
+ data: undefined,
1419
+ dataKey: "value",
1420
+ xAxisId: 7,
1421
+ yAxisId: 9,
1422
+ zAxisId: 0,
1423
+ stackId: "q",
1424
+ hide: true,
1425
+ barSize: 13,
1426
+ minPointSize: 3,
1427
+ maxBarSize: 90,
1428
+ hasCustomShape: false,
1429
+ },
1430
+ ];
1431
+ expectLastCalledWith(spy, expected);
1432
+
1433
+ setShowBar(false);
1434
+ flush();
1435
+ flush();
1436
+ expectLastCalledWith(spy, []);
1437
+ });
1438
+
1439
+ it("should report default props to redux state", () => {
1440
+ const spy = vi.fn();
1441
+
1442
+ const Comp = (): null => {
1443
+ const cartesianItems = useAppSelector((state) => state.graphicalItems.cartesianItems);
1444
+ createEffect(
1445
+ () => cartesianItems(),
1446
+ (items) => spy(items),
1447
+ );
1448
+ return null;
1449
+ };
1450
+
1451
+ renderChart(() => (
1452
+ <ChartElement data={data}>
1453
+ <Bar dataKey="value" />
1454
+ <Comp />
1455
+ </ChartElement>
1456
+ ));
1457
+
1458
+ const expected: ReadonlyArray<CartesianGraphicalItemSettings> = [
1459
+ {
1460
+ id: expect.stringMatching("^recharts-bar-[:a-z0-9]+$"),
1461
+ isPanorama: false,
1462
+ type: "bar",
1463
+ data: undefined,
1464
+ dataKey: "value",
1465
+ xAxisId: 0,
1466
+ yAxisId: 0,
1467
+ zAxisId: 0,
1468
+ stackId: undefined,
1469
+ hide: false,
1470
+ barSize: undefined,
1471
+ minPointSize: 0,
1472
+ maxBarSize: undefined,
1473
+ hasCustomShape: false,
1474
+ },
1475
+ ];
1476
+ expectLastCalledWith(spy, expected);
1477
+ });
1478
+ });
1479
+
1480
+ describe("legendType", () => {
1481
+ const allLegendTypesExceptNone: ReadonlyArray<LegendType> = [
1482
+ "circle",
1483
+ "cross",
1484
+ "diamond",
1485
+ "line",
1486
+ "plainline",
1487
+ "rect",
1488
+ "square",
1489
+ "star",
1490
+ "triangle",
1491
+ "wye",
1492
+ ];
1493
+
1494
+ test.each(allLegendTypesExceptNone)("should render legendType %s", (legendType) => {
1495
+ const { container } = renderChart(() => (
1496
+ <ChartElement data={data}>
1497
+ <Bar dataKey="value" legendType={legendType} />
1498
+ <Legend />
1499
+ </ChartElement>
1500
+ ));
1501
+
1502
+ const legendIcon = container.querySelectorAll(".recharts-legend-item-text");
1503
+ expect(legendIcon).toHaveLength(1);
1504
+ });
1505
+
1506
+ it("should not render any legend if legendType = none", () => {
1507
+ const { container } = renderChart(() => (
1508
+ <ChartElement data={data}>
1509
+ <Bar dataKey="value" legendType="none" />
1510
+ <Legend />
1511
+ </ChartElement>
1512
+ ));
1513
+
1514
+ const legendIcon = container.querySelectorAll(".recharts-legend-item-text");
1515
+ expect(legendIcon).toHaveLength(0);
1516
+ });
1517
+ });
1518
+ });
1519
+
1520
+ describe.each(chartsThatDoNotSupportBar)("<Bar /> as a child of $testName", ({ ChartElement }) => {
1521
+ it("should not render anything", () => {
1522
+ const { container } = renderChart(() => (
1523
+ <ChartElement data={data}>
1524
+ <Bar isAnimationActive={false} dataKey="value" />
1525
+ </ChartElement>
1526
+ ));
1527
+
1528
+ expect(container.querySelectorAll(".recharts-bar-rectangle")).toHaveLength(0);
1529
+ });
1530
+ });
1531
+
1532
+ describe("mouse interactions in stacked bar: https://github.com/recharts/recharts/issues/5124", () => {
1533
+ beforeEach(() => {
1534
+ mockGetBoundingClientRect({ width: 100, height: 100 });
1535
+ });
1536
+
1537
+ const stackedData = [{ x: 1, y: 2 }];
1538
+
1539
+ const stackedBars = [
1540
+ {
1541
+ d: "M 14,65 h 72 v 30 h -72 Z",
1542
+ height: "30",
1543
+ radius: "0",
1544
+ width: "72",
1545
+ x: "14",
1546
+ y: "65",
1547
+ },
1548
+ {
1549
+ d: "M 14,5 h 72 v 60 h -72 Z",
1550
+ height: "60",
1551
+ radius: "0",
1552
+ width: "72",
1553
+ x: "14",
1554
+ y: "5",
1555
+ },
1556
+ ];
1557
+
1558
+ describe("with Tooltip shared=true", () => {
1559
+ const renderTestCase = createSelectorTestCase((props) => (
1560
+ <BarChart data={stackedData} width={100} height={100}>
1561
+ <Bar activeBar dataKey="x" stackId="1" isAnimationActive={false} />
1562
+ <Bar activeBar dataKey="y" stackId="1" isAnimationActive={false} />
1563
+ <Tooltip shared isAnimationActive={false} />
1564
+ {props.children}
1565
+ </BarChart>
1566
+ ));
1567
+
1568
+ it("should render two bars on the same index", () => {
1569
+ const { container } = renderTestCase();
1570
+ expectBars(container, stackedBars);
1571
+ });
1572
+
1573
+ it("should render all bars inactive before user interaction", () => {
1574
+ const { container } = renderTestCase();
1575
+ const bars = getAllBars(container);
1576
+ expectActiveBars(container, []);
1577
+ expect(bars).toHaveLength(2);
1578
+ });
1579
+
1580
+ it("should show tooltip when hovering over a chart", () => {
1581
+ const { container, spy } = renderTestCase(selectActiveTooltipIndex);
1582
+ expectLastCalledWith(spy, null);
1583
+
1584
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
1585
+ clientX: 10,
1586
+ clientY: 10,
1587
+ });
1588
+ expectLastCalledWith(spy, "0");
1589
+ expectTooltipPayload(container, "0", ["x : 1", "y : 2"]);
1590
+ });
1591
+
1592
+ it("should show tooltip somewhere close to the mouse cursor", () => {
1593
+ mockGetBoundingClientRect({
1594
+ width: 10,
1595
+ height: 10,
1596
+ });
1597
+ const { container } = renderTestCase();
1598
+
1599
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
1600
+ clientX: 10,
1601
+ clientY: 10,
1602
+ });
1603
+ expectTooltipCoordinate(container, { x: 60, y: 20 });
1604
+
1605
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
1606
+ clientX: 20,
1607
+ clientY: 20,
1608
+ });
1609
+ expectTooltipCoordinate(container, { x: 60, y: 30 });
1610
+ });
1611
+
1612
+ it("should make both bars active when hovering over the chart", () => {
1613
+ const { container } = renderTestCase();
1614
+
1615
+ expectActiveBars(container, []);
1616
+
1617
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
1618
+ clientX: 10,
1619
+ clientY: 10,
1620
+ });
1621
+ vi.runOnlyPendingTimers();
1622
+ flush();
1623
+
1624
+ expectActiveBars(container, stackedBars);
1625
+ });
1626
+ });
1627
+
1628
+ describe("with Tooltip shared=false", () => {
1629
+ const renderTestCase = createSelectorTestCase((props) => (
1630
+ <BarChart data={stackedData} width={100} height={100}>
1631
+ <Bar activeBar dataKey="x" stackId="1" isAnimationActive={false} />
1632
+ <Bar activeBar dataKey="y" stackId="1" isAnimationActive={false} />
1633
+ <Tooltip shared={false} isAnimationActive={false} />
1634
+ {props.children}
1635
+ </BarChart>
1636
+ ));
1637
+
1638
+ it("should render two bars on the same index", () => {
1639
+ const { container } = renderTestCase();
1640
+ expectBars(container, stackedBars);
1641
+ });
1642
+
1643
+ it("should render all bars inactive before user interaction", () => {
1644
+ const { container } = renderTestCase();
1645
+ const bars = getAllBars(container);
1646
+
1647
+ expectActiveBars(container, []);
1648
+ expect(bars).toHaveLength(2);
1649
+ });
1650
+
1651
+ it("should show tooltip when hovering over a bar", () => {
1652
+ const { container, spy } = renderTestCase(selectActiveTooltipIndex);
1653
+ expectLastCalledWith(spy, null);
1654
+
1655
+ const bars = getAllBars(container);
1656
+ showTooltipOnCoordinate(bars[0]!, undefined, { clientX: 10, clientY: 10 });
1657
+ expectLastCalledWith(spy, "0");
1658
+ expectTooltipPayload(container, "", ["x : 1"]);
1659
+ });
1660
+
1661
+ it("should select tooltip axis ticks", () => {
1662
+ const { spy } = renderTestCase(selectTooltipAxisTicks);
1663
+ expectLastCalledWith(spy, [
1664
+ {
1665
+ coordinate: 50,
1666
+ index: 0,
1667
+ offset: 45,
1668
+ value: 0,
1669
+ },
1670
+ ]);
1671
+ });
1672
+
1673
+ it("should update tooltip interaction state after mouse hover", () => {
1674
+ const { container, spy } = renderTestCase((state) => state.tooltip);
1675
+ const expectedStateBeforeHover: TooltipState = {
1676
+ axisInteraction: {
1677
+ click: noInteraction,
1678
+ hover: noInteraction,
1679
+ },
1680
+ itemInteraction: {
1681
+ click: noInteraction,
1682
+ hover: noInteraction,
1683
+ },
1684
+ keyboardInteraction: noInteraction,
1685
+ settings: {
1686
+ active: undefined,
1687
+ axisId: 0,
1688
+ defaultIndex: undefined,
1689
+ shared: false,
1690
+ trigger: "hover",
1691
+ },
1692
+ syncInteraction: {
1693
+ ...noInteraction,
1694
+ label: undefined,
1695
+ sourceViewBox: undefined,
1696
+ },
1697
+ tooltipItemPayloads: [
1698
+ {
1699
+ dataDefinedOnItem: undefined,
1700
+ getPosition: expect.any(Function),
1701
+ settings: {
1702
+ color: undefined,
1703
+ dataKey: "x",
1704
+ fill: undefined,
1705
+ graphicalItemId: expect.stringMatching(/^recharts-bar-.+/),
1706
+ hide: false,
1707
+ name: "x",
1708
+ nameKey: undefined,
1709
+ stroke: undefined,
1710
+ strokeWidth: undefined,
1711
+ type: undefined,
1712
+ unit: undefined,
1713
+ },
1714
+ },
1715
+ {
1716
+ dataDefinedOnItem: undefined,
1717
+ getPosition: expect.any(Function),
1718
+ settings: {
1719
+ color: undefined,
1720
+ dataKey: "y",
1721
+ fill: undefined,
1722
+ graphicalItemId: expect.stringMatching(/^recharts-bar-.+/),
1723
+ hide: false,
1724
+ name: "y",
1725
+ nameKey: undefined,
1726
+ stroke: undefined,
1727
+ strokeWidth: undefined,
1728
+ type: undefined,
1729
+ unit: undefined,
1730
+ },
1731
+ },
1732
+ ],
1733
+ };
1734
+ expectLastCalledWith(spy, expectedStateBeforeHover);
1735
+
1736
+ const bars = getAllBars(container);
1737
+ showTooltipOnCoordinate(bars[0]!, undefined, { clientX: 10, clientY: 10 });
1738
+
1739
+ const expectedStateAfterHover: TooltipState = {
1740
+ axisInteraction: {
1741
+ click: noInteraction,
1742
+ hover: noInteraction,
1743
+ },
1744
+ itemInteraction: {
1745
+ click: noInteraction,
1746
+ hover: {
1747
+ active: true,
1748
+ coordinate: {
1749
+ x: 50,
1750
+ y: 80,
1751
+ },
1752
+ dataKey: "x",
1753
+ index: "0",
1754
+ graphicalItemId: expect.stringMatching(/^recharts-bar-.+/),
1755
+ },
1756
+ },
1757
+ keyboardInteraction: noInteraction,
1758
+ settings: {
1759
+ active: undefined,
1760
+ axisId: 0,
1761
+ defaultIndex: undefined,
1762
+ shared: false,
1763
+ trigger: "hover",
1764
+ },
1765
+ syncInteraction: {
1766
+ ...noInteraction,
1767
+ label: undefined,
1768
+ sourceViewBox: undefined,
1769
+ },
1770
+ tooltipItemPayloads: [
1771
+ {
1772
+ dataDefinedOnItem: undefined,
1773
+ getPosition: expect.any(Function),
1774
+ settings: {
1775
+ color: undefined,
1776
+ dataKey: "x",
1777
+ fill: undefined,
1778
+ graphicalItemId: expect.stringMatching(/^recharts-bar-.+/),
1779
+ hide: false,
1780
+ name: "x",
1781
+ nameKey: undefined,
1782
+ stroke: undefined,
1783
+ strokeWidth: undefined,
1784
+ type: undefined,
1785
+ unit: undefined,
1786
+ },
1787
+ },
1788
+ {
1789
+ dataDefinedOnItem: undefined,
1790
+ getPosition: expect.any(Function),
1791
+ settings: {
1792
+ color: undefined,
1793
+ dataKey: "y",
1794
+ fill: undefined,
1795
+ graphicalItemId: expect.stringMatching(/^recharts-bar-.+/),
1796
+ hide: false,
1797
+ name: "y",
1798
+ nameKey: undefined,
1799
+ stroke: undefined,
1800
+ strokeWidth: undefined,
1801
+ type: undefined,
1802
+ unit: undefined,
1803
+ },
1804
+ },
1805
+ ],
1806
+ };
1807
+ expectLastCalledWith(spy, expectedStateAfterHover);
1808
+ });
1809
+
1810
+ it("should show tooltip somewhere close to the mouse cursor", () => {
1811
+ mockGetBoundingClientRect({
1812
+ width: 10,
1813
+ height: 10,
1814
+ });
1815
+ const { container } = renderTestCase();
1816
+
1817
+ const bars = getAllBars(container);
1818
+ showTooltipOnCoordinate(bars[0]!, undefined, { clientX: 10, clientY: 10 });
1819
+ expectTooltipCoordinate(container, { x: 60, y: 60 });
1820
+
1821
+ showTooltipOnCoordinate(bars[0]!, undefined, { clientX: 20, clientY: 20 });
1822
+ /*
1823
+ * okay so it shows the tooltip at the same place as the last time, not the new mouse position
1824
+ * - fine, it's sticking to the item, not the mouse.
1825
+ */
1826
+ expectTooltipCoordinate(container, { x: 60, y: 60 });
1827
+
1828
+ // let's hover over the second bar and check the coordinate again
1829
+ showTooltipOnCoordinate(bars[1]!, undefined, { clientX: 20, clientY: 20 });
1830
+ expectTooltipCoordinate(container, { x: 60, y: 45.00000000000001 });
1831
+ });
1832
+
1833
+ it("should make the first bar active - but not the second one - when hovering over it", () => {
1834
+ const { container } = renderTestCase();
1835
+ const bars = getAllBars(container);
1836
+ expectActiveBars(container, []);
1837
+
1838
+ showTooltipOnCoordinate(bars[0]!, undefined, { clientX: 10, clientY: 10 });
1839
+ expectActiveBars(container, [stackedBars[0]!]);
1840
+ });
1841
+ });
1842
+ });
1843
+
1844
+ describe("Bar events", () => {
1845
+ it("should fire onClick event when clicking on a bar", () => {
1846
+ const handleClick = vi.fn();
1847
+ const { container } = renderChart(() => (
1848
+ <BarChart width={200} height={200} layout="horizontal" data={data}>
1849
+ <Bar isAnimationActive={false} dataKey="value" onClick={handleClick} />
1850
+ </BarChart>
1851
+ ));
1852
+
1853
+ const bars = getAllBars(container);
1854
+ const index = 1;
1855
+ fireEvent.click(bars[index]!);
1856
+ expect(handleClick).toHaveBeenCalledTimes(1);
1857
+ expectLastCalledWith(
1858
+ handleClick,
1859
+ expect.objectContaining({
1860
+ label: "test2",
1861
+ originalDataIndex: 1,
1862
+ value: 200,
1863
+ payload: expect.objectContaining({ label: "test2", value: 200 }),
1864
+ }),
1865
+ index,
1866
+ expect.any(Object),
1867
+ );
1868
+ });
1869
+
1870
+ it("should fire onMouseOver and onMouseOut events when hovering over a bar", () => {
1871
+ const handleMouseOver = vi.fn();
1872
+ const handleMouseOut = vi.fn();
1873
+
1874
+ const { container } = renderChart(() => (
1875
+ <BarChart width={200} height={200} layout="horizontal" data={data}>
1876
+ <Bar
1877
+ isAnimationActive={false}
1878
+ dataKey="value"
1879
+ onMouseOver={handleMouseOver}
1880
+ onMouseOut={handleMouseOut}
1881
+ />
1882
+ </BarChart>
1883
+ ));
1884
+
1885
+ const bars = getAllBars(container);
1886
+ fireEvent.mouseOver(bars[1]!);
1887
+ expect(handleMouseOver).toHaveBeenCalledTimes(1);
1888
+ expectLastCalledWith(
1889
+ handleMouseOver,
1890
+ expect.objectContaining({ label: "test2", originalDataIndex: 1, value: 200 }),
1891
+ 1,
1892
+ expect.any(Object),
1893
+ );
1894
+
1895
+ fireEvent.mouseOut(bars[1]!);
1896
+ expect(handleMouseOut).toHaveBeenCalledTimes(1);
1897
+ expectLastCalledWith(
1898
+ handleMouseOut,
1899
+ expect.objectContaining({ label: "test2", originalDataIndex: 1, value: 200 }),
1900
+ 1,
1901
+ expect.any(Object),
1902
+ );
1903
+ });
1904
+
1905
+ it("should fire onMouseMove, onMouseDown and onMouseUp events on a bar", () => {
1906
+ const handleMouseMove = vi.fn();
1907
+ const handleMouseDown = vi.fn();
1908
+ const handleMouseUp = vi.fn();
1909
+
1910
+ const { container } = renderChart(() => (
1911
+ <BarChart width={200} height={200} layout="horizontal" data={data}>
1912
+ <Bar
1913
+ isAnimationActive={false}
1914
+ dataKey="value"
1915
+ onMouseMove={handleMouseMove}
1916
+ onMouseDown={handleMouseDown}
1917
+ onMouseUp={handleMouseUp}
1918
+ />
1919
+ </BarChart>
1920
+ ));
1921
+
1922
+ // move/down/up ride the rectangle path itself (the reference's wrapping-g
1923
+ // attachment is bubble-equivalent for these events) — fire on the path.
1924
+ const bars = getAllBarPaths(container);
1925
+
1926
+ fireEvent.mouseMove(bars[1]!, { clientX: 10, clientY: 10 });
1927
+ expect(handleMouseMove).toHaveBeenCalledTimes(1);
1928
+ expectLastCalledWith(
1929
+ handleMouseMove,
1930
+ expect.objectContaining({ label: "test2", originalDataIndex: 1, value: 200 }),
1931
+ 1,
1932
+ expect.any(Object),
1933
+ );
1934
+
1935
+ fireEvent.mouseDown(bars[1]!);
1936
+ expect(handleMouseDown).toHaveBeenCalledTimes(1);
1937
+ expectLastCalledWith(
1938
+ handleMouseDown,
1939
+ expect.objectContaining({ label: "test2", originalDataIndex: 1, value: 200 }),
1940
+ 1,
1941
+ expect.any(Object),
1942
+ );
1943
+
1944
+ fireEvent.mouseUp(bars[1]!);
1945
+ expect(handleMouseUp).toHaveBeenCalledTimes(1);
1946
+ expectLastCalledWith(
1947
+ handleMouseUp,
1948
+ expect.objectContaining({ label: "test2", originalDataIndex: 1, value: 200 }),
1949
+ 1,
1950
+ expect.any(Object),
1951
+ );
1952
+ });
1953
+
1954
+ it("should fire onTouchMove and onTouchEnd events when touching a bar", () => {
1955
+ const handleTouchMove = vi.fn();
1956
+ const handleTouchEnd = vi.fn();
1957
+
1958
+ const { container } = renderChart(() => (
1959
+ <BarChart width={200} height={200} layout="horizontal" data={data} throttledEvents={[]}>
1960
+ <Bar
1961
+ isAnimationActive={false}
1962
+ dataKey="value"
1963
+ onTouchMove={handleTouchMove}
1964
+ onTouchEnd={handleTouchEnd}
1965
+ />
1966
+ </BarChart>
1967
+ ));
1968
+
1969
+ const bars = getAllBars(container);
1970
+ fireEvent.touchMove(bars[0]!, { touches: [{ clientX: 200, clientY: 200 }] });
1971
+ expect(handleTouchMove).toHaveBeenCalledTimes(1);
1972
+ expectLastCalledWith(
1973
+ handleTouchMove,
1974
+ expect.objectContaining({ label: "test1", originalDataIndex: 0, value: 100 }),
1975
+ 0,
1976
+ expect.any(Object),
1977
+ );
1978
+ });
1979
+ });
1980
+
1981
+ // Regression: the item-dispatch hooks used to receive `dataKey`/handlers BY VALUE
1982
+ // from an untracked component-body read — a signal-driven dataKey tripped
1983
+ // STRICT_READ_UNTRACKED (the global diagnostics guard fails this test if it
1984
+ // fires) and the dispatched payload's activeDataKey went stale. The hooks now
1985
+ // take getters and read at event time.
1986
+ describe("Bar with a signal-driven dataKey", () => {
1987
+ const dualKeyData = [
1988
+ { label: "test1", value: 100, value2: 500 },
1989
+ { label: "test2", value: 200, value2: 400 },
1990
+ { label: "test3", value: 300, value2: 300 },
1991
+ ];
1992
+
1993
+ it("re-renders the bars and dispatches the fresh dataKey after the signal changes", () => {
1994
+ const [barDataKey, setBarDataKey] = createSignal<string>("value");
1995
+ const handleClick = vi.fn();
1996
+ const activeDataKeySpy = vi.fn();
1997
+
1998
+ function ActiveDataKeySpy(): JSX.Element {
1999
+ const activeDataKey = useAppSelector(selectActiveTooltipDataKey);
2000
+ createEffect(
2001
+ () => activeDataKey(),
2002
+ (dk) => {
2003
+ activeDataKeySpy(dk);
2004
+ },
2005
+ );
2006
+ return null;
2007
+ }
2008
+
2009
+ const { container } = renderChart(() => (
2010
+ <BarChart width={200} height={200} layout="horizontal" data={dualKeyData}>
2011
+ <Bar isAnimationActive={false} dataKey={barDataKey()} onClick={handleClick} />
2012
+ {/* shared={false} → item-type tooltip, so the item dispatch's activeDataKey
2013
+ lands in the stored interaction state the spy reads. */}
2014
+ <Tooltip shared={false} />
2015
+ <ActiveDataKeySpy />
2016
+ </BarChart>
2017
+ ));
2018
+
2019
+ const before = Array.from(getAllBarPaths(container)).map((bar) => bar.getAttribute("d"));
2020
+ expect(before).toHaveLength(dualKeyData.length);
2021
+
2022
+ // Exercise the item-dispatch path while the dataKey comes from a signal.
2023
+ showTooltipOnCoordinate(getAllBars(container)[0]!, undefined, { clientX: 10, clientY: 10 });
2024
+ flush();
2025
+ expect(activeDataKeySpy).toHaveBeenLastCalledWith("value");
2026
+ fireEvent.click(getAllBars(container)[0]!);
2027
+ expect(handleClick).toHaveBeenCalledTimes(1);
2028
+ expectLastCalledWith(
2029
+ handleClick,
2030
+ expect.objectContaining({ value: 100 }),
2031
+ 0,
2032
+ expect.any(Object),
2033
+ );
2034
+
2035
+ setBarDataKey("value2");
2036
+ flush();
2037
+
2038
+ // The chart re-rendered against the new dataKey…
2039
+ const after = Array.from(getAllBarPaths(container)).map((bar) => bar.getAttribute("d"));
2040
+ expect(after).toHaveLength(dualKeyData.length);
2041
+ expect(after).not.toEqual(before);
2042
+
2043
+ // …and a fresh interaction dispatches the NEW dataKey (the by-value hook
2044
+ // captured the mount-time "value" forever).
2045
+ showTooltipOnCoordinate(getAllBars(container)[1]!, undefined, { clientX: 11, clientY: 11 });
2046
+ flush();
2047
+ expect(activeDataKeySpy).toHaveBeenLastCalledWith("value2");
2048
+ fireEvent.click(getAllBars(container)[1]!);
2049
+ expect(handleClick).toHaveBeenCalledTimes(2);
2050
+ expectLastCalledWith(
2051
+ handleClick,
2052
+ expect.objectContaining({ value: 400 }),
2053
+ 1,
2054
+ expect.any(Object),
2055
+ );
2056
+ });
2057
+ });
2058
+
2059
+ describe("Bar background zIndex", () => {
2060
+ const composedDataWithBackground = [
2061
+ {
2062
+ x: 10,
2063
+ y: 50,
2064
+ width: 20,
2065
+ height: 20,
2066
+ value: 40,
2067
+ label: "test",
2068
+ background: { x: 10, y: 50, width: 20, height: 50 },
2069
+ },
2070
+ {
2071
+ x: 50,
2072
+ y: 50,
2073
+ width: 20,
2074
+ height: 50,
2075
+ value: 100,
2076
+ label: "test",
2077
+ background: { x: 50, y: 50, width: 20, height: 50 },
2078
+ },
2079
+ ];
2080
+
2081
+ it("should use default barBackground zIndex when background prop is true", () => {
2082
+ const { container } = renderChart(() => (
2083
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2084
+ <Bar background isAnimationActive={false} dataKey="value" />
2085
+ </BarChart>
2086
+ ));
2087
+
2088
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2089
+ expect(backgroundRects).toHaveLength(composedDataWithBackground.length);
2090
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2091
+ assertZIndexLayerOrder({ front: bars[0]!, back: backgroundRects[0]! });
2092
+ });
2093
+
2094
+ it("should use default barBackground zIndex when background prop is an object without zIndex", () => {
2095
+ const { container } = renderChart(() => (
2096
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2097
+ <Bar background={{ fill: "#eee" }} isAnimationActive={false} dataKey="value" />
2098
+ </BarChart>
2099
+ ));
2100
+
2101
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2102
+ expect(backgroundRects).toHaveLength(composedDataWithBackground.length);
2103
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2104
+ assertZIndexLayerOrder({ front: bars[0]!, back: backgroundRects[0]! });
2105
+ });
2106
+
2107
+ it("should use custom zIndex when background prop is an object with zIndex", () => {
2108
+ const customZIndex = DefaultZIndexes.bar + 1;
2109
+ const { container } = renderChart(() => (
2110
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2111
+ <Bar
2112
+ background={{ fill: "#eee", zIndex: customZIndex }}
2113
+ isAnimationActive={false}
2114
+ dataKey="value"
2115
+ />
2116
+ </BarChart>
2117
+ ));
2118
+ flush();
2119
+
2120
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2121
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2122
+ assertZIndexLayerOrder({ back: bars[0]!, front: backgroundRects[0]! });
2123
+ });
2124
+
2125
+ it("should handle background prop with zIndex as 0", () => {
2126
+ const { container } = renderChart(() => (
2127
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2128
+ <Bar background={{ fill: "#eee", zIndex: 0 }} isAnimationActive={false} dataKey="value" />
2129
+ </BarChart>
2130
+ ));
2131
+
2132
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2133
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2134
+ assertZIndexLayerOrder({ front: bars[0]!, back: backgroundRects[0]! });
2135
+ });
2136
+
2137
+ it("should handle negative zIndex values in background prop", () => {
2138
+ const { container } = renderChart(() => (
2139
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2140
+ <Bar
2141
+ background={{ fill: "#eee", zIndex: -200 }}
2142
+ isAnimationActive={false}
2143
+ dataKey="value"
2144
+ />
2145
+ </BarChart>
2146
+ ));
2147
+ flush();
2148
+
2149
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2150
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2151
+ assertZIndexLayerOrder({ front: bars[0]!, back: backgroundRects[0]! });
2152
+ });
2153
+
2154
+ it("should ignore non-number zIndex values in background prop", () => {
2155
+ const { container } = renderChart(() => (
2156
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2157
+ <Bar
2158
+ background={
2159
+ { fill: "#eee", zIndex: "1100" } as unknown as BarProps["background"] & {
2160
+ zIndex: string;
2161
+ }
2162
+ }
2163
+ isAnimationActive={false}
2164
+ dataKey="value"
2165
+ />
2166
+ </BarChart>
2167
+ ));
2168
+
2169
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2170
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2171
+ assertZIndexLayerOrder({ front: bars[0]!, back: backgroundRects[0]! });
2172
+ });
2173
+
2174
+ it("should handle background prop when it is a function", () => {
2175
+ const backgroundComponent = () => <rect class="custom-background" />;
2176
+ const { container } = renderChart(() => (
2177
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2178
+ <Bar background={backgroundComponent} isAnimationActive={false} dataKey="value" />
2179
+ </BarChart>
2180
+ ));
2181
+
2182
+ const customBackgrounds = container.querySelectorAll(".custom-background");
2183
+ expect(customBackgrounds).toHaveLength(composedDataWithBackground.length);
2184
+ const bars = container.querySelectorAll(".recharts-bar-rectangle");
2185
+ assertZIndexLayerOrder({ front: bars[0]!, back: customBackgrounds[0]! });
2186
+ });
2187
+ });
2188
+
2189
+ describe("activeBar with missing data", () => {
2190
+ beforeEach(() => {
2191
+ mockGetBoundingClientRect({ width: 500, height: 300 });
2192
+ });
2193
+
2194
+ it("should highlight the correct bar when data has null values", () => {
2195
+ const dataWithMissingValues = [
2196
+ { name: "Page A", uv: 2400, pv: 4000 },
2197
+ { name: "Page B", uv: null, pv: null },
2198
+ { name: "Page C", uv: 9800, pv: 2000 },
2199
+ { name: "Page D", uv: null, pv: null },
2200
+ { name: "Page E", uv: 4800, pv: 1890 },
2201
+ ];
2202
+
2203
+ const renderTestCase = createSelectorTestCase((props) => (
2204
+ <BarChart data={dataWithMissingValues} width={500} height={300}>
2205
+ <XAxis dataKey="name" />
2206
+ <YAxis />
2207
+ <Bar activeBar dataKey="uv" isAnimationActive={false} />
2208
+ <Tooltip isAnimationActive={false} />
2209
+ {props.children}
2210
+ </BarChart>
2211
+ ));
2212
+
2213
+ const { container, spy } = renderTestCase(selectActiveTooltipIndex);
2214
+
2215
+ expectActiveBars(container, []);
2216
+ expectLastCalledWith(spy, null);
2217
+
2218
+ const allBars = getAllBars(container);
2219
+ expect(allBars).toHaveLength(3);
2220
+
2221
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
2222
+ clientX: 450,
2223
+ clientY: 150,
2224
+ });
2225
+
2226
+ expectLastCalledWith(spy, "4");
2227
+
2228
+ vi.runOnlyPendingTimers();
2229
+ flush();
2230
+
2231
+ const activeBars = container.querySelectorAll(".recharts-active-bar");
2232
+ expect(activeBars).toHaveLength(1);
2233
+
2234
+ expectTooltipPayload(container, "Page E", ["uv : 4800"]);
2235
+ });
2236
+
2237
+ it("should highlight the correct bar when hovering over middle bar with surrounding nulls", () => {
2238
+ const dataWithMissingValues = [
2239
+ { name: "Page A", uv: 2400 },
2240
+ { name: "Page B", uv: null },
2241
+ { name: "Page C", uv: 9800 },
2242
+ { name: "Page D", uv: null },
2243
+ { name: "Page E", uv: 4800 },
2244
+ ];
2245
+
2246
+ const renderTestCase = createSelectorTestCase((props) => (
2247
+ <BarChart data={dataWithMissingValues} width={500} height={300}>
2248
+ <XAxis dataKey="name" />
2249
+ <YAxis />
2250
+ <Bar activeBar dataKey="uv" isAnimationActive={false} />
2251
+ <Tooltip isAnimationActive={false} />
2252
+ {props.children}
2253
+ </BarChart>
2254
+ ));
2255
+
2256
+ const { container, spy } = renderTestCase(selectActiveTooltipIndex);
2257
+
2258
+ showTooltipOnCoordinate(container, barChartMouseHoverTooltipSelector, {
2259
+ clientX: 250,
2260
+ clientY: 150,
2261
+ });
2262
+
2263
+ expectLastCalledWith(spy, "2");
2264
+
2265
+ vi.runOnlyPendingTimers();
2266
+ flush();
2267
+
2268
+ const activeBars = container.querySelectorAll(".recharts-active-bar");
2269
+ expect(activeBars).toHaveLength(1);
2270
+
2271
+ expectTooltipPayload(container, "Page C", ["uv : 9800"]);
2272
+ });
2273
+ });
2274
+
2275
+ describe("Bar background disabled", () => {
2276
+ const composedDataWithBackground = [
2277
+ {
2278
+ x: 10,
2279
+ y: 50,
2280
+ width: 20,
2281
+ height: 20,
2282
+ value: 40,
2283
+ label: "test",
2284
+ background: { x: 10, y: 50, width: 20, height: 50 },
2285
+ },
2286
+ {
2287
+ x: 50,
2288
+ y: 50,
2289
+ width: 20,
2290
+ height: 50,
2291
+ value: 100,
2292
+ label: "test",
2293
+ background: { x: 50, y: 50, width: 20, height: 50 },
2294
+ },
2295
+ ];
2296
+
2297
+ it.each([null, false, undefined] as const)(
2298
+ "should not render any background elements when background=%s",
2299
+ (background) => {
2300
+ const { container } = renderChart(() => (
2301
+ <BarChart width={500} height={300} data={composedDataWithBackground}>
2302
+ <Bar
2303
+ background={background as BarProps["background"]}
2304
+ isAnimationActive={false}
2305
+ dataKey="value"
2306
+ />
2307
+ </BarChart>
2308
+ ));
2309
+
2310
+ const backgroundRects = container.querySelectorAll(".recharts-bar-background-rectangle");
2311
+ expect(backgroundRects).toHaveLength(0);
2312
+ },
2313
+ );
2314
+ });