@solidports/recharts 0.1.0 → 0.1.1
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/dist/index.d.ts +40 -2
- package/dist/index.js +14238 -7174
- package/dist/{dev.js → index.jsx} +18367 -15900
- package/dist/server.js +48178 -0
- package/package.json +36 -19
- package/src/animation/AnimatedItems.tsx +0 -183
- package/src/animation/AnimationController.ts +0 -33
- package/src/animation/AnimationControllerImpl.ts +0 -36
- package/src/animation/AnimationHandle.ts +0 -307
- package/src/animation/CSSTransitionAnimate.tsx +0 -170
- package/src/animation/JavascriptAnimate.tsx +0 -119
- package/src/animation/easing.ts +0 -221
- package/src/animation/matchBy.ts +0 -164
- package/src/animation/timeoutController.ts +0 -70
- package/src/animation/useAnimationController.tsx +0 -34
- package/src/animation/useAnimationStartSnapshot.ts +0 -118
- package/src/animation/util.ts +0 -41
- package/src/cartesian/Area.tsx +0 -915
- package/src/cartesian/AreaRevealShape.tsx +0 -190
- package/src/cartesian/Bar.tsx +0 -1369
- package/src/cartesian/BarStack.tsx +0 -152
- package/src/cartesian/Brush.tsx +0 -951
- package/src/cartesian/CartesianAxis.tsx +0 -722
- package/src/cartesian/CartesianGrid.tsx +0 -711
- package/src/cartesian/ErrorBar.tsx +0 -361
- package/src/cartesian/Funnel.tsx +0 -803
- package/src/cartesian/GraphicalItemClipPath.tsx +0 -67
- package/src/cartesian/Line.tsx +0 -863
- package/src/cartesian/LineDrawShape.tsx +0 -89
- package/src/cartesian/ReferenceArea.tsx +0 -331
- package/src/cartesian/ReferenceDot.tsx +0 -304
- package/src/cartesian/ReferenceLine.tsx +0 -474
- package/src/cartesian/Scatter.tsx +0 -888
- package/src/cartesian/XAxis.tsx +0 -433
- package/src/cartesian/YAxis.tsx +0 -443
- package/src/cartesian/ZAxis.tsx +0 -155
- package/src/cartesian/cartesianPositionToCSSTranslate.tsx +0 -29
- package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +0 -21
- package/src/cartesian/getCartesianPosition.tsx +0 -267
- package/src/cartesian/getEquidistantTicks.ts +0 -144
- package/src/cartesian/getTicks.ts +0 -225
- package/src/cartesian/isOutsidePosition.ts +0 -15
- package/src/cartesian/useAnimatedLineLength.ts +0 -54
- package/src/chart/AreaChart.tsx +0 -29
- package/src/chart/BarChart.tsx +0 -29
- package/src/chart/CartesianChart.tsx +0 -131
- package/src/chart/CategoricalChart.tsx +0 -94
- package/src/chart/ComposedChart.tsx +0 -29
- package/src/chart/FunnelChart.tsx +0 -29
- package/src/chart/LineChart.tsx +0 -29
- package/src/chart/PieChart.tsx +0 -50
- package/src/chart/PolarChart.tsx +0 -164
- package/src/chart/RadarChart.tsx +0 -70
- package/src/chart/RadialBarChart.tsx +0 -46
- package/src/chart/RechartsWrapper.tsx +0 -551
- package/src/chart/Sankey.tsx +0 -1534
- package/src/chart/ScatterChart.tsx +0 -29
- package/src/chart/SunburstChart.tsx +0 -504
- package/src/chart/Treemap.tsx +0 -1223
- package/src/chart/createInitialRootProps.ts +0 -24
- package/src/chart/types.ts +0 -53
- package/src/component/ActivePoints.tsx +0 -144
- package/src/component/Cell.tsx +0 -37
- package/src/component/Cursor.tsx +0 -185
- package/src/component/Customized.tsx +0 -50
- package/src/component/DefaultLegendContent.tsx +0 -348
- package/src/component/DefaultTooltipContent.tsx +0 -224
- package/src/component/Dots.tsx +0 -157
- package/src/component/Label.tsx +0 -636
- package/src/component/LabelList.tsx +0 -375
- package/src/component/Legend.tsx +0 -512
- package/src/component/ResponsiveContainer.tsx +0 -348
- package/src/component/Text.tsx +0 -541
- package/src/component/Tooltip.tsx +0 -470
- package/src/component/TooltipBoundingBox.tsx +0 -146
- package/src/component/responsiveContainerUtils.ts +0 -134
- package/src/container/ClipPathProvider.tsx +0 -51
- package/src/container/Layer.tsx +0 -38
- package/src/container/RootSurface.tsx +0 -120
- package/src/container/Surface.tsx +0 -61
- package/src/context/CellsContext.tsx +0 -54
- package/src/context/ErrorBarContext.tsx +0 -146
- package/src/context/GraphicalItemChildrenScope.tsx +0 -18
- package/src/context/PanoramaContext.tsx +0 -9
- package/src/context/RegisterGraphicalItemId.tsx +0 -30
- package/src/context/accessibilityContext.tsx +0 -6
- package/src/context/brushUpdateContext.tsx +0 -9
- package/src/context/chartDataContext.tsx +0 -97
- package/src/context/chartLayoutContext.tsx +0 -201
- package/src/context/legendPayloadContext.tsx +0 -20
- package/src/context/legendPortalContext.tsx +0 -12
- package/src/context/tooltipContext.tsx +0 -89
- package/src/context/tooltipPortalContext.tsx +0 -12
- package/src/context/useTooltipAxis.ts +0 -22
- package/src/hooks.ts +0 -476
- package/src/index.ts +0 -280
- package/src/polar/Pie.tsx +0 -1360
- package/src/polar/PolarAngleAxis.tsx +0 -616
- package/src/polar/PolarGrid.tsx +0 -312
- package/src/polar/PolarRadiusAxis.tsx +0 -547
- package/src/polar/Radar.tsx +0 -734
- package/src/polar/RadialBar.tsx +0 -917
- package/src/polar/defaultPolarAngleAxisProps.tsx +0 -27
- package/src/polar/defaultPolarRadiusAxisProps.tsx +0 -25
- package/src/shape/Cross.tsx +0 -89
- package/src/shape/Curve.tsx +0 -343
- package/src/shape/Dot.tsx +0 -70
- package/src/shape/Polygon.tsx +0 -195
- package/src/shape/Rectangle.tsx +0 -470
- package/src/shape/Sector.tsx +0 -347
- package/src/shape/Symbols.tsx +0 -139
- package/src/shape/Trapezoid.tsx +0 -280
- package/src/state/RechartsStateContext.tsx +0 -12
- package/src/state/RechartsStateProvider.tsx +0 -87
- package/src/state/RechartsStoreContext.tsx +0 -25
- package/src/state/RechartsStoreProvider.tsx +0 -35
- package/src/state/ReportChartProps.tsx +0 -40
- package/src/state/ReportEventSettings.tsx +0 -30
- package/src/state/ReportMainChartProps.tsx +0 -61
- package/src/state/ReportPolarOptions.tsx +0 -35
- package/src/state/SetGraphicalItem.ts +0 -79
- package/src/state/SetLegendPayload.ts +0 -134
- package/src/state/SetTooltipEntrySettings.tsx +0 -72
- package/src/state/actions.ts +0 -464
- package/src/state/brushSlice.ts +0 -13
- package/src/state/cartesianAxisSlice.ts +0 -141
- package/src/state/chartDataSlice.ts +0 -50
- package/src/state/chartState.ts +0 -297
- package/src/state/errorBarSlice.ts +0 -29
- package/src/state/eventSettingsSlice.ts +0 -8
- package/src/state/events.ts +0 -76
- package/src/state/externalEventsMiddleware.ts +0 -255
- package/src/state/graphicalItemsSlice.ts +0 -74
- package/src/state/hooks/useChartSelectors.tsx +0 -45
- package/src/state/keyboardEventsMiddleware.ts +0 -228
- package/src/state/layoutSlice.ts +0 -21
- package/src/state/legendSlice.ts +0 -57
- package/src/state/mouseEventsMiddleware.ts +0 -185
- package/src/state/optionsSlice.ts +0 -47
- package/src/state/polarAxisSlice.ts +0 -10
- package/src/state/polarOptionsSlice.ts +0 -12
- package/src/state/rawData.ts +0 -26
- package/src/state/referenceElementsSlice.ts +0 -40
- package/src/state/renderedTicksSlice.ts +0 -15
- package/src/state/rootPropsSlice.ts +0 -47
- package/src/state/selectors/areaSelectors.ts +0 -240
- package/src/state/selectors/arrayEqualityCheck.ts +0 -29
- package/src/state/selectors/axisSelectors.ts +0 -2157
- package/src/state/selectors/barSelectors.ts +0 -310
- package/src/state/selectors/barStackSelectors.ts +0 -77
- package/src/state/selectors/brushSelectors.ts +0 -33
- package/src/state/selectors/chartSelector.ts +0 -185
- package/src/state/selectors/combiners/combineActiveLabel.ts +0 -16
- package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +0 -95
- package/src/state/selectors/combiners/combineAllBarPositions.ts +0 -122
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +0 -16
- package/src/state/selectors/combiners/combineBarPosition.ts +0 -23
- package/src/state/selectors/combiners/combineBarSizeList.ts +0 -80
- package/src/state/selectors/combiners/combineCheckedDomain.ts +0 -48
- package/src/state/selectors/combiners/combineConfiguredScale.ts +0 -111
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +0 -45
- package/src/state/selectors/combiners/combineDisplayedStackedData.ts +0 -50
- package/src/state/selectors/combiners/combineInverseScaleFunction.ts +0 -16
- package/src/state/selectors/combiners/combineRealScaleType.ts +0 -44
- package/src/state/selectors/combiners/combineStackedData.ts +0 -27
- package/src/state/selectors/combiners/combineTooltipInteractionState.ts +0 -86
- package/src/state/selectors/combiners/combineTooltipPayload.ts +0 -205
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +0 -58
- package/src/state/selectors/containerSelectors.ts +0 -12
- package/src/state/selectors/dataSelectors.ts +0 -88
- package/src/state/selectors/funnelSelectors.ts +0 -75
- package/src/state/selectors/graphicalItemSelectors.ts +0 -30
- package/src/state/selectors/legendSelectors.ts +0 -29
- package/src/state/selectors/lineSelectors.ts +0 -134
- package/src/state/selectors/numberDomainEqualityCheck.ts +0 -14
- package/src/state/selectors/pickAxisId.ts +0 -5
- package/src/state/selectors/pickAxisType.ts +0 -3
- package/src/state/selectors/pieSelectors.ts +0 -97
- package/src/state/selectors/polarAxisSelectors.ts +0 -201
- package/src/state/selectors/polarGridSelectors.ts +0 -28
- package/src/state/selectors/polarScaleSelectors.ts +0 -133
- package/src/state/selectors/polarSelectors.ts +0 -219
- package/src/state/selectors/radarSelectors.ts +0 -191
- package/src/state/selectors/radialBarSelectors.ts +0 -435
- package/src/state/selectors/rootPropsSelectors.ts +0 -25
- package/src/state/selectors/scatterSelectors.ts +0 -96
- package/src/state/selectors/selectActivePropsFromChartPointer.ts +0 -26
- package/src/state/selectors/selectAllAxes.ts +0 -17
- package/src/state/selectors/selectChartOffset.ts +0 -16
- package/src/state/selectors/selectChartOffsetInternal.ts +0 -136
- package/src/state/selectors/selectLegendArea.ts +0 -20
- package/src/state/selectors/selectPlotArea.ts +0 -22
- package/src/state/selectors/selectTooltipAxisId.ts +0 -7
- package/src/state/selectors/selectTooltipAxisType.ts +0 -32
- package/src/state/selectors/selectTooltipEventType.ts +0 -48
- package/src/state/selectors/selectTooltipPayloadSearcher.ts +0 -6
- package/src/state/selectors/selectTooltipSettings.ts +0 -39
- package/src/state/selectors/selectTooltipState.ts +0 -8
- package/src/state/selectors/selectors.ts +0 -271
- package/src/state/selectors/tooltipSelectors.ts +0 -578
- package/src/state/selectors/touchSelectors.ts +0 -31
- package/src/state/store.ts +0 -29
- package/src/state/storeIdentity.ts +0 -9
- package/src/state/teardownWrite.ts +0 -10
- package/src/state/tooltipInteraction.ts +0 -23
- package/src/state/tooltipSlice.ts +0 -334
- package/src/state/touchEventsMiddleware.ts +0 -214
- package/src/state/types/AnimationSettings.ts +0 -20
- package/src/state/types/AreaSettings.ts +0 -14
- package/src/state/types/BarSettings.ts +0 -15
- package/src/state/types/LineSettings.ts +0 -9
- package/src/state/types/PieSettings.ts +0 -34
- package/src/state/types/RadarSettings.ts +0 -5
- package/src/state/types/RadialBarSettings.ts +0 -10
- package/src/state/types/ScatterSettings.ts +0 -12
- package/src/state/types/StackedGraphicalItem.ts +0 -34
- package/src/state/useChartState.ts +0 -17
- package/src/state/zIndexSlice.ts +0 -39
- package/src/synchronisation/syncSelectors.ts +0 -7
- package/src/synchronisation/types.ts +0 -44
- package/src/synchronisation/useChartSynchronisation.tsx +0 -404
- package/src/theme/RechartsTheme.ts +0 -16
- package/src/theme/RechartsThemeContext.ts +0 -19
- package/src/theme/darkTheme.ts +0 -13
- package/src/theme/graphicalItemIdentity.ts +0 -70
- package/src/theme/legacyTheme.ts +0 -17
- package/src/theme/lightTheme.ts +0 -13
- package/src/types.ts +0 -54
- package/src/util/ActiveShapeUtils.tsx +0 -162
- package/src/util/BarUtils.tsx +0 -62
- package/src/util/BarePortal.tsx +0 -50
- package/src/util/CamelCaseSVGAttrs.ts +0 -34
- package/src/util/CartesianUtils.ts +0 -48
- package/src/util/ChartUtils.ts +0 -802
- package/src/util/Constants.ts +0 -42
- package/src/util/CssPrefixUtils.ts +0 -20
- package/src/util/DOMUtils.ts +0 -129
- package/src/util/DataUtils.ts +0 -216
- package/src/util/Events.ts +0 -16
- package/src/util/FunnelUtils.tsx +0 -15
- package/src/util/Global.ts +0 -12
- package/src/util/IfOverflow.ts +0 -15
- package/src/util/LRUCache.ts +0 -41
- package/src/util/LogUtils.ts +0 -22
- package/src/util/PolarUtils.ts +0 -132
- package/src/util/RadialBarUtils.tsx +0 -24
- package/src/util/ReactUtils.ts +0 -95
- package/src/util/ReduceCSSCalc.ts +0 -187
- package/src/util/ScatterUtils.tsx +0 -52
- package/src/util/ShapeElementProps.tsx +0 -87
- package/src/util/TickUtils.ts +0 -60
- package/src/util/XAxisUtils.ts +0 -48
- package/src/util/YAxisUtils.ts +0 -48
- package/src/util/axisPropsAreEqual.ts +0 -48
- package/src/util/createCartesianCharts.tsx +0 -150
- package/src/util/createEventProxy.ts +0 -20
- package/src/util/createPolarCharts.tsx +0 -112
- package/src/util/cursor/getCursorPoints.ts +0 -46
- package/src/util/cursor/getCursorRectangle.ts +0 -28
- package/src/util/cursor/getRadialCursorPoints.ts +0 -32
- package/src/util/excludeEventProps.ts +0 -171
- package/src/util/getActiveCoordinate.ts +0 -213
- package/src/util/getAxisTypeBasedOnLayout.ts +0 -21
- package/src/util/getClassNameFromUnknown.ts +0 -6
- package/src/util/getEveryNth.ts +0 -27
- package/src/util/getRadiusAndStrokeWidthFromDot.ts +0 -35
- package/src/util/getRelativeCoordinate.ts +0 -80
- package/src/util/getSliced.ts +0 -13
- package/src/util/hoverDedupe.ts +0 -41
- package/src/util/isDomainSpecifiedByUser.ts +0 -219
- package/src/util/isWellBehavedNumber.ts +0 -7
- package/src/util/pathTotalLength.ts +0 -25
- package/src/util/payload/getUniqPayload.ts +0 -28
- package/src/util/propsAreEqual.ts +0 -121
- package/src/util/resolveDefaultProps.ts +0 -161
- package/src/util/round.ts +0 -32
- package/src/util/scale/CartesianScaleHelper.ts +0 -72
- package/src/util/scale/CustomScaleDefinition.ts +0 -81
- package/src/util/scale/RechartsScale.ts +0 -130
- package/src/util/scale/createCategoricalInverse.ts +0 -72
- package/src/util/scale/getNiceTickValues.ts +0 -311
- package/src/util/scale/index.ts +0 -2
- package/src/util/scale/util/arithmetic.ts +0 -54
- package/src/util/solid-1-compat.ts +0 -310
- package/src/util/solidJsxCamelAugment.d.ts +0 -84
- package/src/util/stacks/getStackSeriesIdentifier.ts +0 -21
- package/src/util/stacks/stackTypes.ts +0 -60
- package/src/util/structurallyEqual.ts +0 -31
- package/src/util/svgPropertiesAndEvents.ts +0 -53
- package/src/util/svgPropertiesNoEvents.ts +0 -571
- package/src/util/tooltip/translate.ts +0 -171
- package/src/util/typedDataKey.ts +0 -48
- package/src/util/types.ts +0 -1560
- package/src/util/useAnimationId.ts +0 -31
- package/src/util/useElementOffset.ts +0 -110
- package/src/util/useId.ts +0 -8
- package/src/util/usePrefersReducedMotion.ts +0 -48
- package/src/util/useReportScale.ts +0 -24
- package/src/util/useUniqueId.ts +0 -30
- package/src/zIndex/DefaultZIndexes.ts +0 -84
- package/src/zIndex/ZIndexLayer.tsx +0 -121
- package/src/zIndex/ZIndexPortal.tsx +0 -79
- package/src/zIndex/getZIndexFromUnknown.ts +0 -14
- package/src/zIndex/zIndexSelectors.ts +0 -48
|
@@ -1,888 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-cycle */
|
|
2
|
-
import type { Formatter } from "../component/DefaultTooltipContent"
|
|
3
|
-
import { createMemo, For, Show, untrack } from 'solid-js';
|
|
4
|
-
import { structurallyEqual } from "../util/structurallyEqual"
|
|
5
|
-
import { ShapeOption } from "../util/ShapeElementProps"
|
|
6
|
-
import { CellsContextProvider, createCellsRegistry } from "../context/CellsContext"
|
|
7
|
-
import type { CellsRegistry } from "../context/CellsContext"
|
|
8
|
-
import { createHoverDedupe } from "../util/hoverDedupe"
|
|
9
|
-
import type { JSX } from '@solidjs/web';
|
|
10
|
-
import { clsx } from "clsx"
|
|
11
|
-
import { Layer } from "../container/Layer"
|
|
12
|
-
import {
|
|
13
|
-
LabelListContextBridge,
|
|
14
|
-
CartesianLabelListContextProvider,
|
|
15
|
-
type CartesianLabelListEntry,
|
|
16
|
-
type ImplicitLabelListType,
|
|
17
|
-
LabelListFromLabelProp,
|
|
18
|
-
} from "../component/LabelList"
|
|
19
|
-
import { Curve, type CurveType, type Props as CurveProps } from "../shape/Curve"
|
|
20
|
-
import type { ErrorBarDataItem, ErrorBarDataPointFormatter, ErrorBarDirection } from "./ErrorBar"
|
|
21
|
-
import { getLinearRegression, interpolate, isNullish } from "../util/DataUtils"
|
|
22
|
-
import { getCateCoordinateOfLine, getTooltipNameProp, getValueByDataKey } from "../util/ChartUtils"
|
|
23
|
-
import { adaptEventsOfChild } from "../util/types"
|
|
24
|
-
import type { CartesianLayout, ShapeAnimationProps } from "../util/types"
|
|
25
|
-
import type {
|
|
26
|
-
ActiveShape,
|
|
27
|
-
AnimationDuration,
|
|
28
|
-
AnimationTiming,
|
|
29
|
-
Coordinate,
|
|
30
|
-
DataConsumer,
|
|
31
|
-
DataKey,
|
|
32
|
-
DataProvider,
|
|
33
|
-
LegendType,
|
|
34
|
-
NonEmptyArray,
|
|
35
|
-
NullableCoordinate,
|
|
36
|
-
PresentationAttributesAdaptChildEvent,
|
|
37
|
-
SymbolType,
|
|
38
|
-
TickItem,
|
|
39
|
-
TrapezoidViewBox,
|
|
40
|
-
} from "../util/types"
|
|
41
|
-
import type { TooltipType } from "../component/DefaultTooltipContent"
|
|
42
|
-
import type { ScatterShapeProps } from "../util/ScatterUtils"
|
|
43
|
-
import { ScatterSymbol } from "../util/ScatterUtils"
|
|
44
|
-
import type { InnerSymbolsProp } from "../shape/Symbols"
|
|
45
|
-
import type { LegendPayload } from "../component/DefaultLegendContent"
|
|
46
|
-
import {
|
|
47
|
-
useMouseClickItemDispatch,
|
|
48
|
-
useMouseEnterItemDispatch,
|
|
49
|
-
useMouseLeaveItemDispatch,
|
|
50
|
-
} from "../context/tooltipContext"
|
|
51
|
-
import type {
|
|
52
|
-
TooltipPayload,
|
|
53
|
-
TooltipPayloadConfiguration,
|
|
54
|
-
TooltipPayloadEntry,
|
|
55
|
-
} from "../state/tooltipSlice"
|
|
56
|
-
import { SetTooltipEntrySettings } from "../state/SetTooltipEntrySettings"
|
|
57
|
-
import { SetErrorBarContext } from "../context/ErrorBarContext"
|
|
58
|
-
import { GraphicalItemChildrenScope } from "../context/GraphicalItemChildrenScope"
|
|
59
|
-
import type { AxisId } from "../state/cartesianAxisSlice"
|
|
60
|
-
import { GraphicalItemClipPath, useNeedsClip } from "./GraphicalItemClipPath"
|
|
61
|
-
import { selectScatterPoints } from "../state/selectors/scatterSelectors"
|
|
62
|
-
import { useChartStore } from "../state/RechartsStoreContext"
|
|
63
|
-
import type { BaseAxisWithScale, ZAxisWithScale } from "../state/selectors/axisSelectors"
|
|
64
|
-
import { implicitZAxis } from "../state/selectors/axisSelectors"
|
|
65
|
-
import { useIsPanorama } from "../context/PanoramaContext"
|
|
66
|
-
import { selectActiveTooltipIndex } from "../state/selectors/tooltipSelectors"
|
|
67
|
-
import { SetLegendPayload } from "../state/SetLegendPayload"
|
|
68
|
-
import { DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME } from "../util/Constants"
|
|
69
|
-
import { resolveDefaultProps } from "../util/resolveDefaultProps"
|
|
70
|
-
import { RegisterGraphicalItemId } from "../context/RegisterGraphicalItemId"
|
|
71
|
-
import type { ScatterSettings } from "../state/types/ScatterSettings"
|
|
72
|
-
import { SetCartesianGraphicalItem } from "../state/SetGraphicalItem"
|
|
73
|
-
import {
|
|
74
|
-
svgPropertiesNoEvents,
|
|
75
|
-
svgPropertiesNoEventsFromUnknown,
|
|
76
|
-
} from "../util/svgPropertiesNoEvents"
|
|
77
|
-
import { useCartesianChartLayout } from "../context/chartLayoutContext"
|
|
78
|
-
import { AnimatedItems, useAnimationCallbacks } from "../animation/AnimatedItems"
|
|
79
|
-
import type { AnimationInterpolateFn } from "../animation/AnimatedItems"
|
|
80
|
-
import { matchAppend } from "../animation/matchBy"
|
|
81
|
-
import type { AnimationMatchByProp } from "../animation/matchBy"
|
|
82
|
-
import { useViewBox } from "../context/chartLayoutContext"
|
|
83
|
-
import type { WithIdRequired, WithoutId } from "../util/useUniqueId"
|
|
84
|
-
import type { GraphicalItemId } from "../state/graphicalItemsSlice"
|
|
85
|
-
import type { ZIndexable } from "../zIndex/ZIndexLayer"
|
|
86
|
-
import { ZIndexLayer } from "../zIndex/ZIndexLayer"
|
|
87
|
-
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
88
|
-
import type { ChartData } from "../state/chartDataSlice"
|
|
89
|
-
|
|
90
|
-
import { splitProps } from '../util/solid-1-compat';
|
|
91
|
-
export interface ScatterPointNode {
|
|
92
|
-
x?: number | string
|
|
93
|
-
y?: number | string
|
|
94
|
-
z?: number | string
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Scatter coordinates are nullable because sometimes the point value is out of the domain,
|
|
99
|
-
* and we can't compute a valid coordinate for it.
|
|
100
|
-
*
|
|
101
|
-
* Scatter -> Symbol ignores points with null cx or cy so those won't render if using the default shapes.
|
|
102
|
-
* However: the points are exposed via various props and can be used in custom shapes so we keep them around.
|
|
103
|
-
*/
|
|
104
|
-
export interface ScatterPointItem {
|
|
105
|
-
/** The x coordinate of the point center in pixels. */
|
|
106
|
-
cx: number | undefined
|
|
107
|
-
/** The y coordinate of the point center in pixels. */
|
|
108
|
-
cy: number | undefined
|
|
109
|
-
/** The x coordinate (in pixels) of the top-left corner of the rectangle that wraps the point. */
|
|
110
|
-
x: number | undefined
|
|
111
|
-
/** The y coordinate (in pixels) of the top-left corner of the rectangle that wraps the point. */
|
|
112
|
-
y: number | undefined
|
|
113
|
-
/** ScatterPointItem size is an abstract number that is used to calculate the radius of the point. */
|
|
114
|
-
size: number
|
|
115
|
-
/** Width of the point in pixels. */
|
|
116
|
-
width: number
|
|
117
|
-
/** Height of the point in pixels. */
|
|
118
|
-
height: number
|
|
119
|
-
node: ScatterPointNode
|
|
120
|
-
payload?: unknown
|
|
121
|
-
tooltipPayload?: TooltipPayload
|
|
122
|
-
tooltipPosition: Coordinate
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export type ScatterCustomizedShape =
|
|
126
|
-
| ActiveShape<ScatterShapeProps, SVGPathElement & InnerSymbolsProp>
|
|
127
|
-
| SymbolType
|
|
128
|
-
|
|
129
|
-
interface ScatterInternalProps extends ZIndexable {
|
|
130
|
-
data?: ChartData
|
|
131
|
-
xAxisId: string | number
|
|
132
|
-
yAxisId: string | number
|
|
133
|
-
zAxisId: string | number
|
|
134
|
-
dataKey?: DataKey<unknown>
|
|
135
|
-
line?: JSX.Element | ((lineProps: Record<string, unknown>) => JSX.Element) | CurveProps | boolean
|
|
136
|
-
lineType: "fitting" | "joint"
|
|
137
|
-
lineJointType: CurveType
|
|
138
|
-
legendType: LegendType
|
|
139
|
-
tooltipType?: TooltipType
|
|
140
|
-
formatter?: Formatter
|
|
141
|
-
className?: string
|
|
142
|
-
name?: string
|
|
143
|
-
activeShape?: ScatterCustomizedShape
|
|
144
|
-
shape: ScatterCustomizedShape
|
|
145
|
-
points: ReadonlyArray<ScatterPointItem>
|
|
146
|
-
hide: boolean
|
|
147
|
-
label?: ImplicitLabelListType
|
|
148
|
-
isAnimationActive: boolean | "auto"
|
|
149
|
-
animationBegin: number
|
|
150
|
-
animationDuration: AnimationDuration
|
|
151
|
-
animationEasing: AnimationTiming
|
|
152
|
-
animationInterpolateFn: AnimationInterpolateFn<ScatterPointItem, CartesianLayout>
|
|
153
|
-
animationMatchBy: AnimationMatchByProp<ScatterPointItem>
|
|
154
|
-
needClip: boolean
|
|
155
|
-
id: GraphicalItemId
|
|
156
|
-
children?: JSX.Element
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
interface ScatterProps<DataPointType = unknown, DataValueType = unknown>
|
|
160
|
-
extends DataProvider<DataPointType>, DataConsumer<DataPointType, DataValueType>, ZIndexable {
|
|
161
|
-
id?: string
|
|
162
|
-
xAxisId?: AxisId
|
|
163
|
-
yAxisId?: AxisId
|
|
164
|
-
zAxisId?: AxisId
|
|
165
|
-
line?: JSX.Element | ((lineProps: Record<string, unknown>) => JSX.Element) | CurveProps | boolean
|
|
166
|
-
lineType?: "fitting" | "joint"
|
|
167
|
-
lineJointType?: CurveType
|
|
168
|
-
legendType?: LegendType
|
|
169
|
-
tooltipType?: TooltipType
|
|
170
|
-
/**
|
|
171
|
-
* Formats the value displayed in the tooltip for this Scatter.
|
|
172
|
-
* When set, takes precedence over the `formatter` prop on the Tooltip component.
|
|
173
|
-
*/
|
|
174
|
-
formatter?: Formatter
|
|
175
|
-
className?: string
|
|
176
|
-
name?: string
|
|
177
|
-
activeShape?: ScatterCustomizedShape
|
|
178
|
-
shape?: ScatterCustomizedShape
|
|
179
|
-
hide?: boolean
|
|
180
|
-
label?: ImplicitLabelListType
|
|
181
|
-
isAnimationActive?: boolean | "auto"
|
|
182
|
-
animationBegin?: number
|
|
183
|
-
animationDuration?: AnimationDuration
|
|
184
|
-
animationEasing?: AnimationTiming
|
|
185
|
-
/**
|
|
186
|
-
* Custom animation function for interpolating data items.
|
|
187
|
-
* When provided, this replaces the default animation interpolation.
|
|
188
|
-
*
|
|
189
|
-
* @since 3.9
|
|
190
|
-
* @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
|
|
191
|
-
*/
|
|
192
|
-
animationInterpolateFn?: AnimationInterpolateFn<ScatterPointItem, CartesianLayout>
|
|
193
|
-
/**
|
|
194
|
-
* Strategy for matching previous items to next items during animation.
|
|
195
|
-
*
|
|
196
|
-
* - `matchAppend` (default): match sequentially by index and treat newly appended items as new
|
|
197
|
-
* - `matchByIndex`: match by array position with proportional stretching
|
|
198
|
-
* - `matchByDataKey('someKey')`: match by a data key from the payload
|
|
199
|
-
* - Custom function `(item, index) => key`: match by the returned key
|
|
200
|
-
*
|
|
201
|
-
* @defaultValue append
|
|
202
|
-
*/
|
|
203
|
-
animationMatchBy?: AnimationMatchByProp<ScatterPointItem>
|
|
204
|
-
zIndex?: number
|
|
205
|
-
children?: JSX.Element
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
type BaseScatterSvgProps = Omit<
|
|
209
|
-
PresentationAttributesAdaptChildEvent<ScatterPointItem, SVGGraphicsElement>,
|
|
210
|
-
"points" | "ref" | "children" | "dangerouslySetInnerHTML"
|
|
211
|
-
>
|
|
212
|
-
|
|
213
|
-
type InternalProps = BaseScatterSvgProps & ScatterInternalProps
|
|
214
|
-
|
|
215
|
-
/* eslint-disable-next-line typescript-eslint/no-explicit-any -- upstream contract: untyped items accept any data */
|
|
216
|
-
export type Props<DataPointType = any, DataValueType = any> = BaseScatterSvgProps & ScatterProps<DataPointType, DataValueType>
|
|
217
|
-
|
|
218
|
-
/* eslint-disable solid/reactivity -- plain utility fn; Props parameter is not a Solid reactive proxy at this call site */
|
|
219
|
-
const computeLegendPayloadFromScatterProps = (
|
|
220
|
-
scatterProps: Props,
|
|
221
|
-
): ReadonlyArray<LegendPayload> => {
|
|
222
|
-
return [
|
|
223
|
-
{
|
|
224
|
-
color: scatterProps.fill,
|
|
225
|
-
dataKey: scatterProps.dataKey,
|
|
226
|
-
inactive: scatterProps.hide,
|
|
227
|
-
payload: scatterProps,
|
|
228
|
-
type: scatterProps.legendType,
|
|
229
|
-
value: getTooltipNameProp(scatterProps.name, scatterProps.dataKey),
|
|
230
|
-
},
|
|
231
|
-
]
|
|
232
|
-
}
|
|
233
|
-
/* eslint-enable solid/reactivity */
|
|
234
|
-
|
|
235
|
-
function SetScatterTooltipEntrySettings(props: {
|
|
236
|
-
dataKey?: DataKey<unknown> | undefined
|
|
237
|
-
points?: ReadonlyArray<ScatterPointItem>
|
|
238
|
-
stroke?: string
|
|
239
|
-
strokeWidth?: number | string
|
|
240
|
-
fill?: string
|
|
241
|
-
name?: string
|
|
242
|
-
hide?: boolean
|
|
243
|
-
tooltipType?: TooltipType
|
|
244
|
-
formatter?: Formatter
|
|
245
|
-
id: GraphicalItemId
|
|
246
|
-
}) {
|
|
247
|
-
/* GOTCHA-005: createMemo so reactive props flow into the settings object. */
|
|
248
|
-
const tooltipEntrySettings = createMemo<TooltipPayloadConfiguration>(() => ({
|
|
249
|
-
dataDefinedOnItem: props.points?.map((p: ScatterPointItem) => p.tooltipPayload),
|
|
250
|
-
getPosition: (index) => props.points?.[Number(index)]?.tooltipPosition,
|
|
251
|
-
settings: {
|
|
252
|
-
color: props.fill,
|
|
253
|
-
dataKey: props.dataKey,
|
|
254
|
-
fill: props.fill,
|
|
255
|
-
formatter: props.formatter,
|
|
256
|
-
graphicalItemId: props.id,
|
|
257
|
-
hide: props.hide,
|
|
258
|
-
name: getTooltipNameProp(props.name, props.dataKey),
|
|
259
|
-
nameKey: undefined,
|
|
260
|
-
stroke: props.stroke,
|
|
261
|
-
strokeWidth: props.strokeWidth,
|
|
262
|
-
type: props.tooltipType,
|
|
263
|
-
unit: "",
|
|
264
|
-
},
|
|
265
|
-
}))
|
|
266
|
-
return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings()} />
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function ScatterLine(props: {
|
|
270
|
-
points: ReadonlyArray<ScatterPointItem>
|
|
271
|
-
allProps: WithoutId<InternalProps>
|
|
272
|
-
}) {
|
|
273
|
-
return (
|
|
274
|
-
<Show when={props.allProps.line}>
|
|
275
|
-
{(() => {
|
|
276
|
-
const scatterProps = () => svgPropertiesNoEvents(props.allProps)
|
|
277
|
-
const customLineProps = () => svgPropertiesNoEventsFromUnknown(props.allProps.line)
|
|
278
|
-
const linePoints = (): ReadonlyArray<NullableCoordinate> => {
|
|
279
|
-
if (props.allProps.lineType === "joint") {
|
|
280
|
-
return props.points.map((entry) => ({ x: entry.cx ?? null, y: entry.cy ?? null }))
|
|
281
|
-
}
|
|
282
|
-
if (props.allProps.lineType === "fitting" && props.points.length > 0) {
|
|
283
|
-
const { xmin, xmax, a, b } = getLinearRegression(
|
|
284
|
-
props.points as NonEmptyArray<ScatterPointItem>,
|
|
285
|
-
)
|
|
286
|
-
const linearExp = (x: number) => a * x + b
|
|
287
|
-
return [
|
|
288
|
-
{ x: xmin, y: linearExp(xmin) },
|
|
289
|
-
{ x: xmax, y: linearExp(xmax) },
|
|
290
|
-
]
|
|
291
|
-
}
|
|
292
|
-
return []
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const lineProps = () => {
|
|
296
|
-
const sp: Record<string, unknown> = scatterProps()
|
|
297
|
-
const clp = customLineProps()
|
|
298
|
-
const strokeFromFill = typeof sp?.fill === "string" ? sp.fill : undefined
|
|
299
|
-
return {
|
|
300
|
-
...sp,
|
|
301
|
-
...clp,
|
|
302
|
-
fill: typeof clp?.fill === "string" ? clp.fill : "none",
|
|
303
|
-
points: linePoints(),
|
|
304
|
-
stroke: typeof clp?.stroke === "string" ? clp.stroke : strokeFromFill,
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/* element: cloned with lineProps; function: called with them; otherwise a Curve */
|
|
309
|
-
return (
|
|
310
|
-
<Layer class="recharts-scatter-line">
|
|
311
|
-
<ShapeOption
|
|
312
|
-
option={typeof props.allProps.line === "boolean" ? undefined : props.allProps.line}
|
|
313
|
-
shapeProps={lineProps() as Record<string, unknown>}
|
|
314
|
-
renderDefault={(shapeProps) => <Curve {...shapeProps} type={props.allProps.lineJointType} />}
|
|
315
|
-
/>
|
|
316
|
-
</Layer>
|
|
317
|
-
)
|
|
318
|
-
})()}
|
|
319
|
-
</Show>
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function ScatterLabelListProvider(props: {
|
|
324
|
-
showLabels: boolean
|
|
325
|
-
points: ReadonlyArray<ScatterPointItem>
|
|
326
|
-
children: JSX.Element
|
|
327
|
-
}) {
|
|
328
|
-
const chartViewBox = createMemo(() => useViewBox())
|
|
329
|
-
const labelListEntries = createMemo((): ReadonlyArray<CartesianLabelListEntry> => {
|
|
330
|
-
return props.points?.map((point): CartesianLabelListEntry => {
|
|
331
|
-
const viewBox: TrapezoidViewBox = {
|
|
332
|
-
height: point.height,
|
|
333
|
-
lowerWidth: point.width,
|
|
334
|
-
upperWidth: point.width,
|
|
335
|
-
width: point.width,
|
|
336
|
-
x: point.x ?? 0,
|
|
337
|
-
y: point.y ?? 0,
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
...viewBox,
|
|
341
|
-
fill: undefined,
|
|
342
|
-
parentViewBox: chartViewBox(),
|
|
343
|
-
payload: point.payload,
|
|
344
|
-
value: undefined,
|
|
345
|
-
viewBox,
|
|
346
|
-
}
|
|
347
|
-
})
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
/* eslint-disable solid/reactivity -- Provider value reads labelListEntries() and props.showLabels inside JSX attribute; both are reactive */
|
|
351
|
-
return (
|
|
352
|
-
<CartesianLabelListContextProvider value={props.showLabels ? labelListEntries() : undefined}>
|
|
353
|
-
{props.children}
|
|
354
|
-
</CartesianLabelListContextProvider>
|
|
355
|
-
)
|
|
356
|
-
/* eslint-enable solid/reactivity */
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function ScatterSymbols(
|
|
360
|
-
props: ShapeAnimationProps & {
|
|
361
|
-
points: ReadonlyArray<ScatterPointItem>
|
|
362
|
-
showLabels: boolean
|
|
363
|
-
allOtherScatterProps: InternalProps
|
|
364
|
-
},
|
|
365
|
-
) {
|
|
366
|
-
/* GOTCHA-016-C: one entry per pointer move across both event pairs, shared by all items. */
|
|
367
|
-
const hover = createHoverDedupe()
|
|
368
|
-
const ctx = useChartStore()
|
|
369
|
-
/* perf: cache selector result; without memo every consumer read triggers full chain. */
|
|
370
|
-
const activeIndex = createMemo(() => (ctx ? selectActiveTooltipIndex(ctx.store) : undefined))
|
|
371
|
-
/* eslint-disable solid/reactivity -- allOtherScatterProps destructure and dataKey/id reads are stable identifiers captured once at setup; dispatch hooks take static config */
|
|
372
|
-
const [idProps, allOtherPropsWithoutId] = splitProps(props.allOtherScatterProps, ["id"])
|
|
373
|
-
const id = idProps.id
|
|
374
|
-
|
|
375
|
-
const baseProps = () => svgPropertiesNoEvents(allOtherPropsWithoutId)
|
|
376
|
-
const onMouseEnterFromContext = useMouseEnterItemDispatch(
|
|
377
|
-
() => props.allOtherScatterProps.onMouseEnter as never,
|
|
378
|
-
() => props.allOtherScatterProps.dataKey,
|
|
379
|
-
String(id),
|
|
380
|
-
)
|
|
381
|
-
const onMouseLeaveFromContext = useMouseLeaveItemDispatch(
|
|
382
|
-
() => props.allOtherScatterProps.onMouseLeave as never,
|
|
383
|
-
)
|
|
384
|
-
const onClickFromContext = useMouseClickItemDispatch(
|
|
385
|
-
() => props.allOtherScatterProps.onClick as never,
|
|
386
|
-
() => props.allOtherScatterProps.dataKey,
|
|
387
|
-
String(id),
|
|
388
|
-
)
|
|
389
|
-
/* eslint-enable solid/reactivity */
|
|
390
|
-
|
|
391
|
-
/* eslint-disable solid/reactivity -- i() is the <For> index accessor; all reads inside the For callback ARE tracked */
|
|
392
|
-
return (
|
|
393
|
-
<Show when={props.points?.length > 0}>
|
|
394
|
-
<ScatterLine
|
|
395
|
-
points={props.points as ReadonlyArray<ScatterPointItem>}
|
|
396
|
-
allProps={allOtherPropsWithoutId}
|
|
397
|
-
/>
|
|
398
|
-
<For each={props.points}>
|
|
399
|
-
{(entry: ScatterPointItem, i) => {
|
|
400
|
-
const hasActiveShape = () =>
|
|
401
|
-
props.allOtherScatterProps.activeShape != null &&
|
|
402
|
-
props.allOtherScatterProps.activeShape !== false
|
|
403
|
-
/* Memos so a hover only re-renders the points whose active state flips. */
|
|
404
|
-
const isActive = createMemo(() => hasActiveShape() && activeIndex() === String(i()))
|
|
405
|
-
const option = createMemo(() =>
|
|
406
|
-
hasActiveShape() && isActive()
|
|
407
|
-
? props.allOtherScatterProps.activeShape
|
|
408
|
-
: props.allOtherScatterProps.shape,
|
|
409
|
-
)
|
|
410
|
-
const symbolProps = (): ScatterShapeProps => ({
|
|
411
|
-
...baseProps(),
|
|
412
|
-
...entry,
|
|
413
|
-
animationElapsedTime: props.animationElapsedTime,
|
|
414
|
-
index: i(),
|
|
415
|
-
isAnimating: props.isAnimating,
|
|
416
|
-
isEntrance: props.isEntrance,
|
|
417
|
-
[DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME]: String(id),
|
|
418
|
-
})
|
|
419
|
-
/* Event handlers bind once per item, like a keyed list. */
|
|
420
|
-
const handlerIndex = untrack(i)
|
|
421
|
-
const adapted = untrack(
|
|
422
|
-
() =>
|
|
423
|
-
(adaptEventsOfChild(
|
|
424
|
-
props.allOtherScatterProps as unknown as Record<string, unknown>,
|
|
425
|
-
entry,
|
|
426
|
-
handlerIndex,
|
|
427
|
-
) ?? {}) as Record<string, ((e: Event) => void) | undefined>,
|
|
428
|
-
)
|
|
429
|
-
|
|
430
|
-
/* GOTCHA-016-C: bind both pairs, dedupe per-instance. Compose adapted user handlers. */
|
|
431
|
-
const enter = onMouseEnterFromContext(entry, handlerIndex)
|
|
432
|
-
const leave = onMouseLeaveFromContext(entry, handlerIndex)
|
|
433
|
-
const userOver = adapted.onMouseOver
|
|
434
|
-
const userOut = adapted.onMouseOut
|
|
435
|
-
const fireEnter = (e: MouseEvent & { currentTarget: SVGElement }) => {
|
|
436
|
-
if (!hover.enter(e)) return
|
|
437
|
-
userOver?.(e)
|
|
438
|
-
enter(e)
|
|
439
|
-
}
|
|
440
|
-
const fireLeave = (e: MouseEvent & { currentTarget: SVGElement }) => {
|
|
441
|
-
if (!hover.leave(e)) return
|
|
442
|
-
userOut?.(e)
|
|
443
|
-
leave(e)
|
|
444
|
-
}
|
|
445
|
-
return (
|
|
446
|
-
<ZIndexLayer zIndex={isActive() ? DefaultZIndexes.activeDot : undefined}>
|
|
447
|
-
<Layer
|
|
448
|
-
class="recharts-scatter-symbol"
|
|
449
|
-
{...adapted}
|
|
450
|
-
onMouseEnter={fireEnter}
|
|
451
|
-
onMouseOver={fireEnter}
|
|
452
|
-
onMouseLeave={fireLeave}
|
|
453
|
-
onMouseOut={fireLeave}
|
|
454
|
-
onClick={onClickFromContext(entry, handlerIndex)}
|
|
455
|
-
>
|
|
456
|
-
<ScatterSymbol option={option()} isActive={isActive()} {...symbolProps()} />
|
|
457
|
-
</Layer>
|
|
458
|
-
</ZIndexLayer>
|
|
459
|
-
)
|
|
460
|
-
}}
|
|
461
|
-
</For>
|
|
462
|
-
</Show>
|
|
463
|
-
)
|
|
464
|
-
/* eslint-enable solid/reactivity */
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const defaultScatterAnimateItems: AnimationInterpolateFn<ScatterPointItem, CartesianLayout> = (
|
|
468
|
-
items,
|
|
469
|
-
animationElapsedTime,
|
|
470
|
-
) => {
|
|
471
|
-
if (items == null) return []
|
|
472
|
-
if (animationElapsedTime === 1) {
|
|
473
|
-
return items.flatMap((item) => (item.status === "removed" ? [] : [item.next]))
|
|
474
|
-
}
|
|
475
|
-
return items.flatMap((item) => {
|
|
476
|
-
if (item.status === "removed") return []
|
|
477
|
-
if (item.status === "matched") {
|
|
478
|
-
return [
|
|
479
|
-
{
|
|
480
|
-
...item.next,
|
|
481
|
-
cx: item.next.cx == null ? undefined : interpolate(item.prev.cx, item.next.cx, animationElapsedTime),
|
|
482
|
-
cy: item.next.cy == null ? undefined : interpolate(item.prev.cy, item.next.cy, animationElapsedTime),
|
|
483
|
-
size: interpolate(item.prev.size, item.next.size, animationElapsedTime),
|
|
484
|
-
},
|
|
485
|
-
]
|
|
486
|
-
}
|
|
487
|
-
// added
|
|
488
|
-
return [{ ...item.next, size: interpolate(0, item.next.size, animationElapsedTime) }]
|
|
489
|
-
})
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function SymbolsWithAnimation(props: {
|
|
493
|
-
allProps: InternalProps
|
|
494
|
-
previousPointsRef: { current: ReadonlyArray<ScatterPointItem> | null }
|
|
495
|
-
}) {
|
|
496
|
-
const { isAnimating, handleAnimationStart, handleAnimationEnd } = useAnimationCallbacks()
|
|
497
|
-
const layout = createMemo(() => useCartesianChartLayout())
|
|
498
|
-
|
|
499
|
-
return (
|
|
500
|
-
<Show when={layout()}>
|
|
501
|
-
{(cartesianLayout) => (
|
|
502
|
-
<ScatterLabelListProvider showLabels={!isAnimating()} points={props.allProps.points}>
|
|
503
|
-
<AnimatedItems
|
|
504
|
-
animationInput={props.allProps.points}
|
|
505
|
-
animationIdPrefix="recharts-scatter-"
|
|
506
|
-
items={props.allProps.points}
|
|
507
|
-
previousItemsRef={props.previousPointsRef}
|
|
508
|
-
isAnimationActive={props.allProps.isAnimationActive}
|
|
509
|
-
animationBegin={props.allProps.animationBegin}
|
|
510
|
-
animationDuration={props.allProps.animationDuration}
|
|
511
|
-
animationEasing={props.allProps.animationEasing}
|
|
512
|
-
onAnimationStart={handleAnimationStart}
|
|
513
|
-
onAnimationEnd={handleAnimationEnd}
|
|
514
|
-
animationInterpolateFn={props.allProps.animationInterpolateFn}
|
|
515
|
-
animationMatchBy={props.allProps.animationMatchBy}
|
|
516
|
-
layout={cartesianLayout()}
|
|
517
|
-
>
|
|
518
|
-
{(stepData, animationElapsedTime, isEntrance) => (
|
|
519
|
-
<Layer>
|
|
520
|
-
<ScatterSymbols
|
|
521
|
-
points={stepData()}
|
|
522
|
-
allOtherScatterProps={props.allProps}
|
|
523
|
-
showLabels={!isAnimating()}
|
|
524
|
-
animationElapsedTime={animationElapsedTime()}
|
|
525
|
-
isAnimating={isAnimating() || animationElapsedTime() < 1}
|
|
526
|
-
isEntrance={isEntrance()}
|
|
527
|
-
/>
|
|
528
|
-
</Layer>
|
|
529
|
-
)}
|
|
530
|
-
</AnimatedItems>
|
|
531
|
-
<LabelListFromLabelProp label={props.allProps.label} />
|
|
532
|
-
</ScatterLabelListProvider>
|
|
533
|
-
)}
|
|
534
|
-
</Show>
|
|
535
|
-
)
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function RenderSymbols(props: { allProps: InternalProps }) {
|
|
539
|
-
const previousPointsRef: { current: ReadonlyArray<ScatterPointItem> | null } = { current: null }
|
|
540
|
-
return (
|
|
541
|
-
<SymbolsWithAnimation
|
|
542
|
-
allProps={props.allProps}
|
|
543
|
-
previousPointsRef={previousPointsRef}
|
|
544
|
-
/>
|
|
545
|
-
)
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
export function computeScatterPoints({
|
|
549
|
-
displayedData,
|
|
550
|
-
xAxis,
|
|
551
|
-
yAxis,
|
|
552
|
-
zAxis,
|
|
553
|
-
scatterSettings,
|
|
554
|
-
xAxisTicks,
|
|
555
|
-
yAxisTicks,
|
|
556
|
-
cells,
|
|
557
|
-
}: {
|
|
558
|
-
displayedData: ReadonlyArray<unknown>
|
|
559
|
-
xAxis: BaseAxisWithScale
|
|
560
|
-
yAxis: BaseAxisWithScale
|
|
561
|
-
zAxis: ZAxisWithScale | undefined
|
|
562
|
-
scatterSettings: ScatterSettings
|
|
563
|
-
xAxisTicks: ReadonlyArray<TickItem> | undefined
|
|
564
|
-
yAxisTicks: ReadonlyArray<TickItem> | undefined
|
|
565
|
-
cells: ReadonlyArray<JSX.Element> | undefined
|
|
566
|
-
}): ReadonlyArray<ScatterPointItem> {
|
|
567
|
-
const xAxisDataKey = isNullish(xAxis.dataKey) ? scatterSettings.dataKey : xAxis.dataKey
|
|
568
|
-
const yAxisDataKey = isNullish(yAxis.dataKey) ? scatterSettings.dataKey : yAxis.dataKey
|
|
569
|
-
const zAxisDataKey = zAxis && zAxis.dataKey
|
|
570
|
-
const defaultRangeZ = zAxis ? zAxis.range : implicitZAxis.range
|
|
571
|
-
const defaultZ = defaultRangeZ && defaultRangeZ[0]
|
|
572
|
-
const xBandSize = xAxis.scale.bandwidth ? xAxis.scale.bandwidth() : 0
|
|
573
|
-
const yBandSize = yAxis.scale.bandwidth ? yAxis.scale.bandwidth() : 0
|
|
574
|
-
return displayedData.map((entry: unknown, index): ScatterPointItem => {
|
|
575
|
-
const x: unknown = getValueByDataKey(entry, xAxisDataKey)
|
|
576
|
-
const y: unknown = getValueByDataKey(entry, yAxisDataKey)
|
|
577
|
-
const z: unknown = (!isNullish(zAxisDataKey) && getValueByDataKey(entry, zAxisDataKey)) || "-"
|
|
578
|
-
|
|
579
|
-
const tooltipPayload: Array<TooltipPayloadEntry> = [
|
|
580
|
-
{
|
|
581
|
-
dataKey: xAxisDataKey,
|
|
582
|
-
graphicalItemId: scatterSettings.id,
|
|
583
|
-
name: isNullish(xAxis.dataKey) ? scatterSettings.name : xAxis.name || String(xAxis.dataKey),
|
|
584
|
-
payload: entry,
|
|
585
|
-
type: scatterSettings.tooltipType,
|
|
586
|
-
unit: xAxis.unit || "",
|
|
587
|
-
value: x as number,
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
dataKey: yAxisDataKey,
|
|
591
|
-
graphicalItemId: scatterSettings.id,
|
|
592
|
-
name: isNullish(yAxis.dataKey) ? scatterSettings.name : yAxis.name || String(yAxis.dataKey),
|
|
593
|
-
payload: entry,
|
|
594
|
-
type: scatterSettings.tooltipType,
|
|
595
|
-
unit: yAxis.unit || "",
|
|
596
|
-
value: y as number,
|
|
597
|
-
},
|
|
598
|
-
]
|
|
599
|
-
|
|
600
|
-
if (z !== "-" && zAxis != null) {
|
|
601
|
-
tooltipPayload.push({
|
|
602
|
-
dataKey: zAxisDataKey,
|
|
603
|
-
graphicalItemId: scatterSettings.id,
|
|
604
|
-
name: zAxis.name || (zAxis.dataKey as string),
|
|
605
|
-
payload: entry,
|
|
606
|
-
type: scatterSettings.tooltipType,
|
|
607
|
-
unit: zAxis.unit || "",
|
|
608
|
-
value: z as number,
|
|
609
|
-
})
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
const cx: number | null = getCateCoordinateOfLine({
|
|
613
|
-
axis: xAxis,
|
|
614
|
-
bandSize: xBandSize,
|
|
615
|
-
dataKey: xAxisDataKey,
|
|
616
|
-
entry: entry as Record<string, unknown>,
|
|
617
|
-
index,
|
|
618
|
-
ticks: xAxisTicks,
|
|
619
|
-
})
|
|
620
|
-
const cy = getCateCoordinateOfLine({
|
|
621
|
-
axis: yAxis,
|
|
622
|
-
bandSize: yBandSize,
|
|
623
|
-
dataKey: yAxisDataKey,
|
|
624
|
-
entry: entry as Record<string, unknown>,
|
|
625
|
-
index,
|
|
626
|
-
ticks: yAxisTicks,
|
|
627
|
-
})
|
|
628
|
-
const size = z !== "-" && zAxis != null ? zAxis.scale.map(z) : defaultZ
|
|
629
|
-
const radius = size == null ? 0 : Math.sqrt(Math.max(size, 0) / Math.PI)
|
|
630
|
-
|
|
631
|
-
return {
|
|
632
|
-
...(entry as Record<string, unknown>),
|
|
633
|
-
cx,
|
|
634
|
-
cy,
|
|
635
|
-
height: 2 * radius,
|
|
636
|
-
node: { x, y, z } as ScatterPointNode,
|
|
637
|
-
payload: entry,
|
|
638
|
-
size,
|
|
639
|
-
tooltipPayload,
|
|
640
|
-
tooltipPosition: { x: cx as number, y: cy as number },
|
|
641
|
-
width: 2 * radius,
|
|
642
|
-
x: cx == null ? undefined : cx - radius,
|
|
643
|
-
y: cy == null ? undefined : cy - radius,
|
|
644
|
-
...(cells && cells[index] && (cells[index] as { props?: Record<string, unknown> }).props),
|
|
645
|
-
} as ScatterPointItem
|
|
646
|
-
})
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
const errorBarDataPointFormatter: ErrorBarDataPointFormatter<ScatterPointItem> = (
|
|
650
|
-
dataPoint: ScatterPointItem,
|
|
651
|
-
dataKey,
|
|
652
|
-
direction: ErrorBarDirection,
|
|
653
|
-
): ErrorBarDataItem => {
|
|
654
|
-
return {
|
|
655
|
-
errorVal: getValueByDataKey(dataPoint, dataKey) as number | number[] | undefined,
|
|
656
|
-
value: direction === "x" ? Number(dataPoint.node.x) : Number(dataPoint.node.y),
|
|
657
|
-
x: dataPoint.cx,
|
|
658
|
-
y: dataPoint.cy,
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function ScatterWithId(props: InternalProps) {
|
|
663
|
-
return (
|
|
664
|
-
<Show when={!props.hide}>
|
|
665
|
-
{(() => {
|
|
666
|
-
const layerClass = () => clsx("recharts-scatter", props.className)
|
|
667
|
-
const clipPathId = () => props.id
|
|
668
|
-
|
|
669
|
-
return (
|
|
670
|
-
<ZIndexLayer zIndex={props.zIndex}>
|
|
671
|
-
<Layer
|
|
672
|
-
class={layerClass()}
|
|
673
|
-
clip-path={props.needClip ? `url(#clipPath-${clipPathId()})` : undefined}
|
|
674
|
-
id={props.id}
|
|
675
|
-
>
|
|
676
|
-
<Show when={props.needClip}>
|
|
677
|
-
<defs>
|
|
678
|
-
<GraphicalItemClipPath
|
|
679
|
-
clipPathId={clipPathId()}
|
|
680
|
-
xAxisId={props.xAxisId}
|
|
681
|
-
yAxisId={props.yAxisId}
|
|
682
|
-
/>
|
|
683
|
-
</defs>
|
|
684
|
-
</Show>
|
|
685
|
-
{/* GOTCHA-017 (session 34): SetErrorBarContext hoisted to Scatter()
|
|
686
|
-
outer scope so user <ErrorBar/> evaluates inside the live Provider
|
|
687
|
-
owner. RenderSymbols + children are now inside that Provider via the
|
|
688
|
-
wrapper at outer scope. */}
|
|
689
|
-
<Layer>
|
|
690
|
-
<RenderSymbols allProps={props} />
|
|
691
|
-
</Layer>
|
|
692
|
-
<GraphicalItemChildrenScope>{props.children}</GraphicalItemChildrenScope>
|
|
693
|
-
</Layer>
|
|
694
|
-
</ZIndexLayer>
|
|
695
|
-
)
|
|
696
|
-
})()}
|
|
697
|
-
</Show>
|
|
698
|
-
)
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
export const defaultScatterProps = {
|
|
702
|
-
animationBegin: 0,
|
|
703
|
-
animationDuration: 400,
|
|
704
|
-
animationEasing: "linear",
|
|
705
|
-
animationInterpolateFn: defaultScatterAnimateItems,
|
|
706
|
-
animationMatchBy: matchAppend,
|
|
707
|
-
hide: false,
|
|
708
|
-
isAnimationActive: "auto",
|
|
709
|
-
label: false,
|
|
710
|
-
legendType: "circle",
|
|
711
|
-
line: false,
|
|
712
|
-
lineJointType: "linear",
|
|
713
|
-
lineType: "joint",
|
|
714
|
-
|
|
715
|
-
shape: "circle",
|
|
716
|
-
xAxisId: 0,
|
|
717
|
-
yAxisId: 0,
|
|
718
|
-
zAxisId: 0,
|
|
719
|
-
zIndex: DefaultZIndexes.scatter,
|
|
720
|
-
} as const satisfies Partial<Props>
|
|
721
|
-
|
|
722
|
-
function ScatterImpl(props: WithIdRequired<Props> & { cellsRegistry: CellsRegistry }) {
|
|
723
|
-
/* GOTCHA-017: split children, route via JSX child slot only. ErrorBar must
|
|
724
|
-
evaluate inside SetErrorBarContext (deeper, in ScatterWithId), wrapped by
|
|
725
|
-
GraphicalItemChildrenScope. */
|
|
726
|
-
const [childrenProps, restProps] = splitProps(props, ["children"])
|
|
727
|
-
const resolved = resolveDefaultProps(restProps, defaultScatterProps)
|
|
728
|
-
|
|
729
|
-
const needClipResult = createMemo(() => useNeedsClip(resolved.xAxisId, resolved.yAxisId))
|
|
730
|
-
const cells = createMemo((): ReadonlyArray<Record<string, unknown>> | undefined => {
|
|
731
|
-
const list = props.cellsRegistry.cells()
|
|
732
|
-
return list.length === 0 ? undefined : (list as unknown as ReadonlyArray<Record<string, unknown>>)
|
|
733
|
-
})
|
|
734
|
-
const isPanorama = useIsPanorama()
|
|
735
|
-
const ctx = useChartStore()
|
|
736
|
-
|
|
737
|
-
/* Per-chart chartSelector memo keyed by ids and cells; settings come from the store. */
|
|
738
|
-
const points = createMemo(() => {
|
|
739
|
-
return ctx
|
|
740
|
-
? selectScatterPoints(
|
|
741
|
-
ctx.store,
|
|
742
|
-
resolved.xAxisId,
|
|
743
|
-
resolved.yAxisId,
|
|
744
|
-
resolved.zAxisId,
|
|
745
|
-
props.id,
|
|
746
|
-
cells(),
|
|
747
|
-
isPanorama,
|
|
748
|
-
)
|
|
749
|
-
: undefined
|
|
750
|
-
/* selectors rebuild equal points after unrelated store writes; keep the previous
|
|
751
|
-
array so the keyed point list does not remount every symbol */
|
|
752
|
-
}, { equals: structurallyEqual })
|
|
753
|
-
|
|
754
|
-
return (
|
|
755
|
-
<Show when={needClipResult() != null && points() != null}>
|
|
756
|
-
<>
|
|
757
|
-
<SetScatterTooltipEntrySettings
|
|
758
|
-
dataKey={props.dataKey}
|
|
759
|
-
points={points() as ReadonlyArray<ScatterPointItem>}
|
|
760
|
-
stroke={props.stroke}
|
|
761
|
-
strokeWidth={props["stroke-width"]}
|
|
762
|
-
fill={props.fill}
|
|
763
|
-
name={props.name}
|
|
764
|
-
hide={props.hide}
|
|
765
|
-
tooltipType={props.tooltipType}
|
|
766
|
-
formatter={props.formatter}
|
|
767
|
-
id={props.id}
|
|
768
|
-
/>
|
|
769
|
-
<ScatterWithId
|
|
770
|
-
{...resolved}
|
|
771
|
-
xAxisId={resolved.xAxisId}
|
|
772
|
-
yAxisId={resolved.yAxisId}
|
|
773
|
-
zAxisId={resolved.zAxisId}
|
|
774
|
-
lineType={resolved.lineType}
|
|
775
|
-
lineJointType={resolved.lineJointType}
|
|
776
|
-
legendType={resolved.legendType}
|
|
777
|
-
shape={resolved.shape}
|
|
778
|
-
hide={resolved.hide}
|
|
779
|
-
isAnimationActive={resolved.isAnimationActive}
|
|
780
|
-
animationBegin={resolved.animationBegin}
|
|
781
|
-
animationDuration={resolved.animationDuration}
|
|
782
|
-
animationEasing={resolved.animationEasing}
|
|
783
|
-
points={points() as ReadonlyArray<ScatterPointItem>}
|
|
784
|
-
needClip={needClipResult()?.needClip() ?? false}
|
|
785
|
-
>
|
|
786
|
-
{childrenProps.children}
|
|
787
|
-
</ScatterWithId>
|
|
788
|
-
</>
|
|
789
|
-
</Show>
|
|
790
|
-
)
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* @provides LabelListContext
|
|
795
|
-
* @provides ErrorBarContext
|
|
796
|
-
* @provides CellReader
|
|
797
|
-
* @consumes CartesianChartContext
|
|
798
|
-
*/
|
|
799
|
-
function ScatterFn(outsideProps: Props): JSX.Element {
|
|
800
|
-
/* GOTCHA-013: split children before resolveDefaultProps so user JSX (ErrorBar) is
|
|
801
|
-
not eagerly invoked at Scatter setup, before RegisterGraphicalItemId installs
|
|
802
|
-
its Provider. */
|
|
803
|
-
const [childrenProps, restProps] = splitProps(outsideProps, ["children"])
|
|
804
|
-
const props = resolveDefaultProps(restProps, defaultScatterProps)
|
|
805
|
-
const isPanorama = useIsPanorama()
|
|
806
|
-
const ctx = useChartStore()
|
|
807
|
-
return (
|
|
808
|
-
<RegisterGraphicalItemId id={props.id} type="scatter">
|
|
809
|
-
{(id) => {
|
|
810
|
-
/* perf: cache selector result; without memo every consumer read triggers full chain. */
|
|
811
|
-
const points = createMemo(() =>
|
|
812
|
-
ctx
|
|
813
|
-
? selectScatterPoints(
|
|
814
|
-
ctx.store,
|
|
815
|
-
props.xAxisId,
|
|
816
|
-
props.yAxisId,
|
|
817
|
-
props.zAxisId,
|
|
818
|
-
id,
|
|
819
|
-
undefined,
|
|
820
|
-
isPanorama,
|
|
821
|
-
)
|
|
822
|
-
: undefined,
|
|
823
|
-
)
|
|
824
|
-
return (
|
|
825
|
-
<>
|
|
826
|
-
<SetLegendPayload legendPayload={computeLegendPayloadFromScatterProps(props)} />
|
|
827
|
-
<SetCartesianGraphicalItem
|
|
828
|
-
type="scatter"
|
|
829
|
-
id={id}
|
|
830
|
-
data={props.data}
|
|
831
|
-
xAxisId={props.xAxisId}
|
|
832
|
-
yAxisId={props.yAxisId}
|
|
833
|
-
zAxisId={props.zAxisId}
|
|
834
|
-
dataKey={props.dataKey}
|
|
835
|
-
hide={props.hide}
|
|
836
|
-
name={props.name}
|
|
837
|
-
tooltipType={props.tooltipType}
|
|
838
|
-
isPanorama={isPanorama}
|
|
839
|
-
/>
|
|
840
|
-
<SetErrorBarContext
|
|
841
|
-
xAxisId={props.xAxisId}
|
|
842
|
-
yAxisId={props.yAxisId}
|
|
843
|
-
data={points()}
|
|
844
|
-
dataPointFormatter={errorBarDataPointFormatter}
|
|
845
|
-
errorBarOffset={0}
|
|
846
|
-
>
|
|
847
|
-
<LabelListContextBridge>
|
|
848
|
-
{(() => {
|
|
849
|
-
/* <Cell/> children register here; upstream reads them with findAllByType. */
|
|
850
|
-
const cellsRegistry = createCellsRegistry()
|
|
851
|
-
return (
|
|
852
|
-
<CellsContextProvider value={cellsRegistry}>
|
|
853
|
-
{(() => {
|
|
854
|
-
/* GOTCHA-017 (session 34): memoize children INSIDE SetErrorBarContext.
|
|
855
|
-
createMemo establishes its owner at the call site — by placing it
|
|
856
|
-
here, the ErrorBar JSX evaluates with the live SetErrorBarContext
|
|
857
|
-
in scope. Without the memo, repeated reads of props.children re-mint
|
|
858
|
-
ErrorBar and loop the addErrorBar dispatch. */
|
|
859
|
-
const memoizedChildren = createMemo(() => childrenProps.children)
|
|
860
|
-
return (
|
|
861
|
-
<ScatterImpl {...props} id={id} cellsRegistry={cellsRegistry}>
|
|
862
|
-
{memoizedChildren()}
|
|
863
|
-
</ScatterImpl>
|
|
864
|
-
)
|
|
865
|
-
})()}
|
|
866
|
-
</CellsContextProvider>
|
|
867
|
-
)
|
|
868
|
-
})()}
|
|
869
|
-
</LabelListContextBridge>
|
|
870
|
-
</SetErrorBarContext>
|
|
871
|
-
</>
|
|
872
|
-
)
|
|
873
|
-
}}
|
|
874
|
-
</RegisterGraphicalItemId>
|
|
875
|
-
)
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Typed entry point: the generics constrain props at the call site, like upstream.
|
|
880
|
-
*/
|
|
881
|
-
/* eslint-disable-next-line typescript-eslint/no-explicit-any -- upstream contract: untyped usage accepts any data */
|
|
882
|
-
export const Scatter = ScatterFn as {
|
|
883
|
-
<DataPointType = any, DataValueType = any>(props: Props<DataPointType, DataValueType>): JSX.Element
|
|
884
|
-
/* eslint-disable-next-line typescript-eslint/no-explicit-any -- upstream fallback overload for mismatched data/dataKey */
|
|
885
|
-
(props: Props<any, any>): JSX.Element
|
|
886
|
-
displayName?: string
|
|
887
|
-
}
|
|
888
|
-
Scatter.displayName = "Scatter"
|