@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,54 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
-
function ownKeys(e, r) {
|
|
4
|
-
var t = Object.keys(e);
|
|
5
|
-
if (Object.getOwnPropertySymbols) {
|
|
6
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
7
|
-
(r &&
|
|
8
|
-
(o = o.filter(function (r) {
|
|
9
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
10
|
-
})),
|
|
11
|
-
t.push.apply(t, o));
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
}
|
|
15
|
-
function _objectSpread(e) {
|
|
16
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
17
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
18
|
-
r % 2
|
|
19
|
-
? ownKeys(Object(t), !0).forEach(function (r) {
|
|
20
|
-
_defineProperty(e, r, t[r]);
|
|
21
|
-
})
|
|
22
|
-
: Object.getOwnPropertyDescriptors
|
|
23
|
-
? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
|
|
24
|
-
: ownKeys(Object(t)).forEach(function (r) {
|
|
25
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return e;
|
|
29
|
-
}
|
|
30
|
-
function _defineProperty(e, r, t) {
|
|
31
|
-
return (
|
|
32
|
-
(r = _toPropertyKey(r)) in e
|
|
33
|
-
? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 })
|
|
34
|
-
: (e[r] = t),
|
|
35
|
-
e
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
function _toPropertyKey(t) {
|
|
39
|
-
var i = _toPrimitive(t, 'string');
|
|
40
|
-
return 'symbol' == typeof i ? i : i + '';
|
|
41
|
-
}
|
|
42
|
-
function _toPrimitive(t, r) {
|
|
43
|
-
if ('object' != typeof t || !t) return t;
|
|
44
|
-
var e = t[Symbol.toPrimitive];
|
|
45
|
-
if (void 0 !== e) {
|
|
46
|
-
var i = e.call(t, r || 'default');
|
|
47
|
-
if ('object' != typeof i) return i;
|
|
48
|
-
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
49
|
-
}
|
|
50
|
-
return ('string' === r ? String : Number)(t);
|
|
51
|
-
}
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
52
2
|
/**
|
|
53
3
|
* This function mimics the behavior of the `defaultProps` static property in React.
|
|
54
4
|
* Functional components do not have a defaultProps property, so this function is useful to resolve default props.
|
|
@@ -64,19 +14,22 @@ function _toPrimitive(t, r) {
|
|
|
64
14
|
* @param defaultProps - the default props object defined in the component by Recharts
|
|
65
15
|
* @returns - the props object with all the default props resolved. All `undefined` values are replaced with the default value.
|
|
66
16
|
*/
|
|
67
|
-
export function resolveDefaultProps
|
|
17
|
+
export function resolveDefaultProps<T, D extends Partial<T>>(
|
|
18
|
+
realProps: T,
|
|
19
|
+
defaultProps: D & DisallowExtraKeys<T, D>,
|
|
20
|
+
): RequiresDefaultProps<T, D> {
|
|
68
21
|
/*
|
|
69
22
|
* To avoid mutating the original `realProps` object passed to the function, create a shallow copy of it.
|
|
70
23
|
* `resolvedProps` will be modified directly with the defaults.
|
|
71
24
|
*/
|
|
72
|
-
|
|
25
|
+
const resolvedProps: T = { ...realProps };
|
|
73
26
|
/*
|
|
74
27
|
* Since the function guarantees `D extends Partial<T>`, this assignment is safe.
|
|
75
28
|
* It allows TypeScript to work with the well-defined `Partial<T>` type inside the loop,
|
|
76
29
|
* making subsequent type inference (especially for `dp[key]`) much more straightforward for the compiler.
|
|
77
30
|
* This is a key step to improve type safety *without* value assertions later.
|
|
78
31
|
*/
|
|
79
|
-
|
|
32
|
+
const dp: Partial<T> = defaultProps;
|
|
80
33
|
/*
|
|
81
34
|
* `Object.keys` doesn't preserve strong key types - it always returns Array<string>.
|
|
82
35
|
* However, due to the `D extends Partial<T>` constraint,
|
|
@@ -86,8 +39,8 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
86
39
|
* Type assertions are not sound but in this case it's necessary
|
|
87
40
|
* as `Object.keys` does not do what we want it to do.
|
|
88
41
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
42
|
+
const keys = Object.keys(defaultProps) as Array<keyof T>;
|
|
43
|
+
const withDefaults: T = keys.reduce((acc: T, key: keyof T): T => {
|
|
91
44
|
if (acc[key] === undefined && dp[key] !== undefined) {
|
|
92
45
|
acc[key] = dp[key];
|
|
93
46
|
}
|
|
@@ -97,7 +50,7 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
97
50
|
* And again type assertions are not safe but here we have done the runtime work
|
|
98
51
|
* so let's bypass the lack of static type safety and tell the compiler what happened.
|
|
99
52
|
*/
|
|
100
|
-
return withDefaults
|
|
53
|
+
return withDefaults as RequiresDefaultProps<T, D>;
|
|
101
54
|
}
|
|
102
55
|
|
|
103
56
|
/**
|
|
@@ -106,6 +59,9 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
106
59
|
* it means K is required, so we keep K; otherwise, we discard it (never).
|
|
107
60
|
* [keyof T] at the end creates a union of the kept keys.
|
|
108
61
|
*/
|
|
62
|
+
export type RequiredKeys<T> = {
|
|
63
|
+
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
|
|
64
|
+
}[keyof T];
|
|
109
65
|
|
|
110
66
|
/**
|
|
111
67
|
* Helper type to extract the keys of T that are optional.
|
|
@@ -113,6 +69,9 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
113
69
|
* it means K is optional (or potentially missing), so we keep K; otherwise, we discard it (never).
|
|
114
70
|
* [keyof T] at the end creates a union of the kept keys.
|
|
115
71
|
*/
|
|
72
|
+
export type OptionalKeys<T> = {
|
|
73
|
+
[K in keyof T]-?: object extends Pick<T, K> ? K : never;
|
|
74
|
+
}[keyof T];
|
|
116
75
|
|
|
117
76
|
/**
|
|
118
77
|
* Helper type to ensure keys of D exist in T.
|
|
@@ -120,6 +79,7 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
120
79
|
* If K is NOT a key of T, map it to type `never`.
|
|
121
80
|
* An object cannot have a property of type `never`, effectively disallowing extra keys.
|
|
122
81
|
*/
|
|
82
|
+
export type DisallowExtraKeys<T, D> = { [K in keyof D]: K extends keyof T ? D[K] : never };
|
|
123
83
|
|
|
124
84
|
/**
|
|
125
85
|
* This type will take a source type `Props` and a default type `Defaults` and will return a new type
|
|
@@ -129,3 +89,21 @@ export function resolveDefaultProps(realProps, defaultProps) {
|
|
|
129
89
|
*
|
|
130
90
|
* This is useful for creating a type that represents the resolved props of a component with default props.
|
|
131
91
|
*/
|
|
92
|
+
export type RequiresDefaultProps<Props, Defaults extends Partial<Props>> =
|
|
93
|
+
// Section 1: Properties that were already required in T.
|
|
94
|
+
// We use Pick<T, RequiredKeys<T>> to select only the keys that were originally
|
|
95
|
+
// required in T. Pick preserves their required status and original types.
|
|
96
|
+
Pick<Props, RequiredKeys<Props>> &
|
|
97
|
+
// Section 2: Properties that were optional in T BUT have a default specified in D.
|
|
98
|
+
// These properties should become required in the resulting type.
|
|
99
|
+
// - OptionalKeys<T>: Gets the union of keys that are optional in T.
|
|
100
|
+
// - RequiredKeys<D>: Gets the keys that are required in the default props D.
|
|
101
|
+
// - Extract<..., ...>: Finds the intersection of these two sets – the keys that are optional in T AND required in D.
|
|
102
|
+
// - Pick<T, Extract<...>>: Selects these specific properties from T. At this stage, they still retain their original optional ('?') status from T.
|
|
103
|
+
// - Required<...>: Wraps the picked properties, removing the '?' modifier and making them required. Their underlying type (e.g., `string | undefined`) remains unchanged.
|
|
104
|
+
Required<Pick<Props, Extract<OptionalKeys<Props>, RequiredKeys<Defaults>>>> &
|
|
105
|
+
// Section 3: Properties that were optional in T AND do NOT have a default in D.
|
|
106
|
+
// These properties should remain optional.
|
|
107
|
+
// - Exclude<OptionalKeys<T>, keyof D>: Finds the keys that are optional in T but are NOT present in D.
|
|
108
|
+
// - Pick<T, Exclude<...>>: Selects these properties from T. Pick preserves their original optional status and types.
|
|
109
|
+
Pick<Props, Exclude<OptionalKeys<Props>, keyof Defaults>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
// if you go lower than 3, wild wild things happen during rendering
|
|
3
|
+
const defaultRoundPrecision = 4;
|
|
4
|
+
|
|
5
|
+
export function round(num: number, roundPrecision: number = defaultRoundPrecision): number {
|
|
6
|
+
const factor = 10 ** roundPrecision;
|
|
7
|
+
const rounded = Math.round(num * factor) / factor;
|
|
8
|
+
if (Object.is(rounded, -0)) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
return rounded;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This function will accept a string template literal and for each
|
|
16
|
+
* variable placeholder, it will round the value to avoid long float numbers in
|
|
17
|
+
* the SVG path which might cause rendering issues in some browsers.
|
|
18
|
+
*/
|
|
19
|
+
export function roundTemplateLiteral(
|
|
20
|
+
strings: TemplateStringsArray,
|
|
21
|
+
...values: ReadonlyArray<number | string>
|
|
22
|
+
) {
|
|
23
|
+
return strings.reduce((result, string, i) => {
|
|
24
|
+
const value = values[i - 1];
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return result + value + string;
|
|
27
|
+
}
|
|
28
|
+
if (value !== undefined) {
|
|
29
|
+
return result + round(value) + string;
|
|
30
|
+
}
|
|
31
|
+
return result + string;
|
|
32
|
+
}, '');
|
|
33
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { CategoricalDomainItem } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A subset of d3-scale. This is the external representation;
|
|
6
|
+
* This is the type that we expect from `axis.scale` props, if users want to provide custom scales.
|
|
7
|
+
*
|
|
8
|
+
* The actual d3 scales have many more methods, but we don't need them all.
|
|
9
|
+
* Specifically we want to avoid all the setters
|
|
10
|
+
* - immutable API is preferred in Recharts and mutating state will lead to hard-to-debug issues.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link ScaleType} and {@link RechartsScaleType} for string shortcuts that you can use instead of this interface.
|
|
13
|
+
*/
|
|
14
|
+
export interface CustomScaleDefinition<
|
|
15
|
+
Domain extends CategoricalDomainItem = CategoricalDomainItem,
|
|
16
|
+
> {
|
|
17
|
+
/**
|
|
18
|
+
* Returns the scale's current domain.
|
|
19
|
+
* The domain could be:
|
|
20
|
+
* - in categorical scales: an array of strings or categories
|
|
21
|
+
* - in continuous scales: tuple of two numbers: [min, max]
|
|
22
|
+
*/
|
|
23
|
+
domain(): ReadonlyArray<Domain>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sets the domain of the scale.
|
|
27
|
+
*/
|
|
28
|
+
domain(newDomain: ReadonlyArray<Domain>): this;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the scale’s current range.
|
|
32
|
+
*/
|
|
33
|
+
range(): ReadonlyArray<number>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sets the range of the scale.
|
|
37
|
+
*/
|
|
38
|
+
range(newRange: ReadonlyArray<number>): this;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
|
|
42
|
+
* We use this method in Recharts to ensure immutability - changes to the scale outside should not affect the internal state,
|
|
43
|
+
* as they won't trigger re-renders in React.
|
|
44
|
+
*/
|
|
45
|
+
copy(): CustomScaleDefinition<Domain>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns width of each band.
|
|
49
|
+
* Most scales are not banded, so this method is optional.
|
|
50
|
+
* Banded scales (like scaleBand from d3-scale) will implement this method.
|
|
51
|
+
*/
|
|
52
|
+
bandwidth?: () => number;
|
|
53
|
+
/**
|
|
54
|
+
* Quantitative (continuous) scales provide a ticks method that returns representative values from the scale’s domain.
|
|
55
|
+
* Ordinal and band scales do not have this method.
|
|
56
|
+
*
|
|
57
|
+
* An optional count argument requests more or fewer ticks.
|
|
58
|
+
* The number of ticks returned, however, is not necessarily equal to the requested count.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://d3js.org/d3-scale/linear#linear_ticks}
|
|
61
|
+
* @see {@link https://observablehq.com/@d3/scale-ticks}
|
|
62
|
+
*
|
|
63
|
+
* @param count number of ticks
|
|
64
|
+
*/
|
|
65
|
+
ticks?: (count: number | undefined) => ReadonlyArray<number>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Given an arbitrary input, returns the corresponding point derived from the output range if the input is in the scale's domain.
|
|
69
|
+
* If the input is not included in the domain, returns undefined.
|
|
70
|
+
*
|
|
71
|
+
* @param input
|
|
72
|
+
*/
|
|
73
|
+
(input: Domain): number | undefined;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Given a value from the range, returns the corresponding value from the domain.
|
|
77
|
+
*
|
|
78
|
+
* This method is optional, as not all scales provide an inverse mapping.
|
|
79
|
+
* Linear and time scales typically do, while band and ordinal scales may not.
|
|
80
|
+
*/
|
|
81
|
+
invert?(value: number): Domain | undefined;
|
|
82
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { CustomScaleDefinition } from './CustomScaleDefinition';
|
|
3
|
+
import { CategoricalDomainItem } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is internal representation of scale used in Recharts.
|
|
7
|
+
* Users will provide CustomScaleDefinition or a string, which we will parse into RechartsScale.
|
|
8
|
+
* Most importantly, RechartsScale is fully immutable - there are no setters that mutate the scale in place.
|
|
9
|
+
* This is important for React integration - if the scale changes, we want to trigger re-renders.
|
|
10
|
+
* Mutating the scale in place would not trigger re-renders, leading to stale UI.
|
|
11
|
+
*/
|
|
12
|
+
export interface RechartsScale<Domain extends CategoricalDomainItem = CategoricalDomainItem> {
|
|
13
|
+
/**
|
|
14
|
+
* Returns the scale's current domain.
|
|
15
|
+
* The domain could be:
|
|
16
|
+
* - in categorical scales: an array of strings or categories
|
|
17
|
+
* - in continuous scales: tuple of two numbers: [min, max]
|
|
18
|
+
*/
|
|
19
|
+
domain(): ReadonlyArray<Domain>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the scale’s current range.
|
|
23
|
+
*
|
|
24
|
+
* This should be a readonly tuple of two numbers: [min, max]
|
|
25
|
+
* and so a better type would be `readonly [number, number]` but again - breaking changes,
|
|
26
|
+
* so let's keep that for 4.0.
|
|
27
|
+
*/
|
|
28
|
+
range(): ReadonlyArray<number>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the minimum value from the range.
|
|
32
|
+
*/
|
|
33
|
+
rangeMin(): number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns the maximum value from the range.
|
|
37
|
+
*/
|
|
38
|
+
rangeMax(): number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the given value is within the scale's range.
|
|
42
|
+
* @param value
|
|
43
|
+
*/
|
|
44
|
+
isInRange(value: number): boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns width of each band.
|
|
48
|
+
* Most scales are not banded, so this method is optional.
|
|
49
|
+
* Banded scales (like scaleBand from d3-scale) will implement this method.
|
|
50
|
+
*/
|
|
51
|
+
bandwidth?: () => number;
|
|
52
|
+
/**
|
|
53
|
+
* Quantitative (continuous) scales provide a ticks method that returns representative values from the scale’s domain.
|
|
54
|
+
* Ordinal and band scales do not have this method.
|
|
55
|
+
*
|
|
56
|
+
* An optional count argument requests more or fewer ticks.
|
|
57
|
+
* The number of ticks returned, however, is not necessarily equal to the requested count.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://d3js.org/d3-scale/linear#linear_ticks}
|
|
60
|
+
* @see {@link https://observablehq.com/@d3/scale-ticks}
|
|
61
|
+
*
|
|
62
|
+
* @param count number of ticks
|
|
63
|
+
*/
|
|
64
|
+
ticks?: (count: number | undefined) => ReadonlyArray<number>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Given an arbitrary input, returns the corresponding point derived from the output range if the input is in the scale's domain.
|
|
68
|
+
* If the input is not included in the domain, returns undefined.
|
|
69
|
+
*/
|
|
70
|
+
map(input: unknown, options?: { position?: BandPosition }): number | undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Position within a band for banded scales.
|
|
75
|
+
* In scales that are not banded, this parameter is ignored.
|
|
76
|
+
*
|
|
77
|
+
* @inline
|
|
78
|
+
*/
|
|
79
|
+
export type BandPosition = 'start' | 'middle' | 'end';
|
|
80
|
+
|
|
81
|
+
export function rechartsScaleFactory<Domain extends CategoricalDomainItem = CategoricalDomainItem>(
|
|
82
|
+
d3Scale: CustomScaleDefinition<Domain>,
|
|
83
|
+
): RechartsScale<Domain>;
|
|
84
|
+
export function rechartsScaleFactory<Domain extends CategoricalDomainItem = CategoricalDomainItem>(
|
|
85
|
+
d3Scale: CustomScaleDefinition<Domain> | undefined,
|
|
86
|
+
): RechartsScale<Domain> | undefined;
|
|
87
|
+
export function rechartsScaleFactory<Domain extends CategoricalDomainItem = CategoricalDomainItem>(
|
|
88
|
+
d3Scale: CustomScaleDefinition<Domain> | undefined,
|
|
89
|
+
): RechartsScale<Domain> | undefined {
|
|
90
|
+
if (d3Scale == null) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const ticksFn = d3Scale.ticks;
|
|
94
|
+
const bandwidthFn = d3Scale.bandwidth;
|
|
95
|
+
const d3Range: ReadonlyArray<number> = d3Scale.range();
|
|
96
|
+
const range: [number, number] = [Math.min(...d3Range), Math.max(...d3Range)];
|
|
97
|
+
return {
|
|
98
|
+
domain: () => d3Scale.domain(),
|
|
99
|
+
range: () => range,
|
|
100
|
+
rangeMin: () => range[0],
|
|
101
|
+
rangeMax: () => range[1],
|
|
102
|
+
isInRange(value: number): boolean {
|
|
103
|
+
const first = range[0];
|
|
104
|
+
const last = range[1];
|
|
105
|
+
return first <= last ? value >= first && value <= last : value >= last && value <= first;
|
|
106
|
+
},
|
|
107
|
+
bandwidth: bandwidthFn ? () => bandwidthFn.call(d3Scale) : undefined,
|
|
108
|
+
ticks: ticksFn ? (count: number | undefined) => ticksFn.call(d3Scale, count) : undefined,
|
|
109
|
+
map: (input: Domain, options?: { position?: BandPosition }) => {
|
|
110
|
+
let baseValue = d3Scale(input);
|
|
111
|
+
if (baseValue == null) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (d3Scale.bandwidth && options?.position) {
|
|
115
|
+
const bandWidth = d3Scale.bandwidth();
|
|
116
|
+
switch (options.position) {
|
|
117
|
+
case 'middle':
|
|
118
|
+
baseValue += bandWidth / 2;
|
|
119
|
+
break;
|
|
120
|
+
case 'end':
|
|
121
|
+
baseValue += bandWidth;
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
// 'start' requires no adjustment
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return baseValue;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { InverseScaleFunction } from '../../hooks';
|
|
3
|
+
import { CustomScaleDefinition } from './CustomScaleDefinition';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Binary search to find the index where x would fit in array a.
|
|
5
7
|
* Works for arrays that are sorted both ascending and descending.
|
|
@@ -10,13 +12,14 @@
|
|
|
10
12
|
* @param needle Number to find the insertion index for
|
|
11
13
|
* @returns Index where x would fit in array a
|
|
12
14
|
*/
|
|
13
|
-
export function bisect(haystack
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export function bisect(haystack: ReadonlyArray<number>, needle: number): number {
|
|
16
|
+
let lo = 0;
|
|
17
|
+
let hi = haystack.length;
|
|
18
|
+
const ascending = haystack[0]! < haystack[haystack.length - 1]!;
|
|
19
|
+
|
|
17
20
|
while (lo < hi) {
|
|
18
|
-
|
|
19
|
-
if (ascending ? haystack[mid] < needle : haystack[mid] > needle) {
|
|
21
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
22
|
+
if (ascending ? haystack[mid]! < needle : haystack[mid]! > needle) {
|
|
20
23
|
lo = mid + 1;
|
|
21
24
|
} else {
|
|
22
25
|
hi = mid;
|
|
@@ -29,28 +32,26 @@ export function bisect(haystack, needle) {
|
|
|
29
32
|
* Computes an inverse scale function for categorical/ordinal scales.
|
|
30
33
|
* Uses bisect to find the closest domain value for a given pixel coordinate.
|
|
31
34
|
*/
|
|
32
|
-
export function createCategoricalInverse(
|
|
35
|
+
export function createCategoricalInverse(
|
|
36
|
+
scale: CustomScaleDefinition | undefined,
|
|
37
|
+
allDataPointsOnAxis?: ReadonlyArray<unknown>,
|
|
38
|
+
): InverseScaleFunction | undefined {
|
|
33
39
|
if (!scale) {
|
|
34
40
|
return undefined;
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
allDataPointsOnAxis !== null && allDataPointsOnAxis !== void 0
|
|
38
|
-
? allDataPointsOnAxis
|
|
39
|
-
: scale.domain();
|
|
42
|
+
const domain = allDataPointsOnAxis ?? scale.domain();
|
|
40
43
|
// Build an array of pixel positions for each domain value
|
|
41
44
|
// @ts-expect-error we're attempting to scale unknown without having guarantee that it is a Domain type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
var range = scale.range();
|
|
45
|
+
const pixelPositions: number[] = domain.map((d) => scale(d) ?? 0);
|
|
46
|
+
const range = scale.range();
|
|
47
|
+
|
|
47
48
|
if (domain.length === 0 || range.length < 2) {
|
|
48
49
|
return undefined;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
return (pixelValue: number): unknown => {
|
|
52
53
|
// Find the closest domain value using bisect
|
|
53
|
-
|
|
54
|
+
const index = bisect(pixelPositions, pixelValue);
|
|
54
55
|
|
|
55
56
|
// Clamp to valid range
|
|
56
57
|
if (index <= 0) {
|
|
@@ -61,14 +62,8 @@ export function createCategoricalInverse(scale, allDataPointsOnAxis) {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
// Check which neighbor is closer
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
? _pixelPositions
|
|
67
|
-
: 0;
|
|
68
|
-
var rightPixel =
|
|
69
|
-
(_pixelPositions$index = pixelPositions[index]) !== null && _pixelPositions$index !== void 0
|
|
70
|
-
? _pixelPositions$index
|
|
71
|
-
: 0;
|
|
65
|
+
const leftPixel = pixelPositions[index - 1] ?? 0;
|
|
66
|
+
const rightPixel = pixelPositions[index] ?? 0;
|
|
72
67
|
if (Math.abs(pixelValue - leftPixel) <= Math.abs(pixelValue - rightPixel)) {
|
|
73
68
|
return domain[index - 1];
|
|
74
69
|
}
|