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.
- package/package.json +4 -6
- package/src/animation/AnimatedItems.tsx +4 -2
- package/src/animation/CSSTransitionAnimate.tsx +39 -41
- package/src/animation/JavascriptAnimate.tsx +41 -45
- package/src/cartesian/Area.tsx +4 -4
- package/src/cartesian/AreaRevealShape.tsx +1 -1
- package/src/cartesian/Bar.tsx +21 -33
- package/src/cartesian/BarStack.tsx +5 -5
- package/src/cartesian/Brush.tsx +15 -19
- package/src/cartesian/CartesianAxis.tsx +4 -4
- package/src/cartesian/CartesianGrid.tsx +5 -5
- package/src/cartesian/ErrorBar.tsx +7 -9
- package/src/cartesian/Funnel.tsx +3 -3
- package/src/cartesian/GraphicalItemClipPath.tsx +1 -1
- package/src/cartesian/Line.tsx +16 -18
- package/src/cartesian/LineDrawShape.tsx +13 -14
- package/src/cartesian/ReferenceArea.tsx +4 -4
- package/src/cartesian/ReferenceDot.tsx +4 -4
- package/src/cartesian/ReferenceLine.tsx +4 -4
- package/src/cartesian/RenderedTicksReporter.tsx +17 -19
- package/src/cartesian/Scatter.tsx +3 -3
- package/src/cartesian/XAxis.tsx +1 -1
- package/src/cartesian/YAxis.tsx +33 -35
- package/src/cartesian/ZAxis.tsx +2 -3
- package/src/chart/AreaChart.tsx +1 -1
- package/src/chart/BarChart.tsx +1 -1
- package/src/chart/CartesianChart.tsx +3 -4
- package/src/chart/CategoricalChart.tsx +5 -5
- package/src/chart/ComposedChart.tsx +1 -1
- package/src/chart/FunnelChart.tsx +1 -1
- package/src/chart/LineChart.tsx +1 -1
- package/src/chart/PieChart.tsx +3 -4
- package/src/chart/PolarChart.tsx +3 -4
- package/src/chart/RadarChart.tsx +3 -4
- package/src/chart/RadialBarChart.tsx +3 -7
- package/src/chart/RechartsWrapper.tsx +24 -14
- package/src/chart/Sankey.tsx +6 -9
- package/src/chart/ScatterChart.tsx +1 -1
- package/src/chart/SunburstChart.tsx +4 -5
- package/src/chart/Treemap.tsx +4 -5
- package/src/component/ActivePoints.tsx +6 -6
- package/src/component/Cell.tsx +5 -23
- package/src/component/Cursor.tsx +3 -3
- package/src/component/DefaultLegendContent.tsx +6 -8
- package/src/component/DefaultTooltipContent.tsx +10 -14
- package/src/component/Dots.tsx +5 -5
- package/src/component/Label.tsx +10 -13
- package/src/component/LabelList.tsx +7 -12
- package/src/component/Legend.tsx +21 -26
- package/src/component/ResponsiveContainer.tsx +49 -52
- package/src/component/Text.tsx +5 -5
- package/src/component/Tooltip.tsx +18 -21
- package/src/component/TooltipBoundingBox.tsx +16 -18
- package/src/component/responsiveContainerUtils.ts +1 -1
- package/src/container/ClipPathProvider.tsx +3 -3
- package/src/container/Layer.tsx +5 -5
- package/src/container/RootSurface.tsx +1 -1
- package/src/container/Surface.tsx +6 -5
- package/src/context/ErrorBarContext.tsx +2 -2
- package/src/context/PanoramaContext.tsx +2 -2
- package/src/context/RegisterGraphicalItemId.tsx +2 -4
- package/src/context/chartDataContext.tsx +23 -26
- package/src/context/chartLayoutContext.tsx +12 -16
- package/src/polar/Pie.tsx +12 -13
- package/src/polar/PolarAngleAxis.tsx +3 -3
- package/src/polar/PolarGrid.tsx +5 -5
- package/src/polar/PolarRadiusAxis.tsx +3 -3
- package/src/polar/Radar.tsx +3 -3
- package/src/polar/RadialBar.tsx +3 -3
- package/src/shape/Cross.tsx +5 -5
- package/src/shape/Curve.tsx +7 -6
- package/src/shape/Dot.tsx +4 -4
- package/src/shape/Polygon.tsx +5 -5
- package/src/shape/Rectangle.tsx +20 -22
- package/src/shape/Sector.tsx +5 -5
- package/src/shape/Symbols.tsx +5 -5
- package/src/shape/Trapezoid.tsx +27 -29
- package/src/state/RechartsStoreProvider.tsx +3 -5
- package/src/state/ReportChartProps.tsx +6 -8
- package/src/state/ReportEventSettings.tsx +6 -8
- package/src/state/ReportMainChartProps.tsx +9 -11
- package/src/state/ReportPolarOptions.tsx +13 -15
- package/src/state/SetLegendPayload.ts +1 -1
- package/src/state/SetTooltipEntrySettings.tsx +1 -1
- package/src/state/brushSlice.ts +8 -10
- package/src/state/cartesianAxisSlice.ts +38 -46
- package/src/state/chartDataSlice.ts +23 -29
- package/src/state/errorBarSlice.ts +16 -22
- package/src/state/eventSettingsSlice.ts +9 -11
- package/src/state/graphicalItemsSlice.ts +13 -17
- package/src/state/layoutSlice.ts +19 -27
- package/src/state/legendSlice.ts +18 -24
- package/src/state/optionsSlice.ts +6 -8
- package/src/state/polarAxisSlice.ts +13 -21
- package/src/state/polarOptionsSlice.ts +14 -16
- package/src/state/referenceElementsSlice.ts +19 -25
- package/src/state/registerInStore.ts +13 -15
- package/src/state/renderedTicksSlice.ts +7 -11
- package/src/state/rootPropsSlice.ts +14 -16
- package/src/state/tooltipSlice.ts +95 -115
- package/src/state/unregisterOnCleanup.ts +20 -5
- package/src/state/zIndexSlice.ts +42 -50
- package/src/synchronisation/useChartSynchronisation.tsx +217 -213
- package/src/util/ActiveShapeUtils.tsx +2 -2
- package/src/util/BarUtils.tsx +3 -5
- package/src/util/FunnelUtils.tsx +1 -1
- package/src/util/RadialBarUtils.tsx +3 -4
- package/src/util/createCartesianCharts.tsx +1 -1
- package/src/util/createPolarCharts.tsx +1 -1
- package/src/util/svgPropertiesAndEvents.ts +1 -1
- package/src/util/tooltip/translate.ts +2 -2
- package/src/util/types.ts +2 -2
- package/src/zIndex/ZIndexLayer.tsx +68 -39
- package/src/zIndex/ZIndexPortal.tsx +25 -29
- package/test/_data.ts +408 -0
- package/test/animation/AnimationController.typed.spec.ts +53 -0
- package/test/animation/AnimationControllerImpl.spec.ts +271 -0
- package/test/animation/CSSTransitionAnimate.timing.spec.tsx +473 -0
- package/test/animation/JavascriptAnimate.spec.tsx +62 -0
- package/test/animation/RechartsAnimation.spec.ts +636 -0
- package/test/animation/easing.spec.ts +218 -0
- package/test/animation/legacyAnimationLengthChange.spec.tsx +803 -0
- package/test/animation/matchBy.spec.ts +467 -0
- package/test/animation/mockAnimationController.ts +40 -0
- package/test/animation/mockControllerAnimationManager.ts +143 -0
- package/test/animation/mockTimeoutController.ts +114 -0
- package/test/animation/timeoutController.spec.ts +138 -0
- package/test/animation/useAnimationStartSnapshot.spec.ts +147 -0
- package/test/animation/util.spec.ts +28 -0
- package/test/cartesian/Area.animation.spec.tsx +363 -0
- package/test/cartesian/Area.range.spec.tsx +54 -0
- package/test/cartesian/Area.spec.tsx +1202 -0
- package/test/cartesian/Area.stacked.render.spec.tsx +69 -0
- package/test/cartesian/Area.typed.spec.tsx +209 -0
- package/test/cartesian/Axis.integration.spec.tsx +158 -0
- package/test/cartesian/Bar/Bar.csstransition.spec.tsx +299 -0
- package/test/cartesian/Bar/Bar.spec.tsx +2314 -0
- package/test/cartesian/Bar/Bar.typed.spec.tsx +192 -0
- package/test/cartesian/Bar.animation.spec.tsx +426 -0
- package/test/cartesian/Bar.stackDomain.spec.tsx +66 -0
- package/test/cartesian/Bar.stacked.render.spec.tsx +53 -0
- package/test/cartesian/Bar.truncateByDomain.spec.tsx +237 -0
- package/test/cartesian/Bar.zeroDimensionFiltering.spec.tsx +336 -0
- package/test/cartesian/BarStack.spec.tsx +91 -0
- package/test/cartesian/Brush.keyboard.spec.tsx +88 -0
- package/test/cartesian/Brush.panorama.spec.tsx +41 -0
- package/test/cartesian/Brush.props.spec.tsx +63 -0
- package/test/cartesian/Brush.render.spec.tsx +117 -0
- package/test/cartesian/Brush.spec.tsx +522 -0
- package/test/cartesian/Brush.stacked.spec.tsx +221 -0
- package/test/cartesian/CartesianAxis.render.spec.tsx +50 -0
- package/test/cartesian/CartesianAxis.spec.tsx +396 -0
- package/test/cartesian/CartesianGrid.render.spec.tsx +39 -0
- package/test/cartesian/CartesianGrid.spec.tsx +2103 -0
- package/test/cartesian/ErrorBar.render.spec.tsx +69 -0
- package/test/cartesian/ErrorBar.spec.tsx +2414 -0
- package/test/cartesian/Funnel.animation.spec.tsx +241 -0
- package/test/cartesian/Funnel.spec.tsx +226 -0
- package/test/cartesian/Funnel.typed.spec.tsx +221 -0
- package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +627 -0
- package/test/cartesian/GraphicalItemClipPath.spec.tsx +427 -0
- package/test/cartesian/Line.animation.spec.tsx +643 -0
- package/test/cartesian/Line.sparseAnimationPath.spec.tsx +98 -0
- package/test/cartesian/Line.spec.tsx +471 -0
- package/test/cartesian/Line.typed.spec.tsx +152 -0
- package/test/cartesian/ReferenceArea.render.spec.tsx +63 -0
- package/test/cartesian/ReferenceArea.spec.tsx +663 -0
- package/test/cartesian/ReferenceArea.typed.spec.tsx +74 -0
- package/test/cartesian/ReferenceDot.render.spec.tsx +55 -0
- package/test/cartesian/ReferenceDot.spec.tsx +462 -0
- package/test/cartesian/ReferenceDot.typed.spec.tsx +76 -0
- package/test/cartesian/ReferenceLine/ReferenceLine.panorama.spec.tsx +184 -0
- package/test/cartesian/ReferenceLine/ReferenceLine.spec.tsx +744 -0
- package/test/cartesian/ReferenceLine/ReferenceLine.typed.spec.tsx +74 -0
- package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +399 -0
- package/test/cartesian/ReferenceLine.render.spec.tsx +134 -0
- package/test/cartesian/Scatter.animation.spec.tsx +381 -0
- package/test/cartesian/Scatter.render.spec.tsx +61 -0
- package/test/cartesian/Scatter.spec.tsx +406 -0
- package/test/cartesian/Scatter.typed.spec.tsx +153 -0
- package/test/cartesian/XAxis/XAxis.barSize.spec.tsx +336 -0
- package/test/cartesian/XAxis/XAxis.brush.spec.tsx +266 -0
- package/test/cartesian/XAxis/XAxis.categorydomain.spec.tsx +872 -0
- package/test/cartesian/XAxis/XAxis.dataKey.spec.tsx +86 -0
- package/test/cartesian/XAxis/XAxis.datatypes.spec.tsx +127 -0
- package/test/cartesian/XAxis/XAxis.hide.spec.tsx +106 -0
- package/test/cartesian/XAxis/XAxis.multiaxis.spec.tsx +336 -0
- package/test/cartesian/XAxis/XAxis.numberdomain.spec.tsx +1466 -0
- package/test/cartesian/XAxis/XAxis.padding.spec.tsx +758 -0
- package/test/cartesian/XAxis/XAxis.padding_clip.spec.tsx +65 -0
- package/test/cartesian/XAxis/XAxis.state.spec.tsx +355 -0
- package/test/cartesian/XAxis/XAxis.tick.spec.tsx +493 -0
- package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +233 -0
- package/test/cartesian/XAxis/XAxis.type.spec.tsx +107 -0
- package/test/cartesian/XAxis/XAxis.typed.spec.tsx +102 -0
- package/test/cartesian/XAxis/XAxis.vertical.spec.tsx +265 -0
- package/test/cartesian/XAxis.tickFormatter.spec.tsx +54 -0
- package/test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx +230 -0
- package/test/cartesian/YAxis/YAxis.7362.spec.tsx +104 -0
- package/test/cartesian/YAxis/YAxis.interval-zero.spec.tsx +88 -0
- package/test/cartesian/YAxis/YAxis.label.spec.tsx +219 -0
- package/test/cartesian/YAxis/YAxis.spec.tsx +1595 -0
- package/test/cartesian/YAxis/YAxis.tick.spec.tsx +428 -0
- package/test/cartesian/YAxis/YAxis.tickFormatter.spec.tsx +54 -0
- package/test/cartesian/YAxis/YAxis.ticks.spec.tsx +263 -0
- package/test/cartesian/YAxis/YAxis.type.spec.tsx +107 -0
- package/test/cartesian/YAxis/YAxis.typed.spec.tsx +102 -0
- package/test/cartesian/ZAxis.spec.tsx +300 -0
- package/test/cartesian/ZAxis.typed.spec.tsx +33 -0
- package/test/cartesian/__snapshots__/Brush.spec.tsx.snap +5 -0
- package/test/cartesian/axisLineAndStroke.spec.tsx +72 -0
- package/test/cartesian/getCartesianPosition.spec.ts +907 -0
- package/test/cartesian/getEquidistantTicks.spec.ts +88 -0
- package/test/cartesian/getTicks.spec.ts +378 -0
- package/test/cartesian/miscFeatureGaps.spec.tsx +89 -0
- package/test/cartesian/useAnimatedLineLength.spec.ts +168 -0
- package/test/chart/AccessibilityLayer.spec.tsx +569 -0
- package/test/chart/AccessibilityScans.spec.tsx +286 -0
- package/test/chart/AreaChart.spec.tsx +409 -0
- package/test/chart/AreaChart.stacked.spec.tsx +1407 -0
- package/test/chart/AreaChart.typed.spec.tsx +39 -0
- package/test/chart/BarChart.spec.tsx +3719 -0
- package/test/chart/BarChart.typed.spec.tsx +60 -0
- package/test/chart/CategoricalChart.spec.tsx +255 -0
- package/test/chart/ComposedChart.spec.tsx +199 -0
- package/test/chart/ComposedChart.typed.spec.tsx +39 -0
- package/test/chart/FunnelChart.spec.tsx +215 -0
- package/test/chart/FunnelChart.typed.spec.tsx +39 -0
- package/test/chart/LineChart.multiseries.spec.tsx +50 -0
- package/test/chart/LineChart.smoke.spec.tsx +50 -0
- package/test/chart/LineChart.spec.tsx +930 -0
- package/test/chart/LineChart.typed.spec.tsx +39 -0
- package/test/chart/NicheChartTooltip.spec.tsx +81 -0
- package/test/chart/PieChart.spec.tsx +793 -0
- package/test/chart/PieChart.typed.spec.tsx +39 -0
- package/test/chart/RadarChart.spec.tsx +530 -0
- package/test/chart/RadarChart.typed.spec.tsx +39 -0
- package/test/chart/RadialBarChart.5966.spec.tsx +48 -0
- package/test/chart/RadialBarChart.spec.tsx +679 -0
- package/test/chart/RadialBarChart.typed.spec.tsx +39 -0
- package/test/chart/RechartsWrapper.spec.tsx +83 -0
- package/test/chart/Sankey.content.spec.tsx +46 -0
- package/test/chart/Sankey.spec.tsx +952 -0
- package/test/chart/Sankey.typed.spec.tsx +29 -0
- package/test/chart/ScatterChart.spec.tsx +2613 -0
- package/test/chart/ScatterChart.typed.spec.tsx +39 -0
- package/test/chart/SunburstChart.spec.tsx +146 -0
- package/test/chart/Treemap.animation.spec.tsx +52 -0
- package/test/chart/Treemap.spec.tsx +1003 -0
- package/test/chart/Treemap.typed.spec.tsx +26 -0
- package/test/chart/chartEvents.spec.tsx +127 -0
- package/test/chart/responsive.spec.tsx +620 -0
- package/test/component/Cell.render.spec.tsx +155 -0
- package/test/component/Cell.spec.tsx +12 -0
- package/test/component/Cursor.spec.tsx +186 -0
- package/test/component/DefaultTooltipContent.spec.tsx +102 -0
- package/test/component/Label.render.spec.tsx +63 -0
- package/test/component/Label.spec.tsx +686 -0
- package/test/component/Label.typed.spec.tsx +46 -0
- package/test/component/LabelList.spec.tsx +188 -0
- package/test/component/Legend.itemSorter.spec.tsx +704 -0
- package/test/component/Legend.render.spec.tsx +92 -0
- package/test/component/Legend.spec.tsx +2213 -0
- package/test/component/Legend.typed.spec.tsx +22 -0
- package/test/component/ResponsiveContainer.spec.tsx +523 -0
- package/test/component/ResponsiveContainerDataTest.spec.tsx +51 -0
- package/test/component/Text.spec.tsx +415 -0
- package/test/component/Text.typed.spec.tsx +46 -0
- package/test/component/Tooltip/ActiveDot.spec.tsx +370 -0
- package/test/component/Tooltip/Tooltip.animation.spec.tsx +209 -0
- package/test/component/Tooltip/Tooltip.content.spec.tsx +128 -0
- package/test/component/Tooltip/Tooltip.formatter.spec.tsx +152 -0
- package/test/component/Tooltip/Tooltip.includeHidden.spec.tsx +79 -0
- package/test/component/Tooltip/Tooltip.multipleDataArrays.spec.tsx +165 -0
- package/test/component/Tooltip/Tooltip.offset.spec.tsx +113 -0
- package/test/component/Tooltip/Tooltip.state.spec.tsx +74 -0
- package/test/component/Tooltip/Tooltip.sync.spec.tsx +639 -0
- package/test/component/Tooltip/defaultIndex.spec.tsx +227 -0
- package/test/component/Tooltip/graphicalItem.formatter.spec.tsx +138 -0
- package/test/component/Tooltip/itemSorter.spec.tsx +2815 -0
- package/test/component/Tooltip/tooltipEventType.spec.tsx +344 -0
- package/test/component/Tooltip/tooltipMouseHoverSelectors.ts +41 -0
- package/test/component/Tooltip/tooltipTestHelpers.tsx +162 -0
- package/test/component/Tooltip.defaultIndex.spec.tsx +48 -0
- package/test/component/Tooltip.hover.spec.tsx +61 -0
- package/test/component/Tooltip.item.spec.tsx +54 -0
- package/test/component/Tooltip.keyboard.spec.tsx +51 -0
- package/test/component/Tooltip.payload.spec.tsx +1716 -0
- package/test/component/Tooltip.touch.spec.tsx +39 -0
- package/test/component/Tooltip.visibility.spec.tsx +1889 -0
- package/test/component/TooltipBoundingBox.spec.tsx +89 -0
- package/test/component/responsiveContainerUtils.spec.ts +205 -0
- package/test/container/ClipPath.spec.tsx +602 -0
- package/test/container/chartDimensions.spec.tsx +368 -0
- package/test/context/chartLayoutContext.spec.tsx +378 -0
- package/test/helper/ExpectAxisDomain.tsx +27 -0
- package/test/helper/assertNotNull.ts +6 -0
- package/test/helper/assertZIndexLayerOrder.ts +19 -0
- package/test/helper/createSelectorTestCase.tsx +176 -0
- package/test/helper/expectAnimatedPieAngles.ts +100 -0
- package/test/helper/expectAnimatedPiePaths.ts +78 -0
- package/test/helper/expectAreaCurve.ts +15 -0
- package/test/helper/expectAxisTicks.ts +48 -0
- package/test/helper/expectBars.ts +54 -0
- package/test/helper/expectFunctionReturning.ts +58 -0
- package/test/helper/expectLabel.ts +32 -0
- package/test/helper/expectLastCalledWith.ts +48 -0
- package/test/helper/expectLine.ts +20 -0
- package/test/helper/expectPieSectors.ts +80 -0
- package/test/helper/expectScale.ts +37 -0
- package/test/helper/expectScatterPoints.ts +52 -0
- package/test/helper/expectStackGroups.ts +144 -0
- package/test/helper/mockAxes.ts +22 -0
- package/test/helper/mockGetBoundingClientRect.ts +66 -0
- package/test/helper/mockHTMLElementProperty.ts +19 -0
- package/test/helper/mockTouchingElement.ts +27 -0
- package/test/helper/offsetHelpers.ts +19 -0
- package/test/helper/parameterizedTestCases.tsx +99 -0
- package/test/helper/produceState.ts +32 -0
- package/test/helper/selectorTestHelpers.tsx +63 -0
- package/test/helper/trim.spec.ts +35 -0
- package/test/helper/trim.ts +11 -0
- package/test/hooks/useActiveTooltipDataPoints.spec.tsx +358 -0
- package/test/hooks/useAxisDomain.spec.tsx +361 -0
- package/test/hooks/useAxisScale.spec.tsx +283 -0
- package/test/hooks/useAxisTicks.spec.tsx +130 -0
- package/test/hooks/useOffset.spec.tsx +248 -0
- package/test/hooks/useTooltipStateHooks.spec.tsx +109 -0
- package/test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx +135 -0
- package/test/polar/Pie/Pie.spec.tsx +784 -0
- package/test/polar/Pie/Pie.typed.spec.tsx +78 -0
- package/test/polar/Pie.animation.spec.tsx +529 -0
- package/test/polar/PieWithLegend.animation.spec.tsx +142 -0
- package/test/polar/PolarAngleAxis/PolarAngleAxis.events.spec.tsx +76 -0
- package/test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx +2079 -0
- package/test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx +102 -0
- package/test/polar/PolarAngleAxis.render.spec.tsx +79 -0
- package/test/polar/PolarGrid.render.spec.tsx +75 -0
- package/test/polar/PolarGrid.spec.tsx +918 -0
- package/test/polar/PolarLegendPerRow.render.spec.tsx +85 -0
- package/test/polar/PolarRadiusAxis.events.spec.tsx +65 -0
- package/test/polar/PolarRadiusAxis.render.spec.tsx +52 -0
- package/test/polar/PolarRadiusAxis.spec.tsx +991 -0
- package/test/polar/PolarRadiusAxis.typed.spec.tsx +84 -0
- package/test/polar/PolarTooltipLegend.render.spec.tsx +80 -0
- package/test/polar/Radar.animation.spec.tsx +570 -0
- package/test/polar/Radar.render.spec.tsx +71 -0
- package/test/polar/Radar.spec.tsx +265 -0
- package/test/polar/Radar.typed.spec.tsx +119 -0
- package/test/polar/RadialBar/RadialBar.spec.tsx +1521 -0
- package/test/polar/RadialBar/RadialBar.typed.spec.tsx +132 -0
- package/test/polar/RadialBar.animation.spec.tsx +375 -0
- package/test/polar/RadialBar.render.spec.tsx +66 -0
- package/test/polar/RadialBar.stacked.spec.tsx +57 -0
- package/test/setup.ts +84 -0
- package/test/shape/ActiveShape.spec.tsx +181 -0
- package/test/shape/Cross.spec.tsx +60 -0
- package/test/shape/Cross.typed.spec.tsx +26 -0
- package/test/shape/Curve.spec.tsx +368 -0
- package/test/shape/Curve.typed.spec.tsx +69 -0
- package/test/shape/Dot.spec.tsx +73 -0
- package/test/shape/Dot.typed.spec.tsx +30 -0
- package/test/shape/Polygon.spec.tsx +357 -0
- package/test/shape/Polygon.typed.spec.tsx +28 -0
- package/test/shape/Rectangle.animation.spec.tsx +451 -0
- package/test/shape/Rectangle.spec.tsx +68 -0
- package/test/shape/Rectangle.typed.spec.tsx +24 -0
- package/test/shape/Sector.spec.tsx +76 -0
- package/test/shape/Sector.typed.spec.tsx +24 -0
- package/test/shape/Symbols.spec.tsx +43 -0
- package/test/shape/Symbols.typed.spec.tsx +24 -0
- package/test/shape/Trapezoid.spec.tsx +50 -0
- package/test/shape/Trapezoid.typed.spec.tsx +24 -0
- package/test/shape/__snapshots__/Cross.spec.tsx.snap +62 -0
- package/test/shape/__snapshots__/Curve.spec.tsx.snap +460 -0
- package/test/shape/__snapshots__/Polygon.spec.tsx.snap +58 -0
- package/test/shape/__snapshots__/Rectangle.spec.tsx.snap +117 -0
- package/test/shape/__snapshots__/Sector.spec.tsx.snap +71 -0
- package/test/shape/__snapshots__/Trapezoid.spec.tsx.snap +64 -0
- package/test/state/chartDataSlice.spec.ts +53 -0
- package/test/state/createCollectionActions.spec.ts +87 -0
- package/test/state/createSelector.spec.ts +158 -0
- package/test/state/externalEventsMiddleware.spec.ts +178 -0
- package/test/state/graphicalItemsSlice.spec.ts +92 -0
- package/test/state/hooks.spec.tsx +68 -0
- package/test/state/legendSlice.spec.ts +44 -0
- package/test/state/mouseEventsMiddleware.spec.ts +75 -0
- package/test/state/optionsSlice.spec.ts +19 -0
- package/test/state/referenceElementsSlice.spec.ts +84 -0
- package/test/state/registerInStore.spec.tsx +101 -0
- package/test/state/selectors/areaSelectors.spec.tsx +77 -0
- package/test/state/selectors/axisSelectors.spec.tsx +1418 -0
- package/test/state/selectors/barStackSelectors.spec.tsx +752 -0
- package/test/state/selectors/brushSelectors.spec.tsx +30 -0
- package/test/state/selectors/cartesianAxisSlice.spec.ts +96 -0
- package/test/state/selectors/combineNiceTicks.spec.ts +207 -0
- package/test/state/selectors/combiners/combineActiveTooltipIndex.spec.ts +61 -0
- package/test/state/selectors/combiners/combineAllBarPositions.spec.ts +39 -0
- package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +56 -0
- package/test/state/selectors/combiners/combineDisplayedStackedData.spec.ts +123 -0
- package/test/state/selectors/combiners/combineRealScaleType.spec.ts +80 -0
- package/test/state/selectors/containerSelectors.spec.tsx +168 -0
- package/test/state/selectors/dataSelectors.spec.tsx +136 -0
- package/test/state/selectors/legendSelectors.spec.tsx +113 -0
- package/test/state/selectors/lineSelectors.spec.tsx +60 -0
- package/test/state/selectors/pieSelectors.spec.tsx +72 -0
- package/test/state/selectors/radarSelectors.spec.tsx +496 -0
- package/test/state/selectors/rootPropsSelectors.spec.tsx +169 -0
- package/test/state/selectors/scatterSelectors.spec.tsx +47 -0
- package/test/state/selectors/selectActiveTooltipIndex.spec.tsx +234 -0
- package/test/state/selectors/selectAllAxes.spec.tsx +18 -0
- package/test/state/selectors/selectAxisDomain.spec.tsx +21 -0
- package/test/state/selectors/selectAxisDomainIncludingNiceTicks.spec.tsx +19 -0
- package/test/state/selectors/selectAxisRangeWithReverse.spec.tsx +22 -0
- package/test/state/selectors/selectAxisScale.spec.tsx +91 -0
- package/test/state/selectors/selectBarRectangles.stackOffset.spec.tsx +503 -0
- package/test/state/selectors/selectBaseAxis.spec.tsx +56 -0
- package/test/state/selectors/selectCartesianItemsSettings.spec.tsx +57 -0
- package/test/state/selectors/selectChartOffset.spec.tsx +26 -0
- package/test/state/selectors/selectDisplayedData.spec.tsx +282 -0
- package/test/state/selectors/selectIsTooltipActive.spec.tsx +231 -0
- package/test/state/selectors/selectNumericalDomain.spec.tsx +21 -0
- package/test/state/selectors/selectRealScaleType.spec.tsx +19 -0
- package/test/state/selectors/selectStackGroups.spec.tsx +322 -0
- package/test/state/selectors/selectXAxisPosition.spec.tsx +22 -0
- package/test/state/selectors/selectYAxisPosition.spec.tsx +22 -0
- package/test/state/selectors/selectorMemoization.spec.tsx +136 -0
- package/test/state/selectors/selectors.spec.tsx +1613 -0
- package/test/state/throttling.spec.ts +200 -0
- package/test/state/zIndexSlice.spec.ts +85 -0
- package/test/synchronisation/useChartSynchronisation.spec.tsx +225 -0
- package/test/util/BarUtils.spec.ts +39 -0
- package/test/util/CartesianUtils/CartesianUtils.spec.ts +261 -0
- package/test/util/CartesianUtils/rectWithPoints.spec.ts +48 -0
- package/test/util/ChartUtils/ChartUtils.spec.ts +491 -0
- package/test/util/ChartUtils/appendOffsetOfLegend.spec.ts +136 -0
- package/test/util/ChartUtils/appendOffsetOfLegend.spec.tsx +133 -0
- package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +97 -0
- package/test/util/ChartUtils/getStackedData.spec.ts +416 -0
- package/test/util/ChartUtils/truncateByDomain.spec.ts +70 -0
- package/test/util/DataUtils.spec.ts +385 -0
- package/test/util/DomUtils.spec.tsx +117 -0
- package/test/util/FunnelUtils.spec.tsx +70 -0
- package/test/util/Global.spec.ts +11 -0
- package/test/util/LRUCache.spec.ts +81 -0
- package/test/util/LogUtils.spec.ts +45 -0
- package/test/util/PolarUtils.spec.ts +66 -0
- package/test/util/ReduceCssCalcPrototype.spec.ts +141 -0
- package/test/util/ShallowEqual.spec.ts +102 -0
- package/test/util/TickUtils.spec.ts +29 -0
- package/test/util/createChartHelpers.spec.tsx +210 -0
- package/test/util/cursor/getCursorPoints.spec.ts +136 -0
- package/test/util/cursor/getCursorRectangle.spec.ts +50 -0
- package/test/util/cursor/getRadialCursorPoints.spec.ts +36 -0
- package/test/util/errorValue.spec.ts +69 -0
- package/test/util/getEveryNth.spec.ts +39 -0
- package/test/util/getRadiusAndStrokeWidthFromDot.spec.ts +51 -0
- package/test/util/getRelativeCoordinate.spec.ts +250 -0
- package/test/util/getSliced.spec.ts +45 -0
- package/test/util/isDomainSpecifiedByUser.spec.ts +207 -0
- package/test/util/isWellBehavedNumber.spec.ts +54 -0
- package/test/util/payload/getUniqPayload.spec.ts +56 -0
- package/test/util/propsAreEqual.spec.ts +75 -0
- package/test/util/round.spec.ts +112 -0
- package/test/util/scale/arithmetic.spec.ts +61 -0
- package/test/util/scale/createCategoricalInverse.spec.ts +84 -0
- package/test/util/scale/getNiceTickValues.spec.ts +421 -0
- package/test/util/scale/getTickValuesFixedDomain.spec.ts +155 -0
- package/test/util/svgPropertiesAndEvents.spec.tsx +206 -0
- package/test/util/svgPropertiesNoEvents.spec.tsx +228 -0
- package/test/util/tooltip/translate.spec.ts +396 -0
- package/test/util/useAnimationId.spec.tsx +59 -0
- package/test/util/useElementOffset.spec.tsx +173 -0
- package/test/util/usePrefersReducedMotion.spec.ts +54 -0
- package/test/util/useUniqueId.spec.ts +99 -0
- package/test/utils/diagnostics-allowlist.ts +18 -0
- package/test/utils/diagnostics.ts +58 -0
- package/test/zIndex/AllZIndexPortals.spec.tsx +83 -0
- package/test/zIndex/DefaultZIndexes.spec.ts +80 -0
- package/test/zIndex/DynamicZIndex.spec.tsx +102 -0
- package/test/zIndex/ZIndexLayer.portalOwner.spec.tsx +125 -0
- package/test/zIndex/componentZIndex.spec.tsx +255 -0
- package/test/zIndex/getZIndexFromUnknown.spec.ts +51 -0
- package/test/zIndex/multiChartZIndexIsolation.spec.tsx +90 -0
- package/test/zIndex/zIndexSelectors.spec.ts +172 -0
- package/test-results/.last-run.json +4 -0
- package/tsconfig.json +11 -0
- package/src/util/DirectPortal.tsx +0 -107
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
// Subset port of recharts 3.8.1 test/chart/Sankey.spec.tsx (commit 7a23854): the
|
|
2
|
+
// Sankey lays out nodes (Rectangles) + value-weighted link ribbons (paths) — one
|
|
3
|
+
// per data node / link. `flush()` because the chart size is reported via an effect
|
|
4
|
+
// before the layout computes.
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { createEffect, createSignal, flush } from "solid-js";
|
|
7
|
+
import { render, fireEvent } from "@solidjs/testing-library";
|
|
8
|
+
import { Sankey, Tooltip, XAxis, YAxis } from "../../src";
|
|
9
|
+
import { computeData, sankeyPayloadSearcher } from "../../src/chart/Sankey";
|
|
10
|
+
import type { SankeyLinkProps, SankeyNodeProps } from "../../src";
|
|
11
|
+
import { exampleSankeyData } from "../_data";
|
|
12
|
+
import { useChartHeight, useChartWidth, useViewBox } from "../../src/context/chartLayoutContext";
|
|
13
|
+
import { useClipPathId } from "../../src/container/ClipPathProvider";
|
|
14
|
+
import { assertNotNull } from "../helper/assertNotNull";
|
|
15
|
+
import {
|
|
16
|
+
sankeyLinkMouseHoverTooltipSelector,
|
|
17
|
+
sankeyNodeMouseHoverTooltipSelector,
|
|
18
|
+
} from "../component/Tooltip/tooltipMouseHoverSelectors";
|
|
19
|
+
import { getTooltip, showTooltip } from "../component/Tooltip/tooltipTestHelpers";
|
|
20
|
+
import { expectLastCalledWith } from "../helper/expectLastCalledWith";
|
|
21
|
+
import { mockTouchingElement } from "../helper/mockTouchingElement";
|
|
22
|
+
|
|
23
|
+
const data = {
|
|
24
|
+
nodes: [{ name: "A" }, { name: "B" }, { name: "C" }, { name: "D" }],
|
|
25
|
+
links: [
|
|
26
|
+
{ source: 0, target: 1, value: 10 },
|
|
27
|
+
{ source: 0, target: 2, value: 5 },
|
|
28
|
+
{ source: 1, target: 3, value: 8 },
|
|
29
|
+
{ source: 2, target: 3, value: 3 },
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const readSvgNumber = (element: Element, attribute: string): number =>
|
|
34
|
+
Number(element.getAttribute(attribute));
|
|
35
|
+
|
|
36
|
+
const getCubicPoint = (
|
|
37
|
+
start: number,
|
|
38
|
+
control1: number,
|
|
39
|
+
control2: number,
|
|
40
|
+
end: number,
|
|
41
|
+
t: number,
|
|
42
|
+
): number => {
|
|
43
|
+
const inverseT = 1 - t;
|
|
44
|
+
return (
|
|
45
|
+
inverseT ** 3 * start +
|
|
46
|
+
3 * inverseT ** 2 * t * control1 +
|
|
47
|
+
3 * inverseT * t ** 2 * control2 +
|
|
48
|
+
t ** 3 * end
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getLinkYAtX = (path: Element, x: number): number => {
|
|
53
|
+
const coordinates = path
|
|
54
|
+
.getAttribute("d")
|
|
55
|
+
?.match(/-?\d+(?:\.\d+)?/g)
|
|
56
|
+
?.map(Number);
|
|
57
|
+
|
|
58
|
+
if (coordinates == null) {
|
|
59
|
+
throw new Error("Expected Sankey link path to have coordinates");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const [
|
|
63
|
+
sourceX,
|
|
64
|
+
sourceY,
|
|
65
|
+
sourceControlX,
|
|
66
|
+
sourceControlY,
|
|
67
|
+
targetControlX,
|
|
68
|
+
targetControlY,
|
|
69
|
+
targetX,
|
|
70
|
+
targetY,
|
|
71
|
+
] = coordinates;
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
sourceX == null ||
|
|
75
|
+
sourceY == null ||
|
|
76
|
+
sourceControlX == null ||
|
|
77
|
+
sourceControlY == null ||
|
|
78
|
+
targetControlX == null ||
|
|
79
|
+
targetControlY == null ||
|
|
80
|
+
targetX == null ||
|
|
81
|
+
targetY == null
|
|
82
|
+
) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Expected Sankey link path to have at least 8 coordinates, got ${coordinates.length}`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let minT = 0;
|
|
89
|
+
let maxT = 1;
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < 30; i++) {
|
|
92
|
+
const middleT = (minT + maxT) / 2;
|
|
93
|
+
const middleX = getCubicPoint(sourceX, sourceControlX, targetControlX, targetX, middleT);
|
|
94
|
+
|
|
95
|
+
if (middleX < x) {
|
|
96
|
+
minT = middleT;
|
|
97
|
+
} else {
|
|
98
|
+
maxT = middleT;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const t = (minT + maxT) / 2;
|
|
103
|
+
return getCubicPoint(sourceY, sourceControlY, targetControlY, targetY, t);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
describe("<Sankey />", () => {
|
|
107
|
+
it("renders one node rect per node and one link path per link", () => {
|
|
108
|
+
const { container } = render(() => <Sankey width={600} height={400} data={data} />);
|
|
109
|
+
flush();
|
|
110
|
+
|
|
111
|
+
expect(container.querySelectorAll(".recharts-sankey-node")).toHaveLength(data.nodes.length);
|
|
112
|
+
expect(container.querySelectorAll(".recharts-sankey-link")).toHaveLength(data.links.length);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("draws nodes at the default nodeWidth and links with a cubic-Bézier path", () => {
|
|
116
|
+
const { container } = render(() => <Sankey width={600} height={400} data={data} />);
|
|
117
|
+
flush();
|
|
118
|
+
|
|
119
|
+
const node = container.querySelector(".recharts-sankey-node");
|
|
120
|
+
expect(node).not.toBeNull();
|
|
121
|
+
// Default nodeWidth is 10.
|
|
122
|
+
expect(Number(node!.getAttribute("width"))).toBe(10);
|
|
123
|
+
|
|
124
|
+
const link = container.querySelector(".recharts-sankey-link");
|
|
125
|
+
expect(link).not.toBeNull();
|
|
126
|
+
// The ribbon is a cubic curve (M…C…).
|
|
127
|
+
expect(link!.getAttribute("d")).toMatch(/^M[\d.,-]+C/);
|
|
128
|
+
expect(Number(link!.getAttribute("stroke-width"))).toBeGreaterThan(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("fires onClick with the clicked node and its type", () => {
|
|
132
|
+
const onClick = vi.fn();
|
|
133
|
+
const { container } = render(() => (
|
|
134
|
+
<Sankey width={600} height={400} data={data} onClick={onClick} />
|
|
135
|
+
));
|
|
136
|
+
flush();
|
|
137
|
+
|
|
138
|
+
fireEvent.click(container.querySelector(".recharts-sankey-node")!);
|
|
139
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
140
|
+
expect(onClick.mock.calls[0]![1]).toBe("node");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("renders 48 nodes in simple SankeyChart", () => {
|
|
144
|
+
const { container } = render(() => (
|
|
145
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} />
|
|
146
|
+
));
|
|
147
|
+
flush();
|
|
148
|
+
|
|
149
|
+
expect(container.querySelectorAll(".recharts-sankey-node")).toHaveLength(48);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("renders 68 links in simple SankeyChart", () => {
|
|
153
|
+
const { container } = render(() => (
|
|
154
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} />
|
|
155
|
+
));
|
|
156
|
+
flush();
|
|
157
|
+
|
|
158
|
+
expect(container.querySelectorAll(".recharts-sankey-link")).toHaveLength(68);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("re-renders links and nodes when data changes", () => {
|
|
162
|
+
const [data2, setData2] = createSignal(exampleSankeyData);
|
|
163
|
+
const { container } = render(() => <Sankey width={1000} height={500} data={data2()} />);
|
|
164
|
+
flush();
|
|
165
|
+
|
|
166
|
+
expect(container.querySelectorAll(".recharts-sankey-node")).toHaveLength(48);
|
|
167
|
+
expect(container.querySelectorAll(".recharts-sankey-link")).toHaveLength(68);
|
|
168
|
+
|
|
169
|
+
setData2({
|
|
170
|
+
nodes: [...exampleSankeyData.nodes, { name: "New Node" }],
|
|
171
|
+
links: [
|
|
172
|
+
...exampleSankeyData.links,
|
|
173
|
+
{ source: 2, target: exampleSankeyData.nodes.length, value: 100.0 },
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
flush();
|
|
177
|
+
|
|
178
|
+
expect(container.querySelectorAll(".recharts-sankey-node")).toHaveLength(49);
|
|
179
|
+
expect(container.querySelectorAll(".recharts-sankey-link")).toHaveLength(69);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("Sankey layout context", () => {
|
|
183
|
+
it("should provide viewBox, but not clipPathId", () => {
|
|
184
|
+
const clipPathSpy = vi.fn();
|
|
185
|
+
const viewBoxSpy = vi.fn();
|
|
186
|
+
const Comp = (): null => {
|
|
187
|
+
clipPathSpy(useClipPathId());
|
|
188
|
+
const viewBox = useViewBox();
|
|
189
|
+
createEffect(
|
|
190
|
+
() => viewBox(),
|
|
191
|
+
(v) => viewBoxSpy(v),
|
|
192
|
+
);
|
|
193
|
+
return null;
|
|
194
|
+
};
|
|
195
|
+
render(() => (
|
|
196
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
197
|
+
<Comp />
|
|
198
|
+
</Sankey>
|
|
199
|
+
));
|
|
200
|
+
flush();
|
|
201
|
+
expect(clipPathSpy).toHaveBeenLastCalledWith(undefined);
|
|
202
|
+
expect(viewBoxSpy).toHaveBeenLastCalledWith({ x: 5, y: 5, width: 990, height: 490 });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("should set width and height in context", () => {
|
|
206
|
+
const widthSpy = vi.fn();
|
|
207
|
+
const heightSpy = vi.fn();
|
|
208
|
+
const Comp = (): null => {
|
|
209
|
+
const width = useChartWidth();
|
|
210
|
+
const height = useChartHeight();
|
|
211
|
+
createEffect(
|
|
212
|
+
() => width(),
|
|
213
|
+
(v) => widthSpy(v),
|
|
214
|
+
);
|
|
215
|
+
createEffect(
|
|
216
|
+
() => height(),
|
|
217
|
+
(v) => heightSpy(v),
|
|
218
|
+
);
|
|
219
|
+
return null;
|
|
220
|
+
};
|
|
221
|
+
render(() => (
|
|
222
|
+
<Sankey width={100} height={50} data={exampleSankeyData}>
|
|
223
|
+
<Comp />
|
|
224
|
+
</Sankey>
|
|
225
|
+
));
|
|
226
|
+
flush();
|
|
227
|
+
expect(widthSpy).toHaveBeenLastCalledWith(100);
|
|
228
|
+
expect(heightSpy).toHaveBeenLastCalledWith(50);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("should not throw if axes are provided - they are not an allowed child anyway", () => {
|
|
232
|
+
expect(() =>
|
|
233
|
+
render(() => (
|
|
234
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
235
|
+
<XAxis dataKey="number" type="number" />
|
|
236
|
+
<YAxis type="category" dataKey="name" />
|
|
237
|
+
</Sankey>
|
|
238
|
+
)),
|
|
239
|
+
).not.toThrow();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("with Tooltip trigger=hover", () => {
|
|
244
|
+
it("should display Tooltip on mouse enter on Link and hide it on mouse leave", () => {
|
|
245
|
+
const { container } = render(() => (
|
|
246
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
247
|
+
<XAxis dataKey="number" type="number" />
|
|
248
|
+
<YAxis type="category" dataKey="name" />
|
|
249
|
+
<Tooltip trigger="hover" />
|
|
250
|
+
</Sankey>
|
|
251
|
+
));
|
|
252
|
+
flush();
|
|
253
|
+
|
|
254
|
+
const tooltip = getTooltip(container);
|
|
255
|
+
expect(tooltip).not.toBeVisible();
|
|
256
|
+
|
|
257
|
+
const tooltipTriggerElement = showTooltip(container, sankeyLinkMouseHoverTooltipSelector);
|
|
258
|
+
|
|
259
|
+
expect(tooltip).toBeVisible();
|
|
260
|
+
|
|
261
|
+
fireEvent.mouseOut(tooltipTriggerElement);
|
|
262
|
+
|
|
263
|
+
expect(tooltip).not.toBeVisible();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("should display Tooltip on mouse enter on a Node and hide it on mouse leave", () => {
|
|
267
|
+
const { container } = render(() => (
|
|
268
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
269
|
+
<XAxis dataKey="number" type="number" />
|
|
270
|
+
<YAxis type="category" dataKey="name" />
|
|
271
|
+
<Tooltip trigger="hover" />
|
|
272
|
+
</Sankey>
|
|
273
|
+
));
|
|
274
|
+
flush();
|
|
275
|
+
|
|
276
|
+
const tooltip = getTooltip(container);
|
|
277
|
+
expect(tooltip).not.toBeVisible();
|
|
278
|
+
|
|
279
|
+
const tooltipTriggerElement = showTooltip(container, sankeyNodeMouseHoverTooltipSelector);
|
|
280
|
+
|
|
281
|
+
expect(tooltip).toBeVisible();
|
|
282
|
+
|
|
283
|
+
fireEvent.mouseOut(tooltipTriggerElement);
|
|
284
|
+
|
|
285
|
+
expect(tooltip).not.toBeVisible();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("should not display Tooltip when clicking on a Link", () => {
|
|
289
|
+
const { container } = render(() => (
|
|
290
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
291
|
+
<XAxis dataKey="number" type="number" />
|
|
292
|
+
<YAxis type="category" dataKey="name" />
|
|
293
|
+
<Tooltip trigger="hover" />
|
|
294
|
+
</Sankey>
|
|
295
|
+
));
|
|
296
|
+
flush();
|
|
297
|
+
|
|
298
|
+
const tooltip = getTooltip(container);
|
|
299
|
+
const tooltipTriggerElement = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
300
|
+
assertNotNull(tooltipTriggerElement);
|
|
301
|
+
expect(tooltip).not.toBeVisible();
|
|
302
|
+
|
|
303
|
+
fireEvent.click(tooltipTriggerElement);
|
|
304
|
+
flush();
|
|
305
|
+
|
|
306
|
+
expect(tooltip).not.toBeVisible();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("should not display Tooltip when clicking on a Node", () => {
|
|
310
|
+
const { container } = render(() => (
|
|
311
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
312
|
+
<XAxis dataKey="number" type="number" />
|
|
313
|
+
<YAxis type="category" dataKey="name" />
|
|
314
|
+
<Tooltip trigger="hover" />
|
|
315
|
+
</Sankey>
|
|
316
|
+
));
|
|
317
|
+
flush();
|
|
318
|
+
|
|
319
|
+
const tooltip = getTooltip(container);
|
|
320
|
+
const tooltipTriggerElement = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
321
|
+
assertNotNull(tooltipTriggerElement);
|
|
322
|
+
expect(tooltip).not.toBeVisible();
|
|
323
|
+
|
|
324
|
+
fireEvent.click(tooltipTriggerElement);
|
|
325
|
+
flush();
|
|
326
|
+
|
|
327
|
+
expect(tooltip).not.toBeVisible();
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("with Tooltip trigger=click", () => {
|
|
332
|
+
it("should display Tooltip on mouse click on Link and keep it on second click", () => {
|
|
333
|
+
const { container } = render(() => (
|
|
334
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
335
|
+
<XAxis dataKey="number" type="number" />
|
|
336
|
+
<YAxis type="category" dataKey="name" />
|
|
337
|
+
<Tooltip trigger="click" />
|
|
338
|
+
</Sankey>
|
|
339
|
+
));
|
|
340
|
+
flush();
|
|
341
|
+
|
|
342
|
+
const tooltip = getTooltip(container);
|
|
343
|
+
expect(tooltip).not.toBeVisible();
|
|
344
|
+
|
|
345
|
+
const tooltipTriggerElement = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
346
|
+
assertNotNull(tooltipTriggerElement);
|
|
347
|
+
fireEvent.click(tooltipTriggerElement);
|
|
348
|
+
flush();
|
|
349
|
+
|
|
350
|
+
expect(tooltip).toBeVisible();
|
|
351
|
+
|
|
352
|
+
fireEvent.click(tooltipTriggerElement);
|
|
353
|
+
flush();
|
|
354
|
+
|
|
355
|
+
expect(tooltip).toBeVisible();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should display Tooltip on mouse enter on a Node and keep it on mouse leave", () => {
|
|
359
|
+
const { container } = render(() => (
|
|
360
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
361
|
+
<XAxis dataKey="number" type="number" />
|
|
362
|
+
<YAxis type="category" dataKey="name" />
|
|
363
|
+
<Tooltip trigger="click" />
|
|
364
|
+
</Sankey>
|
|
365
|
+
));
|
|
366
|
+
flush();
|
|
367
|
+
|
|
368
|
+
const tooltip = getTooltip(container);
|
|
369
|
+
expect(tooltip).not.toBeVisible();
|
|
370
|
+
|
|
371
|
+
const tooltipTriggerElement = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
372
|
+
assertNotNull(tooltipTriggerElement);
|
|
373
|
+
fireEvent.click(tooltipTriggerElement);
|
|
374
|
+
flush();
|
|
375
|
+
|
|
376
|
+
expect(tooltip).toBeVisible();
|
|
377
|
+
|
|
378
|
+
fireEvent.click(tooltipTriggerElement);
|
|
379
|
+
flush();
|
|
380
|
+
|
|
381
|
+
expect(tooltip).toBeVisible();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("should do nothing on hover over Link or Node", () => {
|
|
385
|
+
const { container } = render(() => (
|
|
386
|
+
<Sankey width={1000} height={500} data={exampleSankeyData}>
|
|
387
|
+
<XAxis dataKey="number" type="number" />
|
|
388
|
+
<YAxis type="category" dataKey="name" />
|
|
389
|
+
<Tooltip trigger="click" />
|
|
390
|
+
</Sankey>
|
|
391
|
+
));
|
|
392
|
+
flush();
|
|
393
|
+
|
|
394
|
+
const tooltip = getTooltip(container);
|
|
395
|
+
showTooltip(container, sankeyLinkMouseHoverTooltipSelector);
|
|
396
|
+
showTooltip(container, sankeyNodeMouseHoverTooltipSelector);
|
|
397
|
+
expect(tooltip).not.toBeVisible();
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
describe("events", () => {
|
|
402
|
+
it("should call onClick handler on links", () => {
|
|
403
|
+
const onClick = vi.fn();
|
|
404
|
+
const { container } = render(() => (
|
|
405
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} onClick={onClick} />
|
|
406
|
+
));
|
|
407
|
+
flush();
|
|
408
|
+
|
|
409
|
+
const link = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
410
|
+
assertNotNull(link);
|
|
411
|
+
|
|
412
|
+
fireEvent.click(link, { clientX: 200, clientY: 200 });
|
|
413
|
+
flush();
|
|
414
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
415
|
+
const expectedLinkProps: SankeyLinkProps = {
|
|
416
|
+
index: 0,
|
|
417
|
+
linkWidth: 13.172337974085991,
|
|
418
|
+
payload: {
|
|
419
|
+
dy: 13.172337974085991,
|
|
420
|
+
source: {
|
|
421
|
+
depth: 0,
|
|
422
|
+
dx: 10,
|
|
423
|
+
dy: 13.172337974085991,
|
|
424
|
+
name: "Agricultural waste",
|
|
425
|
+
sourceLinks: [],
|
|
426
|
+
sourceNodes: [],
|
|
427
|
+
targetLinks: [0],
|
|
428
|
+
targetNodes: [1],
|
|
429
|
+
value: 124.729,
|
|
430
|
+
x: 0,
|
|
431
|
+
y: 127.92976245668771,
|
|
432
|
+
},
|
|
433
|
+
sy: 0,
|
|
434
|
+
target: {
|
|
435
|
+
depth: 1,
|
|
436
|
+
dx: 10,
|
|
437
|
+
dy: 41.07345963305562,
|
|
438
|
+
name: "Bio-conversion",
|
|
439
|
+
sourceLinks: [65, 0, 51, 44],
|
|
440
|
+
sourceNodes: [0, 34, 39, 45],
|
|
441
|
+
targetLinks: [2, 3, 4, 1],
|
|
442
|
+
targetNodes: [2, 3, 4, 5],
|
|
443
|
+
value: 388.925,
|
|
444
|
+
x: 140,
|
|
445
|
+
y: 113.96304660380619,
|
|
446
|
+
},
|
|
447
|
+
ty: 19.221650415407733,
|
|
448
|
+
value: 124.729,
|
|
449
|
+
},
|
|
450
|
+
sourceControlX: 80,
|
|
451
|
+
sourceRelativeY: 0,
|
|
452
|
+
sourceX: 15,
|
|
453
|
+
sourceY: 139.51593144373072,
|
|
454
|
+
targetControlX: 80,
|
|
455
|
+
targetRelativeY: 19.221650415407733,
|
|
456
|
+
targetX: 145,
|
|
457
|
+
targetY: 144.77086600625694,
|
|
458
|
+
};
|
|
459
|
+
expectLastCalledWith(
|
|
460
|
+
onClick,
|
|
461
|
+
expectedLinkProps,
|
|
462
|
+
"link",
|
|
463
|
+
expect.objectContaining({ type: "click" }) as never,
|
|
464
|
+
);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("should call onClick handler on nodes", () => {
|
|
468
|
+
const onClick = vi.fn();
|
|
469
|
+
const { container } = render(() => (
|
|
470
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} onClick={onClick} />
|
|
471
|
+
));
|
|
472
|
+
flush();
|
|
473
|
+
|
|
474
|
+
const node = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
475
|
+
assertNotNull(node);
|
|
476
|
+
|
|
477
|
+
fireEvent.click(node, { clientX: 200, clientY: 200 });
|
|
478
|
+
flush();
|
|
479
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
480
|
+
const expectedNodeProps: SankeyNodeProps = {
|
|
481
|
+
height: 13.172337974085991,
|
|
482
|
+
index: 0,
|
|
483
|
+
payload: {
|
|
484
|
+
depth: 0,
|
|
485
|
+
dx: 10,
|
|
486
|
+
dy: 13.172337974085991,
|
|
487
|
+
name: "Agricultural waste",
|
|
488
|
+
sourceLinks: [],
|
|
489
|
+
sourceNodes: [],
|
|
490
|
+
targetLinks: [0],
|
|
491
|
+
targetNodes: [1],
|
|
492
|
+
value: 124.729,
|
|
493
|
+
x: 0,
|
|
494
|
+
y: 127.92976245668771,
|
|
495
|
+
},
|
|
496
|
+
width: 10,
|
|
497
|
+
x: 5,
|
|
498
|
+
y: 132.9297624566877,
|
|
499
|
+
};
|
|
500
|
+
expectLastCalledWith(
|
|
501
|
+
onClick,
|
|
502
|
+
expectedNodeProps,
|
|
503
|
+
"node",
|
|
504
|
+
expect.objectContaining({ type: "click" }) as never,
|
|
505
|
+
);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("should call onMouseEnter and onMouseLeave handlers on links", () => {
|
|
509
|
+
const onMouseEnter = vi.fn();
|
|
510
|
+
const onMouseLeave = vi.fn();
|
|
511
|
+
const { container } = render(() => (
|
|
512
|
+
<Sankey
|
|
513
|
+
width={1000}
|
|
514
|
+
height={500}
|
|
515
|
+
data={exampleSankeyData}
|
|
516
|
+
onMouseEnter={onMouseEnter}
|
|
517
|
+
onMouseLeave={onMouseLeave}
|
|
518
|
+
/>
|
|
519
|
+
));
|
|
520
|
+
flush();
|
|
521
|
+
|
|
522
|
+
const link = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
523
|
+
assertNotNull(link);
|
|
524
|
+
|
|
525
|
+
fireEvent.mouseEnter(link, { clientX: 200, clientY: 200 });
|
|
526
|
+
flush();
|
|
527
|
+
expect(onMouseEnter).toHaveBeenCalledTimes(1);
|
|
528
|
+
const expectedLinkProps: SankeyLinkProps = {
|
|
529
|
+
sourceX: 15,
|
|
530
|
+
targetX: 145,
|
|
531
|
+
sourceY: 139.51593144373072,
|
|
532
|
+
targetY: 144.77086600625694,
|
|
533
|
+
sourceControlX: 80,
|
|
534
|
+
targetControlX: 80,
|
|
535
|
+
sourceRelativeY: 0,
|
|
536
|
+
targetRelativeY: 19.221650415407733,
|
|
537
|
+
linkWidth: 13.172337974085991,
|
|
538
|
+
index: 0,
|
|
539
|
+
payload: {
|
|
540
|
+
source: {
|
|
541
|
+
name: "Agricultural waste",
|
|
542
|
+
sourceNodes: [],
|
|
543
|
+
sourceLinks: [],
|
|
544
|
+
targetLinks: [0],
|
|
545
|
+
targetNodes: [1],
|
|
546
|
+
value: 124.729,
|
|
547
|
+
depth: 0,
|
|
548
|
+
x: 0,
|
|
549
|
+
dx: 10,
|
|
550
|
+
y: 127.92976245668771,
|
|
551
|
+
dy: 13.172337974085991,
|
|
552
|
+
},
|
|
553
|
+
target: {
|
|
554
|
+
name: "Bio-conversion",
|
|
555
|
+
sourceNodes: [0, 34, 39, 45],
|
|
556
|
+
sourceLinks: [65, 0, 51, 44],
|
|
557
|
+
targetLinks: [2, 3, 4, 1],
|
|
558
|
+
targetNodes: [2, 3, 4, 5],
|
|
559
|
+
value: 388.925,
|
|
560
|
+
depth: 1,
|
|
561
|
+
x: 140,
|
|
562
|
+
dx: 10,
|
|
563
|
+
y: 113.96304660380619,
|
|
564
|
+
dy: 41.07345963305562,
|
|
565
|
+
},
|
|
566
|
+
value: 124.729,
|
|
567
|
+
dy: 13.172337974085991,
|
|
568
|
+
sy: 0,
|
|
569
|
+
ty: 19.221650415407733,
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
expectLastCalledWith(
|
|
573
|
+
onMouseEnter,
|
|
574
|
+
expectedLinkProps,
|
|
575
|
+
"link",
|
|
576
|
+
expect.objectContaining({ type: "mouseenter" }) as never,
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
fireEvent.mouseLeave(link);
|
|
580
|
+
flush();
|
|
581
|
+
expect(onMouseLeave).toHaveBeenCalledTimes(1);
|
|
582
|
+
expectLastCalledWith(
|
|
583
|
+
onMouseLeave,
|
|
584
|
+
expectedLinkProps,
|
|
585
|
+
"link",
|
|
586
|
+
expect.objectContaining({ type: "mouseleave" }) as never,
|
|
587
|
+
);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("should do nothing onMouseMove on links", () => {
|
|
591
|
+
const onMouseMove = vi.fn();
|
|
592
|
+
const { container } = render(() => (
|
|
593
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} onMouseMove={onMouseMove} />
|
|
594
|
+
));
|
|
595
|
+
flush();
|
|
596
|
+
|
|
597
|
+
const link = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
598
|
+
assertNotNull(link);
|
|
599
|
+
|
|
600
|
+
fireEvent.mouseMove(link, { clientX: 200, clientY: 200 });
|
|
601
|
+
flush();
|
|
602
|
+
expect(onMouseMove).toHaveBeenCalledTimes(0);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it("should call onMouseEnter and onMouseLeave handlers on nodes", () => {
|
|
606
|
+
const onMouseEnter = vi.fn();
|
|
607
|
+
const onMouseLeave = vi.fn();
|
|
608
|
+
const { container } = render(() => (
|
|
609
|
+
<Sankey
|
|
610
|
+
width={1000}
|
|
611
|
+
height={500}
|
|
612
|
+
data={exampleSankeyData}
|
|
613
|
+
onMouseEnter={onMouseEnter}
|
|
614
|
+
onMouseLeave={onMouseLeave}
|
|
615
|
+
/>
|
|
616
|
+
));
|
|
617
|
+
flush();
|
|
618
|
+
|
|
619
|
+
const node = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
620
|
+
assertNotNull(node);
|
|
621
|
+
|
|
622
|
+
fireEvent.mouseEnter(node, { clientX: 200, clientY: 200 });
|
|
623
|
+
flush();
|
|
624
|
+
expect(onMouseEnter).toHaveBeenCalledTimes(1);
|
|
625
|
+
const expectedNodeProps: SankeyNodeProps = {
|
|
626
|
+
height: 13.172337974085991,
|
|
627
|
+
index: 0,
|
|
628
|
+
payload: {
|
|
629
|
+
name: "Agricultural waste",
|
|
630
|
+
sourceNodes: [],
|
|
631
|
+
sourceLinks: [],
|
|
632
|
+
targetLinks: [0],
|
|
633
|
+
targetNodes: [1],
|
|
634
|
+
value: 124.729,
|
|
635
|
+
depth: 0,
|
|
636
|
+
x: 0,
|
|
637
|
+
dx: 10,
|
|
638
|
+
y: 127.92976245668771,
|
|
639
|
+
dy: 13.172337974085991,
|
|
640
|
+
},
|
|
641
|
+
width: 10,
|
|
642
|
+
x: 5,
|
|
643
|
+
y: 132.9297624566877,
|
|
644
|
+
};
|
|
645
|
+
expectLastCalledWith(
|
|
646
|
+
onMouseEnter,
|
|
647
|
+
expectedNodeProps,
|
|
648
|
+
"node",
|
|
649
|
+
expect.objectContaining({ type: "mouseenter" }) as never,
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
fireEvent.mouseLeave(node);
|
|
653
|
+
flush();
|
|
654
|
+
expect(onMouseLeave).toHaveBeenCalledTimes(1);
|
|
655
|
+
expectLastCalledWith(
|
|
656
|
+
onMouseLeave,
|
|
657
|
+
expectedNodeProps,
|
|
658
|
+
"node",
|
|
659
|
+
expect.objectContaining({ type: "mouseleave" }) as never,
|
|
660
|
+
);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("should do nothing onMouseMove on nodes", () => {
|
|
664
|
+
const onMouseMove = vi.fn();
|
|
665
|
+
const { container } = render(() => (
|
|
666
|
+
<Sankey width={1000} height={500} data={exampleSankeyData} onMouseMove={onMouseMove} />
|
|
667
|
+
));
|
|
668
|
+
flush();
|
|
669
|
+
|
|
670
|
+
const node = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
671
|
+
assertNotNull(node);
|
|
672
|
+
|
|
673
|
+
fireEvent.mouseMove(node, { clientX: 200, clientY: 200 });
|
|
674
|
+
flush();
|
|
675
|
+
expect(onMouseMove).toHaveBeenCalledTimes(0);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
it("should do nothing onTouchMove on links", () => {
|
|
679
|
+
mockTouchingElement("1", "a");
|
|
680
|
+
const onTouchMove = vi.fn();
|
|
681
|
+
const onTouchEnd = vi.fn();
|
|
682
|
+
const { container } = render(() => (
|
|
683
|
+
<Sankey
|
|
684
|
+
width={1000}
|
|
685
|
+
height={500}
|
|
686
|
+
data={exampleSankeyData}
|
|
687
|
+
onTouchMove={onTouchMove}
|
|
688
|
+
onTouchEnd={onTouchEnd}
|
|
689
|
+
/>
|
|
690
|
+
));
|
|
691
|
+
flush();
|
|
692
|
+
|
|
693
|
+
const link = container.querySelector(sankeyLinkMouseHoverTooltipSelector);
|
|
694
|
+
assertNotNull(link);
|
|
695
|
+
|
|
696
|
+
fireEvent.touchMove(link, { touches: [{ clientX: 200, clientY: 200 }] });
|
|
697
|
+
flush();
|
|
698
|
+
expect(onTouchMove).toHaveBeenCalledTimes(0);
|
|
699
|
+
|
|
700
|
+
fireEvent.touchEnd(link, { changedTouches: [{ clientX: 200, clientY: 200 }] });
|
|
701
|
+
flush();
|
|
702
|
+
expect(onTouchEnd).toHaveBeenCalledTimes(0);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it("should do nothing onTouchMove and onTouchEnd on nodes", () => {
|
|
706
|
+
mockTouchingElement("1", "a");
|
|
707
|
+
const onTouchMove = vi.fn();
|
|
708
|
+
const onTouchEnd = vi.fn();
|
|
709
|
+
const { container } = render(() => (
|
|
710
|
+
<Sankey
|
|
711
|
+
width={1000}
|
|
712
|
+
height={500}
|
|
713
|
+
data={exampleSankeyData}
|
|
714
|
+
onTouchMove={onTouchMove}
|
|
715
|
+
onTouchEnd={onTouchEnd}
|
|
716
|
+
/>
|
|
717
|
+
));
|
|
718
|
+
flush();
|
|
719
|
+
|
|
720
|
+
const node = container.querySelector(sankeyNodeMouseHoverTooltipSelector);
|
|
721
|
+
assertNotNull(node);
|
|
722
|
+
|
|
723
|
+
fireEvent.touchMove(node, { touches: [{ clientX: 200, clientY: 200 }] });
|
|
724
|
+
flush();
|
|
725
|
+
expect(onTouchMove).toHaveBeenCalledTimes(0);
|
|
726
|
+
|
|
727
|
+
fireEvent.touchEnd(node, { changedTouches: [{ clientX: 200, clientY: 200 }] });
|
|
728
|
+
flush();
|
|
729
|
+
expect(onTouchEnd).toHaveBeenCalledTimes(0);
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it("should not produce NaN node positions or link widths when all link values are 0", () => {
|
|
734
|
+
const zeroData = {
|
|
735
|
+
nodes: [{ name: "A" }, { name: "B" }, { name: "C" }],
|
|
736
|
+
links: [
|
|
737
|
+
{ source: 0, target: 1, value: 0 },
|
|
738
|
+
{ source: 1, target: 2, value: 0 },
|
|
739
|
+
],
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
const { container } = render(() => <Sankey width={500} height={300} data={zeroData} />);
|
|
743
|
+
flush();
|
|
744
|
+
|
|
745
|
+
// Rectangle component drops 0-height rectangles, so no nodes render
|
|
746
|
+
const nodes = container.querySelectorAll(".recharts-sankey-node");
|
|
747
|
+
expect(nodes.length).toBe(0);
|
|
748
|
+
|
|
749
|
+
const links = container.querySelectorAll(".recharts-sankey-link");
|
|
750
|
+
expect(links.length).toBeGreaterThan(0);
|
|
751
|
+
|
|
752
|
+
links.forEach((link) => {
|
|
753
|
+
const path = link.querySelector("path") ?? link; // Sometimes the element itself is the path
|
|
754
|
+
const d = path.getAttribute("d");
|
|
755
|
+
const strokeWidth = path.getAttribute("stroke-width");
|
|
756
|
+
|
|
757
|
+
expect(d).not.toContain("NaN");
|
|
758
|
+
expect(Number.isFinite(Number(strokeWidth))).toBe(true);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it("should not squash positive nodes to 0 height if one depth level has all 0 values", () => {
|
|
763
|
+
const mixedData = {
|
|
764
|
+
nodes: [{ name: "A" }, { name: "B" }, { name: "C" }, { name: "D" }],
|
|
765
|
+
links: [
|
|
766
|
+
{ source: 0, target: 1, value: 100 },
|
|
767
|
+
{ source: 0, target: 2, value: 0 },
|
|
768
|
+
{ source: 2, target: 3, value: 0 },
|
|
769
|
+
],
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
const { container } = render(() => <Sankey width={500} height={300} data={mixedData} />);
|
|
773
|
+
flush();
|
|
774
|
+
|
|
775
|
+
const nodes = container.querySelectorAll(".recharts-sankey-node");
|
|
776
|
+
// A and B should render because they have >0 values.
|
|
777
|
+
// C and D have 0 values, so they get 0 height and do not render.
|
|
778
|
+
expect(nodes.length).toBe(2);
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
it("should keep intermediate nodes out of links that skip over their depth", () => {
|
|
782
|
+
const overlappingData = {
|
|
783
|
+
nodes: [
|
|
784
|
+
{ name: "Consumption bought" },
|
|
785
|
+
{ name: "Total consumption" },
|
|
786
|
+
{ name: "Total production" },
|
|
787
|
+
{ name: "Consumed production" },
|
|
788
|
+
{ name: "Passive surplus" },
|
|
789
|
+
{ name: "Unused production" },
|
|
790
|
+
],
|
|
791
|
+
links: [
|
|
792
|
+
{ source: 0, target: 1, value: 797.44 },
|
|
793
|
+
{ source: 2, target: 3, value: 39.73 },
|
|
794
|
+
{ source: 3, target: 1, value: 39.73 },
|
|
795
|
+
{ source: 2, target: 4, value: 1.95 },
|
|
796
|
+
{ source: 4, target: 5, value: 1.95 },
|
|
797
|
+
],
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
const { container } = render(() => <Sankey width={760} height={420} data={overlappingData} />);
|
|
801
|
+
flush();
|
|
802
|
+
|
|
803
|
+
const nodes = Array.from(container.querySelectorAll(".recharts-sankey-node"));
|
|
804
|
+
const link = container.querySelector(".recharts-sankey-link");
|
|
805
|
+
|
|
806
|
+
assertNotNull(link);
|
|
807
|
+
|
|
808
|
+
for (const node of [nodes[3], nodes[4]]) {
|
|
809
|
+
assertNotNull(node);
|
|
810
|
+
|
|
811
|
+
const nodeX = readSvgNumber(node, "x");
|
|
812
|
+
const nodeY = readSvgNumber(node, "y");
|
|
813
|
+
const nodeWidth = readSvgNumber(node, "width");
|
|
814
|
+
const nodeHeight = readSvgNumber(node, "height");
|
|
815
|
+
const linkY = getLinkYAtX(link, nodeX + nodeWidth / 2);
|
|
816
|
+
const linkWidth = readSvgNumber(link, "stroke-width");
|
|
817
|
+
const isAboveLink = nodeY + nodeHeight <= linkY - linkWidth / 2;
|
|
818
|
+
const isBelowLink = nodeY >= linkY + linkWidth / 2;
|
|
819
|
+
|
|
820
|
+
expect(
|
|
821
|
+
isAboveLink || isBelowLink,
|
|
822
|
+
JSON.stringify({ nodeY, nodeHeight, linkY, linkWidth, nodeBottom: nodeY + nodeHeight }),
|
|
823
|
+
).toBe(true);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
describe("layout of large, heavily branching graphs", () => {
|
|
828
|
+
const computeOptions = {
|
|
829
|
+
width: 1000,
|
|
830
|
+
height: 500,
|
|
831
|
+
iterations: 32,
|
|
832
|
+
nodeWidth: 10,
|
|
833
|
+
nodePadding: 10,
|
|
834
|
+
sort: true,
|
|
835
|
+
verticalAlign: "justify",
|
|
836
|
+
align: "justify",
|
|
837
|
+
} as const;
|
|
838
|
+
|
|
839
|
+
type ChainLink = { source: number; target: number; value: number };
|
|
840
|
+
type BranchingChain = {
|
|
841
|
+
nodes: Array<{ name: string }>;
|
|
842
|
+
links: ChainLink[];
|
|
843
|
+
segments: number;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Builds a chain where every node branches into two nodes that immediately merge back into the
|
|
848
|
+
* next node. The graph stays small (a few nodes per segment), but the number of distinct paths
|
|
849
|
+
* from the first node to the last grows as `2 ** segments`.
|
|
850
|
+
*
|
|
851
|
+
* The default of 28 segments makes the path count large enough to exercise the layout on a
|
|
852
|
+
* densely branching graph. The chosen `segments` is returned so callers can assert on it
|
|
853
|
+
* without repeating the number.
|
|
854
|
+
*/
|
|
855
|
+
const makeBranchingChainData = (segments = 28): BranchingChain => {
|
|
856
|
+
const nodes: Array<{ name: string }> = [{ name: "entry-0" }];
|
|
857
|
+
const links: ChainLink[] = [];
|
|
858
|
+
let entry = 0;
|
|
859
|
+
|
|
860
|
+
for (let i = 0; i < segments; i++) {
|
|
861
|
+
const top = nodes.push({ name: `top-${i}` }) - 1;
|
|
862
|
+
const bottom = nodes.push({ name: `bottom-${i}` }) - 1;
|
|
863
|
+
const next = nodes.push({ name: `entry-${i + 1}` }) - 1;
|
|
864
|
+
|
|
865
|
+
links.push({ source: entry, target: top, value: 1 });
|
|
866
|
+
links.push({ source: entry, target: bottom, value: 1 });
|
|
867
|
+
links.push({ source: top, target: next, value: 1 });
|
|
868
|
+
links.push({ source: bottom, target: next, value: 1 });
|
|
869
|
+
|
|
870
|
+
entry = next;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return { nodes, links, segments };
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
it("assigns depth as the longest path from a source, even when nodes skip layers", () => {
|
|
877
|
+
// 0 -> 1 -> 2, plus a shortcut 0 -> 2.
|
|
878
|
+
// Node 2 must take the longer path (depth 2), not the shortcut.
|
|
879
|
+
const shortcutData = {
|
|
880
|
+
nodes: [{ name: "a" }, { name: "b" }, { name: "c" }],
|
|
881
|
+
links: [
|
|
882
|
+
{ source: 0, target: 1, value: 1 },
|
|
883
|
+
{ source: 1, target: 2, value: 1 },
|
|
884
|
+
{ source: 0, target: 2, value: 1 },
|
|
885
|
+
],
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
const { nodes } = computeData({ data: shortcutData, ...computeOptions });
|
|
889
|
+
|
|
890
|
+
expect(nodes.map((node) => node.depth)).toEqual([0, 1, 2]);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it("computes the layout in linear time for a heavily branching graph", () => {
|
|
894
|
+
const { segments, ...chainData } = makeBranchingChainData();
|
|
895
|
+
|
|
896
|
+
const { nodes } = computeData({ data: chainData, ...computeOptions });
|
|
897
|
+
|
|
898
|
+
expect(nodes).toHaveLength(chainData.nodes.length);
|
|
899
|
+
// Each segment contributes two layers of depth (entry -> top/bottom -> next entry).
|
|
900
|
+
expect(Math.max(...nodes.map((node) => node.depth))).toBe(segments * 2);
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
it("renders a heavily branching graph without freezing the main thread", () => {
|
|
904
|
+
const { nodes, links } = makeBranchingChainData();
|
|
905
|
+
|
|
906
|
+
const { container } = render(() => (
|
|
907
|
+
<Sankey width={1000} height={500} data={{ nodes, links }} />
|
|
908
|
+
));
|
|
909
|
+
flush();
|
|
910
|
+
|
|
911
|
+
expect(container.querySelectorAll(".recharts-sankey-node")).toHaveLength(nodes.length);
|
|
912
|
+
expect(container.querySelectorAll(".recharts-sankey-link")).toHaveLength(links.length);
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// Tooltip names resolve through the user's `nameKey` (reference
|
|
918
|
+
// getPayloadOfTooltip: getValueByDataKey(payload, nameKey, '')).
|
|
919
|
+
describe("sankeyPayloadSearcher", () => {
|
|
920
|
+
const computedData = {
|
|
921
|
+
nodes: [{ payload: { name: "Visit", label: "Visits!", value: 100 } }],
|
|
922
|
+
links: [
|
|
923
|
+
{
|
|
924
|
+
payload: {
|
|
925
|
+
source: { name: "Visit", label: "Visits!" },
|
|
926
|
+
target: { name: "Order", label: "Orders!" },
|
|
927
|
+
value: 30,
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
],
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
it("resolves node and link names through the default `name` key", () => {
|
|
934
|
+
expect(sankeyPayloadSearcher(undefined, "node-0", computedData)).toMatchObject({
|
|
935
|
+
name: "Visit",
|
|
936
|
+
value: 100,
|
|
937
|
+
});
|
|
938
|
+
expect(sankeyPayloadSearcher(undefined, "link-0", computedData)).toMatchObject({
|
|
939
|
+
name: "Visit - Order",
|
|
940
|
+
value: 30,
|
|
941
|
+
});
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
it("resolves names through a custom nameKey", () => {
|
|
945
|
+
expect(sankeyPayloadSearcher(undefined, "node-0", computedData, "label")).toMatchObject({
|
|
946
|
+
name: "Visits!",
|
|
947
|
+
});
|
|
948
|
+
expect(sankeyPayloadSearcher(undefined, "link-0", computedData, "label")).toMatchObject({
|
|
949
|
+
name: "Visits! - Orders!",
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
});
|