@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,24 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { UpdatableChartOptions } from "../state/rootPropsSlice"
|
|
3
|
+
import { initialRootPropsState } from "../state/rootPropsSlice"
|
|
4
|
+
|
|
5
|
+
const rootPropKeys = Object.keys(initialRootPropsState) as ReadonlyArray<keyof UpdatableChartOptions>
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Seeds `rootProps` at store creation so the first render already sees the chart's options
|
|
9
|
+
* (ReportChartProps keeps them in sync afterwards). Call untracked; reads only option keys,
|
|
10
|
+
* never `children`.
|
|
11
|
+
*/
|
|
12
|
+
export function createInitialRootProps(
|
|
13
|
+
chartProps: Partial<Record<keyof UpdatableChartOptions, unknown>>,
|
|
14
|
+
): UpdatableChartOptions {
|
|
15
|
+
const result: Record<string, unknown> = { ...initialRootPropsState }
|
|
16
|
+
for (const key of rootPropKeys) {
|
|
17
|
+
/* eslint-disable-next-line solid/reactivity -- seed snapshot, called untracked at store creation */
|
|
18
|
+
const value = chartProps[key]
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
result[key] = value
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result as UpdatableChartOptions
|
|
24
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { MouseHandlerDataParam } from "../synchronisation/types"
|
|
3
|
+
|
|
4
|
+
export type TooltipTrigger = "hover" | "click"
|
|
5
|
+
|
|
6
|
+
export type CategoricalChartFunc<E = Event> = (nextState: MouseHandlerDataParam, event: E) => void
|
|
7
|
+
|
|
8
|
+
export interface ExternalMouseEvents {
|
|
9
|
+
/**
|
|
10
|
+
* The customized event handler of click in this chart.
|
|
11
|
+
*/
|
|
12
|
+
onClick?: CategoricalChartFunc<MouseEvent>
|
|
13
|
+
/**
|
|
14
|
+
* The customized event handler of mouseleave in this chart.
|
|
15
|
+
*/
|
|
16
|
+
onMouseLeave?: CategoricalChartFunc<MouseEvent>
|
|
17
|
+
/**
|
|
18
|
+
* The customized event handler of mouseenter in this chart.
|
|
19
|
+
*/
|
|
20
|
+
onMouseEnter?: CategoricalChartFunc<MouseEvent>
|
|
21
|
+
/**
|
|
22
|
+
* The customized event handler of mousemove in this chart.
|
|
23
|
+
*/
|
|
24
|
+
onMouseMove?: CategoricalChartFunc<MouseEvent>
|
|
25
|
+
/**
|
|
26
|
+
* The customized event handler of mousedown in this chart.
|
|
27
|
+
*/
|
|
28
|
+
onMouseDown?: CategoricalChartFunc<MouseEvent>
|
|
29
|
+
/**
|
|
30
|
+
* The customized event handler of mouseup in this chart.
|
|
31
|
+
*/
|
|
32
|
+
onMouseUp?: CategoricalChartFunc<MouseEvent>
|
|
33
|
+
/**
|
|
34
|
+
* The customized event handler of contextmenu in this chart.
|
|
35
|
+
*/
|
|
36
|
+
onContextMenu?: CategoricalChartFunc<MouseEvent>
|
|
37
|
+
/**
|
|
38
|
+
* The customized event handler of dblclick in this chart.
|
|
39
|
+
*/
|
|
40
|
+
onDoubleClick?: CategoricalChartFunc<MouseEvent>
|
|
41
|
+
/**
|
|
42
|
+
* The customized event handler of touchstart in this chart.
|
|
43
|
+
*/
|
|
44
|
+
onTouchStart?: CategoricalChartFunc<TouchEvent>
|
|
45
|
+
/**
|
|
46
|
+
* The customized event handler of touchmove in this chart.
|
|
47
|
+
*/
|
|
48
|
+
onTouchMove?: CategoricalChartFunc<TouchEvent>
|
|
49
|
+
/**
|
|
50
|
+
* The customized event handler of touchend in this chart.
|
|
51
|
+
*/
|
|
52
|
+
onTouchEnd?: CategoricalChartFunc<TouchEvent>
|
|
53
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { createMemo, Show } from 'solid-js';
|
|
3
|
+
import type { JSX } from '@solidjs/web';
|
|
4
|
+
import type { ActiveDotProps, ActiveDotType, DataKey } from "../util/types"
|
|
5
|
+
import { adaptEventHandlers } from "../util/types"
|
|
6
|
+
import { Dot } from "../shape/Dot"
|
|
7
|
+
import { Layer } from "../container/Layer"
|
|
8
|
+
import { useChartStore } from "../state/RechartsStoreContext"
|
|
9
|
+
import { selectActiveTooltipIndex } from "../state/selectors/tooltipSelectors"
|
|
10
|
+
import { useActiveTooltipDataPoints } from "../hooks"
|
|
11
|
+
import { isNullish } from "../util/DataUtils"
|
|
12
|
+
import { svgPropertiesNoEventsFromUnknown } from "../util/svgPropertiesNoEvents"
|
|
13
|
+
import type { ZIndexable } from "../zIndex/ZIndexLayer"
|
|
14
|
+
import { ZIndexLayer } from "../zIndex/ZIndexLayer"
|
|
15
|
+
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
16
|
+
import { cloneJsxNodeWithProps, isJsxNode } from "../util/ReactUtils"
|
|
17
|
+
|
|
18
|
+
export interface PointType {
|
|
19
|
+
readonly x: number | null
|
|
20
|
+
readonly y: number | null
|
|
21
|
+
readonly value?: unknown
|
|
22
|
+
readonly payload?: unknown
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function ActivePoint(props: {
|
|
26
|
+
point: PointType
|
|
27
|
+
activeDot: ActiveDotType
|
|
28
|
+
childIndex: number
|
|
29
|
+
dataKey: DataKey<unknown> | undefined
|
|
30
|
+
/**
|
|
31
|
+
* Different graphical elements have different opinion on what is their main color.
|
|
32
|
+
* Sometimes stroke, sometimes fill, sometimes combination.
|
|
33
|
+
*/
|
|
34
|
+
mainColor: string | undefined
|
|
35
|
+
clipPath?: string
|
|
36
|
+
}): JSX.Element {
|
|
37
|
+
return <>{renderActivePoint(props)}</>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Runs inside ActivePoint's JSX expression so every reactive read is tracked. */
|
|
41
|
+
function renderActivePoint(props: {
|
|
42
|
+
point: PointType
|
|
43
|
+
activeDot: ActiveDotType
|
|
44
|
+
childIndex: number
|
|
45
|
+
dataKey: DataKey<unknown> | undefined
|
|
46
|
+
/**
|
|
47
|
+
* Different graphical elements have different opinion on what is their main color.
|
|
48
|
+
* Sometimes stroke, sometimes fill, sometimes combination.
|
|
49
|
+
*/
|
|
50
|
+
mainColor: string | undefined
|
|
51
|
+
clipPath?: string
|
|
52
|
+
}) {
|
|
53
|
+
/* eslint-disable solid/reactivity -- activeDot/point checks are structural guards; dotProps is a reactive accessor that re-reads props on each call */
|
|
54
|
+
if (props.activeDot === false || props.point.x == null || props.point.y == null) {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const dotProps = createMemo(
|
|
59
|
+
(): ActiveDotProps =>
|
|
60
|
+
/* eslint-disable sort-keys -- upstream key order becomes the DOM attribute order */
|
|
61
|
+
({
|
|
62
|
+
index: props.childIndex,
|
|
63
|
+
dataKey: props.dataKey,
|
|
64
|
+
cx: props.point.x,
|
|
65
|
+
cy: props.point.y,
|
|
66
|
+
r: 4,
|
|
67
|
+
fill: props.mainColor ?? "none",
|
|
68
|
+
strokeWidth: 2,
|
|
69
|
+
stroke: "#fff",
|
|
70
|
+
payload: props.point.payload,
|
|
71
|
+
value: props.point.value,
|
|
72
|
+
/* eslint-enable sort-keys */
|
|
73
|
+
...svgPropertiesNoEventsFromUnknown(props.activeDot),
|
|
74
|
+
...(typeof props.activeDot === "object" && props.activeDot !== null
|
|
75
|
+
? adaptEventHandlers(props.activeDot as Record<string, unknown>)
|
|
76
|
+
: {}),
|
|
77
|
+
}) as ActiveDotProps,
|
|
78
|
+
)
|
|
79
|
+
/* eslint-enable solid/reactivity */
|
|
80
|
+
|
|
81
|
+
const renderDot = (): JSX.Element => {
|
|
82
|
+
if (typeof props.activeDot === "function") {
|
|
83
|
+
return (props.activeDot as (p: ActiveDotProps) => JSX.Element)(dotProps())
|
|
84
|
+
}
|
|
85
|
+
if (isJsxNode(props.activeDot)) {
|
|
86
|
+
return cloneJsxNodeWithProps(
|
|
87
|
+
props.activeDot,
|
|
88
|
+
dotProps() as unknown as Record<string, unknown>,
|
|
89
|
+
) as unknown as JSX.Element
|
|
90
|
+
}
|
|
91
|
+
return <Dot {...dotProps()} />
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Layer class="recharts-active-dot" clip-path={props.clipPath}>
|
|
96
|
+
{renderDot()}
|
|
97
|
+
</Layer>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface ActivePointsProps extends ZIndexable {
|
|
102
|
+
points: ReadonlyArray<PointType>
|
|
103
|
+
/**
|
|
104
|
+
* Different graphical elements have different opinion on what is their main color.
|
|
105
|
+
* Sometimes stroke, sometimes fill, sometimes combination.
|
|
106
|
+
* `undefined` means that the color is not set, and the point will be transparent.
|
|
107
|
+
*/
|
|
108
|
+
mainColor: string | undefined
|
|
109
|
+
itemDataKey: DataKey<unknown> | undefined
|
|
110
|
+
activeDot: ActiveDotType
|
|
111
|
+
clipPath?: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function ActivePoints(props: ActivePointsProps) {
|
|
115
|
+
const ctx = useChartStore()
|
|
116
|
+
const zIndex = () => props.zIndex ?? DefaultZIndexes.activeDot
|
|
117
|
+
const activeTooltipIndex = createMemo(() =>
|
|
118
|
+
ctx ? selectActiveTooltipIndex(ctx.store) : undefined,
|
|
119
|
+
)
|
|
120
|
+
const activeDataPoints = createMemo(() => useActiveTooltipDataPoints())
|
|
121
|
+
|
|
122
|
+
const activePoint = (): PointType | undefined => {
|
|
123
|
+
const dataPoints = activeDataPoints()
|
|
124
|
+
if (props.points == null || dataPoints == null) {
|
|
125
|
+
return undefined
|
|
126
|
+
}
|
|
127
|
+
return props.points.find((p) => dataPoints.includes(p.payload))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<Show when={!isNullish(activePoint())}>
|
|
132
|
+
<ZIndexLayer zIndex={zIndex()}>
|
|
133
|
+
<ActivePoint
|
|
134
|
+
point={activePoint() as PointType}
|
|
135
|
+
childIndex={Number(activeTooltipIndex())}
|
|
136
|
+
mainColor={props.mainColor}
|
|
137
|
+
dataKey={props.itemDataKey}
|
|
138
|
+
activeDot={props.activeDot}
|
|
139
|
+
clipPath={props.clipPath}
|
|
140
|
+
/>
|
|
141
|
+
</ZIndexLayer>
|
|
142
|
+
</Show>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JSX } from '@solidjs/web';
|
|
2
|
+
import { useCellsRegistry } from "../context/CellsContext"
|
|
3
|
+
|
|
4
|
+
export interface Props {
|
|
5
|
+
/** The fill color. */
|
|
6
|
+
fill?: string
|
|
7
|
+
/** The stroke color. */
|
|
8
|
+
stroke?: string
|
|
9
|
+
[key: string]: unknown
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Cell component used to define colors and styles of chart elements.
|
|
14
|
+
*
|
|
15
|
+
* This component is now deprecated and will be removed in Recharts 4.0.
|
|
16
|
+
*
|
|
17
|
+
* Please use the `shape` prop or `content` prop on the respective chart components
|
|
18
|
+
* to customize the rendering of chart elements instead of using `Cell`.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://recharts.github.io/en-US/guide/cell/ Guide: Migrate from Cell component to shape prop}
|
|
21
|
+
*
|
|
22
|
+
* @deprecated
|
|
23
|
+
* @consumes CellReader
|
|
24
|
+
*/
|
|
25
|
+
export const Cell = (props: Props): JSX.Element | null => {
|
|
26
|
+
/* Solid cannot introspect JSX (no findAllByType parity). Cell instead opts
|
|
27
|
+
* into the closest CellsRegistry — Bar/Pie/Scatter/... mount one above their
|
|
28
|
+
* children scope. Outside any registry the call is a no-op so standalone
|
|
29
|
+
* usage (e.g. unit tests) keeps the empty-DOM contract. */
|
|
30
|
+
const registry = useCellsRegistry()
|
|
31
|
+
if (registry) {
|
|
32
|
+
registry.register(() => ({ ...props }))
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Cell.displayName = "Cell"
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle, sort-keys */
|
|
2
|
+
import { createMemo, Show } from 'solid-js';
|
|
3
|
+
import type { Component } from 'solid-js';
|
|
4
|
+
import type { JSX } from '@solidjs/web';
|
|
5
|
+
import { Dynamic } from '@solidjs/web';
|
|
6
|
+
import { clsx } from "clsx"
|
|
7
|
+
import type {
|
|
8
|
+
ChartOffsetInternal,
|
|
9
|
+
Coordinate,
|
|
10
|
+
LayoutType,
|
|
11
|
+
PolarCoordinate,
|
|
12
|
+
TooltipEventType,
|
|
13
|
+
} from "../util/types"
|
|
14
|
+
import { isPolarCoordinate } from "../util/types"
|
|
15
|
+
import { Curve } from "../shape/Curve"
|
|
16
|
+
import { Cross } from "../shape/Cross"
|
|
17
|
+
import { getCursorRectangle } from "../util/cursor/getCursorRectangle"
|
|
18
|
+
import { Rectangle } from "../shape/Rectangle"
|
|
19
|
+
import { getRadialCursorPoints } from "../util/cursor/getRadialCursorPoints"
|
|
20
|
+
import { Sector } from "../shape/Sector"
|
|
21
|
+
import { getCursorPoints } from "../util/cursor/getCursorPoints"
|
|
22
|
+
import { useChartLayout, useOffsetInternal } from "../context/chartLayoutContext"
|
|
23
|
+
import { useTooltipAxisBandSize } from "../context/useTooltipAxis"
|
|
24
|
+
import { useChartName } from "../state/selectors/selectors"
|
|
25
|
+
import type { TooltipIndex, TooltipPayload } from "../state/tooltipSlice"
|
|
26
|
+
import { useChartStore } from "../state/RechartsStoreContext"
|
|
27
|
+
import { svgPropertiesNoEventsFromUnknown } from "../util/svgPropertiesNoEvents"
|
|
28
|
+
import type { ZIndexable } from "../zIndex/ZIndexLayer"
|
|
29
|
+
import { ZIndexLayer } from "../zIndex/ZIndexLayer"
|
|
30
|
+
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* If set false, no cursor will be drawn when tooltip is active.
|
|
34
|
+
* If set an object, the option is the configuration of cursor.
|
|
35
|
+
* If set a JSX element, the option is the custom element of drawing cursor
|
|
36
|
+
*/
|
|
37
|
+
export type CursorDefinition = boolean | JSX.Element | Record<string, unknown>
|
|
38
|
+
|
|
39
|
+
export interface CursorProps extends ZIndexable {
|
|
40
|
+
cursor: CursorDefinition
|
|
41
|
+
tooltipEventType: TooltipEventType
|
|
42
|
+
coordinate: Coordinate | PolarCoordinate | undefined
|
|
43
|
+
payload: TooltipPayload
|
|
44
|
+
index: TooltipIndex | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type CursorConnectedProps = CursorProps & {
|
|
48
|
+
tooltipAxisBandSize: number
|
|
49
|
+
layout: LayoutType
|
|
50
|
+
offset: ChartOffsetInternal
|
|
51
|
+
chartName: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function RenderCursor(props: {
|
|
55
|
+
cursor: CursorDefinition
|
|
56
|
+
cursorComp: Component<Record<string, unknown>>
|
|
57
|
+
cursorProps: Record<string, unknown>
|
|
58
|
+
}) {
|
|
59
|
+
/* eslint-disable solid/reactivity -- cursor type is structural (stable at mount); nodeType check runs once */
|
|
60
|
+
if (typeof props.cursor === "object" && props.cursor != null && "nodeType" in props.cursor) {
|
|
61
|
+
/* JSX element passed directly -- not common in Solid, but handle gracefully */
|
|
62
|
+
return props.cursor as JSX.Element
|
|
63
|
+
}
|
|
64
|
+
/* eslint-enable solid/reactivity */
|
|
65
|
+
/* Spread props.cursorProps via Dynamic — props is a Solid props proxy, so each
|
|
66
|
+
property read flows through reactively. The plain-literal returned by the
|
|
67
|
+
parent's accessor is wrapped in the proxy via parent's `cursorProps={...}`
|
|
68
|
+
getter compiled by Solid. */
|
|
69
|
+
return <Dynamic component={props.cursorComp} {...props.cursorProps} />
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function CursorInternal(props: CursorConnectedProps) {
|
|
73
|
+
/* GOTCHA-017 (cursor reactivity): each piece is a SEPARATE reactive accessor.
|
|
74
|
+
The previous version used a single createMemo returning a fresh object literal —
|
|
75
|
+
plain object spread on Dynamic enumerates keys once and freezes points/d.
|
|
76
|
+
Per-key accessors via mergeProps make Dynamic's spread track each value live. */
|
|
77
|
+
const isVisible = (): boolean =>
|
|
78
|
+
Boolean(
|
|
79
|
+
props.cursor &&
|
|
80
|
+
props.coordinate != null &&
|
|
81
|
+
(props.chartName === "ScatterChart" || props.tooltipEventType === "axis"),
|
|
82
|
+
)
|
|
83
|
+
const cursorComp = (): Component<Record<string, unknown>> => {
|
|
84
|
+
if (props.chartName === "ScatterChart") return Cross as Component<Record<string, unknown>>
|
|
85
|
+
if (props.chartName === "BarChart") return Rectangle as Component<Record<string, unknown>>
|
|
86
|
+
if (
|
|
87
|
+
props.layout === "radial" &&
|
|
88
|
+
props.coordinate != null &&
|
|
89
|
+
isPolarCoordinate(props.coordinate as Coordinate | PolarCoordinate)
|
|
90
|
+
) {
|
|
91
|
+
return Sector as Component<Record<string, unknown>>
|
|
92
|
+
}
|
|
93
|
+
return Curve as Component<Record<string, unknown>>
|
|
94
|
+
}
|
|
95
|
+
const preferredZIndex = (): number => {
|
|
96
|
+
if (props.chartName === "BarChart") return DefaultZIndexes.cursorRectangle
|
|
97
|
+
return DefaultZIndexes.cursorLine
|
|
98
|
+
}
|
|
99
|
+
const restPropsObj = (): Record<string, unknown> => {
|
|
100
|
+
const coord = props.coordinate
|
|
101
|
+
if (coord == null) return {}
|
|
102
|
+
if (props.chartName === "ScatterChart") {
|
|
103
|
+
return coord as unknown as Record<string, unknown>
|
|
104
|
+
}
|
|
105
|
+
if (props.chartName === "BarChart") {
|
|
106
|
+
return getCursorRectangle(
|
|
107
|
+
props.layout,
|
|
108
|
+
coord as Coordinate,
|
|
109
|
+
props.offset,
|
|
110
|
+
props.tooltipAxisBandSize,
|
|
111
|
+
) as unknown as Record<string, unknown>
|
|
112
|
+
}
|
|
113
|
+
if (props.layout === "radial" && isPolarCoordinate(coord as Coordinate | PolarCoordinate)) {
|
|
114
|
+
const { cx, cy, radius, startAngle, endAngle } = getRadialCursorPoints(
|
|
115
|
+
coord as PolarCoordinate,
|
|
116
|
+
)
|
|
117
|
+
return { cx, cy, endAngle, innerRadius: radius, outerRadius: radius, startAngle }
|
|
118
|
+
}
|
|
119
|
+
return { points: getCursorPoints(props.layout, coord as Coordinate, props.offset) }
|
|
120
|
+
}
|
|
121
|
+
const extraClassName = (): string | undefined => {
|
|
122
|
+
const cursorObj =
|
|
123
|
+
typeof props.cursor === "object" && props.cursor != null ? props.cursor : undefined
|
|
124
|
+
return cursorObj && "className" in cursorObj ? String(cursorObj.className) : undefined
|
|
125
|
+
}
|
|
126
|
+
const cursorProps = (): Record<string, unknown> => ({
|
|
127
|
+
stroke: "#ccc",
|
|
128
|
+
"pointer-events": "none",
|
|
129
|
+
...props.offset,
|
|
130
|
+
...restPropsObj(),
|
|
131
|
+
...svgPropertiesNoEventsFromUnknown(props.cursor),
|
|
132
|
+
payload: props.payload,
|
|
133
|
+
payloadIndex: props.index,
|
|
134
|
+
class: clsx("recharts-tooltip-cursor", extraClassName()),
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Show when={isVisible()}>
|
|
139
|
+
<ZIndexLayer zIndex={props.zIndex ?? preferredZIndex()}>
|
|
140
|
+
<RenderCursor
|
|
141
|
+
cursor={props.cursor}
|
|
142
|
+
cursorComp={cursorComp()}
|
|
143
|
+
cursorProps={cursorProps()}
|
|
144
|
+
/>
|
|
145
|
+
</ZIndexLayer>
|
|
146
|
+
</Show>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Cursor is the background, or a highlight,
|
|
152
|
+
* that shows when user mouses over or activates
|
|
153
|
+
* an area.
|
|
154
|
+
*
|
|
155
|
+
* It usually shows together with a tooltip
|
|
156
|
+
* to emphasise which part of the chart does the tooltip refer to.
|
|
157
|
+
*/
|
|
158
|
+
export function Cursor(props: CursorProps) {
|
|
159
|
+
const ctx = useChartStore()
|
|
160
|
+
/* All public/internal hooks bare T (GOTCHA-011). Arrow-thunk pattern
|
|
161
|
+
preserves callsite shape and re-runs the selector on each reactive read. */
|
|
162
|
+
const tooltipAxisBandSize = createMemo(() => useTooltipAxisBandSize())
|
|
163
|
+
const offset = createMemo(() => useOffsetInternal())
|
|
164
|
+
const layout = createMemo(() => useChartLayout())
|
|
165
|
+
const chartName = createMemo(() => (ctx ? useChartName(ctx.store) : undefined))
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Show
|
|
169
|
+
when={
|
|
170
|
+
tooltipAxisBandSize() != null &&
|
|
171
|
+
offset() != null &&
|
|
172
|
+
layout() != null &&
|
|
173
|
+
chartName() != null
|
|
174
|
+
}
|
|
175
|
+
>
|
|
176
|
+
<CursorInternal
|
|
177
|
+
{...props}
|
|
178
|
+
offset={offset()}
|
|
179
|
+
layout={layout() as NonNullable<ReturnType<typeof layout>>}
|
|
180
|
+
tooltipAxisBandSize={tooltipAxisBandSize() as NonNullable<ReturnType<typeof tooltipAxisBandSize>>}
|
|
181
|
+
chartName={chartName() as NonNullable<ReturnType<typeof chartName>>}
|
|
182
|
+
/>
|
|
183
|
+
</Show>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview Customized
|
|
3
|
+
*/
|
|
4
|
+
import { untrack } from 'solid-js';
|
|
5
|
+
import { splitProps } from '../util/solid-1-compat';
|
|
6
|
+
import type { Component } from 'solid-js';
|
|
7
|
+
import type { JSX } from '@solidjs/web';
|
|
8
|
+
import { Dynamic } from '@solidjs/web';
|
|
9
|
+
import { Layer } from "../container/Layer"
|
|
10
|
+
|
|
11
|
+
type Comp<P extends Record<string, unknown>> = Component<P> | JSX.Element
|
|
12
|
+
export type Props<P extends Record<string, unknown>, C extends Comp<P>> = P & {
|
|
13
|
+
/**
|
|
14
|
+
* Render your components directly, without Customized wrapper. Will be removed in 4.0
|
|
15
|
+
* @deprecated
|
|
16
|
+
* @example Before: `<Customized component={<MyCustomComponent />} />`
|
|
17
|
+
* @example After: `<MyCustomComponent />`
|
|
18
|
+
*/
|
|
19
|
+
component: C
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Customized component used to be necessary to render custom elements in Recharts 2.x.
|
|
24
|
+
* Starting from Recharts 3.x, all charts are able to render arbitrary elements anywhere,
|
|
25
|
+
* and Customized is no longer needed.
|
|
26
|
+
*
|
|
27
|
+
* @example Before: `<Customized component={<MyCustomComponent />} />`
|
|
28
|
+
* @example After: `<MyCustomComponent />`
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Just render your components directly. Will be removed in 4.0
|
|
31
|
+
*/
|
|
32
|
+
export function Customized<P extends Record<string, unknown>, C extends Comp<P>>(
|
|
33
|
+
allProps: Props<P, C>,
|
|
34
|
+
) {
|
|
35
|
+
const [local, rest] = splitProps(allProps, ["component"])
|
|
36
|
+
/* Read once: a JSX.Element getter would create the element again on each read.
|
|
37
|
+
The component prop is structural (deprecated wrapper), not reactive. */
|
|
38
|
+
const component = untrack(() => local.component)
|
|
39
|
+
const child: JSX.Element =
|
|
40
|
+
typeof component === "function" ? (
|
|
41
|
+
<Dynamic component={component as Component<Record<string, unknown>>} {...rest} />
|
|
42
|
+
) : (
|
|
43
|
+
/* Solid evaluates <Comp /> eagerly; components returning null yield null. */
|
|
44
|
+
(component as JSX.Element)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return <Layer class="recharts-customized-wrapper">{child}</Layer>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Customized.displayName = "Customized"
|