@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,185 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { ChartState } from "./chartState"
|
|
3
|
+
import type { RelativePointer, HTMLMousePointer } from "../util/types"
|
|
4
|
+
import { selectActivePropsFromChartPointer } from "./selectors/selectActivePropsFromChartPointer"
|
|
5
|
+
import { selectTooltipEventType } from "./selectors/selectTooltipEventType"
|
|
6
|
+
import { getRelativeCoordinate } from "../util/getRelativeCoordinate"
|
|
7
|
+
import { readChartState } from "./chartState"
|
|
8
|
+
|
|
9
|
+
import { type SetStoreFunction } from '../util/solid-1-compat';
|
|
10
|
+
import { setTooltipInteraction } from "./tooltipInteraction"
|
|
11
|
+
export type MouseEventHandlers = {
|
|
12
|
+
handleMouseClick: (mousePointer: HTMLMousePointer) => void
|
|
13
|
+
handleMouseMove: (mousePointer: HTMLMousePointer) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates mouse event handler functions that read from the Solid store and update it directly.
|
|
18
|
+
* Replaces the Redux createListenerMiddleware pattern.
|
|
19
|
+
*/
|
|
20
|
+
export function createMouseEventHandlers(
|
|
21
|
+
store: ChartState,
|
|
22
|
+
setStore: SetStoreFunction<ChartState>,
|
|
23
|
+
): MouseEventHandlers {
|
|
24
|
+
/*
|
|
25
|
+
* This single rafId is safe because:
|
|
26
|
+
* 1. Each chart has its own store instance with its own handlers
|
|
27
|
+
* 2. mouseMove only fires from one DOM element (the chart wrapper)
|
|
28
|
+
* 3. Rapid mousemove events from the same element SHOULD debounce - we only care about the latest position
|
|
29
|
+
* This is different from externalEventsMiddleware which handles multiple event types
|
|
30
|
+
* (click, mouseenter, mouseleave, etc.) that should NOT cancel each other.
|
|
31
|
+
*/
|
|
32
|
+
let rafId: number | null = null
|
|
33
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
|
34
|
+
let latestChartPointer: RelativePointer | null = null
|
|
35
|
+
|
|
36
|
+
function handleMouseClick(mousePointer: HTMLMousePointer): void {
|
|
37
|
+
const activeProps = selectActivePropsFromChartPointer(
|
|
38
|
+
store,
|
|
39
|
+
getRelativeCoordinate(mousePointer),
|
|
40
|
+
)
|
|
41
|
+
if (activeProps?.activeIndex != null) {
|
|
42
|
+
setTooltipInteraction(setStore, "axisInteraction", "click", {
|
|
43
|
+
active: true,
|
|
44
|
+
coordinate: activeProps.activeCoordinate,
|
|
45
|
+
dataKey: undefined,
|
|
46
|
+
graphicalItemId: undefined,
|
|
47
|
+
index: activeProps.activeIndex,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function handleMouseMove(mousePointer: HTMLMousePointer): void {
|
|
53
|
+
const { throttleDelay, throttledEvents } = store.eventSettings
|
|
54
|
+
const isThrottled = throttledEvents === "all" || throttledEvents?.includes("mousemove")
|
|
55
|
+
|
|
56
|
+
/* Cancel any pending execution */
|
|
57
|
+
if (rafId !== null) {
|
|
58
|
+
cancelAnimationFrame(rafId)
|
|
59
|
+
rafId = null
|
|
60
|
+
}
|
|
61
|
+
if (timeoutId !== null && (typeof throttleDelay !== "number" || !isThrottled)) {
|
|
62
|
+
clearTimeout(timeoutId)
|
|
63
|
+
timeoutId = null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* Here it is important to resolve the chart pointer _before_ the callback,
|
|
68
|
+
* because once we leave the current event loop, the mousePointer event object will lose
|
|
69
|
+
* reference to currentTarget which getRelativeCoordinate uses.
|
|
70
|
+
*/
|
|
71
|
+
latestChartPointer = getRelativeCoordinate(mousePointer)
|
|
72
|
+
const callback = () => {
|
|
73
|
+
/*
|
|
74
|
+
* Here we read a fresh state again inside the callback to ensure we have the latest state values
|
|
75
|
+
* after any potential actions that may have been dispatched between the original event and this callback.
|
|
76
|
+
*/
|
|
77
|
+
const tooltipEventType = selectTooltipEventType(
|
|
78
|
+
store,
|
|
79
|
+
readChartState(store).tooltip.settings.shared,
|
|
80
|
+
)
|
|
81
|
+
if (latestChartPointer == null) {
|
|
82
|
+
rafId = null
|
|
83
|
+
timeoutId = null
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* This functionality only applies to charts that have axes.
|
|
89
|
+
* Graphical items have its own mouse events handling mechanism where they attach events directly to the items.
|
|
90
|
+
*/
|
|
91
|
+
if (tooltipEventType === "axis") {
|
|
92
|
+
const activeProps = selectActivePropsFromChartPointer(store, latestChartPointer)
|
|
93
|
+
if (activeProps?.activeIndex != null) {
|
|
94
|
+
setTooltipInteraction(setStore, "axisInteraction", "hover", {
|
|
95
|
+
active: true,
|
|
96
|
+
coordinate: activeProps.activeCoordinate,
|
|
97
|
+
dataKey: undefined,
|
|
98
|
+
graphicalItemId: undefined,
|
|
99
|
+
index: activeProps.activeIndex,
|
|
100
|
+
})
|
|
101
|
+
} else {
|
|
102
|
+
/* Mouse moves inside svg but out of plot area — flip `active` only, mirror
|
|
103
|
+
upstream mouseLeaveChart so coordinate/index survive for the active=true
|
|
104
|
+
prop and animation tail. */
|
|
105
|
+
setStore("tooltip", "axisInteraction", "hover", "active", false)
|
|
106
|
+
setStore("tooltip", "itemInteraction", "hover", "active", false)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
rafId = null
|
|
110
|
+
timeoutId = null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!isThrottled) {
|
|
114
|
+
callback()
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (throttleDelay === "raf") {
|
|
119
|
+
rafId = requestAnimationFrame(callback)
|
|
120
|
+
} else if (typeof throttleDelay === "number") {
|
|
121
|
+
if (timeoutId === null) {
|
|
122
|
+
timeoutId = setTimeout(callback, throttleDelay)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { handleMouseClick, handleMouseMove }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Action thunk wrappers for use with the dispatch pattern.
|
|
132
|
+
* These delegate to the same logic as createMouseEventHandlers.
|
|
133
|
+
*/
|
|
134
|
+
export const mouseClickAction =
|
|
135
|
+
(mousePointer: HTMLMousePointer) =>
|
|
136
|
+
(
|
|
137
|
+
setStore: SetStoreFunction<ChartState>,
|
|
138
|
+
store: ChartState,
|
|
139
|
+
) => {
|
|
140
|
+
const activeProps = selectActivePropsFromChartPointer(
|
|
141
|
+
store,
|
|
142
|
+
getRelativeCoordinate(mousePointer),
|
|
143
|
+
)
|
|
144
|
+
if (activeProps?.activeIndex != null) {
|
|
145
|
+
const payload = {
|
|
146
|
+
active: true,
|
|
147
|
+
coordinate: activeProps.activeCoordinate,
|
|
148
|
+
dataKey: undefined,
|
|
149
|
+
graphicalItemId: undefined,
|
|
150
|
+
index: activeProps.activeIndex,
|
|
151
|
+
}
|
|
152
|
+
setTooltipInteraction(setStore, "axisInteraction", "click", payload)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const mouseMoveAction =
|
|
157
|
+
(mousePointer: HTMLMousePointer) =>
|
|
158
|
+
(
|
|
159
|
+
setStore: SetStoreFunction<ChartState>,
|
|
160
|
+
store: ChartState,
|
|
161
|
+
) => {
|
|
162
|
+
const chartPointer = getRelativeCoordinate(mousePointer)
|
|
163
|
+
const tooltipEventType = selectTooltipEventType(
|
|
164
|
+
store,
|
|
165
|
+
readChartState(store).tooltip.settings.shared,
|
|
166
|
+
)
|
|
167
|
+
if (tooltipEventType === "axis") {
|
|
168
|
+
const activeProps = selectActivePropsFromChartPointer(store, chartPointer)
|
|
169
|
+
if (activeProps?.activeIndex != null) {
|
|
170
|
+
const payload = {
|
|
171
|
+
active: true,
|
|
172
|
+
coordinate: activeProps.activeCoordinate,
|
|
173
|
+
dataKey: undefined,
|
|
174
|
+
graphicalItemId: undefined,
|
|
175
|
+
index: activeProps.activeIndex,
|
|
176
|
+
}
|
|
177
|
+
setTooltipInteraction(setStore, "axisInteraction", "hover", payload)
|
|
178
|
+
} else {
|
|
179
|
+
{
|
|
180
|
+
setStore("tooltip", "axisInteraction", "hover", "active", false)
|
|
181
|
+
setStore("tooltip", "itemInteraction", "hover", "active", false)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { TooltipEventType } from "../util/types"
|
|
3
|
+
import type { TooltipIndex, TooltipPayloadSearcher } from "./tooltipSlice"
|
|
4
|
+
import { isNan } from "../util/DataUtils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* These chart options are decided internally, by Recharts,
|
|
8
|
+
* and will not change during the lifetime of the chart.
|
|
9
|
+
*
|
|
10
|
+
* Changing these options can be done by swapping the root element
|
|
11
|
+
* which will make a brand-new store.
|
|
12
|
+
*
|
|
13
|
+
* If you want to store options that can be changed by the user,
|
|
14
|
+
* use UpdatableChartOptions in rootPropsSlice.ts.
|
|
15
|
+
*/
|
|
16
|
+
export type ChartOptions = {
|
|
17
|
+
chartName: string
|
|
18
|
+
defaultTooltipEventType: TooltipEventType
|
|
19
|
+
validateTooltipEventTypes?: ReadonlyArray<TooltipEventType>
|
|
20
|
+
tooltipPayloadSearcher: TooltipPayloadSearcher
|
|
21
|
+
/**
|
|
22
|
+
* We use this to identify which chart is sending events when synchronising.
|
|
23
|
+
* Without it, we can't tell the difference between an action that arrived from another chart
|
|
24
|
+
* and an action that was dispatched by the chart itself.
|
|
25
|
+
*/
|
|
26
|
+
eventEmitter: symbol | undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const arrayTooltipSearcher: TooltipPayloadSearcher = (
|
|
30
|
+
data: unknown,
|
|
31
|
+
strIndex: TooltipIndex,
|
|
32
|
+
): unknown | undefined => {
|
|
33
|
+
if (strIndex === null || strIndex === undefined) return undefined
|
|
34
|
+
if (!Array.isArray(data)) return undefined
|
|
35
|
+
const numIndex = Number.parseInt(strIndex, 10)
|
|
36
|
+
if (isNan(numIndex)) {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
return data[numIndex] as unknown
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const initialOptionsState: ChartOptions = {
|
|
43
|
+
chartName: "",
|
|
44
|
+
defaultTooltipEventType: "axis",
|
|
45
|
+
eventEmitter: undefined,
|
|
46
|
+
tooltipPayloadSearcher: () => undefined,
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AxisId, BaseCartesianAxis, TicksSettings } from "./cartesianAxisSlice"
|
|
2
|
+
|
|
3
|
+
export type RadiusAxisSettings = BaseCartesianAxis & TicksSettings
|
|
4
|
+
|
|
5
|
+
export type AngleAxisSettings = BaseCartesianAxis & TicksSettings
|
|
6
|
+
|
|
7
|
+
export type PolarAxisState = {
|
|
8
|
+
radiusAxis: Record<AxisId, RadiusAxisSettings>
|
|
9
|
+
angleAxis: Record<AxisId, AngleAxisSettings>
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type PolarChartOptions = {
|
|
2
|
+
cx: number | string
|
|
3
|
+
cy: number | string
|
|
4
|
+
endAngle: number
|
|
5
|
+
innerRadius: number | string
|
|
6
|
+
outerRadius: number | string
|
|
7
|
+
startAngle: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type PolarChartState = PolarChartOptions | null
|
|
11
|
+
|
|
12
|
+
export const initialPolarOptionsState: PolarChartState = null
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createStore, runWithOwner } from "solid-js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Marks chart data as a raw record so the chart store serves it by reference instead of
|
|
5
|
+
* wrapping every row in a proxy.
|
|
6
|
+
*
|
|
7
|
+
* Upstream treats chart data as immutable: a change replaces the whole array, and selectors
|
|
8
|
+
* compare it by reference. A deep store would instead track each row field a selector reads,
|
|
9
|
+
* so a derivation over N rows would subscribe to N × fields signals. A shallow store ingests
|
|
10
|
+
* its values as raw records (Solid's sticky raw contract), after which no store wraps them; the
|
|
11
|
+
* slot that holds the array still tracks replacement.
|
|
12
|
+
*
|
|
13
|
+
* Values that cannot be marked stay deep-tracked: proxies from a user store (Solid skips them),
|
|
14
|
+
* and raw objects that already back a deep store (Solid throws, and exposes no query for it).
|
|
15
|
+
*/
|
|
16
|
+
export function markRawData<T>(value: T): T {
|
|
17
|
+
if (value == null || typeof value !== "object") {
|
|
18
|
+
return value
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
runWithOwner(null, () => createStore({ value }, { shallow: true }))
|
|
22
|
+
} catch {
|
|
23
|
+
/* already backs a deep store: keep it deep-tracked */
|
|
24
|
+
}
|
|
25
|
+
return value
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AxisId } from "./cartesianAxisSlice"
|
|
2
|
+
import type { IfOverflow } from "../util/IfOverflow"
|
|
3
|
+
import type { ReferenceLineSegment } from "../cartesian/ReferenceLine"
|
|
4
|
+
|
|
5
|
+
export type ReferenceElementSettings = {
|
|
6
|
+
yAxisId: AxisId
|
|
7
|
+
xAxisId: AxisId
|
|
8
|
+
ifOverflow: IfOverflow
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ReferenceDotSettings = ReferenceElementSettings & {
|
|
12
|
+
x: unknown
|
|
13
|
+
y: unknown
|
|
14
|
+
r: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ReferenceAreaSettings = ReferenceElementSettings & {
|
|
18
|
+
x1: unknown
|
|
19
|
+
x2: unknown
|
|
20
|
+
y1: unknown
|
|
21
|
+
y2: unknown
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ReferenceLineSettings = ReferenceElementSettings & {
|
|
25
|
+
x: unknown
|
|
26
|
+
y: unknown
|
|
27
|
+
segment: ReferenceLineSegment | undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ReferenceElementState = {
|
|
31
|
+
dots: ReadonlyArray<ReferenceDotSettings>
|
|
32
|
+
areas: ReadonlyArray<ReferenceAreaSettings>
|
|
33
|
+
lines: ReadonlyArray<ReferenceLineSettings>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const initialReferenceElementsState: ReferenceElementState = {
|
|
37
|
+
areas: [],
|
|
38
|
+
dots: [],
|
|
39
|
+
lines: [],
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TickItem } from "../util/types"
|
|
2
|
+
import type { AxisId } from "./cartesianAxisSlice"
|
|
3
|
+
|
|
4
|
+
export type RenderedTicksAxisState = {
|
|
5
|
+
[axisId: AxisId]: ReadonlyArray<TickItem>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type RenderedTicksState = {
|
|
9
|
+
xAxis: RenderedTicksAxisState
|
|
10
|
+
yAxis: RenderedTicksAxisState
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createInitialRenderedTicksState(): RenderedTicksState {
|
|
14
|
+
return { xAxis: {}, yAxis: {} }
|
|
15
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { StackOffsetType } from "../util/types"
|
|
3
|
+
import { SyncMethod } from "../synchronisation/types"
|
|
4
|
+
import { BaseValue } from "../cartesian/Area"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* These are chart options that users can choose - which means they can also
|
|
8
|
+
* choose to change them which should trigger a re-render.
|
|
9
|
+
*/
|
|
10
|
+
export type UpdatableChartOptions = {
|
|
11
|
+
accessibilityLayer: boolean
|
|
12
|
+
barCategoryGap: number | string
|
|
13
|
+
barGap: number | string
|
|
14
|
+
barSize: string | number | undefined
|
|
15
|
+
baseValue: BaseValue | undefined
|
|
16
|
+
/**
|
|
17
|
+
* Useful for debugging which chart is which when synchronising.
|
|
18
|
+
* The className is also passed to the root element of the chart but that's done in the JSX, not through Redux.
|
|
19
|
+
*/
|
|
20
|
+
className: string | undefined
|
|
21
|
+
maxBarSize: number | undefined
|
|
22
|
+
/**
|
|
23
|
+
* If false, stacked items will be rendered left to right. If true, stacked items will be rendered right to left.
|
|
24
|
+
* (Render direction affects SVG layering, not x position.)
|
|
25
|
+
*/
|
|
26
|
+
reverseStackOrder: boolean
|
|
27
|
+
stackOffset: StackOffsetType
|
|
28
|
+
/**
|
|
29
|
+
* Charts that share the same syncId will have their Tooltip and Brush synchronised.
|
|
30
|
+
*/
|
|
31
|
+
syncId: number | string | undefined
|
|
32
|
+
syncMethod: SyncMethod
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const initialRootPropsState: UpdatableChartOptions = {
|
|
36
|
+
accessibilityLayer: true,
|
|
37
|
+
barCategoryGap: "10%",
|
|
38
|
+
barGap: 4,
|
|
39
|
+
barSize: undefined,
|
|
40
|
+
baseValue: undefined,
|
|
41
|
+
className: undefined,
|
|
42
|
+
maxBarSize: undefined,
|
|
43
|
+
reverseStackOrder: false,
|
|
44
|
+
stackOffset: "none",
|
|
45
|
+
syncId: undefined,
|
|
46
|
+
syncMethod: "index",
|
|
47
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import type { DataKey, NullableCoordinate } from "../../util/types"
|
|
3
|
+
import { computeArea } from "../../cartesian/Area"
|
|
4
|
+
import {
|
|
5
|
+
selectAxisWithScale,
|
|
6
|
+
selectStackGroups,
|
|
7
|
+
selectTicksOfGraphicalItem,
|
|
8
|
+
selectUnfilteredCartesianItems,
|
|
9
|
+
} from "./axisSelectors"
|
|
10
|
+
import type { ChartState } from "../store"
|
|
11
|
+
import type { AxisId, XAxisSettings, YAxisSettings } from "../cartesianAxisSlice"
|
|
12
|
+
import { selectChartLayout } from "../../context/chartLayoutContext"
|
|
13
|
+
import { selectChartDataWithIndexesIfNotInPanoramaPosition3 } from "./dataSelectors"
|
|
14
|
+
import { getBandSizeOfAxis, isCategoricalAxis, type StackId } from "../../util/ChartUtils"
|
|
15
|
+
import { isNotNil } from "../../util/DataUtils"
|
|
16
|
+
import type { ChartData } from "../chartDataSlice"
|
|
17
|
+
import { getStackSeriesIdentifier } from "../../util/stacks/getStackSeriesIdentifier"
|
|
18
|
+
import type {
|
|
19
|
+
StackDataPoint,
|
|
20
|
+
StackGroup,
|
|
21
|
+
StackSeries,
|
|
22
|
+
StackSeriesIdentifier,
|
|
23
|
+
} from "../../util/stacks/stackTypes"
|
|
24
|
+
import type { AreaSettings } from "../types/AreaSettings"
|
|
25
|
+
import type { GraphicalItemId } from "../graphicalItemsSlice"
|
|
26
|
+
import { selectChartBaseValue } from "./rootPropsSelectors"
|
|
27
|
+
import { chartSelector } from "./chartSelector"
|
|
28
|
+
import {
|
|
29
|
+
selectXAxisIdFromGraphicalItemId,
|
|
30
|
+
selectYAxisIdFromGraphicalItemId,
|
|
31
|
+
} from "./graphicalItemSelectors"
|
|
32
|
+
|
|
33
|
+
/** Optional overrides — bypass the axis-settings lookup on hot animation frames. */
|
|
34
|
+
export type AreaAxisOverrides = {
|
|
35
|
+
xAxis?: XAxisSettings
|
|
36
|
+
yAxis?: YAxisSettings
|
|
37
|
+
areaSettings?: AreaSettings
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AreaPointItem extends NullableCoordinate {
|
|
41
|
+
x: number | null
|
|
42
|
+
y: number | null
|
|
43
|
+
value?: ReadonlyArray<unknown>
|
|
44
|
+
payload?: unknown
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ComputedArea = {
|
|
48
|
+
points: ReadonlyArray<AreaPointItem>
|
|
49
|
+
baseLine: number | ReadonlyArray<AreaPointItem>
|
|
50
|
+
isRange: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const selectXAxisWithScale = chartSelector((
|
|
54
|
+
state: ChartState,
|
|
55
|
+
graphicalItemId: GraphicalItemId,
|
|
56
|
+
isPanorama: boolean,
|
|
57
|
+
override?: XAxisSettings,
|
|
58
|
+
) =>
|
|
59
|
+
selectAxisWithScale(
|
|
60
|
+
state,
|
|
61
|
+
"xAxis",
|
|
62
|
+
selectXAxisIdFromGraphicalItemId(state, graphicalItemId),
|
|
63
|
+
isPanorama,
|
|
64
|
+
override,
|
|
65
|
+
))
|
|
66
|
+
|
|
67
|
+
const selectXAxisTicks = chartSelector((
|
|
68
|
+
state: ChartState,
|
|
69
|
+
graphicalItemId: GraphicalItemId,
|
|
70
|
+
isPanorama: boolean,
|
|
71
|
+
) =>
|
|
72
|
+
selectTicksOfGraphicalItem(
|
|
73
|
+
state,
|
|
74
|
+
"xAxis",
|
|
75
|
+
selectXAxisIdFromGraphicalItemId(state, graphicalItemId),
|
|
76
|
+
isPanorama,
|
|
77
|
+
))
|
|
78
|
+
|
|
79
|
+
const selectYAxisWithScale = chartSelector((
|
|
80
|
+
state: ChartState,
|
|
81
|
+
graphicalItemId: GraphicalItemId,
|
|
82
|
+
isPanorama: boolean,
|
|
83
|
+
override?: YAxisSettings,
|
|
84
|
+
) =>
|
|
85
|
+
selectAxisWithScale(
|
|
86
|
+
state,
|
|
87
|
+
"yAxis",
|
|
88
|
+
selectYAxisIdFromGraphicalItemId(state, graphicalItemId),
|
|
89
|
+
isPanorama,
|
|
90
|
+
override,
|
|
91
|
+
))
|
|
92
|
+
|
|
93
|
+
const selectYAxisTicks = chartSelector((
|
|
94
|
+
state: ChartState,
|
|
95
|
+
graphicalItemId: GraphicalItemId,
|
|
96
|
+
isPanorama: boolean,
|
|
97
|
+
) =>
|
|
98
|
+
selectTicksOfGraphicalItem(
|
|
99
|
+
state,
|
|
100
|
+
"yAxis",
|
|
101
|
+
selectYAxisIdFromGraphicalItemId(state, graphicalItemId),
|
|
102
|
+
isPanorama,
|
|
103
|
+
))
|
|
104
|
+
|
|
105
|
+
const selectBandSize = chartSelector(function selectBandSize(state: ChartState, graphicalItemId: GraphicalItemId, isPanorama: boolean, overrides?: AreaAxisOverrides) {
|
|
106
|
+
const layout = selectChartLayout(state)
|
|
107
|
+
const xAxis = selectXAxisWithScale(state, graphicalItemId, isPanorama, overrides?.xAxis)
|
|
108
|
+
const yAxis = selectYAxisWithScale(state, graphicalItemId, isPanorama, overrides?.yAxis)
|
|
109
|
+
const xAxisTicks = selectXAxisTicks(state, graphicalItemId, isPanorama)
|
|
110
|
+
const yAxisTicks = selectYAxisTicks(state, graphicalItemId, isPanorama)
|
|
111
|
+
if (isCategoricalAxis(layout, "xAxis")) {
|
|
112
|
+
return getBandSizeOfAxis(xAxis, xAxisTicks, false)
|
|
113
|
+
}
|
|
114
|
+
return getBandSizeOfAxis(yAxis, yAxisTicks, false)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const selectSynchronisedAreaSettings = chartSelector(function selectSynchronisedAreaSettings(state: ChartState, id: GraphicalItemId): AreaSettings | undefined {
|
|
118
|
+
const graphicalItems = selectUnfilteredCartesianItems(state)
|
|
119
|
+
return graphicalItems.filter((item) => item.type === "area").find((item) => item.id === id) as
|
|
120
|
+
| AreaSettings
|
|
121
|
+
| undefined
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const selectNumericalAxisType = chartSelector((state: ChartState): "xAxis" | "yAxis" => {
|
|
125
|
+
const layout = selectChartLayout(state)
|
|
126
|
+
const isXAxisCategorical = isCategoricalAxis(layout, "xAxis")
|
|
127
|
+
return isXAxisCategorical ? "yAxis" : "xAxis"
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const selectNumericalAxisIdFromGraphicalItemId = chartSelector((
|
|
131
|
+
state: ChartState,
|
|
132
|
+
graphicalItemId: GraphicalItemId,
|
|
133
|
+
): AxisId => {
|
|
134
|
+
const axisType = selectNumericalAxisType(state)
|
|
135
|
+
if (axisType === "yAxis") {
|
|
136
|
+
return selectYAxisIdFromGraphicalItemId(state, graphicalItemId)
|
|
137
|
+
}
|
|
138
|
+
return selectXAxisIdFromGraphicalItemId(state, graphicalItemId)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const selectNumericalAxisStackGroups = chartSelector((
|
|
142
|
+
state: ChartState,
|
|
143
|
+
graphicalItemId: GraphicalItemId,
|
|
144
|
+
isPanorama: boolean,
|
|
145
|
+
): Record<StackId, StackGroup> | undefined =>
|
|
146
|
+
selectStackGroups(
|
|
147
|
+
state,
|
|
148
|
+
selectNumericalAxisType(state),
|
|
149
|
+
selectNumericalAxisIdFromGraphicalItemId(state, graphicalItemId),
|
|
150
|
+
isPanorama,
|
|
151
|
+
))
|
|
152
|
+
|
|
153
|
+
export const selectGraphicalItemStackedData = chartSelector(function selectGraphicalItemStackedData(state: ChartState, id: GraphicalItemId, isPanorama: boolean): ReadonlyArray<StackDataPoint> | undefined {
|
|
154
|
+
const areaSettings = selectSynchronisedAreaSettings(state, id)
|
|
155
|
+
const stackGroups = selectNumericalAxisStackGroups(state, id, isPanorama)
|
|
156
|
+
if (areaSettings == null || stackGroups == null) {
|
|
157
|
+
return undefined
|
|
158
|
+
}
|
|
159
|
+
const { stackId } = areaSettings
|
|
160
|
+
const stackSeriesIdentifier: StackSeriesIdentifier | undefined =
|
|
161
|
+
getStackSeriesIdentifier(areaSettings)
|
|
162
|
+
if (stackId == null || stackSeriesIdentifier == null) {
|
|
163
|
+
return undefined
|
|
164
|
+
}
|
|
165
|
+
const groups: ReadonlyArray<StackSeries> | undefined = stackGroups[stackId]?.stackedData
|
|
166
|
+
const found: StackSeries | undefined = groups?.find((v) => v.key === stackSeriesIdentifier)
|
|
167
|
+
if (found == null) {
|
|
168
|
+
return undefined
|
|
169
|
+
}
|
|
170
|
+
return found.map((item): StackDataPoint => [item[0], item[1]])
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
const selectStackDataKeys = chartSelector(function selectStackDataKeys(state: ChartState, id: GraphicalItemId, isPanorama: boolean): ReadonlyArray<DataKey<unknown>> | undefined {
|
|
174
|
+
const areaSettings = selectSynchronisedAreaSettings(state, id)
|
|
175
|
+
const stackGroups = selectNumericalAxisStackGroups(state, id, isPanorama)
|
|
176
|
+
if (areaSettings == null || areaSettings.stackId == null || stackGroups == null) {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
const group: StackGroup | undefined = stackGroups[areaSettings.stackId]
|
|
180
|
+
if (group == null) {
|
|
181
|
+
return undefined
|
|
182
|
+
}
|
|
183
|
+
return group.graphicalItems.map((item) => item.dataKey).filter(isNotNil)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
export const selectArea = chartSelector(function selectArea(state: ChartState, id: GraphicalItemId, isPanorama: boolean, overrides?: AreaAxisOverrides): ComputedArea | undefined {
|
|
187
|
+
const layout = selectChartLayout(state)
|
|
188
|
+
const xAxis = selectXAxisWithScale(state, id, isPanorama, overrides?.xAxis)
|
|
189
|
+
const yAxis = selectYAxisWithScale(state, id, isPanorama, overrides?.yAxis)
|
|
190
|
+
const xAxisTicks = selectXAxisTicks(state, id, isPanorama)
|
|
191
|
+
const yAxisTicks = selectYAxisTicks(state, id, isPanorama)
|
|
192
|
+
const stackedData = selectGraphicalItemStackedData(state, id, isPanorama)
|
|
193
|
+
const { chartData, dataStartIndex, dataEndIndex } =
|
|
194
|
+
selectChartDataWithIndexesIfNotInPanoramaPosition3(state, undefined, isPanorama)
|
|
195
|
+
const bandSize = selectBandSize(state, id, isPanorama, overrides)
|
|
196
|
+
const areaSettings = overrides?.areaSettings ?? selectSynchronisedAreaSettings(state, id)
|
|
197
|
+
const chartBaseValue = selectChartBaseValue(state)
|
|
198
|
+
const stackDataKeys = selectStackDataKeys(state, id, isPanorama)
|
|
199
|
+
|
|
200
|
+
if (
|
|
201
|
+
areaSettings == null ||
|
|
202
|
+
(layout !== "horizontal" && layout !== "vertical") ||
|
|
203
|
+
xAxis == null ||
|
|
204
|
+
yAxis == null ||
|
|
205
|
+
xAxisTicks == null ||
|
|
206
|
+
yAxisTicks == null ||
|
|
207
|
+
xAxisTicks.length === 0 ||
|
|
208
|
+
yAxisTicks.length === 0 ||
|
|
209
|
+
bandSize == null
|
|
210
|
+
) {
|
|
211
|
+
return undefined
|
|
212
|
+
}
|
|
213
|
+
const { data } = areaSettings
|
|
214
|
+
|
|
215
|
+
let displayedData: ChartData | undefined
|
|
216
|
+
if (data && data.length > 0) {
|
|
217
|
+
displayedData = data
|
|
218
|
+
} else {
|
|
219
|
+
displayedData = chartData?.slice(dataStartIndex, dataEndIndex + 1)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (displayedData == null) {
|
|
223
|
+
return undefined
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return computeArea({
|
|
227
|
+
areaSettings,
|
|
228
|
+
bandSize,
|
|
229
|
+
chartBaseValue,
|
|
230
|
+
dataStartIndex,
|
|
231
|
+
displayedData,
|
|
232
|
+
layout,
|
|
233
|
+
stackedData,
|
|
234
|
+
stackDataKeys,
|
|
235
|
+
xAxis,
|
|
236
|
+
xAxisTicks,
|
|
237
|
+
yAxis,
|
|
238
|
+
yAxisTicks,
|
|
239
|
+
})
|
|
240
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if two arrays are equal, treating empty arrays as equal regardless of reference.
|
|
3
|
+
* If both arrays are non-empty, it checks for reference equality.
|
|
4
|
+
* @param a
|
|
5
|
+
* @param b
|
|
6
|
+
*/
|
|
7
|
+
export function emptyArraysAreEqualCheck<T>(a: ReadonlyArray<T>, b: ReadonlyArray<T>): boolean {
|
|
8
|
+
if (Array.isArray(a) && Array.isArray(b) && a.length === 0 && b.length === 0) {
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
return a === b
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if two arrays have the same contents in the same order.
|
|
16
|
+
* @param a
|
|
17
|
+
* @param b
|
|
18
|
+
*/
|
|
19
|
+
export function arrayContentsAreEqualCheck<T>(a: ReadonlyArray<T>, b: ReadonlyArray<T>): boolean {
|
|
20
|
+
if (a.length === b.length) {
|
|
21
|
+
for (let i = 0; i < a.length; i++) {
|
|
22
|
+
if (a[i] !== b[i]) {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
return false
|
|
29
|
+
}
|