@octanejs/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 +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
package/src/hooks.js
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/hooks.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { defaultAxisId } from './state/cartesianAxisSlice';
|
|
4
|
+
import {
|
|
5
|
+
selectAxisDomain,
|
|
6
|
+
selectAxisInverseScale,
|
|
7
|
+
selectAxisInverseDataSnapScale,
|
|
8
|
+
selectAxisInverseTickSnapScale,
|
|
9
|
+
selectAxisScale,
|
|
10
|
+
selectAxisWithScale,
|
|
11
|
+
selectRenderedTicksOfAxis,
|
|
12
|
+
} from './state/selectors/axisSelectors';
|
|
13
|
+
import { useAppSelector } from './state/hooks';
|
|
14
|
+
import { useIsPanorama } from './context/PanoramaContext';
|
|
15
|
+
import {
|
|
16
|
+
selectActiveLabel,
|
|
17
|
+
selectActiveTooltipCoordinate,
|
|
18
|
+
selectActiveTooltipDataPoints,
|
|
19
|
+
selectIsTooltipActive,
|
|
20
|
+
} from './state/selectors/tooltipSelectors';
|
|
21
|
+
import { selectChartOffset } from './state/selectors/selectChartOffset';
|
|
22
|
+
import { selectPlotArea } from './state/selectors/selectPlotArea';
|
|
23
|
+
export var useXAxis = (xAxisId) => {
|
|
24
|
+
var isPanorama = useIsPanorama();
|
|
25
|
+
return useAppSelector((state) => selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama));
|
|
26
|
+
};
|
|
27
|
+
export var useYAxis = (yAxisId) => {
|
|
28
|
+
var isPanorama = useIsPanorama();
|
|
29
|
+
return useAppSelector((state) => selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A function that converts data values to pixel coordinates.
|
|
34
|
+
* @param value - The data value to convert (number, string, or category).
|
|
35
|
+
* @param options - Optional configuration for banded scales.
|
|
36
|
+
* @param options.position - Position within a band: 'start', 'middle', or 'end'.
|
|
37
|
+
* @returns The pixel coordinate, or `undefined` if the value is not in the domain.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A function that converts pixel coordinates back to data values.
|
|
42
|
+
* @param pixelValue - The pixel coordinate to convert.
|
|
43
|
+
* @returns The closest data value in the domain.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns a function to convert data values to pixel coordinates for an {@link XAxis}.
|
|
48
|
+
*
|
|
49
|
+
* This is useful for positioning annotations, custom shapes, or other elements
|
|
50
|
+
* at specific data points on the chart.
|
|
51
|
+
*
|
|
52
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
53
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const xScale = useXAxisScale();
|
|
58
|
+
* if (xScale) {
|
|
59
|
+
* const pixelX = xScale('Page A'); // Returns the pixel x-coordinate for 'Page A'
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @param xAxisId The `xAxisId` of the XAxis. Defaults to `0` if not provided.
|
|
64
|
+
* @returns A scale function that maps data values to pixel coordinates, or `undefined`.
|
|
65
|
+
* @since 3.8
|
|
66
|
+
*/
|
|
67
|
+
export var useXAxisScale = function useXAxisScale() {
|
|
68
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
69
|
+
var isPanorama = useIsPanorama();
|
|
70
|
+
var scale = useAppSelector((state) => selectAxisScale(state, 'xAxis', xAxisId, isPanorama));
|
|
71
|
+
return scale === null || scale === void 0 ? void 0 : scale.map;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns a function to convert data values to pixel coordinates for a {@link YAxis}.
|
|
76
|
+
*
|
|
77
|
+
* This is useful for positioning annotations, custom shapes, or other elements
|
|
78
|
+
* at specific data points on the chart.
|
|
79
|
+
*
|
|
80
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
81
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const yScale = useYAxisScale();
|
|
86
|
+
* if (yScale) {
|
|
87
|
+
* const pixelY = yScale(1500); // Returns the pixel y-coordinate for value 1500
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param yAxisId The `yAxisId` of the YAxis. Defaults to `0` if not provided.
|
|
92
|
+
* @returns A scale function that maps data values to pixel coordinates, or `undefined`.
|
|
93
|
+
* @since 3.8
|
|
94
|
+
*/
|
|
95
|
+
export var useYAxisScale = function useYAxisScale() {
|
|
96
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
97
|
+
var isPanorama = useIsPanorama();
|
|
98
|
+
var scale = useAppSelector((state) => selectAxisScale(state, 'yAxis', yAxisId, isPanorama));
|
|
99
|
+
return scale === null || scale === void 0 ? void 0 : scale.map;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns a function to convert pixel coordinates back to data values for an {@link XAxis}.
|
|
104
|
+
*
|
|
105
|
+
* This is useful for implementing interactions like click-to-add-annotation,
|
|
106
|
+
* drag interactions, or tooltips that need to determine what data point
|
|
107
|
+
* corresponds to a mouse position.
|
|
108
|
+
*
|
|
109
|
+
* For continuous (numerical) scales, returns an interpolated value.
|
|
110
|
+
* For categorical scales, returns the closest category in the domain - which is the same behaviour as {@link useXAxisInverseDataSnapScale}.
|
|
111
|
+
*
|
|
112
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
113
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```tsx
|
|
117
|
+
* const xInverseScale = useXAxisInverseScale();
|
|
118
|
+
* if (xInverseScale) {
|
|
119
|
+
* const dataValue = xInverseScale(150); // Returns the data value at pixel x=150
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @param xAxisId The `xAxisId` of the XAxis. Defaults to `0` if not provided.
|
|
124
|
+
* @returns An inverse scale function that maps pixel coordinates to data values, or `undefined`.
|
|
125
|
+
* @since 3.8
|
|
126
|
+
*/
|
|
127
|
+
export var useXAxisInverseScale = function useXAxisInverseScale() {
|
|
128
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
129
|
+
var isPanorama = useIsPanorama();
|
|
130
|
+
return useAppSelector((state) => selectAxisInverseScale(state, 'xAxis', xAxisId, isPanorama));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns a function to convert pixel coordinates back to data values for an {@link XAxis},
|
|
135
|
+
* but snapping to the closest data point.
|
|
136
|
+
*
|
|
137
|
+
* This is similar to {@link useXAxisInverseScale}, but instead of returning the exact data value
|
|
138
|
+
* at the pixel position (interpolation), it returns the value of the closest data point.
|
|
139
|
+
*
|
|
140
|
+
* This is useful for implementing interactions where you want to select the closest data point
|
|
141
|
+
* rather than an exact value or a tick.
|
|
142
|
+
*
|
|
143
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
144
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
145
|
+
*
|
|
146
|
+
* @param xAxisId The `xAxisId` of the XAxis. Defaults to `0` if not provided.
|
|
147
|
+
* @returns An inverse scale function that maps pixel coordinates to the closest data value, or `undefined`.
|
|
148
|
+
* @since 3.8
|
|
149
|
+
*/
|
|
150
|
+
export var useXAxisInverseDataSnapScale = function useXAxisInverseDataSnapScale() {
|
|
151
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
152
|
+
var isPanorama = useIsPanorama();
|
|
153
|
+
return useAppSelector((state) =>
|
|
154
|
+
selectAxisInverseDataSnapScale(state, 'xAxis', xAxisId, isPanorama),
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns a function to convert pixel coordinates back to data values for an {@link XAxis},
|
|
160
|
+
* but snapping to the closest axis tick.
|
|
161
|
+
*
|
|
162
|
+
* This is similar to {@link useXAxisInverseScale}, but instead of returning the exact data value
|
|
163
|
+
* at the pixel position (interpolation), it returns the value of the closest tick.
|
|
164
|
+
*
|
|
165
|
+
* This is useful for implementing interactions where you want to select the closest tick
|
|
166
|
+
* rather than an exact value or a data point.
|
|
167
|
+
*
|
|
168
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
169
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
170
|
+
*
|
|
171
|
+
* @param xAxisId The `xAxisId` of the XAxis. Defaults to `0` if not provided.
|
|
172
|
+
* @returns An inverse scale function that maps pixel coordinates to the closest tick value, or `undefined`.
|
|
173
|
+
* @since 3.8
|
|
174
|
+
*/
|
|
175
|
+
export var useXAxisInverseTickSnapScale = function useXAxisInverseTickSnapScale() {
|
|
176
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
177
|
+
return useAppSelector((state) => selectAxisInverseTickSnapScale(state, 'xAxis', xAxisId));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns a function to convert pixel coordinates back to data values for a {@link YAxis}.
|
|
182
|
+
*
|
|
183
|
+
* This is useful for implementing interactions like click-to-add-annotation,
|
|
184
|
+
* drag interactions, or tooltips that need to determine what data point
|
|
185
|
+
* corresponds to a mouse position.
|
|
186
|
+
*
|
|
187
|
+
* For continuous (numerical) scales, returns an interpolated value.
|
|
188
|
+
* For categorical scales, returns the closest category in the domain - which is the same behaviour as {@link useYAxisInverseDataSnapScale}.
|
|
189
|
+
*
|
|
190
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
191
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```tsx
|
|
195
|
+
* const yInverseScale = useYAxisInverseScale();
|
|
196
|
+
* if (yInverseScale) {
|
|
197
|
+
* const dataValue = yInverseScale(200); // Returns the data value at pixel y=200
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @param yAxisId The `yAxisId` of the YAxis. Defaults to `0` if not provided.
|
|
202
|
+
* @returns An inverse scale function that maps pixel coordinates to data values, or `undefined`.
|
|
203
|
+
* @since 3.8
|
|
204
|
+
*/
|
|
205
|
+
export var useYAxisInverseScale = function useYAxisInverseScale() {
|
|
206
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
207
|
+
var isPanorama = useIsPanorama();
|
|
208
|
+
return useAppSelector((state) => selectAxisInverseScale(state, 'yAxis', yAxisId, isPanorama));
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Returns a function to convert pixel coordinates back to data values for a {@link YAxis},
|
|
213
|
+
* but snapping to the closest data point.
|
|
214
|
+
*
|
|
215
|
+
* This is similar to {@link useYAxisInverseScale}, but instead of returning the exact data value
|
|
216
|
+
* at the pixel position (interpolation), it returns the value of the closest data point.
|
|
217
|
+
*
|
|
218
|
+
* This is useful for implementing interactions where you want to select the closest data point
|
|
219
|
+
* rather than an exact value or a tick.
|
|
220
|
+
*
|
|
221
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
222
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
223
|
+
*
|
|
224
|
+
* @param yAxisId The `yAxisId` of the YAxis. Defaults to `0` if not provided.
|
|
225
|
+
* @returns An inverse scale function that maps pixel coordinates to the closest data value, or `undefined`.
|
|
226
|
+
* @since 3.8
|
|
227
|
+
*/
|
|
228
|
+
export var useYAxisInverseDataSnapScale = function useYAxisInverseDataSnapScale() {
|
|
229
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
230
|
+
var isPanorama = useIsPanorama();
|
|
231
|
+
return useAppSelector((state) =>
|
|
232
|
+
selectAxisInverseDataSnapScale(state, 'yAxis', yAxisId, isPanorama),
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Returns a function to convert pixel coordinates back to data values for a {@link YAxis},
|
|
238
|
+
* but snapping to the closest axis tick.
|
|
239
|
+
*
|
|
240
|
+
* This is similar to {@link useYAxisInverseScale}, but instead of returning the exact data value
|
|
241
|
+
* at the pixel position (interpolation), it returns the value of the closest tick.
|
|
242
|
+
*
|
|
243
|
+
* This is useful for implementing interactions where you want to select the closest tick
|
|
244
|
+
* rather than an exact value or a data point.
|
|
245
|
+
*
|
|
246
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
247
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist.
|
|
248
|
+
*
|
|
249
|
+
* @param yAxisId The `yAxisId` of the YAxis. Defaults to `0` if not provided.
|
|
250
|
+
* @returns An inverse scale function that maps pixel coordinates to the closest tick value, or `undefined`.
|
|
251
|
+
* @since 3.8
|
|
252
|
+
*/
|
|
253
|
+
export var useYAxisInverseTickSnapScale = function useYAxisInverseTickSnapScale() {
|
|
254
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
255
|
+
return useAppSelector((state) => selectAxisInverseTickSnapScale(state, 'yAxis', yAxisId));
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns the ticks of an {@link XAxis}.
|
|
260
|
+
*
|
|
261
|
+
* This hook is useful for accessing the calculated ticks of an XAxis.
|
|
262
|
+
* The ticks are the same as the ones rendered by the XAxis component.
|
|
263
|
+
*
|
|
264
|
+
* @param xAxisId The `xAxisId` of the XAxis. Defaults to `0` if not provided.
|
|
265
|
+
* @returns An array of ticks, or `undefined` if the axis doesn't exist or hasn't been calculated yet.
|
|
266
|
+
* @since 3.8
|
|
267
|
+
*/
|
|
268
|
+
export var useXAxisTicks = function useXAxisTicks() {
|
|
269
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
270
|
+
return useAppSelector((state) => selectRenderedTicksOfAxis(state, 'xAxis', xAxisId));
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Returns the ticks of a {@link YAxis}.
|
|
275
|
+
*
|
|
276
|
+
* This hook is useful for accessing the calculated ticks of a YAxis.
|
|
277
|
+
* The ticks are the same as the ones rendered by the YAxis component.
|
|
278
|
+
*
|
|
279
|
+
* @param yAxisId The `yAxisId` of the YAxis. Defaults to `0` if not provided.
|
|
280
|
+
* @returns An array of ticks, or `undefined` if the axis doesn't exist or hasn't been calculated yet.
|
|
281
|
+
* @since 3.8
|
|
282
|
+
*/
|
|
283
|
+
export var useYAxisTicks = function useYAxisTicks() {
|
|
284
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
285
|
+
return useAppSelector((state) => selectRenderedTicksOfAxis(state, 'yAxis', yAxisId));
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Data point with x and y values that can be converted to pixel coordinates.
|
|
290
|
+
* The x and y values should be in the same format as your chart data.
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Converts a data point (in data coordinates) to pixel coordinates.
|
|
295
|
+
*
|
|
296
|
+
* This hook is useful for positioning annotations, custom shapes, or other elements
|
|
297
|
+
* at specific data points on the chart. It uses the axis scales to convert
|
|
298
|
+
* data values to their corresponding pixel positions within the chart area.
|
|
299
|
+
*
|
|
300
|
+
* This hook must be used within a chart context (inside a {@link LineChart}, {@link BarChart}, etc.).
|
|
301
|
+
* Returns `undefined` if used outside a chart context, or if the axes don't exist, or if the data point
|
|
302
|
+
* cannot be converted (e.g., if the data values are outside the axis domains).
|
|
303
|
+
*
|
|
304
|
+
* This is a convenience hook that combines {@link useXAxisScale} and {@link useYAxisScale} together in a single call.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```tsx
|
|
308
|
+
* // Position a marker at data point { x: 'Page C', y: 2500 }
|
|
309
|
+
* const pixelCoords = useCartesianScale({ x: 'Page C', y: 2500 });
|
|
310
|
+
* if (pixelCoords) {
|
|
311
|
+
* return <circle cx={pixelCoords.x} cy={pixelCoords.y} r={5} fill="red" />;
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @param dataPoint The data point with x and y values in data coordinates.
|
|
316
|
+
* @param xAxisId The `xAxisId` of the X-axis. Defaults to `0` if not provided.
|
|
317
|
+
* @param yAxisId The `yAxisId` of the Y-axis. Defaults to `0` if not provided.
|
|
318
|
+
* @returns The pixel x,y coordinates, or `undefined` if conversion is not possible.
|
|
319
|
+
* @since 3.8
|
|
320
|
+
*/
|
|
321
|
+
export var useCartesianScale = function useCartesianScale(dataPoint) {
|
|
322
|
+
var xAxisId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultAxisId;
|
|
323
|
+
var yAxisId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultAxisId;
|
|
324
|
+
var xScale = useXAxisScale(xAxisId);
|
|
325
|
+
var yScale = useYAxisScale(yAxisId);
|
|
326
|
+
if (xScale == null || yScale == null) {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
var pixelX = xScale(dataPoint.x);
|
|
330
|
+
var pixelY = yScale(dataPoint.y);
|
|
331
|
+
if (pixelX == null || pixelY == null) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
x: pixelX,
|
|
336
|
+
y: pixelY,
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Returns the active tooltip label. The label is one of the values from the chart data,
|
|
342
|
+
* and is used to display in the tooltip content.
|
|
343
|
+
*
|
|
344
|
+
* Returns undefined if there is no active user interaction or if used outside a chart context
|
|
345
|
+
*
|
|
346
|
+
* @returns ActiveLabel
|
|
347
|
+
* @since 3.0
|
|
348
|
+
*/
|
|
349
|
+
export var useActiveTooltipLabel = () => {
|
|
350
|
+
return useAppSelector(selectActiveLabel);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Returns the offset of the chart in pixels.
|
|
355
|
+
*
|
|
356
|
+
* Offset defines the blank space between the chart and the plot area.
|
|
357
|
+
* This blank space is occupied by supporting elements like axes, legends, and brushes.
|
|
358
|
+
*
|
|
359
|
+
* The offset includes:
|
|
360
|
+
*
|
|
361
|
+
* - Margins
|
|
362
|
+
* - Width and height of the axes
|
|
363
|
+
* - Width and height of the legend
|
|
364
|
+
* - Brush height
|
|
365
|
+
*
|
|
366
|
+
* If you are interested in the margin alone, use {@link useMargin} instead.
|
|
367
|
+
*
|
|
368
|
+
* The offset is independent of charts position on the page, meaning it does not change as the chart is scrolled or resized.
|
|
369
|
+
*
|
|
370
|
+
* It is also independent of the scale and zoom, meaning that as the user zooms in and out,
|
|
371
|
+
* the numbers will not change as the chart gets visually larger or smaller.
|
|
372
|
+
*
|
|
373
|
+
* This hook must be used within a chart context (inside a `<LineChart>`, `<BarChart>`, etc.).
|
|
374
|
+
* This hook returns `undefined` if used outside a chart context.
|
|
375
|
+
*
|
|
376
|
+
* @returns Offset of the chart in pixels, or undefined if used outside a chart context.
|
|
377
|
+
* @since 3.1
|
|
378
|
+
*/
|
|
379
|
+
export var useOffset = () => {
|
|
380
|
+
return useAppSelector(selectChartOffset);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Plot area is the area where the actual chart data is rendered.
|
|
385
|
+
* This means: bars, lines, scatter points, etc.
|
|
386
|
+
*
|
|
387
|
+
* The plot area is calculated based on the chart dimensions and the offset.
|
|
388
|
+
*
|
|
389
|
+
* Plot area `width` and `height` are the dimensions in pixels;
|
|
390
|
+
* `x` and `y` are the coordinates of the top-left corner of the plot area relative to the chart container.
|
|
391
|
+
*
|
|
392
|
+
* They are also independent of the scale and zoom, meaning that as the user zooms in and out,
|
|
393
|
+
* the plot area dimensions will not change as the chart gets visually larger or smaller.
|
|
394
|
+
*
|
|
395
|
+
* This hook must be used within a chart context (inside a `<LineChart>`, `<BarChart>`, etc.).
|
|
396
|
+
* This hook returns `undefined` if used outside a chart context.
|
|
397
|
+
*
|
|
398
|
+
* @returns Plot area of the chart in pixels, or undefined if used outside a chart context.
|
|
399
|
+
* @since 3.1
|
|
400
|
+
*/
|
|
401
|
+
export var usePlotArea = () => {
|
|
402
|
+
return useAppSelector(selectPlotArea);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Returns the currently active data points being displayed in the Tooltip.
|
|
407
|
+
* Active means that it is currently visible; this hook will return `undefined` if there is no current interaction.
|
|
408
|
+
*
|
|
409
|
+
* This follows the `<Tooltip />` props, if the Tooltip element is present in the chart.
|
|
410
|
+
* If there is no `<Tooltip />` then this hook will follow the default Tooltip props.
|
|
411
|
+
*
|
|
412
|
+
* Data point is whatever you pass as an input to the chart using the `data={}` prop.
|
|
413
|
+
*
|
|
414
|
+
* This returns an array because a chart can have multiple graphical items in it (multiple Lines for example)
|
|
415
|
+
* and tooltip with `shared={true}` will display all items at the same time.
|
|
416
|
+
*
|
|
417
|
+
* Returns undefined when used outside a chart context.
|
|
418
|
+
*
|
|
419
|
+
* @returns Data points that are currently visible in a Tooltip
|
|
420
|
+
*
|
|
421
|
+
* @since 3.1
|
|
422
|
+
*/
|
|
423
|
+
export var useActiveTooltipDataPoints = () => {
|
|
424
|
+
return useAppSelector(selectActiveTooltipDataPoints);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Returns the calculated domain of an X-axis.
|
|
429
|
+
*
|
|
430
|
+
* The domain can be numerical: `[min, max]`, or categorical: `['a', 'b', 'c']`.
|
|
431
|
+
*
|
|
432
|
+
* The type of the domain is defined by the `type` prop of the XAxis.
|
|
433
|
+
*
|
|
434
|
+
* The values of the domain are calculated based on the data and the `dataKey` of the axis.
|
|
435
|
+
*
|
|
436
|
+
* If the chart has a Brush, the domain will be filtered to the brushed indexes if the hook is used outside a Brush context,
|
|
437
|
+
* and the full domain will be returned if the hook is used inside a Brush context.
|
|
438
|
+
*
|
|
439
|
+
* @param xAxisId The `xAxisId` of the X-axis. Defaults to `0` if not provided.
|
|
440
|
+
* @returns The domain of the X-axis, or `undefined` if it cannot be calculated or if used outside a chart context.
|
|
441
|
+
* @since 3.2
|
|
442
|
+
*/
|
|
443
|
+
export var useXAxisDomain = function useXAxisDomain() {
|
|
444
|
+
var xAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
445
|
+
var isPanorama = useIsPanorama();
|
|
446
|
+
return useAppSelector((state) => selectAxisDomain(state, 'xAxis', xAxisId, isPanorama));
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Returns the calculated domain of a Y-axis.
|
|
451
|
+
*
|
|
452
|
+
* The domain can be numerical: `[min, max]`, or categorical: `['a', 'b', 'c']`.
|
|
453
|
+
*
|
|
454
|
+
* The type of the domain is defined by the `type` prop of the YAxis.
|
|
455
|
+
*
|
|
456
|
+
* The values of the domain are calculated based on the data and the `dataKey` of the axis.
|
|
457
|
+
*
|
|
458
|
+
* Does not interact with Brushes, as Y-axes do not support brushing.
|
|
459
|
+
*
|
|
460
|
+
* @param yAxisId The `yAxisId` of the Y-axis. Defaults to `0` if not provided.
|
|
461
|
+
* @returns The domain of the Y-axis, or `undefined` if it cannot be calculated or if used outside a chart context.
|
|
462
|
+
* @since 3.2
|
|
463
|
+
*/
|
|
464
|
+
export var useYAxisDomain = function useYAxisDomain() {
|
|
465
|
+
var yAxisId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultAxisId;
|
|
466
|
+
var isPanorama = useIsPanorama();
|
|
467
|
+
return useAppSelector((state) => selectAxisDomain(state, 'yAxis', yAxisId, isPanorama));
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Returns true if the {@link Tooltip} is currently active (visible).
|
|
472
|
+
*
|
|
473
|
+
* Returns false if the Tooltip is not active or if used outside a chart context.
|
|
474
|
+
*
|
|
475
|
+
* Recharts only allows one Tooltip per chart, so this hook does not take any parameters.
|
|
476
|
+
* Weird things may happen if you have multiple Tooltip components in the same chart so please don't do that.
|
|
477
|
+
*
|
|
478
|
+
* @returns {boolean} True if the Tooltip is active, false otherwise.
|
|
479
|
+
* @since 3.7
|
|
480
|
+
*/
|
|
481
|
+
export var useIsTooltipActive = () => {
|
|
482
|
+
var _useAppSelector;
|
|
483
|
+
return (_useAppSelector = useAppSelector(selectIsTooltipActive)) !== null &&
|
|
484
|
+
_useAppSelector !== void 0
|
|
485
|
+
? _useAppSelector
|
|
486
|
+
: false;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Returns the Cartesian `x` + `y` coordinates of the active {@link Tooltip}.
|
|
491
|
+
*
|
|
492
|
+
* Returns undefined if there is no active user interaction or if used outside a chart context.
|
|
493
|
+
*
|
|
494
|
+
* Recharts only allows one Tooltip per chart, so this hook does not take any parameters.
|
|
495
|
+
* Weird things may happen if you have multiple Tooltip components in the same chart so please don't do that.
|
|
496
|
+
*
|
|
497
|
+
* @returns {Coordinate | undefined} The coordinate of the active Tooltip, or undefined.
|
|
498
|
+
* @since 3.7
|
|
499
|
+
*/
|
|
500
|
+
export var useActiveTooltipCoordinate = () => {
|
|
501
|
+
var coordinate = useAppSelector(selectActiveTooltipCoordinate);
|
|
502
|
+
if (coordinate == null) {
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
x: coordinate.x,
|
|
507
|
+
y: coordinate.y,
|
|
508
|
+
};
|
|
509
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @octanejs/recharts — Recharts for the octane renderer.
|
|
2
|
+
//
|
|
3
|
+
// Recharts 3 splits cleanly along the same seam as the other octane bindings:
|
|
4
|
+
// its chart STATE is framework-agnostic (Redux Toolkit slices + reselect
|
|
5
|
+
// selectors; d3 math via victory-vendor; es-toolkit utilities) and its React
|
|
6
|
+
// layer is components + hooks over an isolated redux store. This package
|
|
7
|
+
// MIRRORS upstream's file layout under src/: framework-agnostic modules are
|
|
8
|
+
// vendored verbatim (`.js`, marked with a "Vendored verbatim" header) and the
|
|
9
|
+
// React layer is re-implemented on octane (`.ts`/`.tsrx`) at the same paths —
|
|
10
|
+
// so upstream's relative imports resolve unchanged, vendored or ported.
|
|
11
|
+
// The store runs through @octanejs/redux.
|
|
12
|
+
//
|
|
13
|
+
// Port status: Phase 1 (static BarChart + LineChart pipeline) — see
|
|
14
|
+
// docs/recharts-port-plan.md for the phase map.
|
|
15
|
+
export { Surface } from './container/Surface.tsrx';
|
|
16
|
+
export { Layer } from './container/Layer.tsrx';
|
|
17
|
+
export { Cell } from './component/Cell';
|
|
18
|
+
export { Rectangle } from './shape/Rectangle.tsrx';
|
|
19
|
+
export { Dot } from './shape/Dot.tsrx';
|
|
20
|
+
export { Cross } from './shape/Cross.tsrx';
|
|
21
|
+
export { Polygon } from './shape/Polygon.tsrx';
|
|
22
|
+
export { Curve } from './shape/Curve.tsrx';
|
|
23
|
+
export { Sector } from './shape/Sector.tsrx';
|
|
24
|
+
export { Symbols } from './shape/Symbols.tsrx';
|
|
25
|
+
export { Trapezoid } from './shape/Trapezoid.tsrx';
|
|
26
|
+
|
|
27
|
+
// Phase 1 — the static cartesian pipeline.
|
|
28
|
+
export { BarChart } from './chart/BarChart.tsrx';
|
|
29
|
+
export { LineChart } from './chart/LineChart.tsrx';
|
|
30
|
+
export { CartesianChart } from './chart/CartesianChart.tsrx';
|
|
31
|
+
export { Bar } from './cartesian/Bar.tsrx';
|
|
32
|
+
export { Line } from './cartesian/Line.tsrx';
|
|
33
|
+
export { XAxis } from './cartesian/XAxis.tsrx';
|
|
34
|
+
export { YAxis } from './cartesian/YAxis.tsrx';
|
|
35
|
+
export { CartesianAxis } from './cartesian/CartesianAxis.tsrx';
|
|
36
|
+
export { BarStack } from './cartesian/BarStack.tsrx';
|
|
37
|
+
export { LineDrawShape } from './cartesian/LineDrawShape.tsrx';
|
|
38
|
+
export { Text } from './component/Text.tsrx';
|
|
39
|
+
export { Label } from './component/Label.tsrx';
|
|
40
|
+
export { LabelList } from './component/LabelList.tsrx';
|
|
41
|
+
export { ZIndexLayer } from './zIndex/ZIndexLayer.tsrx';
|
|
42
|
+
export { AnimationControllerProvider } from './animation/useAnimationController';
|
|
43
|
+
export {
|
|
44
|
+
useChartWidth,
|
|
45
|
+
useChartHeight,
|
|
46
|
+
useMargin,
|
|
47
|
+
useChartLayout,
|
|
48
|
+
useCartesianChartLayout,
|
|
49
|
+
usePolarChartLayout,
|
|
50
|
+
useIsInChartContext,
|
|
51
|
+
useViewBox,
|
|
52
|
+
} from './context/chartLayoutContext';
|
|
53
|
+
export {
|
|
54
|
+
useXAxis,
|
|
55
|
+
useYAxis,
|
|
56
|
+
useXAxisScale,
|
|
57
|
+
useYAxisScale,
|
|
58
|
+
useXAxisInverseScale,
|
|
59
|
+
useYAxisInverseScale,
|
|
60
|
+
useOffset,
|
|
61
|
+
usePlotArea,
|
|
62
|
+
useActiveTooltipLabel,
|
|
63
|
+
useActiveTooltipDataPoints,
|
|
64
|
+
} from './hooks';
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Slot mechanics shared by the binding's plain-`.ts` hooks (same helper as
|
|
2
|
+
// @octanejs/tanstack-query). The octane compiler injects a per-call-site Symbol slot into
|
|
3
|
+
// every hook call in compiled files; these binding files are NOT compiled, so a
|
|
4
|
+
// hook here receives the caller's slot as its trailing argument and derives a
|
|
5
|
+
// distinct sub-slot for each base hook it composes.
|
|
6
|
+
|
|
7
|
+
// Memoized: subSlot runs on EVERY hook call every render; the cache returns the
|
|
8
|
+
// identical Symbol.for-interned value without the concat + registry lookup.
|
|
9
|
+
const subSlotCache = new Map<symbol, Map<string, symbol>>();
|
|
10
|
+
// Tag-only symbols for the slotless-caller case (see below).
|
|
11
|
+
const bareTagCache = new Map<string, symbol>();
|
|
12
|
+
|
|
13
|
+
export function subSlot(slot: symbol | undefined, tag: string): symbol {
|
|
14
|
+
// No inherited slot (the caller was NOT compiled — e.g. a vendored wrapper
|
|
15
|
+
// hook): return a stable TAG-ONLY symbol rather than undefined. The runtime
|
|
16
|
+
// combines it with the ambient withSlot path, so sibling base hooks inside
|
|
17
|
+
// one composed hook stay DISTINCT per tag. Returning undefined here made
|
|
18
|
+
// them all resolve to the bare path — one shared slot, state collision.
|
|
19
|
+
if (slot === undefined) {
|
|
20
|
+
let bare = bareTagCache.get(tag);
|
|
21
|
+
if (bare === undefined) bareTagCache.set(tag, (bare = Symbol.for(':' + tag)));
|
|
22
|
+
return bare;
|
|
23
|
+
}
|
|
24
|
+
let byTag = subSlotCache.get(slot);
|
|
25
|
+
if (byTag === undefined) subSlotCache.set(slot, (byTag = new Map()));
|
|
26
|
+
let sym = byTag.get(tag);
|
|
27
|
+
if (sym === undefined) byTag.set(tag, (sym = Symbol.for((slot.description ?? '') + ':' + tag)));
|
|
28
|
+
return sym;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Split the compiler-injected trailing slot off a hook's runtime args, returning
|
|
32
|
+
// the user args (everything before it) and the slot.
|
|
33
|
+
export function splitSlot(args: any[]): [any[], symbol | undefined] {
|
|
34
|
+
const tail = args[args.length - 1];
|
|
35
|
+
const slot = typeof tail === 'symbol' ? (tail as symbol) : undefined;
|
|
36
|
+
return [slot !== undefined ? args.slice(0, -1) : args, slot];
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/polar/defaultPolarAngleAxisProps.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
4
|
+
export var defaultPolarAngleAxisProps = {
|
|
5
|
+
allowDecimals: false,
|
|
6
|
+
allowDuplicatedCategory: true,
|
|
7
|
+
// if I set this to false then Tooltip synchronisation stops working in Radar, wtf
|
|
8
|
+
allowDataOverflow: false,
|
|
9
|
+
angle: 0,
|
|
10
|
+
angleAxisId: 0,
|
|
11
|
+
axisLine: true,
|
|
12
|
+
axisLineType: 'polygon',
|
|
13
|
+
cx: 0,
|
|
14
|
+
cy: 0,
|
|
15
|
+
hide: false,
|
|
16
|
+
includeHidden: false,
|
|
17
|
+
label: false,
|
|
18
|
+
niceTicks: 'auto',
|
|
19
|
+
orientation: 'outer',
|
|
20
|
+
reversed: false,
|
|
21
|
+
scale: 'auto',
|
|
22
|
+
tick: true,
|
|
23
|
+
tickLine: true,
|
|
24
|
+
tickSize: 8,
|
|
25
|
+
type: 'auto',
|
|
26
|
+
zIndex: DefaultZIndexes.axis,
|
|
27
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/polar/defaultPolarRadiusAxisProps.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
4
|
+
export var defaultPolarRadiusAxisProps = {
|
|
5
|
+
allowDataOverflow: false,
|
|
6
|
+
allowDecimals: false,
|
|
7
|
+
allowDuplicatedCategory: true,
|
|
8
|
+
angle: 0,
|
|
9
|
+
axisLine: true,
|
|
10
|
+
includeHidden: false,
|
|
11
|
+
hide: false,
|
|
12
|
+
niceTicks: 'auto',
|
|
13
|
+
label: false,
|
|
14
|
+
orientation: 'right',
|
|
15
|
+
radiusAxisId: 0,
|
|
16
|
+
reversed: false,
|
|
17
|
+
scale: 'auto',
|
|
18
|
+
stroke: '#ccc',
|
|
19
|
+
tick: true,
|
|
20
|
+
tickCount: 5,
|
|
21
|
+
tickLine: true,
|
|
22
|
+
type: 'auto',
|
|
23
|
+
zIndex: DefaultZIndexes.axis,
|
|
24
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Port of shape/Cross.tsx — the axis-cursor crosshair (a vertical + horizontal
|
|
2
|
+
// line pair as one path).
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { isNumber } from '../util/DataUtils';
|
|
5
|
+
import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents.ts';
|
|
6
|
+
|
|
7
|
+
function getPath(x, y, width, height, top, left) {
|
|
8
|
+
return 'M' + x + ',' + top + 'v' + height + 'M' + left + ',' + y + 'h' + width;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Cross(crossProps) {
|
|
12
|
+
const { x = 0, y = 0, top = 0, left = 0, width = 0, height = 0, className, ...rest } = crossProps;
|
|
13
|
+
const props = { x, y, top, left, width, height, ...rest };
|
|
14
|
+
if (
|
|
15
|
+
!isNumber(x) || !isNumber(y) || !isNumber(width) || !isNumber(height) || !isNumber(top) ||
|
|
16
|
+
!isNumber(left)
|
|
17
|
+
) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return <path
|
|
21
|
+
{...svgPropertiesAndEvents(props)}
|
|
22
|
+
className={clsx('recharts-cross', className)}
|
|
23
|
+
d={getPath(x, y, width, height, top, left)}
|
|
24
|
+
/>;
|
|
25
|
+
}
|