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