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,2103 @@
1
+ // Port of recharts 3.8.1 test/cartesian/CartesianGrid.spec.tsx (commit 7a23854).
2
+ // Tier A (byte-identical DOM assertions): the grid-line count + coordinate cases.
3
+ // Harness adaptation only: React render -> Solid `render(() => <.../>)` + flush();
4
+ // dropped `import React`; @testing-library/react -> the repo's local testing-library.
5
+ //
6
+ // The "Biaxial storybook" case reads the yAxis scale from the store via an inline
7
+ // probe component rendered as a chart child (the Solid-idiomatic equivalent of
8
+ // recharts' <Customized> spy — there is no <Customized> in this port; a plain
9
+ // chart child already has the store context).
10
+ //
11
+ // Now ported (previously deferred):
12
+ // - "renders 2 grid lines in an empty chart": self-generated edge coordinates.
13
+ // - "...to the background" cases: the `rect.recharts-cartesian-grid-bg` rect.
14
+ // - "uses offset.width and offset.height when width and height are NaN".
15
+ import { describe, expect, it, type Mock, test, vi } from "vitest";
16
+ import { createEffect, flush } from "solid-js";
17
+ import type { JSX } from "@solidjs/web";
18
+ import { render } from "../helper/render";
19
+ import {
20
+ CartesianGrid,
21
+ LineChart,
22
+ ComposedChart,
23
+ BarChart,
24
+ ScatterChart,
25
+ AreaChart,
26
+ Area,
27
+ YAxis,
28
+ XAxis,
29
+ Brush,
30
+ Legend,
31
+ Line,
32
+ Tooltip,
33
+ } from "../../src";
34
+ import type { ChartOffsetInternal, Margin } from "../../src/util/types";
35
+ import type {
36
+ AxisPropsForCartesianGridTicksGeneration,
37
+ GridLineTypeFunctionProps,
38
+ HorizontalCoordinatesGenerator,
39
+ VerticalCoordinatesGenerator,
40
+ } from "../../src/cartesian/CartesianGrid";
41
+ import { assertNotNull } from "../helper/assertNotNull";
42
+ import { pageData } from "../_data";
43
+ import { selectAxisScale } from "../../src/state/selectors/axisSelectors";
44
+ import { useAppSelector } from "../../src/state/hooks";
45
+ import { expectLastCalledWith } from "../helper/expectLastCalledWith";
46
+ import { DefaultZIndexes } from "../../src/zIndex/DefaultZIndexes";
47
+
48
+ const allChartsThatSupportCartesianGrid = [
49
+ { ChartElement: AreaChart, testName: "AreaElement" },
50
+ { ChartElement: ComposedChart, testName: "ComposedChart" },
51
+ { ChartElement: BarChart, testName: "BarChart" },
52
+ { ChartElement: LineChart, testName: "LineChart" },
53
+ { ChartElement: ScatterChart, testName: "ScatterChart" },
54
+ ] as const;
55
+
56
+ type ExpectedHorizontalLine = {
57
+ y: string | null;
58
+ };
59
+
60
+ function expectHorizontalGridLines(
61
+ container: Element,
62
+ expectedLines: ReadonlyArray<ExpectedHorizontalLine>,
63
+ ) {
64
+ const horizontalLines = container.querySelectorAll(".recharts-cartesian-grid-horizontal line");
65
+ assertNotNull(horizontalLines);
66
+ const horizontalLinesContexts = Array.from(horizontalLines).map((line) => ({
67
+ y: line.getAttribute("y1"),
68
+ }));
69
+ expect(horizontalLinesContexts).toEqual(expectedLines);
70
+ horizontalLines.forEach((line) => {
71
+ expect(line.getAttribute("y1")).toEqual(line.getAttribute("y2"));
72
+ expect.soft(line).toHaveAttribute("x1", expect.any(String));
73
+ expect.soft(line).toHaveAttribute("x2", expect.any(String));
74
+ });
75
+ }
76
+
77
+ type ExpectedVerticalLine = {
78
+ x: string | null;
79
+ };
80
+
81
+ function expectVerticalGridLines(
82
+ container: Element,
83
+ expectedLines: ReadonlyArray<ExpectedVerticalLine>,
84
+ ) {
85
+ const verticalLines = container.querySelectorAll(".recharts-cartesian-grid-vertical line");
86
+ assertNotNull(verticalLines);
87
+ const verticalLinesContexts = Array.from(verticalLines).map((line) => ({
88
+ x: line.getAttribute("x1"),
89
+ }));
90
+ expect(verticalLinesContexts).toEqual(expectedLines);
91
+ verticalLines.forEach((line) => {
92
+ expect(line.getAttribute("x1")).toEqual(line.getAttribute("x2"));
93
+ expect.soft(line).toHaveAttribute("y1", expect.any(String));
94
+ expect.soft(line).toHaveAttribute("y2", expect.any(String));
95
+ });
96
+ }
97
+
98
+ describe("CartesianGrid", () => {
99
+ test("renders 2 grid lines in an empty chart", () => {
100
+ const { container } = render(() => (
101
+ <AreaChart width={500} height={500}>
102
+ <CartesianGrid />
103
+ </AreaChart>
104
+ ));
105
+ flush();
106
+ expectHorizontalGridLines(container, [
107
+ {
108
+ y: "5",
109
+ },
110
+ {
111
+ y: "495",
112
+ },
113
+ ]);
114
+ expectVerticalGridLines(container, [
115
+ {
116
+ x: "5",
117
+ },
118
+ {
119
+ x: "495",
120
+ },
121
+ ]);
122
+ });
123
+
124
+ it("renders more grid lines when the chart has data", () => {
125
+ const { container } = render(() => (
126
+ <AreaChart width={500} height={500} data={pageData}>
127
+ <Area dataKey="pv" />
128
+ <CartesianGrid />
129
+ </AreaChart>
130
+ ));
131
+ flush();
132
+ expectHorizontalGridLines(container, [
133
+ {
134
+ y: "495",
135
+ },
136
+ {
137
+ y: "372.5",
138
+ },
139
+ {
140
+ y: "250",
141
+ },
142
+ {
143
+ y: "127.5",
144
+ },
145
+ {
146
+ y: "5",
147
+ },
148
+ ]);
149
+ expectVerticalGridLines(container, [
150
+ {
151
+ x: "5",
152
+ },
153
+ {
154
+ x: "86.66666666666667",
155
+ },
156
+ {
157
+ x: "168.33333333333334",
158
+ },
159
+ {
160
+ x: "250",
161
+ },
162
+ {
163
+ x: "331.6666666666667",
164
+ },
165
+ {
166
+ x: "413.33333333333337",
167
+ },
168
+ {
169
+ x: "495",
170
+ },
171
+ ]);
172
+ });
173
+
174
+ it("renders as many grid lines as the axis has ticks", () => {
175
+ const { container } = render(() => (
176
+ <AreaChart width={500} height={500} data={pageData}>
177
+ <Area dataKey="pv" />
178
+ <YAxis tickCount={6} />
179
+ <XAxis dataKey="uv" type="number" tickCount={3} />
180
+ <CartesianGrid />
181
+ </AreaChart>
182
+ ));
183
+ flush();
184
+ expectHorizontalGridLines(container, [
185
+ {
186
+ y: "465",
187
+ },
188
+ {
189
+ y: "373",
190
+ },
191
+ {
192
+ y: "281",
193
+ },
194
+ {
195
+ y: "189",
196
+ },
197
+ {
198
+ y: "96.99999999999999",
199
+ },
200
+ {
201
+ y: "5",
202
+ },
203
+ ]);
204
+ expectVerticalGridLines(container, [
205
+ {
206
+ x: "65",
207
+ },
208
+ {
209
+ x: "280",
210
+ },
211
+ {
212
+ x: "495",
213
+ },
214
+ ]);
215
+ });
216
+
217
+ it("should render fewer ticks when clipped by a Brush", () => {
218
+ const { container } = render(() => (
219
+ <AreaChart width={500} height={500} data={pageData}>
220
+ <Area dataKey="pv" />
221
+ <CartesianGrid />
222
+ <Brush startIndex={0} endIndex={2} />
223
+ </AreaChart>
224
+ ));
225
+ flush();
226
+ expectHorizontalGridLines(container, [
227
+ {
228
+ y: "455",
229
+ },
230
+ {
231
+ y: "342.5",
232
+ },
233
+ {
234
+ y: "230",
235
+ },
236
+ {
237
+ y: "117.5",
238
+ },
239
+ {
240
+ y: "5",
241
+ },
242
+ ]);
243
+ expectVerticalGridLines(container, [
244
+ {
245
+ x: "5",
246
+ },
247
+ {
248
+ x: "250",
249
+ },
250
+ {
251
+ x: "495",
252
+ },
253
+ ]);
254
+ });
255
+
256
+ it("should render all ticks from LineChart Biaxial storybook", () => {
257
+ const scaleSpy = vi.fn();
258
+ // Inline probe — the Solid-idiomatic equivalent of recharts' <Customized> spy.
259
+ const Comp = (): null => {
260
+ const scale = useAppSelector((state) => selectAxisScale(state, "yAxis", "left", false));
261
+ createEffect(
262
+ () => scale()?.domain(),
263
+ (domain) => scaleSpy(domain),
264
+ );
265
+ return null;
266
+ };
267
+ const { container } = render(() => (
268
+ <LineChart
269
+ width={500}
270
+ height={300}
271
+ data={pageData}
272
+ margin={{
273
+ top: 5,
274
+ right: 30,
275
+ left: 20,
276
+ bottom: 5,
277
+ }}
278
+ >
279
+ <CartesianGrid yAxisId="left" strokeDasharray="3 3" />
280
+ <XAxis dataKey="name" />
281
+ <YAxis yAxisId="left" />
282
+ <YAxis yAxisId="right" orientation="right" />
283
+ <Legend />
284
+ <Line yAxisId="left" type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
285
+ <Line yAxisId="right" type="monotone" dataKey="uv" stroke="#82ca9d" />
286
+ <Tooltip />
287
+ <Comp />
288
+ </LineChart>
289
+ ));
290
+ flush();
291
+
292
+ expect(scaleSpy).toHaveBeenLastCalledWith([0, 1200]);
293
+ expectHorizontalGridLines(container, [
294
+ {
295
+ y: "265",
296
+ },
297
+ {
298
+ y: "200",
299
+ },
300
+ {
301
+ y: "135",
302
+ },
303
+ {
304
+ y: "70",
305
+ },
306
+ {
307
+ y: "5",
308
+ },
309
+ ]);
310
+ expectVerticalGridLines(container, [
311
+ {
312
+ x: "80",
313
+ },
314
+ {
315
+ x: "135",
316
+ },
317
+ {
318
+ x: "190",
319
+ },
320
+ {
321
+ x: "245",
322
+ },
323
+ {
324
+ x: "300",
325
+ },
326
+ {
327
+ x: "355",
328
+ },
329
+ {
330
+ x: "410",
331
+ },
332
+ ]);
333
+ });
334
+ });
335
+
336
+ describe.each(allChartsThatSupportCartesianGrid)(
337
+ "<CartesianGrid /> when child of $testName",
338
+ ({ ChartElement }) => {
339
+ describe("when horizontalPoints and verticalPoints are set explicitly", () => {
340
+ const horizontalPoints = [10, 20, 30, 100, 400];
341
+ /**
342
+ * JavaScript produces numbers like this when multiplying floats, for example:
343
+ * 1.1 * 1.1 * 100
344
+ * 1.1 * 2.1 * 100
345
+ */
346
+ const floatingPointPrecisionExamples = [121.0000000000002, 231.0000000000005];
347
+ const verticalPoints = [100, 200, 300, 400];
348
+
349
+ const chartMargin: Margin = {
350
+ bottom: 11,
351
+ left: 12,
352
+ right: 13,
353
+ top: 14,
354
+ };
355
+
356
+ const expectedOffset: ChartOffsetInternal = {
357
+ bottom: 11,
358
+ brushBottom: 11,
359
+ height: 175,
360
+ left: 12,
361
+ right: 13,
362
+ top: 14,
363
+ width: 275,
364
+ };
365
+
366
+ const exampleCartesianGridDimensions = {
367
+ x: 1,
368
+ y: 2,
369
+ width: 300,
370
+ height: 200,
371
+ };
372
+
373
+ describe("layout and size when set explicitly in $testName", () => {
374
+ it("should put x, y, width and height as coordinates to the background", () => {
375
+ const { container } = render(() => (
376
+ <ChartElement width={500} height={500}>
377
+ <CartesianGrid
378
+ {...exampleCartesianGridDimensions}
379
+ fill="green"
380
+ ry={10}
381
+ verticalPoints={verticalPoints}
382
+ horizontalPoints={horizontalPoints}
383
+ />
384
+ </ChartElement>
385
+ ));
386
+ flush();
387
+ const background = container.querySelector("rect.recharts-cartesian-grid-bg");
388
+ expect.soft(background).toHaveAttribute("x", "1");
389
+ expect.soft(background).toHaveAttribute("y", "2");
390
+ expect.soft(background).toHaveAttribute("width", "300");
391
+ expect.soft(background).toHaveAttribute("height", "200");
392
+ expect.soft(background).toHaveAttribute("ry", "10");
393
+ });
394
+
395
+ it("should put x, y, width and height as coordinates to all lines", () => {
396
+ const { container } = render(() => (
397
+ <ChartElement width={500} height={500}>
398
+ <CartesianGrid
399
+ {...exampleCartesianGridDimensions}
400
+ verticalPoints={verticalPoints}
401
+ horizontalPoints={horizontalPoints}
402
+ />
403
+ </ChartElement>
404
+ ));
405
+ flush();
406
+ const horizontalLines = container.querySelectorAll(
407
+ ".recharts-cartesian-grid-horizontal line",
408
+ );
409
+ expect(horizontalLines).toHaveLength(horizontalPoints.length);
410
+ horizontalLines.forEach((line) => {
411
+ expect.soft(line).toHaveAttribute("x", "1");
412
+ expect.soft(line).toHaveAttribute("y", "2");
413
+ expect.soft(line).toHaveAttribute("x1", "1");
414
+ expect.soft(line).toHaveAttribute("x2", "301");
415
+ expect.soft(line).toHaveAttribute("y1", expect.any(String));
416
+ expect.soft(line).toHaveAttribute("y2", expect.any(String));
417
+ expect(line.getAttribute("y1")).toEqual(line.getAttribute("y2"));
418
+ });
419
+ expectHorizontalGridLines(container, [
420
+ {
421
+ y: "10",
422
+ },
423
+ {
424
+ y: "20",
425
+ },
426
+ {
427
+ y: "30",
428
+ },
429
+ {
430
+ y: "100",
431
+ },
432
+ {
433
+ y: "400",
434
+ },
435
+ ]);
436
+ const verticalLines = container.querySelectorAll(
437
+ ".recharts-cartesian-grid-vertical line",
438
+ );
439
+ expect(verticalLines).toHaveLength(verticalPoints.length);
440
+ verticalLines.forEach((line) => {
441
+ expect.soft(line).toHaveAttribute("x", "1");
442
+ expect.soft(line).toHaveAttribute("y", "2");
443
+ expect.soft(line).toHaveAttribute("x1", expect.any(String));
444
+ expect.soft(line).toHaveAttribute("x2", expect.any(String));
445
+ expect(line.getAttribute("x1")).toEqual(line.getAttribute("x2"));
446
+ expect.soft(line).toHaveAttribute("y1", "2");
447
+ expect.soft(line).toHaveAttribute("y2", "202");
448
+ });
449
+ expectVerticalGridLines(container, [
450
+ {
451
+ x: "100",
452
+ },
453
+ {
454
+ x: "200",
455
+ },
456
+ {
457
+ x: "300",
458
+ },
459
+ {
460
+ x: "400",
461
+ },
462
+ ]);
463
+ });
464
+ });
465
+
466
+ describe("layout and size when inherited from parent chart", () => {
467
+ it("should put x, y, width and height as coordinates to the background", () => {
468
+ const { container } = render(() => (
469
+ <ChartElement margin={chartMargin} width={500} height={400}>
470
+ <CartesianGrid
471
+ fill="green"
472
+ verticalPoints={verticalPoints}
473
+ horizontalPoints={horizontalPoints}
474
+ />
475
+ </ChartElement>
476
+ ));
477
+ flush();
478
+ const background = container.querySelector("rect.recharts-cartesian-grid-bg");
479
+ expect.soft(background).toHaveAttribute("x", "12");
480
+ expect.soft(background).toHaveAttribute("y", "14");
481
+ expect.soft(background).toHaveAttribute("width", "475");
482
+ expect.soft(background).toHaveAttribute("height", "375");
483
+ });
484
+
485
+ it("should put x, y, width and height as coordinates to all lines", () => {
486
+ const { container } = render(() => (
487
+ <ChartElement margin={chartMargin} width={500} height={400}>
488
+ <CartesianGrid verticalPoints={verticalPoints} horizontalPoints={horizontalPoints} />
489
+ </ChartElement>
490
+ ));
491
+ flush();
492
+ const horizontalLines = container.querySelectorAll(
493
+ ".recharts-cartesian-grid-horizontal line",
494
+ );
495
+ expect(horizontalLines).toHaveLength(5);
496
+ horizontalLines.forEach((line) => {
497
+ expect.soft(line).toHaveAttribute("x", "12");
498
+ expect.soft(line).toHaveAttribute("y", "14");
499
+ expect.soft(line).toHaveAttribute("x1", "12");
500
+ expect.soft(line).toHaveAttribute("x2", "487");
501
+ });
502
+ const verticalLines = container.querySelectorAll(
503
+ ".recharts-cartesian-grid-vertical line",
504
+ );
505
+ expect(verticalLines).toHaveLength(4);
506
+ verticalLines.forEach((line) => {
507
+ expect.soft(line).toHaveAttribute("x", "12");
508
+ expect.soft(line).toHaveAttribute("y", "14");
509
+ expect.soft(line).toHaveAttribute("y1", "14");
510
+ expect.soft(line).toHaveAttribute("y2", "389");
511
+ });
512
+ });
513
+ });
514
+
515
+ describe("grid", () => {
516
+ describe("basic features", () => {
517
+ it("should render on its own, outside of Recharts", () => {
518
+ const { container } = render(() => (
519
+ <ChartElement width={500} height={500}>
520
+ <CartesianGrid
521
+ {...exampleCartesianGridDimensions}
522
+ verticalPoints={verticalPoints}
523
+ horizontalPoints={horizontalPoints}
524
+ />
525
+ </ChartElement>
526
+ ));
527
+ flush();
528
+ const allLines = container.querySelectorAll("line");
529
+ expect.soft(allLines).toHaveLength(9);
530
+ for (let i = 0; i < allLines.length; i++) {
531
+ const line = allLines[i];
532
+ expect.soft(line).toHaveAttribute("stroke", "#ccc");
533
+ expect.soft(line).toHaveAttribute("fill", "none");
534
+ }
535
+ expect
536
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
537
+ .toHaveLength(horizontalPoints.length);
538
+ expect
539
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
540
+ .toHaveLength(verticalPoints.length);
541
+ });
542
+
543
+ test("Render 5 horizontal lines and 4 vertical lines in simple CartesianGrid", () => {
544
+ const { container } = render(() => (
545
+ <ChartElement width={500} height={500}>
546
+ <CartesianGrid
547
+ {...exampleCartesianGridDimensions}
548
+ verticalPoints={verticalPoints}
549
+ horizontalPoints={horizontalPoints}
550
+ />
551
+ </ChartElement>
552
+ ));
553
+ flush();
554
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
555
+ expect
556
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
557
+ .toHaveLength(horizontalPoints.length);
558
+ expect
559
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
560
+ .toHaveLength(verticalPoints.length);
561
+ });
562
+
563
+ test.each([0, -1, -Infinity])("Don't render any lines when width is %s", (w) => {
564
+ const { container } = render(() => (
565
+ <ChartElement width={500} height={500}>
566
+ <CartesianGrid
567
+ width={w}
568
+ height={500}
569
+ verticalPoints={verticalPoints}
570
+ horizontalPoints={horizontalPoints}
571
+ />
572
+ </ChartElement>
573
+ ));
574
+ flush();
575
+ expect(container.querySelectorAll("line")).toHaveLength(0);
576
+ });
577
+
578
+ test("uses offset.width and offset.height when width and height are NaN", () => {
579
+ const { container } = render(() => (
580
+ <ChartElement margin={chartMargin} width={500} height={400}>
581
+ <CartesianGrid
582
+ width={NaN}
583
+ height={NaN}
584
+ verticalPoints={verticalPoints}
585
+ horizontalPoints={horizontalPoints}
586
+ />
587
+ </ChartElement>
588
+ ));
589
+ flush();
590
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
591
+ expect
592
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
593
+ .toHaveLength(horizontalPoints.length);
594
+ expect
595
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
596
+ .toHaveLength(verticalPoints.length);
597
+ });
598
+
599
+ test.each([0, -1, -Infinity])("Don't render any lines when height is %s", (h) => {
600
+ const { container } = render(() => (
601
+ <ChartElement width={500} height={500}>
602
+ <CartesianGrid
603
+ width={500}
604
+ height={h}
605
+ verticalPoints={verticalPoints}
606
+ horizontalPoints={horizontalPoints}
607
+ />
608
+ </ChartElement>
609
+ ));
610
+ flush();
611
+ expect(container.querySelectorAll("line")).toHaveLength(0);
612
+ });
613
+ });
614
+
615
+ describe("horizontalPoints without generator", () => {
616
+ it("should not render any lines if horizontal=false", () => {
617
+ const { container } = render(() => (
618
+ <ChartElement width={500} height={500}>
619
+ <CartesianGrid
620
+ {...exampleCartesianGridDimensions}
621
+ horizontal={false}
622
+ verticalPoints={verticalPoints}
623
+ horizontalPoints={horizontalPoints}
624
+ />
625
+ </ChartElement>
626
+ ));
627
+ flush();
628
+ expect.soft(container.querySelectorAll("line")).toHaveLength(verticalPoints.length);
629
+ expect
630
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
631
+ .toHaveLength(0);
632
+ expect
633
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
634
+ .toHaveLength(verticalPoints.length);
635
+ });
636
+
637
+ it("should render all lines if horizontal=true", () => {
638
+ const { container } = render(() => (
639
+ <ChartElement width={500} height={500}>
640
+ <CartesianGrid
641
+ {...exampleCartesianGridDimensions}
642
+ horizontal
643
+ verticalPoints={verticalPoints}
644
+ horizontalPoints={horizontalPoints}
645
+ />
646
+ </ChartElement>
647
+ ));
648
+ flush();
649
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
650
+ expect
651
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
652
+ .toHaveLength(horizontalPoints.length);
653
+ expect
654
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
655
+ .toHaveLength(verticalPoints.length);
656
+ });
657
+
658
+ it("should render all lines if horizontal is undefined", () => {
659
+ const { container } = render(() => (
660
+ <ChartElement width={500} height={500}>
661
+ <CartesianGrid
662
+ {...exampleCartesianGridDimensions}
663
+ verticalPoints={verticalPoints}
664
+ horizontalPoints={horizontalPoints}
665
+ />
666
+ </ChartElement>
667
+ ));
668
+ flush();
669
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
670
+ expect
671
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
672
+ .toHaveLength(horizontalPoints.length);
673
+ expect
674
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
675
+ .toHaveLength(verticalPoints.length);
676
+ });
677
+ });
678
+
679
+ describe("verticalPoints without generator", () => {
680
+ it("should not render any lines if vertical=false", () => {
681
+ const { container } = render(() => (
682
+ <ChartElement width={500} height={500}>
683
+ <CartesianGrid
684
+ {...exampleCartesianGridDimensions}
685
+ vertical={false}
686
+ verticalPoints={verticalPoints}
687
+ horizontalPoints={horizontalPoints}
688
+ />
689
+ </ChartElement>
690
+ ));
691
+ flush();
692
+ expect.soft(container.querySelectorAll("line")).toHaveLength(horizontalPoints.length);
693
+ expect
694
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
695
+ .toHaveLength(horizontalPoints.length);
696
+ expect
697
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
698
+ .toHaveLength(0);
699
+ });
700
+
701
+ it("should render all lines if vertical=true", () => {
702
+ const { container } = render(() => (
703
+ <ChartElement width={500} height={500}>
704
+ <CartesianGrid
705
+ {...exampleCartesianGridDimensions}
706
+ vertical
707
+ verticalPoints={verticalPoints}
708
+ horizontalPoints={horizontalPoints}
709
+ />
710
+ </ChartElement>
711
+ ));
712
+ flush();
713
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
714
+ expect
715
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
716
+ .toHaveLength(horizontalPoints.length);
717
+ expect
718
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
719
+ .toHaveLength(verticalPoints.length);
720
+ });
721
+
722
+ it("should render all lines if vertical is undefined", () => {
723
+ const { container } = render(() => (
724
+ <ChartElement width={500} height={500}>
725
+ <CartesianGrid
726
+ {...exampleCartesianGridDimensions}
727
+ verticalPoints={verticalPoints}
728
+ horizontalPoints={horizontalPoints}
729
+ />
730
+ </ChartElement>
731
+ ));
732
+ flush();
733
+ expect.soft(container.querySelectorAll("line")).toHaveLength(9);
734
+ expect
735
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-horizontal line"))
736
+ .toHaveLength(horizontalPoints.length);
737
+ expect
738
+ .soft(container.querySelectorAll(".recharts-cartesian-grid-vertical line"))
739
+ .toHaveLength(verticalPoints.length);
740
+ });
741
+ });
742
+
743
+ describe("horizontalCoordinatesGenerator", () => {
744
+ it("should render lines that the generator returns", () => {
745
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
746
+ .fn()
747
+ .mockReturnValue([3, 4]);
748
+ const { container } = render(() => (
749
+ <ChartElement width={500} height={500}>
750
+ <CartesianGrid
751
+ {...exampleCartesianGridDimensions}
752
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
753
+ />
754
+ </ChartElement>
755
+ ));
756
+ flush();
757
+
758
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
759
+
760
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-horizontal line");
761
+ expect(allLines).toHaveLength(2);
762
+ expect.soft(allLines[0]).toHaveAttribute("x", "1");
763
+ expect.soft(allLines[0]).toHaveAttribute("x1", "1");
764
+ expect.soft(allLines[0]).toHaveAttribute("x2", "301");
765
+ expect.soft(allLines[0]).toHaveAttribute("y", "2");
766
+ expect.soft(allLines[0]).toHaveAttribute("y1", "3");
767
+ expect.soft(allLines[0]).toHaveAttribute("y2", "3");
768
+ expect.soft(allLines[1]).toHaveAttribute("x", "1");
769
+ expect.soft(allLines[1]).toHaveAttribute("x1", "1");
770
+ expect.soft(allLines[1]).toHaveAttribute("x2", "301");
771
+ expect.soft(allLines[1]).toHaveAttribute("y", "2");
772
+ expect.soft(allLines[1]).toHaveAttribute("y1", "4");
773
+ expect.soft(allLines[1]).toHaveAttribute("y2", "4");
774
+ });
775
+
776
+ it("if both horizontalCoordinatesGenerator and horizontalPoints are present then horizontalPoints win", () => {
777
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
778
+ .fn()
779
+ .mockReturnValue([1, 2]);
780
+ expect(horizontalPoints.length).not.toBe(2);
781
+ const { container } = render(() => (
782
+ <ChartElement width={500} height={500}>
783
+ <CartesianGrid
784
+ {...exampleCartesianGridDimensions}
785
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
786
+ horizontalPoints={horizontalPoints}
787
+ />
788
+ </ChartElement>
789
+ ));
790
+ flush();
791
+
792
+ expect(horizontalCoordinatesGenerator).not.toHaveBeenCalled();
793
+
794
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-horizontal line");
795
+ expect(allLines).toHaveLength(horizontalPoints.length);
796
+ });
797
+
798
+ it("should pass props to the generator", () => {
799
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
800
+ .fn()
801
+ .mockReturnValue([]);
802
+ render(() => (
803
+ <ChartElement width={300} height={200} margin={chartMargin}>
804
+ <CartesianGrid
805
+ {...exampleCartesianGridDimensions}
806
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
807
+ />
808
+ </ChartElement>
809
+ ));
810
+ flush();
811
+
812
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
813
+ const expectedYAxis: AxisPropsForCartesianGridTicksGeneration = {
814
+ angle: 0,
815
+ interval: "preserveEnd",
816
+ minTickGap: 5,
817
+ orientation: "left",
818
+ tick: true,
819
+ tickFormatter: undefined,
820
+ unit: undefined,
821
+ axisType: "yAxis",
822
+ categoricalDomain: undefined,
823
+ duplicateDomain: undefined,
824
+ isCategorical: false,
825
+ niceTicks: undefined,
826
+ range: [189, 14],
827
+ realScaleType: "linear",
828
+ scale: undefined,
829
+ tickCount: 5,
830
+ ticks: undefined,
831
+ type: "number",
832
+ };
833
+ expectLastCalledWith(
834
+ horizontalCoordinatesGenerator,
835
+ {
836
+ yAxis: expectedYAxis,
837
+ width: 300,
838
+ height: 200,
839
+ offset: expectedOffset,
840
+ },
841
+ false,
842
+ );
843
+ });
844
+
845
+ it(`should set syncWithTicks=true, and ticks=horizontalValues, when horizontalValues is provided, even if the explicit syncWithTicks is false`, () => {
846
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
847
+ .fn()
848
+ .mockReturnValue([]);
849
+ render(() => (
850
+ <ChartElement width={300} height={200} margin={chartMargin}>
851
+ <CartesianGrid
852
+ {...exampleCartesianGridDimensions}
853
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
854
+ syncWithTicks={false}
855
+ horizontalValues={["a", "b"]}
856
+ />
857
+ </ChartElement>
858
+ ));
859
+ flush();
860
+
861
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
862
+ const expectedYAxis: AxisPropsForCartesianGridTicksGeneration = {
863
+ angle: 0,
864
+ interval: "preserveEnd",
865
+ minTickGap: 5,
866
+ orientation: "left",
867
+ tick: true,
868
+ tickFormatter: undefined,
869
+ unit: undefined,
870
+ axisType: "yAxis",
871
+ categoricalDomain: undefined,
872
+ duplicateDomain: undefined,
873
+ isCategorical: false,
874
+ niceTicks: undefined,
875
+ range: [189, 14],
876
+ realScaleType: "linear",
877
+ scale: undefined,
878
+ tickCount: 5,
879
+ ticks: ["a", "b"],
880
+ type: "number",
881
+ };
882
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledWith(
883
+ {
884
+ yAxis: expectedYAxis,
885
+ width: 300,
886
+ height: 200,
887
+ offset: expectedOffset,
888
+ },
889
+ true,
890
+ );
891
+ });
892
+
893
+ test.each([true, false, undefined])(
894
+ "should set syncWithTicks as %s when horizontalValues is provided but is empty",
895
+ (syncWithTicks) => {
896
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
897
+ .fn()
898
+ .mockReturnValue([]);
899
+ render(() => (
900
+ <ChartElement width={300} height={200} margin={chartMargin}>
901
+ <CartesianGrid
902
+ {...exampleCartesianGridDimensions}
903
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
904
+ syncWithTicks={syncWithTicks}
905
+ horizontalValues={[]}
906
+ />
907
+ </ChartElement>
908
+ ));
909
+ flush();
910
+
911
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
912
+ const expectedYAxis: AxisPropsForCartesianGridTicksGeneration = {
913
+ angle: 0,
914
+ interval: "preserveEnd",
915
+ minTickGap: 5,
916
+ orientation: "left",
917
+ tick: true,
918
+ tickFormatter: undefined,
919
+ unit: undefined,
920
+ axisType: "yAxis",
921
+ categoricalDomain: undefined,
922
+ duplicateDomain: undefined,
923
+ isCategorical: false,
924
+ niceTicks: undefined,
925
+ range: [189, 14],
926
+ realScaleType: "linear",
927
+ scale: undefined,
928
+ tickCount: 5,
929
+ ticks: undefined,
930
+ type: "number",
931
+ };
932
+ expectLastCalledWith(
933
+ horizontalCoordinatesGenerator,
934
+ {
935
+ yAxis: expectedYAxis,
936
+ width: 300,
937
+ height: 200,
938
+ offset: expectedOffset,
939
+ },
940
+ Boolean(syncWithTicks),
941
+ );
942
+ },
943
+ );
944
+
945
+ test.each([true, false, undefined])(
946
+ "should pass props to the generator when syncWithTicks is %s",
947
+ (syncWithTicks) => {
948
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
949
+ .fn()
950
+ .mockReturnValue([]);
951
+ render(() => (
952
+ <ChartElement width={300} height={200} margin={chartMargin}>
953
+ <CartesianGrid
954
+ {...exampleCartesianGridDimensions}
955
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
956
+ syncWithTicks={syncWithTicks}
957
+ />
958
+ </ChartElement>
959
+ ));
960
+ flush();
961
+
962
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
963
+ const expectedYAxis: AxisPropsForCartesianGridTicksGeneration = {
964
+ angle: 0,
965
+ interval: "preserveEnd",
966
+ minTickGap: 5,
967
+ orientation: "left",
968
+ tick: true,
969
+ tickFormatter: undefined,
970
+ unit: undefined,
971
+ axisType: "yAxis",
972
+ categoricalDomain: undefined,
973
+ duplicateDomain: undefined,
974
+ isCategorical: false,
975
+ niceTicks: undefined,
976
+ range: [189, 14],
977
+ realScaleType: "linear",
978
+ scale: undefined,
979
+ tickCount: 5,
980
+ ticks: undefined,
981
+ type: "number",
982
+ };
983
+ expectLastCalledWith(
984
+ horizontalCoordinatesGenerator,
985
+ {
986
+ yAxis: expectedYAxis,
987
+ width: 300,
988
+ height: 200,
989
+ offset: expectedOffset,
990
+ },
991
+ Boolean(syncWithTicks),
992
+ );
993
+ },
994
+ );
995
+
996
+ test.each([
997
+ { gen: [] },
998
+ { gen: null },
999
+ { gen: undefined },
1000
+ { gen: "some random string" },
1001
+ { gen: NaN },
1002
+ ])("should render nothing if the generator returns $gen", ({ gen }) => {
1003
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
1004
+ .fn()
1005
+ .mockReturnValue(gen);
1006
+ const { container } = render(() => (
1007
+ <ChartElement width={500} height={500}>
1008
+ <CartesianGrid
1009
+ {...exampleCartesianGridDimensions}
1010
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
1011
+ />
1012
+ </ChartElement>
1013
+ ));
1014
+ flush();
1015
+
1016
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1017
+
1018
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-horizontal line");
1019
+ expect(allLines).toHaveLength(0);
1020
+ });
1021
+
1022
+ it("should generate its own ticks if neither horizontalPoints nor horizontalCoordinatesGenerator are provided", () => {
1023
+ const { container } = render(() => (
1024
+ <ChartElement width={500} height={500}>
1025
+ <CartesianGrid x={0} y={0} width={500} height={500} />
1026
+ </ChartElement>
1027
+ ));
1028
+ flush();
1029
+
1030
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-horizontal line");
1031
+ expect(allLines).toHaveLength(2);
1032
+ expect.soft(allLines[0]).toHaveAttribute("x", "0");
1033
+ expect.soft(allLines[0]).toHaveAttribute("x1", "0");
1034
+ expect.soft(allLines[0]).toHaveAttribute("x2", "500");
1035
+ expect.soft(allLines[0]).toHaveAttribute("y", "0");
1036
+ expect.soft(allLines[0]).toHaveAttribute("y1", "5");
1037
+ expect.soft(allLines[0]).toHaveAttribute("y2", "5");
1038
+ expect.soft(allLines[1]).toHaveAttribute("x", "0");
1039
+ expect.soft(allLines[1]).toHaveAttribute("x1", "0");
1040
+ expect.soft(allLines[1]).toHaveAttribute("x2", "500");
1041
+ expect.soft(allLines[1]).toHaveAttribute("y", "0");
1042
+ expect.soft(allLines[1]).toHaveAttribute("y1", "495");
1043
+ expect.soft(allLines[1]).toHaveAttribute("y2", "495");
1044
+ });
1045
+ });
1046
+
1047
+ describe("verticalCoordinatesGenerator", () => {
1048
+ it("should render lines that the generator returns", () => {
1049
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1050
+ .fn()
1051
+ .mockReturnValue([3, 4]);
1052
+ const { container } = render(() => (
1053
+ <ChartElement width={500} height={500}>
1054
+ <CartesianGrid
1055
+ {...exampleCartesianGridDimensions}
1056
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1057
+ />
1058
+ </ChartElement>
1059
+ ));
1060
+ flush();
1061
+
1062
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1063
+
1064
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-vertical line");
1065
+ expect(allLines).toHaveLength(2);
1066
+ expect.soft(allLines[0]).toHaveAttribute("x", "1");
1067
+ expect.soft(allLines[0]).toHaveAttribute("x1", "3");
1068
+ expect.soft(allLines[0]).toHaveAttribute("x2", "3");
1069
+ expect.soft(allLines[0]).toHaveAttribute("y", "2");
1070
+ expect.soft(allLines[0]).toHaveAttribute("y1", "2");
1071
+ expect.soft(allLines[0]).toHaveAttribute("y2", "202");
1072
+ expect.soft(allLines[1]).toHaveAttribute("x", "1");
1073
+ expect.soft(allLines[1]).toHaveAttribute("x1", "4");
1074
+ expect.soft(allLines[1]).toHaveAttribute("x2", "4");
1075
+ expect.soft(allLines[1]).toHaveAttribute("y", "2");
1076
+ expect.soft(allLines[1]).toHaveAttribute("y1", "2");
1077
+ expect.soft(allLines[1]).toHaveAttribute("y2", "202");
1078
+ });
1079
+
1080
+ it("if both verticalCoordinatesGenerator and verticalPoints are present then verticalPoints wins", () => {
1081
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1082
+ .fn()
1083
+ .mockReturnValue([1, 2]);
1084
+ expect(verticalPoints.length).not.toBe(2);
1085
+ const { container } = render(() => (
1086
+ <ChartElement width={500} height={500}>
1087
+ <CartesianGrid
1088
+ {...exampleCartesianGridDimensions}
1089
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1090
+ verticalPoints={verticalPoints}
1091
+ />
1092
+ </ChartElement>
1093
+ ));
1094
+ flush();
1095
+
1096
+ expect(verticalCoordinatesGenerator).not.toHaveBeenCalled();
1097
+
1098
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-vertical line");
1099
+ expect(allLines).toHaveLength(verticalPoints.length);
1100
+ });
1101
+
1102
+ it("should pass props to the generator", () => {
1103
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1104
+ .fn()
1105
+ .mockReturnValue([]);
1106
+ render(() => (
1107
+ <ChartElement width={300} height={200} margin={chartMargin}>
1108
+ <CartesianGrid
1109
+ {...exampleCartesianGridDimensions}
1110
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1111
+ />
1112
+ </ChartElement>
1113
+ ));
1114
+ flush();
1115
+
1116
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1117
+ const expectedXAxis: AxisPropsForCartesianGridTicksGeneration = {
1118
+ angle: 0,
1119
+ axisType: "xAxis",
1120
+ categoricalDomain: undefined,
1121
+ duplicateDomain: undefined,
1122
+ interval: "preserveEnd",
1123
+ isCategorical: true,
1124
+ minTickGap: 5,
1125
+ niceTicks: undefined,
1126
+ orientation: "bottom",
1127
+ range: [12, 287],
1128
+ realScaleType: expect.any(String),
1129
+ scale: undefined,
1130
+ tick: true,
1131
+ tickCount: 5,
1132
+ tickFormatter: undefined,
1133
+ ticks: undefined,
1134
+ type: "category",
1135
+ unit: undefined,
1136
+ };
1137
+ expectLastCalledWith(
1138
+ verticalCoordinatesGenerator,
1139
+ {
1140
+ xAxis: expectedXAxis,
1141
+ width: 300,
1142
+ height: 200,
1143
+ offset: expectedOffset,
1144
+ },
1145
+ false,
1146
+ );
1147
+ });
1148
+
1149
+ it(`should set syncWithTicks=true, and ticks=verticalValues, when verticalValues is provided, even if the explicit syncWithTicks is false`, () => {
1150
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1151
+ .fn()
1152
+ .mockReturnValue([]);
1153
+ render(() => (
1154
+ <ChartElement width={300} height={200} margin={chartMargin}>
1155
+ <CartesianGrid
1156
+ {...exampleCartesianGridDimensions}
1157
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1158
+ syncWithTicks={false}
1159
+ verticalValues={["a", "b"]}
1160
+ />
1161
+ </ChartElement>
1162
+ ));
1163
+ flush();
1164
+
1165
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1166
+ const expectedXAxis: AxisPropsForCartesianGridTicksGeneration = {
1167
+ angle: 0,
1168
+ axisType: "xAxis",
1169
+ categoricalDomain: undefined,
1170
+ duplicateDomain: undefined,
1171
+ interval: "preserveEnd",
1172
+ isCategorical: true,
1173
+ minTickGap: 5,
1174
+ niceTicks: undefined,
1175
+ orientation: "bottom",
1176
+ range: [12, 287],
1177
+ realScaleType: expect.any(String),
1178
+ scale: undefined,
1179
+ tick: true,
1180
+ tickCount: 5,
1181
+ tickFormatter: undefined,
1182
+ ticks: ["a", "b"],
1183
+ type: "category",
1184
+ unit: undefined,
1185
+ };
1186
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledWith(
1187
+ {
1188
+ xAxis: expectedXAxis,
1189
+ width: 300,
1190
+ height: 200,
1191
+ offset: expectedOffset,
1192
+ },
1193
+ true,
1194
+ );
1195
+ });
1196
+
1197
+ test.each([true, false, undefined])(
1198
+ "should set syncWithTicks as %s when horizontalValues is provided but is empty",
1199
+ (syncWithTicks) => {
1200
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1201
+ .fn()
1202
+ .mockReturnValue([]);
1203
+ render(() => (
1204
+ <ChartElement width={300} height={200} margin={chartMargin}>
1205
+ <CartesianGrid
1206
+ {...exampleCartesianGridDimensions}
1207
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1208
+ syncWithTicks={syncWithTicks}
1209
+ horizontalValues={[]}
1210
+ />
1211
+ </ChartElement>
1212
+ ));
1213
+ flush();
1214
+
1215
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1216
+ const expectedXAxis: AxisPropsForCartesianGridTicksGeneration = {
1217
+ angle: 0,
1218
+ axisType: "xAxis",
1219
+ categoricalDomain: undefined,
1220
+ duplicateDomain: undefined,
1221
+ interval: "preserveEnd",
1222
+ isCategorical: true,
1223
+ minTickGap: 5,
1224
+ niceTicks: undefined,
1225
+ orientation: "bottom",
1226
+ range: [12, 287],
1227
+ realScaleType: expect.any(String),
1228
+ scale: undefined,
1229
+ tick: true,
1230
+ tickCount: 5,
1231
+ tickFormatter: undefined,
1232
+ ticks: undefined,
1233
+ type: "category",
1234
+ unit: undefined,
1235
+ };
1236
+ expectLastCalledWith(
1237
+ verticalCoordinatesGenerator,
1238
+ {
1239
+ xAxis: expectedXAxis,
1240
+ width: 300,
1241
+ height: 200,
1242
+ offset: expectedOffset,
1243
+ },
1244
+ Boolean(syncWithTicks),
1245
+ );
1246
+ },
1247
+ );
1248
+
1249
+ test.each([true, false, undefined])(
1250
+ "should pass props to the generator when syncWithTicks is %s",
1251
+ (syncWithTicks) => {
1252
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1253
+ .fn()
1254
+ .mockReturnValue([]);
1255
+ render(() => (
1256
+ <ChartElement width={300} height={200} margin={chartMargin}>
1257
+ <CartesianGrid
1258
+ {...exampleCartesianGridDimensions}
1259
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1260
+ syncWithTicks={syncWithTicks}
1261
+ />
1262
+ </ChartElement>
1263
+ ));
1264
+ flush();
1265
+
1266
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1267
+ const expectedXAxis: AxisPropsForCartesianGridTicksGeneration = {
1268
+ angle: 0,
1269
+ axisType: "xAxis",
1270
+ categoricalDomain: undefined,
1271
+ duplicateDomain: undefined,
1272
+ interval: "preserveEnd",
1273
+ isCategorical: true,
1274
+ minTickGap: 5,
1275
+ niceTicks: undefined,
1276
+ orientation: "bottom",
1277
+ range: [12, 287],
1278
+ realScaleType: expect.any(String),
1279
+ scale: undefined,
1280
+ tick: true,
1281
+ tickCount: 5,
1282
+ tickFormatter: undefined,
1283
+ ticks: undefined,
1284
+ type: "category",
1285
+ unit: undefined,
1286
+ };
1287
+ expectLastCalledWith(
1288
+ verticalCoordinatesGenerator,
1289
+ {
1290
+ xAxis: expectedXAxis,
1291
+ width: 300,
1292
+ height: 200,
1293
+ offset: expectedOffset,
1294
+ },
1295
+ Boolean(syncWithTicks),
1296
+ );
1297
+ },
1298
+ );
1299
+
1300
+ test.each([
1301
+ { gen: [] },
1302
+ { gen: null },
1303
+ { gen: undefined },
1304
+ { gen: "some random string" },
1305
+ { gen: NaN },
1306
+ ])("should render nothing if the generator returns $gen", ({ gen }) => {
1307
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1308
+ .fn()
1309
+ .mockReturnValue(gen);
1310
+ const { container } = render(() => (
1311
+ <ChartElement width={500} height={500}>
1312
+ <CartesianGrid
1313
+ {...exampleCartesianGridDimensions}
1314
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1315
+ />
1316
+ </ChartElement>
1317
+ ));
1318
+ flush();
1319
+
1320
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1321
+
1322
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-vertical line");
1323
+ expect(allLines).toHaveLength(0);
1324
+ });
1325
+
1326
+ it("should generate its own ticks if neither verticalPoints nor verticalCoordinatesGenerator are provided", () => {
1327
+ const { container } = render(() => (
1328
+ <LineChart width={500} height={500}>
1329
+ <CartesianGrid {...exampleCartesianGridDimensions} />
1330
+ </LineChart>
1331
+ ));
1332
+ flush();
1333
+
1334
+ const allLines = container.querySelectorAll(".recharts-cartesian-grid-vertical line");
1335
+ expect(allLines).toHaveLength(2);
1336
+ expect.soft(allLines[0]).toHaveAttribute("x", "1");
1337
+ expect.soft(allLines[0]).toHaveAttribute("x1", "5");
1338
+ expect.soft(allLines[0]).toHaveAttribute("x2", "5");
1339
+ expect.soft(allLines[0]).toHaveAttribute("y", "2");
1340
+ expect.soft(allLines[0]).toHaveAttribute("y1", "2");
1341
+ expect.soft(allLines[0]).toHaveAttribute("y2", "202");
1342
+ expect.soft(allLines[1]).toHaveAttribute("x", "1");
1343
+ expect.soft(allLines[1]).toHaveAttribute("x1", "495");
1344
+ expect.soft(allLines[1]).toHaveAttribute("x2", "495");
1345
+ expect.soft(allLines[1]).toHaveAttribute("y", "2");
1346
+ expect.soft(allLines[1]).toHaveAttribute("y1", "2");
1347
+ expect.soft(allLines[1]).toHaveAttribute("y2", "202");
1348
+ });
1349
+ });
1350
+
1351
+ describe("horizontal as a function", () => {
1352
+ it("should pass props, add default stroke, and then render result of the function", () => {
1353
+ // Solid JSX in value position is a LIVE DOM node, so mockReturnValue would
1354
+ // return the same node every call (DOM inserts it once). mockImplementation
1355
+ // builds a fresh node per call — the Solid equivalent of React's element-as-data.
1356
+ const horizontal = vi.fn(
1357
+ (_p: GridLineTypeFunctionProps) =>
1358
+ (<g data-testid="my_mock_line" />) as unknown as JSX.Element,
1359
+ );
1360
+ const { container } = render(() => (
1361
+ <ChartElement width={500} height={500}>
1362
+ <CartesianGrid
1363
+ {...exampleCartesianGridDimensions}
1364
+ verticalPoints={verticalPoints}
1365
+ horizontalPoints={horizontalPoints}
1366
+ horizontal={horizontal}
1367
+ />
1368
+ </ChartElement>
1369
+ ));
1370
+ flush();
1371
+ expect(horizontal).toHaveBeenCalledTimes(horizontalPoints.length);
1372
+
1373
+ const expectedProps: GridLineTypeFunctionProps = {
1374
+ stroke: "#ccc",
1375
+ syncWithTicks: false,
1376
+ fill: "none",
1377
+ height: 200,
1378
+ width: 300,
1379
+ vertical: true,
1380
+ horizontalFill: [],
1381
+ horizontalPoints,
1382
+ verticalFill: [],
1383
+ verticalPoints,
1384
+ horizontal,
1385
+ key: expect.stringMatching(/line-[0-9]/),
1386
+ x: 1,
1387
+ y: 2,
1388
+ x1: 1,
1389
+ x2: 301,
1390
+ y1: expect.any(Number),
1391
+ y2: expect.any(Number),
1392
+ index: expect.any(Number),
1393
+ zIndex: DefaultZIndexes.grid,
1394
+ offset: {
1395
+ bottom: 5,
1396
+ brushBottom: 5,
1397
+ height: 490,
1398
+ left: 5,
1399
+ right: 5,
1400
+ top: 5,
1401
+ width: 490,
1402
+ },
1403
+ xAxis: {
1404
+ angle: 0,
1405
+ axisType: "xAxis",
1406
+ categoricalDomain: undefined,
1407
+ duplicateDomain: undefined,
1408
+ interval: "preserveEnd",
1409
+ isCategorical: true,
1410
+ minTickGap: 5,
1411
+ niceTicks: undefined,
1412
+ orientation: "bottom",
1413
+ range: [5, 495],
1414
+ realScaleType: expect.any(String),
1415
+ scale: undefined,
1416
+ tick: true,
1417
+ tickCount: 5,
1418
+ tickFormatter: undefined,
1419
+ ticks: undefined,
1420
+ type: "category",
1421
+ unit: undefined,
1422
+ },
1423
+ yAxis: {
1424
+ angle: 0,
1425
+ axisType: "yAxis",
1426
+ categoricalDomain: undefined,
1427
+ duplicateDomain: undefined,
1428
+ interval: "preserveEnd",
1429
+ isCategorical: false,
1430
+ minTickGap: 5,
1431
+ niceTicks: undefined,
1432
+ orientation: "left",
1433
+ range: [495, 5],
1434
+ realScaleType: "linear",
1435
+ scale: undefined,
1436
+ tick: true,
1437
+ tickCount: 5,
1438
+ tickFormatter: undefined,
1439
+ ticks: undefined,
1440
+ type: "number",
1441
+ unit: undefined,
1442
+ },
1443
+ };
1444
+ expect(horizontal).toHaveBeenCalledWith(expectedProps);
1445
+
1446
+ expect(container.querySelectorAll("[data-testid=my_mock_line]")).toHaveLength(
1447
+ horizontalPoints.length,
1448
+ );
1449
+ });
1450
+ });
1451
+
1452
+ describe("vertical as a function", () => {
1453
+ it("should pass props, add default stroke, and then render result of the function", () => {
1454
+ // See note above: fresh node per call (Solid JSX is a live DOM node).
1455
+ const vertical = vi.fn(
1456
+ (_p: GridLineTypeFunctionProps) =>
1457
+ (<g data-testid="my_mock_line" />) as unknown as JSX.Element,
1458
+ );
1459
+ const { container } = render(() => (
1460
+ <ChartElement width={500} height={500}>
1461
+ <CartesianGrid
1462
+ {...exampleCartesianGridDimensions}
1463
+ verticalPoints={verticalPoints}
1464
+ horizontalPoints={horizontalPoints}
1465
+ vertical={vertical}
1466
+ />
1467
+ </ChartElement>
1468
+ ));
1469
+ flush();
1470
+ expect(vertical).toHaveBeenCalledTimes(verticalPoints.length);
1471
+
1472
+ const expectedProps: GridLineTypeFunctionProps = {
1473
+ stroke: "#ccc",
1474
+ syncWithTicks: false,
1475
+ fill: "none",
1476
+ height: 200,
1477
+ width: 300,
1478
+ horizontal: true,
1479
+ horizontalFill: [],
1480
+ horizontalPoints,
1481
+ verticalFill: [],
1482
+ verticalPoints,
1483
+ vertical,
1484
+ key: expect.stringMatching(/line-[0-9]/),
1485
+ x: 1,
1486
+ y: 2,
1487
+ x1: expect.any(Number),
1488
+ x2: expect.any(Number),
1489
+ y1: 2,
1490
+ y2: 202,
1491
+ index: expect.any(Number),
1492
+ zIndex: DefaultZIndexes.grid,
1493
+ offset: {
1494
+ bottom: 5,
1495
+ brushBottom: 5,
1496
+ height: 490,
1497
+ left: 5,
1498
+ right: 5,
1499
+ top: 5,
1500
+ width: 490,
1501
+ },
1502
+ xAxis: {
1503
+ angle: 0,
1504
+ axisType: "xAxis",
1505
+ categoricalDomain: undefined,
1506
+ duplicateDomain: undefined,
1507
+ interval: "preserveEnd",
1508
+ isCategorical: true,
1509
+ minTickGap: 5,
1510
+ niceTicks: undefined,
1511
+ orientation: "bottom",
1512
+ range: [5, 495],
1513
+ realScaleType: expect.any(String),
1514
+ scale: undefined,
1515
+ tick: true,
1516
+ tickCount: 5,
1517
+ tickFormatter: undefined,
1518
+ ticks: undefined,
1519
+ type: "category",
1520
+ unit: undefined,
1521
+ },
1522
+ yAxis: {
1523
+ angle: 0,
1524
+ axisType: "yAxis",
1525
+ categoricalDomain: undefined,
1526
+ duplicateDomain: undefined,
1527
+ interval: "preserveEnd",
1528
+ isCategorical: false,
1529
+ minTickGap: 5,
1530
+ niceTicks: undefined,
1531
+ orientation: "left",
1532
+ range: [495, 5],
1533
+ realScaleType: "linear",
1534
+ scale: undefined,
1535
+ tick: true,
1536
+ tickCount: 5,
1537
+ tickFormatter: undefined,
1538
+ ticks: undefined,
1539
+ type: "number",
1540
+ unit: undefined,
1541
+ },
1542
+ };
1543
+ expect(vertical).toHaveBeenCalledWith(expectedProps);
1544
+
1545
+ expect(container.querySelectorAll("[data-testid=my_mock_line]")).toHaveLength(
1546
+ verticalPoints.length,
1547
+ );
1548
+ });
1549
+ });
1550
+ });
1551
+
1552
+ describe("stripes", () => {
1553
+ const emptyFillCases: { fill: string[] | undefined }[] = [
1554
+ { fill: [] },
1555
+ { fill: undefined },
1556
+ ];
1557
+
1558
+ describe("horizontal stripes", () => {
1559
+ test.each([true, undefined])(
1560
+ "should render horizontal stripes if horizontal prop = %s",
1561
+ (horizontal) => {
1562
+ const extraSpaceAtTheTopOfChart = 7;
1563
+ const { container } = render(() => (
1564
+ <svg>
1565
+ <CartesianGrid
1566
+ {...exampleCartesianGridDimensions}
1567
+ height={Math.max(...horizontalPoints) + extraSpaceAtTheTopOfChart}
1568
+ verticalPoints={verticalPoints}
1569
+ horizontalPoints={horizontalPoints}
1570
+ horizontalFill={["red", "green"]}
1571
+ fillOpacity="20%"
1572
+ horizontal={horizontal}
1573
+ />
1574
+ </svg>
1575
+ ));
1576
+ flush();
1577
+ const allStripes = container.querySelectorAll(
1578
+ ".recharts-cartesian-gridstripes-horizontal rect",
1579
+ );
1580
+ expect(allStripes).toHaveLength(horizontalPoints.length + 1);
1581
+
1582
+ for (let i = 0; i < allStripes.length; i++) {
1583
+ const element = allStripes[i];
1584
+ expect.soft(element).toHaveAttribute("x", "1");
1585
+ expect.soft(element).toHaveAttribute("stroke", "none");
1586
+ expect.soft(element).toHaveAttribute("fill-opacity", "20%");
1587
+ expect.soft(element).toHaveClass("recharts-cartesian-grid-bg");
1588
+ }
1589
+
1590
+ expect(allStripes[0]).toHaveAttribute("fill", "red");
1591
+ expect(allStripes[0]).toHaveAttribute("y", "0");
1592
+ expect(allStripes[0]).toHaveAttribute("height", "10");
1593
+
1594
+ expect(allStripes[1]).toHaveAttribute("fill", "green");
1595
+ expect(allStripes[1]).toHaveAttribute("y", "10");
1596
+ expect(allStripes[1]).toHaveAttribute("height", "10");
1597
+
1598
+ expect(allStripes[2]).toHaveAttribute("fill", "red");
1599
+ expect(allStripes[2]).toHaveAttribute("y", "20");
1600
+ expect(allStripes[2]).toHaveAttribute("height", "10");
1601
+
1602
+ expect(allStripes[3]).toHaveAttribute("fill", "green");
1603
+ expect(allStripes[3]).toHaveAttribute("y", "30");
1604
+ expect(allStripes[3]).toHaveAttribute("height", "70");
1605
+
1606
+ expect(allStripes[4]).toHaveAttribute("fill", "red");
1607
+ expect(allStripes[4]).toHaveAttribute("y", "100");
1608
+ expect(allStripes[4]).toHaveAttribute("height", "300");
1609
+
1610
+ expect(allStripes[5]).toHaveAttribute("fill", "green");
1611
+ expect(allStripes[5]).toHaveAttribute("y", "400");
1612
+ expect(allStripes[5]).toHaveAttribute(
1613
+ "height",
1614
+ String(extraSpaceAtTheTopOfChart + exampleCartesianGridDimensions.y),
1615
+ );
1616
+ },
1617
+ );
1618
+
1619
+ it("should render stripes defined by horizontalCoordinatesGenerator", () => {
1620
+ const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi
1621
+ .fn()
1622
+ .mockReturnValue([1, 2]);
1623
+ const { container } = render(() => (
1624
+ <ChartElement width={500} height={500}>
1625
+ <CartesianGrid
1626
+ {...exampleCartesianGridDimensions}
1627
+ horizontalCoordinatesGenerator={horizontalCoordinatesGenerator}
1628
+ horizontalFill={["red", "green"]}
1629
+ />
1630
+ </ChartElement>
1631
+ ));
1632
+ flush();
1633
+
1634
+ expect(horizontalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1635
+
1636
+ const allLines = container.querySelectorAll(
1637
+ ".recharts-cartesian-gridstripes-horizontal rect",
1638
+ );
1639
+ expect(allLines).toHaveLength(3);
1640
+ });
1641
+
1642
+ it("should not render anything if horizontal=false", () => {
1643
+ const extraSpaceAtTheTopOfChart = 1;
1644
+ const { container } = render(() => (
1645
+ <svg>
1646
+ <CartesianGrid
1647
+ {...exampleCartesianGridDimensions}
1648
+ height={Math.max(...horizontalPoints) + extraSpaceAtTheTopOfChart}
1649
+ verticalPoints={verticalPoints}
1650
+ horizontalPoints={horizontalPoints}
1651
+ horizontalFill={["red", "green"]}
1652
+ fillOpacity="20%"
1653
+ horizontal={false}
1654
+ />
1655
+ </svg>
1656
+ ));
1657
+ flush();
1658
+ const allStripes = container.querySelectorAll(
1659
+ ".recharts-cartesian-gridstripes-horizontal rect",
1660
+ );
1661
+ expect(allStripes).toHaveLength(0);
1662
+ });
1663
+
1664
+ test.each(emptyFillCases)(
1665
+ "should render nothing if horizontalFill is $fill",
1666
+ ({ fill }) => {
1667
+ const { container } = render(() => (
1668
+ <svg>
1669
+ <CartesianGrid
1670
+ {...exampleCartesianGridDimensions}
1671
+ height={Math.max(...horizontalPoints) + 1}
1672
+ verticalPoints={verticalPoints}
1673
+ horizontalPoints={horizontalPoints}
1674
+ horizontalFill={fill}
1675
+ />
1676
+ </svg>
1677
+ ));
1678
+ flush();
1679
+ const allStripes = container.querySelectorAll(
1680
+ ".recharts-cartesian-gridstripes-horizontal rect",
1681
+ );
1682
+ expect(allStripes).toHaveLength(0);
1683
+ },
1684
+ );
1685
+
1686
+ it("should leave out the stripe at the beginning if the smallest horizontalPoints happens to be exactly at position y", () => {
1687
+ const { container } = render(() => (
1688
+ <svg>
1689
+ <CartesianGrid
1690
+ {...exampleCartesianGridDimensions}
1691
+ y={Math.min(...horizontalPoints)}
1692
+ height={Math.max(...horizontalPoints) + 1}
1693
+ verticalPoints={verticalPoints}
1694
+ horizontalPoints={horizontalPoints}
1695
+ horizontalFill={["red", "green"]}
1696
+ />
1697
+ </svg>
1698
+ ));
1699
+ flush();
1700
+ const allStripes = container.querySelectorAll(
1701
+ ".recharts-cartesian-gridstripes-horizontal rect",
1702
+ );
1703
+ expect(allStripes).toHaveLength(horizontalPoints.length);
1704
+ });
1705
+
1706
+ it("render the stripe at the beginning if the smallest horizontalPoints is smaller than position y", () => {
1707
+ const { container } = render(() => (
1708
+ <svg>
1709
+ <CartesianGrid
1710
+ {...exampleCartesianGridDimensions}
1711
+ y={Math.min(...horizontalPoints) - 1}
1712
+ height={Math.max(...horizontalPoints) + 1}
1713
+ verticalPoints={verticalPoints}
1714
+ horizontalPoints={horizontalPoints}
1715
+ horizontalFill={["red", "green"]}
1716
+ />
1717
+ </svg>
1718
+ ));
1719
+ flush();
1720
+ const allStripes = container.querySelectorAll(
1721
+ ".recharts-cartesian-gridstripes-horizontal rect",
1722
+ );
1723
+ expect(allStripes).toHaveLength(horizontalPoints.length + 1);
1724
+ });
1725
+
1726
+ it("removes the one stripe at the end if it would render outside of the Grid", () => {
1727
+ const { container } = render(() => (
1728
+ <svg>
1729
+ <CartesianGrid
1730
+ {...exampleCartesianGridDimensions}
1731
+ y={0}
1732
+ height={Math.max(...horizontalPoints) - 1}
1733
+ verticalPoints={verticalPoints}
1734
+ horizontalPoints={horizontalPoints}
1735
+ horizontalFill={["red", "green"]}
1736
+ />
1737
+ </svg>
1738
+ ));
1739
+ flush();
1740
+ const allStripes = container.querySelectorAll(
1741
+ ".recharts-cartesian-gridstripes-horizontal rect",
1742
+ );
1743
+ expect(allStripes).toHaveLength(horizontalPoints.length);
1744
+ });
1745
+
1746
+ it("removes still only one stripe even if all of them render outside of the grid", () => {
1747
+ const { container } = render(() => (
1748
+ <svg>
1749
+ <CartesianGrid
1750
+ {...exampleCartesianGridDimensions}
1751
+ height={1}
1752
+ verticalPoints={verticalPoints}
1753
+ horizontalPoints={horizontalPoints}
1754
+ horizontalFill={["red", "green"]}
1755
+ />
1756
+ </svg>
1757
+ ));
1758
+ flush();
1759
+ const allStripes = container.querySelectorAll(
1760
+ ".recharts-cartesian-gridstripes-horizontal rect",
1761
+ );
1762
+ expect(allStripes).toHaveLength(horizontalPoints.length);
1763
+ });
1764
+
1765
+ it("should round horizontalPoints [https://github.com/recharts/recharts/pull/3075]", () => {
1766
+ const { container } = render(() => (
1767
+ <svg>
1768
+ <CartesianGrid
1769
+ x={0}
1770
+ y={0}
1771
+ width={500}
1772
+ height={500}
1773
+ verticalPoints={verticalPoints}
1774
+ horizontalPoints={floatingPointPrecisionExamples}
1775
+ horizontalFill={["red", "green"]}
1776
+ />
1777
+ </svg>
1778
+ ));
1779
+ flush();
1780
+ const allStripes = container.querySelectorAll(
1781
+ ".recharts-cartesian-gridstripes-horizontal rect",
1782
+ );
1783
+ expect(allStripes).toHaveLength(floatingPointPrecisionExamples.length + 1);
1784
+
1785
+ expect.soft(allStripes[0]).toHaveAttribute("height", "121");
1786
+ expect.soft(allStripes[1]).toHaveAttribute("height", "110");
1787
+ expect.soft(allStripes[2]).toHaveAttribute("height", "269");
1788
+ });
1789
+
1790
+ it("should ignore stripes that have computed height 0", () => {
1791
+ const { container } = render(() => (
1792
+ <svg>
1793
+ <CartesianGrid
1794
+ {...exampleCartesianGridDimensions}
1795
+ verticalPoints={verticalPoints}
1796
+ horizontalPoints={[10, 20, 10, 500]}
1797
+ horizontalFill={["red", "green"]}
1798
+ />
1799
+ </svg>
1800
+ ));
1801
+ flush();
1802
+ const allStripes = container.querySelectorAll(
1803
+ ".recharts-cartesian-gridstripes-horizontal rect",
1804
+ );
1805
+ expect(allStripes).toHaveLength(3);
1806
+
1807
+ expect.soft(allStripes[0]).toHaveAttribute("height", "10");
1808
+ expect.soft(allStripes[0]).toHaveAttribute("y", "0");
1809
+
1810
+ expect.soft(allStripes[1]).toHaveAttribute("height", "10");
1811
+ expect.soft(allStripes[1]).toHaveAttribute("y", "10");
1812
+
1813
+ expect.soft(allStripes[2]).toHaveAttribute("height", "480");
1814
+ expect.soft(allStripes[2]).toHaveAttribute("y", "20");
1815
+ });
1816
+ });
1817
+
1818
+ describe("vertical stripes", () => {
1819
+ test.each([true, undefined])(
1820
+ "should render vertical stripes if vertical prop = %s",
1821
+ (vertical) => {
1822
+ const extraSpaceAtTheEndOfChart = 7;
1823
+ const { container } = render(() => (
1824
+ <svg>
1825
+ <CartesianGrid
1826
+ {...exampleCartesianGridDimensions}
1827
+ width={Math.max(...verticalPoints) + extraSpaceAtTheEndOfChart}
1828
+ verticalPoints={verticalPoints}
1829
+ verticalFill={["red", "green"]}
1830
+ fillOpacity="20%"
1831
+ vertical={vertical}
1832
+ />
1833
+ </svg>
1834
+ ));
1835
+ flush();
1836
+ const allStripes = container.querySelectorAll(
1837
+ ".recharts-cartesian-gridstripes-vertical rect",
1838
+ );
1839
+ expect(allStripes).toHaveLength(verticalPoints.length + 1);
1840
+
1841
+ for (let i = 0; i < allStripes.length; i++) {
1842
+ const element = allStripes[i];
1843
+ expect.soft(element).toHaveAttribute("y", "2");
1844
+ expect.soft(element).toHaveAttribute("height", "200");
1845
+ expect.soft(element).toHaveAttribute("stroke", "none");
1846
+ expect.soft(element).toHaveAttribute("fill-opacity", "20%");
1847
+ expect.soft(element).toHaveClass("recharts-cartesian-grid-bg");
1848
+ }
1849
+
1850
+ expect.soft(allStripes[0]).toHaveAttribute("fill", "red");
1851
+ expect.soft(allStripes[0]).toHaveAttribute("x", "0");
1852
+ expect.soft(allStripes[0]).toHaveAttribute("width", "100");
1853
+
1854
+ expect.soft(allStripes[1]).toHaveAttribute("fill", "green");
1855
+ expect.soft(allStripes[1]).toHaveAttribute("x", "100");
1856
+ expect.soft(allStripes[1]).toHaveAttribute("width", "100");
1857
+
1858
+ expect.soft(allStripes[2]).toHaveAttribute("fill", "red");
1859
+ expect.soft(allStripes[2]).toHaveAttribute("x", "200");
1860
+ expect.soft(allStripes[2]).toHaveAttribute("width", "100");
1861
+
1862
+ expect.soft(allStripes[3]).toHaveAttribute("fill", "green");
1863
+ expect.soft(allStripes[3]).toHaveAttribute("x", "300");
1864
+ expect.soft(allStripes[3]).toHaveAttribute("width", "100");
1865
+
1866
+ expect.soft(allStripes[4]).toHaveAttribute("fill", "red");
1867
+ expect.soft(allStripes[4]).toHaveAttribute("x", "400");
1868
+ expect
1869
+ .soft(allStripes[4])
1870
+ .toHaveAttribute(
1871
+ "width",
1872
+ String(extraSpaceAtTheEndOfChart + exampleCartesianGridDimensions.x),
1873
+ );
1874
+ },
1875
+ );
1876
+
1877
+ it("should render stripes defined by verticalCoordinatesGenerator", () => {
1878
+ const verticalCoordinatesGenerator: Mock<VerticalCoordinatesGenerator> = vi
1879
+ .fn()
1880
+ .mockReturnValue([1, 2]);
1881
+ const { container } = render(() => (
1882
+ <ChartElement width={500} height={500}>
1883
+ <CartesianGrid
1884
+ x={0}
1885
+ y={0}
1886
+ width={500}
1887
+ height={500}
1888
+ verticalCoordinatesGenerator={verticalCoordinatesGenerator}
1889
+ verticalFill={["red", "green"]}
1890
+ />
1891
+ </ChartElement>
1892
+ ));
1893
+ flush();
1894
+
1895
+ expect(verticalCoordinatesGenerator).toHaveBeenCalledTimes(1);
1896
+
1897
+ const allLines = container.querySelectorAll(
1898
+ ".recharts-cartesian-gridstripes-vertical rect",
1899
+ );
1900
+ expect(allLines).toHaveLength(3);
1901
+ });
1902
+
1903
+ it("should not render anything if vertical=false", () => {
1904
+ const extraSpaceAtTheTopOfChart = 1;
1905
+ const { container } = render(() => (
1906
+ <svg>
1907
+ <CartesianGrid
1908
+ {...exampleCartesianGridDimensions}
1909
+ width={Math.max(...verticalPoints) + extraSpaceAtTheTopOfChart}
1910
+ verticalPoints={verticalPoints}
1911
+ verticalFill={["red", "green"]}
1912
+ fillOpacity="20%"
1913
+ vertical={false}
1914
+ />
1915
+ </svg>
1916
+ ));
1917
+ flush();
1918
+ const allStripes = container.querySelectorAll(
1919
+ ".recharts-cartesian-gridstripes-vertical rect",
1920
+ );
1921
+ expect(allStripes).toHaveLength(0);
1922
+ });
1923
+
1924
+ test.each(emptyFillCases)(
1925
+ "should render nothing if verticalFill is $fill",
1926
+ ({ fill }) => {
1927
+ const { container } = render(() => (
1928
+ <svg>
1929
+ <CartesianGrid
1930
+ {...exampleCartesianGridDimensions}
1931
+ width={Math.max(...verticalPoints) + 1}
1932
+ verticalPoints={verticalPoints}
1933
+ verticalFill={fill}
1934
+ />
1935
+ </svg>
1936
+ ));
1937
+ flush();
1938
+ const allStripes = container.querySelectorAll(
1939
+ ".recharts-cartesian-gridstripes-vertical rect",
1940
+ );
1941
+ expect(allStripes).toHaveLength(0);
1942
+ },
1943
+ );
1944
+
1945
+ it("should leave out the stripe at the beginning if the smallest verticalPoints happens to be exactly at position x", () => {
1946
+ const { container } = render(() => (
1947
+ <svg>
1948
+ <CartesianGrid
1949
+ {...exampleCartesianGridDimensions}
1950
+ x={Math.min(...verticalPoints)}
1951
+ width={Math.max(...verticalPoints) + 1}
1952
+ verticalPoints={verticalPoints}
1953
+ verticalFill={["red", "green"]}
1954
+ />
1955
+ </svg>
1956
+ ));
1957
+ flush();
1958
+ const allStripes = container.querySelectorAll(
1959
+ ".recharts-cartesian-gridstripes-vertical rect",
1960
+ );
1961
+ expect(allStripes).toHaveLength(verticalPoints.length);
1962
+ });
1963
+
1964
+ it("render the stripe at the beginning if the smallest verticalPoints is smaller than position x", () => {
1965
+ const { container } = render(() => (
1966
+ <svg>
1967
+ <CartesianGrid
1968
+ {...exampleCartesianGridDimensions}
1969
+ x={Math.min(...verticalPoints) - 1}
1970
+ width={Math.max(...verticalPoints) + 1}
1971
+ verticalPoints={verticalPoints}
1972
+ verticalFill={["red", "green"]}
1973
+ />
1974
+ </svg>
1975
+ ));
1976
+ flush();
1977
+ const allStripes = container.querySelectorAll(
1978
+ ".recharts-cartesian-gridstripes-vertical rect",
1979
+ );
1980
+ expect(allStripes).toHaveLength(verticalPoints.length + 1);
1981
+ });
1982
+
1983
+ it("removes the one stripe at the end if it would render outside of the Grid", () => {
1984
+ const { container } = render(() => (
1985
+ <svg>
1986
+ <CartesianGrid
1987
+ {...exampleCartesianGridDimensions}
1988
+ width={Math.max(...verticalPoints) - 1}
1989
+ verticalPoints={verticalPoints}
1990
+ verticalFill={["red", "green"]}
1991
+ />
1992
+ </svg>
1993
+ ));
1994
+ flush();
1995
+ const allStripes = container.querySelectorAll(
1996
+ ".recharts-cartesian-gridstripes-vertical rect",
1997
+ );
1998
+ expect(allStripes).toHaveLength(verticalPoints.length);
1999
+ });
2000
+
2001
+ it("removes still only one stripe even if all of them render outside of the grid", () => {
2002
+ const { container } = render(() => (
2003
+ <svg>
2004
+ <CartesianGrid
2005
+ {...exampleCartesianGridDimensions}
2006
+ width={1}
2007
+ verticalPoints={verticalPoints}
2008
+ verticalFill={["red", "green"]}
2009
+ />
2010
+ </svg>
2011
+ ));
2012
+ flush();
2013
+ const allStripes = container.querySelectorAll(
2014
+ ".recharts-cartesian-gridstripes-vertical rect",
2015
+ );
2016
+ expect(allStripes).toHaveLength(verticalPoints.length);
2017
+ });
2018
+
2019
+ it("should round verticalPoints [https://github.com/recharts/recharts/pull/3075]", () => {
2020
+ const { container } = render(() => (
2021
+ <svg>
2022
+ <CartesianGrid
2023
+ x={0}
2024
+ y={0}
2025
+ width={500}
2026
+ height={500}
2027
+ verticalPoints={floatingPointPrecisionExamples}
2028
+ verticalFill={["red", "green"]}
2029
+ />
2030
+ </svg>
2031
+ ));
2032
+ flush();
2033
+ const allStripes = container.querySelectorAll(
2034
+ ".recharts-cartesian-gridstripes-vertical rect",
2035
+ );
2036
+ expect(allStripes).toHaveLength(floatingPointPrecisionExamples.length + 1);
2037
+ for (let i = 0; i < allStripes.length; i++) {
2038
+ const stripe = allStripes[i];
2039
+ expect(stripe).toHaveAttribute("height", "500");
2040
+ }
2041
+
2042
+ expect.soft(allStripes[0]).toHaveAttribute("width", "121");
2043
+ expect.soft(allStripes[1]).toHaveAttribute("width", "110");
2044
+ expect.soft(allStripes[2]).toHaveAttribute("width", "269");
2045
+ });
2046
+
2047
+ it("should ignore stripes that have computed width 0", () => {
2048
+ const { container } = render(() => (
2049
+ <svg>
2050
+ <CartesianGrid
2051
+ {...exampleCartesianGridDimensions}
2052
+ verticalPoints={[10, 20, 10, 500]}
2053
+ verticalFill={["red", "green"]}
2054
+ />
2055
+ </svg>
2056
+ ));
2057
+ flush();
2058
+ const allStripes = container.querySelectorAll(
2059
+ ".recharts-cartesian-gridstripes-vertical rect",
2060
+ );
2061
+ expect(allStripes).toHaveLength(3);
2062
+
2063
+ expect.soft(allStripes[0]).toHaveAttribute("width", "10");
2064
+ expect.soft(allStripes[0]).toHaveAttribute("height", "200");
2065
+ expect.soft(allStripes[0]).toHaveAttribute("x", "0");
2066
+ expect.soft(allStripes[0]).toHaveAttribute("y", "2");
2067
+
2068
+ expect.soft(allStripes[1]).toHaveAttribute("width", "10");
2069
+ expect.soft(allStripes[1]).toHaveAttribute("height", "200");
2070
+ expect.soft(allStripes[1]).toHaveAttribute("x", "10");
2071
+ expect.soft(allStripes[1]).toHaveAttribute("y", "2");
2072
+
2073
+ expect.soft(allStripes[2]).toHaveAttribute("width", "480");
2074
+ expect.soft(allStripes[2]).toHaveAttribute("height", "200");
2075
+ expect.soft(allStripes[2]).toHaveAttribute("x", "20");
2076
+ expect.soft(allStripes[2]).toHaveAttribute("y", "2");
2077
+ });
2078
+ });
2079
+ });
2080
+
2081
+ describe("offset prop", () => {
2082
+ it("should not pass the offset prop anywhere", () => {
2083
+ const { container } = render(() => (
2084
+ <ChartElement width={500} height={500}>
2085
+ <CartesianGrid
2086
+ {...exampleCartesianGridDimensions}
2087
+ verticalPoints={verticalPoints}
2088
+ horizontalPoints={horizontalPoints}
2089
+ />
2090
+ </ChartElement>
2091
+ ));
2092
+ flush();
2093
+ const allElements = container.querySelectorAll("*");
2094
+ expect(allElements.length).toBeGreaterThan(0);
2095
+ for (let i = 0; i < allElements.length; i++) {
2096
+ const element = allElements[0];
2097
+ expect(element).not.toHaveAttribute("offset");
2098
+ }
2099
+ });
2100
+ });
2101
+ });
2102
+ },
2103
+ );