@octanejs/recharts 0.1.40 → 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/internal.ts +4 -20
- 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
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import type { NativeTouchEvent } from '../util/OctaneTypes';
|
|
3
|
+
import {
|
|
4
|
+
createAction,
|
|
5
|
+
createListenerMiddleware,
|
|
6
|
+
ListenerEffectAPI,
|
|
7
|
+
PayloadAction,
|
|
8
|
+
} from '@reduxjs/toolkit';
|
|
9
|
+
|
|
10
|
+
import { AppDispatch, RechartsRootState } from './store';
|
|
4
11
|
import { setActiveMouseOverItemIndex, setMouseOverAxisIndex } from './tooltipSlice';
|
|
5
12
|
import { selectActivePropsFromChartPointer } from './selectors/selectActivePropsFromChartPointer';
|
|
13
|
+
|
|
6
14
|
import { getRelativeCoordinate } from '../util/getRelativeCoordinate';
|
|
7
15
|
import { selectTooltipEventType } from './selectors/selectTooltipEventType';
|
|
8
16
|
import {
|
|
@@ -11,26 +19,35 @@ import {
|
|
|
11
19
|
} from '../util/Constants';
|
|
12
20
|
import { selectTooltipCoordinate } from './selectors/touchSelectors';
|
|
13
21
|
import { selectAllGraphicalItemsSettings } from './selectors/tooltipSelectors';
|
|
22
|
+
import { RelativePointer } from '../util/types';
|
|
14
23
|
import { createEventProxy } from '../util/createEventProxy';
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
export const touchEventAction = createAction<NativeTouchEvent<HTMLDivElement>>('touchMove');
|
|
26
|
+
|
|
27
|
+
export const touchEventMiddleware = createListenerMiddleware<RechartsRootState>();
|
|
28
|
+
|
|
29
|
+
let rafId: number | null = null;
|
|
30
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
31
|
+
let latestChartPointers: ReadonlyArray<RelativePointer> | null = null;
|
|
32
|
+
let latestTouchEvent: NativeTouchEvent<HTMLDivElement> | null = null;
|
|
33
|
+
|
|
21
34
|
touchEventMiddleware.startListening({
|
|
22
35
|
actionCreator: touchEventAction,
|
|
23
|
-
effect: (
|
|
24
|
-
|
|
36
|
+
effect: (
|
|
37
|
+
action: PayloadAction<NativeTouchEvent<HTMLDivElement>>,
|
|
38
|
+
listenerApi: ListenerEffectAPI<RechartsRootState, AppDispatch>,
|
|
39
|
+
) => {
|
|
40
|
+
const touchEvent = action.payload;
|
|
25
41
|
if (touchEvent.touches == null || touchEvent.touches.length === 0) {
|
|
26
42
|
return;
|
|
27
43
|
}
|
|
44
|
+
|
|
28
45
|
latestTouchEvent = createEventProxy(touchEvent);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
46
|
+
|
|
47
|
+
const state = listenerApi.getState();
|
|
48
|
+
const { throttleDelay, throttledEvents } = state.eventSettings;
|
|
49
|
+
const isThrottled = throttledEvents === 'all' || throttledEvents.includes('touchmove');
|
|
50
|
+
|
|
34
51
|
if (rafId !== null) {
|
|
35
52
|
cancelAnimationFrame(rafId);
|
|
36
53
|
rafId = null;
|
|
@@ -39,6 +56,7 @@ touchEventMiddleware.startListening({
|
|
|
39
56
|
clearTimeout(timeoutId);
|
|
40
57
|
timeoutId = null;
|
|
41
58
|
}
|
|
59
|
+
|
|
42
60
|
latestChartPointers = Array.from(touchEvent.touches).map((touch) =>
|
|
43
61
|
getRelativeCoordinate({
|
|
44
62
|
clientX: touch.clientX,
|
|
@@ -46,31 +64,26 @@ touchEventMiddleware.startListening({
|
|
|
46
64
|
currentTarget: touchEvent.currentTarget,
|
|
47
65
|
}),
|
|
48
66
|
);
|
|
49
|
-
|
|
67
|
+
|
|
68
|
+
const callback = () => {
|
|
50
69
|
if (latestTouchEvent == null) {
|
|
51
70
|
return;
|
|
52
71
|
}
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
|
|
73
|
+
const currentState = listenerApi.getState();
|
|
74
|
+
const tooltipEventType = selectTooltipEventType(
|
|
55
75
|
currentState,
|
|
56
76
|
currentState.tooltip.settings.shared,
|
|
57
77
|
);
|
|
58
78
|
if (tooltipEventType === 'axis') {
|
|
59
|
-
|
|
60
|
-
var latestTouchPointer =
|
|
61
|
-
(_latestChartPointers = latestChartPointers) === null || _latestChartPointers === void 0
|
|
62
|
-
? void 0
|
|
63
|
-
: _latestChartPointers[0];
|
|
79
|
+
const latestTouchPointer = latestChartPointers?.[0];
|
|
64
80
|
if (latestTouchPointer == null) {
|
|
65
81
|
rafId = null;
|
|
66
82
|
timeoutId = null;
|
|
67
83
|
return;
|
|
68
84
|
}
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
(activeProps === null || activeProps === void 0 ? void 0 : activeProps.activeIndex) !=
|
|
72
|
-
null
|
|
73
|
-
) {
|
|
85
|
+
const activeProps = selectActivePropsFromChartPointer(currentState, latestTouchPointer);
|
|
86
|
+
if (activeProps?.activeIndex != null) {
|
|
74
87
|
listenerApi.dispatch(
|
|
75
88
|
setMouseOverAxisIndex({
|
|
76
89
|
activeIndex: activeProps.activeIndex,
|
|
@@ -80,30 +93,26 @@ touchEventMiddleware.startListening({
|
|
|
80
93
|
);
|
|
81
94
|
}
|
|
82
95
|
} else if (tooltipEventType === 'item') {
|
|
83
|
-
|
|
84
|
-
var touch = latestTouchEvent.touches[0];
|
|
96
|
+
const touch = latestTouchEvent.touches[0];
|
|
85
97
|
if (document.elementFromPoint == null || touch == null) {
|
|
86
98
|
return;
|
|
87
99
|
}
|
|
88
|
-
|
|
100
|
+
const target = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
89
101
|
if (!target || !target.getAttribute) {
|
|
90
102
|
return;
|
|
91
103
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)) !== null && _target$getAttribute !== void 0
|
|
97
|
-
? _target$getAttribute
|
|
98
|
-
: undefined;
|
|
99
|
-
var settings = selectAllGraphicalItemsSettings(currentState).find(
|
|
104
|
+
const itemIndex = target.getAttribute(DATA_ITEM_INDEX_ATTRIBUTE_NAME);
|
|
105
|
+
const graphicalItemId =
|
|
106
|
+
target.getAttribute(DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME) ?? undefined;
|
|
107
|
+
const settings = selectAllGraphicalItemsSettings(currentState).find(
|
|
100
108
|
(item) => item.id === graphicalItemId,
|
|
101
109
|
);
|
|
102
110
|
if (itemIndex == null || settings == null || graphicalItemId == null) {
|
|
103
111
|
return;
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
const { dataKey } = settings;
|
|
114
|
+
const coordinate = selectTooltipCoordinate(currentState, itemIndex, graphicalItemId);
|
|
115
|
+
|
|
107
116
|
listenerApi.dispatch(
|
|
108
117
|
setActiveMouseOverItemIndex({
|
|
109
118
|
activeDataKey: dataKey,
|
|
@@ -116,16 +125,19 @@ touchEventMiddleware.startListening({
|
|
|
116
125
|
rafId = null;
|
|
117
126
|
timeoutId = null;
|
|
118
127
|
};
|
|
128
|
+
|
|
119
129
|
if (!isThrottled) {
|
|
120
130
|
callback();
|
|
121
131
|
return;
|
|
122
132
|
}
|
|
133
|
+
|
|
123
134
|
if (throttleDelay === 'raf') {
|
|
124
135
|
rafId = requestAnimationFrame(callback);
|
|
125
136
|
} else if (typeof throttleDelay === 'number') {
|
|
126
137
|
if (timeoutId === null) {
|
|
127
138
|
callback();
|
|
128
139
|
latestTouchEvent = null;
|
|
140
|
+
|
|
129
141
|
timeoutId = setTimeout(() => {
|
|
130
142
|
if (latestTouchEvent) {
|
|
131
143
|
callback();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { BaseValue } from '../../cartesian/Area.tsrx';
|
|
3
|
+
import { DataKey } from '../../util/types';
|
|
4
|
+
import { ChartData } from '../chartDataSlice';
|
|
5
|
+
import { MaybeStackedGraphicalItem } from './StackedGraphicalItem';
|
|
6
|
+
import { BaseCartesianGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
7
|
+
|
|
8
|
+
export type AreaSettings = BaseCartesianGraphicalItemSettings &
|
|
9
|
+
MaybeStackedGraphicalItem & {
|
|
10
|
+
type: 'area';
|
|
11
|
+
connectNulls: boolean;
|
|
12
|
+
baseValue: BaseValue | undefined;
|
|
13
|
+
dataKey: DataKey<any>;
|
|
14
|
+
data: ChartData | undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { MinPointSize } from '../../util/BarUtils.tsrx';
|
|
3
|
+
import { MaybeStackedGraphicalItem } from './StackedGraphicalItem';
|
|
4
|
+
import { BaseCartesianGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
5
|
+
|
|
6
|
+
export type BarSettings = BaseCartesianGraphicalItemSettings &
|
|
7
|
+
MaybeStackedGraphicalItem & {
|
|
8
|
+
type: 'bar';
|
|
9
|
+
maxBarSize: number | undefined;
|
|
10
|
+
minPointSize: MinPointSize;
|
|
11
|
+
/**
|
|
12
|
+
* When true, zero-dimension bars are not filtered out because the custom shape may still render something visible.
|
|
13
|
+
*/
|
|
14
|
+
hasCustomShape: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { ChartData } from '../chartDataSlice';
|
|
3
|
+
import { DataKey } from '../../util/types';
|
|
4
|
+
import { BaseCartesianGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
5
|
+
|
|
6
|
+
export type LineSettings = BaseCartesianGraphicalItemSettings & {
|
|
7
|
+
type: 'line';
|
|
8
|
+
data: ChartData | undefined;
|
|
9
|
+
dataKey: DataKey<any> | undefined;
|
|
10
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import type { SVGProps } from '../../util/OctaneTypes';
|
|
3
|
+
|
|
4
|
+
import { BasePolarGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
5
|
+
import { DataKey, LegendType } from '../../util/types';
|
|
6
|
+
import { TooltipType } from '../../component/DefaultTooltipContent.tsrx';
|
|
7
|
+
import { SVGPropsNoEvents } from '../../util/svgPropertiesNoEvents';
|
|
8
|
+
import { WithoutId } from '../../util/useUniqueId';
|
|
9
|
+
|
|
10
|
+
export type PiePresentationProps = SVGPropsNoEvents<WithoutId<SVGProps<SVGPathElement>>>;
|
|
11
|
+
|
|
12
|
+
export interface PieSettings extends BasePolarGraphicalItemSettings {
|
|
13
|
+
type: 'pie';
|
|
14
|
+
name: string | number | undefined;
|
|
15
|
+
nameKey: DataKey<any>;
|
|
16
|
+
tooltipType: TooltipType | undefined;
|
|
17
|
+
|
|
18
|
+
legendType: LegendType;
|
|
19
|
+
fill: string;
|
|
20
|
+
|
|
21
|
+
cx: number | string;
|
|
22
|
+
cy: number | string;
|
|
23
|
+
startAngle: number;
|
|
24
|
+
endAngle: number;
|
|
25
|
+
paddingAngle: number;
|
|
26
|
+
minAngle: number;
|
|
27
|
+
innerRadius: number | string;
|
|
28
|
+
outerRadius: number | string | ((element: any) => number | string);
|
|
29
|
+
maxRadius: number | undefined;
|
|
30
|
+
cornerRadius: number | string | undefined;
|
|
31
|
+
presentationProps: PiePresentationProps | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { MaybeStackedGraphicalItem } from './StackedGraphicalItem';
|
|
3
|
+
import { BasePolarGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
4
|
+
|
|
5
|
+
export interface RadialBarSettings
|
|
6
|
+
extends BasePolarGraphicalItemSettings, MaybeStackedGraphicalItem {
|
|
7
|
+
type: 'radialBar';
|
|
8
|
+
minPointSize: number;
|
|
9
|
+
maxBarSize: number | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { ChartData } from '../chartDataSlice';
|
|
3
|
+
import { DataKey } from '../../util/types';
|
|
4
|
+
import { TooltipType } from '../../component/DefaultTooltipContent.tsrx';
|
|
5
|
+
import { BaseCartesianGraphicalItemSettings } from '../graphicalItemsSlice';
|
|
6
|
+
|
|
7
|
+
export type ScatterSettings = BaseCartesianGraphicalItemSettings & {
|
|
8
|
+
type: 'scatter';
|
|
9
|
+
data: ChartData | undefined;
|
|
10
|
+
dataKey: DataKey<any> | undefined;
|
|
11
|
+
tooltipType: TooltipType | undefined;
|
|
12
|
+
name: string | number | undefined;
|
|
13
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { GraphicalItemSettings } from '../graphicalItemsSlice';
|
|
3
|
+
import { NormalizedStackId } from '../../util/ChartUtils';
|
|
4
|
+
import { DataKey } from '../../util/types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Some graphical items allow data stacking. The stacks are optional,
|
|
8
|
+
* so all props here are optional too.
|
|
9
|
+
*/
|
|
10
|
+
export interface MaybeStackedGraphicalItem extends GraphicalItemSettings {
|
|
11
|
+
stackId: NormalizedStackId | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Bars have a size but Area does not.
|
|
14
|
+
*/
|
|
15
|
+
barSize: number | string | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Some graphical items allow data stacking.
|
|
20
|
+
* This interface is used to represent the items that are stacked
|
|
21
|
+
* because the user has provided the stackId and dataKey properties.
|
|
22
|
+
*/
|
|
23
|
+
export interface DefinitelyStackedGraphicalItem extends MaybeStackedGraphicalItem {
|
|
24
|
+
stackId: NormalizedStackId;
|
|
25
|
+
dataKey: DataKey<any>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isStacked<T extends GraphicalItemSettings>(
|
|
29
|
+
graphicalItem: T,
|
|
30
|
+
): graphicalItem is T & DefinitelyStackedGraphicalItem {
|
|
31
|
+
return (
|
|
32
|
+
'stackId' in graphicalItem && graphicalItem.stackId != null && graphicalItem.dataKey != null
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
/**
|
|
3
|
+
* This slice contains a registry of z-index values for various components.
|
|
4
|
+
* The state is a map from z-index numbers to element references.
|
|
5
|
+
*/
|
|
6
|
+
import { createSlice, PayloadAction, prepareAutoBatched } from '@reduxjs/toolkit';
|
|
7
|
+
import { castDraft } from 'immer';
|
|
8
|
+
|
|
9
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
10
|
+
|
|
11
|
+
type ZIndexEntry = {
|
|
12
|
+
/**
|
|
13
|
+
* Reference to the DOM element that corresponds to this z-index.
|
|
14
|
+
* This element is used to create a React portal for rendering components at this z-index.
|
|
15
|
+
*
|
|
16
|
+
* If undefined, it means no element is currently registered for this z-index,
|
|
17
|
+
* and registration is in progress. If that happens, wait for the next render cycle.
|
|
18
|
+
*/
|
|
19
|
+
element: Element | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Panorama items can't mix with normal items in the same z-index layer,
|
|
22
|
+
* because they are rendered in a different SVG element.
|
|
23
|
+
* So we need to have a separate element reference for panorama z-index portals.
|
|
24
|
+
*/
|
|
25
|
+
panoramaElement: Element | undefined;
|
|
26
|
+
consumers: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type ZIndexState = {
|
|
30
|
+
zIndexMap: Record<number, ZIndexEntry>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const seed: ZIndexState['zIndexMap'] = {};
|
|
34
|
+
|
|
35
|
+
const initialState: ZIndexState = {
|
|
36
|
+
zIndexMap: Object.values(DefaultZIndexes).reduce(
|
|
37
|
+
(acc: ZIndexState['zIndexMap'], current: number): ZIndexState['zIndexMap'] => ({
|
|
38
|
+
...acc,
|
|
39
|
+
[current]: {
|
|
40
|
+
element: undefined,
|
|
41
|
+
panoramaElement: undefined,
|
|
42
|
+
consumers: 0,
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
seed,
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const defaultZIndexSet = new Set<number>(Object.values(DefaultZIndexes));
|
|
50
|
+
function isDefaultZIndex(zIndex: number): boolean {
|
|
51
|
+
return defaultZIndexSet.has(zIndex);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const zIndexSlice = createSlice({
|
|
55
|
+
name: 'zIndex',
|
|
56
|
+
initialState,
|
|
57
|
+
reducers: {
|
|
58
|
+
registerZIndexPortal: {
|
|
59
|
+
reducer: (state, action: PayloadAction<{ zIndex: number }>) => {
|
|
60
|
+
const { zIndex } = action.payload;
|
|
61
|
+
if (state.zIndexMap[zIndex]) {
|
|
62
|
+
state.zIndexMap[zIndex].consumers += 1;
|
|
63
|
+
} else {
|
|
64
|
+
state.zIndexMap[zIndex] = {
|
|
65
|
+
consumers: 1,
|
|
66
|
+
element: undefined,
|
|
67
|
+
panoramaElement: undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
prepare: prepareAutoBatched<{ zIndex: number }>(),
|
|
72
|
+
},
|
|
73
|
+
unregisterZIndexPortal: {
|
|
74
|
+
reducer: (state, action: PayloadAction<{ zIndex: number }>) => {
|
|
75
|
+
const { zIndex } = action.payload;
|
|
76
|
+
if (state.zIndexMap[zIndex]) {
|
|
77
|
+
state.zIndexMap[zIndex].consumers -= 1;
|
|
78
|
+
/*
|
|
79
|
+
* Garbage collect unused z-index entries, except for default z-indexes.
|
|
80
|
+
* Default z-indexes are always rendered, regardless of whether there are consumers or not.
|
|
81
|
+
* And because of that, even if we delete this entry, the ZIndexPortal provider will still be rendered
|
|
82
|
+
* and React is not going to re-create it, and it won't re-register the element ID.
|
|
83
|
+
* So let's not delete default z-index entries.
|
|
84
|
+
*/
|
|
85
|
+
if (state.zIndexMap[zIndex].consumers <= 0 && !isDefaultZIndex(zIndex)) {
|
|
86
|
+
delete state.zIndexMap[zIndex];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
prepare: prepareAutoBatched<{ zIndex: number }>(),
|
|
91
|
+
},
|
|
92
|
+
registerZIndexPortalElement: {
|
|
93
|
+
reducer: (
|
|
94
|
+
state,
|
|
95
|
+
action: PayloadAction<{ zIndex: number; element: Element; isPanorama: boolean }>,
|
|
96
|
+
) => {
|
|
97
|
+
const { zIndex, element, isPanorama } = action.payload;
|
|
98
|
+
if (state.zIndexMap[zIndex]) {
|
|
99
|
+
if (isPanorama) {
|
|
100
|
+
state.zIndexMap[zIndex].panoramaElement = castDraft(element);
|
|
101
|
+
} else {
|
|
102
|
+
state.zIndexMap[zIndex].element = castDraft(element);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
state.zIndexMap[zIndex] = {
|
|
106
|
+
consumers: 0,
|
|
107
|
+
element: isPanorama ? undefined : castDraft(element),
|
|
108
|
+
panoramaElement: isPanorama ? castDraft(element) : undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
prepare: prepareAutoBatched<{ zIndex: number; element: Element; isPanorama: boolean }>(),
|
|
113
|
+
},
|
|
114
|
+
unregisterZIndexPortalElement: {
|
|
115
|
+
reducer: (state, action: PayloadAction<{ zIndex: number; isPanorama: boolean }>) => {
|
|
116
|
+
const { zIndex } = action.payload;
|
|
117
|
+
if (state.zIndexMap[zIndex]) {
|
|
118
|
+
if (action.payload.isPanorama) {
|
|
119
|
+
state.zIndexMap[zIndex].panoramaElement = undefined;
|
|
120
|
+
} else {
|
|
121
|
+
state.zIndexMap[zIndex].element = undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
prepare: prepareAutoBatched<{ zIndex: number; isPanorama: boolean }>(),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const {
|
|
131
|
+
registerZIndexPortal,
|
|
132
|
+
unregisterZIndexPortal,
|
|
133
|
+
registerZIndexPortalElement,
|
|
134
|
+
unregisterZIndexPortalElement,
|
|
135
|
+
} = zIndexSlice.actions;
|
|
136
|
+
|
|
137
|
+
export const zIndexReducer = zIndexSlice.reducer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { RechartsRootState } from '../state/store';
|
|
3
|
+
import { TooltipSyncState } from '../state/tooltipSlice';
|
|
4
|
+
|
|
5
|
+
export function selectSynchronisedTooltipState(state: RechartsRootState): TooltipSyncState {
|
|
6
|
+
return state.tooltip.syncInteraction;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { Coordinate, DataKey, TickItem } from '../util/types';
|
|
3
|
+
import { TooltipIndex } from '../state/tooltipSlice';
|
|
4
|
+
|
|
5
|
+
export type ActiveLabel = string | number | undefined;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Despite the name, this type is used for all event types, not just mouse events.
|
|
9
|
+
*/
|
|
10
|
+
export type MouseHandlerDataParam = {
|
|
11
|
+
/**
|
|
12
|
+
* Index of the active tick in the current chart. Only works with number-indexed one-dimensional data charts,
|
|
13
|
+
* like Line, Area, Bar, Pie, etc.
|
|
14
|
+
*
|
|
15
|
+
* Doesn't work with two-dimensional data charts like Treemap, Sankey. But one day it will which is why the TooltipIndex type is here.
|
|
16
|
+
*/
|
|
17
|
+
activeTooltipIndex: number | TooltipIndex | undefined;
|
|
18
|
+
isTooltipActive: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Exactly the same as activeTooltipIndex - this was also duplicated in recharts@2 so let's keep both properties for better backwards compatibility.
|
|
21
|
+
*/
|
|
22
|
+
activeIndex: number | TooltipIndex | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The category or domain value of the active tooltip entry.
|
|
25
|
+
*/
|
|
26
|
+
activeLabel: ActiveLabel;
|
|
27
|
+
activeDataKey: DataKey<any> | undefined;
|
|
28
|
+
activeCoordinate: Coordinate | undefined;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Allows customisation of how the charts will synchronize tooltips and brushes.
|
|
33
|
+
* Default: index
|
|
34
|
+
*
|
|
35
|
+
* 'index': other charts will reuse current datum's index within the data array. In cases where data does not have the same length, this might yield unexpected results.
|
|
36
|
+
* 'value': will try to match other charts values
|
|
37
|
+
* custom function: will receive two arguments and should return an index of the active tick in the current chart:
|
|
38
|
+
* argument 1: ticks from the current chart
|
|
39
|
+
* argument 2: active tooltip state from the other chart
|
|
40
|
+
*/
|
|
41
|
+
export type SyncMethod =
|
|
42
|
+
'index' | 'value' | ((ticks: ReadonlyArray<TickItem>, data: MouseHandlerDataParam) => number);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type { PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
import type { BrushStartEndIndex } from '../context/brushUpdateContext';
|
|
3
|
+
import type { TooltipIndex, TooltipSyncState } from '../state/tooltipSlice';
|
|
4
|
+
import type { Coordinate, TickItem, TooltipEventType } from '../util/types';
|
|
5
|
+
import type { TooltipTrigger } from '../chart/types';
|
|
6
|
+
import type { ActiveLabel, MouseHandlerDataParam } from './types';
|
|
7
|
+
|
|
1
8
|
// Port of synchronisation/useChartSynchronisation.ts — cross-chart tooltip and
|
|
2
9
|
// brush synchronisation over the shared eventemitter3 event center. A `.tsrx`
|
|
3
10
|
// module so the compiler slots every store read (these hooks read many
|
|
@@ -42,7 +49,11 @@ function useTooltipSyncEventsListener() {
|
|
|
42
49
|
// This chart is not synchronised with any other chart.
|
|
43
50
|
return noop;
|
|
44
51
|
}
|
|
45
|
-
const listener = (
|
|
52
|
+
const listener = (
|
|
53
|
+
incomingSyncId: number | string,
|
|
54
|
+
action: PayloadAction<TooltipSyncState>,
|
|
55
|
+
emitter: symbol,
|
|
56
|
+
) => {
|
|
46
57
|
if (myEventEmitter === emitter) {
|
|
47
58
|
// We don't want to dispatch actions that we sent ourselves.
|
|
48
59
|
return;
|
|
@@ -94,10 +105,10 @@ function useTooltipSyncEventsListener() {
|
|
|
94
105
|
// for the other two sync methods, we need the ticks to be available
|
|
95
106
|
return;
|
|
96
107
|
}
|
|
97
|
-
let activeTick;
|
|
108
|
+
let activeTick: TickItem | undefined;
|
|
98
109
|
if (typeof syncMethod === 'function') {
|
|
99
110
|
// The 2.x CategoricalChartState data shape, kept for compatibility.
|
|
100
|
-
const syncMethodParam = {
|
|
111
|
+
const syncMethodParam: MouseHandlerDataParam = {
|
|
101
112
|
activeTooltipIndex: action.payload.index == null
|
|
102
113
|
? undefined
|
|
103
114
|
: Number(action.payload.index),
|
|
@@ -148,7 +159,7 @@ function useTooltipSyncEventsListener() {
|
|
|
148
159
|
const { x, y } = coordinate;
|
|
149
160
|
const validateChartX = Math.min(x, viewBox.x + viewBox.width);
|
|
150
161
|
const validateChartY = Math.min(y, viewBox.y + viewBox.height);
|
|
151
|
-
const activeCoordinate = {
|
|
162
|
+
const activeCoordinate: Coordinate = {
|
|
152
163
|
x: layout === 'horizontal' ? activeTick.coordinate : validateChartX,
|
|
153
164
|
y: layout === 'horizontal' ? validateChartY : activeTick.coordinate,
|
|
154
165
|
};
|
|
@@ -182,7 +193,11 @@ function useBrushSyncEventsListener() {
|
|
|
182
193
|
if (mySyncId == null) {
|
|
183
194
|
return noop;
|
|
184
195
|
}
|
|
185
|
-
const listener = (
|
|
196
|
+
const listener = (
|
|
197
|
+
incomingSyncId: number | string,
|
|
198
|
+
action: BrushStartEndIndex,
|
|
199
|
+
emitter: symbol,
|
|
200
|
+
) => {
|
|
186
201
|
if (myEventEmitter === emitter) {
|
|
187
202
|
return;
|
|
188
203
|
}
|
|
@@ -213,12 +228,12 @@ export function useSynchronisedEventsFromOtherCharts() {
|
|
|
213
228
|
* which prevents sparse-data charts from cascade-clearing other tooltips.
|
|
214
229
|
*/
|
|
215
230
|
export function useTooltipChartSynchronisation(
|
|
216
|
-
tooltipEventType,
|
|
217
|
-
trigger,
|
|
218
|
-
activeCoordinate,
|
|
219
|
-
activeLabel,
|
|
220
|
-
activeIndex,
|
|
221
|
-
isTooltipActive,
|
|
231
|
+
tooltipEventType: TooltipEventType | undefined,
|
|
232
|
+
trigger: TooltipTrigger,
|
|
233
|
+
activeCoordinate: Coordinate | undefined,
|
|
234
|
+
activeLabel: ActiveLabel,
|
|
235
|
+
activeIndex: TooltipIndex | undefined,
|
|
236
|
+
isTooltipActive: boolean,
|
|
222
237
|
) {
|
|
223
238
|
const activeDataKey = useAppSelector(
|
|
224
239
|
(state) => selectTooltipDataKey(state, tooltipEventType, trigger),
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
/**
|
|
3
|
+
* Defines the blank space between the chart and the plot area.
|
|
4
|
+
* This blank space is occupied by supporting elements like axes, legends, and brushes.
|
|
5
|
+
* This also includes any margins that might be applied to the chart.
|
|
6
|
+
*/
|
|
7
|
+
export type ChartOffset = {
|
|
8
|
+
/**
|
|
9
|
+
* Distance from the top edge of the chart to the top edge of the plot area.
|
|
10
|
+
*/
|
|
11
|
+
readonly top: number;
|
|
12
|
+
/**
|
|
13
|
+
* Distance from the bottom edge of the chart to the bottom edge of the plot area.
|
|
14
|
+
* Note that this is not a coordinate, this is a distance.
|
|
15
|
+
* Meaning, `offset.bottom` could be 0 in a perfectly fine big chart.
|
|
16
|
+
*/
|
|
17
|
+
readonly bottom: number;
|
|
18
|
+
/**
|
|
19
|
+
* Distance from the left edge of the chart to the left edge of the plot area.
|
|
20
|
+
*/
|
|
21
|
+
readonly left: number;
|
|
22
|
+
/**
|
|
23
|
+
* Distance from the right edge of the chart to the right edge of the plot area.
|
|
24
|
+
* Note that this is not a coordinate, this is a distance.
|
|
25
|
+
* Meaning, `offset.right` could be 0 in a perfectly fine big chart.
|
|
26
|
+
*/
|
|
27
|
+
readonly right: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Plot area is the area where the actual chart data is rendered.
|
|
32
|
+
* This means: bars, lines, scatter points, etc.
|
|
33
|
+
*/
|
|
34
|
+
export type PlotArea = {
|
|
35
|
+
/**
|
|
36
|
+
* The width of the plot area.
|
|
37
|
+
* This will be the same as `chartWidth - offset.left - offset.right`
|
|
38
|
+
*/
|
|
39
|
+
readonly width: number;
|
|
40
|
+
/**
|
|
41
|
+
* The height of the plot area.
|
|
42
|
+
* This will be the same as `chartHeight - offset.top - offset.bottom`
|
|
43
|
+
*/
|
|
44
|
+
readonly height: number;
|
|
45
|
+
/**
|
|
46
|
+
* The x coordinate of the top-left corner of the plot area.
|
|
47
|
+
* This will be the same as `offset.left`
|
|
48
|
+
*/
|
|
49
|
+
readonly x: number;
|
|
50
|
+
/**
|
|
51
|
+
* The y coordinate of the top-left corner of the plot area.
|
|
52
|
+
* This will be the same as `offset.top`
|
|
53
|
+
*/
|
|
54
|
+
readonly y: number;
|
|
55
|
+
};
|