solid-recharts 0.2.1 → 1.0.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 (488) hide show
  1. package/package.json +13 -11
  2. package/src/animation/AnimatedItems.tsx +2 -4
  3. package/src/animation/CSSTransitionAnimate.tsx +41 -39
  4. package/src/animation/JavascriptAnimate.tsx +45 -41
  5. package/src/cartesian/Area.tsx +4 -4
  6. package/src/cartesian/AreaRevealShape.tsx +1 -1
  7. package/src/cartesian/Bar.tsx +33 -21
  8. package/src/cartesian/BarStack.tsx +5 -5
  9. package/src/cartesian/Brush.tsx +19 -15
  10. package/src/cartesian/CartesianAxis.tsx +4 -4
  11. package/src/cartesian/CartesianGrid.tsx +5 -5
  12. package/src/cartesian/ErrorBar.tsx +9 -7
  13. package/src/cartesian/Funnel.tsx +3 -3
  14. package/src/cartesian/GraphicalItemClipPath.tsx +1 -1
  15. package/src/cartesian/Line.tsx +18 -16
  16. package/src/cartesian/LineDrawShape.tsx +14 -13
  17. package/src/cartesian/ReferenceArea.tsx +4 -4
  18. package/src/cartesian/ReferenceDot.tsx +4 -4
  19. package/src/cartesian/ReferenceLine.tsx +4 -4
  20. package/src/cartesian/RenderedTicksReporter.tsx +19 -17
  21. package/src/cartesian/Scatter.tsx +3 -3
  22. package/src/cartesian/XAxis.tsx +1 -1
  23. package/src/cartesian/YAxis.tsx +35 -33
  24. package/src/cartesian/ZAxis.tsx +3 -2
  25. package/src/chart/AreaChart.tsx +1 -1
  26. package/src/chart/BarChart.tsx +1 -1
  27. package/src/chart/CartesianChart.tsx +4 -3
  28. package/src/chart/CategoricalChart.tsx +5 -5
  29. package/src/chart/ComposedChart.tsx +1 -1
  30. package/src/chart/FunnelChart.tsx +1 -1
  31. package/src/chart/LineChart.tsx +1 -1
  32. package/src/chart/PieChart.tsx +4 -3
  33. package/src/chart/PolarChart.tsx +4 -3
  34. package/src/chart/RadarChart.tsx +4 -3
  35. package/src/chart/RadialBarChart.tsx +7 -3
  36. package/src/chart/RechartsWrapper.tsx +14 -24
  37. package/src/chart/Sankey.tsx +9 -6
  38. package/src/chart/ScatterChart.tsx +1 -1
  39. package/src/chart/SunburstChart.tsx +5 -4
  40. package/src/chart/Treemap.tsx +5 -4
  41. package/src/component/ActivePoints.tsx +6 -6
  42. package/src/component/Cell.tsx +23 -5
  43. package/src/component/Cursor.tsx +3 -3
  44. package/src/component/DefaultLegendContent.tsx +8 -6
  45. package/src/component/DefaultTooltipContent.tsx +14 -10
  46. package/src/component/Dots.tsx +5 -5
  47. package/src/component/Label.tsx +13 -10
  48. package/src/component/LabelList.tsx +12 -7
  49. package/src/component/Legend.tsx +26 -21
  50. package/src/component/ResponsiveContainer.tsx +52 -49
  51. package/src/component/Text.tsx +5 -5
  52. package/src/component/Tooltip.tsx +21 -18
  53. package/src/component/TooltipBoundingBox.tsx +18 -16
  54. package/src/component/responsiveContainerUtils.ts +1 -1
  55. package/src/container/ClipPathProvider.tsx +3 -3
  56. package/src/container/Layer.tsx +5 -5
  57. package/src/container/RootSurface.tsx +1 -1
  58. package/src/container/Surface.tsx +5 -6
  59. package/src/context/ErrorBarContext.tsx +2 -2
  60. package/src/context/PanoramaContext.tsx +2 -2
  61. package/src/context/RegisterGraphicalItemId.tsx +4 -2
  62. package/src/context/chartDataContext.tsx +26 -23
  63. package/src/context/chartLayoutContext.tsx +16 -12
  64. package/src/polar/Pie.tsx +13 -12
  65. package/src/polar/PolarAngleAxis.tsx +3 -3
  66. package/src/polar/PolarGrid.tsx +5 -5
  67. package/src/polar/PolarRadiusAxis.tsx +3 -3
  68. package/src/polar/Radar.tsx +3 -3
  69. package/src/polar/RadialBar.tsx +3 -3
  70. package/src/shape/Cross.tsx +5 -5
  71. package/src/shape/Curve.tsx +6 -7
  72. package/src/shape/Dot.tsx +4 -4
  73. package/src/shape/Polygon.tsx +5 -5
  74. package/src/shape/Rectangle.tsx +22 -20
  75. package/src/shape/Sector.tsx +5 -5
  76. package/src/shape/Symbols.tsx +5 -5
  77. package/src/shape/Trapezoid.tsx +29 -27
  78. package/src/state/RechartsStoreProvider.tsx +5 -3
  79. package/src/state/ReportChartProps.tsx +8 -6
  80. package/src/state/ReportEventSettings.tsx +8 -6
  81. package/src/state/ReportMainChartProps.tsx +11 -9
  82. package/src/state/ReportPolarOptions.tsx +15 -13
  83. package/src/state/SetLegendPayload.ts +1 -1
  84. package/src/state/SetTooltipEntrySettings.tsx +1 -1
  85. package/src/state/brushSlice.ts +10 -8
  86. package/src/state/cartesianAxisSlice.ts +46 -38
  87. package/src/state/chartDataSlice.ts +29 -23
  88. package/src/state/errorBarSlice.ts +22 -16
  89. package/src/state/eventSettingsSlice.ts +11 -9
  90. package/src/state/graphicalItemsSlice.ts +17 -13
  91. package/src/state/layoutSlice.ts +27 -19
  92. package/src/state/legendSlice.ts +24 -18
  93. package/src/state/optionsSlice.ts +8 -6
  94. package/src/state/polarAxisSlice.ts +21 -13
  95. package/src/state/polarOptionsSlice.ts +16 -14
  96. package/src/state/referenceElementsSlice.ts +25 -19
  97. package/src/state/registerInStore.ts +15 -13
  98. package/src/state/renderedTicksSlice.ts +11 -7
  99. package/src/state/rootPropsSlice.ts +16 -14
  100. package/src/state/tooltipSlice.ts +115 -95
  101. package/src/state/unregisterOnCleanup.ts +5 -20
  102. package/src/state/zIndexSlice.ts +50 -42
  103. package/src/synchronisation/useChartSynchronisation.tsx +213 -217
  104. package/src/util/ActiveShapeUtils.tsx +2 -2
  105. package/src/util/BarUtils.tsx +5 -3
  106. package/src/util/DirectPortal.tsx +107 -0
  107. package/src/util/FunnelUtils.tsx +1 -1
  108. package/src/util/RadialBarUtils.tsx +4 -3
  109. package/src/util/createCartesianCharts.tsx +1 -1
  110. package/src/util/createPolarCharts.tsx +1 -1
  111. package/src/util/svgPropertiesAndEvents.ts +1 -1
  112. package/src/util/tooltip/translate.ts +2 -2
  113. package/src/util/types.ts +2 -2
  114. package/src/zIndex/ZIndexLayer.tsx +39 -68
  115. package/src/zIndex/ZIndexPortal.tsx +29 -25
  116. package/test/_data.ts +0 -408
  117. package/test/animation/AnimationController.typed.spec.ts +0 -53
  118. package/test/animation/AnimationControllerImpl.spec.ts +0 -271
  119. package/test/animation/CSSTransitionAnimate.timing.spec.tsx +0 -473
  120. package/test/animation/JavascriptAnimate.spec.tsx +0 -62
  121. package/test/animation/RechartsAnimation.spec.ts +0 -636
  122. package/test/animation/easing.spec.ts +0 -218
  123. package/test/animation/legacyAnimationLengthChange.spec.tsx +0 -803
  124. package/test/animation/matchBy.spec.ts +0 -467
  125. package/test/animation/mockAnimationController.ts +0 -40
  126. package/test/animation/mockControllerAnimationManager.ts +0 -143
  127. package/test/animation/mockTimeoutController.ts +0 -114
  128. package/test/animation/timeoutController.spec.ts +0 -138
  129. package/test/animation/useAnimationStartSnapshot.spec.ts +0 -147
  130. package/test/animation/util.spec.ts +0 -28
  131. package/test/cartesian/Area.animation.spec.tsx +0 -363
  132. package/test/cartesian/Area.range.spec.tsx +0 -54
  133. package/test/cartesian/Area.spec.tsx +0 -1202
  134. package/test/cartesian/Area.stacked.render.spec.tsx +0 -69
  135. package/test/cartesian/Area.typed.spec.tsx +0 -209
  136. package/test/cartesian/Axis.integration.spec.tsx +0 -158
  137. package/test/cartesian/Bar/Bar.csstransition.spec.tsx +0 -299
  138. package/test/cartesian/Bar/Bar.spec.tsx +0 -2314
  139. package/test/cartesian/Bar/Bar.typed.spec.tsx +0 -192
  140. package/test/cartesian/Bar.animation.spec.tsx +0 -426
  141. package/test/cartesian/Bar.stackDomain.spec.tsx +0 -66
  142. package/test/cartesian/Bar.stacked.render.spec.tsx +0 -53
  143. package/test/cartesian/Bar.truncateByDomain.spec.tsx +0 -237
  144. package/test/cartesian/Bar.zeroDimensionFiltering.spec.tsx +0 -336
  145. package/test/cartesian/BarStack.spec.tsx +0 -91
  146. package/test/cartesian/Brush.keyboard.spec.tsx +0 -88
  147. package/test/cartesian/Brush.panorama.spec.tsx +0 -41
  148. package/test/cartesian/Brush.props.spec.tsx +0 -63
  149. package/test/cartesian/Brush.render.spec.tsx +0 -117
  150. package/test/cartesian/Brush.spec.tsx +0 -522
  151. package/test/cartesian/Brush.stacked.spec.tsx +0 -221
  152. package/test/cartesian/CartesianAxis.render.spec.tsx +0 -50
  153. package/test/cartesian/CartesianAxis.spec.tsx +0 -396
  154. package/test/cartesian/CartesianGrid.render.spec.tsx +0 -39
  155. package/test/cartesian/CartesianGrid.spec.tsx +0 -2103
  156. package/test/cartesian/ErrorBar.render.spec.tsx +0 -69
  157. package/test/cartesian/ErrorBar.spec.tsx +0 -2414
  158. package/test/cartesian/Funnel.animation.spec.tsx +0 -241
  159. package/test/cartesian/Funnel.spec.tsx +0 -226
  160. package/test/cartesian/Funnel.typed.spec.tsx +0 -221
  161. package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +0 -627
  162. package/test/cartesian/GraphicalItemClipPath.spec.tsx +0 -427
  163. package/test/cartesian/Line.animation.spec.tsx +0 -643
  164. package/test/cartesian/Line.sparseAnimationPath.spec.tsx +0 -98
  165. package/test/cartesian/Line.spec.tsx +0 -471
  166. package/test/cartesian/Line.typed.spec.tsx +0 -152
  167. package/test/cartesian/ReferenceArea.render.spec.tsx +0 -63
  168. package/test/cartesian/ReferenceArea.spec.tsx +0 -663
  169. package/test/cartesian/ReferenceArea.typed.spec.tsx +0 -74
  170. package/test/cartesian/ReferenceDot.render.spec.tsx +0 -55
  171. package/test/cartesian/ReferenceDot.spec.tsx +0 -462
  172. package/test/cartesian/ReferenceDot.typed.spec.tsx +0 -76
  173. package/test/cartesian/ReferenceLine/ReferenceLine.panorama.spec.tsx +0 -184
  174. package/test/cartesian/ReferenceLine/ReferenceLine.spec.tsx +0 -744
  175. package/test/cartesian/ReferenceLine/ReferenceLine.typed.spec.tsx +0 -74
  176. package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +0 -399
  177. package/test/cartesian/ReferenceLine.render.spec.tsx +0 -134
  178. package/test/cartesian/Scatter.animation.spec.tsx +0 -381
  179. package/test/cartesian/Scatter.render.spec.tsx +0 -61
  180. package/test/cartesian/Scatter.spec.tsx +0 -406
  181. package/test/cartesian/Scatter.typed.spec.tsx +0 -153
  182. package/test/cartesian/XAxis/XAxis.barSize.spec.tsx +0 -336
  183. package/test/cartesian/XAxis/XAxis.brush.spec.tsx +0 -266
  184. package/test/cartesian/XAxis/XAxis.categorydomain.spec.tsx +0 -872
  185. package/test/cartesian/XAxis/XAxis.dataKey.spec.tsx +0 -86
  186. package/test/cartesian/XAxis/XAxis.datatypes.spec.tsx +0 -127
  187. package/test/cartesian/XAxis/XAxis.hide.spec.tsx +0 -106
  188. package/test/cartesian/XAxis/XAxis.multiaxis.spec.tsx +0 -336
  189. package/test/cartesian/XAxis/XAxis.numberdomain.spec.tsx +0 -1466
  190. package/test/cartesian/XAxis/XAxis.padding.spec.tsx +0 -758
  191. package/test/cartesian/XAxis/XAxis.padding_clip.spec.tsx +0 -65
  192. package/test/cartesian/XAxis/XAxis.state.spec.tsx +0 -355
  193. package/test/cartesian/XAxis/XAxis.tick.spec.tsx +0 -493
  194. package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +0 -233
  195. package/test/cartesian/XAxis/XAxis.type.spec.tsx +0 -107
  196. package/test/cartesian/XAxis/XAxis.typed.spec.tsx +0 -102
  197. package/test/cartesian/XAxis/XAxis.vertical.spec.tsx +0 -265
  198. package/test/cartesian/XAxis.tickFormatter.spec.tsx +0 -54
  199. package/test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx +0 -230
  200. package/test/cartesian/YAxis/YAxis.7362.spec.tsx +0 -104
  201. package/test/cartesian/YAxis/YAxis.interval-zero.spec.tsx +0 -88
  202. package/test/cartesian/YAxis/YAxis.label.spec.tsx +0 -219
  203. package/test/cartesian/YAxis/YAxis.spec.tsx +0 -1595
  204. package/test/cartesian/YAxis/YAxis.tick.spec.tsx +0 -428
  205. package/test/cartesian/YAxis/YAxis.tickFormatter.spec.tsx +0 -54
  206. package/test/cartesian/YAxis/YAxis.ticks.spec.tsx +0 -263
  207. package/test/cartesian/YAxis/YAxis.type.spec.tsx +0 -107
  208. package/test/cartesian/YAxis/YAxis.typed.spec.tsx +0 -102
  209. package/test/cartesian/ZAxis.spec.tsx +0 -300
  210. package/test/cartesian/ZAxis.typed.spec.tsx +0 -33
  211. package/test/cartesian/__snapshots__/Brush.spec.tsx.snap +0 -5
  212. package/test/cartesian/axisLineAndStroke.spec.tsx +0 -72
  213. package/test/cartesian/getCartesianPosition.spec.ts +0 -907
  214. package/test/cartesian/getEquidistantTicks.spec.ts +0 -88
  215. package/test/cartesian/getTicks.spec.ts +0 -378
  216. package/test/cartesian/miscFeatureGaps.spec.tsx +0 -89
  217. package/test/cartesian/useAnimatedLineLength.spec.ts +0 -168
  218. package/test/chart/AccessibilityLayer.spec.tsx +0 -569
  219. package/test/chart/AccessibilityScans.spec.tsx +0 -286
  220. package/test/chart/AreaChart.spec.tsx +0 -409
  221. package/test/chart/AreaChart.stacked.spec.tsx +0 -1407
  222. package/test/chart/AreaChart.typed.spec.tsx +0 -39
  223. package/test/chart/BarChart.spec.tsx +0 -3719
  224. package/test/chart/BarChart.typed.spec.tsx +0 -60
  225. package/test/chart/CategoricalChart.spec.tsx +0 -255
  226. package/test/chart/ComposedChart.spec.tsx +0 -199
  227. package/test/chart/ComposedChart.typed.spec.tsx +0 -39
  228. package/test/chart/FunnelChart.spec.tsx +0 -215
  229. package/test/chart/FunnelChart.typed.spec.tsx +0 -39
  230. package/test/chart/LineChart.multiseries.spec.tsx +0 -50
  231. package/test/chart/LineChart.smoke.spec.tsx +0 -50
  232. package/test/chart/LineChart.spec.tsx +0 -930
  233. package/test/chart/LineChart.typed.spec.tsx +0 -39
  234. package/test/chart/NicheChartTooltip.spec.tsx +0 -81
  235. package/test/chart/PieChart.spec.tsx +0 -793
  236. package/test/chart/PieChart.typed.spec.tsx +0 -39
  237. package/test/chart/RadarChart.spec.tsx +0 -530
  238. package/test/chart/RadarChart.typed.spec.tsx +0 -39
  239. package/test/chart/RadialBarChart.5966.spec.tsx +0 -48
  240. package/test/chart/RadialBarChart.spec.tsx +0 -679
  241. package/test/chart/RadialBarChart.typed.spec.tsx +0 -39
  242. package/test/chart/RechartsWrapper.spec.tsx +0 -83
  243. package/test/chart/Sankey.content.spec.tsx +0 -46
  244. package/test/chart/Sankey.spec.tsx +0 -952
  245. package/test/chart/Sankey.typed.spec.tsx +0 -29
  246. package/test/chart/ScatterChart.spec.tsx +0 -2613
  247. package/test/chart/ScatterChart.typed.spec.tsx +0 -39
  248. package/test/chart/SunburstChart.spec.tsx +0 -146
  249. package/test/chart/Treemap.animation.spec.tsx +0 -52
  250. package/test/chart/Treemap.spec.tsx +0 -1003
  251. package/test/chart/Treemap.typed.spec.tsx +0 -26
  252. package/test/chart/chartEvents.spec.tsx +0 -127
  253. package/test/chart/responsive.spec.tsx +0 -620
  254. package/test/component/Cell.render.spec.tsx +0 -155
  255. package/test/component/Cell.spec.tsx +0 -12
  256. package/test/component/Cursor.spec.tsx +0 -186
  257. package/test/component/DefaultTooltipContent.spec.tsx +0 -102
  258. package/test/component/Label.render.spec.tsx +0 -63
  259. package/test/component/Label.spec.tsx +0 -686
  260. package/test/component/Label.typed.spec.tsx +0 -46
  261. package/test/component/LabelList.spec.tsx +0 -188
  262. package/test/component/Legend.itemSorter.spec.tsx +0 -704
  263. package/test/component/Legend.render.spec.tsx +0 -92
  264. package/test/component/Legend.spec.tsx +0 -2213
  265. package/test/component/Legend.typed.spec.tsx +0 -22
  266. package/test/component/ResponsiveContainer.spec.tsx +0 -523
  267. package/test/component/ResponsiveContainerDataTest.spec.tsx +0 -51
  268. package/test/component/Text.spec.tsx +0 -415
  269. package/test/component/Text.typed.spec.tsx +0 -46
  270. package/test/component/Tooltip/ActiveDot.spec.tsx +0 -370
  271. package/test/component/Tooltip/Tooltip.animation.spec.tsx +0 -209
  272. package/test/component/Tooltip/Tooltip.content.spec.tsx +0 -128
  273. package/test/component/Tooltip/Tooltip.formatter.spec.tsx +0 -152
  274. package/test/component/Tooltip/Tooltip.includeHidden.spec.tsx +0 -79
  275. package/test/component/Tooltip/Tooltip.multipleDataArrays.spec.tsx +0 -165
  276. package/test/component/Tooltip/Tooltip.offset.spec.tsx +0 -113
  277. package/test/component/Tooltip/Tooltip.state.spec.tsx +0 -74
  278. package/test/component/Tooltip/Tooltip.sync.spec.tsx +0 -639
  279. package/test/component/Tooltip/defaultIndex.spec.tsx +0 -227
  280. package/test/component/Tooltip/graphicalItem.formatter.spec.tsx +0 -138
  281. package/test/component/Tooltip/itemSorter.spec.tsx +0 -2815
  282. package/test/component/Tooltip/tooltipEventType.spec.tsx +0 -344
  283. package/test/component/Tooltip/tooltipMouseHoverSelectors.ts +0 -41
  284. package/test/component/Tooltip/tooltipTestHelpers.tsx +0 -162
  285. package/test/component/Tooltip.defaultIndex.spec.tsx +0 -48
  286. package/test/component/Tooltip.hover.spec.tsx +0 -61
  287. package/test/component/Tooltip.item.spec.tsx +0 -54
  288. package/test/component/Tooltip.keyboard.spec.tsx +0 -51
  289. package/test/component/Tooltip.payload.spec.tsx +0 -1716
  290. package/test/component/Tooltip.touch.spec.tsx +0 -39
  291. package/test/component/Tooltip.visibility.spec.tsx +0 -1889
  292. package/test/component/TooltipBoundingBox.spec.tsx +0 -89
  293. package/test/component/responsiveContainerUtils.spec.ts +0 -205
  294. package/test/container/ClipPath.spec.tsx +0 -602
  295. package/test/container/chartDimensions.spec.tsx +0 -368
  296. package/test/context/chartLayoutContext.spec.tsx +0 -378
  297. package/test/helper/ExpectAxisDomain.tsx +0 -27
  298. package/test/helper/assertNotNull.ts +0 -6
  299. package/test/helper/assertZIndexLayerOrder.ts +0 -19
  300. package/test/helper/createSelectorTestCase.tsx +0 -176
  301. package/test/helper/expectAnimatedPieAngles.ts +0 -100
  302. package/test/helper/expectAnimatedPiePaths.ts +0 -78
  303. package/test/helper/expectAreaCurve.ts +0 -15
  304. package/test/helper/expectAxisTicks.ts +0 -48
  305. package/test/helper/expectBars.ts +0 -54
  306. package/test/helper/expectFunctionReturning.ts +0 -58
  307. package/test/helper/expectLabel.ts +0 -32
  308. package/test/helper/expectLastCalledWith.ts +0 -48
  309. package/test/helper/expectLine.ts +0 -20
  310. package/test/helper/expectPieSectors.ts +0 -80
  311. package/test/helper/expectScale.ts +0 -37
  312. package/test/helper/expectScatterPoints.ts +0 -52
  313. package/test/helper/expectStackGroups.ts +0 -144
  314. package/test/helper/mockAxes.ts +0 -22
  315. package/test/helper/mockGetBoundingClientRect.ts +0 -66
  316. package/test/helper/mockHTMLElementProperty.ts +0 -19
  317. package/test/helper/mockTouchingElement.ts +0 -27
  318. package/test/helper/offsetHelpers.ts +0 -19
  319. package/test/helper/parameterizedTestCases.tsx +0 -99
  320. package/test/helper/produceState.ts +0 -32
  321. package/test/helper/selectorTestHelpers.tsx +0 -63
  322. package/test/helper/trim.spec.ts +0 -35
  323. package/test/helper/trim.ts +0 -11
  324. package/test/hooks/useActiveTooltipDataPoints.spec.tsx +0 -358
  325. package/test/hooks/useAxisDomain.spec.tsx +0 -361
  326. package/test/hooks/useAxisScale.spec.tsx +0 -283
  327. package/test/hooks/useAxisTicks.spec.tsx +0 -130
  328. package/test/hooks/useOffset.spec.tsx +0 -248
  329. package/test/hooks/useTooltipStateHooks.spec.tsx +0 -109
  330. package/test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx +0 -135
  331. package/test/polar/Pie/Pie.spec.tsx +0 -784
  332. package/test/polar/Pie/Pie.typed.spec.tsx +0 -78
  333. package/test/polar/Pie.animation.spec.tsx +0 -529
  334. package/test/polar/PieWithLegend.animation.spec.tsx +0 -142
  335. package/test/polar/PolarAngleAxis/PolarAngleAxis.events.spec.tsx +0 -76
  336. package/test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx +0 -2079
  337. package/test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx +0 -102
  338. package/test/polar/PolarAngleAxis.render.spec.tsx +0 -79
  339. package/test/polar/PolarGrid.render.spec.tsx +0 -75
  340. package/test/polar/PolarGrid.spec.tsx +0 -918
  341. package/test/polar/PolarLegendPerRow.render.spec.tsx +0 -85
  342. package/test/polar/PolarRadiusAxis.events.spec.tsx +0 -65
  343. package/test/polar/PolarRadiusAxis.render.spec.tsx +0 -52
  344. package/test/polar/PolarRadiusAxis.spec.tsx +0 -991
  345. package/test/polar/PolarRadiusAxis.typed.spec.tsx +0 -84
  346. package/test/polar/PolarTooltipLegend.render.spec.tsx +0 -80
  347. package/test/polar/Radar.animation.spec.tsx +0 -570
  348. package/test/polar/Radar.render.spec.tsx +0 -71
  349. package/test/polar/Radar.spec.tsx +0 -265
  350. package/test/polar/Radar.typed.spec.tsx +0 -119
  351. package/test/polar/RadialBar/RadialBar.spec.tsx +0 -1521
  352. package/test/polar/RadialBar/RadialBar.typed.spec.tsx +0 -132
  353. package/test/polar/RadialBar.animation.spec.tsx +0 -375
  354. package/test/polar/RadialBar.render.spec.tsx +0 -66
  355. package/test/polar/RadialBar.stacked.spec.tsx +0 -57
  356. package/test/setup.ts +0 -84
  357. package/test/shape/ActiveShape.spec.tsx +0 -181
  358. package/test/shape/Cross.spec.tsx +0 -60
  359. package/test/shape/Cross.typed.spec.tsx +0 -26
  360. package/test/shape/Curve.spec.tsx +0 -368
  361. package/test/shape/Curve.typed.spec.tsx +0 -69
  362. package/test/shape/Dot.spec.tsx +0 -73
  363. package/test/shape/Dot.typed.spec.tsx +0 -30
  364. package/test/shape/Polygon.spec.tsx +0 -357
  365. package/test/shape/Polygon.typed.spec.tsx +0 -28
  366. package/test/shape/Rectangle.animation.spec.tsx +0 -451
  367. package/test/shape/Rectangle.spec.tsx +0 -68
  368. package/test/shape/Rectangle.typed.spec.tsx +0 -24
  369. package/test/shape/Sector.spec.tsx +0 -76
  370. package/test/shape/Sector.typed.spec.tsx +0 -24
  371. package/test/shape/Symbols.spec.tsx +0 -43
  372. package/test/shape/Symbols.typed.spec.tsx +0 -24
  373. package/test/shape/Trapezoid.spec.tsx +0 -50
  374. package/test/shape/Trapezoid.typed.spec.tsx +0 -24
  375. package/test/shape/__snapshots__/Cross.spec.tsx.snap +0 -62
  376. package/test/shape/__snapshots__/Curve.spec.tsx.snap +0 -460
  377. package/test/shape/__snapshots__/Polygon.spec.tsx.snap +0 -58
  378. package/test/shape/__snapshots__/Rectangle.spec.tsx.snap +0 -117
  379. package/test/shape/__snapshots__/Sector.spec.tsx.snap +0 -71
  380. package/test/shape/__snapshots__/Trapezoid.spec.tsx.snap +0 -64
  381. package/test/state/chartDataSlice.spec.ts +0 -53
  382. package/test/state/createCollectionActions.spec.ts +0 -87
  383. package/test/state/createSelector.spec.ts +0 -158
  384. package/test/state/externalEventsMiddleware.spec.ts +0 -178
  385. package/test/state/graphicalItemsSlice.spec.ts +0 -92
  386. package/test/state/hooks.spec.tsx +0 -68
  387. package/test/state/legendSlice.spec.ts +0 -44
  388. package/test/state/mouseEventsMiddleware.spec.ts +0 -75
  389. package/test/state/optionsSlice.spec.ts +0 -19
  390. package/test/state/referenceElementsSlice.spec.ts +0 -84
  391. package/test/state/registerInStore.spec.tsx +0 -101
  392. package/test/state/selectors/areaSelectors.spec.tsx +0 -77
  393. package/test/state/selectors/axisSelectors.spec.tsx +0 -1418
  394. package/test/state/selectors/barStackSelectors.spec.tsx +0 -752
  395. package/test/state/selectors/brushSelectors.spec.tsx +0 -30
  396. package/test/state/selectors/cartesianAxisSlice.spec.ts +0 -96
  397. package/test/state/selectors/combineNiceTicks.spec.ts +0 -207
  398. package/test/state/selectors/combiners/combineActiveTooltipIndex.spec.ts +0 -61
  399. package/test/state/selectors/combiners/combineAllBarPositions.spec.ts +0 -39
  400. package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +0 -56
  401. package/test/state/selectors/combiners/combineDisplayedStackedData.spec.ts +0 -123
  402. package/test/state/selectors/combiners/combineRealScaleType.spec.ts +0 -80
  403. package/test/state/selectors/containerSelectors.spec.tsx +0 -168
  404. package/test/state/selectors/dataSelectors.spec.tsx +0 -136
  405. package/test/state/selectors/legendSelectors.spec.tsx +0 -113
  406. package/test/state/selectors/lineSelectors.spec.tsx +0 -60
  407. package/test/state/selectors/pieSelectors.spec.tsx +0 -72
  408. package/test/state/selectors/radarSelectors.spec.tsx +0 -496
  409. package/test/state/selectors/rootPropsSelectors.spec.tsx +0 -169
  410. package/test/state/selectors/scatterSelectors.spec.tsx +0 -47
  411. package/test/state/selectors/selectActiveTooltipIndex.spec.tsx +0 -234
  412. package/test/state/selectors/selectAllAxes.spec.tsx +0 -18
  413. package/test/state/selectors/selectAxisDomain.spec.tsx +0 -21
  414. package/test/state/selectors/selectAxisDomainIncludingNiceTicks.spec.tsx +0 -19
  415. package/test/state/selectors/selectAxisRangeWithReverse.spec.tsx +0 -22
  416. package/test/state/selectors/selectAxisScale.spec.tsx +0 -91
  417. package/test/state/selectors/selectBarRectangles.stackOffset.spec.tsx +0 -503
  418. package/test/state/selectors/selectBaseAxis.spec.tsx +0 -56
  419. package/test/state/selectors/selectCartesianItemsSettings.spec.tsx +0 -57
  420. package/test/state/selectors/selectChartOffset.spec.tsx +0 -26
  421. package/test/state/selectors/selectDisplayedData.spec.tsx +0 -282
  422. package/test/state/selectors/selectIsTooltipActive.spec.tsx +0 -231
  423. package/test/state/selectors/selectNumericalDomain.spec.tsx +0 -21
  424. package/test/state/selectors/selectRealScaleType.spec.tsx +0 -19
  425. package/test/state/selectors/selectStackGroups.spec.tsx +0 -322
  426. package/test/state/selectors/selectXAxisPosition.spec.tsx +0 -22
  427. package/test/state/selectors/selectYAxisPosition.spec.tsx +0 -22
  428. package/test/state/selectors/selectorMemoization.spec.tsx +0 -136
  429. package/test/state/selectors/selectors.spec.tsx +0 -1613
  430. package/test/state/throttling.spec.ts +0 -200
  431. package/test/state/zIndexSlice.spec.ts +0 -85
  432. package/test/synchronisation/useChartSynchronisation.spec.tsx +0 -225
  433. package/test/util/BarUtils.spec.ts +0 -39
  434. package/test/util/CartesianUtils/CartesianUtils.spec.ts +0 -261
  435. package/test/util/CartesianUtils/rectWithPoints.spec.ts +0 -48
  436. package/test/util/ChartUtils/ChartUtils.spec.ts +0 -491
  437. package/test/util/ChartUtils/appendOffsetOfLegend.spec.ts +0 -136
  438. package/test/util/ChartUtils/appendOffsetOfLegend.spec.tsx +0 -133
  439. package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +0 -97
  440. package/test/util/ChartUtils/getStackedData.spec.ts +0 -416
  441. package/test/util/ChartUtils/truncateByDomain.spec.ts +0 -70
  442. package/test/util/DataUtils.spec.ts +0 -385
  443. package/test/util/DomUtils.spec.tsx +0 -117
  444. package/test/util/FunnelUtils.spec.tsx +0 -70
  445. package/test/util/Global.spec.ts +0 -11
  446. package/test/util/LRUCache.spec.ts +0 -81
  447. package/test/util/LogUtils.spec.ts +0 -45
  448. package/test/util/PolarUtils.spec.ts +0 -66
  449. package/test/util/ReduceCssCalcPrototype.spec.ts +0 -141
  450. package/test/util/ShallowEqual.spec.ts +0 -102
  451. package/test/util/TickUtils.spec.ts +0 -29
  452. package/test/util/createChartHelpers.spec.tsx +0 -210
  453. package/test/util/cursor/getCursorPoints.spec.ts +0 -136
  454. package/test/util/cursor/getCursorRectangle.spec.ts +0 -50
  455. package/test/util/cursor/getRadialCursorPoints.spec.ts +0 -36
  456. package/test/util/errorValue.spec.ts +0 -69
  457. package/test/util/getEveryNth.spec.ts +0 -39
  458. package/test/util/getRadiusAndStrokeWidthFromDot.spec.ts +0 -51
  459. package/test/util/getRelativeCoordinate.spec.ts +0 -250
  460. package/test/util/getSliced.spec.ts +0 -45
  461. package/test/util/isDomainSpecifiedByUser.spec.ts +0 -207
  462. package/test/util/isWellBehavedNumber.spec.ts +0 -54
  463. package/test/util/payload/getUniqPayload.spec.ts +0 -56
  464. package/test/util/propsAreEqual.spec.ts +0 -75
  465. package/test/util/round.spec.ts +0 -112
  466. package/test/util/scale/arithmetic.spec.ts +0 -61
  467. package/test/util/scale/createCategoricalInverse.spec.ts +0 -84
  468. package/test/util/scale/getNiceTickValues.spec.ts +0 -421
  469. package/test/util/scale/getTickValuesFixedDomain.spec.ts +0 -155
  470. package/test/util/svgPropertiesAndEvents.spec.tsx +0 -206
  471. package/test/util/svgPropertiesNoEvents.spec.tsx +0 -228
  472. package/test/util/tooltip/translate.spec.ts +0 -396
  473. package/test/util/useAnimationId.spec.tsx +0 -59
  474. package/test/util/useElementOffset.spec.tsx +0 -173
  475. package/test/util/usePrefersReducedMotion.spec.ts +0 -54
  476. package/test/util/useUniqueId.spec.ts +0 -99
  477. package/test/utils/diagnostics-allowlist.ts +0 -18
  478. package/test/utils/diagnostics.ts +0 -58
  479. package/test/zIndex/AllZIndexPortals.spec.tsx +0 -83
  480. package/test/zIndex/DefaultZIndexes.spec.ts +0 -80
  481. package/test/zIndex/DynamicZIndex.spec.tsx +0 -102
  482. package/test/zIndex/ZIndexLayer.portalOwner.spec.tsx +0 -125
  483. package/test/zIndex/componentZIndex.spec.tsx +0 -255
  484. package/test/zIndex/getZIndexFromUnknown.spec.ts +0 -51
  485. package/test/zIndex/multiChartZIndexIsolation.spec.tsx +0 -90
  486. package/test/zIndex/zIndexSelectors.spec.ts +0 -172
  487. package/test-results/.last-run.json +0 -4
  488. package/tsconfig.json +0 -11
@@ -1,2103 +0,0 @@
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 "@solidjs/testing-library";
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
- );