@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,578 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "../store"
|
|
3
|
+
import { selectChartDataSliceWithIndexes } from "./dataSelectors"
|
|
4
|
+
import { readChartState } from "../chartState"
|
|
5
|
+
import {
|
|
6
|
+
type AxisRange,
|
|
7
|
+
combineAllAppliedValues,
|
|
8
|
+
combineAreasDomain,
|
|
9
|
+
combineAxisDomain,
|
|
10
|
+
combineAxisDomainWithNiceTicks,
|
|
11
|
+
combineCategoricalDomain,
|
|
12
|
+
combineDisplayedData,
|
|
13
|
+
combineDomainOfAllAppliedNumericalValuesIncludingErrorValues,
|
|
14
|
+
combineDomainOfStackGroups,
|
|
15
|
+
combineDotsDomain,
|
|
16
|
+
combineDuplicateDomain,
|
|
17
|
+
combineGraphicalItemsData,
|
|
18
|
+
combineLinesDomain,
|
|
19
|
+
combineNiceTicks,
|
|
20
|
+
combineNumericalDomain,
|
|
21
|
+
combineStackGroups,
|
|
22
|
+
filterGraphicalNotStackedItems,
|
|
23
|
+
filterReferenceElements,
|
|
24
|
+
getDomainDefinition,
|
|
25
|
+
itemAxisPredicate,
|
|
26
|
+
mergeDomains,
|
|
27
|
+
type RenderableAxisSettings,
|
|
28
|
+
selectAllErrorBarSettings,
|
|
29
|
+
selectAxisRange,
|
|
30
|
+
selectHasBar,
|
|
31
|
+
selectReferenceAreas,
|
|
32
|
+
selectReferenceDots,
|
|
33
|
+
selectReferenceLines,
|
|
34
|
+
selectTooltipAxis,
|
|
35
|
+
selectTooltipAxisDataKey,
|
|
36
|
+
selectUnfilteredCartesianItems,
|
|
37
|
+
} from "./axisSelectors"
|
|
38
|
+
import { selectUnfilteredPolarItems } from "./polarSelectors"
|
|
39
|
+
import { selectChartLayout } from "../../context/chartLayoutContext"
|
|
40
|
+
import { isCategoricalAxis, type StackId } from "../../util/ChartUtils"
|
|
41
|
+
import type {
|
|
42
|
+
AxisDomain,
|
|
43
|
+
CategoricalDomain,
|
|
44
|
+
CategoricalDomainItem,
|
|
45
|
+
Coordinate,
|
|
46
|
+
D3ScaleType,
|
|
47
|
+
DataKey,
|
|
48
|
+
LayoutType,
|
|
49
|
+
NumberDomain,
|
|
50
|
+
TickItem,
|
|
51
|
+
TooltipEventType,
|
|
52
|
+
} from "../../util/types"
|
|
53
|
+
import type { AppliedChartData, ChartData } from "../chartDataSlice"
|
|
54
|
+
import { selectChartDataWithIndexes } from "./dataSelectors"
|
|
55
|
+
import type {
|
|
56
|
+
CartesianGraphicalItemSettings,
|
|
57
|
+
GraphicalItemSettings,
|
|
58
|
+
PolarGraphicalItemSettings,
|
|
59
|
+
} from "../graphicalItemsSlice"
|
|
60
|
+
import type {
|
|
61
|
+
ReferenceAreaSettings,
|
|
62
|
+
ReferenceDotSettings,
|
|
63
|
+
ReferenceLineSettings,
|
|
64
|
+
} from "../referenceElementsSlice"
|
|
65
|
+
import {
|
|
66
|
+
selectChartName,
|
|
67
|
+
selectReverseStackOrder,
|
|
68
|
+
selectStackOffsetType,
|
|
69
|
+
} from "./rootPropsSelectors"
|
|
70
|
+
import { isNotNil, mathSign } from "../../util/DataUtils"
|
|
71
|
+
import { combineAxisRangeWithReverse } from "./combiners/combineAxisRangeWithReverse"
|
|
72
|
+
import type {
|
|
73
|
+
TooltipIndex,
|
|
74
|
+
TooltipInteractionState,
|
|
75
|
+
TooltipPayload,
|
|
76
|
+
TooltipSettingsState,
|
|
77
|
+
} from "../tooltipSlice"
|
|
78
|
+
|
|
79
|
+
import {
|
|
80
|
+
combineTooltipEventType,
|
|
81
|
+
selectDefaultTooltipEventType,
|
|
82
|
+
selectValidateTooltipEventTypes,
|
|
83
|
+
} from "./selectTooltipEventType"
|
|
84
|
+
|
|
85
|
+
import { combineActiveLabel } from "./combiners/combineActiveLabel"
|
|
86
|
+
|
|
87
|
+
import { selectTooltipSettings } from "./selectTooltipSettings"
|
|
88
|
+
|
|
89
|
+
import { combineTooltipInteractionState } from "./combiners/combineTooltipInteractionState"
|
|
90
|
+
import { combineActiveTooltipIndex } from "./combiners/combineActiveTooltipIndex"
|
|
91
|
+
import { combineCoordinateForDefaultIndex } from "./combiners/combineCoordinateForDefaultIndex"
|
|
92
|
+
import { selectChartHeight, selectChartWidth } from "./containerSelectors"
|
|
93
|
+
import { selectChartOffsetInternal } from "./selectChartOffsetInternal"
|
|
94
|
+
import { combineTooltipPayloadConfigurations } from "./combiners/combineTooltipPayloadConfigurations"
|
|
95
|
+
import { selectTooltipPayloadSearcher } from "./selectTooltipPayloadSearcher"
|
|
96
|
+
import { selectTooltipState } from "./selectTooltipState"
|
|
97
|
+
|
|
98
|
+
import { combineTooltipPayload } from "./combiners/combineTooltipPayload"
|
|
99
|
+
import type { StackGroup } from "../../util/stacks/stackTypes"
|
|
100
|
+
import { selectTooltipAxisId } from "./selectTooltipAxisId"
|
|
101
|
+
import { type RenderableAxisType, selectTooltipAxisType } from "./selectTooltipAxisType"
|
|
102
|
+
import {
|
|
103
|
+
combineDisplayedStackedData,
|
|
104
|
+
type DisplayedStackedData,
|
|
105
|
+
} from "./combiners/combineDisplayedStackedData"
|
|
106
|
+
import { type DefinitelyStackedGraphicalItem, isStacked } from "../types/StackedGraphicalItem"
|
|
107
|
+
import { numericalDomainSpecifiedWithoutRequiringData } from "../../util/isDomainSpecifiedByUser"
|
|
108
|
+
import type { ActiveLabel } from "../../synchronisation/types"
|
|
109
|
+
import { type RechartsScale, rechartsScaleFactory } from "../../util/scale/RechartsScale"
|
|
110
|
+
import { isWellBehavedNumber } from "../../util/isWellBehavedNumber"
|
|
111
|
+
import { combineRealScaleType } from "./combiners/combineRealScaleType"
|
|
112
|
+
import { combineConfiguredScale } from "./combiners/combineConfiguredScale"
|
|
113
|
+
import { chartSelector } from "./chartSelector"
|
|
114
|
+
import type { CustomScaleDefinition } from "../../util/scale/CustomScaleDefinition"
|
|
115
|
+
|
|
116
|
+
export const selectTooltipAxisRealScaleType = chartSelector(function selectTooltipAxisRealScaleType(state: ChartState): D3ScaleType | undefined {
|
|
117
|
+
return combineRealScaleType(selectTooltipAxis(state), selectHasBar(state), selectChartName(state))
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
export const selectAllUnfilteredGraphicalItems = chartSelector(function selectAllUnfilteredGraphicalItems(state: ChartState): ReadonlyArray<CartesianGraphicalItemSettings | PolarGraphicalItemSettings> {
|
|
121
|
+
return [
|
|
122
|
+
...selectUnfilteredCartesianItems(state),
|
|
123
|
+
...selectUnfilteredPolarItems(state),
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const selectTooltipAxisPredicate = chartSelector(function selectTooltipAxisPredicate(state: ChartState) {
|
|
128
|
+
return itemAxisPredicate(selectTooltipAxisType(state), selectTooltipAxisId(state))
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
export const selectAllGraphicalItemsSettings = chartSelector(function selectAllGraphicalItemsSettings(state: ChartState): ReadonlyArray<GraphicalItemSettings> {
|
|
132
|
+
// One pass over the item map; same order and result as
|
|
133
|
+
// combineGraphicalItemsSettings(selectAllUnfilteredGraphicalItems(state), axis, predicate).
|
|
134
|
+
const graphicalItems = readChartState(state).graphicalItems
|
|
135
|
+
const includeHidden = selectTooltipAxis(state)?.includeHidden === true
|
|
136
|
+
const axisPredicate = selectTooltipAxisPredicate(state)
|
|
137
|
+
const cartesian: GraphicalItemSettings[] = []
|
|
138
|
+
const polar: GraphicalItemSettings[] = []
|
|
139
|
+
for (const id in graphicalItems) {
|
|
140
|
+
const item = graphicalItems[id]
|
|
141
|
+
if (item == null || typeof item !== "object") {
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
const type = item.type
|
|
145
|
+
const settings = item.settings
|
|
146
|
+
const isCartesian = type === "line" || type === "area" || type === "bar" || type === "scatter"
|
|
147
|
+
const isPolar =
|
|
148
|
+
(type === "pie" || type === "radar" || type === "radialBar") &&
|
|
149
|
+
settings !== null &&
|
|
150
|
+
typeof settings === "object"
|
|
151
|
+
if ((isCartesian || isPolar) && axisPredicate(settings) && (includeHidden || !settings.hide)) {
|
|
152
|
+
;(isCartesian ? cartesian : polar).push(settings)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (polar.length === 0) {
|
|
156
|
+
return cartesian
|
|
157
|
+
}
|
|
158
|
+
return cartesian.length === 0 ? polar : [...cartesian, ...polar]
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const selectAllStackedGraphicalItemsSettings = chartSelector(function selectAllStackedGraphicalItemsSettings(state: ChartState): ReadonlyArray<DefinitelyStackedGraphicalItem> {
|
|
162
|
+
return selectAllGraphicalItemsSettings(state).filter(isStacked)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
export const selectTooltipGraphicalItemsData = chartSelector(function selectTooltipGraphicalItemsData(state: ChartState): ChartData {
|
|
166
|
+
return combineGraphicalItemsData(selectAllGraphicalItemsSettings(state))
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Data for tooltip always use the data with indexes set by a Brush,
|
|
171
|
+
* and never accept the isPanorama flag:
|
|
172
|
+
* because Tooltip never displays inside the panorama anyway
|
|
173
|
+
* so we don't need to worry what would happen there.
|
|
174
|
+
*/
|
|
175
|
+
export const selectTooltipDisplayedData = chartSelector(function selectTooltipDisplayedData(state: ChartState): ChartData {
|
|
176
|
+
return combineDisplayedData(
|
|
177
|
+
selectTooltipGraphicalItemsData(state),
|
|
178
|
+
selectChartDataWithIndexes(state),
|
|
179
|
+
)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const selectTooltipStackedData = chartSelector(function selectTooltipStackedData(state: ChartState): DisplayedStackedData {
|
|
183
|
+
return combineDisplayedStackedData(
|
|
184
|
+
selectAllStackedGraphicalItemsSettings(state),
|
|
185
|
+
selectChartDataWithIndexes(state),
|
|
186
|
+
selectTooltipAxis(state),
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const selectAnyTooltipItemUsesChartData = chartSelector(function selectAnyTooltipItemUsesChartData(state: ChartState): boolean {
|
|
191
|
+
return selectAllGraphicalItemsSettings(state).some((item) => !(item as { data?: unknown }).data)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const selectAllTooltipAppliedValues = chartSelector(function selectAllTooltipAppliedValues(state: ChartState): AppliedChartData {
|
|
195
|
+
return combineAllAppliedValues(
|
|
196
|
+
selectTooltipDisplayedData(state),
|
|
197
|
+
selectTooltipAxis(state),
|
|
198
|
+
selectAllGraphicalItemsSettings(state),
|
|
199
|
+
selectChartDataWithIndexes(state),
|
|
200
|
+
selectAnyTooltipItemUsesChartData(state),
|
|
201
|
+
selectTooltipGraphicalItemsData(state),
|
|
202
|
+
)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
const selectTooltipAxisDomainDefinition = chartSelector(function selectTooltipAxisDomainDefinition(state: ChartState): AxisDomain | undefined {
|
|
206
|
+
return getDomainDefinition(selectTooltipAxis(state))
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
function selectTooltipDataOverflow(state: ChartState): boolean {
|
|
210
|
+
return selectTooltipAxis(state).allowDataOverflow
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const selectTooltipDomainFromUserPreferences = chartSelector(function selectTooltipDomainFromUserPreferences(state: ChartState): NumberDomain | undefined {
|
|
214
|
+
return numericalDomainSpecifiedWithoutRequiringData(
|
|
215
|
+
selectTooltipAxisDomainDefinition(state),
|
|
216
|
+
selectTooltipDataOverflow(state),
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const selectAllStackedGraphicalItems = chartSelector(function selectAllStackedGraphicalItems(state: ChartState): ReadonlyArray<DefinitelyStackedGraphicalItem> {
|
|
221
|
+
return selectAllGraphicalItemsSettings(state).filter(isStacked)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
const selectTooltipStackGroups = chartSelector(function selectTooltipStackGroups(state: ChartState): Record<StackId, StackGroup> {
|
|
225
|
+
return combineStackGroups(
|
|
226
|
+
selectTooltipStackedData(state),
|
|
227
|
+
selectAllStackedGraphicalItems(state),
|
|
228
|
+
selectStackOffsetType(state),
|
|
229
|
+
selectReverseStackOrder(state),
|
|
230
|
+
)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
const selectTooltipDomainOfStackGroups = chartSelector(function selectTooltipDomainOfStackGroups(state: ChartState): NumberDomain | undefined {
|
|
234
|
+
return combineDomainOfStackGroups(
|
|
235
|
+
selectTooltipStackGroups(state),
|
|
236
|
+
selectChartDataWithIndexes(state),
|
|
237
|
+
selectTooltipAxisType(state),
|
|
238
|
+
selectTooltipDomainFromUserPreferences(state),
|
|
239
|
+
)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const selectTooltipItemsSettingsExceptStacked = chartSelector(function selectTooltipItemsSettingsExceptStacked(state: ChartState): ReadonlyArray<GraphicalItemSettings> {
|
|
243
|
+
return filterGraphicalNotStackedItems(selectAllGraphicalItemsSettings(state))
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const selectTooltipDomainOfAllAppliedNumericalValuesIncludingErrorValues = chartSelector(function selectTooltipDomainOfAllAppliedNumericalValuesIncludingErrorValues(state: ChartState): NumberDomain | undefined {
|
|
247
|
+
return combineDomainOfAllAppliedNumericalValuesIncludingErrorValues(
|
|
248
|
+
selectTooltipDisplayedData(state),
|
|
249
|
+
selectTooltipAxis(state),
|
|
250
|
+
selectTooltipItemsSettingsExceptStacked(state),
|
|
251
|
+
selectAllErrorBarSettings(state),
|
|
252
|
+
selectTooltipAxisType(state),
|
|
253
|
+
selectChartDataSliceWithIndexes(state),
|
|
254
|
+
)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
const selectReferenceDotsByTooltipAxis = chartSelector(function selectReferenceDotsByTooltipAxis(state: ChartState): ReadonlyArray<ReferenceDotSettings> | undefined {
|
|
258
|
+
return filterReferenceElements(
|
|
259
|
+
selectReferenceDots(state),
|
|
260
|
+
selectTooltipAxisType(state),
|
|
261
|
+
selectTooltipAxisId(state),
|
|
262
|
+
)
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
const selectTooltipReferenceDotsDomain = chartSelector(function selectTooltipReferenceDotsDomain(state: ChartState): NumberDomain | undefined {
|
|
266
|
+
return combineDotsDomain(selectReferenceDotsByTooltipAxis(state), selectTooltipAxisType(state))
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
const selectReferenceAreasByTooltipAxis = chartSelector(function selectReferenceAreasByTooltipAxis(state: ChartState): ReadonlyArray<ReferenceAreaSettings> | undefined {
|
|
270
|
+
return filterReferenceElements(
|
|
271
|
+
selectReferenceAreas(state),
|
|
272
|
+
selectTooltipAxisType(state),
|
|
273
|
+
selectTooltipAxisId(state),
|
|
274
|
+
)
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
const selectTooltipReferenceAreasDomain = chartSelector(function selectTooltipReferenceAreasDomain(state: ChartState): NumberDomain | undefined {
|
|
278
|
+
return combineAreasDomain(selectReferenceAreasByTooltipAxis(state), selectTooltipAxisType(state))
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
const selectReferenceLinesByTooltipAxis = chartSelector(function selectReferenceLinesByTooltipAxis(state: ChartState): ReadonlyArray<ReferenceLineSettings> | undefined {
|
|
282
|
+
return filterReferenceElements(
|
|
283
|
+
selectReferenceLines(state),
|
|
284
|
+
selectTooltipAxisType(state),
|
|
285
|
+
selectTooltipAxisId(state),
|
|
286
|
+
)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const selectTooltipReferenceLinesDomain = chartSelector(function selectTooltipReferenceLinesDomain(state: ChartState): NumberDomain | undefined {
|
|
290
|
+
return combineLinesDomain(selectReferenceLinesByTooltipAxis(state), selectTooltipAxisType(state))
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const selectTooltipReferenceElementsDomain = chartSelector(function selectTooltipReferenceElementsDomain(state: ChartState): NumberDomain | undefined {
|
|
294
|
+
return mergeDomains(
|
|
295
|
+
selectTooltipReferenceDotsDomain(state),
|
|
296
|
+
selectTooltipReferenceLinesDomain(state),
|
|
297
|
+
selectTooltipReferenceAreasDomain(state),
|
|
298
|
+
)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
const selectTooltipNumericalDomain = chartSelector(function selectTooltipNumericalDomain(state: ChartState): NumberDomain | undefined {
|
|
302
|
+
return combineNumericalDomain(
|
|
303
|
+
selectTooltipAxis(state),
|
|
304
|
+
selectTooltipAxisDomainDefinition(state),
|
|
305
|
+
selectTooltipDomainFromUserPreferences(state),
|
|
306
|
+
selectTooltipDomainOfStackGroups(state),
|
|
307
|
+
selectTooltipDomainOfAllAppliedNumericalValuesIncludingErrorValues(state),
|
|
308
|
+
selectTooltipReferenceElementsDomain(state),
|
|
309
|
+
selectChartLayout(state),
|
|
310
|
+
selectTooltipAxisType(state),
|
|
311
|
+
)
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
export const selectTooltipAxisDomain = chartSelector(function selectTooltipAxisDomain(state: ChartState): NumberDomain | CategoricalDomain | undefined {
|
|
315
|
+
return combineAxisDomain(
|
|
316
|
+
selectTooltipAxis(state),
|
|
317
|
+
selectChartLayout(state),
|
|
318
|
+
selectTooltipDisplayedData(state),
|
|
319
|
+
selectAllTooltipAppliedValues(state),
|
|
320
|
+
selectStackOffsetType(state),
|
|
321
|
+
selectTooltipAxisType(state),
|
|
322
|
+
selectTooltipNumericalDomain(state),
|
|
323
|
+
)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
const selectTooltipNiceTicks = chartSelector(function selectTooltipNiceTicks(state: ChartState): ReadonlyArray<number> | undefined {
|
|
327
|
+
return combineNiceTicks(
|
|
328
|
+
selectTooltipAxisDomain(state),
|
|
329
|
+
selectTooltipAxis(state),
|
|
330
|
+
selectTooltipAxisRealScaleType(state),
|
|
331
|
+
)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
export const selectTooltipAxisDomainIncludingNiceTicks = chartSelector(function selectTooltipAxisDomainIncludingNiceTicks(state: ChartState): NumberDomain | CategoricalDomain | undefined {
|
|
335
|
+
return combineAxisDomainWithNiceTicks(
|
|
336
|
+
selectTooltipAxis(state),
|
|
337
|
+
selectTooltipAxisDomain(state),
|
|
338
|
+
selectTooltipNiceTicks(state),
|
|
339
|
+
selectTooltipAxisType(state),
|
|
340
|
+
)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const selectTooltipAxisRange = chartSelector((state: ChartState): AxisRange | undefined => {
|
|
344
|
+
const axisType = selectTooltipAxisType(state)
|
|
345
|
+
const axisId = selectTooltipAxisId(state)
|
|
346
|
+
const isPanorama = false
|
|
347
|
+
return selectAxisRange(state, axisType, axisId, isPanorama)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
export const selectTooltipAxisRangeWithReverse = chartSelector(function selectTooltipAxisRangeWithReverse(state: ChartState): AxisRange | undefined {
|
|
351
|
+
return combineAxisRangeWithReverse(selectTooltipAxis(state), selectTooltipAxisRange(state))
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
const selectTooltipConfiguredScale = chartSelector(function selectTooltipConfiguredScale(state: ChartState): CustomScaleDefinition | undefined {
|
|
355
|
+
return combineConfiguredScale(
|
|
356
|
+
selectTooltipAxis(state),
|
|
357
|
+
selectTooltipAxisRealScaleType(state),
|
|
358
|
+
selectTooltipAxisDomainIncludingNiceTicks(state),
|
|
359
|
+
selectTooltipAxisRangeWithReverse(state),
|
|
360
|
+
)
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
export const selectTooltipAxisScale = chartSelector(function selectTooltipAxisScale(state: ChartState): RechartsScale | undefined {
|
|
364
|
+
return rechartsScaleFactory(selectTooltipConfiguredScale(state))
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
const selectTooltipDuplicateDomain = chartSelector(function selectTooltipDuplicateDomain(state: ChartState): ReadonlyArray<unknown> | undefined {
|
|
368
|
+
return combineDuplicateDomain(
|
|
369
|
+
selectChartLayout(state),
|
|
370
|
+
selectAllTooltipAppliedValues(state),
|
|
371
|
+
selectTooltipAxis(state),
|
|
372
|
+
selectTooltipAxisType(state),
|
|
373
|
+
)
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
export const selectTooltipCategoricalDomain = chartSelector(function selectTooltipCategoricalDomain(state: ChartState): ReadonlyArray<unknown> | undefined {
|
|
377
|
+
return combineCategoricalDomain(
|
|
378
|
+
selectChartLayout(state),
|
|
379
|
+
selectAllTooltipAppliedValues(state),
|
|
380
|
+
selectTooltipAxis(state),
|
|
381
|
+
selectTooltipAxisType(state),
|
|
382
|
+
)
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
const combineTicksOfTooltipAxis = (
|
|
386
|
+
layout: LayoutType,
|
|
387
|
+
axis: RenderableAxisSettings,
|
|
388
|
+
realScaleType: string | undefined,
|
|
389
|
+
scale: RechartsScale | undefined,
|
|
390
|
+
axisRange: AxisRange | undefined,
|
|
391
|
+
duplicateDomain: ReadonlyArray<unknown> | undefined,
|
|
392
|
+
categoricalDomain: ReadonlyArray<unknown> | undefined,
|
|
393
|
+
axisType: RenderableAxisType,
|
|
394
|
+
): ReadonlyArray<TickItem> | undefined => {
|
|
395
|
+
if (!axis) {
|
|
396
|
+
return undefined
|
|
397
|
+
}
|
|
398
|
+
const { type } = axis
|
|
399
|
+
|
|
400
|
+
const isCategorical = isCategoricalAxis(layout, axisType)
|
|
401
|
+
|
|
402
|
+
if (!scale) {
|
|
403
|
+
return undefined
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const offsetForBand = realScaleType === "scaleBand" && scale.bandwidth ? scale.bandwidth() / 2 : 2
|
|
407
|
+
let offset = type === "category" && scale.bandwidth ? scale.bandwidth() / offsetForBand : 0
|
|
408
|
+
|
|
409
|
+
offset =
|
|
410
|
+
axisType === "angleAxis" && axisRange != null && axisRange?.length >= 2
|
|
411
|
+
? mathSign(axisRange[0] - axisRange[1]) * 2 * offset
|
|
412
|
+
: offset
|
|
413
|
+
|
|
414
|
+
if (isCategorical && categoricalDomain) {
|
|
415
|
+
return categoricalDomain
|
|
416
|
+
.map((entry: unknown, index: number): TickItem | null => {
|
|
417
|
+
const scaled = scale.map(entry)
|
|
418
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
419
|
+
return null
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
coordinate: scaled + offset,
|
|
423
|
+
index,
|
|
424
|
+
offset,
|
|
425
|
+
value: entry,
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
.filter(isNotNil)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return scale
|
|
432
|
+
.domain()
|
|
433
|
+
.map((entry: CategoricalDomainItem, index: number): TickItem | null => {
|
|
434
|
+
const scaled = scale.map(entry)
|
|
435
|
+
if (!isWellBehavedNumber(scaled)) {
|
|
436
|
+
return null
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
coordinate: scaled + offset,
|
|
440
|
+
index,
|
|
441
|
+
offset,
|
|
442
|
+
value: duplicateDomain ? duplicateDomain[entry as unknown as number] : entry,
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
.filter(isNotNil)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Of on four almost identical implementations of tick generation.
|
|
450
|
+
* The four horsemen of tick generation are:
|
|
451
|
+
* - {@link selectTooltipAxisTicks}
|
|
452
|
+
* - {@link combineAxisTicks}
|
|
453
|
+
* - {@link getTicksOfAxis}.
|
|
454
|
+
* - {@link combineGraphicalItemTicks}
|
|
455
|
+
*/
|
|
456
|
+
export const selectTooltipAxisTicks = chartSelector(function selectTooltipAxisTicks(state: ChartState): ReadonlyArray<TickItem> | undefined {
|
|
457
|
+
return combineTicksOfTooltipAxis(
|
|
458
|
+
selectChartLayout(state),
|
|
459
|
+
selectTooltipAxis(state),
|
|
460
|
+
selectTooltipAxisRealScaleType(state),
|
|
461
|
+
selectTooltipAxisScale(state),
|
|
462
|
+
selectTooltipAxisRange(state),
|
|
463
|
+
selectTooltipDuplicateDomain(state),
|
|
464
|
+
selectTooltipCategoricalDomain(state),
|
|
465
|
+
selectTooltipAxisType(state),
|
|
466
|
+
)
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
const selectTooltipEventType = chartSelector(function selectTooltipEventType(state: ChartState): TooltipEventType | undefined {
|
|
470
|
+
const defaultTooltipEventType = selectDefaultTooltipEventType(state)
|
|
471
|
+
const validateTooltipEventType = selectValidateTooltipEventTypes(state)
|
|
472
|
+
const settings: TooltipSettingsState = selectTooltipSettings(state)
|
|
473
|
+
return combineTooltipEventType(settings.shared, defaultTooltipEventType, validateTooltipEventType)
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
const selectTooltipTrigger = (state: ChartState) => {
|
|
477
|
+
return readChartState(state).tooltip.settings.trigger
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const selectDefaultIndex = chartSelector((state: ChartState): TooltipIndex | undefined => {
|
|
481
|
+
const raw = readChartState(state).tooltip.settings.defaultIndex
|
|
482
|
+
if (typeof raw === "number") return String(raw)
|
|
483
|
+
return raw
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
const selectTooltipInteractionState = chartSelector(function selectTooltipInteractionState(state: ChartState): TooltipInteractionState | undefined {
|
|
487
|
+
return combineTooltipInteractionState(
|
|
488
|
+
selectTooltipState(state),
|
|
489
|
+
selectTooltipEventType(state),
|
|
490
|
+
selectTooltipTrigger(state),
|
|
491
|
+
selectDefaultIndex(state),
|
|
492
|
+
)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
export const selectActiveTooltipIndex = chartSelector(function selectActiveTooltipIndex(state: ChartState): TooltipIndex | null {
|
|
496
|
+
return combineActiveTooltipIndex(
|
|
497
|
+
selectTooltipInteractionState(state),
|
|
498
|
+
selectTooltipDisplayedData(state),
|
|
499
|
+
selectTooltipAxisDataKey(state),
|
|
500
|
+
selectTooltipAxisDomain(state),
|
|
501
|
+
)
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
export const selectActiveLabel = chartSelector(function selectActiveLabel(state: ChartState): ActiveLabel {
|
|
505
|
+
return combineActiveLabel(selectTooltipAxisTicks(state), selectActiveTooltipIndex(state))
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
export const selectActiveTooltipDataKey = chartSelector(function selectActiveTooltipDataKey(state: ChartState): DataKey<unknown> | undefined {
|
|
509
|
+
const tooltipInteraction = selectTooltipInteractionState(state)
|
|
510
|
+
if (!tooltipInteraction) {
|
|
511
|
+
return undefined
|
|
512
|
+
}
|
|
513
|
+
return tooltipInteraction.dataKey
|
|
514
|
+
})
|
|
515
|
+
|
|
516
|
+
export const selectActiveTooltipGraphicalItemId = chartSelector(function selectActiveTooltipGraphicalItemId(state: ChartState): string | undefined {
|
|
517
|
+
const tooltipInteraction = selectTooltipInteractionState(state)
|
|
518
|
+
if (!tooltipInteraction) {
|
|
519
|
+
return undefined
|
|
520
|
+
}
|
|
521
|
+
return tooltipInteraction.graphicalItemId
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
const selectTooltipPayloadConfigurations = chartSelector(function selectTooltipPayloadConfigurations(state: ChartState) {
|
|
525
|
+
return combineTooltipPayloadConfigurations(
|
|
526
|
+
selectTooltipState(state),
|
|
527
|
+
selectTooltipEventType(state),
|
|
528
|
+
selectTooltipTrigger(state),
|
|
529
|
+
selectDefaultIndex(state),
|
|
530
|
+
)
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
const selectTooltipCoordinateForDefaultIndex = chartSelector(function selectTooltipCoordinateForDefaultIndex(state: ChartState): Coordinate | undefined {
|
|
534
|
+
return combineCoordinateForDefaultIndex(
|
|
535
|
+
selectChartWidth(state),
|
|
536
|
+
selectChartHeight(state),
|
|
537
|
+
selectChartLayout(state),
|
|
538
|
+
selectChartOffsetInternal(state),
|
|
539
|
+
selectTooltipAxisTicks(state),
|
|
540
|
+
selectDefaultIndex(state),
|
|
541
|
+
selectTooltipPayloadConfigurations(state),
|
|
542
|
+
)
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
export const selectActiveTooltipCoordinate = chartSelector(function selectActiveTooltipCoordinate(state: ChartState): Coordinate | undefined {
|
|
546
|
+
const tooltipInteractionState = selectTooltipInteractionState(state)
|
|
547
|
+
const defaultIndexCoordinate = selectTooltipCoordinateForDefaultIndex(state)
|
|
548
|
+
if (tooltipInteractionState?.coordinate) {
|
|
549
|
+
return tooltipInteractionState.coordinate
|
|
550
|
+
}
|
|
551
|
+
return defaultIndexCoordinate
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
export const selectIsTooltipActive = chartSelector(function selectIsTooltipActive(state: ChartState): boolean {
|
|
555
|
+
const tooltipInteractionState = selectTooltipInteractionState(state)
|
|
556
|
+
return tooltipInteractionState?.active ?? false
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
export const selectActiveTooltipPayload = chartSelector(function selectActiveTooltipPayload(state: ChartState): TooltipPayload | undefined {
|
|
560
|
+
return combineTooltipPayload(
|
|
561
|
+
selectTooltipPayloadConfigurations(state),
|
|
562
|
+
selectActiveTooltipIndex(state),
|
|
563
|
+
selectChartDataWithIndexes(state),
|
|
564
|
+
selectTooltipAxisDataKey(state),
|
|
565
|
+
selectActiveLabel(state),
|
|
566
|
+
selectTooltipPayloadSearcher(state),
|
|
567
|
+
selectTooltipEventType(state),
|
|
568
|
+
)
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
export const selectActiveTooltipDataPoints = chartSelector(function selectActiveTooltipDataPoints(state: ChartState) {
|
|
572
|
+
const payload = selectActiveTooltipPayload(state)
|
|
573
|
+
if (payload == null) {
|
|
574
|
+
return undefined
|
|
575
|
+
}
|
|
576
|
+
const dataPoints = payload.map((p) => p.payload).filter((p) => p != null)
|
|
577
|
+
return Array.from(new Set(dataPoints))
|
|
578
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "../store"
|
|
3
|
+
import type { TooltipIndex, TooltipPayloadConfiguration } from "../tooltipSlice"
|
|
4
|
+
import type { Coordinate } from "../../util/types"
|
|
5
|
+
import { selectTooltipState } from "./selectTooltipState"
|
|
6
|
+
import { chartSelector } from "./chartSelector"
|
|
7
|
+
import type { GraphicalItemId } from "../graphicalItemsSlice"
|
|
8
|
+
|
|
9
|
+
const selectAllTooltipPayloadConfiguration = chartSelector(function selectAllTooltipPayloadConfiguration(state: ChartState): ReadonlyArray<TooltipPayloadConfiguration> {
|
|
10
|
+
const tooltipState = selectTooltipState(state)
|
|
11
|
+
return tooltipState.tooltipItemPayloads
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const selectTooltipCoordinate = chartSelector(function selectTooltipCoordinate(state: ChartState, tooltipIndex: TooltipIndex, graphicalItemId: GraphicalItemId): Coordinate | undefined {
|
|
15
|
+
const allTooltipConfigurations = selectAllTooltipPayloadConfiguration(state)
|
|
16
|
+
|
|
17
|
+
if (tooltipIndex == null) {
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
const mostRelevantTooltipConfiguration = allTooltipConfigurations.find((tooltipConfiguration) => {
|
|
21
|
+
return tooltipConfiguration.settings.graphicalItemId === graphicalItemId
|
|
22
|
+
})
|
|
23
|
+
if (mostRelevantTooltipConfiguration == null) {
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
const { getPosition } = mostRelevantTooltipConfiguration
|
|
27
|
+
if (getPosition == null) {
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
return getPosition(tooltipIndex)
|
|
31
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "./chartState"
|
|
3
|
+
import { createInitialChartState } from "./chartState"
|
|
4
|
+
|
|
5
|
+
import { createStore } from '../util/solid-1-compat';
|
|
6
|
+
export type { ChartState }
|
|
7
|
+
export { createInitialChartState }
|
|
8
|
+
|
|
9
|
+
/** Alias so existing tests can keep calling createInitialState. */
|
|
10
|
+
export function createInitialState(preloadedState?: Partial<ChartState>): ChartState {
|
|
11
|
+
return createInitialChartState(preloadedState)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type StoreTuple<T> = [T, (...args: unknown[]) => void]
|
|
15
|
+
type ReduxShim<T> = {
|
|
16
|
+
getState: () => T
|
|
17
|
+
dispatch: (action: (setStore: unknown, store: T) => void) => void
|
|
18
|
+
}
|
|
19
|
+
export type RechartsStoreHandle = StoreTuple<ChartState> & ReduxShim<ChartState>
|
|
20
|
+
|
|
21
|
+
export function createRechartsStore(preloadedState?: Partial<ChartState>): RechartsStoreHandle {
|
|
22
|
+
const [store, setStore] = createStore<ChartState>(createInitialChartState(preloadedState))
|
|
23
|
+
const result = [store, setStore] as unknown as RechartsStoreHandle
|
|
24
|
+
result.getState = () => store
|
|
25
|
+
result.dispatch = (action) => {
|
|
26
|
+
action(setStore, store)
|
|
27
|
+
}
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { snapshot } from "solid-js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Inside a store draft, entries are store proxies, never `===` the raw object that was
|
|
5
|
+
* written. Compare through `snapshot`, which resolves a proxy to its backing object.
|
|
6
|
+
*/
|
|
7
|
+
export function isSameStoreEntry(a: unknown, b: unknown): boolean {
|
|
8
|
+
return a === b || snapshot(a) === snapshot(b)
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { runWithOwner } from "solid-js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs chart-state writes from a cleanup. Disposal can happen inside a computation
|
|
5
|
+
* (for example a `Show` switching branches), where Solid 2 rejects owned writes;
|
|
6
|
+
* teardown bookkeeping has no owner of its own.
|
|
7
|
+
*/
|
|
8
|
+
export function teardownWrite(write: () => void): void {
|
|
9
|
+
runWithOwner(null, write)
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ChartState } from "./chartState"
|
|
2
|
+
import type { TooltipInteractionState } from "./tooltipSlice"
|
|
3
|
+
|
|
4
|
+
type DraftSetter = (write: (draft: ChartState) => void) => void
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A chart's own pointer interaction, mirroring upstream's setMouseOverAxisIndex /
|
|
8
|
+
* setMouseClickAxisIndex / setActiveMouseOverItemIndex / setActiveClickItemIndex reducers:
|
|
9
|
+
* it ends any incoming synchronisation and keyboard interaction before recording itself.
|
|
10
|
+
*/
|
|
11
|
+
export function setTooltipInteraction(
|
|
12
|
+
setState: DraftSetter,
|
|
13
|
+
interaction: "axisInteraction" | "itemInteraction",
|
|
14
|
+
trigger: "hover" | "click",
|
|
15
|
+
payload: TooltipInteractionState,
|
|
16
|
+
): void {
|
|
17
|
+
setState((draft) => {
|
|
18
|
+
draft.tooltip.syncInteraction.active = false
|
|
19
|
+
draft.tooltip.syncInteraction.sourceViewBox = undefined
|
|
20
|
+
draft.tooltip.keyboardInteraction.active = false
|
|
21
|
+
draft.tooltip[interaction][trigger] = payload
|
|
22
|
+
})
|
|
23
|
+
}
|