@octanejs/recharts 0.1.41 → 0.1.42
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/{LICENSE → LICENSE.recharts} +3 -2
- package/README.md +12 -0
- package/package.json +10 -9
- package/src/animation/AnimatedItems.tsrx +36 -3
- package/src/animation/AnimationController.ts +17 -65
- package/src/animation/{AnimationControllerImpl.js → AnimationControllerImpl.ts} +19 -12
- package/src/animation/{AnimationHandle.js → AnimationHandle.ts} +82 -65
- package/src/animation/CSSTransitionAnimate.tsrx +3 -2
- package/src/animation/JavascriptAnimate.tsrx +18 -2
- package/src/animation/easing.ts +235 -0
- package/src/animation/{matchBy.js → matchBy.ts} +76 -120
- package/src/animation/timeoutController.ts +71 -0
- package/src/animation/useAnimationController.ts +4 -1
- package/src/animation/useAnimationStartSnapshot.ts +3 -3
- package/src/animation/util.ts +12 -0
- package/src/cartesian/Area.tsrx +33 -31
- package/src/cartesian/AreaRevealShape.tsrx +4 -3
- package/src/cartesian/Bar.ts +1 -0
- package/src/cartesian/Bar.tsrx +293 -39
- package/src/cartesian/BarStack.tsrx +31 -9
- package/src/cartesian/CartesianAxis.tsrx +154 -22
- package/src/cartesian/CartesianGrid.tsrx +5 -6
- package/src/cartesian/ErrorBar.tsrx +9 -8
- package/src/cartesian/Funnel.tsrx +40 -37
- package/src/cartesian/GraphicalItemClipPath.tsrx +11 -4
- package/src/cartesian/Line.ts +1 -0
- package/src/cartesian/Line.tsrx +206 -28
- package/src/cartesian/LineDrawShape.tsrx +23 -10
- package/src/cartesian/ReferenceLine.tsrx +8 -8
- package/src/cartesian/Scatter.tsrx +61 -66
- package/src/cartesian/XAxis.tsrx +78 -9
- package/src/cartesian/YAxis.tsrx +85 -12
- package/src/cartesian/getCartesianPosition.ts +265 -0
- package/src/cartesian/getEquidistantTicks.ts +144 -0
- package/src/cartesian/getTicks.ts +221 -0
- package/src/chart/AreaChart.tsrx +5 -1
- package/src/chart/BarChart.tsrx +8 -2
- package/src/chart/CartesianChart.tsrx +17 -4
- package/src/chart/CategoricalChart.tsrx +4 -1
- package/src/chart/ComposedChart.tsrx +5 -1
- package/src/chart/FunnelChart.tsrx +5 -1
- package/src/chart/LineChart.tsrx +8 -2
- package/src/chart/PieChart.tsrx +6 -2
- package/src/chart/PolarChart.tsrx +5 -4
- package/src/chart/RadarChart.tsrx +6 -2
- package/src/chart/RadialBarChart.tsrx +6 -2
- package/src/chart/RechartsWrapper.tsrx +57 -21
- package/src/chart/Sankey.tsrx +89 -91
- package/src/chart/ScatterChart.tsrx +5 -1
- package/src/chart/SunburstChart.tsrx +21 -14
- package/src/chart/types.ts +0 -1
- package/src/component/ActivePoints.tsrx +30 -5
- package/src/component/Cell.ts +19 -1
- package/src/component/Cursor.tsrx +11 -10
- package/src/component/DefaultLegendContent.tsrx +15 -10
- package/src/component/DefaultTooltipContent.tsrx +11 -9
- package/src/component/Dots.tsrx +37 -6
- package/src/component/Label.tsrx +99 -19
- package/src/component/LabelList.tsrx +54 -5
- package/src/component/Legend.tsrx +9 -5
- package/src/component/ResponsiveContainer.tsrx +13 -10
- package/src/component/Text.tsrx +95 -32
- package/src/component/Tooltip.tsrx +11 -10
- package/src/component/TooltipBoundingBox.tsrx +4 -5
- package/src/component/{responsiveContainerUtils.js → responsiveContainerUtils.ts} +59 -36
- package/src/container/ClipPathProvider.tsrx +6 -2
- package/src/container/Layer.tsrx +8 -1
- package/src/container/RootSurface.tsrx +15 -4
- package/src/container/Surface.tsrx +15 -1
- package/src/context/CellsContext.ts +6 -5
- package/src/context/ErrorBarContext.tsrx +23 -4
- package/src/context/RegisterGraphicalItemId.tsrx +10 -2
- package/src/context/accessibilityContext.ts +5 -0
- package/src/context/brushUpdateContext.ts +11 -0
- package/src/context/chartDataContext.ts +5 -4
- package/src/context/chartLayoutContext.ts +22 -8
- package/src/context/legendPayloadContext.tsrx +1 -1
- package/src/context/tooltipContext.ts +83 -0
- package/src/{hooks.js → hooks.ts} +88 -66
- package/src/index.ts +37 -37
- package/src/legacy-props.ts +129 -0
- package/src/polar/Pie.tsrx +91 -69
- package/src/polar/PolarAngleAxis.tsrx +47 -47
- package/src/polar/PolarGrid.tsrx +7 -6
- package/src/polar/PolarRadiusAxis.tsrx +29 -21
- package/src/polar/Radar.tsrx +26 -19
- package/src/polar/RadialBar.tsrx +59 -42
- package/src/polar/{defaultPolarAngleAxisProps.js → defaultPolarAngleAxisProps.ts} +6 -6
- package/src/polar/{defaultPolarRadiusAxisProps.js → defaultPolarRadiusAxisProps.ts} +5 -4
- package/src/shape/Cross.tsrx +14 -2
- package/src/shape/Curve.tsrx +111 -23
- package/src/shape/Dot.tsrx +12 -1
- package/src/shape/Polygon.tsrx +28 -6
- package/src/shape/Rectangle.tsrx +30 -3
- package/src/shape/Sector.tsrx +48 -6
- package/src/shape/Symbols.tsrx +24 -6
- package/src/shape/Trapezoid.tsrx +33 -3
- package/src/state/RechartsStoreProvider.tsrx +11 -2
- package/src/state/ReportChartProps.ts +2 -2
- package/src/state/ReportMainChartProps.ts +2 -1
- package/src/state/SetGraphicalItem.ts +6 -4
- package/src/state/SetLegendPayload.ts +7 -4
- package/src/state/SetTooltipEntrySettings.ts +5 -2
- package/src/state/brushSlice.ts +40 -0
- package/src/state/cartesianAxisSlice.ts +291 -0
- package/src/state/chartDataSlice.ts +87 -0
- package/src/state/errorBarSlice.ts +78 -0
- package/src/state/eventSettingsSlice.ts +30 -0
- package/src/state/{externalEventsMiddleware.js → externalEventsMiddleware.ts} +55 -34
- package/src/state/graphicalItemsSlice.ts +180 -0
- package/src/state/{keyboardEventsMiddleware.js → keyboardEventsMiddleware.ts} +72 -57
- package/src/state/layoutSlice.ts +50 -0
- package/src/state/legendSlice.ts +109 -0
- package/src/state/{mouseEventsMiddleware.js → mouseEventsMiddleware.ts} +45 -35
- package/src/state/optionsSlice.ts +65 -0
- package/src/state/polarAxisSlice.ts +42 -0
- package/src/state/polarOptionsSlice.ts +43 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.ts +13 -0
- package/src/state/referenceElementsSlice.ts +100 -0
- package/src/state/renderedTicksSlice.ts +60 -0
- package/src/state/rootPropsSlice.ts +72 -0
- package/src/state/selectors/areaSelectors.ts +1 -2
- package/src/state/selectors/{arrayEqualityCheck.js → arrayEqualityCheck.ts} +4 -5
- package/src/state/selectors/axisSelectors.ts +2502 -0
- package/src/state/selectors/barSelectors.ts +373 -0
- package/src/state/selectors/barStackSelectors.ts +99 -0
- package/src/state/selectors/brushSelectors.ts +28 -0
- package/src/state/selectors/combiners/combineActiveLabel.ts +16 -0
- package/src/state/selectors/combiners/{combineActiveTooltipIndex.js → combineActiveTooltipIndex.ts} +45 -23
- package/src/state/selectors/combiners/combineAllBarPositions.ts +130 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +16 -0
- package/src/state/selectors/combiners/combineBarPosition.ts +23 -0
- package/src/state/selectors/combiners/combineBarSizeList.ts +79 -0
- package/src/state/selectors/combiners/{combineCheckedDomain.js → combineCheckedDomain.ts} +9 -6
- package/src/state/selectors/combiners/combineConfiguredScale.ts +100 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +46 -0
- package/src/state/selectors/combiners/{combineDisplayedStackedData.js → combineDisplayedStackedData.ts} +23 -19
- package/src/state/selectors/combiners/combineInverseScaleFunction.ts +16 -0
- package/src/state/selectors/combiners/{combineRealScaleType.js → combineRealScaleType.ts} +16 -8
- package/src/state/selectors/combiners/combineStackedData.ts +27 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.ts +86 -0
- package/src/state/selectors/combiners/combineTooltipPayload.ts +201 -0
- package/src/state/selectors/combiners/{combineTooltipPayloadConfigurations.js → combineTooltipPayloadConfigurations.ts} +17 -18
- package/src/state/selectors/containerSelectors.ts +12 -0
- package/src/state/selectors/{dataSelectors.js → dataSelectors.ts} +43 -41
- package/src/state/selectors/funnelSelectors.ts +5 -5
- package/src/state/selectors/graphicalItemSelectors.ts +22 -0
- package/src/state/selectors/legendSelectors.ts +25 -0
- package/src/state/selectors/lineSelectors.ts +159 -0
- package/src/state/selectors/numberDomainEqualityCheck.ts +15 -0
- package/src/state/selectors/pickAxisId.ts +6 -0
- package/src/state/selectors/pickAxisType.ts +4 -0
- package/src/state/selectors/pieSelectors.ts +14 -13
- package/src/state/selectors/polarAxisSelectors.ts +223 -0
- package/src/state/selectors/polarSelectors.ts +1 -1
- package/src/state/selectors/radarSelectors.ts +1 -1
- package/src/state/selectors/radialBarSelectors.ts +17 -16
- package/src/state/selectors/rootPropsSelectors.ts +26 -0
- package/src/state/selectors/scatterSelectors.ts +11 -10
- package/src/state/selectors/{selectActivePropsFromChartPointer.js → selectActivePropsFromChartPointer.ts} +11 -4
- package/src/state/selectors/selectAllAxes.ts +20 -0
- package/src/state/selectors/selectChartOffset.ts +17 -0
- package/src/state/selectors/selectChartOffsetInternal.ts +147 -0
- package/src/state/selectors/{selectPlotArea.js → selectPlotArea.ts} +4 -3
- package/src/state/selectors/selectTooltipAxisId.ts +6 -0
- package/src/state/selectors/{selectTooltipAxisType.js → selectTooltipAxisType.ts} +10 -4
- package/src/state/selectors/selectTooltipEventType.ts +39 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.ts +6 -0
- package/src/state/selectors/selectTooltipSettings.ts +6 -0
- package/src/state/selectors/selectTooltipState.ts +5 -0
- package/src/state/selectors/selectors.ts +315 -0
- package/src/state/selectors/tooltipSelectors.ts +611 -0
- package/src/state/selectors/touchSelectors.ts +52 -0
- package/src/state/{store.js → store.ts} +46 -36
- package/src/state/tooltipSlice.ts +507 -0
- package/src/state/{touchEventsMiddleware.js → touchEventsMiddleware.ts} +54 -42
- package/src/state/types/AreaSettings.ts +15 -0
- package/src/state/types/BarSettings.ts +15 -0
- package/src/state/types/LineSettings.ts +10 -0
- package/src/state/types/PieSettings.ts +32 -0
- package/src/state/types/RadarSettings.ts +6 -0
- package/src/state/types/RadialBarSettings.ts +10 -0
- package/src/state/types/ScatterSettings.ts +13 -0
- package/src/state/types/StackedGraphicalItem.ts +34 -0
- package/src/state/zIndexSlice.ts +137 -0
- package/src/synchronisation/syncSelectors.ts +7 -0
- package/src/synchronisation/types.ts +42 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +26 -11
- package/src/types.ts +55 -0
- package/src/util/ActiveShapeUtils.tsrx +34 -10
- package/src/util/BarUtils.tsrx +43 -3
- package/src/util/{CartesianUtils.js → CartesianUtils.ts} +22 -39
- package/src/util/ChartUtils.ts +759 -0
- package/src/util/{Constants.js → Constants.ts} +6 -6
- package/src/util/DOMUtils.ts +135 -0
- package/src/util/{DataUtils.js → DataUtils.ts} +120 -47
- package/src/util/Events.ts +22 -0
- package/src/util/FunnelUtils.tsrx +3 -3
- package/src/util/Global.ts +13 -0
- package/src/util/IfOverflow.ts +16 -0
- package/src/util/LRUCache.ts +42 -0
- package/src/util/{LogUtils.js → LogUtils.ts} +7 -12
- package/src/util/OctaneTypes.ts +51 -0
- package/src/util/PolarUtils.ts +132 -0
- package/src/util/RadialBarUtils.tsrx +3 -3
- package/src/util/ReduceCSSCalc.ts +186 -0
- package/src/util/ScatterUtils.tsrx +9 -7
- package/src/util/{TickUtils.js → TickUtils.ts} +30 -13
- package/src/util/{YAxisUtils.js → YAxisUtils.ts} +27 -17
- package/src/util/axisPropsAreEqual.ts +49 -0
- package/src/util/createEventProxy.ts +20 -0
- package/src/util/{excludeEventProps.js → excludeEventProps.ts} +8 -6
- package/src/util/getActiveCoordinate.ts +210 -0
- package/src/util/{getAxisTypeBasedOnLayout.js → getAxisTypeBasedOnLayout.ts} +7 -3
- package/src/util/getClassNameFromUnknown.ts +7 -0
- package/src/util/{getEveryNth.js → getEveryNth.ts} +5 -6
- package/src/util/getRadiusAndStrokeWidthFromDot.ts +31 -0
- package/src/util/{getRelativeCoordinate.js → getRelativeCoordinate.ts} +26 -9
- package/src/util/getSliced.ts +14 -0
- package/src/util/{isDomainSpecifiedByUser.js → isDomainSpecifiedByUser.ts} +46 -100
- package/src/util/isWellBehavedNumber.ts +8 -0
- package/src/util/payload/getUniqPayload.ts +1 -1
- package/src/util/{propsAreEqual.js → propsAreEqual.ts} +10 -8
- package/src/util/{resolveDefaultProps.js → resolveDefaultProps.ts} +35 -57
- package/src/util/round.ts +33 -0
- package/src/util/scale/CustomScaleDefinition.ts +82 -0
- package/src/util/scale/RechartsScale.ts +131 -0
- package/src/util/scale/{createCategoricalInverse.js → createCategoricalInverse.ts} +24 -29
- package/src/util/scale/{getNiceTickValues.js → getNiceTickValues.ts} +125 -146
- package/src/util/scale/index.ts +2 -0
- package/src/util/scale/util/{arithmetic.js → arithmetic.ts} +12 -8
- package/src/util/stacks/getStackSeriesIdentifier.ts +21 -0
- package/src/util/stacks/stackTypes.ts +58 -0
- package/src/util/{svgPropertiesNoEvents.js → svgPropertiesNoEvents.ts} +52 -27
- package/src/util/tooltip/translate.ts +2 -1
- package/src/util/typedDataKey.ts +49 -0
- package/src/util/types.ts +1265 -7
- package/src/util/{useUniqueId.js → useUniqueId.ts} +9 -5
- package/src/zIndex/{DefaultZIndexes.js → DefaultZIndexes.ts} +13 -4
- package/src/zIndex/ZIndexLayer.tsrx +13 -4
- package/src/zIndex/ZIndexPortal.tsrx +14 -4
- package/src/zIndex/{getZIndexFromUnknown.js → getZIndexFromUnknown.ts} +3 -3
- package/src/zIndex/{zIndexSelectors.js → zIndexSelectors.ts} +17 -11
- package/src/animation/easing.js +0 -193
- package/src/animation/timeoutController.js +0 -49
- package/src/animation/util.js +0 -11
- package/src/cartesian/Area.tsrx.d.ts +0 -340
- package/src/cartesian/Bar.tsrx.d.ts +0 -4
- package/src/cartesian/BarStack.tsrx.d.ts +0 -6
- package/src/cartesian/CartesianAxis.tsrx.d.ts +0 -3
- package/src/cartesian/CartesianGrid.tsrx.d.ts +0 -219
- package/src/cartesian/ErrorBar.tsrx.d.ts +0 -131
- package/src/cartesian/Funnel.tsrx.d.ts +0 -274
- package/src/cartesian/Line.tsrx.d.ts +0 -4
- package/src/cartesian/LineDrawShape.tsrx.d.ts +0 -2
- package/src/cartesian/ReferenceLine.tsrx.d.ts +0 -178
- package/src/cartesian/Scatter.tsrx.d.ts +0 -351
- package/src/cartesian/XAxis.tsrx.d.ts +0 -3
- package/src/cartesian/YAxis.tsrx.d.ts +0 -3
- package/src/cartesian/ZAxis.tsrx.d.ts +0 -102
- package/src/cartesian/getCartesianPosition.js +0 -277
- package/src/cartesian/getEquidistantTicks.js +0 -133
- package/src/cartesian/getTicks.js +0 -280
- package/src/chart/AreaChart.tsrx.d.ts +0 -12
- package/src/chart/BarChart.tsrx.d.ts +0 -2
- package/src/chart/CartesianChart.tsrx.d.ts +0 -10
- package/src/chart/ComposedChart.tsrx.d.ts +0 -12
- package/src/chart/FunnelChart.tsrx.d.ts +0 -12
- package/src/chart/LineChart.tsrx.d.ts +0 -2
- package/src/chart/PieChart.tsrx.d.ts +0 -31
- package/src/chart/RadarChart.tsrx.d.ts +0 -31
- package/src/chart/RadialBarChart.tsrx.d.ts +0 -31
- package/src/chart/Sankey.tsrx.d.ts +0 -253
- package/src/chart/ScatterChart.tsrx.d.ts +0 -12
- package/src/chart/SunburstChart.tsrx.d.ts +0 -146
- package/src/component/DefaultLegendContent.tsrx.d.ts +0 -125
- package/src/component/DefaultTooltipContent.tsrx.d.ts +0 -87
- package/src/component/Label.tsrx.d.ts +0 -12
- package/src/component/LabelList.tsrx.d.ts +0 -8
- package/src/component/Legend.tsrx.d.ts +0 -88
- package/src/component/ResponsiveContainer.tsrx.d.ts +0 -81
- package/src/component/Text.tsrx.d.ts +0 -9
- package/src/component/Tooltip.tsrx.d.ts +0 -246
- package/src/container/Layer.tsrx.d.ts +0 -6
- package/src/container/Surface.tsrx.d.ts +0 -12
- package/src/context/accessibilityContext.js +0 -10
- package/src/context/tooltipContext.js +0 -55
- package/src/index.d.ts +0 -281
- package/src/polar/Pie.tsrx.d.ts +0 -436
- package/src/polar/PolarAngleAxis.tsrx.d.ts +0 -215
- package/src/polar/PolarGrid.tsrx.d.ts +0 -117
- package/src/polar/PolarRadiusAxis.tsrx.d.ts +0 -209
- package/src/polar/Radar.tsrx.d.ts +0 -215
- package/src/polar/RadialBar.tsrx.d.ts +0 -340
- package/src/shape/Cross.tsrx.d.ts +0 -12
- package/src/shape/Curve.tsrx.d.ts +0 -42
- package/src/shape/Dot.tsrx.d.ts +0 -9
- package/src/shape/Polygon.tsrx.d.ts +0 -13
- package/src/shape/Rectangle.tsrx.d.ts +0 -31
- package/src/shape/Sector.tsrx.d.ts +0 -29
- package/src/shape/Symbols.tsrx.d.ts +0 -15
- package/src/shape/Trapezoid.tsrx.d.ts +0 -29
- package/src/state/brushSlice.js +0 -36
- package/src/state/cartesianAxisSlice.js +0 -256
- package/src/state/chartDataSlice.js +0 -67
- package/src/state/errorBarSlice.js +0 -53
- package/src/state/eventSettingsSlice.js +0 -25
- package/src/state/graphicalItemsSlice.js +0 -91
- package/src/state/layoutSlice.js +0 -57
- package/src/state/legendSlice.js +0 -83
- package/src/state/optionsSlice.js +0 -45
- package/src/state/polarAxisSlice.js +0 -33
- package/src/state/polarOptionsSlice.js +0 -26
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +0 -14
- package/src/state/referenceElementsSlice.js +0 -51
- package/src/state/renderedTicksSlice.js +0 -41
- package/src/state/rootPropsSlice.js +0 -48
- package/src/state/selectors/axisSelectors.js +0 -2113
- package/src/state/selectors/barSelectors.js +0 -263
- package/src/state/selectors/barStackSelectors.js +0 -65
- package/src/state/selectors/brushSelectors.js +0 -21
- package/src/state/selectors/combiners/combineActiveLabel.js +0 -18
- package/src/state/selectors/combiners/combineAllBarPositions.js +0 -169
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +0 -11
- package/src/state/selectors/combiners/combineBarPosition.js +0 -17
- package/src/state/selectors/combiners/combineBarSizeList.js +0 -115
- package/src/state/selectors/combiners/combineConfiguredScale.js +0 -46
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +0 -48
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +0 -12
- package/src/state/selectors/combiners/combineStackedData.js +0 -22
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +0 -121
- package/src/state/selectors/combiners/combineTooltipPayload.js +0 -248
- package/src/state/selectors/containerSelectors.js +0 -6
- package/src/state/selectors/graphicalItemSelectors.js +0 -25
- package/src/state/selectors/legendSelectors.js +0 -18
- package/src/state/selectors/lineSelectors.js +0 -106
- package/src/state/selectors/numberDomainEqualityCheck.js +0 -11
- package/src/state/selectors/pickAxisId.js +0 -3
- package/src/state/selectors/pickAxisType.js +0 -3
- package/src/state/selectors/polarAxisSelectors.js +0 -237
- package/src/state/selectors/rootPropsSelectors.js +0 -13
- package/src/state/selectors/selectAllAxes.js +0 -15
- package/src/state/selectors/selectChartOffset.js +0 -12
- package/src/state/selectors/selectChartOffsetInternal.js +0 -174
- package/src/state/selectors/selectTooltipAxisId.js +0 -3
- package/src/state/selectors/selectTooltipEventType.js +0 -27
- package/src/state/selectors/selectTooltipPayloadSearcher.js +0 -3
- package/src/state/selectors/selectTooltipSettings.js +0 -3
- package/src/state/selectors/selectTooltipState.js +0 -3
- package/src/state/selectors/selectors.js +0 -222
- package/src/state/selectors/tooltipSelectors.js +0 -471
- package/src/state/selectors/touchSelectors.js +0 -31
- package/src/state/tooltipSlice.js +0 -237
- package/src/state/types/StackedGraphicalItem.js +0 -18
- package/src/state/zIndexSlice.js +0 -167
- package/src/synchronisation/syncSelectors.js +0 -5
- package/src/util/ChartUtils.js +0 -630
- package/src/util/DOMUtils.js +0 -180
- package/src/util/Events.js +0 -7
- package/src/util/Global.js +0 -13
- package/src/util/LRUCache.js +0 -58
- package/src/util/PolarUtils.js +0 -190
- package/src/util/ReduceCSSCalc.js +0 -260
- package/src/util/axisPropsAreEqual.js +0 -63
- package/src/util/createEventProxy.js +0 -18
- package/src/util/getActiveCoordinate.js +0 -253
- package/src/util/getClassNameFromUnknown.js +0 -8
- package/src/util/getRadiusAndStrokeWidthFromDot.js +0 -28
- package/src/util/getSliced.js +0 -11
- package/src/util/isWellBehavedNumber.js +0 -8
- package/src/util/round.js +0 -39
- package/src/util/scale/RechartsScale.js +0 -68
- package/src/util/scale/index.js +0 -3
- package/src/util/stacks/getStackSeriesIdentifier.js +0 -10
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +0 -2
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { sortBy } from 'es-toolkit/compat';
|
|
3
|
+
import { get } from 'es-toolkit/compat';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Series,
|
|
7
|
+
type SeriesPoint,
|
|
8
|
+
stack as shapeStack,
|
|
9
|
+
stackOffsetExpand,
|
|
10
|
+
stackOffsetNone,
|
|
11
|
+
stackOffsetSilhouette,
|
|
12
|
+
stackOffsetWiggle,
|
|
13
|
+
stackOrderNone,
|
|
14
|
+
} from 'victory-vendor/d3-shape';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
findEntryInArray,
|
|
18
|
+
isNan,
|
|
19
|
+
isNotNil,
|
|
20
|
+
isNullish,
|
|
21
|
+
isNumber,
|
|
22
|
+
isNumOrStr,
|
|
23
|
+
mathSign,
|
|
24
|
+
} from './DataUtils';
|
|
25
|
+
|
|
26
|
+
import { TooltipEntrySettings, TooltipPayloadEntry } from '../state/tooltipSlice';
|
|
27
|
+
import {
|
|
28
|
+
AxisTick,
|
|
29
|
+
AxisType,
|
|
30
|
+
CartesianLayout,
|
|
31
|
+
CategoricalDomainItem,
|
|
32
|
+
RelativePointer,
|
|
33
|
+
DataKey,
|
|
34
|
+
LayoutType,
|
|
35
|
+
NumberDomain,
|
|
36
|
+
OffsetHorizontal,
|
|
37
|
+
OffsetVertical,
|
|
38
|
+
PolarLayout,
|
|
39
|
+
RangeObj,
|
|
40
|
+
Size,
|
|
41
|
+
StackOffsetType,
|
|
42
|
+
TickItem,
|
|
43
|
+
AxisDomainTypeInput,
|
|
44
|
+
} from './types';
|
|
45
|
+
import { ValueType } from '../component/DefaultTooltipContent.tsrx';
|
|
46
|
+
import { LegendSettings } from '../state/legendSlice';
|
|
47
|
+
import { AxisRange, BaseAxisWithScale } from '../state/selectors/axisSelectors';
|
|
48
|
+
import { StackGroup } from './stacks/stackTypes';
|
|
49
|
+
import { getSliced } from './getSliced';
|
|
50
|
+
import { isWellBehavedNumber } from './isWellBehavedNumber';
|
|
51
|
+
import { RechartsScale } from './scale/RechartsScale';
|
|
52
|
+
|
|
53
|
+
export function getValueByDataKey<DataPointType, DataValueType>(
|
|
54
|
+
obj: DataPointType | null | undefined,
|
|
55
|
+
dataKey: DataKey<DataPointType, DataValueType> | undefined,
|
|
56
|
+
defaultValue: DataValueType,
|
|
57
|
+
): DataValueType;
|
|
58
|
+
export function getValueByDataKey<DataPointType, DataValueType>(
|
|
59
|
+
obj: DataPointType | null | undefined,
|
|
60
|
+
dataKey: DataKey<DataPointType, DataValueType> | undefined,
|
|
61
|
+
defaultValue?: DataValueType,
|
|
62
|
+
): DataValueType | undefined;
|
|
63
|
+
export function getValueByDataKey<DataPointType, DataValueType>(
|
|
64
|
+
obj: DataPointType | null | undefined,
|
|
65
|
+
dataKey: DataKey<DataPointType, DataValueType> | undefined,
|
|
66
|
+
defaultValue?: DataValueType,
|
|
67
|
+
): DataValueType | undefined {
|
|
68
|
+
if (isNullish(obj) || isNullish(dataKey)) {
|
|
69
|
+
return defaultValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isNumOrStr(dataKey)) {
|
|
73
|
+
return get(obj, dataKey, defaultValue);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof dataKey === 'function') {
|
|
77
|
+
return dataKey(obj);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return defaultValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type BarPositionPosition = {
|
|
84
|
+
/**
|
|
85
|
+
* Offset is returned always from zero position.
|
|
86
|
+
* So in a way it's "absolute".
|
|
87
|
+
*
|
|
88
|
+
* NOT inbetween bars, but always from zero.
|
|
89
|
+
*/
|
|
90
|
+
offset: number;
|
|
91
|
+
/**
|
|
92
|
+
* Size of the bar.
|
|
93
|
+
* If the input data is undefined, this will be 0.
|
|
94
|
+
* If the input data is NaN then this size too will be NaN.
|
|
95
|
+
*/
|
|
96
|
+
size: number;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const appendOffsetOfLegend = (
|
|
100
|
+
offset: OffsetVertical & OffsetHorizontal,
|
|
101
|
+
legendSettings: LegendSettings,
|
|
102
|
+
legendSize: Size,
|
|
103
|
+
): OffsetVertical & OffsetHorizontal => {
|
|
104
|
+
if (legendSettings && legendSize) {
|
|
105
|
+
const { width: boxWidth, height: boxHeight } = legendSize;
|
|
106
|
+
const { align, verticalAlign, layout } = legendSettings;
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
(layout === 'vertical' || (layout === 'horizontal' && verticalAlign === 'middle')) &&
|
|
110
|
+
align !== 'center' &&
|
|
111
|
+
isNumber(offset[align])
|
|
112
|
+
) {
|
|
113
|
+
return { ...offset, [align]: offset[align] + (boxWidth || 0) };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
(layout === 'horizontal' || (layout === 'vertical' && align === 'center')) &&
|
|
118
|
+
verticalAlign !== 'middle' &&
|
|
119
|
+
isNumber(offset[verticalAlign])
|
|
120
|
+
) {
|
|
121
|
+
return { ...offset, [verticalAlign]: offset[verticalAlign] + (boxHeight || 0) };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return offset;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const isCategoricalAxis = (layout: LayoutType, axisType: AxisType) =>
|
|
129
|
+
(layout === 'horizontal' && axisType === 'xAxis') ||
|
|
130
|
+
(layout === 'vertical' && axisType === 'yAxis') ||
|
|
131
|
+
(layout === 'centric' && axisType === 'angleAxis') ||
|
|
132
|
+
(layout === 'radial' && axisType === 'radiusAxis');
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Calculate the Coordinates of grid
|
|
136
|
+
* @param {Array} ticks The ticks in axis
|
|
137
|
+
* @param {Number} minValue The minimum value of axis
|
|
138
|
+
* @param {Number} maxValue The maximum value of axis
|
|
139
|
+
* @param {boolean} syncWithTicks Synchronize grid lines with ticks or not
|
|
140
|
+
* @return {Array} Coordinates
|
|
141
|
+
*/
|
|
142
|
+
export const getCoordinatesOfGrid = (
|
|
143
|
+
ticks: ReadonlyArray<TickItem>,
|
|
144
|
+
minValue: number,
|
|
145
|
+
maxValue: number,
|
|
146
|
+
syncWithTicks: boolean,
|
|
147
|
+
) => {
|
|
148
|
+
if (syncWithTicks) {
|
|
149
|
+
return ticks.map((entry) => entry.coordinate);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let hasMin, hasMax;
|
|
153
|
+
|
|
154
|
+
const values = ticks.map((entry) => {
|
|
155
|
+
if (entry.coordinate === minValue) {
|
|
156
|
+
hasMin = true;
|
|
157
|
+
}
|
|
158
|
+
if (entry.coordinate === maxValue) {
|
|
159
|
+
hasMax = true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return entry.coordinate;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (!hasMin) {
|
|
166
|
+
values.push(minValue);
|
|
167
|
+
}
|
|
168
|
+
if (!hasMax) {
|
|
169
|
+
values.push(maxValue);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return values;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type AxisPropsNeededForTicksGenerator = {
|
|
176
|
+
axisType?: AxisType;
|
|
177
|
+
categoricalDomain?: ReadonlyArray<unknown>;
|
|
178
|
+
duplicateDomain?: ReadonlyArray<unknown>;
|
|
179
|
+
isCategorical?: boolean;
|
|
180
|
+
niceTicks?: ReadonlyArray<AxisTick>;
|
|
181
|
+
/**
|
|
182
|
+
* The range appears to be only used in Angle Axis - needs further investigation
|
|
183
|
+
*/
|
|
184
|
+
range?: AxisRange;
|
|
185
|
+
realScaleType?: 'scaleBand' | string;
|
|
186
|
+
scale: RechartsScale | undefined;
|
|
187
|
+
tickCount?: number;
|
|
188
|
+
ticks?: ReadonlyArray<AxisTick>;
|
|
189
|
+
type?: 'number' | 'category';
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Of on four almost identical implementations of tick generation.
|
|
194
|
+
* The four horsemen of tick generation are:
|
|
195
|
+
* - {@link selectTooltipAxisTicks}
|
|
196
|
+
* - {@link combineAxisTicks}
|
|
197
|
+
* - {@link getTicksOfAxis}.
|
|
198
|
+
* - {@link combineGraphicalItemTicks}
|
|
199
|
+
*/
|
|
200
|
+
export const getTicksOfAxis = (
|
|
201
|
+
axis: undefined | AxisPropsNeededForTicksGenerator,
|
|
202
|
+
isGrid?: boolean,
|
|
203
|
+
isAll?: boolean,
|
|
204
|
+
): ReadonlyArray<TickItem> | null => {
|
|
205
|
+
if (!axis) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const {
|
|
209
|
+
duplicateDomain,
|
|
210
|
+
type,
|
|
211
|
+
range,
|
|
212
|
+
scale,
|
|
213
|
+
realScaleType,
|
|
214
|
+
isCategorical,
|
|
215
|
+
categoricalDomain,
|
|
216
|
+
tickCount,
|
|
217
|
+
ticks,
|
|
218
|
+
niceTicks,
|
|
219
|
+
axisType,
|
|
220
|
+
} = axis;
|
|
221
|
+
|
|
222
|
+
if (!scale) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const offsetForBand =
|
|
227
|
+
realScaleType === 'scaleBand' && scale.bandwidth ? scale.bandwidth() / 2 : 2;
|
|
228
|
+
let offset =
|
|
229
|
+
(isGrid || isAll) && type === 'category' && scale.bandwidth
|
|
230
|
+
? scale.bandwidth() / offsetForBand
|
|
231
|
+
: 0;
|
|
232
|
+
|
|
233
|
+
offset =
|
|
234
|
+
axisType === 'angleAxis' && range && range.length >= 2
|
|
235
|
+
? mathSign(range[0] - range[1]) * 2 * offset
|
|
236
|
+
: offset;
|
|
237
|
+
|
|
238
|
+
// The ticks set by user should only affect the ticks adjacent to axis line
|
|
239
|
+
if (isGrid && (ticks || niceTicks)) {
|
|
240
|
+
const result = (ticks || niceTicks || [])
|
|
241
|
+
.map((entry: AxisTick, index: number): TickItem | null => {
|
|
242
|
+
const scaleContent = duplicateDomain ? duplicateDomain.indexOf(entry) : entry;
|
|
243
|
+
|
|
244
|
+
const scaled = scale.map(scaleContent);
|
|
245
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
// If the scaleContent is not a number, the coordinate will be NaN.
|
|
250
|
+
// That could be the case for example with a PointScale and a string as domain.
|
|
251
|
+
coordinate: scaled + offset,
|
|
252
|
+
value: entry,
|
|
253
|
+
offset,
|
|
254
|
+
index,
|
|
255
|
+
};
|
|
256
|
+
})
|
|
257
|
+
.filter(isNotNil);
|
|
258
|
+
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// When axis is a categorical axis, but the type of axis is number or the scale of axis is not "auto"
|
|
263
|
+
// For type='number' with niceTicks available, skip this branch so ticks are evenly spaced (GitHub issue #4271)
|
|
264
|
+
if (isCategorical && categoricalDomain) {
|
|
265
|
+
return categoricalDomain
|
|
266
|
+
.map((entry: unknown, index: number): TickItem | null => {
|
|
267
|
+
const scaled = scale.map(entry);
|
|
268
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
coordinate: scaled + offset,
|
|
273
|
+
value: entry,
|
|
274
|
+
index,
|
|
275
|
+
offset,
|
|
276
|
+
};
|
|
277
|
+
})
|
|
278
|
+
.filter(isNotNil);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (scale.ticks && !isAll && tickCount != null) {
|
|
282
|
+
return scale
|
|
283
|
+
.ticks(tickCount)
|
|
284
|
+
.map((entry: number, index: number): TickItem | null => {
|
|
285
|
+
const scaled = scale.map(entry);
|
|
286
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return { coordinate: scaled + offset, value: entry, index, offset };
|
|
290
|
+
})
|
|
291
|
+
.filter(isNotNil);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// When axis has duplicated text, serial numbers are used to generate scale
|
|
295
|
+
return scale
|
|
296
|
+
.domain()
|
|
297
|
+
.map((entry: CategoricalDomainItem, index: number): TickItem | null => {
|
|
298
|
+
const scaled = scale.map(entry);
|
|
299
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
coordinate: scaled + offset,
|
|
304
|
+
// @ts-expect-error can't use Date as an index
|
|
305
|
+
value: duplicateDomain ? duplicateDomain[entry] : entry,
|
|
306
|
+
index,
|
|
307
|
+
offset,
|
|
308
|
+
};
|
|
309
|
+
})
|
|
310
|
+
.filter(isNotNil);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Both value and domain are tuples of two numbers
|
|
315
|
+
* - but the type stays as array of numbers until we have better support in rest of the app
|
|
316
|
+
* @param value input that will be truncated
|
|
317
|
+
* @param domain boundaries
|
|
318
|
+
* @returns tuple of two numbers
|
|
319
|
+
*/
|
|
320
|
+
export const truncateByDomain = (
|
|
321
|
+
value: SeriesPoint<Record<number, number>>,
|
|
322
|
+
domain: ReadonlyArray<number>,
|
|
323
|
+
): [number, number] | SeriesPoint<Record<number, number>> => {
|
|
324
|
+
if (!domain || domain.length !== 2 || !isNumber(domain[0]) || !isNumber(domain[1])) {
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const minValue = Math.min(domain[0], domain[1]);
|
|
329
|
+
const maxValue = Math.max(domain[0], domain[1]);
|
|
330
|
+
|
|
331
|
+
const result: [number, number] = [value[0], value[1]];
|
|
332
|
+
if (!isNumber(value[0]) || value[0] < minValue) {
|
|
333
|
+
result[0] = minValue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (!isNumber(value[1]) || value[1] > maxValue) {
|
|
337
|
+
result[1] = maxValue;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (result[0] > maxValue) {
|
|
341
|
+
result[0] = maxValue;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (result[1] < minValue) {
|
|
345
|
+
result[1] = minValue;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return result;
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Stacks all positive numbers above zero and all negative numbers below zero.
|
|
353
|
+
*
|
|
354
|
+
* If all values in the series are positive then this behaves the same as 'none' stacker.
|
|
355
|
+
*
|
|
356
|
+
* @param {Array} series from d3-shape Stack
|
|
357
|
+
* @return {Array} series with applied offset
|
|
358
|
+
*/
|
|
359
|
+
export const offsetSign: OffsetAccessor = (series) => {
|
|
360
|
+
const n = series.length;
|
|
361
|
+
if (n <= 0) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const m = series[0]?.length;
|
|
365
|
+
if (m == null || m <= 0) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
for (let j = 0; j < m; ++j) {
|
|
370
|
+
let positive = 0;
|
|
371
|
+
let negative = 0;
|
|
372
|
+
|
|
373
|
+
for (let i = 0; i < n; ++i) {
|
|
374
|
+
const row = series[i];
|
|
375
|
+
const col = row?.[j];
|
|
376
|
+
if (col == null) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const series1 = col[1];
|
|
380
|
+
const series0 = col[0];
|
|
381
|
+
const value = isNan(series1) ? series0 : series1;
|
|
382
|
+
|
|
383
|
+
if (value >= 0) {
|
|
384
|
+
col[0] = positive;
|
|
385
|
+
positive += value;
|
|
386
|
+
col[1] = positive;
|
|
387
|
+
} else {
|
|
388
|
+
col[0] = negative;
|
|
389
|
+
negative += value;
|
|
390
|
+
col[1] = negative;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Replaces all negative values with zero when stacking data.
|
|
398
|
+
*
|
|
399
|
+
* If all values in the series are positive then this behaves the same as 'none' stacker.
|
|
400
|
+
*
|
|
401
|
+
* @param {Array} series from d3-shape Stack
|
|
402
|
+
* @return {Array} series with applied offset
|
|
403
|
+
*/
|
|
404
|
+
export const offsetPositive: OffsetAccessor = (series) => {
|
|
405
|
+
const n = series.length;
|
|
406
|
+
if (n <= 0) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const m = series[0]?.length;
|
|
410
|
+
if (m == null || m <= 0) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
for (let j = 0; j < m; ++j) {
|
|
415
|
+
let positive = 0;
|
|
416
|
+
|
|
417
|
+
for (let i = 0; i < n; ++i) {
|
|
418
|
+
const row = series[i];
|
|
419
|
+
const col = row?.[j];
|
|
420
|
+
if (col == null) {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const value = isNan(col[1]) ? col[0] : col[1];
|
|
424
|
+
|
|
425
|
+
if (value >= 0) {
|
|
426
|
+
col[0] = positive;
|
|
427
|
+
positive += value;
|
|
428
|
+
col[1] = positive;
|
|
429
|
+
} else {
|
|
430
|
+
col[0] = 0;
|
|
431
|
+
col[1] = 0;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/** Offsets mutate point bounds, not the series' datum or key metadata. */
|
|
438
|
+
type OffsetAccessor = <Datum, Key>(series: Array<Series<Datum, Key>>, order: number[]) => void;
|
|
439
|
+
|
|
440
|
+
// D3 passes the complete series array. @types/d3-shape before 3.1.8 incorrectly
|
|
441
|
+
// declared a single Series in these callbacks. Add the verified array overload
|
|
442
|
+
// at this dependency boundary without changing functions or erasing metadata.
|
|
443
|
+
const STACK_OFFSET_MAP: Record<StackOffsetType, OffsetAccessor> = {
|
|
444
|
+
sign: offsetSign,
|
|
445
|
+
expand: stackOffsetExpand as typeof stackOffsetExpand & OffsetAccessor,
|
|
446
|
+
none: stackOffsetNone as typeof stackOffsetNone & OffsetAccessor,
|
|
447
|
+
silhouette: stackOffsetSilhouette as typeof stackOffsetSilhouette & OffsetAccessor,
|
|
448
|
+
wiggle: stackOffsetWiggle as typeof stackOffsetWiggle & OffsetAccessor,
|
|
449
|
+
positive: offsetPositive,
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
type StackWithArrayOffset<Datum, Key> = ReturnType<typeof shapeStack<Datum, Key>> & {
|
|
453
|
+
offset(
|
|
454
|
+
offset: (series: Array<Series<Datum, Key>>, order: number[]) => void,
|
|
455
|
+
): StackWithArrayOffset<Datum, Key>;
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
export const getStackedData = (
|
|
459
|
+
data: ReadonlyArray<Record<string, unknown>>,
|
|
460
|
+
dataKeys: ReadonlyArray<DataKey<any>>,
|
|
461
|
+
offsetType: StackOffsetType,
|
|
462
|
+
): ReadonlyArray<Series<Record<string, unknown>, DataKey<any>>> => {
|
|
463
|
+
const offsetAccessor: OffsetAccessor = STACK_OFFSET_MAP[offsetType] ?? stackOffsetNone;
|
|
464
|
+
const stack = (
|
|
465
|
+
shapeStack<Record<string, unknown>, DataKey<any>>() as StackWithArrayOffset<
|
|
466
|
+
Record<string, unknown>,
|
|
467
|
+
DataKey<any>
|
|
468
|
+
>
|
|
469
|
+
)
|
|
470
|
+
.keys(dataKeys)
|
|
471
|
+
.value((d, key) => Number(getValueByDataKey(d, key, 0)))
|
|
472
|
+
.order(stackOrderNone)
|
|
473
|
+
.offset(offsetAccessor);
|
|
474
|
+
|
|
475
|
+
const result = stack(data);
|
|
476
|
+
|
|
477
|
+
// Post-process ranged data: if value is an array of two numbers, use them directly without stacking
|
|
478
|
+
result.forEach((series, seriesIndex) => {
|
|
479
|
+
series.forEach((point, pointIndex) => {
|
|
480
|
+
const value = getValueByDataKey(data[pointIndex], dataKeys[seriesIndex], 0);
|
|
481
|
+
if (Array.isArray(value) && value.length === 2 && isNumber(value[0]) && isNumber(value[1])) {
|
|
482
|
+
// eslint-disable-next-line prefer-destructuring,no-param-reassign
|
|
483
|
+
point[0] = value[0];
|
|
484
|
+
// eslint-disable-next-line prefer-destructuring,no-param-reassign
|
|
485
|
+
point[1] = value[1];
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
return result;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Externally, we accept both strings and numbers as stack IDs
|
|
495
|
+
* @inline
|
|
496
|
+
*/
|
|
497
|
+
export type StackId = string | number;
|
|
498
|
+
/**
|
|
499
|
+
* Stack IDs in the external props allow numbers; but internally we use it as an object key
|
|
500
|
+
* and object keys are always strings. Also, it would be kinda confusing if stackId=8 and stackId='8' were different stacks
|
|
501
|
+
* so let's just force a string.
|
|
502
|
+
*/
|
|
503
|
+
export type NormalizedStackId = string;
|
|
504
|
+
|
|
505
|
+
export function getNormalizedStackId(
|
|
506
|
+
publicStackId: StackId | undefined,
|
|
507
|
+
): NormalizedStackId | undefined {
|
|
508
|
+
return publicStackId == null ? undefined : String(publicStackId);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function getCateCoordinateOfLine<T extends Record<string, unknown>>({
|
|
512
|
+
axis,
|
|
513
|
+
ticks,
|
|
514
|
+
bandSize,
|
|
515
|
+
entry,
|
|
516
|
+
index,
|
|
517
|
+
dataKey,
|
|
518
|
+
}: {
|
|
519
|
+
axis: {
|
|
520
|
+
dataKey?: DataKey<T>;
|
|
521
|
+
allowDuplicatedCategory?: boolean;
|
|
522
|
+
type?: AxisDomainTypeInput;
|
|
523
|
+
scale: RechartsScale;
|
|
524
|
+
};
|
|
525
|
+
ticks: ReadonlyArray<TickItem> | undefined;
|
|
526
|
+
bandSize: number;
|
|
527
|
+
entry: T;
|
|
528
|
+
index: number;
|
|
529
|
+
dataKey?: DataKey<T>;
|
|
530
|
+
}): number | null {
|
|
531
|
+
if (axis.type === 'category') {
|
|
532
|
+
// find coordinate of category axis by the value of category
|
|
533
|
+
// @ts-expect-error why does this use direct object access instead of getValueByDataKey?
|
|
534
|
+
if (!axis.allowDuplicatedCategory && axis.dataKey && !isNullish(entry[axis.dataKey])) {
|
|
535
|
+
// @ts-expect-error why does this use direct object access instead of getValueByDataKey?
|
|
536
|
+
const matchedTick = findEntryInArray(ticks, 'value', entry[axis.dataKey]);
|
|
537
|
+
|
|
538
|
+
if (matchedTick) {
|
|
539
|
+
return matchedTick.coordinate + bandSize / 2;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return ticks?.[index] ? ticks[index].coordinate + bandSize / 2 : null;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const value = getValueByDataKey(entry, !isNullish(dataKey) ? dataKey : axis.dataKey);
|
|
547
|
+
|
|
548
|
+
const scaled = axis.scale.map(value);
|
|
549
|
+
if (!isNumber(scaled)) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
return scaled;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export const getCateCoordinateOfBar = ({
|
|
556
|
+
axis,
|
|
557
|
+
ticks,
|
|
558
|
+
offset,
|
|
559
|
+
bandSize,
|
|
560
|
+
entry,
|
|
561
|
+
index,
|
|
562
|
+
}: {
|
|
563
|
+
axis: BaseAxisWithScale;
|
|
564
|
+
ticks: ReadonlyArray<TickItem>;
|
|
565
|
+
offset: number;
|
|
566
|
+
bandSize: number;
|
|
567
|
+
entry: unknown;
|
|
568
|
+
index: number;
|
|
569
|
+
}): number | null => {
|
|
570
|
+
if (axis.type === 'category') {
|
|
571
|
+
return ticks[index] ? ticks[index].coordinate + offset : null;
|
|
572
|
+
}
|
|
573
|
+
// getValueByDataKey does not validate the output type
|
|
574
|
+
const value: number | undefined = getValueByDataKey(
|
|
575
|
+
entry,
|
|
576
|
+
axis.dataKey,
|
|
577
|
+
axis.scale.domain()[index],
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
if (isNullish(value)) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const scaled = axis.scale.map(value);
|
|
585
|
+
if (!isNumber(scaled)) {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
return scaled - bandSize / 2 + offset;
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
export const getBaseValueOfBar = ({
|
|
592
|
+
numericAxis,
|
|
593
|
+
}: {
|
|
594
|
+
numericAxis: BaseAxisWithScale;
|
|
595
|
+
}): number | unknown => {
|
|
596
|
+
const domain = numericAxis.scale.domain();
|
|
597
|
+
|
|
598
|
+
if (numericAxis.type === 'number') {
|
|
599
|
+
// @ts-expect-error type number means the domain has numbers in it but this relationship is not known to typescript
|
|
600
|
+
const minValue = Math.min(domain[0], domain[1]);
|
|
601
|
+
// @ts-expect-error type number means the domain has numbers in it but this relationship is not known to typescript
|
|
602
|
+
const maxValue = Math.max(domain[0], domain[1]);
|
|
603
|
+
|
|
604
|
+
if (minValue <= 0 && maxValue >= 0) {
|
|
605
|
+
return 0;
|
|
606
|
+
}
|
|
607
|
+
if (maxValue < 0) {
|
|
608
|
+
return maxValue;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return minValue;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return domain[0];
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
const getDomainOfSingle = (data: ReadonlyArray<ReadonlyArray<unknown>>): number[] => {
|
|
618
|
+
const flat = data.flat(2).filter(isNumber);
|
|
619
|
+
return [Math.min(...flat), Math.max(...flat)];
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
const makeDomainFinite = (domain: NumberDomain): NumberDomain => {
|
|
623
|
+
return [domain[0] === Infinity ? 0 : domain[0], domain[1] === -Infinity ? 0 : domain[1]];
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
export const getDomainOfStackGroups = (
|
|
627
|
+
stackGroups: Record<StackId, StackGroup> | undefined,
|
|
628
|
+
startIndex: number,
|
|
629
|
+
endIndex: number,
|
|
630
|
+
): NumberDomain | undefined => {
|
|
631
|
+
if (stackGroups == null || Object.keys(stackGroups).length === 0) {
|
|
632
|
+
return undefined;
|
|
633
|
+
}
|
|
634
|
+
return makeDomainFinite(
|
|
635
|
+
Object.keys(stackGroups).reduce(
|
|
636
|
+
(result, stackId): NumberDomain => {
|
|
637
|
+
const group = stackGroups[stackId];
|
|
638
|
+
if (!group) {
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
const { stackedData } = group;
|
|
642
|
+
const domain: NumberDomain = stackedData.reduce(
|
|
643
|
+
(res: NumberDomain, entry): NumberDomain => {
|
|
644
|
+
const sliced = getSliced(entry, startIndex, endIndex);
|
|
645
|
+
const s = getDomainOfSingle(sliced);
|
|
646
|
+
if (!isWellBehavedNumber(s[0]) || !isWellBehavedNumber(s[1])) {
|
|
647
|
+
return res;
|
|
648
|
+
}
|
|
649
|
+
return [Math.min(res[0], s[0]), Math.max(res[1], s[1])];
|
|
650
|
+
},
|
|
651
|
+
[Infinity, -Infinity],
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
return [Math.min(domain[0], result[0]), Math.max(domain[1], result[1])];
|
|
655
|
+
},
|
|
656
|
+
[Infinity, -Infinity],
|
|
657
|
+
),
|
|
658
|
+
);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
export const MIN_VALUE_REG = /^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/;
|
|
662
|
+
export const MAX_VALUE_REG = /^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/;
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Calculate the size between two category
|
|
666
|
+
* @param {Object} axis The options of axis
|
|
667
|
+
* @param {Array} ticks The ticks of axis
|
|
668
|
+
* @param {Boolean} isBar if items in axis are bars
|
|
669
|
+
* @return {Number} Size
|
|
670
|
+
*/
|
|
671
|
+
export const getBandSizeOfAxis = (
|
|
672
|
+
axis?: BaseAxisWithScale,
|
|
673
|
+
ticks?: ReadonlyArray<TickItem>,
|
|
674
|
+
isBar?: boolean,
|
|
675
|
+
): number | undefined => {
|
|
676
|
+
if (axis && axis.scale && axis.scale.bandwidth) {
|
|
677
|
+
const bandWidth = axis.scale.bandwidth();
|
|
678
|
+
|
|
679
|
+
if (!isBar || bandWidth > 0) {
|
|
680
|
+
return bandWidth;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if (axis && ticks && ticks.length >= 2) {
|
|
685
|
+
const orderedTicks: ReadonlyArray<TickItem> = sortBy(ticks, (o: TickItem) => o.coordinate);
|
|
686
|
+
let bandSize = Infinity;
|
|
687
|
+
|
|
688
|
+
for (let i = 1, len = orderedTicks.length; i < len; i++) {
|
|
689
|
+
const cur = orderedTicks[i];
|
|
690
|
+
const prev = orderedTicks[i - 1];
|
|
691
|
+
|
|
692
|
+
bandSize = Math.min((cur?.coordinate || 0) - (prev?.coordinate || 0), bandSize);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return bandSize === Infinity ? 0 : bandSize;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return isBar ? undefined : 0;
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
export function getTooltipEntry({
|
|
702
|
+
tooltipEntrySettings,
|
|
703
|
+
dataKey,
|
|
704
|
+
payload,
|
|
705
|
+
value,
|
|
706
|
+
name,
|
|
707
|
+
}: {
|
|
708
|
+
tooltipEntrySettings: TooltipEntrySettings;
|
|
709
|
+
dataKey: DataKey<any> | undefined;
|
|
710
|
+
payload: any;
|
|
711
|
+
value: ValueType;
|
|
712
|
+
name: string | undefined;
|
|
713
|
+
}): TooltipPayloadEntry {
|
|
714
|
+
return {
|
|
715
|
+
...tooltipEntrySettings,
|
|
716
|
+
dataKey,
|
|
717
|
+
payload,
|
|
718
|
+
value,
|
|
719
|
+
name,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
export function getTooltipNameProp(
|
|
724
|
+
nameFromItem: string | number | undefined | unknown,
|
|
725
|
+
dataKey: DataKey<any> | undefined,
|
|
726
|
+
): string | undefined {
|
|
727
|
+
if (nameFromItem != null) {
|
|
728
|
+
return String(nameFromItem);
|
|
729
|
+
}
|
|
730
|
+
if (typeof dataKey === 'string') {
|
|
731
|
+
return dataKey;
|
|
732
|
+
}
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export const calculateCartesianTooltipPos = (
|
|
737
|
+
coordinate: RelativePointer,
|
|
738
|
+
layout: CartesianLayout,
|
|
739
|
+
): number | undefined => {
|
|
740
|
+
if (layout === 'horizontal') {
|
|
741
|
+
return coordinate.relativeX;
|
|
742
|
+
}
|
|
743
|
+
if (layout === 'vertical') {
|
|
744
|
+
return coordinate.relativeY;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return undefined;
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
export const calculatePolarTooltipPos = (
|
|
751
|
+
rangeObj: RangeObj,
|
|
752
|
+
layout: PolarLayout,
|
|
753
|
+
): number | undefined => {
|
|
754
|
+
if (layout === 'centric') {
|
|
755
|
+
return rangeObj.angle;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return rangeObj.radius;
|
|
759
|
+
};
|