solid-recharts 1.0.0 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (488) hide show
  1. package/package.json +4 -6
  2. package/src/animation/AnimatedItems.tsx +4 -2
  3. package/src/animation/CSSTransitionAnimate.tsx +39 -41
  4. package/src/animation/JavascriptAnimate.tsx +41 -45
  5. package/src/cartesian/Area.tsx +4 -4
  6. package/src/cartesian/AreaRevealShape.tsx +1 -1
  7. package/src/cartesian/Bar.tsx +21 -33
  8. package/src/cartesian/BarStack.tsx +5 -5
  9. package/src/cartesian/Brush.tsx +15 -19
  10. package/src/cartesian/CartesianAxis.tsx +4 -4
  11. package/src/cartesian/CartesianGrid.tsx +5 -5
  12. package/src/cartesian/ErrorBar.tsx +7 -9
  13. package/src/cartesian/Funnel.tsx +3 -3
  14. package/src/cartesian/GraphicalItemClipPath.tsx +1 -1
  15. package/src/cartesian/Line.tsx +16 -18
  16. package/src/cartesian/LineDrawShape.tsx +13 -14
  17. package/src/cartesian/ReferenceArea.tsx +4 -4
  18. package/src/cartesian/ReferenceDot.tsx +4 -4
  19. package/src/cartesian/ReferenceLine.tsx +4 -4
  20. package/src/cartesian/RenderedTicksReporter.tsx +17 -19
  21. package/src/cartesian/Scatter.tsx +3 -3
  22. package/src/cartesian/XAxis.tsx +1 -1
  23. package/src/cartesian/YAxis.tsx +33 -35
  24. package/src/cartesian/ZAxis.tsx +2 -3
  25. package/src/chart/AreaChart.tsx +1 -1
  26. package/src/chart/BarChart.tsx +1 -1
  27. package/src/chart/CartesianChart.tsx +3 -4
  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 +3 -4
  33. package/src/chart/PolarChart.tsx +3 -4
  34. package/src/chart/RadarChart.tsx +3 -4
  35. package/src/chart/RadialBarChart.tsx +3 -7
  36. package/src/chart/RechartsWrapper.tsx +24 -14
  37. package/src/chart/Sankey.tsx +6 -9
  38. package/src/chart/ScatterChart.tsx +1 -1
  39. package/src/chart/SunburstChart.tsx +4 -5
  40. package/src/chart/Treemap.tsx +4 -5
  41. package/src/component/ActivePoints.tsx +6 -6
  42. package/src/component/Cell.tsx +5 -23
  43. package/src/component/Cursor.tsx +3 -3
  44. package/src/component/DefaultLegendContent.tsx +6 -8
  45. package/src/component/DefaultTooltipContent.tsx +10 -14
  46. package/src/component/Dots.tsx +5 -5
  47. package/src/component/Label.tsx +10 -13
  48. package/src/component/LabelList.tsx +7 -12
  49. package/src/component/Legend.tsx +21 -26
  50. package/src/component/ResponsiveContainer.tsx +49 -52
  51. package/src/component/Text.tsx +5 -5
  52. package/src/component/Tooltip.tsx +18 -21
  53. package/src/component/TooltipBoundingBox.tsx +16 -18
  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 +6 -5
  59. package/src/context/ErrorBarContext.tsx +2 -2
  60. package/src/context/PanoramaContext.tsx +2 -2
  61. package/src/context/RegisterGraphicalItemId.tsx +2 -4
  62. package/src/context/chartDataContext.tsx +23 -26
  63. package/src/context/chartLayoutContext.tsx +12 -16
  64. package/src/polar/Pie.tsx +12 -13
  65. package/src/polar/PolarAngleAxis.tsx +3 -3
  66. package/src/polar/PolarGrid.tsx +5 -5
  67. package/src/polar/PolarRadiusAxis.tsx +3 -3
  68. package/src/polar/Radar.tsx +3 -3
  69. package/src/polar/RadialBar.tsx +3 -3
  70. package/src/shape/Cross.tsx +5 -5
  71. package/src/shape/Curve.tsx +7 -6
  72. package/src/shape/Dot.tsx +4 -4
  73. package/src/shape/Polygon.tsx +5 -5
  74. package/src/shape/Rectangle.tsx +20 -22
  75. package/src/shape/Sector.tsx +5 -5
  76. package/src/shape/Symbols.tsx +5 -5
  77. package/src/shape/Trapezoid.tsx +27 -29
  78. package/src/state/RechartsStoreProvider.tsx +3 -5
  79. package/src/state/ReportChartProps.tsx +6 -8
  80. package/src/state/ReportEventSettings.tsx +6 -8
  81. package/src/state/ReportMainChartProps.tsx +9 -11
  82. package/src/state/ReportPolarOptions.tsx +13 -15
  83. package/src/state/SetLegendPayload.ts +1 -1
  84. package/src/state/SetTooltipEntrySettings.tsx +1 -1
  85. package/src/state/brushSlice.ts +8 -10
  86. package/src/state/cartesianAxisSlice.ts +38 -46
  87. package/src/state/chartDataSlice.ts +23 -29
  88. package/src/state/errorBarSlice.ts +16 -22
  89. package/src/state/eventSettingsSlice.ts +9 -11
  90. package/src/state/graphicalItemsSlice.ts +13 -17
  91. package/src/state/layoutSlice.ts +19 -27
  92. package/src/state/legendSlice.ts +18 -24
  93. package/src/state/optionsSlice.ts +6 -8
  94. package/src/state/polarAxisSlice.ts +13 -21
  95. package/src/state/polarOptionsSlice.ts +14 -16
  96. package/src/state/referenceElementsSlice.ts +19 -25
  97. package/src/state/registerInStore.ts +13 -15
  98. package/src/state/renderedTicksSlice.ts +7 -11
  99. package/src/state/rootPropsSlice.ts +14 -16
  100. package/src/state/tooltipSlice.ts +95 -115
  101. package/src/state/unregisterOnCleanup.ts +20 -5
  102. package/src/state/zIndexSlice.ts +42 -50
  103. package/src/synchronisation/useChartSynchronisation.tsx +217 -213
  104. package/src/util/ActiveShapeUtils.tsx +2 -2
  105. package/src/util/BarUtils.tsx +3 -5
  106. package/src/util/FunnelUtils.tsx +1 -1
  107. package/src/util/RadialBarUtils.tsx +3 -4
  108. package/src/util/createCartesianCharts.tsx +1 -1
  109. package/src/util/createPolarCharts.tsx +1 -1
  110. package/src/util/svgPropertiesAndEvents.ts +1 -1
  111. package/src/util/tooltip/translate.ts +2 -2
  112. package/src/util/types.ts +2 -2
  113. package/src/zIndex/ZIndexLayer.tsx +68 -39
  114. package/src/zIndex/ZIndexPortal.tsx +25 -29
  115. package/test/_data.ts +408 -0
  116. package/test/animation/AnimationController.typed.spec.ts +53 -0
  117. package/test/animation/AnimationControllerImpl.spec.ts +271 -0
  118. package/test/animation/CSSTransitionAnimate.timing.spec.tsx +473 -0
  119. package/test/animation/JavascriptAnimate.spec.tsx +62 -0
  120. package/test/animation/RechartsAnimation.spec.ts +636 -0
  121. package/test/animation/easing.spec.ts +218 -0
  122. package/test/animation/legacyAnimationLengthChange.spec.tsx +803 -0
  123. package/test/animation/matchBy.spec.ts +467 -0
  124. package/test/animation/mockAnimationController.ts +40 -0
  125. package/test/animation/mockControllerAnimationManager.ts +143 -0
  126. package/test/animation/mockTimeoutController.ts +114 -0
  127. package/test/animation/timeoutController.spec.ts +138 -0
  128. package/test/animation/useAnimationStartSnapshot.spec.ts +147 -0
  129. package/test/animation/util.spec.ts +28 -0
  130. package/test/cartesian/Area.animation.spec.tsx +363 -0
  131. package/test/cartesian/Area.range.spec.tsx +54 -0
  132. package/test/cartesian/Area.spec.tsx +1202 -0
  133. package/test/cartesian/Area.stacked.render.spec.tsx +69 -0
  134. package/test/cartesian/Area.typed.spec.tsx +209 -0
  135. package/test/cartesian/Axis.integration.spec.tsx +158 -0
  136. package/test/cartesian/Bar/Bar.csstransition.spec.tsx +299 -0
  137. package/test/cartesian/Bar/Bar.spec.tsx +2314 -0
  138. package/test/cartesian/Bar/Bar.typed.spec.tsx +192 -0
  139. package/test/cartesian/Bar.animation.spec.tsx +426 -0
  140. package/test/cartesian/Bar.stackDomain.spec.tsx +66 -0
  141. package/test/cartesian/Bar.stacked.render.spec.tsx +53 -0
  142. package/test/cartesian/Bar.truncateByDomain.spec.tsx +237 -0
  143. package/test/cartesian/Bar.zeroDimensionFiltering.spec.tsx +336 -0
  144. package/test/cartesian/BarStack.spec.tsx +91 -0
  145. package/test/cartesian/Brush.keyboard.spec.tsx +88 -0
  146. package/test/cartesian/Brush.panorama.spec.tsx +41 -0
  147. package/test/cartesian/Brush.props.spec.tsx +63 -0
  148. package/test/cartesian/Brush.render.spec.tsx +117 -0
  149. package/test/cartesian/Brush.spec.tsx +522 -0
  150. package/test/cartesian/Brush.stacked.spec.tsx +221 -0
  151. package/test/cartesian/CartesianAxis.render.spec.tsx +50 -0
  152. package/test/cartesian/CartesianAxis.spec.tsx +396 -0
  153. package/test/cartesian/CartesianGrid.render.spec.tsx +39 -0
  154. package/test/cartesian/CartesianGrid.spec.tsx +2103 -0
  155. package/test/cartesian/ErrorBar.render.spec.tsx +69 -0
  156. package/test/cartesian/ErrorBar.spec.tsx +2414 -0
  157. package/test/cartesian/Funnel.animation.spec.tsx +241 -0
  158. package/test/cartesian/Funnel.spec.tsx +226 -0
  159. package/test/cartesian/Funnel.typed.spec.tsx +221 -0
  160. package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +627 -0
  161. package/test/cartesian/GraphicalItemClipPath.spec.tsx +427 -0
  162. package/test/cartesian/Line.animation.spec.tsx +643 -0
  163. package/test/cartesian/Line.sparseAnimationPath.spec.tsx +98 -0
  164. package/test/cartesian/Line.spec.tsx +471 -0
  165. package/test/cartesian/Line.typed.spec.tsx +152 -0
  166. package/test/cartesian/ReferenceArea.render.spec.tsx +63 -0
  167. package/test/cartesian/ReferenceArea.spec.tsx +663 -0
  168. package/test/cartesian/ReferenceArea.typed.spec.tsx +74 -0
  169. package/test/cartesian/ReferenceDot.render.spec.tsx +55 -0
  170. package/test/cartesian/ReferenceDot.spec.tsx +462 -0
  171. package/test/cartesian/ReferenceDot.typed.spec.tsx +76 -0
  172. package/test/cartesian/ReferenceLine/ReferenceLine.panorama.spec.tsx +184 -0
  173. package/test/cartesian/ReferenceLine/ReferenceLine.spec.tsx +744 -0
  174. package/test/cartesian/ReferenceLine/ReferenceLine.typed.spec.tsx +74 -0
  175. package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +399 -0
  176. package/test/cartesian/ReferenceLine.render.spec.tsx +134 -0
  177. package/test/cartesian/Scatter.animation.spec.tsx +381 -0
  178. package/test/cartesian/Scatter.render.spec.tsx +61 -0
  179. package/test/cartesian/Scatter.spec.tsx +406 -0
  180. package/test/cartesian/Scatter.typed.spec.tsx +153 -0
  181. package/test/cartesian/XAxis/XAxis.barSize.spec.tsx +336 -0
  182. package/test/cartesian/XAxis/XAxis.brush.spec.tsx +266 -0
  183. package/test/cartesian/XAxis/XAxis.categorydomain.spec.tsx +872 -0
  184. package/test/cartesian/XAxis/XAxis.dataKey.spec.tsx +86 -0
  185. package/test/cartesian/XAxis/XAxis.datatypes.spec.tsx +127 -0
  186. package/test/cartesian/XAxis/XAxis.hide.spec.tsx +106 -0
  187. package/test/cartesian/XAxis/XAxis.multiaxis.spec.tsx +336 -0
  188. package/test/cartesian/XAxis/XAxis.numberdomain.spec.tsx +1466 -0
  189. package/test/cartesian/XAxis/XAxis.padding.spec.tsx +758 -0
  190. package/test/cartesian/XAxis/XAxis.padding_clip.spec.tsx +65 -0
  191. package/test/cartesian/XAxis/XAxis.state.spec.tsx +355 -0
  192. package/test/cartesian/XAxis/XAxis.tick.spec.tsx +493 -0
  193. package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +233 -0
  194. package/test/cartesian/XAxis/XAxis.type.spec.tsx +107 -0
  195. package/test/cartesian/XAxis/XAxis.typed.spec.tsx +102 -0
  196. package/test/cartesian/XAxis/XAxis.vertical.spec.tsx +265 -0
  197. package/test/cartesian/XAxis.tickFormatter.spec.tsx +54 -0
  198. package/test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx +230 -0
  199. package/test/cartesian/YAxis/YAxis.7362.spec.tsx +104 -0
  200. package/test/cartesian/YAxis/YAxis.interval-zero.spec.tsx +88 -0
  201. package/test/cartesian/YAxis/YAxis.label.spec.tsx +219 -0
  202. package/test/cartesian/YAxis/YAxis.spec.tsx +1595 -0
  203. package/test/cartesian/YAxis/YAxis.tick.spec.tsx +428 -0
  204. package/test/cartesian/YAxis/YAxis.tickFormatter.spec.tsx +54 -0
  205. package/test/cartesian/YAxis/YAxis.ticks.spec.tsx +263 -0
  206. package/test/cartesian/YAxis/YAxis.type.spec.tsx +107 -0
  207. package/test/cartesian/YAxis/YAxis.typed.spec.tsx +102 -0
  208. package/test/cartesian/ZAxis.spec.tsx +300 -0
  209. package/test/cartesian/ZAxis.typed.spec.tsx +33 -0
  210. package/test/cartesian/__snapshots__/Brush.spec.tsx.snap +5 -0
  211. package/test/cartesian/axisLineAndStroke.spec.tsx +72 -0
  212. package/test/cartesian/getCartesianPosition.spec.ts +907 -0
  213. package/test/cartesian/getEquidistantTicks.spec.ts +88 -0
  214. package/test/cartesian/getTicks.spec.ts +378 -0
  215. package/test/cartesian/miscFeatureGaps.spec.tsx +89 -0
  216. package/test/cartesian/useAnimatedLineLength.spec.ts +168 -0
  217. package/test/chart/AccessibilityLayer.spec.tsx +569 -0
  218. package/test/chart/AccessibilityScans.spec.tsx +286 -0
  219. package/test/chart/AreaChart.spec.tsx +409 -0
  220. package/test/chart/AreaChart.stacked.spec.tsx +1407 -0
  221. package/test/chart/AreaChart.typed.spec.tsx +39 -0
  222. package/test/chart/BarChart.spec.tsx +3719 -0
  223. package/test/chart/BarChart.typed.spec.tsx +60 -0
  224. package/test/chart/CategoricalChart.spec.tsx +255 -0
  225. package/test/chart/ComposedChart.spec.tsx +199 -0
  226. package/test/chart/ComposedChart.typed.spec.tsx +39 -0
  227. package/test/chart/FunnelChart.spec.tsx +215 -0
  228. package/test/chart/FunnelChart.typed.spec.tsx +39 -0
  229. package/test/chart/LineChart.multiseries.spec.tsx +50 -0
  230. package/test/chart/LineChart.smoke.spec.tsx +50 -0
  231. package/test/chart/LineChart.spec.tsx +930 -0
  232. package/test/chart/LineChart.typed.spec.tsx +39 -0
  233. package/test/chart/NicheChartTooltip.spec.tsx +81 -0
  234. package/test/chart/PieChart.spec.tsx +793 -0
  235. package/test/chart/PieChart.typed.spec.tsx +39 -0
  236. package/test/chart/RadarChart.spec.tsx +530 -0
  237. package/test/chart/RadarChart.typed.spec.tsx +39 -0
  238. package/test/chart/RadialBarChart.5966.spec.tsx +48 -0
  239. package/test/chart/RadialBarChart.spec.tsx +679 -0
  240. package/test/chart/RadialBarChart.typed.spec.tsx +39 -0
  241. package/test/chart/RechartsWrapper.spec.tsx +83 -0
  242. package/test/chart/Sankey.content.spec.tsx +46 -0
  243. package/test/chart/Sankey.spec.tsx +952 -0
  244. package/test/chart/Sankey.typed.spec.tsx +29 -0
  245. package/test/chart/ScatterChart.spec.tsx +2613 -0
  246. package/test/chart/ScatterChart.typed.spec.tsx +39 -0
  247. package/test/chart/SunburstChart.spec.tsx +146 -0
  248. package/test/chart/Treemap.animation.spec.tsx +52 -0
  249. package/test/chart/Treemap.spec.tsx +1003 -0
  250. package/test/chart/Treemap.typed.spec.tsx +26 -0
  251. package/test/chart/chartEvents.spec.tsx +127 -0
  252. package/test/chart/responsive.spec.tsx +620 -0
  253. package/test/component/Cell.render.spec.tsx +155 -0
  254. package/test/component/Cell.spec.tsx +12 -0
  255. package/test/component/Cursor.spec.tsx +186 -0
  256. package/test/component/DefaultTooltipContent.spec.tsx +102 -0
  257. package/test/component/Label.render.spec.tsx +63 -0
  258. package/test/component/Label.spec.tsx +686 -0
  259. package/test/component/Label.typed.spec.tsx +46 -0
  260. package/test/component/LabelList.spec.tsx +188 -0
  261. package/test/component/Legend.itemSorter.spec.tsx +704 -0
  262. package/test/component/Legend.render.spec.tsx +92 -0
  263. package/test/component/Legend.spec.tsx +2213 -0
  264. package/test/component/Legend.typed.spec.tsx +22 -0
  265. package/test/component/ResponsiveContainer.spec.tsx +523 -0
  266. package/test/component/ResponsiveContainerDataTest.spec.tsx +51 -0
  267. package/test/component/Text.spec.tsx +415 -0
  268. package/test/component/Text.typed.spec.tsx +46 -0
  269. package/test/component/Tooltip/ActiveDot.spec.tsx +370 -0
  270. package/test/component/Tooltip/Tooltip.animation.spec.tsx +209 -0
  271. package/test/component/Tooltip/Tooltip.content.spec.tsx +128 -0
  272. package/test/component/Tooltip/Tooltip.formatter.spec.tsx +152 -0
  273. package/test/component/Tooltip/Tooltip.includeHidden.spec.tsx +79 -0
  274. package/test/component/Tooltip/Tooltip.multipleDataArrays.spec.tsx +165 -0
  275. package/test/component/Tooltip/Tooltip.offset.spec.tsx +113 -0
  276. package/test/component/Tooltip/Tooltip.state.spec.tsx +74 -0
  277. package/test/component/Tooltip/Tooltip.sync.spec.tsx +639 -0
  278. package/test/component/Tooltip/defaultIndex.spec.tsx +227 -0
  279. package/test/component/Tooltip/graphicalItem.formatter.spec.tsx +138 -0
  280. package/test/component/Tooltip/itemSorter.spec.tsx +2815 -0
  281. package/test/component/Tooltip/tooltipEventType.spec.tsx +344 -0
  282. package/test/component/Tooltip/tooltipMouseHoverSelectors.ts +41 -0
  283. package/test/component/Tooltip/tooltipTestHelpers.tsx +162 -0
  284. package/test/component/Tooltip.defaultIndex.spec.tsx +48 -0
  285. package/test/component/Tooltip.hover.spec.tsx +61 -0
  286. package/test/component/Tooltip.item.spec.tsx +54 -0
  287. package/test/component/Tooltip.keyboard.spec.tsx +51 -0
  288. package/test/component/Tooltip.payload.spec.tsx +1716 -0
  289. package/test/component/Tooltip.touch.spec.tsx +39 -0
  290. package/test/component/Tooltip.visibility.spec.tsx +1889 -0
  291. package/test/component/TooltipBoundingBox.spec.tsx +89 -0
  292. package/test/component/responsiveContainerUtils.spec.ts +205 -0
  293. package/test/container/ClipPath.spec.tsx +602 -0
  294. package/test/container/chartDimensions.spec.tsx +368 -0
  295. package/test/context/chartLayoutContext.spec.tsx +378 -0
  296. package/test/helper/ExpectAxisDomain.tsx +27 -0
  297. package/test/helper/assertNotNull.ts +6 -0
  298. package/test/helper/assertZIndexLayerOrder.ts +19 -0
  299. package/test/helper/createSelectorTestCase.tsx +176 -0
  300. package/test/helper/expectAnimatedPieAngles.ts +100 -0
  301. package/test/helper/expectAnimatedPiePaths.ts +78 -0
  302. package/test/helper/expectAreaCurve.ts +15 -0
  303. package/test/helper/expectAxisTicks.ts +48 -0
  304. package/test/helper/expectBars.ts +54 -0
  305. package/test/helper/expectFunctionReturning.ts +58 -0
  306. package/test/helper/expectLabel.ts +32 -0
  307. package/test/helper/expectLastCalledWith.ts +48 -0
  308. package/test/helper/expectLine.ts +20 -0
  309. package/test/helper/expectPieSectors.ts +80 -0
  310. package/test/helper/expectScale.ts +37 -0
  311. package/test/helper/expectScatterPoints.ts +52 -0
  312. package/test/helper/expectStackGroups.ts +144 -0
  313. package/test/helper/mockAxes.ts +22 -0
  314. package/test/helper/mockGetBoundingClientRect.ts +66 -0
  315. package/test/helper/mockHTMLElementProperty.ts +19 -0
  316. package/test/helper/mockTouchingElement.ts +27 -0
  317. package/test/helper/offsetHelpers.ts +19 -0
  318. package/test/helper/parameterizedTestCases.tsx +99 -0
  319. package/test/helper/produceState.ts +32 -0
  320. package/test/helper/selectorTestHelpers.tsx +63 -0
  321. package/test/helper/trim.spec.ts +35 -0
  322. package/test/helper/trim.ts +11 -0
  323. package/test/hooks/useActiveTooltipDataPoints.spec.tsx +358 -0
  324. package/test/hooks/useAxisDomain.spec.tsx +361 -0
  325. package/test/hooks/useAxisScale.spec.tsx +283 -0
  326. package/test/hooks/useAxisTicks.spec.tsx +130 -0
  327. package/test/hooks/useOffset.spec.tsx +248 -0
  328. package/test/hooks/useTooltipStateHooks.spec.tsx +109 -0
  329. package/test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx +135 -0
  330. package/test/polar/Pie/Pie.spec.tsx +784 -0
  331. package/test/polar/Pie/Pie.typed.spec.tsx +78 -0
  332. package/test/polar/Pie.animation.spec.tsx +529 -0
  333. package/test/polar/PieWithLegend.animation.spec.tsx +142 -0
  334. package/test/polar/PolarAngleAxis/PolarAngleAxis.events.spec.tsx +76 -0
  335. package/test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx +2079 -0
  336. package/test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx +102 -0
  337. package/test/polar/PolarAngleAxis.render.spec.tsx +79 -0
  338. package/test/polar/PolarGrid.render.spec.tsx +75 -0
  339. package/test/polar/PolarGrid.spec.tsx +918 -0
  340. package/test/polar/PolarLegendPerRow.render.spec.tsx +85 -0
  341. package/test/polar/PolarRadiusAxis.events.spec.tsx +65 -0
  342. package/test/polar/PolarRadiusAxis.render.spec.tsx +52 -0
  343. package/test/polar/PolarRadiusAxis.spec.tsx +991 -0
  344. package/test/polar/PolarRadiusAxis.typed.spec.tsx +84 -0
  345. package/test/polar/PolarTooltipLegend.render.spec.tsx +80 -0
  346. package/test/polar/Radar.animation.spec.tsx +570 -0
  347. package/test/polar/Radar.render.spec.tsx +71 -0
  348. package/test/polar/Radar.spec.tsx +265 -0
  349. package/test/polar/Radar.typed.spec.tsx +119 -0
  350. package/test/polar/RadialBar/RadialBar.spec.tsx +1521 -0
  351. package/test/polar/RadialBar/RadialBar.typed.spec.tsx +132 -0
  352. package/test/polar/RadialBar.animation.spec.tsx +375 -0
  353. package/test/polar/RadialBar.render.spec.tsx +66 -0
  354. package/test/polar/RadialBar.stacked.spec.tsx +57 -0
  355. package/test/setup.ts +84 -0
  356. package/test/shape/ActiveShape.spec.tsx +181 -0
  357. package/test/shape/Cross.spec.tsx +60 -0
  358. package/test/shape/Cross.typed.spec.tsx +26 -0
  359. package/test/shape/Curve.spec.tsx +368 -0
  360. package/test/shape/Curve.typed.spec.tsx +69 -0
  361. package/test/shape/Dot.spec.tsx +73 -0
  362. package/test/shape/Dot.typed.spec.tsx +30 -0
  363. package/test/shape/Polygon.spec.tsx +357 -0
  364. package/test/shape/Polygon.typed.spec.tsx +28 -0
  365. package/test/shape/Rectangle.animation.spec.tsx +451 -0
  366. package/test/shape/Rectangle.spec.tsx +68 -0
  367. package/test/shape/Rectangle.typed.spec.tsx +24 -0
  368. package/test/shape/Sector.spec.tsx +76 -0
  369. package/test/shape/Sector.typed.spec.tsx +24 -0
  370. package/test/shape/Symbols.spec.tsx +43 -0
  371. package/test/shape/Symbols.typed.spec.tsx +24 -0
  372. package/test/shape/Trapezoid.spec.tsx +50 -0
  373. package/test/shape/Trapezoid.typed.spec.tsx +24 -0
  374. package/test/shape/__snapshots__/Cross.spec.tsx.snap +62 -0
  375. package/test/shape/__snapshots__/Curve.spec.tsx.snap +460 -0
  376. package/test/shape/__snapshots__/Polygon.spec.tsx.snap +58 -0
  377. package/test/shape/__snapshots__/Rectangle.spec.tsx.snap +117 -0
  378. package/test/shape/__snapshots__/Sector.spec.tsx.snap +71 -0
  379. package/test/shape/__snapshots__/Trapezoid.spec.tsx.snap +64 -0
  380. package/test/state/chartDataSlice.spec.ts +53 -0
  381. package/test/state/createCollectionActions.spec.ts +87 -0
  382. package/test/state/createSelector.spec.ts +158 -0
  383. package/test/state/externalEventsMiddleware.spec.ts +178 -0
  384. package/test/state/graphicalItemsSlice.spec.ts +92 -0
  385. package/test/state/hooks.spec.tsx +68 -0
  386. package/test/state/legendSlice.spec.ts +44 -0
  387. package/test/state/mouseEventsMiddleware.spec.ts +75 -0
  388. package/test/state/optionsSlice.spec.ts +19 -0
  389. package/test/state/referenceElementsSlice.spec.ts +84 -0
  390. package/test/state/registerInStore.spec.tsx +101 -0
  391. package/test/state/selectors/areaSelectors.spec.tsx +77 -0
  392. package/test/state/selectors/axisSelectors.spec.tsx +1418 -0
  393. package/test/state/selectors/barStackSelectors.spec.tsx +752 -0
  394. package/test/state/selectors/brushSelectors.spec.tsx +30 -0
  395. package/test/state/selectors/cartesianAxisSlice.spec.ts +96 -0
  396. package/test/state/selectors/combineNiceTicks.spec.ts +207 -0
  397. package/test/state/selectors/combiners/combineActiveTooltipIndex.spec.ts +61 -0
  398. package/test/state/selectors/combiners/combineAllBarPositions.spec.ts +39 -0
  399. package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +56 -0
  400. package/test/state/selectors/combiners/combineDisplayedStackedData.spec.ts +123 -0
  401. package/test/state/selectors/combiners/combineRealScaleType.spec.ts +80 -0
  402. package/test/state/selectors/containerSelectors.spec.tsx +168 -0
  403. package/test/state/selectors/dataSelectors.spec.tsx +136 -0
  404. package/test/state/selectors/legendSelectors.spec.tsx +113 -0
  405. package/test/state/selectors/lineSelectors.spec.tsx +60 -0
  406. package/test/state/selectors/pieSelectors.spec.tsx +72 -0
  407. package/test/state/selectors/radarSelectors.spec.tsx +496 -0
  408. package/test/state/selectors/rootPropsSelectors.spec.tsx +169 -0
  409. package/test/state/selectors/scatterSelectors.spec.tsx +47 -0
  410. package/test/state/selectors/selectActiveTooltipIndex.spec.tsx +234 -0
  411. package/test/state/selectors/selectAllAxes.spec.tsx +18 -0
  412. package/test/state/selectors/selectAxisDomain.spec.tsx +21 -0
  413. package/test/state/selectors/selectAxisDomainIncludingNiceTicks.spec.tsx +19 -0
  414. package/test/state/selectors/selectAxisRangeWithReverse.spec.tsx +22 -0
  415. package/test/state/selectors/selectAxisScale.spec.tsx +91 -0
  416. package/test/state/selectors/selectBarRectangles.stackOffset.spec.tsx +503 -0
  417. package/test/state/selectors/selectBaseAxis.spec.tsx +56 -0
  418. package/test/state/selectors/selectCartesianItemsSettings.spec.tsx +57 -0
  419. package/test/state/selectors/selectChartOffset.spec.tsx +26 -0
  420. package/test/state/selectors/selectDisplayedData.spec.tsx +282 -0
  421. package/test/state/selectors/selectIsTooltipActive.spec.tsx +231 -0
  422. package/test/state/selectors/selectNumericalDomain.spec.tsx +21 -0
  423. package/test/state/selectors/selectRealScaleType.spec.tsx +19 -0
  424. package/test/state/selectors/selectStackGroups.spec.tsx +322 -0
  425. package/test/state/selectors/selectXAxisPosition.spec.tsx +22 -0
  426. package/test/state/selectors/selectYAxisPosition.spec.tsx +22 -0
  427. package/test/state/selectors/selectorMemoization.spec.tsx +136 -0
  428. package/test/state/selectors/selectors.spec.tsx +1613 -0
  429. package/test/state/throttling.spec.ts +200 -0
  430. package/test/state/zIndexSlice.spec.ts +85 -0
  431. package/test/synchronisation/useChartSynchronisation.spec.tsx +225 -0
  432. package/test/util/BarUtils.spec.ts +39 -0
  433. package/test/util/CartesianUtils/CartesianUtils.spec.ts +261 -0
  434. package/test/util/CartesianUtils/rectWithPoints.spec.ts +48 -0
  435. package/test/util/ChartUtils/ChartUtils.spec.ts +491 -0
  436. package/test/util/ChartUtils/appendOffsetOfLegend.spec.ts +136 -0
  437. package/test/util/ChartUtils/appendOffsetOfLegend.spec.tsx +133 -0
  438. package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +97 -0
  439. package/test/util/ChartUtils/getStackedData.spec.ts +416 -0
  440. package/test/util/ChartUtils/truncateByDomain.spec.ts +70 -0
  441. package/test/util/DataUtils.spec.ts +385 -0
  442. package/test/util/DomUtils.spec.tsx +117 -0
  443. package/test/util/FunnelUtils.spec.tsx +70 -0
  444. package/test/util/Global.spec.ts +11 -0
  445. package/test/util/LRUCache.spec.ts +81 -0
  446. package/test/util/LogUtils.spec.ts +45 -0
  447. package/test/util/PolarUtils.spec.ts +66 -0
  448. package/test/util/ReduceCssCalcPrototype.spec.ts +141 -0
  449. package/test/util/ShallowEqual.spec.ts +102 -0
  450. package/test/util/TickUtils.spec.ts +29 -0
  451. package/test/util/createChartHelpers.spec.tsx +210 -0
  452. package/test/util/cursor/getCursorPoints.spec.ts +136 -0
  453. package/test/util/cursor/getCursorRectangle.spec.ts +50 -0
  454. package/test/util/cursor/getRadialCursorPoints.spec.ts +36 -0
  455. package/test/util/errorValue.spec.ts +69 -0
  456. package/test/util/getEveryNth.spec.ts +39 -0
  457. package/test/util/getRadiusAndStrokeWidthFromDot.spec.ts +51 -0
  458. package/test/util/getRelativeCoordinate.spec.ts +250 -0
  459. package/test/util/getSliced.spec.ts +45 -0
  460. package/test/util/isDomainSpecifiedByUser.spec.ts +207 -0
  461. package/test/util/isWellBehavedNumber.spec.ts +54 -0
  462. package/test/util/payload/getUniqPayload.spec.ts +56 -0
  463. package/test/util/propsAreEqual.spec.ts +75 -0
  464. package/test/util/round.spec.ts +112 -0
  465. package/test/util/scale/arithmetic.spec.ts +61 -0
  466. package/test/util/scale/createCategoricalInverse.spec.ts +84 -0
  467. package/test/util/scale/getNiceTickValues.spec.ts +421 -0
  468. package/test/util/scale/getTickValuesFixedDomain.spec.ts +155 -0
  469. package/test/util/svgPropertiesAndEvents.spec.tsx +206 -0
  470. package/test/util/svgPropertiesNoEvents.spec.tsx +228 -0
  471. package/test/util/tooltip/translate.spec.ts +396 -0
  472. package/test/util/useAnimationId.spec.tsx +59 -0
  473. package/test/util/useElementOffset.spec.tsx +173 -0
  474. package/test/util/usePrefersReducedMotion.spec.ts +54 -0
  475. package/test/util/useUniqueId.spec.ts +99 -0
  476. package/test/utils/diagnostics-allowlist.ts +18 -0
  477. package/test/utils/diagnostics.ts +58 -0
  478. package/test/zIndex/AllZIndexPortals.spec.tsx +83 -0
  479. package/test/zIndex/DefaultZIndexes.spec.ts +80 -0
  480. package/test/zIndex/DynamicZIndex.spec.tsx +102 -0
  481. package/test/zIndex/ZIndexLayer.portalOwner.spec.tsx +125 -0
  482. package/test/zIndex/componentZIndex.spec.tsx +255 -0
  483. package/test/zIndex/getZIndexFromUnknown.spec.ts +51 -0
  484. package/test/zIndex/multiChartZIndexIsolation.spec.tsx +90 -0
  485. package/test/zIndex/zIndexSelectors.spec.ts +172 -0
  486. package/test-results/.last-run.json +4 -0
  487. package/tsconfig.json +11 -0
  488. package/src/util/DirectPortal.tsx +0 -107
