@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,34 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-cycle */
|
|
2
|
-
import { GraphicalItemSettings } from "../graphicalItemsSlice"
|
|
3
|
-
import { NormalizedStackId } from "../../util/ChartUtils"
|
|
4
|
-
import { DataKey } from "../../util/types"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Some graphical items allow data stacking. The stacks are optional,
|
|
8
|
-
* so all props here are optional too.
|
|
9
|
-
*/
|
|
10
|
-
export interface MaybeStackedGraphicalItem extends GraphicalItemSettings {
|
|
11
|
-
stackId: NormalizedStackId | undefined
|
|
12
|
-
/**
|
|
13
|
-
* Bars have a size but Area does not.
|
|
14
|
-
*/
|
|
15
|
-
barSize: number | string | undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Some graphical items allow data stacking.
|
|
20
|
-
* This interface is used to represent the items that are stacked
|
|
21
|
-
* because the user has provided the stackId and dataKey properties.
|
|
22
|
-
*/
|
|
23
|
-
export interface DefinitelyStackedGraphicalItem extends MaybeStackedGraphicalItem {
|
|
24
|
-
stackId: NormalizedStackId
|
|
25
|
-
dataKey: DataKey<unknown>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function isStacked<T extends GraphicalItemSettings>(
|
|
29
|
-
graphicalItem: T,
|
|
30
|
-
): graphicalItem is T & DefinitelyStackedGraphicalItem {
|
|
31
|
-
return (
|
|
32
|
-
"stackId" in graphicalItem && graphicalItem.stackId != null && graphicalItem.dataKey != null
|
|
33
|
-
)
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'solid-js';
|
|
2
|
-
import { RechartsStateContext } from "./RechartsStateContext"
|
|
3
|
-
import type { RechartsStateContextValue } from "./RechartsStateContext"
|
|
4
|
-
|
|
5
|
-
/** Returns state + setState from the nearest RechartsStateProvider. Throws outside one. */
|
|
6
|
-
export function useChartState(): RechartsStateContextValue {
|
|
7
|
-
const ctx = useContext(RechartsStateContext)
|
|
8
|
-
if (ctx == null) {
|
|
9
|
-
throw new Error("@solidports/recharts: useChartState called outside RechartsStateProvider")
|
|
10
|
-
}
|
|
11
|
-
return ctx
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Returns state + setState from the nearest RechartsStateProvider, or null outside one. */
|
|
15
|
-
export function useOptionalChartState(): RechartsStateContextValue | null {
|
|
16
|
-
return useContext(RechartsStateContext)
|
|
17
|
-
}
|
package/src/state/zIndexSlice.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
2
|
-
|
|
3
|
-
export type ZIndexEntry = {
|
|
4
|
-
/**
|
|
5
|
-
* Reference to the DOM element that corresponds to this z-index.
|
|
6
|
-
* This element is used to create a portal for rendering components at this z-index.
|
|
7
|
-
*
|
|
8
|
-
* If undefined, it means no element is currently registered for this z-index,
|
|
9
|
-
* and registration is in progress. If that happens, wait for the next render cycle.
|
|
10
|
-
*/
|
|
11
|
-
element: Element | undefined
|
|
12
|
-
/**
|
|
13
|
-
* Panorama items can't mix with normal items in the same z-index layer,
|
|
14
|
-
* because they are rendered in a different SVG element.
|
|
15
|
-
* So we need to have a separate element reference for panorama z-index portals.
|
|
16
|
-
*/
|
|
17
|
-
panoramaElement: Element | undefined
|
|
18
|
-
consumers: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ZIndexState = {
|
|
22
|
-
zIndexMap: Record<number, ZIndexEntry>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createInitialZIndexState(): ZIndexState {
|
|
26
|
-
const zIndexMap: ZIndexState["zIndexMap"] = {}
|
|
27
|
-
for (const current of Object.values(DefaultZIndexes)) {
|
|
28
|
-
zIndexMap[current] = { consumers: 0, element: undefined, panoramaElement: undefined }
|
|
29
|
-
}
|
|
30
|
-
return { zIndexMap }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const initialZIndexState: ZIndexState = createInitialZIndexState()
|
|
34
|
-
|
|
35
|
-
const defaultZIndexSet = new Set<number>(Object.values(DefaultZIndexes))
|
|
36
|
-
|
|
37
|
-
export function isDefaultZIndex(zIndex: number): boolean {
|
|
38
|
-
return defaultZIndexSet.has(zIndex)
|
|
39
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ChartState } from "../state/store"
|
|
2
|
-
import type { TooltipSyncState } from "../state/tooltipSlice"
|
|
3
|
-
import { readChartState } from "../state/chartState"
|
|
4
|
-
|
|
5
|
-
export function selectSynchronisedTooltipState(state: ChartState): TooltipSyncState {
|
|
6
|
-
return readChartState(state).tooltip.syncInteraction
|
|
7
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-cycle */
|
|
2
|
-
import { Coordinate, DataKey, TickItem } from "../util/types"
|
|
3
|
-
import { TooltipIndex } from "../state/tooltipSlice"
|
|
4
|
-
|
|
5
|
-
export type ActiveLabel = string | number | undefined
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Despite the name, this type is used for all event types, not just mouse events.
|
|
9
|
-
*/
|
|
10
|
-
export type MouseHandlerDataParam = {
|
|
11
|
-
/**
|
|
12
|
-
* Index of the active tick in the current chart. Only works with number-indexed one-dimensional data charts,
|
|
13
|
-
* like Line, Area, Bar, Pie, etc.
|
|
14
|
-
*
|
|
15
|
-
* Doesn't work with two-dimensional data charts like Treemap, Sankey. But one day it will which is why the TooltipIndex type is here.
|
|
16
|
-
*/
|
|
17
|
-
activeTooltipIndex: number | TooltipIndex | undefined
|
|
18
|
-
isTooltipActive: boolean
|
|
19
|
-
/**
|
|
20
|
-
* Exactly the same as activeTooltipIndex - this was also duplicated in recharts@2 so let's keep both properties for better backwards compatibility.
|
|
21
|
-
*/
|
|
22
|
-
activeIndex: number | TooltipIndex | undefined
|
|
23
|
-
/**
|
|
24
|
-
* The category or domain value of the active tooltip entry.
|
|
25
|
-
*/
|
|
26
|
-
activeLabel: ActiveLabel
|
|
27
|
-
activeDataKey: DataKey<unknown> | undefined
|
|
28
|
-
activeCoordinate: Coordinate | undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Allows customisation of how the charts will synchronize tooltips and brushes.
|
|
33
|
-
* Default: index
|
|
34
|
-
*
|
|
35
|
-
* 'index': other charts will reuse current datum's index within the data array. In cases where data does not have the same length, this might yield unexpected results.
|
|
36
|
-
* 'value': will try to match other charts values
|
|
37
|
-
* custom function: will receive two arguments and should return an index of the active tick in the current chart:
|
|
38
|
-
* argument 1: ticks from the current chart
|
|
39
|
-
* argument 2: active tooltip state from the other chart
|
|
40
|
-
*/
|
|
41
|
-
export type SyncMethod =
|
|
42
|
-
| "index"
|
|
43
|
-
| "value"
|
|
44
|
-
| ((ticks: ReadonlyArray<TickItem>, data: MouseHandlerDataParam) => number)
|
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-cycle */
|
|
2
|
-
import { createEffect, untrack, createMemo } from 'solid-js';
|
|
3
|
-
import { useChartStore } from "../state/RechartsStoreContext"
|
|
4
|
-
import {
|
|
5
|
-
selectEventEmitter,
|
|
6
|
-
selectSyncId,
|
|
7
|
-
selectSyncMethod,
|
|
8
|
-
} from "../state/selectors/rootPropsSelectors"
|
|
9
|
-
import { BRUSH_SYNC_EVENT, eventCenter, TOOLTIP_SYNC_EVENT } from "../util/Events"
|
|
10
|
-
import type { TooltipIndex, TooltipSyncState } from "../state/tooltipSlice"
|
|
11
|
-
import { selectTooltipDataKey } from "../state/selectors/selectors"
|
|
12
|
-
import type { Coordinate, TickItem, TooltipEventType } from "../util/types"
|
|
13
|
-
import type { TooltipTrigger } from "../chart/types"
|
|
14
|
-
import { selectActiveTooltipGraphicalItemId, selectTooltipAxisTicks } from "../state/selectors/tooltipSelectors"
|
|
15
|
-
import { selectSynchronisedTooltipState } from "./syncSelectors"
|
|
16
|
-
import { selectChartLayout, useViewBox } from "../context/chartLayoutContext"
|
|
17
|
-
import { useIsPanorama } from "../context/PanoramaContext"
|
|
18
|
-
import { selectChartViewBox } from "../state/selectors/selectChartOffsetInternal"
|
|
19
|
-
import {
|
|
20
|
-
selectBrushDimensions,
|
|
21
|
-
selectBrushSettings,
|
|
22
|
-
} from "../state/selectors/brushSelectors"
|
|
23
|
-
import type { CartesianViewBoxRequired } from "../util/types"
|
|
24
|
-
import type { BrushStartEndIndex } from "../context/brushUpdateContext"
|
|
25
|
-
import type { ActiveLabel, MouseHandlerDataParam } from "./types"
|
|
26
|
-
|
|
27
|
-
function useTooltipSyncEventsListener() {
|
|
28
|
-
const ctx = useChartStore()
|
|
29
|
-
if (ctx == null) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
const { store, setStore } = ctx
|
|
33
|
-
/* Capture isPanorama at owner setup. The listener fires from a non-Solid
|
|
34
|
-
event bus (no owner on the call stack), so `useContext` inside `useViewBox`
|
|
35
|
-
would return the default. Read viewBox directly off the captured store
|
|
36
|
-
instead. Mirrors the original useViewBox body. */
|
|
37
|
-
const isPanorama = useIsPanorama()
|
|
38
|
-
const viewBox = (): CartesianViewBoxRequired | undefined => {
|
|
39
|
-
const rootViewBox = selectChartViewBox(store)
|
|
40
|
-
const brushDimensions = selectBrushDimensions(store)
|
|
41
|
-
const brushPadding = selectBrushSettings(store)?.padding
|
|
42
|
-
if (isPanorama === false || brushDimensions == null || brushPadding == null) {
|
|
43
|
-
return rootViewBox
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
height: brushDimensions.height - brushPadding.top - brushPadding.bottom,
|
|
47
|
-
width: brushDimensions.width - brushPadding.left - brushPadding.right,
|
|
48
|
-
x: brushPadding.left,
|
|
49
|
-
y: brushPadding.top,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
createEffect(
|
|
54
|
-
() => {
|
|
55
|
-
const mySyncId = selectSyncId(store)
|
|
56
|
-
/* Unsynchronised charts must not track the tooltip ticks (every data point). */
|
|
57
|
-
if (mySyncId == null) {
|
|
58
|
-
return null
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
layout: selectChartLayout(store),
|
|
62
|
-
myEventEmitter: selectEventEmitter(store),
|
|
63
|
-
mySyncId,
|
|
64
|
-
syncMethod: selectSyncMethod(store),
|
|
65
|
-
tooltipTicks: selectTooltipAxisTicks(store),
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
(sync) => {
|
|
69
|
-
if (sync == null) {
|
|
70
|
-
/* This chart is not synchronised with any other chart so we don't need to listen for any events. */
|
|
71
|
-
return undefined
|
|
72
|
-
}
|
|
73
|
-
const { layout, myEventEmitter, mySyncId, syncMethod, tooltipTicks } = sync
|
|
74
|
-
|
|
75
|
-
const listener = (
|
|
76
|
-
incomingSyncId: number | string,
|
|
77
|
-
incomingState: TooltipSyncState,
|
|
78
|
-
emitter: symbol,
|
|
79
|
-
) => {
|
|
80
|
-
if (myEventEmitter === emitter) {
|
|
81
|
-
/* We don't want to process events that we sent ourselves. */
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
if (mySyncId !== incomingSyncId) {
|
|
85
|
-
/* This event is not for this chart */
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/*
|
|
90
|
-
* Handle source chart deactivation (mouseLeave) for ALL sync methods.
|
|
91
|
-
* This must be checked before any syncMethod-specific logic to ensure
|
|
92
|
-
* sourceViewBox is cleared, which allows isReceivingSynchronisation
|
|
93
|
-
* to become false and lets the normal emission flow resume.
|
|
94
|
-
*/
|
|
95
|
-
if (incomingState.active === false) {
|
|
96
|
-
setStore("tooltip", "syncInteraction", {
|
|
97
|
-
active: false,
|
|
98
|
-
coordinate: undefined,
|
|
99
|
-
dataKey: undefined,
|
|
100
|
-
graphicalItemId: undefined,
|
|
101
|
-
index: null,
|
|
102
|
-
label: undefined,
|
|
103
|
-
sourceViewBox: undefined,
|
|
104
|
-
})
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (syncMethod === "index") {
|
|
109
|
-
const vb = viewBox()
|
|
110
|
-
if (vb && incomingState?.coordinate && incomingState.sourceViewBox) {
|
|
111
|
-
const { x, y, ...otherCoordinateProps } = incomingState.coordinate
|
|
112
|
-
const {
|
|
113
|
-
x: sourceX,
|
|
114
|
-
y: sourceY,
|
|
115
|
-
width: sourceWidth,
|
|
116
|
-
height: sourceHeight,
|
|
117
|
-
} = incomingState.sourceViewBox
|
|
118
|
-
|
|
119
|
-
const scaledCoordinate = {
|
|
120
|
-
...otherCoordinateProps,
|
|
121
|
-
x: vb.x + (sourceWidth ? (x - sourceX) / sourceWidth : 0) * vb.width,
|
|
122
|
-
y: vb.y + (sourceHeight ? (y - sourceY) / sourceHeight : 0) * vb.height,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const syncPayload = { ...incomingState, coordinate: scaledCoordinate }
|
|
126
|
-
setStore("tooltip", "syncInteraction", syncPayload)
|
|
127
|
-
} else {
|
|
128
|
-
setStore("tooltip", "syncInteraction", incomingState)
|
|
129
|
-
}
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (tooltipTicks == null) {
|
|
134
|
-
/* for the other two sync methods, we need the ticks to be available */
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
let activeTick: TickItem | undefined
|
|
139
|
-
if (typeof syncMethod === "function") {
|
|
140
|
-
/*
|
|
141
|
-
* This is what the data shape in 2.x CategoricalChartState used to look like.
|
|
142
|
-
* In 3.x we store things differently but let's try to keep the old shape for compatibility.
|
|
143
|
-
*/
|
|
144
|
-
const syncMethodParam: MouseHandlerDataParam = {
|
|
145
|
-
activeCoordinate: incomingState.coordinate,
|
|
146
|
-
activeDataKey: incomingState.dataKey,
|
|
147
|
-
activeIndex: incomingState.index == null ? undefined : Number(incomingState.index),
|
|
148
|
-
activeLabel: incomingState.label,
|
|
149
|
-
activeTooltipIndex: incomingState.index == null ? undefined : Number(incomingState.index),
|
|
150
|
-
isTooltipActive: incomingState.active,
|
|
151
|
-
}
|
|
152
|
-
/* Call a callback function. If there is an application specific algorithm */
|
|
153
|
-
const activeTooltipIndex = syncMethod(tooltipTicks, syncMethodParam)
|
|
154
|
-
activeTick = tooltipTicks[activeTooltipIndex]
|
|
155
|
-
} else if (syncMethod === "value") {
|
|
156
|
-
/* labels are always strings, tick.value might be a string or a number, depending on axis type */
|
|
157
|
-
activeTick = tooltipTicks.find((tick) => String(tick.value) === incomingState.label)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const { coordinate } = incomingState
|
|
161
|
-
|
|
162
|
-
const vbSync = viewBox()
|
|
163
|
-
if (coordinate == null || vbSync == null) {
|
|
164
|
-
setStore("tooltip", "syncInteraction", {
|
|
165
|
-
active: false,
|
|
166
|
-
coordinate: undefined,
|
|
167
|
-
dataKey: undefined,
|
|
168
|
-
graphicalItemId: undefined,
|
|
169
|
-
index: null,
|
|
170
|
-
label: undefined,
|
|
171
|
-
sourceViewBox: undefined,
|
|
172
|
-
})
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (activeTick == null) {
|
|
177
|
-
/*
|
|
178
|
-
* The label from the source chart doesn't match any tick in this chart.
|
|
179
|
-
* This happens when synced charts have different data arrays
|
|
180
|
-
* (e.g., one chart has 3 data points while another has 252).
|
|
181
|
-
*
|
|
182
|
-
* We set active: false so the tooltip hides (correct — no data for this date),
|
|
183
|
-
* but we keep sourceViewBox set to signal that we're still receiving sync events.
|
|
184
|
-
* The emission guard in useTooltipChartSynchronisation checks sourceViewBox
|
|
185
|
-
* (not active) to decide whether to suppress outgoing sync events.
|
|
186
|
-
* Without this, the chart would emit a counter-sync event with active: false,
|
|
187
|
-
* cascading to clear tooltips on ALL other synced charts.
|
|
188
|
-
*/
|
|
189
|
-
setStore("tooltip", "syncInteraction", {
|
|
190
|
-
active: false,
|
|
191
|
-
coordinate: undefined,
|
|
192
|
-
dataKey: undefined,
|
|
193
|
-
graphicalItemId: undefined,
|
|
194
|
-
index: null,
|
|
195
|
-
label: undefined,
|
|
196
|
-
sourceViewBox: incomingState.sourceViewBox,
|
|
197
|
-
})
|
|
198
|
-
return
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const { x, y } = coordinate
|
|
202
|
-
const validateChartX = Math.min(x, vbSync.x + vbSync.width)
|
|
203
|
-
const validateChartY = Math.min(y, vbSync.y + vbSync.height)
|
|
204
|
-
const activeCoordinate: Coordinate = {
|
|
205
|
-
x: layout === "horizontal" ? activeTick.coordinate : validateChartX,
|
|
206
|
-
y: layout === "horizontal" ? validateChartY : activeTick.coordinate,
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const activePayload = {
|
|
210
|
-
active: incomingState.active,
|
|
211
|
-
coordinate: activeCoordinate,
|
|
212
|
-
dataKey: incomingState.dataKey,
|
|
213
|
-
graphicalItemId: incomingState.graphicalItemId,
|
|
214
|
-
index: String(activeTick.index),
|
|
215
|
-
label: incomingState.label,
|
|
216
|
-
sourceViewBox: incomingState.sourceViewBox,
|
|
217
|
-
}
|
|
218
|
-
setStore("tooltip", "syncInteraction", activePayload)
|
|
219
|
-
}
|
|
220
|
-
/* Listeners fire inside another chart's effect; they read this chart's current state. */
|
|
221
|
-
const untrackedListener: typeof listener = (...args) => untrack(() => listener(...args))
|
|
222
|
-
eventCenter.on(TOOLTIP_SYNC_EVENT, untrackedListener)
|
|
223
|
-
|
|
224
|
-
return () => {
|
|
225
|
-
eventCenter.off(TOOLTIP_SYNC_EVENT, untrackedListener)
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function useBrushSyncEventsListener() {
|
|
232
|
-
const ctx = useChartStore()
|
|
233
|
-
if (ctx == null) {
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
const { store, setStore } = ctx
|
|
237
|
-
|
|
238
|
-
createEffect(
|
|
239
|
-
() => ({ myEventEmitter: selectEventEmitter(store), mySyncId: selectSyncId(store) }),
|
|
240
|
-
({ myEventEmitter, mySyncId }) => {
|
|
241
|
-
if (mySyncId == null) {
|
|
242
|
-
/* This chart is not synchronised with any other chart so we don't need to listen for any events. */
|
|
243
|
-
return undefined
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const listener = (
|
|
247
|
-
incomingSyncId: number | string,
|
|
248
|
-
action: BrushStartEndIndex,
|
|
249
|
-
emitter: symbol,
|
|
250
|
-
) => {
|
|
251
|
-
if (myEventEmitter === emitter) {
|
|
252
|
-
/* We don't want to process events that we sent ourselves. */
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
if (mySyncId === incomingSyncId) {
|
|
256
|
-
setStore("chartData", "dataStartIndex", action.startIndex)
|
|
257
|
-
setStore("chartData", "dataEndIndex", action.endIndex)
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/* Listeners fire inside another chart's effect; they read this chart's current state. */
|
|
261
|
-
const untrackedListener: typeof listener = (...args) => untrack(() => listener(...args))
|
|
262
|
-
eventCenter.on(BRUSH_SYNC_EVENT, untrackedListener)
|
|
263
|
-
|
|
264
|
-
return () => {
|
|
265
|
-
eventCenter.off(BRUSH_SYNC_EVENT, untrackedListener)
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Will receive synchronisation events from other charts.
|
|
273
|
-
*
|
|
274
|
-
* Reads syncMethod from state and decides how to synchronise the tooltip based on that.
|
|
275
|
-
*
|
|
276
|
-
* @returns void
|
|
277
|
-
*/
|
|
278
|
-
export function useSynchronisedEventsFromOtherCharts() {
|
|
279
|
-
const ctx = useChartStore()
|
|
280
|
-
if (ctx == null) {
|
|
281
|
-
return
|
|
282
|
-
}
|
|
283
|
-
const { store, setStore } = ctx
|
|
284
|
-
|
|
285
|
-
createEffect(
|
|
286
|
-
() => store.options.eventEmitter,
|
|
287
|
-
(eventEmitter) => {
|
|
288
|
-
if (eventEmitter == null) {
|
|
289
|
-
setStore("options", "eventEmitter", Symbol("rechartsEventEmitter"))
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
useTooltipSyncEventsListener()
|
|
295
|
-
useBrushSyncEventsListener()
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Will send events to other charts.
|
|
300
|
-
* If syncId is undefined, no events will be sent.
|
|
301
|
-
*
|
|
302
|
-
* This ignores the syncMethod, because that is set and computed on the receiving end.
|
|
303
|
-
*
|
|
304
|
-
* @param tooltipEventType from Tooltip
|
|
305
|
-
* @param trigger from Tooltip
|
|
306
|
-
* @param activeCoordinate from state
|
|
307
|
-
* @param activeLabel from state
|
|
308
|
-
* @param activeIndex from state
|
|
309
|
-
* @param isTooltipActive from state
|
|
310
|
-
* @returns void
|
|
311
|
-
*/
|
|
312
|
-
/* Each param is an accessor — reading inside the effect tracks the upstream
|
|
313
|
-
memo, so emit fires whenever finalIsActive / coordinate / index transitions.
|
|
314
|
-
Plain T params would be snapshotted at call time and never refreshed (GOTCHA-002). */
|
|
315
|
-
export function useTooltipChartSynchronisation(
|
|
316
|
-
tooltipEventType: () => TooltipEventType | undefined,
|
|
317
|
-
trigger: () => TooltipTrigger,
|
|
318
|
-
activeCoordinate: () => Coordinate | undefined,
|
|
319
|
-
activeLabel: () => ActiveLabel,
|
|
320
|
-
activeIndex: () => TooltipIndex | undefined,
|
|
321
|
-
isTooltipActive: () => boolean,
|
|
322
|
-
) {
|
|
323
|
-
const ctx = useChartStore()
|
|
324
|
-
if (ctx == null) {
|
|
325
|
-
return
|
|
326
|
-
}
|
|
327
|
-
const { store } = ctx
|
|
328
|
-
const viewBox = createMemo(() => useViewBox())
|
|
329
|
-
|
|
330
|
-
createEffect(
|
|
331
|
-
() => {
|
|
332
|
-
const syncId = selectSyncId(store)
|
|
333
|
-
if (syncId == null) {
|
|
334
|
-
return null
|
|
335
|
-
}
|
|
336
|
-
const activeDataKey = selectTooltipDataKey(store, tooltipEventType(), trigger())
|
|
337
|
-
const eventEmitterSymbol = selectEventEmitter(store)
|
|
338
|
-
const tooltipState = selectSynchronisedTooltipState(store)
|
|
339
|
-
/*
|
|
340
|
-
* Use sourceViewBox (not active) to detect incoming synchronisation. It is set whenever
|
|
341
|
-
* another chart sends us a sync event, even when our own tooltip stays inactive, so charts
|
|
342
|
-
* with sparse data do not emit counter-sync events that clear the other tooltips.
|
|
343
|
-
*/
|
|
344
|
-
const isReceivingSynchronisation = tooltipState?.sourceViewBox != null
|
|
345
|
-
|
|
346
|
-
if (isReceivingSynchronisation) {
|
|
347
|
-
return null
|
|
348
|
-
}
|
|
349
|
-
if (eventEmitterSymbol == null) {
|
|
350
|
-
return null
|
|
351
|
-
}
|
|
352
|
-
const labelValue = activeLabel()
|
|
353
|
-
const idxValue = activeIndex()
|
|
354
|
-
const syncState: TooltipSyncState = {
|
|
355
|
-
active: isTooltipActive(),
|
|
356
|
-
coordinate: activeCoordinate(),
|
|
357
|
-
dataKey: activeDataKey,
|
|
358
|
-
graphicalItemId: selectActiveTooltipGraphicalItemId(store),
|
|
359
|
-
index: idxValue ?? null,
|
|
360
|
-
label: typeof labelValue === "number" ? String(labelValue) : labelValue,
|
|
361
|
-
sourceViewBox: viewBox(),
|
|
362
|
-
}
|
|
363
|
-
return { eventEmitterSymbol, syncId, syncState }
|
|
364
|
-
},
|
|
365
|
-
(sync) => {
|
|
366
|
-
if (sync != null) {
|
|
367
|
-
eventCenter.emit(TOOLTIP_SYNC_EVENT, sync.syncId, sync.syncState, sync.eventEmitterSymbol)
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function useBrushChartSynchronisation() {
|
|
374
|
-
const ctx = useChartStore()
|
|
375
|
-
if (ctx == null) {
|
|
376
|
-
return
|
|
377
|
-
}
|
|
378
|
-
const { store } = ctx
|
|
379
|
-
|
|
380
|
-
createEffect(
|
|
381
|
-
() => {
|
|
382
|
-
const syncId = selectSyncId(store)
|
|
383
|
-
const eventEmitterSymbol = selectEventEmitter(store)
|
|
384
|
-
const brushStartIndex = store.chartData.dataStartIndex
|
|
385
|
-
const brushEndIndex = store.chartData.dataEndIndex
|
|
386
|
-
|
|
387
|
-
if (
|
|
388
|
-
syncId == null ||
|
|
389
|
-
brushStartIndex == null ||
|
|
390
|
-
brushEndIndex == null ||
|
|
391
|
-
eventEmitterSymbol == null
|
|
392
|
-
) {
|
|
393
|
-
return null
|
|
394
|
-
}
|
|
395
|
-
const syncAction: BrushStartEndIndex = { endIndex: brushEndIndex, startIndex: brushStartIndex }
|
|
396
|
-
return { eventEmitterSymbol, syncAction, syncId }
|
|
397
|
-
},
|
|
398
|
-
(sync) => {
|
|
399
|
-
if (sync != null) {
|
|
400
|
-
eventCenter.emit(BRUSH_SYNC_EVENT, sync.syncId, sync.syncAction, sync.eventEmitterSymbol)
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
)
|
|
404
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Styling presets for Recharts components.
|
|
3
|
-
* The theme can be used to customize the appearance of charts, including colors, fonts, and other visual properties.
|
|
4
|
-
*
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
export interface RechartsTheme {
|
|
8
|
-
grid: Partial<{
|
|
9
|
-
stroke: string
|
|
10
|
-
strokeOpacity: number
|
|
11
|
-
strokeWidth: number
|
|
12
|
-
strokeDasharray: string | number | ReadonlyArray<number>
|
|
13
|
-
fillOpacity: number
|
|
14
|
-
fill: string
|
|
15
|
-
}>
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from "solid-js"
|
|
2
|
-
import type { RechartsTheme } from "./RechartsTheme"
|
|
3
|
-
import { legacyTheme } from "./legacyTheme"
|
|
4
|
-
|
|
5
|
-
const RechartsThemeContext = createContext<RechartsTheme>(legacyTheme)
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Applies the provided theme to all charts in the children tree.
|
|
9
|
-
*
|
|
10
|
-
* @experimental
|
|
11
|
-
*/
|
|
12
|
-
export const RechartsThemeProvider = RechartsThemeContext
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Reads the currently active theme in the children tree.
|
|
16
|
-
*
|
|
17
|
-
* @experimental
|
|
18
|
-
*/
|
|
19
|
-
export const useRechartsTheme = (): RechartsTheme => useContext(RechartsThemeContext)
|
package/src/theme/darkTheme.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileOverview
|
|
3
|
-
* This file provides helper methods for assigning theme identity to a
|
|
4
|
-
* graphical item. Graphical items are individual drawable data representations,
|
|
5
|
-
* such as Line or Bar. In previous Recharts versions these can be styled
|
|
6
|
-
* individually. In next version, Recharts will allow the user to provide an
|
|
7
|
-
* array of themes, and then have the graphical items pick one. There is a gap
|
|
8
|
-
* however; graphical items are not sorted and not indexed. We can"t use DOM
|
|
9
|
-
* order because that order changes. So instead we need an identifier that:
|
|
10
|
-
* - we can calculate from props, without requiring the user to provide an
|
|
11
|
-
* explicit id
|
|
12
|
-
* - is stable across renders, so that the same item will always get the same
|
|
13
|
-
* theme
|
|
14
|
-
* - is (within possibilities) unique across all items, so that no two items
|
|
15
|
-
* will get the same theme The uniqueness is impossible to guarantee 100% so
|
|
16
|
-
* we will only provide a best-effort. This file provides a helper method to
|
|
17
|
-
* calculate such an identifier.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import type { DataKey } from "../util/types"
|
|
21
|
-
|
|
22
|
-
export type ThemableItem = {
|
|
23
|
-
dataKey: DataKey<unknown>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Computes a deterministic numeric hash for the given string. Uses djb2 hash
|
|
28
|
-
* algorithm with additional bit-mixing to improve distribution across small
|
|
29
|
-
* moduli (e.g., themeCount = 5).
|
|
30
|
-
*/
|
|
31
|
-
function computeHash(str: string): number {
|
|
32
|
-
let hash = 5381
|
|
33
|
-
for (let i = 0; i < str.length; i++) {
|
|
34
|
-
hash = (hash << 5) + hash + str.charCodeAt(i); // hash * 33 + charCode
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Bit-mixing step: multiply by a large prime, then XOR-shift to spread
|
|
38
|
-
// bit patterns. This prevents collisions that can occur with raw %
|
|
39
|
-
// themeCount when the raw hash"s low bits correlate poorly across inputs.
|
|
40
|
-
hash ^= hash >>> 16
|
|
41
|
-
hash *= 0x85ebca6b
|
|
42
|
-
hash ^= hash >>> 16
|
|
43
|
-
|
|
44
|
-
return hash & 0x7fffffff; // Mask to ensure non-negative 31-bit integer
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Calculates theme index from a given item. The identity is computed
|
|
49
|
-
* deterministically from the dataKey string, ensuring stability across renders
|
|
50
|
-
* and module reloads.
|
|
51
|
-
* @param item - The themable item to calculate identity for
|
|
52
|
-
* @param themeCount - Optional number of available themes; if provided, clamps
|
|
53
|
-
* the hash to [0, themeCount).
|
|
54
|
-
*/
|
|
55
|
-
export function graphicalItemIdentity(item: ThemableItem, themeCount?: number): number {
|
|
56
|
-
// Negative or zero themeCount is semantically invalid (can"t have negative themes,
|
|
57
|
-
// and zero themes means none available)
|
|
58
|
-
if (themeCount != null && themeCount <= 0) {
|
|
59
|
-
return 0
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const keyString = String(item.dataKey)
|
|
63
|
-
const hashResult = computeHash(keyString)
|
|
64
|
-
|
|
65
|
-
if (themeCount != null && themeCount > 0) {
|
|
66
|
-
return hashResult % themeCount
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return hashResult
|
|
70
|
-
}
|
package/src/theme/legacyTheme.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RechartsTheme } from "./RechartsTheme"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This is the theme as was the default in 2.x and 3.x branches.
|
|
5
|
-
*
|
|
6
|
-
* It"s not very consistent, colors are all over the place and overall exists only for backwards compatibility.
|
|
7
|
-
* Prefer to use either {@link lightTheme} or {@link darkTheme} instead.
|
|
8
|
-
*
|
|
9
|
-
* @deprecated
|
|
10
|
-
* @experimental
|
|
11
|
-
*/
|
|
12
|
-
export const legacyTheme: RechartsTheme = {
|
|
13
|
-
grid: {
|
|
14
|
-
stroke: "#ccc",
|
|
15
|
-
fill: "none",
|
|
16
|
-
},
|
|
17
|
-
}
|