@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,265 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { getPercentValue, isNumber, isPercent } from '../util/DataUtils';
|
|
3
|
+
import { CartesianViewBoxRequired, TrapezoidViewBox } from '../util/types';
|
|
4
|
+
import { TextAnchor, TextVerticalAnchor } from '../component/Text.tsrx';
|
|
5
|
+
import { cartesianViewBoxToTrapezoid } from '../context/chartLayoutContext';
|
|
6
|
+
|
|
7
|
+
export type CartesianLabelPosition =
|
|
8
|
+
| 'top'
|
|
9
|
+
| 'left'
|
|
10
|
+
| 'right'
|
|
11
|
+
| 'bottom'
|
|
12
|
+
| 'inside'
|
|
13
|
+
| 'outside'
|
|
14
|
+
| 'insideLeft'
|
|
15
|
+
| 'insideRight'
|
|
16
|
+
| 'insideTop'
|
|
17
|
+
| 'insideBottom'
|
|
18
|
+
| 'insideTopLeft'
|
|
19
|
+
| 'insideBottomLeft'
|
|
20
|
+
| 'insideTopRight'
|
|
21
|
+
| 'insideBottomRight'
|
|
22
|
+
| 'insideStart'
|
|
23
|
+
| 'insideEnd'
|
|
24
|
+
| 'end'
|
|
25
|
+
| 'center'
|
|
26
|
+
| 'centerTop'
|
|
27
|
+
| 'centerBottom'
|
|
28
|
+
| 'middle'
|
|
29
|
+
| {
|
|
30
|
+
x?: number | string;
|
|
31
|
+
y?: number | string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type GetCartesianPositionOptions = {
|
|
35
|
+
viewBox: TrapezoidViewBox | CartesianViewBoxRequired;
|
|
36
|
+
parentViewBox?: CartesianViewBoxRequired;
|
|
37
|
+
/**
|
|
38
|
+
* The offset to the specified "position". Direction of the offset depends on the position.
|
|
39
|
+
*/
|
|
40
|
+
offset?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The position of the element relative to the view box.
|
|
43
|
+
*/
|
|
44
|
+
position?: CartesianLabelPosition;
|
|
45
|
+
/**
|
|
46
|
+
* If true, the returned width and height will be clamped to keep the element within the parentViewBox.
|
|
47
|
+
* This is useful for preventing labels from overflowing the chart area.
|
|
48
|
+
*/
|
|
49
|
+
clamp?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type CartesianPosition = {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
horizontalAnchor: TextAnchor;
|
|
56
|
+
verticalAnchor: TextVerticalAnchor;
|
|
57
|
+
width?: number;
|
|
58
|
+
height?: number;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Calculates the position and alignment for a generic element in a Cartesian coordinate system.
|
|
63
|
+
*
|
|
64
|
+
* @param options - The options including viewBox, position, and offset.
|
|
65
|
+
* @returns The calculated x, y, alignment and size.
|
|
66
|
+
*/
|
|
67
|
+
export const getCartesianPosition = (options: GetCartesianPositionOptions): CartesianPosition => {
|
|
68
|
+
const { viewBox, position, offset = 0, parentViewBox: parentViewBoxFromOptions, clamp } = options;
|
|
69
|
+
|
|
70
|
+
const { x, y, height, upperWidth, lowerWidth } = cartesianViewBoxToTrapezoid(viewBox);
|
|
71
|
+
|
|
72
|
+
// Funnel.tsx provides a viewBox where `x` is the top-left of the trapezoid shape.
|
|
73
|
+
const upperX = x;
|
|
74
|
+
// The trapezoid is centered, so we can calculate the other corners from the top-left.
|
|
75
|
+
const lowerX = x + (upperWidth - lowerWidth) / 2;
|
|
76
|
+
// middleX is the x-coordinate of the left edge at the vertical midpoint of the trapezoid.
|
|
77
|
+
const middleX = (upperX + lowerX) / 2;
|
|
78
|
+
// The width of the trapezoid at its vertical midpoint.
|
|
79
|
+
const midHeightWidth = (upperWidth + lowerWidth) / 2;
|
|
80
|
+
// The center x-coordinate is constant for the entire height of the trapezoid.
|
|
81
|
+
const centerX = upperX + upperWidth / 2;
|
|
82
|
+
|
|
83
|
+
// Define vertical offsets and position inverts based on the value being positive or negative.
|
|
84
|
+
// This allows labels to be positioned correctly for bars with negative height.
|
|
85
|
+
const verticalSign = height >= 0 ? 1 : -1;
|
|
86
|
+
const verticalOffset = verticalSign * offset;
|
|
87
|
+
const verticalEnd = verticalSign > 0 ? 'end' : 'start';
|
|
88
|
+
const verticalStart = verticalSign > 0 ? 'start' : 'end';
|
|
89
|
+
|
|
90
|
+
// Define horizontal offsets and position inverts based on the value being positive or negative.
|
|
91
|
+
// This allows labels to be positioned correctly for bars with negative width.
|
|
92
|
+
const horizontalSign = upperWidth >= 0 ? 1 : -1;
|
|
93
|
+
const horizontalOffset = horizontalSign * offset;
|
|
94
|
+
const horizontalEnd = horizontalSign > 0 ? 'end' : 'start';
|
|
95
|
+
const horizontalStart = horizontalSign > 0 ? 'start' : 'end';
|
|
96
|
+
|
|
97
|
+
// We assume parentViewBox is generic if provided.
|
|
98
|
+
// The user has asserted that parentViewBox will be CartesianViewBoxRequired if present.
|
|
99
|
+
const parentViewBox = parentViewBoxFromOptions;
|
|
100
|
+
|
|
101
|
+
if (position === 'top') {
|
|
102
|
+
const result: CartesianPosition = {
|
|
103
|
+
x: upperX + upperWidth / 2,
|
|
104
|
+
y: y - verticalOffset,
|
|
105
|
+
horizontalAnchor: 'middle',
|
|
106
|
+
verticalAnchor: verticalEnd,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (clamp && parentViewBox) {
|
|
110
|
+
result.height = Math.max(y - parentViewBox.y, 0);
|
|
111
|
+
result.width = upperWidth;
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (position === 'bottom') {
|
|
117
|
+
const result: CartesianPosition = {
|
|
118
|
+
x: lowerX + lowerWidth / 2,
|
|
119
|
+
y: y + height + verticalOffset,
|
|
120
|
+
horizontalAnchor: 'middle',
|
|
121
|
+
verticalAnchor: verticalStart,
|
|
122
|
+
};
|
|
123
|
+
if (clamp && parentViewBox) {
|
|
124
|
+
result.height = Math.max(parentViewBox.y + parentViewBox.height - (y + height), 0);
|
|
125
|
+
result.width = lowerWidth;
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (position === 'left') {
|
|
131
|
+
const result: CartesianPosition = {
|
|
132
|
+
x: middleX - horizontalOffset,
|
|
133
|
+
y: y + height / 2,
|
|
134
|
+
horizontalAnchor: horizontalEnd,
|
|
135
|
+
verticalAnchor: 'middle',
|
|
136
|
+
};
|
|
137
|
+
if (clamp && parentViewBox) {
|
|
138
|
+
result.width = Math.max(result.x - parentViewBox.x, 0);
|
|
139
|
+
result.height = height;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (position === 'right') {
|
|
145
|
+
const result: CartesianPosition = {
|
|
146
|
+
x: middleX + midHeightWidth + horizontalOffset,
|
|
147
|
+
y: y + height / 2,
|
|
148
|
+
horizontalAnchor: horizontalStart,
|
|
149
|
+
verticalAnchor: 'middle',
|
|
150
|
+
};
|
|
151
|
+
if (clamp && parentViewBox) {
|
|
152
|
+
result.width = Math.max(parentViewBox.x + parentViewBox.width - result.x, 0);
|
|
153
|
+
result.height = height;
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const sizeAttrs = clamp && parentViewBox ? { width: midHeightWidth, height } : {};
|
|
159
|
+
|
|
160
|
+
if (position === 'insideLeft') {
|
|
161
|
+
return {
|
|
162
|
+
x: middleX + horizontalOffset,
|
|
163
|
+
y: y + height / 2,
|
|
164
|
+
horizontalAnchor: horizontalStart,
|
|
165
|
+
verticalAnchor: 'middle',
|
|
166
|
+
...sizeAttrs,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (position === 'insideRight') {
|
|
171
|
+
return {
|
|
172
|
+
x: middleX + midHeightWidth - horizontalOffset,
|
|
173
|
+
y: y + height / 2,
|
|
174
|
+
horizontalAnchor: horizontalEnd,
|
|
175
|
+
verticalAnchor: 'middle',
|
|
176
|
+
...sizeAttrs,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (position === 'insideTop') {
|
|
181
|
+
return {
|
|
182
|
+
x: upperX + upperWidth / 2,
|
|
183
|
+
y: y + verticalOffset,
|
|
184
|
+
horizontalAnchor: 'middle',
|
|
185
|
+
verticalAnchor: verticalStart,
|
|
186
|
+
...sizeAttrs,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (position === 'insideBottom') {
|
|
191
|
+
return {
|
|
192
|
+
x: lowerX + lowerWidth / 2,
|
|
193
|
+
y: y + height - verticalOffset,
|
|
194
|
+
horizontalAnchor: 'middle',
|
|
195
|
+
verticalAnchor: verticalEnd,
|
|
196
|
+
...sizeAttrs,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (position === 'insideTopLeft') {
|
|
201
|
+
return {
|
|
202
|
+
x: upperX + horizontalOffset,
|
|
203
|
+
y: y + verticalOffset,
|
|
204
|
+
horizontalAnchor: horizontalStart,
|
|
205
|
+
verticalAnchor: verticalStart,
|
|
206
|
+
...sizeAttrs,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (position === 'insideTopRight') {
|
|
211
|
+
return {
|
|
212
|
+
x: upperX + upperWidth - horizontalOffset,
|
|
213
|
+
y: y + verticalOffset,
|
|
214
|
+
horizontalAnchor: horizontalEnd,
|
|
215
|
+
verticalAnchor: verticalStart,
|
|
216
|
+
...sizeAttrs,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (position === 'insideBottomLeft') {
|
|
221
|
+
return {
|
|
222
|
+
x: lowerX + horizontalOffset,
|
|
223
|
+
y: y + height - verticalOffset,
|
|
224
|
+
horizontalAnchor: horizontalStart,
|
|
225
|
+
verticalAnchor: verticalEnd,
|
|
226
|
+
...sizeAttrs,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (position === 'insideBottomRight') {
|
|
231
|
+
return {
|
|
232
|
+
x: lowerX + lowerWidth - horizontalOffset,
|
|
233
|
+
y: y + height - verticalOffset,
|
|
234
|
+
horizontalAnchor: horizontalEnd,
|
|
235
|
+
verticalAnchor: verticalEnd,
|
|
236
|
+
...sizeAttrs,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (
|
|
241
|
+
!!position &&
|
|
242
|
+
typeof position === 'object' &&
|
|
243
|
+
(isNumber(position.x) || isPercent(position.x)) &&
|
|
244
|
+
(isNumber(position.y) || isPercent(position.y))
|
|
245
|
+
) {
|
|
246
|
+
// TODO: This is not quite right. The width of the trapezoid changes with y.
|
|
247
|
+
// A percentage-based x should be relative to the width at that y.
|
|
248
|
+
// For now, we use the mid-height width as a reasonable approximation.
|
|
249
|
+
return {
|
|
250
|
+
x: x + getPercentValue(position.x, midHeightWidth),
|
|
251
|
+
y: y + getPercentValue(position.y, height),
|
|
252
|
+
horizontalAnchor: 'end',
|
|
253
|
+
verticalAnchor: 'end',
|
|
254
|
+
...sizeAttrs,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
x: centerX,
|
|
260
|
+
y: y + height / 2,
|
|
261
|
+
horizontalAnchor: 'middle',
|
|
262
|
+
verticalAnchor: 'middle',
|
|
263
|
+
...sizeAttrs,
|
|
264
|
+
};
|
|
265
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { isVisible } from '../util/TickUtils';
|
|
3
|
+
import { CartesianTickItem } from '../util/types';
|
|
4
|
+
import { getEveryNth } from '../util/getEveryNth';
|
|
5
|
+
import { Sign } from './getTicks';
|
|
6
|
+
|
|
7
|
+
export function getEquidistantTicks(
|
|
8
|
+
sign: Sign,
|
|
9
|
+
boundaries: { start: number; end: number },
|
|
10
|
+
getTickSize: (tick: CartesianTickItem, index: number) => number,
|
|
11
|
+
ticks: ReadonlyArray<CartesianTickItem>,
|
|
12
|
+
minTickGap: number,
|
|
13
|
+
): ReadonlyArray<CartesianTickItem> {
|
|
14
|
+
// If the ticks are readonly, then the slice might not be necessary
|
|
15
|
+
const result = (ticks || []).slice();
|
|
16
|
+
|
|
17
|
+
const { start: initialStart, end } = boundaries;
|
|
18
|
+
let index = 0;
|
|
19
|
+
// Premature optimisation idea 1: Estimate a lower bound, and start from there.
|
|
20
|
+
// For now, start from every tick
|
|
21
|
+
let stepsize = 1;
|
|
22
|
+
let start = initialStart;
|
|
23
|
+
|
|
24
|
+
while (stepsize <= result.length) {
|
|
25
|
+
// Given stepsize, evaluate whether every stepsize-th tick can be shown.
|
|
26
|
+
// If it can not, then increase the stepsize by 1, and try again.
|
|
27
|
+
|
|
28
|
+
const entry = ticks?.[index];
|
|
29
|
+
|
|
30
|
+
// Break condition - If we have evaluated all the ticks, then we are done.
|
|
31
|
+
if (entry === undefined) {
|
|
32
|
+
return getEveryNth(ticks, stepsize);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Check if the element collides with the next element
|
|
36
|
+
const i = index;
|
|
37
|
+
let size: number | undefined;
|
|
38
|
+
const getSize = () => {
|
|
39
|
+
if (size === undefined) {
|
|
40
|
+
size = getTickSize(entry, i);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return size;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const tickCoord = entry.coordinate;
|
|
47
|
+
// We will always show the first tick.
|
|
48
|
+
const isShow = index === 0 || isVisible(sign, tickCoord, getSize, start, end);
|
|
49
|
+
|
|
50
|
+
if (!isShow) {
|
|
51
|
+
// Start all over with a larger stepsize
|
|
52
|
+
index = 0;
|
|
53
|
+
start = initialStart;
|
|
54
|
+
stepsize += 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (isShow) {
|
|
58
|
+
// If it can be shown, update the start
|
|
59
|
+
start = tickCoord + sign * (getSize() / 2 + minTickGap);
|
|
60
|
+
index += stepsize;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getEquidistantPreserveEndTicks(
|
|
68
|
+
sign: Sign,
|
|
69
|
+
boundaries: { start: number; end: number },
|
|
70
|
+
getTickSize: (tick: CartesianTickItem, index: number) => number,
|
|
71
|
+
ticks: ReadonlyArray<CartesianTickItem>,
|
|
72
|
+
minTickGap: number,
|
|
73
|
+
): ReadonlyArray<CartesianTickItem> {
|
|
74
|
+
// If the ticks are readonly, then the slice might not be necessary
|
|
75
|
+
// Reworked logic for getEquidistantPreserveEndTicks
|
|
76
|
+
const result = (ticks || []).slice();
|
|
77
|
+
const len = result.length;
|
|
78
|
+
|
|
79
|
+
if (len === 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { start: initialStart, end } = boundaries;
|
|
84
|
+
|
|
85
|
+
// Start with stepsize = 1 (every tick) up to the maximum possible stepsize (len)
|
|
86
|
+
for (let stepsize = 1; stepsize <= len; stepsize++) {
|
|
87
|
+
// 1. Calculate the offset so the last tick (index len - 1) is always included in the sequence.
|
|
88
|
+
const offset = (len - 1) % stepsize;
|
|
89
|
+
let start = initialStart; // `start` tracks the coordinate of the last successfully drawn tick + gap
|
|
90
|
+
let ok = true;
|
|
91
|
+
|
|
92
|
+
// 2. Iterate through the end-anchored sequence: offset, offset + stepsize, ..., len - 1
|
|
93
|
+
for (let index = offset; index < len; index += stepsize) {
|
|
94
|
+
const entry = ticks[index];
|
|
95
|
+
if (entry == null) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const i = index;
|
|
99
|
+
let size: number | undefined;
|
|
100
|
+
|
|
101
|
+
// Use a function to get size, as in the original code
|
|
102
|
+
const getSize = () => {
|
|
103
|
+
if (size === undefined) {
|
|
104
|
+
size = getTickSize(entry, i);
|
|
105
|
+
}
|
|
106
|
+
return size;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const tickCoord = entry.coordinate;
|
|
110
|
+
|
|
111
|
+
// 3. Apply visibility logic (including the first tick special case)
|
|
112
|
+
// The reviewer says *not* to unconditionally bypass checks for the last tick.
|
|
113
|
+
const isShow = index === offset || isVisible(sign, tickCoord, getSize, start, end);
|
|
114
|
+
|
|
115
|
+
if (!isShow) {
|
|
116
|
+
// If any tick in this end-anchored sequence fails visibility/collision,
|
|
117
|
+
// reject this stepsize and move to the next iteration (larger stepsize).
|
|
118
|
+
ok = false;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 4. If showable, update the 'start' coordinate for the next collision check
|
|
123
|
+
if (isShow) {
|
|
124
|
+
start = tickCoord + sign * (getSize() / 2 + minTickGap);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 5. If the entire sequence for this stepsize passed the visibility check, return the result
|
|
129
|
+
if (ok) {
|
|
130
|
+
// Build the final result array explicitly using the validated stepsize and offset.
|
|
131
|
+
const finalTicks: CartesianTickItem[] = [];
|
|
132
|
+
for (let index = offset; index < len; index += stepsize) {
|
|
133
|
+
const tick = ticks[index];
|
|
134
|
+
if (tick != null) {
|
|
135
|
+
finalTicks.push(tick);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return finalTicks;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// If no stepsize works (this shouldn't happen unless minTickGap is huge), return an empty array.
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Adapted from recharts@3.9.2, commit b3451050c027a23957ffa50a2665c9119df21e47.
|
|
2
|
+
import { CartesianTickItem, CartesianViewBoxRequired, Size } from '../util/types';
|
|
3
|
+
import { mathSign, isNumber } from '../util/DataUtils';
|
|
4
|
+
import { getStringSize } from '../util/DOMUtils';
|
|
5
|
+
import { Global } from '../util/Global';
|
|
6
|
+
import {
|
|
7
|
+
isVisible,
|
|
8
|
+
getTickBoundaries,
|
|
9
|
+
getNumberIntervalTicks,
|
|
10
|
+
getAngledTickWidth,
|
|
11
|
+
} from '../util/TickUtils';
|
|
12
|
+
import { getEquidistantTicks, getEquidistantPreserveEndTicks } from './getEquidistantTicks';
|
|
13
|
+
import {
|
|
14
|
+
CartesianAxisSettings,
|
|
15
|
+
XAxisOrientation,
|
|
16
|
+
YAxisOrientation,
|
|
17
|
+
} from '../state/cartesianAxisSlice';
|
|
18
|
+
|
|
19
|
+
export type Sign = 0 | 1 | -1;
|
|
20
|
+
|
|
21
|
+
function getTicksEnd(
|
|
22
|
+
sign: Sign,
|
|
23
|
+
boundaries: { start: number; end: number },
|
|
24
|
+
getTickSize: (tick: CartesianTickItem, index: number) => number,
|
|
25
|
+
ticks: ReadonlyArray<CartesianTickItem>,
|
|
26
|
+
minTickGap: number,
|
|
27
|
+
): ReadonlyArray<CartesianTickItem> {
|
|
28
|
+
const result = (ticks || []).slice();
|
|
29
|
+
const len = result.length;
|
|
30
|
+
|
|
31
|
+
const { start } = boundaries;
|
|
32
|
+
let { end } = boundaries;
|
|
33
|
+
|
|
34
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
35
|
+
const initialEntry = result[i];
|
|
36
|
+
if (initialEntry == null) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
let entry = initialEntry;
|
|
40
|
+
let size: number | undefined;
|
|
41
|
+
const getSize = () => {
|
|
42
|
+
if (size === undefined) {
|
|
43
|
+
size = getTickSize(initialEntry, i);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return size;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (i === len - 1) {
|
|
50
|
+
const gap = sign * (entry.coordinate + (sign * getSize()) / 2 - end);
|
|
51
|
+
result[i] = entry = {
|
|
52
|
+
...entry,
|
|
53
|
+
tickCoord: gap > 0 ? entry.coordinate - gap * sign : entry.coordinate,
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
result[i] = entry = { ...entry, tickCoord: entry.coordinate };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (entry.tickCoord != null) {
|
|
60
|
+
const isShow = isVisible(sign, entry.tickCoord, getSize, start, end);
|
|
61
|
+
|
|
62
|
+
if (isShow) {
|
|
63
|
+
end = entry.tickCoord - sign * (getSize() / 2 + minTickGap);
|
|
64
|
+
result[i] = { ...entry, isShow: true };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getTicksStart(
|
|
73
|
+
sign: Sign,
|
|
74
|
+
boundaries: { start: number; end: number },
|
|
75
|
+
getTickSize: (tick: CartesianTickItem, index: number) => number,
|
|
76
|
+
ticks: ReadonlyArray<CartesianTickItem>,
|
|
77
|
+
minTickGap: number,
|
|
78
|
+
preserveEnd?: boolean,
|
|
79
|
+
): ReadonlyArray<CartesianTickItem> {
|
|
80
|
+
// This method is mutating the array so clone is indeed necessary here
|
|
81
|
+
const result: Array<CartesianTickItem> = (ticks || []).slice();
|
|
82
|
+
const len = result.length;
|
|
83
|
+
|
|
84
|
+
let { start, end } = boundaries;
|
|
85
|
+
|
|
86
|
+
if (preserveEnd) {
|
|
87
|
+
// Try to guarantee the tail to be displayed
|
|
88
|
+
let tail = ticks[len - 1];
|
|
89
|
+
if (tail != null) {
|
|
90
|
+
const tailSize = getTickSize(tail, len - 1);
|
|
91
|
+
const tailGap = sign * (tail.coordinate + (sign * tailSize) / 2 - end);
|
|
92
|
+
result[len - 1] = tail = {
|
|
93
|
+
...tail,
|
|
94
|
+
tickCoord: tailGap > 0 ? tail.coordinate - tailGap * sign : tail.coordinate,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (tail.tickCoord != null) {
|
|
98
|
+
const isTailShow = isVisible(sign, tail.tickCoord, () => tailSize, start, end);
|
|
99
|
+
|
|
100
|
+
if (isTailShow) {
|
|
101
|
+
end = tail.tickCoord - sign * (tailSize / 2 + minTickGap);
|
|
102
|
+
result[len - 1] = { ...tail, isShow: true };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const count = preserveEnd ? len - 1 : len;
|
|
109
|
+
for (let i = 0; i < count; i++) {
|
|
110
|
+
const initialEntry = result[i];
|
|
111
|
+
if (initialEntry == null) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let entry = initialEntry;
|
|
115
|
+
let size: number | undefined;
|
|
116
|
+
const getSize = () => {
|
|
117
|
+
if (size === undefined) {
|
|
118
|
+
size = getTickSize(initialEntry, i);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return size;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (i === 0) {
|
|
125
|
+
const gap = sign * (entry.coordinate - (sign * getSize()) / 2 - start);
|
|
126
|
+
result[i] = entry = {
|
|
127
|
+
...entry,
|
|
128
|
+
tickCoord: gap < 0 ? entry.coordinate - gap * sign : entry.coordinate,
|
|
129
|
+
};
|
|
130
|
+
} else {
|
|
131
|
+
result[i] = entry = { ...entry, tickCoord: entry.coordinate };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (entry.tickCoord != null) {
|
|
135
|
+
const isShow = isVisible(sign, entry.tickCoord, getSize, start, end);
|
|
136
|
+
|
|
137
|
+
if (isShow) {
|
|
138
|
+
start = entry.tickCoord + sign * (getSize() / 2 + minTickGap);
|
|
139
|
+
result[i] = { ...entry, isShow: true };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type GetTicksInput = {
|
|
148
|
+
angle?: number;
|
|
149
|
+
interval: CartesianAxisSettings['interval'] | undefined;
|
|
150
|
+
minTickGap: number;
|
|
151
|
+
orientation: XAxisOrientation | YAxisOrientation;
|
|
152
|
+
tick: CartesianAxisSettings['tick'];
|
|
153
|
+
tickFormatter?: CartesianAxisSettings['tickFormatter'];
|
|
154
|
+
ticks: ReadonlyArray<CartesianTickItem> | null;
|
|
155
|
+
unit?: string | number;
|
|
156
|
+
viewBox: CartesianViewBoxRequired;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export function getTicks(
|
|
160
|
+
props: GetTicksInput,
|
|
161
|
+
fontSize?: string,
|
|
162
|
+
letterSpacing?: string,
|
|
163
|
+
): ReadonlyArray<CartesianTickItem> {
|
|
164
|
+
const { tick, ticks, viewBox, minTickGap, orientation, interval, tickFormatter, unit, angle } =
|
|
165
|
+
props;
|
|
166
|
+
|
|
167
|
+
if (!ticks || !ticks.length || !tick) {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (isNumber(interval) || Global.isSsr) {
|
|
172
|
+
return getNumberIntervalTicks(ticks, isNumber(interval) ? interval : 0) ?? [];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let candidates: ReadonlyArray<CartesianTickItem> = [];
|
|
176
|
+
|
|
177
|
+
const sizeKey = orientation === 'top' || orientation === 'bottom' ? 'width' : 'height';
|
|
178
|
+
const unitSize: Size =
|
|
179
|
+
unit && sizeKey === 'width'
|
|
180
|
+
? getStringSize(unit, { fontSize, letterSpacing })
|
|
181
|
+
: { width: 0, height: 0 };
|
|
182
|
+
|
|
183
|
+
const getTickSize = (content: CartesianTickItem, index: number) => {
|
|
184
|
+
const value =
|
|
185
|
+
typeof tickFormatter === 'function' ? tickFormatter(content.value, index) : content.value;
|
|
186
|
+
// Recharts only supports angles when sizeKey === 'width'
|
|
187
|
+
return sizeKey === 'width'
|
|
188
|
+
? getAngledTickWidth(getStringSize(value, { fontSize, letterSpacing }), unitSize, angle)
|
|
189
|
+
: getStringSize(value, { fontSize, letterSpacing })[sizeKey];
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const tick0 = ticks[0];
|
|
193
|
+
const tick1 = ticks[1];
|
|
194
|
+
const sign =
|
|
195
|
+
ticks.length >= 2 && tick0 != null && tick1 != null
|
|
196
|
+
? mathSign(tick1.coordinate - tick0.coordinate)
|
|
197
|
+
: 1;
|
|
198
|
+
const boundaries = getTickBoundaries(viewBox, sign, sizeKey);
|
|
199
|
+
|
|
200
|
+
if (interval === 'equidistantPreserveStart') {
|
|
201
|
+
return getEquidistantTicks(sign, boundaries, getTickSize, ticks, minTickGap);
|
|
202
|
+
}
|
|
203
|
+
if (interval === 'equidistantPreserveEnd') {
|
|
204
|
+
return getEquidistantPreserveEndTicks(sign, boundaries, getTickSize, ticks, minTickGap);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (interval === 'preserveStart' || interval === 'preserveStartEnd') {
|
|
208
|
+
candidates = getTicksStart(
|
|
209
|
+
sign,
|
|
210
|
+
boundaries,
|
|
211
|
+
getTickSize,
|
|
212
|
+
ticks,
|
|
213
|
+
minTickGap,
|
|
214
|
+
interval === 'preserveStartEnd',
|
|
215
|
+
);
|
|
216
|
+
} else {
|
|
217
|
+
candidates = getTicksEnd(sign, boundaries, getTickSize, ticks, minTickGap);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return candidates.filter((entry) => entry.isShow);
|
|
221
|
+
}
|
package/src/chart/AreaChart.tsrx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Ref } from '../util/OctaneTypes.ts';
|
|
2
|
+
|
|
1
3
|
import { arrayTooltipSearcher } from '../state/optionsSlice';
|
|
2
4
|
import { CartesianChart } from './CartesianChart.tsrx';
|
|
3
5
|
import { CartesianChartProps, TooltipEventType } from '../util/types';
|
|
@@ -9,7 +11,9 @@ const allowedTooltipTypes: ReadonlyArray<TooltipEventType> = ['axis'];
|
|
|
9
11
|
* @provides CartesianViewBoxContext
|
|
10
12
|
* @provides CartesianChartContext
|
|
11
13
|
*/
|
|
12
|
-
export function AreaChart(props: CartesianChartProps<
|
|
14
|
+
export function AreaChart<DataPointType = unknown>(props: CartesianChartProps<DataPointType> & {
|
|
15
|
+
ref?: Ref<SVGSVGElement>;
|
|
16
|
+
}) {
|
|
13
17
|
const { ref, ...rest } = props;
|
|
14
18
|
return <CartesianChart
|
|
15
19
|
chartName="AreaChart"
|
package/src/chart/BarChart.tsrx
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
import type { CartesianChartProps } from '../util/types';
|
|
2
|
+
import type { Ref } from '../util/OctaneTypes.ts';
|
|
3
|
+
import type { TooltipEventType } from '../util/types';
|
|
4
|
+
|
|
1
5
|
// Port of chart/BarChart.tsx.
|
|
2
6
|
import { arrayTooltipSearcher } from '../state/optionsSlice';
|
|
3
7
|
import { CartesianChart } from './CartesianChart.tsrx';
|
|
4
8
|
|
|
5
|
-
const allowedTooltipTypes = ['axis', 'item'];
|
|
9
|
+
const allowedTooltipTypes: ReadonlyArray<TooltipEventType> = ['axis', 'item'];
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* @consumes ResponsiveContainerContext
|
|
9
13
|
* @provides CartesianViewBoxContext
|
|
10
14
|
* @provides CartesianChartContext
|
|
11
15
|
*/
|
|
12
|
-
export function BarChart(props
|
|
16
|
+
export function BarChart<DataPointType = unknown>(props: CartesianChartProps<DataPointType> & {
|
|
17
|
+
ref?: Ref<SVGSVGElement>;
|
|
18
|
+
}) {
|
|
13
19
|
const { ref, ...rest } = props;
|
|
14
20
|
return <CartesianChart
|
|
15
21
|
chartName="BarChart"
|