@@ -0,0 +1,2815 @@
1
+ /*
2
+ * Ported from recharts 3.8.1 test/component/Tooltip/itemSorter.spec.tsx (commit 7a23854).
3
+ * Solid adaptations: createSelectorTestCase wrapper uses (props) => {props.children};
4
+ * showTooltip + flush via tooltipTestHelpers; selectors from tooltipSelectors.
5
+ */
6
+ import { describe, expect, it, vi } from "vitest";
7
+ import {
8
+ Area,
9
+ AreaChart,
10
+ Bar,
11
+ BarChart,
12
+ ComposedChart,
13
+ Line,
14
+ Pie,
15
+ PieChart,
16
+ PolarAngleAxis,
17
+ PolarRadiusAxis,
18
+ Radar,
19
+ RadarChart,
20
+ RadialBar,
21
+ RadialBarChart,
22
+ Scatter,
23
+ Tooltip,
24
+ TooltipItemSorter,
25
+ XAxis,
26
+ YAxis,
27
+ } from "../../../src";
28
+ import { PageData } from "../../_data";
29
+ import { createSelectorTestCase } from "../../helper/createSelectorTestCase";
30
+ import type { RechartsRootState } from "../../../src/state/store";
31
+ import { expectTooltipPayload, showTooltip } from "./tooltipTestHelpers";
32
+ import {
33
+ barChartMouseHoverTooltipSelector,
34
+ composedChartMouseHoverTooltipSelector,
35
+ pieChartMouseHoverTooltipSelector,
36
+ radarChartMouseHoverTooltipSelector,
37
+ radialBarChartMouseHoverTooltipSelector,
38
+ } from "./tooltipMouseHoverSelectors";
39
+ import {
40
+ selectTooltipPayload,
41
+ selectTooltipPayloadConfigurations,
42
+ } from "../../../src/state/selectors/tooltipSelectors";
43
+ import { mockGetBoundingClientRect } from "../../helper/mockGetBoundingClientRect";
44
+ import { expectLastCalledWith } from "../../helper/expectLastCalledWith";
45
+ import { noop } from "../../../src/util/DataUtils";
46
+
47
+ describe("itemSorter in ComposedChart", () => {
48
+ beforeEach(() => {
49
+ mockGetBoundingClientRect({ width: 100, height: 100 });
50
+ });
51
+
52
+ describe("without name prop", () => {
53
+ function renderTestCase<T>(
54
+ itemSorter: TooltipItemSorter | undefined,
55
+ selector?: (state: RechartsRootState) => T,
56
+ ) {
57
+ return createSelectorTestCase((props) => (
58
+ <ComposedChart width={300} height={300} data={PageData}>
59
+ <Area dataKey="uv" name="area" id="area-uv" />
60
+ <Bar dataKey="pv" name="bar" id="bar-pv" />
61
+ <Line dataKey="amt" name="line" id="line-amt" />
62
+ {/* name prop on Scatter doesn't do anything, not sure why */}
63
+ <Scatter dataKey="uv" name="scatter" id="scatter-uv" />
64
+ <YAxis dataKey="pv" />
65
+ <XAxis dataKey="name" />
66
+ <Tooltip itemSorter={itemSorter} />
67
+ {props.children}
68
+ </ComposedChart>
69
+ ))(selector);
70
+ }
71
+
72
+ describe("when itemSorter is undefined", () => {
73
+ it("should render payload sorted by name", () => {
74
+ const { container } = renderTestCase(undefined);
75
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
76
+ expectTooltipPayload(container, "Page D", [
77
+ "area : 200",
78
+ "bar : 9800",
79
+ "line : 2400",
80
+ "name : Page D",
81
+ "pv : 9800",
82
+ ]);
83
+ });
84
+
85
+ it("should select tooltipPayloadConfigurations", () => {
86
+ const { spy } = renderTestCase(undefined, (state) =>
87
+ selectTooltipPayloadConfigurations(state, "axis", "hover", "0"),
88
+ );
89
+ expectLastCalledWith(spy, [
90
+ {
91
+ dataDefinedOnItem: undefined,
92
+ getPosition: noop,
93
+ settings: {
94
+ color: "#3182bd",
95
+ dataKey: "uv",
96
+ fill: "#3182bd",
97
+ hide: false,
98
+ name: "area",
99
+ nameKey: undefined,
100
+ stroke: "#3182bd",
101
+ strokeWidth: 1,
102
+ type: undefined,
103
+ unit: undefined,
104
+ graphicalItemId: "area-uv",
105
+ },
106
+ },
107
+ {
108
+ dataDefinedOnItem: undefined,
109
+ getPosition: noop,
110
+ settings: {
111
+ color: undefined,
112
+ dataKey: "pv",
113
+ fill: undefined,
114
+ hide: false,
115
+ name: "bar",
116
+ nameKey: undefined,
117
+ stroke: undefined,
118
+ strokeWidth: undefined,
119
+ type: undefined,
120
+ unit: undefined,
121
+ graphicalItemId: "bar-pv",
122
+ },
123
+ },
124
+ {
125
+ dataDefinedOnItem: undefined,
126
+ getPosition: noop,
127
+ settings: {
128
+ color: "#3182bd",
129
+ dataKey: "amt",
130
+ fill: "#fff",
131
+ hide: false,
132
+ name: "line",
133
+ nameKey: undefined,
134
+ stroke: "#3182bd",
135
+ strokeWidth: 1,
136
+ type: undefined,
137
+ unit: undefined,
138
+ graphicalItemId: "line-amt",
139
+ },
140
+ },
141
+ {
142
+ dataDefinedOnItem: [
143
+ [
144
+ {
145
+ dataKey: "name",
146
+ name: "name",
147
+ payload: {
148
+ amt: 2400,
149
+ name: "Page A",
150
+ pv: 2400,
151
+ uv: 400,
152
+ },
153
+ type: undefined,
154
+ unit: "",
155
+ value: "Page A",
156
+ graphicalItemId: "scatter-uv",
157
+ },
158
+ {
159
+ dataKey: "pv",
160
+ name: "pv",
161
+ payload: {
162
+ amt: 2400,
163
+ name: "Page A",
164
+ pv: 2400,
165
+ uv: 400,
166
+ },
167
+ type: undefined,
168
+ unit: "",
169
+ value: 2400,
170
+ graphicalItemId: "scatter-uv",
171
+ },
172
+ ],
173
+ [
174
+ {
175
+ dataKey: "name",
176
+ name: "name",
177
+ payload: {
178
+ amt: 2400,
179
+ name: "Page B",
180
+ pv: 4567,
181
+ uv: 300,
182
+ },
183
+ type: undefined,
184
+ unit: "",
185
+ value: "Page B",
186
+ graphicalItemId: "scatter-uv",
187
+ },
188
+ {
189
+ dataKey: "pv",
190
+ name: "pv",
191
+ payload: {
192
+ amt: 2400,
193
+ name: "Page B",
194
+ pv: 4567,
195
+ uv: 300,
196
+ },
197
+ type: undefined,
198
+ unit: "",
199
+ value: 4567,
200
+ graphicalItemId: "scatter-uv",
201
+ },
202
+ ],
203
+ [
204
+ {
205
+ dataKey: "name",
206
+ name: "name",
207
+ payload: {
208
+ amt: 2400,
209
+ name: "Page C",
210
+ pv: 1398,
211
+ uv: 300,
212
+ },
213
+ type: undefined,
214
+ unit: "",
215
+ value: "Page C",
216
+ graphicalItemId: "scatter-uv",
217
+ },
218
+ {
219
+ dataKey: "pv",
220
+ name: "pv",
221
+ payload: {
222
+ amt: 2400,
223
+ name: "Page C",
224
+ pv: 1398,
225
+ uv: 300,
226
+ },
227
+ type: undefined,
228
+ unit: "",
229
+ value: 1398,
230
+ graphicalItemId: "scatter-uv",
231
+ },
232
+ ],
233
+ [
234
+ {
235
+ dataKey: "name",
236
+ name: "name",
237
+ payload: {
238
+ amt: 2400,
239
+ name: "Page D",
240
+ pv: 9800,
241
+ uv: 200,
242
+ },
243
+ type: undefined,
244
+ unit: "",
245
+ value: "Page D",
246
+ graphicalItemId: "scatter-uv",
247
+ },
248
+ {
249
+ dataKey: "pv",
250
+ name: "pv",
251
+ payload: {
252
+ amt: 2400,
253
+ name: "Page D",
254
+ pv: 9800,
255
+ uv: 200,
256
+ },
257
+ type: undefined,
258
+ unit: "",
259
+ value: 9800,
260
+ graphicalItemId: "scatter-uv",
261
+ },
262
+ ],
263
+ [
264
+ {
265
+ dataKey: "name",
266
+ name: "name",
267
+ payload: {
268
+ amt: 2400,
269
+ name: "Page E",
270
+ pv: 3908,
271
+ uv: 278,
272
+ },
273
+ type: undefined,
274
+ unit: "",
275
+ value: "Page E",
276
+ graphicalItemId: "scatter-uv",
277
+ },
278
+ {
279
+ dataKey: "pv",
280
+ name: "pv",
281
+ payload: {
282
+ amt: 2400,
283
+ name: "Page E",
284
+ pv: 3908,
285
+ uv: 278,
286
+ },
287
+ type: undefined,
288
+ unit: "",
289
+ value: 3908,
290
+ graphicalItemId: "scatter-uv",
291
+ },
292
+ ],
293
+ [
294
+ {
295
+ dataKey: "name",
296
+ name: "name",
297
+ payload: {
298
+ amt: 2400,
299
+ name: "Page F",
300
+ pv: 4800,
301
+ uv: 189,
302
+ },
303
+ type: undefined,
304
+ unit: "",
305
+ value: "Page F",
306
+ graphicalItemId: "scatter-uv",
307
+ },
308
+ {
309
+ dataKey: "pv",
310
+ name: "pv",
311
+ payload: {
312
+ amt: 2400,
313
+ name: "Page F",
314
+ pv: 4800,
315
+ uv: 189,
316
+ },
317
+ type: undefined,
318
+ unit: "",
319
+ value: 4800,
320
+ graphicalItemId: "scatter-uv",
321
+ },
322
+ ],
323
+ ],
324
+ getPosition: expect.functionReturning([
325
+ ["0", { x: 84.16666666666667, y: 202.6 }],
326
+ ["1", { x: 122.50000000000001, y: 146.258 }],
327
+ ["2", { x: 160.83333333333334, y: 228.65200000000002 }],
328
+ ["3", { x: 199.16666666666666, y: 10.200000000000005 }],
329
+ ["4", { x: 237.5, y: 163.392 }],
330
+ ["5", { x: 275.83333333333337, y: 140.20000000000002 }],
331
+ ]),
332
+ settings: {
333
+ color: undefined,
334
+ dataKey: "uv",
335
+ fill: undefined,
336
+ hide: false,
337
+ name: "scatter",
338
+ nameKey: undefined,
339
+ stroke: undefined,
340
+ type: undefined,
341
+ unit: "",
342
+ graphicalItemId: "scatter-uv",
343
+ },
344
+ },
345
+ ]);
346
+ });
347
+
348
+ it("should select payload sorted by name", () => {
349
+ const { spy } = renderTestCase(undefined, (state) =>
350
+ selectTooltipPayload(state, "axis", "hover", "0"),
351
+ );
352
+ expectLastCalledWith(spy, [
353
+ {
354
+ color: "#3182bd",
355
+ dataKey: "uv",
356
+ fill: "#3182bd",
357
+ hide: false,
358
+ name: "area",
359
+ nameKey: undefined,
360
+ payload: {
361
+ amt: 2400,
362
+ name: "Page A",
363
+ pv: 2400,
364
+ uv: 400,
365
+ },
366
+ stroke: "#3182bd",
367
+ strokeWidth: 1,
368
+ type: undefined,
369
+ unit: undefined,
370
+ value: 400,
371
+ graphicalItemId: "area-uv",
372
+ },
373
+ {
374
+ color: undefined,
375
+ dataKey: "pv",
376
+ fill: undefined,
377
+ hide: false,
378
+ name: "bar",
379
+ nameKey: undefined,
380
+ payload: {
381
+ amt: 2400,
382
+ name: "Page A",
383
+ pv: 2400,
384
+ uv: 400,
385
+ },
386
+ stroke: undefined,
387
+ strokeWidth: undefined,
388
+ type: undefined,
389
+ unit: undefined,
390
+ value: 2400,
391
+ graphicalItemId: "bar-pv",
392
+ },
393
+ {
394
+ color: "#3182bd",
395
+ dataKey: "amt",
396
+ fill: "#fff",
397
+ hide: false,
398
+ name: "line",
399
+ nameKey: undefined,
400
+ payload: {
401
+ amt: 2400,
402
+ name: "Page A",
403
+ pv: 2400,
404
+ uv: 400,
405
+ },
406
+ stroke: "#3182bd",
407
+ strokeWidth: 1,
408
+ type: undefined,
409
+ unit: undefined,
410
+ value: 2400,
411
+ graphicalItemId: "line-amt",
412
+ },
413
+ {
414
+ color: undefined,
415
+ dataKey: "name",
416
+ fill: undefined,
417
+ hide: false,
418
+ name: "name",
419
+ nameKey: undefined,
420
+ payload: {
421
+ amt: 2400,
422
+ name: "Page A",
423
+ pv: 2400,
424
+ uv: 400,
425
+ },
426
+ stroke: undefined,
427
+ type: undefined,
428
+ unit: "",
429
+ value: "Page A",
430
+ graphicalItemId: "scatter-uv",
431
+ },
432
+ {
433
+ color: undefined,
434
+ dataKey: "pv",
435
+ fill: undefined,
436
+ hide: false,
437
+ name: "pv",
438
+ nameKey: undefined,
439
+ payload: {
440
+ amt: 2400,
441
+ name: "Page A",
442
+ pv: 2400,
443
+ uv: 400,
444
+ },
445
+ stroke: undefined,
446
+ type: undefined,
447
+ unit: "",
448
+ value: 2400,
449
+ graphicalItemId: "scatter-uv",
450
+ },
451
+ ]);
452
+ expect(spy).toHaveBeenCalledTimes(3);
453
+ });
454
+ });
455
+
456
+ describe("when itemSorter=`dataKey`", () => {
457
+ it("should render sorted payload", () => {
458
+ const { container } = renderTestCase("dataKey");
459
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
460
+ expectTooltipPayload(container, "Page D", [
461
+ "line : 2400",
462
+ "name : Page D",
463
+ "bar : 9800",
464
+ "pv : 9800",
465
+ "area : 200",
466
+ ]);
467
+ });
468
+ });
469
+
470
+ describe("when itemSorter=`value`", () => {
471
+ it("should render sorted payload", () => {
472
+ const { container } = renderTestCase("value");
473
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
474
+ expectTooltipPayload(container, "Page D", [
475
+ "area : 200",
476
+ "line : 2400",
477
+ "bar : 9800",
478
+ "name : Page D",
479
+ "pv : 9800",
480
+ ]);
481
+ });
482
+ });
483
+
484
+ describe("when itemSorter=`name`", () => {
485
+ it("should render sorted payload", () => {
486
+ const { container } = renderTestCase("name");
487
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
488
+ expectTooltipPayload(container, "Page D", [
489
+ "area : 200",
490
+ "bar : 9800",
491
+ "line : 2400",
492
+ "name : Page D",
493
+ "pv : 9800",
494
+ ]);
495
+ });
496
+ });
497
+
498
+ describe("when itemSorter is a function", () => {
499
+ it("should render sorted payload", () => {
500
+ const { container } = renderTestCase((item) => String(item.value));
501
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
502
+ expectTooltipPayload(container, "Page D", [
503
+ "area : 200",
504
+ "line : 2400",
505
+ "bar : 9800",
506
+ "pv : 9800",
507
+ "name : Page D",
508
+ ]);
509
+ });
510
+
511
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
512
+ const spy = vi.fn();
513
+ const { container } = renderTestCase(spy);
514
+ expect(spy).toHaveBeenCalledTimes(0);
515
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
516
+ expect(spy).toHaveBeenCalledTimes(5);
517
+ expect(spy).toHaveBeenNthCalledWith(1, {
518
+ color: "#3182bd",
519
+ dataKey: "uv",
520
+ fill: "#3182bd",
521
+ graphicalItemId: "area-uv",
522
+ hide: false,
523
+ name: "area",
524
+ nameKey: undefined,
525
+ payload: {
526
+ amt: 2400,
527
+ name: "Page D",
528
+ pv: 9800,
529
+ uv: 200,
530
+ },
531
+ stroke: "#3182bd",
532
+ strokeWidth: 1,
533
+ type: undefined,
534
+ unit: undefined,
535
+ value: 200,
536
+ });
537
+ expect(spy).toHaveBeenNthCalledWith(2, {
538
+ color: undefined,
539
+ dataKey: "pv",
540
+ fill: undefined,
541
+ graphicalItemId: "bar-pv",
542
+ hide: false,
543
+ name: "bar",
544
+ nameKey: undefined,
545
+ payload: {
546
+ amt: 2400,
547
+ name: "Page D",
548
+ pv: 9800,
549
+ uv: 200,
550
+ },
551
+ stroke: undefined,
552
+ strokeWidth: undefined,
553
+ type: undefined,
554
+ unit: undefined,
555
+ value: 9800,
556
+ });
557
+ expect(spy).toHaveBeenNthCalledWith(3, {
558
+ color: "#3182bd",
559
+ dataKey: "amt",
560
+ fill: "#fff",
561
+ graphicalItemId: "line-amt",
562
+ hide: false,
563
+ name: "line",
564
+ nameKey: undefined,
565
+ payload: {
566
+ amt: 2400,
567
+ name: "Page D",
568
+ pv: 9800,
569
+ uv: 200,
570
+ },
571
+ stroke: "#3182bd",
572
+ strokeWidth: 1,
573
+ type: undefined,
574
+ unit: undefined,
575
+ value: 2400,
576
+ });
577
+ expect(spy).toHaveBeenNthCalledWith(4, {
578
+ color: undefined,
579
+ dataKey: "name",
580
+ fill: undefined,
581
+ graphicalItemId: "scatter-uv",
582
+ hide: false,
583
+ name: "name",
584
+ nameKey: undefined,
585
+ payload: {
586
+ amt: 2400,
587
+ name: "Page D",
588
+ pv: 9800,
589
+ uv: 200,
590
+ },
591
+ stroke: undefined,
592
+ type: undefined,
593
+ unit: "",
594
+ value: "Page D",
595
+ });
596
+ expect(spy).toHaveBeenNthCalledWith(5, {
597
+ color: undefined,
598
+ dataKey: "pv",
599
+ fill: undefined,
600
+ graphicalItemId: "scatter-uv",
601
+ hide: false,
602
+ name: "pv",
603
+ nameKey: undefined,
604
+ payload: {
605
+ amt: 2400,
606
+ name: "Page D",
607
+ pv: 9800,
608
+ uv: 200,
609
+ },
610
+ stroke: undefined,
611
+ type: undefined,
612
+ unit: "",
613
+ value: 9800,
614
+ });
615
+ });
616
+ });
617
+ });
618
+
619
+ describe("with name prop", () => {
620
+ function renderTestCase<T>(
621
+ itemSorter: TooltipItemSorter | undefined,
622
+ selector?: (state: RechartsRootState) => T,
623
+ ) {
624
+ return createSelectorTestCase((props) => (
625
+ <ComposedChart width={300} height={300} data={PageData}>
626
+ <Line dataKey="amt" name="Line" id="line-amt" />
627
+ <Area dataKey="uv" name="Area" id="area-uv" />
628
+ <Bar dataKey="pv" name="Bar" id="bar-pv" />
629
+ <Scatter dataKey="uv" name="Scatter" id="scatter-uv" />
630
+ <YAxis dataKey="pv" name="YAxis" />
631
+ <XAxis dataKey="name" name="XAxis" />
632
+ <Tooltip itemSorter={itemSorter} />
633
+ {props.children}
634
+ </ComposedChart>
635
+ ))(selector);
636
+ }
637
+
638
+ describe("when itemSorter is undefined", () => {
639
+ it("should render payload sorted by name", () => {
640
+ const { container } = renderTestCase(undefined);
641
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
642
+ expectTooltipPayload(container, "Page D", [
643
+ "Area : 200",
644
+ "Bar : 9800",
645
+ "Line : 2400",
646
+ "XAxis : Page D",
647
+ "YAxis : 9800",
648
+ ]);
649
+ });
650
+
651
+ it("should select payload sorted by name", () => {
652
+ const { spy } = renderTestCase(undefined, (state) =>
653
+ selectTooltipPayload(state, "axis", "hover", "0"),
654
+ );
655
+ expectLastCalledWith(spy, [
656
+ {
657
+ color: "#3182bd",
658
+ dataKey: "amt",
659
+ fill: "#fff",
660
+ graphicalItemId: "line-amt",
661
+ hide: false,
662
+ name: "Line",
663
+ nameKey: undefined,
664
+ payload: {
665
+ amt: 2400,
666
+ name: "Page A",
667
+ pv: 2400,
668
+ uv: 400,
669
+ },
670
+ stroke: "#3182bd",
671
+ strokeWidth: 1,
672
+ type: undefined,
673
+ unit: undefined,
674
+ value: 2400,
675
+ },
676
+ {
677
+ color: "#3182bd",
678
+ dataKey: "uv",
679
+ fill: "#3182bd",
680
+ graphicalItemId: "area-uv",
681
+ hide: false,
682
+ name: "Area",
683
+ nameKey: undefined,
684
+ payload: {
685
+ amt: 2400,
686
+ name: "Page A",
687
+ pv: 2400,
688
+ uv: 400,
689
+ },
690
+ stroke: "#3182bd",
691
+ strokeWidth: 1,
692
+ type: undefined,
693
+ unit: undefined,
694
+ value: 400,
695
+ },
696
+ {
697
+ color: undefined,
698
+ dataKey: "pv",
699
+ fill: undefined,
700
+ graphicalItemId: "bar-pv",
701
+ hide: false,
702
+ name: "Bar",
703
+ nameKey: undefined,
704
+ payload: {
705
+ amt: 2400,
706
+ name: "Page A",
707
+ pv: 2400,
708
+ uv: 400,
709
+ },
710
+ stroke: undefined,
711
+ strokeWidth: undefined,
712
+ type: undefined,
713
+ unit: undefined,
714
+ value: 2400,
715
+ },
716
+ {
717
+ color: undefined,
718
+ dataKey: "name",
719
+ fill: undefined,
720
+ graphicalItemId: "scatter-uv",
721
+ hide: false,
722
+ name: "XAxis",
723
+ nameKey: undefined,
724
+ payload: {
725
+ amt: 2400,
726
+ name: "Page A",
727
+ pv: 2400,
728
+ uv: 400,
729
+ },
730
+ stroke: undefined,
731
+ type: undefined,
732
+ unit: "",
733
+ value: "Page A",
734
+ },
735
+ {
736
+ color: undefined,
737
+ dataKey: "pv",
738
+ fill: undefined,
739
+ graphicalItemId: "scatter-uv",
740
+ hide: false,
741
+ name: "YAxis",
742
+ nameKey: undefined,
743
+ payload: {
744
+ amt: 2400,
745
+ name: "Page A",
746
+ pv: 2400,
747
+ uv: 400,
748
+ },
749
+ stroke: undefined,
750
+ type: undefined,
751
+ unit: "",
752
+ value: 2400,
753
+ },
754
+ ]);
755
+ expect(spy).toHaveBeenCalledTimes(3);
756
+ });
757
+ });
758
+
759
+ describe("when itemSorter=`dataKey`", () => {
760
+ it("should render sorted payload", () => {
761
+ const { container } = renderTestCase("dataKey");
762
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
763
+ expectTooltipPayload(container, "Page D", [
764
+ "Line : 2400",
765
+ "XAxis : Page D",
766
+ "Bar : 9800",
767
+ "YAxis : 9800",
768
+ "Area : 200",
769
+ ]);
770
+ });
771
+ });
772
+
773
+ describe("when itemSorter=`value`", () => {
774
+ it("should render sorted payload", () => {
775
+ const { container } = renderTestCase("value");
776
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
777
+ expectTooltipPayload(container, "Page D", [
778
+ "Area : 200",
779
+ "Line : 2400",
780
+ "Bar : 9800",
781
+ "XAxis : Page D",
782
+ "YAxis : 9800",
783
+ ]);
784
+ });
785
+ });
786
+
787
+ describe("when itemSorter=`name`", () => {
788
+ it("should render sorted payload", () => {
789
+ const { container } = renderTestCase("name");
790
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
791
+ expectTooltipPayload(container, "Page D", [
792
+ "Area : 200",
793
+ "Bar : 9800",
794
+ "Line : 2400",
795
+ "XAxis : Page D",
796
+ "YAxis : 9800",
797
+ ]);
798
+ });
799
+ });
800
+
801
+ describe("when itemSorter is a function", () => {
802
+ it("should render sorted payload", () => {
803
+ const { container } = renderTestCase((item) => String(item.value));
804
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
805
+ expectTooltipPayload(container, "Page D", [
806
+ "Area : 200",
807
+ "Line : 2400",
808
+ "Bar : 9800",
809
+ "YAxis : 9800",
810
+ "XAxis : Page D",
811
+ ]);
812
+ });
813
+
814
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
815
+ const spy = vi.fn();
816
+ const { container } = renderTestCase(spy);
817
+ expect(spy).toHaveBeenCalledTimes(0);
818
+ showTooltip(container, composedChartMouseHoverTooltipSelector);
819
+ expect(spy).toHaveBeenCalledTimes(5);
820
+ expect(spy).toHaveBeenNthCalledWith(1, {
821
+ color: "#3182bd",
822
+ dataKey: "amt",
823
+ fill: "#fff",
824
+ graphicalItemId: "line-amt",
825
+ hide: false,
826
+ name: "Line",
827
+ nameKey: undefined,
828
+ payload: {
829
+ amt: 2400,
830
+ name: "Page D",
831
+ pv: 9800,
832
+ uv: 200,
833
+ },
834
+ stroke: "#3182bd",
835
+ strokeWidth: 1,
836
+ type: undefined,
837
+ unit: undefined,
838
+ value: 2400,
839
+ });
840
+ expect(spy).toHaveBeenNthCalledWith(2, {
841
+ color: "#3182bd",
842
+ dataKey: "uv",
843
+ fill: "#3182bd",
844
+ graphicalItemId: "area-uv",
845
+ hide: false,
846
+ name: "Area",
847
+ nameKey: undefined,
848
+ payload: {
849
+ amt: 2400,
850
+ name: "Page D",
851
+ pv: 9800,
852
+ uv: 200,
853
+ },
854
+ stroke: "#3182bd",
855
+ strokeWidth: 1,
856
+ type: undefined,
857
+ unit: undefined,
858
+ value: 200,
859
+ });
860
+ expect(spy).toHaveBeenNthCalledWith(3, {
861
+ color: undefined,
862
+ dataKey: "pv",
863
+ fill: undefined,
864
+ graphicalItemId: "bar-pv",
865
+ hide: false,
866
+ name: "Bar",
867
+ nameKey: undefined,
868
+ payload: {
869
+ amt: 2400,
870
+ name: "Page D",
871
+ pv: 9800,
872
+ uv: 200,
873
+ },
874
+ stroke: undefined,
875
+ strokeWidth: undefined,
876
+ type: undefined,
877
+ unit: undefined,
878
+ value: 9800,
879
+ });
880
+ expect(spy).toHaveBeenNthCalledWith(4, {
881
+ color: undefined,
882
+ dataKey: "name",
883
+ fill: undefined,
884
+ graphicalItemId: "scatter-uv",
885
+ hide: false,
886
+ name: "XAxis",
887
+ nameKey: undefined,
888
+ payload: {
889
+ amt: 2400,
890
+ name: "Page D",
891
+ pv: 9800,
892
+ uv: 200,
893
+ },
894
+ stroke: undefined,
895
+ type: undefined,
896
+ unit: "",
897
+ value: "Page D",
898
+ });
899
+ expect(spy).toHaveBeenNthCalledWith(5, {
900
+ color: undefined,
901
+ dataKey: "pv",
902
+ fill: undefined,
903
+ graphicalItemId: "scatter-uv",
904
+ hide: false,
905
+ name: "YAxis",
906
+ nameKey: undefined,
907
+ payload: {
908
+ amt: 2400,
909
+ name: "Page D",
910
+ pv: 9800,
911
+ uv: 200,
912
+ },
913
+ stroke: undefined,
914
+ type: undefined,
915
+ unit: "",
916
+ value: 9800,
917
+ });
918
+ });
919
+ });
920
+ });
921
+ });
922
+
923
+ describe("itemSorter in PieChart", () => {
924
+ beforeEach(() => {
925
+ mockGetBoundingClientRect({ width: 100, height: 100 });
926
+ });
927
+
928
+ function renderTestCase<T>(
929
+ itemSorter: TooltipItemSorter | undefined,
930
+ selector?: (state: RechartsRootState) => T,
931
+ ) {
932
+ return createSelectorTestCase((props) => (
933
+ <PieChart width={300} height={300}>
934
+ <Pie data={PageData} dataKey="uv" isAnimationActive={false} id="pie-uv" />
935
+ <Tooltip itemSorter={itemSorter} />
936
+ {props.children}
937
+ </PieChart>
938
+ ))(selector);
939
+ }
940
+
941
+ describe("when itemSorter is undefined", () => {
942
+ it("should render only one item in the Tooltip so there is nothing to sort", () => {
943
+ const { container } = renderTestCase(undefined);
944
+ showTooltip(container, pieChartMouseHoverTooltipSelector);
945
+ expectTooltipPayload(container, "", ["Page A : 400"]);
946
+ });
947
+
948
+ it("should select payload with only one item so there is nothing to sort", () => {
949
+ const { spy } = renderTestCase(undefined, (state) =>
950
+ selectTooltipPayload(state, "item", "hover", "0"),
951
+ );
952
+ expectLastCalledWith(spy, [
953
+ {
954
+ color: "#808080",
955
+ dataKey: "uv",
956
+ fill: "#808080",
957
+ graphicalItemId: "pie-uv",
958
+ hide: false,
959
+ name: "Page A",
960
+ nameKey: "name",
961
+ payload: {
962
+ amt: 2400,
963
+ name: "Page A",
964
+ pv: 2400,
965
+ uv: 400,
966
+ },
967
+ stroke: "#fff",
968
+ strokeWidth: undefined,
969
+ type: undefined,
970
+ unit: undefined,
971
+ value: 400,
972
+ },
973
+ ]);
974
+ });
975
+ });
976
+ });
977
+
978
+ describe("itemSorter in RadarChart", () => {
979
+ beforeEach(() => {
980
+ mockGetBoundingClientRect({ width: 100, height: 100 });
981
+ });
982
+
983
+ describe("without name prop", () => {
984
+ function renderTestCase<T>(
985
+ itemSorter: TooltipItemSorter | undefined,
986
+ selector?: (state: RechartsRootState) => T,
987
+ ) {
988
+ return createSelectorTestCase((props) => (
989
+ <RadarChart width={600} height={600} data={PageData}>
990
+ <Radar dataKey="uv" isAnimationActive={false} id="radar-uv" />
991
+ <Radar dataKey="pv" isAnimationActive={false} id="radar-pv" />
992
+ <Radar dataKey="amt" isAnimationActive={false} id="radar-amt" />
993
+ <PolarAngleAxis dataKey="name" />
994
+ <PolarRadiusAxis dataKey="uv" />
995
+ <Tooltip itemSorter={itemSorter} />
996
+ {props.children}
997
+ </RadarChart>
998
+ ))(selector);
999
+ }
1000
+
1001
+ describe("when itemSorter is undefined", () => {
1002
+ it("should render payload sorted by name", () => {
1003
+ const { container } = renderTestCase(undefined);
1004
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1005
+ expectTooltipPayload(container, "Page F", ["amt : 2400", "pv : 4800", "uv : 189"]);
1006
+ });
1007
+
1008
+ it("should select payload sorted by name", () => {
1009
+ const { spy } = renderTestCase(undefined, (state) =>
1010
+ selectTooltipPayload(state, "axis", "hover", "0"),
1011
+ );
1012
+ expectLastCalledWith(spy, [
1013
+ {
1014
+ color: undefined,
1015
+ dataKey: "uv",
1016
+ fill: undefined,
1017
+ graphicalItemId: "radar-uv",
1018
+ hide: false,
1019
+ name: "uv",
1020
+ nameKey: undefined,
1021
+ payload: {
1022
+ amt: 2400,
1023
+ name: "Page A",
1024
+ pv: 2400,
1025
+ uv: 400,
1026
+ },
1027
+ stroke: undefined,
1028
+ strokeWidth: undefined,
1029
+ type: undefined,
1030
+ unit: "",
1031
+ value: 400,
1032
+ },
1033
+ {
1034
+ color: undefined,
1035
+ dataKey: "pv",
1036
+ fill: undefined,
1037
+ graphicalItemId: "radar-pv",
1038
+ hide: false,
1039
+ name: "pv",
1040
+ nameKey: undefined,
1041
+ payload: {
1042
+ amt: 2400,
1043
+ name: "Page A",
1044
+ pv: 2400,
1045
+ uv: 400,
1046
+ },
1047
+ stroke: undefined,
1048
+ strokeWidth: undefined,
1049
+ type: undefined,
1050
+ unit: "",
1051
+ value: 2400,
1052
+ },
1053
+ {
1054
+ color: undefined,
1055
+ dataKey: "amt",
1056
+ fill: undefined,
1057
+ graphicalItemId: "radar-amt",
1058
+ hide: false,
1059
+ name: "amt",
1060
+ nameKey: undefined,
1061
+ payload: {
1062
+ amt: 2400,
1063
+ name: "Page A",
1064
+ pv: 2400,
1065
+ uv: 400,
1066
+ },
1067
+ stroke: undefined,
1068
+ strokeWidth: undefined,
1069
+ type: undefined,
1070
+ unit: "",
1071
+ value: 2400,
1072
+ },
1073
+ ]);
1074
+ });
1075
+ });
1076
+
1077
+ describe("when itemSorter=`dataKey`", () => {
1078
+ it("should render sorted payload", () => {
1079
+ const { container } = renderTestCase("dataKey");
1080
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1081
+ expectTooltipPayload(container, "Page F", ["amt : 2400", "pv : 4800", "uv : 189"]);
1082
+ });
1083
+ });
1084
+
1085
+ describe("when itemSorter=`value`", () => {
1086
+ it("should render sorted payload", () => {
1087
+ const { container } = renderTestCase("value");
1088
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1089
+ expectTooltipPayload(container, "Page F", ["uv : 189", "amt : 2400", "pv : 4800"]);
1090
+ });
1091
+ });
1092
+
1093
+ describe("when itemSorter=`name`", () => {
1094
+ it("should render sorted payload", () => {
1095
+ const { container } = renderTestCase("name");
1096
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1097
+ expectTooltipPayload(container, "Page F", ["amt : 2400", "pv : 4800", "uv : 189"]);
1098
+ });
1099
+ });
1100
+
1101
+ describe("when itemSorter is a function", () => {
1102
+ it("should render sorted payload", () => {
1103
+ const { container } = renderTestCase((item) => String(item.value));
1104
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1105
+ expectTooltipPayload(container, "Page F", ["uv : 189", "amt : 2400", "pv : 4800"]);
1106
+ });
1107
+
1108
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
1109
+ const spy = vi.fn();
1110
+ const { container } = renderTestCase(spy);
1111
+ expect(spy).toHaveBeenCalledTimes(0);
1112
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1113
+ expect(spy).toHaveBeenCalledTimes(3);
1114
+ expect(spy).toHaveBeenNthCalledWith(1, {
1115
+ color: undefined,
1116
+ dataKey: "uv",
1117
+ fill: undefined,
1118
+ graphicalItemId: "radar-uv",
1119
+ hide: false,
1120
+ name: "uv",
1121
+ nameKey: undefined,
1122
+ payload: {
1123
+ amt: 2400,
1124
+ name: "Page F",
1125
+ pv: 4800,
1126
+ uv: 189,
1127
+ },
1128
+ stroke: undefined,
1129
+ type: undefined,
1130
+ unit: "",
1131
+ value: 189,
1132
+ });
1133
+ expect(spy).toHaveBeenNthCalledWith(2, {
1134
+ color: undefined,
1135
+ dataKey: "pv",
1136
+ fill: undefined,
1137
+ graphicalItemId: "radar-pv",
1138
+ hide: false,
1139
+ name: "pv",
1140
+ nameKey: undefined,
1141
+ payload: {
1142
+ amt: 2400,
1143
+ name: "Page F",
1144
+ pv: 4800,
1145
+ uv: 189,
1146
+ },
1147
+ stroke: undefined,
1148
+ type: undefined,
1149
+ unit: "",
1150
+ value: 4800,
1151
+ });
1152
+ expect(spy).toHaveBeenNthCalledWith(3, {
1153
+ color: undefined,
1154
+ dataKey: "amt",
1155
+ fill: undefined,
1156
+ graphicalItemId: "radar-amt",
1157
+ hide: false,
1158
+ name: "amt",
1159
+ nameKey: undefined,
1160
+ payload: {
1161
+ amt: 2400,
1162
+ name: "Page F",
1163
+ pv: 4800,
1164
+ uv: 189,
1165
+ },
1166
+ stroke: undefined,
1167
+ type: undefined,
1168
+ unit: "",
1169
+ value: 2400,
1170
+ });
1171
+ });
1172
+ });
1173
+ });
1174
+
1175
+ describe("with name prop", () => {
1176
+ function renderTestCase<T>(
1177
+ itemSorter: TooltipItemSorter | undefined,
1178
+ selector?: (state: RechartsRootState) => T,
1179
+ ) {
1180
+ return createSelectorTestCase((props) => (
1181
+ <RadarChart width={600} height={600} data={PageData}>
1182
+ <Radar dataKey="uv" isAnimationActive={false} name="Radar-uv" id="radar-uv" />
1183
+ <Radar dataKey="pv" isAnimationActive={false} name="Radar-pv" id="radar-pv" />
1184
+ <Radar dataKey="amt" isAnimationActive={false} name="Radar-amt" id="radar-amt" />
1185
+ <PolarAngleAxis dataKey="name" name="PolarAngleAxis" />
1186
+ <PolarRadiusAxis dataKey="uv" name="PolarRadiusAxis" />
1187
+ <Tooltip itemSorter={itemSorter} />
1188
+ {props.children}
1189
+ </RadarChart>
1190
+ ))(selector);
1191
+ }
1192
+
1193
+ describe("when itemSorter is undefined", () => {
1194
+ it("should render payload sorted by name", () => {
1195
+ const { container } = renderTestCase(undefined);
1196
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1197
+ expectTooltipPayload(container, "Page F", [
1198
+ "Radar-amt : 2400",
1199
+ "Radar-pv : 4800",
1200
+ "Radar-uv : 189",
1201
+ ]);
1202
+ });
1203
+
1204
+ it("should select payload sorted by name", () => {
1205
+ const { spy } = renderTestCase(undefined, (state) =>
1206
+ selectTooltipPayload(state, "axis", "hover", "0"),
1207
+ );
1208
+ expectLastCalledWith(spy, [
1209
+ {
1210
+ color: undefined,
1211
+ dataKey: "uv",
1212
+ fill: undefined,
1213
+ graphicalItemId: "radar-uv",
1214
+ hide: false,
1215
+ name: "Radar-uv",
1216
+ nameKey: undefined,
1217
+ payload: {
1218
+ amt: 2400,
1219
+ name: "Page A",
1220
+ pv: 2400,
1221
+ uv: 400,
1222
+ },
1223
+ stroke: undefined,
1224
+ strokeWidth: undefined,
1225
+ type: undefined,
1226
+ unit: "",
1227
+ value: 400,
1228
+ },
1229
+ {
1230
+ color: undefined,
1231
+ dataKey: "pv",
1232
+ fill: undefined,
1233
+ graphicalItemId: "radar-pv",
1234
+ hide: false,
1235
+ name: "Radar-pv",
1236
+ nameKey: undefined,
1237
+ payload: {
1238
+ amt: 2400,
1239
+ name: "Page A",
1240
+ pv: 2400,
1241
+ uv: 400,
1242
+ },
1243
+ stroke: undefined,
1244
+ type: undefined,
1245
+ unit: "",
1246
+ value: 2400,
1247
+ },
1248
+ {
1249
+ color: undefined,
1250
+ dataKey: "amt",
1251
+ fill: undefined,
1252
+ graphicalItemId: "radar-amt",
1253
+ hide: false,
1254
+ name: "Radar-amt",
1255
+ nameKey: undefined,
1256
+ payload: {
1257
+ amt: 2400,
1258
+ name: "Page A",
1259
+ pv: 2400,
1260
+ uv: 400,
1261
+ },
1262
+ stroke: undefined,
1263
+ strokeWidth: undefined,
1264
+ type: undefined,
1265
+ unit: "",
1266
+ value: 2400,
1267
+ },
1268
+ ]);
1269
+ });
1270
+ });
1271
+
1272
+ describe("when itemSorter=`dataKey`", () => {
1273
+ it("should render sorted payload", () => {
1274
+ const { container } = renderTestCase("dataKey");
1275
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1276
+ expectTooltipPayload(container, "Page F", [
1277
+ "Radar-amt : 2400",
1278
+ "Radar-pv : 4800",
1279
+ "Radar-uv : 189",
1280
+ ]);
1281
+ });
1282
+ });
1283
+
1284
+ describe("when itemSorter=`value`", () => {
1285
+ it("should render sorted payload", () => {
1286
+ const { container } = renderTestCase("value");
1287
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1288
+ expectTooltipPayload(container, "Page F", [
1289
+ "Radar-uv : 189",
1290
+ "Radar-amt : 2400",
1291
+ "Radar-pv : 4800",
1292
+ ]);
1293
+ });
1294
+ });
1295
+
1296
+ describe("when itemSorter=`name`", () => {
1297
+ it("should render sorted payload", () => {
1298
+ const { container } = renderTestCase("name");
1299
+ showTooltip(container, radarChartMouseHoverTooltipSelector);
1300
+ expectTooltipPayload(container, "Page F", [
1301
+ "Radar-amt : 2400",
1302
+ "Radar-pv : 4800",
1303
+ "Radar-uv : 189",
1304
+ ]);
1305
+ });
1306
+ });
1307
+ });
1308
+ });
1309
+
1310
+ describe("itemSorter in RadialBarChart", () => {
1311
+ beforeEach(() => {
1312
+ mockGetBoundingClientRect({ width: 100, height: 100 });
1313
+ });
1314
+
1315
+ describe("without name prop", () => {
1316
+ function renderTestCase<T>(
1317
+ itemSorter: TooltipItemSorter | undefined,
1318
+ selector?: (state: RechartsRootState) => T,
1319
+ ) {
1320
+ return createSelectorTestCase((props) => (
1321
+ <RadialBarChart width={600} height={600} data={PageData}>
1322
+ <RadialBar dataKey="uv" isAnimationActive={false} id="radialbar-uv" />
1323
+ <RadialBar dataKey="pv" isAnimationActive={false} id="radialbar-pv" />
1324
+ <RadialBar dataKey="amt" isAnimationActive={false} id="radialbar-amt" />
1325
+ <PolarAngleAxis dataKey="uv" />
1326
+ <PolarRadiusAxis dataKey="name" />
1327
+ <Tooltip itemSorter={itemSorter} />
1328
+ {props.children}
1329
+ </RadialBarChart>
1330
+ ))(selector);
1331
+ }
1332
+
1333
+ describe("when itemSorter is undefined", () => {
1334
+ it("should render payload sorted by name", () => {
1335
+ const { container } = renderTestCase(undefined);
1336
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1337
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
1338
+ });
1339
+
1340
+ it("should select payload sorted by name", () => {
1341
+ const { spy } = renderTestCase(undefined, (state) =>
1342
+ selectTooltipPayload(state, "axis", "hover", "0"),
1343
+ );
1344
+ expectLastCalledWith(spy, [
1345
+ {
1346
+ color: undefined,
1347
+ fill: undefined,
1348
+ graphicalItemId: "radialbar-uv",
1349
+ dataKey: "uv",
1350
+ name: "uv",
1351
+ hide: false,
1352
+ nameKey: undefined,
1353
+ unit: "",
1354
+ payload: {
1355
+ name: "Page A",
1356
+ uv: 400,
1357
+ pv: 2400,
1358
+ amt: 2400,
1359
+ background: {
1360
+ cx: 300,
1361
+ cy: 300,
1362
+ innerRadius: 3.9333333333333336,
1363
+ outerRadius: 11.933333333333334,
1364
+ startAngle: 0,
1365
+ endAngle: 360,
1366
+ },
1367
+ clockWise: false,
1368
+ payload: {
1369
+ name: "Page A",
1370
+ uv: 400,
1371
+ pv: 2400,
1372
+ amt: 2400,
1373
+ },
1374
+ value: 400,
1375
+ cx: 300,
1376
+ cy: 300,
1377
+ innerRadius: 3.9333333333333336,
1378
+ outerRadius: 11.933333333333334,
1379
+ startAngle: 0,
1380
+ endAngle: 360,
1381
+ },
1382
+ stroke: undefined,
1383
+ type: undefined,
1384
+ value: 400,
1385
+ },
1386
+ {
1387
+ color: undefined,
1388
+ fill: undefined,
1389
+ graphicalItemId: "radialbar-pv",
1390
+ dataKey: "pv",
1391
+ name: "pv",
1392
+ hide: false,
1393
+ nameKey: undefined,
1394
+ unit: "",
1395
+ payload: {
1396
+ name: "Page A",
1397
+ uv: 400,
1398
+ pv: 2400,
1399
+ amt: 2400,
1400
+ background: {
1401
+ cx: 300,
1402
+ cy: 300,
1403
+ innerRadius: 15.933333333333334,
1404
+ outerRadius: 23.933333333333334,
1405
+ startAngle: 0,
1406
+ endAngle: 360,
1407
+ },
1408
+ clockWise: false,
1409
+ payload: {
1410
+ name: "Page A",
1411
+ uv: 400,
1412
+ pv: 2400,
1413
+ amt: 2400,
1414
+ },
1415
+ value: 2400,
1416
+ cx: 300,
1417
+ cy: 300,
1418
+ innerRadius: 15.933333333333334,
1419
+ outerRadius: 23.933333333333334,
1420
+ startAngle: 0,
1421
+ endAngle: 2160,
1422
+ },
1423
+ stroke: undefined,
1424
+ type: undefined,
1425
+ value: 2400,
1426
+ },
1427
+ {
1428
+ color: undefined,
1429
+ fill: undefined,
1430
+ graphicalItemId: "radialbar-amt",
1431
+ dataKey: "amt",
1432
+ name: "amt",
1433
+ hide: false,
1434
+ nameKey: undefined,
1435
+ unit: "",
1436
+ payload: {
1437
+ name: "Page A",
1438
+ uv: 400,
1439
+ pv: 2400,
1440
+ amt: 2400,
1441
+ background: {
1442
+ cx: 300,
1443
+ cy: 300,
1444
+ innerRadius: 27.933333333333334,
1445
+ outerRadius: 35.93333333333334,
1446
+ startAngle: 0,
1447
+ endAngle: 360,
1448
+ },
1449
+ clockWise: false,
1450
+ payload: {
1451
+ name: "Page A",
1452
+ uv: 400,
1453
+ pv: 2400,
1454
+ amt: 2400,
1455
+ },
1456
+ value: 2400,
1457
+ cx: 300,
1458
+ cy: 300,
1459
+ innerRadius: 27.933333333333334,
1460
+ outerRadius: 35.93333333333334,
1461
+ startAngle: 0,
1462
+ endAngle: 2160,
1463
+ },
1464
+ stroke: undefined,
1465
+ type: undefined,
1466
+ value: 2400,
1467
+ },
1468
+ ]);
1469
+ });
1470
+ });
1471
+
1472
+ describe("when itemSorter=`dataKey`", () => {
1473
+ it("should render sorted payload", () => {
1474
+ const { container } = renderTestCase("dataKey");
1475
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1476
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
1477
+ });
1478
+ });
1479
+
1480
+ describe("when itemSorter=`value`", () => {
1481
+ it("should render sorted payload", () => {
1482
+ const { container } = renderTestCase("value");
1483
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1484
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
1485
+ });
1486
+ });
1487
+
1488
+ describe("when itemSorter=`name`", () => {
1489
+ it("should render sorted payload", () => {
1490
+ const { container } = renderTestCase("name");
1491
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1492
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
1493
+ });
1494
+ });
1495
+
1496
+ describe("when itemSorter is a function", () => {
1497
+ it("should render sorted payload", () => {
1498
+ const { container } = renderTestCase((item) => String(item.value));
1499
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1500
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
1501
+ });
1502
+
1503
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
1504
+ const spy = vi.fn();
1505
+ const { container } = renderTestCase(spy);
1506
+ expect(spy).toHaveBeenCalledTimes(0);
1507
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1508
+ expect(spy).toHaveBeenCalledTimes(3);
1509
+ expect(spy).toHaveBeenNthCalledWith(1, {
1510
+ color: undefined,
1511
+ dataKey: "uv",
1512
+ fill: undefined,
1513
+ graphicalItemId: "radialbar-uv",
1514
+ hide: false,
1515
+ name: "uv",
1516
+ nameKey: undefined,
1517
+ payload: {
1518
+ amt: 2400,
1519
+ background: {
1520
+ cx: 300,
1521
+ cy: 300,
1522
+ endAngle: 360,
1523
+ innerRadius: 121.93333333333334,
1524
+ outerRadius: 129.93333333333334,
1525
+ startAngle: 0,
1526
+ },
1527
+ clockWise: false,
1528
+ cx: 300,
1529
+ cy: 300,
1530
+ endAngle: 180,
1531
+ innerRadius: 121.93333333333334,
1532
+ name: "Page D",
1533
+ outerRadius: 129.93333333333334,
1534
+ payload: {
1535
+ amt: 2400,
1536
+ name: "Page D",
1537
+ pv: 9800,
1538
+ uv: 200,
1539
+ },
1540
+ pv: 9800,
1541
+ startAngle: 0,
1542
+ uv: 200,
1543
+ value: 200,
1544
+ },
1545
+ stroke: undefined,
1546
+ type: undefined,
1547
+ unit: "",
1548
+ value: 200,
1549
+ });
1550
+ expect(spy).toHaveBeenNthCalledWith(2, {
1551
+ color: undefined,
1552
+ dataKey: "pv",
1553
+ fill: undefined,
1554
+ graphicalItemId: "radialbar-pv",
1555
+ hide: false,
1556
+ name: "pv",
1557
+ nameKey: undefined,
1558
+ payload: {
1559
+ amt: 2400,
1560
+ background: {
1561
+ cx: 300,
1562
+ cy: 300,
1563
+ endAngle: 360,
1564
+ innerRadius: 133.93333333333334,
1565
+ outerRadius: 141.93333333333334,
1566
+ startAngle: 0,
1567
+ },
1568
+ clockWise: false,
1569
+ cx: 300,
1570
+ cy: 300,
1571
+ endAngle: 8820,
1572
+ innerRadius: 133.93333333333334,
1573
+ name: "Page D",
1574
+ outerRadius: 141.93333333333334,
1575
+ payload: {
1576
+ amt: 2400,
1577
+ name: "Page D",
1578
+ pv: 9800,
1579
+ uv: 200,
1580
+ },
1581
+ pv: 9800,
1582
+ startAngle: 0,
1583
+ uv: 200,
1584
+ value: 9800,
1585
+ },
1586
+ stroke: undefined,
1587
+ type: undefined,
1588
+ unit: "",
1589
+ value: 9800,
1590
+ });
1591
+ expect(spy).toHaveBeenNthCalledWith(3, {
1592
+ color: undefined,
1593
+ dataKey: "amt",
1594
+ fill: undefined,
1595
+ graphicalItemId: "radialbar-amt",
1596
+ hide: false,
1597
+ name: "amt",
1598
+ nameKey: undefined,
1599
+ payload: {
1600
+ amt: 2400,
1601
+ background: {
1602
+ cx: 300,
1603
+ cy: 300,
1604
+ endAngle: 360,
1605
+ innerRadius: 145.93333333333334,
1606
+ outerRadius: 153.93333333333334,
1607
+ startAngle: 0,
1608
+ },
1609
+ clockWise: false,
1610
+ cx: 300,
1611
+ cy: 300,
1612
+ endAngle: 2160,
1613
+ innerRadius: 145.93333333333334,
1614
+ name: "Page D",
1615
+ outerRadius: 153.93333333333334,
1616
+ payload: {
1617
+ amt: 2400,
1618
+ name: "Page D",
1619
+ pv: 9800,
1620
+ uv: 200,
1621
+ },
1622
+ pv: 9800,
1623
+ startAngle: 0,
1624
+ uv: 200,
1625
+ value: 2400,
1626
+ },
1627
+ stroke: undefined,
1628
+ type: undefined,
1629
+ unit: "",
1630
+ value: 2400,
1631
+ });
1632
+ });
1633
+ });
1634
+ });
1635
+
1636
+ describe("with name prop", () => {
1637
+ function renderTestCase<T>(
1638
+ itemSorter: TooltipItemSorter | undefined,
1639
+ selector?: (state: RechartsRootState) => T,
1640
+ ) {
1641
+ return createSelectorTestCase((props) => (
1642
+ <RadialBarChart width={600} height={600} data={PageData}>
1643
+ <RadialBar dataKey="uv" isAnimationActive={false} name="RadialBar-uv" id="radialbar-uv" />
1644
+ <RadialBar dataKey="pv" isAnimationActive={false} name="RadialBar-pv" id="radialbar-pv" />
1645
+ <RadialBar
1646
+ dataKey="amt"
1647
+ isAnimationActive={false}
1648
+ name="RadialBar-amt"
1649
+ id="radialbar-amt"
1650
+ />
1651
+ <PolarAngleAxis dataKey="uv" name="PolarAngleAxis" />
1652
+ <PolarRadiusAxis dataKey="name" name="PolarRadiusAxis" />
1653
+ <Tooltip itemSorter={itemSorter} />
1654
+ {props.children}
1655
+ </RadialBarChart>
1656
+ ))(selector);
1657
+ }
1658
+
1659
+ describe("when itemSorter is undefined", () => {
1660
+ it("should render payload sorted by name", () => {
1661
+ const { container } = renderTestCase(undefined);
1662
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1663
+ expectTooltipPayload(container, "Page D", [
1664
+ "RadialBar-amt : 2400",
1665
+ "RadialBar-pv : 9800",
1666
+ "RadialBar-uv : 200",
1667
+ ]);
1668
+ });
1669
+
1670
+ it("should select payload sorted by name", () => {
1671
+ const { spy } = renderTestCase(undefined, (state) =>
1672
+ selectTooltipPayload(state, "axis", "hover", "0"),
1673
+ );
1674
+ expectLastCalledWith(spy, [
1675
+ {
1676
+ color: undefined,
1677
+ fill: undefined,
1678
+ graphicalItemId: "radialbar-uv",
1679
+ dataKey: "uv",
1680
+ name: "RadialBar-uv",
1681
+ hide: false,
1682
+ nameKey: undefined,
1683
+ unit: "",
1684
+ payload: {
1685
+ name: "Page A",
1686
+ uv: 400,
1687
+ pv: 2400,
1688
+ amt: 2400,
1689
+ background: {
1690
+ cx: 300,
1691
+ cy: 300,
1692
+ innerRadius: 3.9333333333333336,
1693
+ outerRadius: 11.933333333333334,
1694
+ startAngle: 0,
1695
+ endAngle: 360,
1696
+ },
1697
+ clockWise: false,
1698
+ payload: {
1699
+ name: "Page A",
1700
+ uv: 400,
1701
+ pv: 2400,
1702
+ amt: 2400,
1703
+ },
1704
+ value: 400,
1705
+ cx: 300,
1706
+ cy: 300,
1707
+ innerRadius: 3.9333333333333336,
1708
+ outerRadius: 11.933333333333334,
1709
+ startAngle: 0,
1710
+ endAngle: 360,
1711
+ },
1712
+ stroke: undefined,
1713
+ type: undefined,
1714
+ value: 400,
1715
+ },
1716
+ {
1717
+ color: undefined,
1718
+ fill: undefined,
1719
+ graphicalItemId: "radialbar-pv",
1720
+ dataKey: "pv",
1721
+ name: "RadialBar-pv",
1722
+ hide: false,
1723
+ nameKey: undefined,
1724
+ unit: "",
1725
+ payload: {
1726
+ name: "Page A",
1727
+ uv: 400,
1728
+ pv: 2400,
1729
+ amt: 2400,
1730
+ background: {
1731
+ cx: 300,
1732
+ cy: 300,
1733
+ innerRadius: 15.933333333333334,
1734
+ outerRadius: 23.933333333333334,
1735
+ startAngle: 0,
1736
+ endAngle: 360,
1737
+ },
1738
+ clockWise: false,
1739
+ payload: {
1740
+ name: "Page A",
1741
+ uv: 400,
1742
+ pv: 2400,
1743
+ amt: 2400,
1744
+ },
1745
+ value: 2400,
1746
+ cx: 300,
1747
+ cy: 300,
1748
+ innerRadius: 15.933333333333334,
1749
+ outerRadius: 23.933333333333334,
1750
+ startAngle: 0,
1751
+ endAngle: 2160,
1752
+ },
1753
+ stroke: undefined,
1754
+ type: undefined,
1755
+ value: 2400,
1756
+ },
1757
+ {
1758
+ color: undefined,
1759
+ fill: undefined,
1760
+ graphicalItemId: "radialbar-amt",
1761
+ dataKey: "amt",
1762
+ name: "RadialBar-amt",
1763
+ hide: false,
1764
+ nameKey: undefined,
1765
+ unit: "",
1766
+ payload: {
1767
+ name: "Page A",
1768
+ uv: 400,
1769
+ pv: 2400,
1770
+ amt: 2400,
1771
+ background: {
1772
+ cx: 300,
1773
+ cy: 300,
1774
+ innerRadius: 27.933333333333334,
1775
+ outerRadius: 35.93333333333334,
1776
+ startAngle: 0,
1777
+ endAngle: 360,
1778
+ },
1779
+ clockWise: false,
1780
+ payload: {
1781
+ name: "Page A",
1782
+ uv: 400,
1783
+ pv: 2400,
1784
+ amt: 2400,
1785
+ },
1786
+ value: 2400,
1787
+ cx: 300,
1788
+ cy: 300,
1789
+ innerRadius: 27.933333333333334,
1790
+ outerRadius: 35.93333333333334,
1791
+ startAngle: 0,
1792
+ endAngle: 2160,
1793
+ },
1794
+ stroke: undefined,
1795
+ type: undefined,
1796
+ value: 2400,
1797
+ },
1798
+ ]);
1799
+ });
1800
+ });
1801
+
1802
+ describe("when itemSorter=`dataKey`", () => {
1803
+ it("should render sorted payload", () => {
1804
+ const { container } = renderTestCase("dataKey");
1805
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1806
+ expectTooltipPayload(container, "Page D", [
1807
+ "RadialBar-amt : 2400",
1808
+ "RadialBar-pv : 9800",
1809
+ "RadialBar-uv : 200",
1810
+ ]);
1811
+ });
1812
+ });
1813
+
1814
+ describe("when itemSorter=`value`", () => {
1815
+ it("should render sorted payload", () => {
1816
+ const { container } = renderTestCase("value");
1817
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1818
+ expectTooltipPayload(container, "Page D", [
1819
+ "RadialBar-uv : 200",
1820
+ "RadialBar-amt : 2400",
1821
+ "RadialBar-pv : 9800",
1822
+ ]);
1823
+ });
1824
+ });
1825
+
1826
+ describe("when itemSorter=`name`", () => {
1827
+ it("should render sorted payload", () => {
1828
+ const { container } = renderTestCase("name");
1829
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1830
+ expectTooltipPayload(container, "Page D", [
1831
+ "RadialBar-amt : 2400",
1832
+ "RadialBar-pv : 9800",
1833
+ "RadialBar-uv : 200",
1834
+ ]);
1835
+ });
1836
+ });
1837
+
1838
+ describe("when itemSorter is a function", () => {
1839
+ it("should render sorted payload", () => {
1840
+ const { container } = renderTestCase((item) => String(item.value));
1841
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1842
+ expectTooltipPayload(container, "Page D", [
1843
+ "RadialBar-uv : 200",
1844
+ "RadialBar-amt : 2400",
1845
+ "RadialBar-pv : 9800",
1846
+ ]);
1847
+ });
1848
+
1849
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
1850
+ const spy = vi.fn();
1851
+ const { container } = renderTestCase(spy);
1852
+ expect(spy).toHaveBeenCalledTimes(0);
1853
+ showTooltip(container, radialBarChartMouseHoverTooltipSelector);
1854
+ expect(spy).toHaveBeenCalledTimes(3);
1855
+ expect(spy).toHaveBeenNthCalledWith(1, {
1856
+ color: undefined,
1857
+ dataKey: "uv",
1858
+ fill: undefined,
1859
+ graphicalItemId: "radialbar-uv",
1860
+ hide: false,
1861
+ name: "RadialBar-uv",
1862
+ nameKey: undefined,
1863
+ payload: {
1864
+ amt: 2400,
1865
+ background: {
1866
+ cx: 300,
1867
+ cy: 300,
1868
+ endAngle: 360,
1869
+ innerRadius: 121.93333333333334,
1870
+ outerRadius: 129.93333333333334,
1871
+ startAngle: 0,
1872
+ },
1873
+ clockWise: false,
1874
+ cx: 300,
1875
+ cy: 300,
1876
+ endAngle: 180,
1877
+ innerRadius: 121.93333333333334,
1878
+ name: "Page D",
1879
+ outerRadius: 129.93333333333334,
1880
+ payload: {
1881
+ amt: 2400,
1882
+ name: "Page D",
1883
+ pv: 9800,
1884
+ uv: 200,
1885
+ },
1886
+ pv: 9800,
1887
+ startAngle: 0,
1888
+ uv: 200,
1889
+ value: 200,
1890
+ },
1891
+ stroke: undefined,
1892
+ type: undefined,
1893
+ unit: "",
1894
+ value: 200,
1895
+ });
1896
+ expect(spy).toHaveBeenNthCalledWith(2, {
1897
+ color: undefined,
1898
+ dataKey: "pv",
1899
+ fill: undefined,
1900
+ graphicalItemId: "radialbar-pv",
1901
+ hide: false,
1902
+ name: "RadialBar-pv",
1903
+ nameKey: undefined,
1904
+ payload: {
1905
+ amt: 2400,
1906
+ background: {
1907
+ cx: 300,
1908
+ cy: 300,
1909
+ endAngle: 360,
1910
+ innerRadius: 133.93333333333334,
1911
+ outerRadius: 141.93333333333334,
1912
+ startAngle: 0,
1913
+ },
1914
+ clockWise: false,
1915
+ cx: 300,
1916
+ cy: 300,
1917
+ endAngle: 8820,
1918
+ innerRadius: 133.93333333333334,
1919
+ name: "Page D",
1920
+ outerRadius: 141.93333333333334,
1921
+ payload: {
1922
+ amt: 2400,
1923
+ name: "Page D",
1924
+ pv: 9800,
1925
+ uv: 200,
1926
+ },
1927
+ pv: 9800,
1928
+ startAngle: 0,
1929
+ uv: 200,
1930
+ value: 9800,
1931
+ },
1932
+ stroke: undefined,
1933
+ type: undefined,
1934
+ unit: "",
1935
+ value: 9800,
1936
+ });
1937
+ expect(spy).toHaveBeenNthCalledWith(3, {
1938
+ color: undefined,
1939
+ dataKey: "amt",
1940
+ fill: undefined,
1941
+ graphicalItemId: "radialbar-amt",
1942
+ hide: false,
1943
+ name: "RadialBar-amt",
1944
+ nameKey: undefined,
1945
+ payload: {
1946
+ amt: 2400,
1947
+ background: {
1948
+ cx: 300,
1949
+ cy: 300,
1950
+ endAngle: 360,
1951
+ innerRadius: 145.93333333333334,
1952
+ outerRadius: 153.93333333333334,
1953
+ startAngle: 0,
1954
+ },
1955
+ clockWise: false,
1956
+ cx: 300,
1957
+ cy: 300,
1958
+ endAngle: 2160,
1959
+ innerRadius: 145.93333333333334,
1960
+ name: "Page D",
1961
+ outerRadius: 153.93333333333334,
1962
+ payload: {
1963
+ amt: 2400,
1964
+ name: "Page D",
1965
+ pv: 9800,
1966
+ uv: 200,
1967
+ },
1968
+ pv: 9800,
1969
+ startAngle: 0,
1970
+ uv: 200,
1971
+ value: 2400,
1972
+ },
1973
+ stroke: undefined,
1974
+ type: undefined,
1975
+ unit: "",
1976
+ value: 2400,
1977
+ });
1978
+ });
1979
+ });
1980
+ });
1981
+ });
1982
+
1983
+ // Funnel, Treemap, Sankey - always only render one payload item so there is nothing to sort either
1984
+
1985
+ describe("itemSorter in stacked BarChart", () => {
1986
+ beforeEach(() => {
1987
+ mockGetBoundingClientRect({ width: 100, height: 100 });
1988
+ });
1989
+
1990
+ describe("without name prop", () => {
1991
+ function renderTestCase<T>(
1992
+ itemSorter: TooltipItemSorter | undefined,
1993
+ selector?: (state: RechartsRootState) => T,
1994
+ ) {
1995
+ return createSelectorTestCase((props) => (
1996
+ <BarChart width={300} height={300} data={PageData}>
1997
+ <Bar dataKey="pv" stackId="stack-1" id="bar-pv" />
1998
+ <Bar dataKey="uv" stackId="stack-1" id="bar-uv" />
1999
+ <Bar dataKey="amt" stackId="stack-1" id="bar-amt" />
2000
+ <YAxis />
2001
+ <XAxis dataKey="name" />
2002
+ <Tooltip itemSorter={itemSorter} />
2003
+ {props.children}
2004
+ </BarChart>
2005
+ ))(selector);
2006
+ }
2007
+
2008
+ describe("when itemSorter is undefined", () => {
2009
+ it("should render payload sorted by name", () => {
2010
+ const { container } = renderTestCase(undefined);
2011
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2012
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2013
+ });
2014
+
2015
+ it("should select payload sorted by name", () => {
2016
+ const { spy } = renderTestCase(undefined, (state) =>
2017
+ selectTooltipPayload(state, "axis", "hover", "0"),
2018
+ );
2019
+ expectLastCalledWith(spy, [
2020
+ {
2021
+ color: undefined,
2022
+ dataKey: "pv",
2023
+ fill: undefined,
2024
+ graphicalItemId: "bar-pv",
2025
+ hide: false,
2026
+ name: "pv",
2027
+ nameKey: undefined,
2028
+ payload: {
2029
+ amt: 2400,
2030
+ name: "Page A",
2031
+ pv: 2400,
2032
+ uv: 400,
2033
+ },
2034
+ stroke: undefined,
2035
+ strokeWidth: undefined,
2036
+ type: undefined,
2037
+ unit: undefined,
2038
+ value: 2400,
2039
+ },
2040
+ {
2041
+ color: undefined,
2042
+ dataKey: "uv",
2043
+ fill: undefined,
2044
+ graphicalItemId: "bar-uv",
2045
+ hide: false,
2046
+ name: "uv",
2047
+ nameKey: undefined,
2048
+ payload: {
2049
+ amt: 2400,
2050
+ name: "Page A",
2051
+ pv: 2400,
2052
+ uv: 400,
2053
+ },
2054
+ stroke: undefined,
2055
+ strokeWidth: undefined,
2056
+ type: undefined,
2057
+ unit: undefined,
2058
+ value: 400,
2059
+ },
2060
+ {
2061
+ color: undefined,
2062
+ dataKey: "amt",
2063
+ fill: undefined,
2064
+ graphicalItemId: "bar-amt",
2065
+ hide: false,
2066
+ name: "amt",
2067
+ nameKey: undefined,
2068
+ payload: {
2069
+ amt: 2400,
2070
+ name: "Page A",
2071
+ pv: 2400,
2072
+ uv: 400,
2073
+ },
2074
+ stroke: undefined,
2075
+ strokeWidth: undefined,
2076
+ type: undefined,
2077
+ unit: undefined,
2078
+ value: 2400,
2079
+ },
2080
+ ]);
2081
+ });
2082
+ });
2083
+
2084
+ describe("when itemSorter=`dataKey`", () => {
2085
+ it("should render sorted payload", () => {
2086
+ const { container } = renderTestCase("dataKey");
2087
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2088
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2089
+ });
2090
+ });
2091
+
2092
+ describe("when itemSorter=`value`", () => {
2093
+ it("should render sorted payload", () => {
2094
+ const { container } = renderTestCase("value");
2095
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2096
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
2097
+ });
2098
+ });
2099
+
2100
+ describe("when itemSorter=`name`", () => {
2101
+ it("should render sorted payload", () => {
2102
+ const { container } = renderTestCase("name");
2103
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2104
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2105
+ });
2106
+ });
2107
+
2108
+ describe("when itemSorter is a function", () => {
2109
+ it("should render sorted payload", () => {
2110
+ const { container } = renderTestCase((item) => String(item.value));
2111
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2112
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
2113
+ });
2114
+
2115
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
2116
+ const spy = vi.fn();
2117
+ const { container } = renderTestCase(spy);
2118
+ expect(spy).toHaveBeenCalledTimes(0);
2119
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2120
+ expect(spy).toHaveBeenCalledTimes(3);
2121
+ expect(spy).toHaveBeenNthCalledWith(1, {
2122
+ color: undefined,
2123
+ dataKey: "pv",
2124
+ fill: undefined,
2125
+ graphicalItemId: "bar-pv",
2126
+ hide: false,
2127
+ name: "pv",
2128
+ nameKey: undefined,
2129
+ payload: {
2130
+ amt: 2400,
2131
+ name: "Page D",
2132
+ pv: 9800,
2133
+ uv: 200,
2134
+ },
2135
+ stroke: undefined,
2136
+ strokeWidth: undefined,
2137
+ type: undefined,
2138
+ unit: undefined,
2139
+ value: 9800,
2140
+ });
2141
+ expect(spy).toHaveBeenNthCalledWith(2, {
2142
+ color: undefined,
2143
+ dataKey: "uv",
2144
+ fill: undefined,
2145
+ graphicalItemId: "bar-uv",
2146
+ hide: false,
2147
+ name: "uv",
2148
+ nameKey: undefined,
2149
+ payload: {
2150
+ amt: 2400,
2151
+ name: "Page D",
2152
+ pv: 9800,
2153
+ uv: 200,
2154
+ },
2155
+ stroke: undefined,
2156
+ strokeWidth: undefined,
2157
+ type: undefined,
2158
+ unit: undefined,
2159
+ value: 200,
2160
+ });
2161
+ expect(spy).toHaveBeenNthCalledWith(3, {
2162
+ color: undefined,
2163
+ dataKey: "amt",
2164
+ fill: undefined,
2165
+ graphicalItemId: "bar-amt",
2166
+ hide: false,
2167
+ name: "amt",
2168
+ nameKey: undefined,
2169
+ payload: {
2170
+ amt: 2400,
2171
+ name: "Page D",
2172
+ pv: 9800,
2173
+ uv: 200,
2174
+ },
2175
+ stroke: undefined,
2176
+ strokeWidth: undefined,
2177
+ type: undefined,
2178
+ unit: undefined,
2179
+ value: 2400,
2180
+ });
2181
+ });
2182
+ });
2183
+ });
2184
+
2185
+ describe("with name prop", () => {
2186
+ function renderTestCase<T>(
2187
+ itemSorter: TooltipItemSorter | undefined,
2188
+ selector?: (state: RechartsRootState) => T,
2189
+ ) {
2190
+ return createSelectorTestCase((props) => (
2191
+ <BarChart width={300} height={300} data={PageData}>
2192
+ <Bar dataKey="pv" stackId="stack-1" name="Bar-pv" id="bar-pv" />
2193
+ <Bar dataKey="uv" stackId="stack-1" name="Bar-uv" id="bar-uv" />
2194
+ <Bar dataKey="amt" stackId="stack-1" name="Bar-amt" id="bar-amt" />
2195
+ <YAxis name="YAxis" />
2196
+ <XAxis dataKey="name" name="XAxis" />
2197
+ <Tooltip itemSorter={itemSorter} />
2198
+ {props.children}
2199
+ </BarChart>
2200
+ ))(selector);
2201
+ }
2202
+
2203
+ describe("when itemSorter is undefined", () => {
2204
+ it("should render payload sorted by name", () => {
2205
+ const { container } = renderTestCase(undefined);
2206
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2207
+ expectTooltipPayload(container, "Page D", [
2208
+ "Bar-amt : 2400",
2209
+ "Bar-pv : 9800",
2210
+ "Bar-uv : 200",
2211
+ ]);
2212
+ });
2213
+
2214
+ it("should select payload sorted by name", () => {
2215
+ const { spy } = renderTestCase(undefined, (state) =>
2216
+ selectTooltipPayload(state, "axis", "hover", "0"),
2217
+ );
2218
+ expectLastCalledWith(spy, [
2219
+ {
2220
+ color: undefined,
2221
+ dataKey: "pv",
2222
+ fill: undefined,
2223
+ graphicalItemId: "bar-pv",
2224
+ hide: false,
2225
+ name: "Bar-pv",
2226
+ nameKey: undefined,
2227
+ payload: {
2228
+ amt: 2400,
2229
+ name: "Page A",
2230
+ pv: 2400,
2231
+ uv: 400,
2232
+ },
2233
+ stroke: undefined,
2234
+ strokeWidth: undefined,
2235
+ type: undefined,
2236
+ unit: undefined,
2237
+ value: 2400,
2238
+ },
2239
+ {
2240
+ color: undefined,
2241
+ dataKey: "uv",
2242
+ fill: undefined,
2243
+ graphicalItemId: "bar-uv",
2244
+ hide: false,
2245
+ name: "Bar-uv",
2246
+ nameKey: undefined,
2247
+ payload: {
2248
+ amt: 2400,
2249
+ name: "Page A",
2250
+ pv: 2400,
2251
+ uv: 400,
2252
+ },
2253
+ stroke: undefined,
2254
+ strokeWidth: undefined,
2255
+ type: undefined,
2256
+ unit: undefined,
2257
+ value: 400,
2258
+ },
2259
+ {
2260
+ color: undefined,
2261
+ dataKey: "amt",
2262
+ fill: undefined,
2263
+ graphicalItemId: "bar-amt",
2264
+ hide: false,
2265
+ name: "Bar-amt",
2266
+ nameKey: undefined,
2267
+ payload: {
2268
+ amt: 2400,
2269
+ name: "Page A",
2270
+ pv: 2400,
2271
+ uv: 400,
2272
+ },
2273
+ stroke: undefined,
2274
+ strokeWidth: undefined,
2275
+ type: undefined,
2276
+ unit: undefined,
2277
+ value: 2400,
2278
+ },
2279
+ ]);
2280
+ });
2281
+ });
2282
+
2283
+ describe("when itemSorter=`dataKey`", () => {
2284
+ it("should render sorted payload", () => {
2285
+ const { container } = renderTestCase("dataKey");
2286
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2287
+ expectTooltipPayload(container, "Page D", [
2288
+ "Bar-amt : 2400",
2289
+ "Bar-pv : 9800",
2290
+ "Bar-uv : 200",
2291
+ ]);
2292
+ });
2293
+ });
2294
+
2295
+ describe("when itemSorter=`value`", () => {
2296
+ it("should render sorted payload", () => {
2297
+ const { container } = renderTestCase("value");
2298
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2299
+ expectTooltipPayload(container, "Page D", [
2300
+ "Bar-uv : 200",
2301
+ "Bar-amt : 2400",
2302
+ "Bar-pv : 9800",
2303
+ ]);
2304
+ });
2305
+ });
2306
+
2307
+ describe("when itemSorter=`name`", () => {
2308
+ it("should render sorted payload", () => {
2309
+ const { container } = renderTestCase("name");
2310
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2311
+ expectTooltipPayload(container, "Page D", [
2312
+ "Bar-amt : 2400",
2313
+ "Bar-pv : 9800",
2314
+ "Bar-uv : 200",
2315
+ ]);
2316
+ });
2317
+ });
2318
+
2319
+ describe("when itemSorter is a function", () => {
2320
+ it("should render sorted payload", () => {
2321
+ const { container } = renderTestCase((item) => String(item.value));
2322
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2323
+ expectTooltipPayload(container, "Page D", [
2324
+ "Bar-uv : 200",
2325
+ "Bar-amt : 2400",
2326
+ "Bar-pv : 9800",
2327
+ ]);
2328
+ });
2329
+
2330
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
2331
+ const spy = vi.fn();
2332
+ const { container } = renderTestCase(spy);
2333
+ expect(spy).toHaveBeenCalledTimes(0);
2334
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2335
+ expect(spy).toHaveBeenCalledTimes(3);
2336
+ expect(spy).toHaveBeenNthCalledWith(1, {
2337
+ color: undefined,
2338
+ dataKey: "pv",
2339
+ fill: undefined,
2340
+ graphicalItemId: "bar-pv",
2341
+ hide: false,
2342
+ name: "Bar-pv",
2343
+ nameKey: undefined,
2344
+ payload: {
2345
+ amt: 2400,
2346
+ name: "Page D",
2347
+ pv: 9800,
2348
+ uv: 200,
2349
+ },
2350
+ stroke: undefined,
2351
+ strokeWidth: undefined,
2352
+ type: undefined,
2353
+ unit: undefined,
2354
+ value: 9800,
2355
+ });
2356
+ expect(spy).toHaveBeenNthCalledWith(2, {
2357
+ color: undefined,
2358
+ dataKey: "uv",
2359
+ fill: undefined,
2360
+ graphicalItemId: "bar-uv",
2361
+ hide: false,
2362
+ name: "Bar-uv",
2363
+ nameKey: undefined,
2364
+ payload: {
2365
+ amt: 2400,
2366
+ name: "Page D",
2367
+ pv: 9800,
2368
+ uv: 200,
2369
+ },
2370
+ stroke: undefined,
2371
+ strokeWidth: undefined,
2372
+ type: undefined,
2373
+ unit: undefined,
2374
+ value: 200,
2375
+ });
2376
+ expect(spy).toHaveBeenNthCalledWith(3, {
2377
+ color: undefined,
2378
+ dataKey: "amt",
2379
+ fill: undefined,
2380
+ graphicalItemId: "bar-amt",
2381
+ hide: false,
2382
+ name: "Bar-amt",
2383
+ nameKey: undefined,
2384
+ payload: {
2385
+ amt: 2400,
2386
+ name: "Page D",
2387
+ pv: 9800,
2388
+ uv: 200,
2389
+ },
2390
+ stroke: undefined,
2391
+ strokeWidth: undefined,
2392
+ type: undefined,
2393
+ unit: undefined,
2394
+ value: 2400,
2395
+ });
2396
+ });
2397
+ });
2398
+ });
2399
+ });
2400
+
2401
+ describe("itemSorter in stacked AreaChart", () => {
2402
+ beforeEach(() => {
2403
+ mockGetBoundingClientRect({ width: 100, height: 100 });
2404
+ });
2405
+
2406
+ describe("without name prop", () => {
2407
+ function renderTestCase<T>(
2408
+ itemSorter: TooltipItemSorter | undefined,
2409
+ selector?: (state: RechartsRootState) => T,
2410
+ ) {
2411
+ return createSelectorTestCase((props) => (
2412
+ <AreaChart width={300} height={300} data={PageData}>
2413
+ <Area dataKey="pv" stackId="stack-1" id="area-pv" />
2414
+ <Area dataKey="uv" stackId="stack-1" id="area-uv" />
2415
+ <Area dataKey="amt" stackId="stack-1" id="area-amt" />
2416
+ <YAxis />
2417
+ <XAxis dataKey="name" />
2418
+ <Tooltip itemSorter={itemSorter} />
2419
+ {props.children}
2420
+ </AreaChart>
2421
+ ))(selector);
2422
+ }
2423
+
2424
+ describe("when itemSorter is undefined", () => {
2425
+ it("should render payload sorted by name", () => {
2426
+ const { container } = renderTestCase(undefined);
2427
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2428
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2429
+ });
2430
+
2431
+ it("should select payload sorted by name", () => {
2432
+ const { spy } = renderTestCase(undefined, (state) =>
2433
+ selectTooltipPayload(state, "axis", "hover", "0"),
2434
+ );
2435
+ expectLastCalledWith(spy, [
2436
+ {
2437
+ color: "#3182bd",
2438
+ dataKey: "pv",
2439
+ fill: "#3182bd",
2440
+ hide: false,
2441
+ name: "pv",
2442
+ nameKey: undefined,
2443
+ payload: {
2444
+ amt: 2400,
2445
+ name: "Page A",
2446
+ pv: 2400,
2447
+ uv: 400,
2448
+ },
2449
+ stroke: "#3182bd",
2450
+ strokeWidth: 1,
2451
+ type: undefined,
2452
+ unit: undefined,
2453
+ value: 2400,
2454
+ graphicalItemId: "area-pv",
2455
+ },
2456
+ {
2457
+ color: "#3182bd",
2458
+ dataKey: "uv",
2459
+ fill: "#3182bd",
2460
+ hide: false,
2461
+ name: "uv",
2462
+ nameKey: undefined,
2463
+ payload: {
2464
+ amt: 2400,
2465
+ name: "Page A",
2466
+ pv: 2400,
2467
+ uv: 400,
2468
+ },
2469
+ stroke: "#3182bd",
2470
+ strokeWidth: 1,
2471
+ type: undefined,
2472
+ unit: undefined,
2473
+ value: 400,
2474
+ graphicalItemId: "area-uv",
2475
+ },
2476
+ {
2477
+ color: "#3182bd",
2478
+ dataKey: "amt",
2479
+ fill: "#3182bd",
2480
+ hide: false,
2481
+ name: "amt",
2482
+ nameKey: undefined,
2483
+ payload: {
2484
+ amt: 2400,
2485
+ name: "Page A",
2486
+ pv: 2400,
2487
+ uv: 400,
2488
+ },
2489
+ stroke: "#3182bd",
2490
+ strokeWidth: 1,
2491
+ type: undefined,
2492
+ unit: undefined,
2493
+ value: 2400,
2494
+ graphicalItemId: "area-amt",
2495
+ },
2496
+ ]);
2497
+ });
2498
+ });
2499
+
2500
+ describe("when itemSorter=`dataKey`", () => {
2501
+ it("should render sorted payload", () => {
2502
+ const { container } = renderTestCase("dataKey");
2503
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2504
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2505
+ });
2506
+ });
2507
+
2508
+ describe("when itemSorter=`value`", () => {
2509
+ it("should render sorted payload", () => {
2510
+ const { container } = renderTestCase("value");
2511
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2512
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
2513
+ });
2514
+ });
2515
+
2516
+ describe("when itemSorter=`name`", () => {
2517
+ it("should render sorted payload", () => {
2518
+ const { container } = renderTestCase("name");
2519
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2520
+ expectTooltipPayload(container, "Page D", ["amt : 2400", "pv : 9800", "uv : 200"]);
2521
+ });
2522
+ });
2523
+
2524
+ describe("when itemSorter is a function", () => {
2525
+ it("should render sorted payload", () => {
2526
+ const { container } = renderTestCase((item) => String(item.value));
2527
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2528
+ expectTooltipPayload(container, "Page D", ["uv : 200", "amt : 2400", "pv : 9800"]);
2529
+ });
2530
+
2531
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
2532
+ const spy = vi.fn();
2533
+ const { container } = renderTestCase(spy);
2534
+ expect(spy).toHaveBeenCalledTimes(0);
2535
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2536
+ expect(spy).toHaveBeenCalledTimes(3);
2537
+ expect(spy).toHaveBeenNthCalledWith(1, {
2538
+ color: "#3182bd",
2539
+ dataKey: "pv",
2540
+ fill: "#3182bd",
2541
+ graphicalItemId: "area-pv",
2542
+ hide: false,
2543
+ name: "pv",
2544
+ nameKey: undefined,
2545
+ payload: {
2546
+ amt: 2400,
2547
+ name: "Page D",
2548
+ pv: 9800,
2549
+ uv: 200,
2550
+ },
2551
+ stroke: "#3182bd",
2552
+ strokeWidth: 1,
2553
+ type: undefined,
2554
+ unit: undefined,
2555
+ value: 9800,
2556
+ });
2557
+ expect(spy).toHaveBeenNthCalledWith(2, {
2558
+ color: "#3182bd",
2559
+ dataKey: "uv",
2560
+ fill: "#3182bd",
2561
+ graphicalItemId: "area-uv",
2562
+ hide: false,
2563
+ name: "uv",
2564
+ nameKey: undefined,
2565
+ payload: {
2566
+ amt: 2400,
2567
+ name: "Page D",
2568
+ pv: 9800,
2569
+ uv: 200,
2570
+ },
2571
+ stroke: "#3182bd",
2572
+ strokeWidth: 1,
2573
+ type: undefined,
2574
+ unit: undefined,
2575
+ value: 200,
2576
+ });
2577
+ expect(spy).toHaveBeenNthCalledWith(3, {
2578
+ color: "#3182bd",
2579
+ dataKey: "amt",
2580
+ fill: "#3182bd",
2581
+ graphicalItemId: "area-amt",
2582
+ hide: false,
2583
+ name: "amt",
2584
+ nameKey: undefined,
2585
+ payload: {
2586
+ amt: 2400,
2587
+ name: "Page D",
2588
+ pv: 9800,
2589
+ uv: 200,
2590
+ },
2591
+ stroke: "#3182bd",
2592
+ strokeWidth: 1,
2593
+ type: undefined,
2594
+ unit: undefined,
2595
+ value: 2400,
2596
+ });
2597
+ });
2598
+ });
2599
+ });
2600
+
2601
+ describe("with name prop", () => {
2602
+ function renderTestCase<T>(
2603
+ itemSorter: TooltipItemSorter | undefined,
2604
+ selector?: (state: RechartsRootState) => T,
2605
+ ) {
2606
+ return createSelectorTestCase((props) => (
2607
+ <AreaChart width={300} height={300} data={PageData}>
2608
+ <Area dataKey="pv" stackId="stack-1" name="Area-pv" id="area-pv" />
2609
+ <Area dataKey="uv" stackId="stack-1" name="Area-uv" id="area-uv" />
2610
+ <Area dataKey="amt" stackId="stack-1" name="Area-amt" id="area-amt" />
2611
+ <YAxis name="YAxis" />
2612
+ <XAxis dataKey="name" name="XAxis" />
2613
+ <Tooltip itemSorter={itemSorter} />
2614
+ {props.children}
2615
+ </AreaChart>
2616
+ ))(selector);
2617
+ }
2618
+
2619
+ describe("when itemSorter is undefined", () => {
2620
+ it("should render payload by name", () => {
2621
+ const { container } = renderTestCase(undefined);
2622
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2623
+ expectTooltipPayload(container, "Page D", [
2624
+ "Area-amt : 2400",
2625
+ "Area-pv : 9800",
2626
+ "Area-uv : 200",
2627
+ ]);
2628
+ });
2629
+
2630
+ it("should select payload sorted by name", () => {
2631
+ const { spy } = renderTestCase(undefined, (state) =>
2632
+ selectTooltipPayload(state, "axis", "hover", "0"),
2633
+ );
2634
+ expectLastCalledWith(spy, [
2635
+ {
2636
+ color: "#3182bd",
2637
+ dataKey: "pv",
2638
+ fill: "#3182bd",
2639
+ hide: false,
2640
+ name: "Area-pv",
2641
+ nameKey: undefined,
2642
+ payload: {
2643
+ amt: 2400,
2644
+ name: "Page A",
2645
+ pv: 2400,
2646
+ uv: 400,
2647
+ },
2648
+ stroke: "#3182bd",
2649
+ strokeWidth: 1,
2650
+ type: undefined,
2651
+ unit: undefined,
2652
+ value: 2400,
2653
+ graphicalItemId: "area-pv",
2654
+ },
2655
+ {
2656
+ color: "#3182bd",
2657
+ dataKey: "uv",
2658
+ fill: "#3182bd",
2659
+ hide: false,
2660
+ name: "Area-uv",
2661
+ nameKey: undefined,
2662
+ payload: {
2663
+ amt: 2400,
2664
+ name: "Page A",
2665
+ pv: 2400,
2666
+ uv: 400,
2667
+ },
2668
+ stroke: "#3182bd",
2669
+ strokeWidth: 1,
2670
+ type: undefined,
2671
+ unit: undefined,
2672
+ value: 400,
2673
+ graphicalItemId: "area-uv",
2674
+ },
2675
+ {
2676
+ color: "#3182bd",
2677
+ dataKey: "amt",
2678
+ fill: "#3182bd",
2679
+ hide: false,
2680
+ name: "Area-amt",
2681
+ nameKey: undefined,
2682
+ payload: {
2683
+ amt: 2400,
2684
+ name: "Page A",
2685
+ pv: 2400,
2686
+ uv: 400,
2687
+ },
2688
+ stroke: "#3182bd",
2689
+ strokeWidth: 1,
2690
+ type: undefined,
2691
+ unit: undefined,
2692
+ value: 2400,
2693
+ graphicalItemId: "area-amt",
2694
+ },
2695
+ ]);
2696
+ });
2697
+ });
2698
+
2699
+ describe("when itemSorter=`dataKey`", () => {
2700
+ it("should render sorted payload", () => {
2701
+ const { container } = renderTestCase("dataKey");
2702
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2703
+ expectTooltipPayload(container, "Page D", [
2704
+ "Area-amt : 2400",
2705
+ "Area-pv : 9800",
2706
+ "Area-uv : 200",
2707
+ ]);
2708
+ });
2709
+ });
2710
+
2711
+ describe("when itemSorter=`value`", () => {
2712
+ it("should render sorted payload", () => {
2713
+ const { container } = renderTestCase("value");
2714
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2715
+ expectTooltipPayload(container, "Page D", [
2716
+ "Area-uv : 200",
2717
+ "Area-amt : 2400",
2718
+ "Area-pv : 9800",
2719
+ ]);
2720
+ });
2721
+ });
2722
+
2723
+ describe("when itemSorter=`name`", () => {
2724
+ it("should render sorted payload", () => {
2725
+ const { container } = renderTestCase("name");
2726
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2727
+ expectTooltipPayload(container, "Page D", [
2728
+ "Area-amt : 2400",
2729
+ "Area-pv : 9800",
2730
+ "Area-uv : 200",
2731
+ ]);
2732
+ });
2733
+ });
2734
+
2735
+ describe("when itemSorter is a function", () => {
2736
+ it("should render sorted payload", () => {
2737
+ const { container } = renderTestCase((item) => String(item.value));
2738
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2739
+ expectTooltipPayload(container, "Page D", [
2740
+ "Area-uv : 200",
2741
+ "Area-amt : 2400",
2742
+ "Area-pv : 9800",
2743
+ ]);
2744
+ });
2745
+
2746
+ it("should call the function once for every payload item, and pass the item as an argument", () => {
2747
+ const spy = vi.fn();
2748
+ const { container } = renderTestCase(spy);
2749
+ expect(spy).toHaveBeenCalledTimes(0);
2750
+ showTooltip(container, barChartMouseHoverTooltipSelector);
2751
+ expect(spy).toHaveBeenCalledTimes(3);
2752
+ expect(spy).toHaveBeenNthCalledWith(1, {
2753
+ color: "#3182bd",
2754
+ dataKey: "pv",
2755
+ fill: "#3182bd",
2756
+ graphicalItemId: "area-pv",
2757
+ hide: false,
2758
+ name: "Area-pv",
2759
+ nameKey: undefined,
2760
+ payload: {
2761
+ amt: 2400,
2762
+ name: "Page D",
2763
+ pv: 9800,
2764
+ uv: 200,
2765
+ },
2766
+ stroke: "#3182bd",
2767
+ strokeWidth: 1,
2768
+ type: undefined,
2769
+ unit: undefined,
2770
+ value: 9800,
2771
+ });
2772
+ expect(spy).toHaveBeenNthCalledWith(2, {
2773
+ color: "#3182bd",
2774
+ dataKey: "uv",
2775
+ fill: "#3182bd",
2776
+ graphicalItemId: "area-uv",
2777
+ hide: false,
2778
+ name: "Area-uv",
2779
+ nameKey: undefined,
2780
+ payload: {
2781
+ amt: 2400,
2782
+ name: "Page D",
2783
+ pv: 9800,
2784
+ uv: 200,
2785
+ },
2786
+ stroke: "#3182bd",
2787
+ strokeWidth: 1,
2788
+ type: undefined,
2789
+ unit: undefined,
2790
+ value: 200,
2791
+ });
2792
+ expect(spy).toHaveBeenNthCalledWith(3, {
2793
+ color: "#3182bd",
2794
+ dataKey: "amt",
2795
+ fill: "#3182bd",
2796
+ graphicalItemId: "area-amt",
2797
+ hide: false,
2798
+ name: "Area-amt",
2799
+ nameKey: undefined,
2800
+ payload: {
2801
+ amt: 2400,
2802
+ name: "Page D",
2803
+ pv: 9800,
2804
+ uv: 200,
2805
+ },
2806
+ stroke: "#3182bd",
2807
+ strokeWidth: 1,
2808
+ type: undefined,
2809
+ unit: undefined,
2810
+ value: 2400,
2811
+ });
2812
+ });
2813
+ });
2814
+ });
2815
+ });