@solidports/recharts 0.1.0
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 +22 -0
- package/NOTICE +19 -0
- package/README.md +102 -0
- package/dist/dev.js +28564 -0
- package/dist/index.d.ts +7859 -0
- package/dist/index.js +28546 -0
- package/package.json +98 -0
- package/src/animation/AnimatedItems.tsx +183 -0
- package/src/animation/AnimationController.ts +33 -0
- package/src/animation/AnimationControllerImpl.ts +36 -0
- package/src/animation/AnimationHandle.ts +307 -0
- package/src/animation/CSSTransitionAnimate.tsx +170 -0
- package/src/animation/JavascriptAnimate.tsx +119 -0
- package/src/animation/easing.ts +221 -0
- package/src/animation/matchBy.ts +164 -0
- package/src/animation/timeoutController.ts +70 -0
- package/src/animation/useAnimationController.tsx +34 -0
- package/src/animation/useAnimationStartSnapshot.ts +118 -0
- package/src/animation/util.ts +41 -0
- package/src/cartesian/Area.tsx +915 -0
- package/src/cartesian/AreaRevealShape.tsx +190 -0
- package/src/cartesian/Bar.tsx +1369 -0
- package/src/cartesian/BarStack.tsx +152 -0
- package/src/cartesian/Brush.tsx +951 -0
- package/src/cartesian/CartesianAxis.tsx +722 -0
- package/src/cartesian/CartesianGrid.tsx +711 -0
- package/src/cartesian/ErrorBar.tsx +361 -0
- package/src/cartesian/Funnel.tsx +803 -0
- package/src/cartesian/GraphicalItemClipPath.tsx +67 -0
- package/src/cartesian/Line.tsx +863 -0
- package/src/cartesian/LineDrawShape.tsx +89 -0
- package/src/cartesian/ReferenceArea.tsx +331 -0
- package/src/cartesian/ReferenceDot.tsx +304 -0
- package/src/cartesian/ReferenceLine.tsx +474 -0
- package/src/cartesian/Scatter.tsx +888 -0
- package/src/cartesian/XAxis.tsx +433 -0
- package/src/cartesian/YAxis.tsx +443 -0
- package/src/cartesian/ZAxis.tsx +155 -0
- package/src/cartesian/cartesianPositionToCSSTranslate.tsx +29 -0
- package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +21 -0
- package/src/cartesian/getCartesianPosition.tsx +267 -0
- package/src/cartesian/getEquidistantTicks.ts +144 -0
- package/src/cartesian/getTicks.ts +225 -0
- package/src/cartesian/isOutsidePosition.ts +15 -0
- package/src/cartesian/useAnimatedLineLength.ts +54 -0
- package/src/chart/AreaChart.tsx +29 -0
- package/src/chart/BarChart.tsx +29 -0
- package/src/chart/CartesianChart.tsx +131 -0
- package/src/chart/CategoricalChart.tsx +94 -0
- package/src/chart/ComposedChart.tsx +29 -0
- package/src/chart/FunnelChart.tsx +29 -0
- package/src/chart/LineChart.tsx +29 -0
- package/src/chart/PieChart.tsx +50 -0
- package/src/chart/PolarChart.tsx +164 -0
- package/src/chart/RadarChart.tsx +70 -0
- package/src/chart/RadialBarChart.tsx +46 -0
- package/src/chart/RechartsWrapper.tsx +551 -0
- package/src/chart/Sankey.tsx +1534 -0
- package/src/chart/ScatterChart.tsx +29 -0
- package/src/chart/SunburstChart.tsx +504 -0
- package/src/chart/Treemap.tsx +1223 -0
- package/src/chart/createInitialRootProps.ts +24 -0
- package/src/chart/types.ts +53 -0
- package/src/component/ActivePoints.tsx +144 -0
- package/src/component/Cell.tsx +37 -0
- package/src/component/Cursor.tsx +185 -0
- package/src/component/Customized.tsx +50 -0
- package/src/component/DefaultLegendContent.tsx +348 -0
- package/src/component/DefaultTooltipContent.tsx +224 -0
- package/src/component/Dots.tsx +157 -0
- package/src/component/Label.tsx +636 -0
- package/src/component/LabelList.tsx +375 -0
- package/src/component/Legend.tsx +512 -0
- package/src/component/ResponsiveContainer.tsx +348 -0
- package/src/component/Text.tsx +541 -0
- package/src/component/Tooltip.tsx +470 -0
- package/src/component/TooltipBoundingBox.tsx +146 -0
- package/src/component/responsiveContainerUtils.ts +134 -0
- package/src/container/ClipPathProvider.tsx +51 -0
- package/src/container/Layer.tsx +38 -0
- package/src/container/RootSurface.tsx +120 -0
- package/src/container/Surface.tsx +61 -0
- package/src/context/CellsContext.tsx +54 -0
- package/src/context/ErrorBarContext.tsx +146 -0
- package/src/context/GraphicalItemChildrenScope.tsx +18 -0
- package/src/context/PanoramaContext.tsx +9 -0
- package/src/context/RegisterGraphicalItemId.tsx +30 -0
- package/src/context/accessibilityContext.tsx +6 -0
- package/src/context/brushUpdateContext.tsx +9 -0
- package/src/context/chartDataContext.tsx +97 -0
- package/src/context/chartLayoutContext.tsx +201 -0
- package/src/context/legendPayloadContext.tsx +20 -0
- package/src/context/legendPortalContext.tsx +12 -0
- package/src/context/tooltipContext.tsx +89 -0
- package/src/context/tooltipPortalContext.tsx +12 -0
- package/src/context/useTooltipAxis.ts +22 -0
- package/src/hooks.ts +476 -0
- package/src/index.ts +280 -0
- package/src/polar/Pie.tsx +1360 -0
- package/src/polar/PolarAngleAxis.tsx +616 -0
- package/src/polar/PolarGrid.tsx +312 -0
- package/src/polar/PolarRadiusAxis.tsx +547 -0
- package/src/polar/Radar.tsx +734 -0
- package/src/polar/RadialBar.tsx +917 -0
- package/src/polar/defaultPolarAngleAxisProps.tsx +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.tsx +25 -0
- package/src/shape/Cross.tsx +89 -0
- package/src/shape/Curve.tsx +343 -0
- package/src/shape/Dot.tsx +70 -0
- package/src/shape/Polygon.tsx +195 -0
- package/src/shape/Rectangle.tsx +470 -0
- package/src/shape/Sector.tsx +347 -0
- package/src/shape/Symbols.tsx +139 -0
- package/src/shape/Trapezoid.tsx +280 -0
- package/src/state/RechartsStateContext.tsx +12 -0
- package/src/state/RechartsStateProvider.tsx +87 -0
- package/src/state/RechartsStoreContext.tsx +25 -0
- package/src/state/RechartsStoreProvider.tsx +35 -0
- package/src/state/ReportChartProps.tsx +40 -0
- package/src/state/ReportEventSettings.tsx +30 -0
- package/src/state/ReportMainChartProps.tsx +61 -0
- package/src/state/ReportPolarOptions.tsx +35 -0
- package/src/state/SetGraphicalItem.ts +79 -0
- package/src/state/SetLegendPayload.ts +134 -0
- package/src/state/SetTooltipEntrySettings.tsx +72 -0
- package/src/state/actions.ts +464 -0
- package/src/state/brushSlice.ts +13 -0
- package/src/state/cartesianAxisSlice.ts +141 -0
- package/src/state/chartDataSlice.ts +50 -0
- package/src/state/chartState.ts +297 -0
- package/src/state/errorBarSlice.ts +29 -0
- package/src/state/eventSettingsSlice.ts +8 -0
- package/src/state/events.ts +76 -0
- package/src/state/externalEventsMiddleware.ts +255 -0
- package/src/state/graphicalItemsSlice.ts +74 -0
- package/src/state/hooks/useChartSelectors.tsx +45 -0
- package/src/state/keyboardEventsMiddleware.ts +228 -0
- package/src/state/layoutSlice.ts +21 -0
- package/src/state/legendSlice.ts +57 -0
- package/src/state/mouseEventsMiddleware.ts +185 -0
- package/src/state/optionsSlice.ts +47 -0
- package/src/state/polarAxisSlice.ts +10 -0
- package/src/state/polarOptionsSlice.ts +12 -0
- package/src/state/rawData.ts +26 -0
- package/src/state/referenceElementsSlice.ts +40 -0
- package/src/state/renderedTicksSlice.ts +15 -0
- package/src/state/rootPropsSlice.ts +47 -0
- package/src/state/selectors/areaSelectors.ts +240 -0
- package/src/state/selectors/arrayEqualityCheck.ts +29 -0
- package/src/state/selectors/axisSelectors.ts +2157 -0
- package/src/state/selectors/barSelectors.ts +310 -0
- package/src/state/selectors/barStackSelectors.ts +77 -0
- package/src/state/selectors/brushSelectors.ts +33 -0
- package/src/state/selectors/chartSelector.ts +185 -0
- package/src/state/selectors/combiners/combineActiveLabel.ts +16 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +95 -0
- package/src/state/selectors/combiners/combineAllBarPositions.ts +122 -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 +80 -0
- package/src/state/selectors/combiners/combineCheckedDomain.ts +48 -0
- package/src/state/selectors/combiners/combineConfiguredScale.ts +111 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +45 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.ts +50 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.ts +16 -0
- package/src/state/selectors/combiners/combineRealScaleType.ts +44 -0
- 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 +205 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +58 -0
- package/src/state/selectors/containerSelectors.ts +12 -0
- package/src/state/selectors/dataSelectors.ts +88 -0
- package/src/state/selectors/funnelSelectors.ts +75 -0
- package/src/state/selectors/graphicalItemSelectors.ts +30 -0
- package/src/state/selectors/legendSelectors.ts +29 -0
- package/src/state/selectors/lineSelectors.ts +134 -0
- package/src/state/selectors/numberDomainEqualityCheck.ts +14 -0
- package/src/state/selectors/pickAxisId.ts +5 -0
- package/src/state/selectors/pickAxisType.ts +3 -0
- package/src/state/selectors/pieSelectors.ts +97 -0
- package/src/state/selectors/polarAxisSelectors.ts +201 -0
- package/src/state/selectors/polarGridSelectors.ts +28 -0
- package/src/state/selectors/polarScaleSelectors.ts +133 -0
- package/src/state/selectors/polarSelectors.ts +219 -0
- package/src/state/selectors/radarSelectors.ts +191 -0
- package/src/state/selectors/radialBarSelectors.ts +435 -0
- package/src/state/selectors/rootPropsSelectors.ts +25 -0
- package/src/state/selectors/scatterSelectors.ts +96 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.ts +26 -0
- package/src/state/selectors/selectAllAxes.ts +17 -0
- package/src/state/selectors/selectChartOffset.ts +16 -0
- package/src/state/selectors/selectChartOffsetInternal.ts +136 -0
- package/src/state/selectors/selectLegendArea.ts +20 -0
- package/src/state/selectors/selectPlotArea.ts +22 -0
- package/src/state/selectors/selectTooltipAxisId.ts +7 -0
- package/src/state/selectors/selectTooltipAxisType.ts +32 -0
- package/src/state/selectors/selectTooltipEventType.ts +48 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.ts +6 -0
- package/src/state/selectors/selectTooltipSettings.ts +39 -0
- package/src/state/selectors/selectTooltipState.ts +8 -0
- package/src/state/selectors/selectors.ts +271 -0
- package/src/state/selectors/tooltipSelectors.ts +578 -0
- package/src/state/selectors/touchSelectors.ts +31 -0
- package/src/state/store.ts +29 -0
- package/src/state/storeIdentity.ts +9 -0
- package/src/state/teardownWrite.ts +10 -0
- package/src/state/tooltipInteraction.ts +23 -0
- package/src/state/tooltipSlice.ts +334 -0
- package/src/state/touchEventsMiddleware.ts +214 -0
- package/src/state/types/AnimationSettings.ts +20 -0
- package/src/state/types/AreaSettings.ts +14 -0
- package/src/state/types/BarSettings.ts +15 -0
- package/src/state/types/LineSettings.ts +9 -0
- package/src/state/types/PieSettings.ts +34 -0
- package/src/state/types/RadarSettings.ts +5 -0
- package/src/state/types/RadialBarSettings.ts +10 -0
- package/src/state/types/ScatterSettings.ts +12 -0
- package/src/state/types/StackedGraphicalItem.ts +34 -0
- package/src/state/useChartState.ts +17 -0
- package/src/state/zIndexSlice.ts +39 -0
- package/src/synchronisation/syncSelectors.ts +7 -0
- package/src/synchronisation/types.ts +44 -0
- package/src/synchronisation/useChartSynchronisation.tsx +404 -0
- package/src/theme/RechartsTheme.ts +16 -0
- package/src/theme/RechartsThemeContext.ts +19 -0
- package/src/theme/darkTheme.ts +13 -0
- package/src/theme/graphicalItemIdentity.ts +70 -0
- package/src/theme/legacyTheme.ts +17 -0
- package/src/theme/lightTheme.ts +13 -0
- package/src/types.ts +54 -0
- package/src/util/ActiveShapeUtils.tsx +162 -0
- package/src/util/BarUtils.tsx +62 -0
- package/src/util/BarePortal.tsx +50 -0
- package/src/util/CamelCaseSVGAttrs.ts +34 -0
- package/src/util/CartesianUtils.ts +48 -0
- package/src/util/ChartUtils.ts +802 -0
- package/src/util/Constants.ts +42 -0
- package/src/util/CssPrefixUtils.ts +20 -0
- package/src/util/DOMUtils.ts +129 -0
- package/src/util/DataUtils.ts +216 -0
- package/src/util/Events.ts +16 -0
- package/src/util/FunnelUtils.tsx +15 -0
- package/src/util/Global.ts +12 -0
- package/src/util/IfOverflow.ts +15 -0
- package/src/util/LRUCache.ts +41 -0
- package/src/util/LogUtils.ts +22 -0
- package/src/util/PolarUtils.ts +132 -0
- package/src/util/RadialBarUtils.tsx +24 -0
- package/src/util/ReactUtils.ts +95 -0
- package/src/util/ReduceCSSCalc.ts +187 -0
- package/src/util/ScatterUtils.tsx +52 -0
- package/src/util/ShapeElementProps.tsx +87 -0
- package/src/util/TickUtils.ts +60 -0
- package/src/util/XAxisUtils.ts +48 -0
- package/src/util/YAxisUtils.ts +48 -0
- package/src/util/axisPropsAreEqual.ts +48 -0
- package/src/util/createCartesianCharts.tsx +150 -0
- package/src/util/createEventProxy.ts +20 -0
- package/src/util/createPolarCharts.tsx +112 -0
- package/src/util/cursor/getCursorPoints.ts +46 -0
- package/src/util/cursor/getCursorRectangle.ts +28 -0
- package/src/util/cursor/getRadialCursorPoints.ts +32 -0
- package/src/util/excludeEventProps.ts +171 -0
- package/src/util/getActiveCoordinate.ts +213 -0
- package/src/util/getAxisTypeBasedOnLayout.ts +21 -0
- package/src/util/getClassNameFromUnknown.ts +6 -0
- package/src/util/getEveryNth.ts +27 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.ts +35 -0
- package/src/util/getRelativeCoordinate.ts +80 -0
- package/src/util/getSliced.ts +13 -0
- package/src/util/hoverDedupe.ts +41 -0
- package/src/util/isDomainSpecifiedByUser.ts +219 -0
- package/src/util/isWellBehavedNumber.ts +7 -0
- package/src/util/pathTotalLength.ts +25 -0
- package/src/util/payload/getUniqPayload.ts +28 -0
- package/src/util/propsAreEqual.ts +121 -0
- package/src/util/resolveDefaultProps.ts +161 -0
- package/src/util/round.ts +32 -0
- package/src/util/scale/CartesianScaleHelper.ts +72 -0
- package/src/util/scale/CustomScaleDefinition.ts +81 -0
- package/src/util/scale/RechartsScale.ts +130 -0
- package/src/util/scale/createCategoricalInverse.ts +72 -0
- package/src/util/scale/getNiceTickValues.ts +311 -0
- package/src/util/scale/index.ts +2 -0
- package/src/util/scale/util/arithmetic.ts +54 -0
- package/src/util/solid-1-compat.ts +310 -0
- package/src/util/solidJsxCamelAugment.d.ts +84 -0
- package/src/util/stacks/getStackSeriesIdentifier.ts +21 -0
- package/src/util/stacks/stackTypes.ts +60 -0
- package/src/util/structurallyEqual.ts +31 -0
- package/src/util/svgPropertiesAndEvents.ts +53 -0
- package/src/util/svgPropertiesNoEvents.ts +571 -0
- package/src/util/tooltip/translate.ts +171 -0
- package/src/util/typedDataKey.ts +48 -0
- package/src/util/types.ts +1560 -0
- package/src/util/useAnimationId.ts +31 -0
- package/src/util/useElementOffset.ts +110 -0
- package/src/util/useId.ts +8 -0
- package/src/util/usePrefersReducedMotion.ts +48 -0
- package/src/util/useReportScale.ts +24 -0
- package/src/util/useUniqueId.ts +30 -0
- package/src/zIndex/DefaultZIndexes.ts +84 -0
- package/src/zIndex/ZIndexLayer.tsx +121 -0
- package/src/zIndex/ZIndexPortal.tsx +79 -0
- package/src/zIndex/getZIndexFromUnknown.ts +14 -0
- package/src/zIndex/zIndexSelectors.ts +48 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { selectLegendSettings, selectLegendSize } from "./legendSelectors"
|
|
3
|
+
import type {
|
|
4
|
+
CartesianViewBoxRequired,
|
|
5
|
+
ChartOffsetInternal,
|
|
6
|
+
Margin,
|
|
7
|
+
OffsetHorizontal,
|
|
8
|
+
OffsetVertical,
|
|
9
|
+
Size,
|
|
10
|
+
} from "../../util/types"
|
|
11
|
+
import type { XAxisSettings, YAxisSettings } from "../cartesianAxisSlice"
|
|
12
|
+
import type { LegendSettings } from "../legendSlice"
|
|
13
|
+
import { appendOffsetOfLegend } from "../../util/ChartUtils"
|
|
14
|
+
import { selectChartHeight, selectChartWidth, selectMargin } from "./containerSelectors"
|
|
15
|
+
import { selectAllXAxes, selectAllYAxes } from "./selectAllAxes"
|
|
16
|
+
import { DEFAULT_X_AXIS_HEIGHT, DEFAULT_Y_AXIS_WIDTH } from "../../util/Constants"
|
|
17
|
+
import type { ChartState } from "../store"
|
|
18
|
+
import { chartSelector } from "./chartSelector"
|
|
19
|
+
import { readChartState } from "../chartState"
|
|
20
|
+
|
|
21
|
+
export const selectBrushHeight = chartSelector((state: ChartState) => {
|
|
22
|
+
return readChartState(state).brush.height ?? 0
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const selectLeftAxesOffset = chartSelector(function selectLeftAxesOffset(state: ChartState): number {
|
|
26
|
+
const yAxes = selectAllYAxes(state)
|
|
27
|
+
return yAxes.reduce((result: number, entry: YAxisSettings): number => {
|
|
28
|
+
if (entry.orientation === "left" && !entry.mirror && !entry.hide) {
|
|
29
|
+
const width = typeof entry.width === "number" ? entry.width : DEFAULT_Y_AXIS_WIDTH
|
|
30
|
+
return result + width
|
|
31
|
+
}
|
|
32
|
+
return result
|
|
33
|
+
}, 0)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const selectRightAxesOffset = chartSelector(function selectRightAxesOffset(state: ChartState): number {
|
|
37
|
+
const yAxes = selectAllYAxes(state)
|
|
38
|
+
return yAxes.reduce((result: number, entry: YAxisSettings): number => {
|
|
39
|
+
if (entry.orientation === "right" && !entry.mirror && !entry.hide) {
|
|
40
|
+
const width = typeof entry.width === "number" ? entry.width : DEFAULT_Y_AXIS_WIDTH
|
|
41
|
+
return result + width
|
|
42
|
+
}
|
|
43
|
+
return result
|
|
44
|
+
}, 0)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const selectTopAxesOffset = chartSelector(function selectTopAxesOffset(state: ChartState): number {
|
|
48
|
+
const xAxes = selectAllXAxes(state)
|
|
49
|
+
return xAxes.reduce((result: number, entry: XAxisSettings): number => {
|
|
50
|
+
if (entry.orientation === "top" && !entry.mirror && !entry.hide) {
|
|
51
|
+
const height = typeof entry.height === "number" ? entry.height : DEFAULT_X_AXIS_HEIGHT
|
|
52
|
+
return result + height
|
|
53
|
+
}
|
|
54
|
+
return result
|
|
55
|
+
}, 0)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const selectBottomAxesOffset = chartSelector(function selectBottomAxesOffset(state: ChartState): number {
|
|
59
|
+
const xAxes = selectAllXAxes(state)
|
|
60
|
+
return xAxes.reduce((result: number, entry: XAxisSettings): number => {
|
|
61
|
+
if (entry.orientation === "bottom" && !entry.mirror && !entry.hide) {
|
|
62
|
+
const height = typeof entry.height === "number" ? entry.height : DEFAULT_X_AXIS_HEIGHT
|
|
63
|
+
return result + height
|
|
64
|
+
}
|
|
65
|
+
return result
|
|
66
|
+
}, 0)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* For internal use only.
|
|
71
|
+
*
|
|
72
|
+
* @param state root state
|
|
73
|
+
* @return ChartOffsetInternal
|
|
74
|
+
*/
|
|
75
|
+
export const selectChartOffsetInternal = chartSelector(function selectChartOffsetInternal(state: ChartState): ChartOffsetInternal {
|
|
76
|
+
const chartWidth: number = selectChartWidth(state)
|
|
77
|
+
const chartHeight: number = selectChartHeight(state)
|
|
78
|
+
const margin: Margin = selectMargin(state)
|
|
79
|
+
const brushHeight: number = selectBrushHeight(state)
|
|
80
|
+
const leftAxesOffset: number = selectLeftAxesOffset(state)
|
|
81
|
+
const rightAxesOffset: number = selectRightAxesOffset(state)
|
|
82
|
+
const topAxesOffset: number = selectTopAxesOffset(state)
|
|
83
|
+
const bottomAxesOffset: number = selectBottomAxesOffset(state)
|
|
84
|
+
const legendSettings: LegendSettings = selectLegendSettings(state)
|
|
85
|
+
const legendSize: Size = selectLegendSize(state)
|
|
86
|
+
|
|
87
|
+
const offsetH: OffsetHorizontal = {
|
|
88
|
+
left: (margin.left || 0) + leftAxesOffset,
|
|
89
|
+
right: (margin.right || 0) + rightAxesOffset,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const offsetV: OffsetVertical = {
|
|
93
|
+
bottom: (margin.bottom || 0) + bottomAxesOffset,
|
|
94
|
+
top: (margin.top || 0) + topAxesOffset,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let offset = { ...offsetV, ...offsetH }
|
|
98
|
+
|
|
99
|
+
const brushBottom = offset.bottom
|
|
100
|
+
|
|
101
|
+
offset.bottom += brushHeight
|
|
102
|
+
|
|
103
|
+
offset = appendOffsetOfLegend(offset, legendSettings, legendSize)
|
|
104
|
+
|
|
105
|
+
const offsetWidth = chartWidth - offset.left - offset.right
|
|
106
|
+
const offsetHeight = chartHeight - offset.top - offset.bottom
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
brushBottom,
|
|
110
|
+
...offset,
|
|
111
|
+
/* never return negative values for height and width */
|
|
112
|
+
height: Math.max(offsetHeight, 0),
|
|
113
|
+
width: Math.max(offsetWidth, 0),
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
export const selectChartViewBox = chartSelector(function selectChartViewBox(state: ChartState): CartesianViewBoxRequired {
|
|
118
|
+
const offset = selectChartOffsetInternal(state)
|
|
119
|
+
return {
|
|
120
|
+
height: offset.height,
|
|
121
|
+
width: offset.width,
|
|
122
|
+
x: offset.left,
|
|
123
|
+
y: offset.top,
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
export const selectAxisViewBox = chartSelector(function selectAxisViewBox(state: ChartState): CartesianViewBoxRequired {
|
|
128
|
+
const width = selectChartWidth(state)
|
|
129
|
+
const height = selectChartHeight(state)
|
|
130
|
+
return {
|
|
131
|
+
height,
|
|
132
|
+
width,
|
|
133
|
+
x: 0,
|
|
134
|
+
y: 0,
|
|
135
|
+
}
|
|
136
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CartesianViewBoxRequired, Margin } from "../../util/types"
|
|
2
|
+
import type { ChartState } from "../store"
|
|
3
|
+
import { selectChartHeight, selectChartWidth, selectMargin } from "./containerSelectors"
|
|
4
|
+
import { chartSelector } from "./chartSelector"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Margin-inset chart area. Outside Legend positions (`top`/`bottom`/`left`/`right`)
|
|
8
|
+
* use this instead of the plot-area viewBox so the legend sits beyond any axes.
|
|
9
|
+
*/
|
|
10
|
+
export const selectLegendArea = chartSelector(function selectLegendArea(state: ChartState): CartesianViewBoxRequired {
|
|
11
|
+
const chartWidth: number = selectChartWidth(state)
|
|
12
|
+
const chartHeight: number = selectChartHeight(state)
|
|
13
|
+
const margin: Margin = selectMargin(state)
|
|
14
|
+
return {
|
|
15
|
+
height: Math.max(chartHeight - (margin.top || 0) - (margin.bottom || 0), 0),
|
|
16
|
+
width: Math.max(chartWidth - (margin.left || 0) - (margin.right || 0), 0),
|
|
17
|
+
x: margin.left || 0,
|
|
18
|
+
y: margin.top || 0,
|
|
19
|
+
}
|
|
20
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { selectChartOffset } from "./selectChartOffset"
|
|
3
|
+
import { selectChartHeight, selectChartWidth } from "./containerSelectors"
|
|
4
|
+
import { chartSelector } from "./chartSelector"
|
|
5
|
+
import type { ChartState } from "../store"
|
|
6
|
+
|
|
7
|
+
export const selectPlotArea = chartSelector(function selectPlotArea(state: ChartState) {
|
|
8
|
+
const offset = selectChartOffset(state)
|
|
9
|
+
const chartWidth = selectChartWidth(state)
|
|
10
|
+
const chartHeight = selectChartHeight(state)
|
|
11
|
+
|
|
12
|
+
if (!offset || chartWidth == null || chartHeight == null) {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
height: Math.max(0, chartHeight - offset.top - offset.bottom),
|
|
18
|
+
width: Math.max(0, chartWidth - offset.left - offset.right),
|
|
19
|
+
x: offset.left,
|
|
20
|
+
y: offset.top,
|
|
21
|
+
}
|
|
22
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { ChartState } from "../store"
|
|
3
|
+
import { AxisId } from "../cartesianAxisSlice"
|
|
4
|
+
import { selectTooltipSettings } from "./selectTooltipSettings"
|
|
5
|
+
|
|
6
|
+
export const selectTooltipAxisId = (state: ChartState): AxisId =>
|
|
7
|
+
selectTooltipSettings(state).axisId
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { ChartState } from "../store"
|
|
3
|
+
import { chartSelector } from "./chartSelector"
|
|
4
|
+
import { selectChartLayout } from "../../context/chartLayoutContext"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* angle, radius, X, Y, and Z axes all have domain and range and scale and associated settings
|
|
8
|
+
*/
|
|
9
|
+
export type AllAxisTypes = "xAxis" | "yAxis" | "zAxis" | "radiusAxis" | "angleAxis"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Z axis is never displayed and so it lacks ticks and tick settings.
|
|
13
|
+
*/
|
|
14
|
+
export type RenderableAxisType = "xAxis" | "yAxis" | "angleAxis" | "radiusAxis"
|
|
15
|
+
|
|
16
|
+
export const selectTooltipAxisType = chartSelector((state: ChartState): RenderableAxisType => {
|
|
17
|
+
const layout = selectChartLayout(state)
|
|
18
|
+
|
|
19
|
+
if (layout === "horizontal") {
|
|
20
|
+
return "xAxis"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (layout === "vertical") {
|
|
24
|
+
return "yAxis"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (layout === "centric") {
|
|
28
|
+
return "angleAxis"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return "radiusAxis"
|
|
32
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { ChartState } from "../store"
|
|
3
|
+
import { TooltipEventType } from "../../util/types"
|
|
4
|
+
import { useChartStore } from "../RechartsStoreContext"
|
|
5
|
+
import { chartSelector } from "./chartSelector"
|
|
6
|
+
import { SharedTooltipSettings } from "../tooltipSlice"
|
|
7
|
+
|
|
8
|
+
export const selectDefaultTooltipEventType = (state: ChartState): TooltipEventType =>
|
|
9
|
+
state.options.defaultTooltipEventType
|
|
10
|
+
|
|
11
|
+
export const selectValidateTooltipEventTypes = (
|
|
12
|
+
state: ChartState,
|
|
13
|
+
): ReadonlyArray<TooltipEventType> | undefined => state.options.validateTooltipEventTypes
|
|
14
|
+
|
|
15
|
+
export function combineTooltipEventType(
|
|
16
|
+
shared: SharedTooltipSettings,
|
|
17
|
+
defaultTooltipEventType: TooltipEventType,
|
|
18
|
+
validateTooltipEventTypes: ReadonlyArray<TooltipEventType> | undefined,
|
|
19
|
+
): TooltipEventType {
|
|
20
|
+
if (shared == null) {
|
|
21
|
+
return defaultTooltipEventType
|
|
22
|
+
}
|
|
23
|
+
const eventType = shared ? "axis" : "item"
|
|
24
|
+
if (validateTooltipEventTypes == null) {
|
|
25
|
+
return defaultTooltipEventType
|
|
26
|
+
}
|
|
27
|
+
return validateTooltipEventTypes.includes(eventType) ? eventType : defaultTooltipEventType
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const selectTooltipEventType = chartSelector(function selectTooltipEventType(state: ChartState, shared: SharedTooltipSettings): TooltipEventType {
|
|
31
|
+
const defaultTooltipEventType = selectDefaultTooltipEventType(state)
|
|
32
|
+
const validateTooltipEventTypes = selectValidateTooltipEventTypes(state)
|
|
33
|
+
return combineTooltipEventType(shared, defaultTooltipEventType, validateTooltipEventTypes)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/* 1:1 port of upstream useTooltipEventType. Returns bare T per GOTCHA-011;
|
|
37
|
+
reads via useChartStore so panorama/standalone usage returns undefined
|
|
38
|
+
instead of throwing. Caller is expected to live in a tracked scope
|
|
39
|
+
(createMemo/createEffect/JSX) for reactivity. */
|
|
40
|
+
export function useTooltipEventType(
|
|
41
|
+
shared: SharedTooltipSettings,
|
|
42
|
+
): TooltipEventType | undefined {
|
|
43
|
+
const ctx = useChartStore()
|
|
44
|
+
if (!ctx) {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
return selectTooltipEventType(ctx.store, shared)
|
|
48
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "../store"
|
|
3
|
+
import type { TooltipSettingsState } from "../tooltipSlice"
|
|
4
|
+
import { chartSelector } from "./chartSelector"
|
|
5
|
+
import { readChartState } from "../chartState"
|
|
6
|
+
|
|
7
|
+
const normalizeIndex = (index: unknown): unknown => (typeof index === "number" ? String(index) : index)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Live view over the settings store node that reports a numeric `defaultIndex` as a string.
|
|
11
|
+
* Reads go through to the store, so the view never goes stale and keeps fine-grained tracking.
|
|
12
|
+
*/
|
|
13
|
+
const indexViewHandler: ProxyHandler<TooltipSettingsState> = {
|
|
14
|
+
get(target, key) {
|
|
15
|
+
const value = Reflect.get(target, key)
|
|
16
|
+
return key === "defaultIndex" ? normalizeIndex(value) : value
|
|
17
|
+
},
|
|
18
|
+
getOwnPropertyDescriptor(target, key) {
|
|
19
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, key)
|
|
20
|
+
return key === "defaultIndex" && descriptor != null
|
|
21
|
+
? { ...descriptor, value: normalizeIndex(descriptor.value) }
|
|
22
|
+
: descriptor
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const indexViews = new WeakMap<TooltipSettingsState, TooltipSettingsState>()
|
|
27
|
+
|
|
28
|
+
export const selectTooltipSettings = chartSelector((state: ChartState): TooltipSettingsState => {
|
|
29
|
+
const settings = readChartState(state).tooltip.settings
|
|
30
|
+
if (typeof settings.defaultIndex !== "number") {
|
|
31
|
+
return settings
|
|
32
|
+
}
|
|
33
|
+
let view = indexViews.get(settings)
|
|
34
|
+
if (view == null) {
|
|
35
|
+
view = new Proxy(settings, indexViewHandler)
|
|
36
|
+
indexViews.set(settings, view)
|
|
37
|
+
}
|
|
38
|
+
return view
|
|
39
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "../store"
|
|
3
|
+
import type { TooltipState } from "../tooltipSlice"
|
|
4
|
+
import { readChartState } from "../chartState"
|
|
5
|
+
|
|
6
|
+
export const selectTooltipState = (state: ChartState): TooltipState => {
|
|
7
|
+
return readChartState(state).tooltip
|
|
8
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import sortBy from "es-toolkit/compat/sortBy"
|
|
3
|
+
import type { ChartState } from "../store"
|
|
4
|
+
import { selectChartName } from "./rootPropsSelectors"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Compatibility wrapper: returns chart name from the store.
|
|
8
|
+
* In Solid, this reads reactively when called inside a tracking scope.
|
|
9
|
+
*/
|
|
10
|
+
export { selectChartName as useChartName }
|
|
11
|
+
import type {
|
|
12
|
+
ActiveTooltipProps,
|
|
13
|
+
TooltipIndex,
|
|
14
|
+
TooltipInteractionState,
|
|
15
|
+
TooltipPayload,
|
|
16
|
+
TooltipPayloadConfiguration,
|
|
17
|
+
} from "../tooltipSlice"
|
|
18
|
+
import { calculateCartesianTooltipPos, calculatePolarTooltipPos } from "../../util/ChartUtils"
|
|
19
|
+
import type {
|
|
20
|
+
AxisType,
|
|
21
|
+
CartesianLayout,
|
|
22
|
+
ChartOffsetInternal,
|
|
23
|
+
RelativePointer,
|
|
24
|
+
Coordinate,
|
|
25
|
+
DataKey,
|
|
26
|
+
PolarCoordinate,
|
|
27
|
+
PolarLayout,
|
|
28
|
+
PolarViewBoxRequired,
|
|
29
|
+
TickItem,
|
|
30
|
+
TooltipEventType,
|
|
31
|
+
} from "../../util/types"
|
|
32
|
+
import type { TooltipTrigger } from "../../chart/types"
|
|
33
|
+
import { selectChartDataWithIndexes } from "./dataSelectors"
|
|
34
|
+
import {
|
|
35
|
+
selectTooltipAxisDomain,
|
|
36
|
+
selectTooltipAxisTicks,
|
|
37
|
+
selectTooltipDisplayedData,
|
|
38
|
+
} from "./tooltipSelectors"
|
|
39
|
+
import { type AxisRange, selectTooltipAxisDataKey } from "./axisSelectors"
|
|
40
|
+
import { selectChartLayout } from "../../context/chartLayoutContext"
|
|
41
|
+
import { selectChartOffsetInternal } from "./selectChartOffsetInternal"
|
|
42
|
+
import { selectChartHeight, selectChartWidth } from "./containerSelectors"
|
|
43
|
+
import { combineActiveLabel } from "./combiners/combineActiveLabel"
|
|
44
|
+
import { combineTooltipInteractionState } from "./combiners/combineTooltipInteractionState"
|
|
45
|
+
import { combineActiveTooltipIndex } from "./combiners/combineActiveTooltipIndex"
|
|
46
|
+
import { combineCoordinateForDefaultIndex } from "./combiners/combineCoordinateForDefaultIndex"
|
|
47
|
+
import { combineTooltipPayloadConfigurations } from "./combiners/combineTooltipPayloadConfigurations"
|
|
48
|
+
import { selectTooltipPayloadSearcher } from "./selectTooltipPayloadSearcher"
|
|
49
|
+
import { selectTooltipState } from "./selectTooltipState"
|
|
50
|
+
import { combineTooltipPayload } from "./combiners/combineTooltipPayload"
|
|
51
|
+
import { chartSelector } from "./chartSelector"
|
|
52
|
+
import {
|
|
53
|
+
calculateActiveTickIndex,
|
|
54
|
+
getActiveCartesianCoordinate,
|
|
55
|
+
getActivePolarCoordinate,
|
|
56
|
+
isInCartesianRange,
|
|
57
|
+
} from "../../util/getActiveCoordinate"
|
|
58
|
+
import { inRangeOfSector } from "../../util/PolarUtils"
|
|
59
|
+
|
|
60
|
+
export const selectOrderedTooltipTicks = chartSelector(function selectOrderedTooltipTicks(state: ChartState) {
|
|
61
|
+
const ticks = selectTooltipAxisTicks(state)
|
|
62
|
+
return sortBy(ticks, (o) => o.coordinate)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const selectTooltipInteractionState = chartSelector(function selectTooltipInteractionState(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): TooltipInteractionState {
|
|
66
|
+
return combineTooltipInteractionState(
|
|
67
|
+
selectTooltipState(state),
|
|
68
|
+
tooltipEventType,
|
|
69
|
+
trigger,
|
|
70
|
+
defaultIndex,
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
export const selectActiveIndex = chartSelector(function selectActiveIndex(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): TooltipIndex | null {
|
|
75
|
+
return combineActiveTooltipIndex(
|
|
76
|
+
selectTooltipInteractionState(state, tooltipEventType, trigger, defaultIndex),
|
|
77
|
+
selectTooltipDisplayedData(state),
|
|
78
|
+
selectTooltipAxisDataKey(state),
|
|
79
|
+
selectTooltipAxisDomain(state),
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export const selectTooltipDataKey = chartSelector(function selectTooltipDataKey(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger): DataKey<unknown> | undefined {
|
|
84
|
+
if (tooltipEventType == null) {
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
const tooltipState = selectTooltipState(state)
|
|
88
|
+
if (tooltipEventType === "axis") {
|
|
89
|
+
if (trigger === "hover") {
|
|
90
|
+
return tooltipState.axisInteraction.hover.dataKey
|
|
91
|
+
}
|
|
92
|
+
return tooltipState.axisInteraction.click.dataKey
|
|
93
|
+
}
|
|
94
|
+
if (trigger === "hover") {
|
|
95
|
+
return tooltipState.itemInteraction.hover.dataKey
|
|
96
|
+
}
|
|
97
|
+
return tooltipState.itemInteraction.click.dataKey
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
export const selectTooltipPayloadConfigurations = chartSelector(function selectTooltipPayloadConfigurations(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): ReadonlyArray<TooltipPayloadConfiguration> {
|
|
101
|
+
return combineTooltipPayloadConfigurations(
|
|
102
|
+
selectTooltipState(state),
|
|
103
|
+
tooltipEventType,
|
|
104
|
+
trigger,
|
|
105
|
+
defaultIndex,
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
export const selectCoordinateForDefaultIndex = chartSelector(function selectCoordinateForDefaultIndex(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): Coordinate | undefined {
|
|
110
|
+
return combineCoordinateForDefaultIndex(
|
|
111
|
+
selectChartWidth(state),
|
|
112
|
+
selectChartHeight(state),
|
|
113
|
+
selectChartLayout(state),
|
|
114
|
+
selectChartOffsetInternal(state),
|
|
115
|
+
selectTooltipAxisTicks(state),
|
|
116
|
+
defaultIndex,
|
|
117
|
+
selectTooltipPayloadConfigurations(state, tooltipEventType, trigger, defaultIndex),
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
export const selectActiveCoordinate = chartSelector(function selectActiveCoordinate(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): Coordinate | undefined {
|
|
122
|
+
const tooltipInteractionState = selectTooltipInteractionState(
|
|
123
|
+
state,
|
|
124
|
+
tooltipEventType,
|
|
125
|
+
trigger,
|
|
126
|
+
defaultIndex,
|
|
127
|
+
)
|
|
128
|
+
const defaultIndexCoordinate = selectCoordinateForDefaultIndex(
|
|
129
|
+
state,
|
|
130
|
+
tooltipEventType,
|
|
131
|
+
trigger,
|
|
132
|
+
defaultIndex,
|
|
133
|
+
)
|
|
134
|
+
return tooltipInteractionState.coordinate ?? defaultIndexCoordinate
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
export const selectActiveLabel = chartSelector(function selectActiveLabel(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): string | number | undefined {
|
|
138
|
+
return combineActiveLabel(
|
|
139
|
+
selectTooltipAxisTicks(state),
|
|
140
|
+
selectActiveIndex(state, tooltipEventType, trigger, defaultIndex),
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
export const selectTooltipPayload = chartSelector(function selectTooltipPayload(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): TooltipPayload | undefined {
|
|
145
|
+
return combineTooltipPayload(
|
|
146
|
+
selectTooltipPayloadConfigurations(state, tooltipEventType, trigger, defaultIndex),
|
|
147
|
+
selectActiveIndex(state, tooltipEventType, trigger, defaultIndex),
|
|
148
|
+
selectChartDataWithIndexes(state),
|
|
149
|
+
selectTooltipAxisDataKey(state),
|
|
150
|
+
selectActiveLabel(state, tooltipEventType, trigger, defaultIndex),
|
|
151
|
+
selectTooltipPayloadSearcher(state),
|
|
152
|
+
tooltipEventType,
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
export const selectIsTooltipActive = chartSelector(function selectIsTooltipActive(state: ChartState, tooltipEventType: TooltipEventType | undefined, trigger: TooltipTrigger, defaultIndex: TooltipIndex | undefined): { isActive: boolean; activeIndex: TooltipIndex | null } {
|
|
157
|
+
const tooltipInteractionState = selectTooltipInteractionState(
|
|
158
|
+
state,
|
|
159
|
+
tooltipEventType,
|
|
160
|
+
trigger,
|
|
161
|
+
defaultIndex,
|
|
162
|
+
)
|
|
163
|
+
const activeIndex = selectActiveIndex(state, tooltipEventType, trigger, defaultIndex)
|
|
164
|
+
return { activeIndex, isActive: tooltipInteractionState.active && activeIndex != null }
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const combineActiveCartesianProps = (
|
|
168
|
+
chartEvent: RelativePointer | undefined,
|
|
169
|
+
layout: CartesianLayout,
|
|
170
|
+
tooltipAxisType: AxisType | undefined,
|
|
171
|
+
tooltipAxisRange: AxisRange | undefined,
|
|
172
|
+
tooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
173
|
+
orderedTooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
174
|
+
offset: ChartOffsetInternal,
|
|
175
|
+
): ActiveTooltipProps | undefined => {
|
|
176
|
+
if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
if (!isInCartesianRange(chartEvent, offset)) {
|
|
180
|
+
return undefined
|
|
181
|
+
}
|
|
182
|
+
const pos: number | undefined = calculateCartesianTooltipPos(chartEvent, layout)
|
|
183
|
+
|
|
184
|
+
const activeIndex = calculateActiveTickIndex(
|
|
185
|
+
pos,
|
|
186
|
+
orderedTooltipTicks,
|
|
187
|
+
tooltipTicks,
|
|
188
|
+
tooltipAxisType,
|
|
189
|
+
tooltipAxisRange,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
const activeCoordinate = getActiveCartesianCoordinate(
|
|
193
|
+
layout,
|
|
194
|
+
tooltipTicks,
|
|
195
|
+
activeIndex,
|
|
196
|
+
chartEvent,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return { activeCoordinate, activeIndex: String(activeIndex) }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const combineActivePolarProps = (
|
|
203
|
+
chartEvent: RelativePointer | undefined,
|
|
204
|
+
layout: PolarLayout,
|
|
205
|
+
polarViewBox: PolarViewBoxRequired | undefined,
|
|
206
|
+
tooltipAxisType: AxisType | undefined,
|
|
207
|
+
tooltipAxisRange: AxisRange | undefined,
|
|
208
|
+
tooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
209
|
+
orderedTooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
210
|
+
): ActiveTooltipProps | undefined => {
|
|
211
|
+
if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks || !polarViewBox) {
|
|
212
|
+
return undefined
|
|
213
|
+
}
|
|
214
|
+
const rangeObj = inRangeOfSector(chartEvent, polarViewBox)
|
|
215
|
+
if (!rangeObj) {
|
|
216
|
+
return undefined
|
|
217
|
+
}
|
|
218
|
+
const pos: number | undefined = calculatePolarTooltipPos(rangeObj, layout)
|
|
219
|
+
|
|
220
|
+
const activeIndex = calculateActiveTickIndex(
|
|
221
|
+
pos,
|
|
222
|
+
orderedTooltipTicks,
|
|
223
|
+
tooltipTicks,
|
|
224
|
+
tooltipAxisType,
|
|
225
|
+
tooltipAxisRange,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
const activeCoordinate: PolarCoordinate = getActivePolarCoordinate(
|
|
229
|
+
layout,
|
|
230
|
+
tooltipTicks,
|
|
231
|
+
activeIndex,
|
|
232
|
+
rangeObj,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
return { activeCoordinate, activeIndex: String(activeIndex) }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export const combineActiveProps = (
|
|
239
|
+
chartEvent: RelativePointer | undefined,
|
|
240
|
+
layout: CartesianLayout | PolarLayout | undefined,
|
|
241
|
+
polarViewBox: PolarViewBoxRequired | undefined,
|
|
242
|
+
tooltipAxisType: AxisType | undefined,
|
|
243
|
+
tooltipAxisRange: AxisRange | undefined,
|
|
244
|
+
tooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
245
|
+
orderedTooltipTicks: ReadonlyArray<TickItem> | undefined,
|
|
246
|
+
offset: ChartOffsetInternal,
|
|
247
|
+
): ActiveTooltipProps | undefined => {
|
|
248
|
+
if (!chartEvent || !layout || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
|
|
249
|
+
return undefined
|
|
250
|
+
}
|
|
251
|
+
if (layout === "horizontal" || layout === "vertical") {
|
|
252
|
+
return combineActiveCartesianProps(
|
|
253
|
+
chartEvent,
|
|
254
|
+
layout,
|
|
255
|
+
tooltipAxisType,
|
|
256
|
+
tooltipAxisRange,
|
|
257
|
+
tooltipTicks,
|
|
258
|
+
orderedTooltipTicks,
|
|
259
|
+
offset,
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
return combineActivePolarProps(
|
|
263
|
+
chartEvent,
|
|
264
|
+
layout,
|
|
265
|
+
polarViewBox,
|
|
266
|
+
tooltipAxisType,
|
|
267
|
+
tooltipAxisRange,
|
|
268
|
+
tooltipTicks,
|
|
269
|
+
orderedTooltipTicks,
|
|
270
|
+
)
|
|
271
|
+
}
|