@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.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +53 -0
  3. package/src/animation/AnimatedItems.tsrx +82 -0
  4. package/src/animation/AnimationControllerImpl.js +33 -0
  5. package/src/animation/AnimationHandle.js +291 -0
  6. package/src/animation/JavascriptAnimate.tsrx +81 -0
  7. package/src/animation/easing.js +193 -0
  8. package/src/animation/matchBy.js +279 -0
  9. package/src/animation/timeoutController.js +49 -0
  10. package/src/animation/useAnimationController.ts +22 -0
  11. package/src/animation/useAnimationStartSnapshot.ts +43 -0
  12. package/src/animation/util.js +11 -0
  13. package/src/cartesian/Bar.ts +4 -0
  14. package/src/cartesian/Bar.tsrx +716 -0
  15. package/src/cartesian/Bar.tsrx.d.ts +4 -0
  16. package/src/cartesian/BarStack.tsrx +97 -0
  17. package/src/cartesian/BarStack.tsrx.d.ts +6 -0
  18. package/src/cartesian/CartesianAxis.tsrx +413 -0
  19. package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
  20. package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
  21. package/src/cartesian/Line.ts +4 -0
  22. package/src/cartesian/Line.tsrx +544 -0
  23. package/src/cartesian/Line.tsrx.d.ts +4 -0
  24. package/src/cartesian/LineDrawShape.tsrx +106 -0
  25. package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
  26. package/src/cartesian/XAxis.tsrx +156 -0
  27. package/src/cartesian/XAxis.tsrx.d.ts +3 -0
  28. package/src/cartesian/YAxis.tsrx +183 -0
  29. package/src/cartesian/YAxis.tsrx.d.ts +3 -0
  30. package/src/cartesian/getCartesianPosition.js +277 -0
  31. package/src/cartesian/getEquidistantTicks.js +133 -0
  32. package/src/cartesian/getTicks.js +280 -0
  33. package/src/cartesian/useAnimatedLineLength.ts +33 -0
  34. package/src/chart/BarChart.tsrx +22 -0
  35. package/src/chart/BarChart.tsrx.d.ts +2 -0
  36. package/src/chart/CartesianChart.tsrx +76 -0
  37. package/src/chart/CartesianChart.tsrx.d.ts +10 -0
  38. package/src/chart/CategoricalChart.tsrx +54 -0
  39. package/src/chart/LineChart.tsrx +22 -0
  40. package/src/chart/LineChart.tsrx.d.ts +2 -0
  41. package/src/chart/RechartsWrapper.tsrx +294 -0
  42. package/src/component/ActivePoints.tsrx +76 -0
  43. package/src/component/Cell.ts +37 -0
  44. package/src/component/Dots.tsrx +74 -0
  45. package/src/component/Label.tsrx +309 -0
  46. package/src/component/Label.tsrx.d.ts +12 -0
  47. package/src/component/LabelList.tsrx +83 -0
  48. package/src/component/LabelList.tsrx.d.ts +8 -0
  49. package/src/component/ResponsiveContainer.ts +22 -0
  50. package/src/component/Text.tsrx +281 -0
  51. package/src/component/Text.tsrx.d.ts +9 -0
  52. package/src/component/responsiveContainerUtils.js +111 -0
  53. package/src/container/ClipPathProvider.tsrx +29 -0
  54. package/src/container/Layer.tsrx +9 -0
  55. package/src/container/Layer.tsrx.d.ts +6 -0
  56. package/src/container/RootSurface.tsrx +76 -0
  57. package/src/container/Surface.tsrx +23 -0
  58. package/src/container/Surface.tsrx.d.ts +12 -0
  59. package/src/context/CellsContext.ts +80 -0
  60. package/src/context/ErrorBarContext.tsrx +53 -0
  61. package/src/context/PanoramaContext.ts +10 -0
  62. package/src/context/RegisterGraphicalItemId.tsrx +19 -0
  63. package/src/context/accessibilityContext.js +10 -0
  64. package/src/context/chartDataContext.ts +57 -0
  65. package/src/context/chartLayoutContext.ts +171 -0
  66. package/src/context/legendPortalContext.ts +5 -0
  67. package/src/context/tooltipContext.js +55 -0
  68. package/src/context/tooltipPortalContext.ts +5 -0
  69. package/src/hooks.js +509 -0
  70. package/src/index.ts +64 -0
  71. package/src/internal.ts +37 -0
  72. package/src/polar/defaultPolarAngleAxisProps.js +27 -0
  73. package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
  74. package/src/shape/Cross.tsrx +25 -0
  75. package/src/shape/Cross.tsrx.d.ts +12 -0
  76. package/src/shape/Curve.tsrx +132 -0
  77. package/src/shape/Curve.tsrx.d.ts +42 -0
  78. package/src/shape/Dot.tsrx +21 -0
  79. package/src/shape/Dot.tsrx.d.ts +9 -0
  80. package/src/shape/Polygon.tsrx +95 -0
  81. package/src/shape/Polygon.tsrx.d.ts +13 -0
  82. package/src/shape/Rectangle.tsrx +162 -0
  83. package/src/shape/Rectangle.tsrx.d.ts +31 -0
  84. package/src/shape/Sector.tsrx +219 -0
  85. package/src/shape/Sector.tsrx.d.ts +29 -0
  86. package/src/shape/Symbols.tsrx +95 -0
  87. package/src/shape/Symbols.tsrx.d.ts +15 -0
  88. package/src/shape/Trapezoid.tsrx +56 -0
  89. package/src/shape/Trapezoid.tsrx.d.ts +29 -0
  90. package/src/state/RechartsReduxContext.ts +7 -0
  91. package/src/state/RechartsStoreProvider.tsrx +24 -0
  92. package/src/state/ReportChartProps.ts +13 -0
  93. package/src/state/ReportEventSettings.ts +15 -0
  94. package/src/state/ReportMainChartProps.ts +22 -0
  95. package/src/state/SetGraphicalItem.ts +61 -0
  96. package/src/state/SetLegendPayload.ts +61 -0
  97. package/src/state/SetTooltipEntrySettings.ts +40 -0
  98. package/src/state/brushSlice.js +36 -0
  99. package/src/state/cartesianAxisSlice.js +256 -0
  100. package/src/state/chartDataSlice.js +67 -0
  101. package/src/state/errorBarSlice.js +53 -0
  102. package/src/state/eventSettingsSlice.js +25 -0
  103. package/src/state/externalEventsMiddleware.js +127 -0
  104. package/src/state/graphicalItemsSlice.js +91 -0
  105. package/src/state/hooks.ts +46 -0
  106. package/src/state/keyboardEventsMiddleware.js +226 -0
  107. package/src/state/layoutSlice.js +57 -0
  108. package/src/state/legendSlice.js +83 -0
  109. package/src/state/mouseEventsMiddleware.js +130 -0
  110. package/src/state/optionsSlice.js +45 -0
  111. package/src/state/polarAxisSlice.js +33 -0
  112. package/src/state/polarOptionsSlice.js +26 -0
  113. package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
  114. package/src/state/referenceElementsSlice.js +51 -0
  115. package/src/state/renderedTicksSlice.js +41 -0
  116. package/src/state/rootPropsSlice.js +48 -0
  117. package/src/state/selectors/arrayEqualityCheck.js +32 -0
  118. package/src/state/selectors/axisSelectors.js +2113 -0
  119. package/src/state/selectors/barSelectors.js +263 -0
  120. package/src/state/selectors/barStackSelectors.js +65 -0
  121. package/src/state/selectors/brushSelectors.js +21 -0
  122. package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
  123. package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
  124. package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
  125. package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
  126. package/src/state/selectors/combiners/combineBarPosition.js +17 -0
  127. package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
  128. package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
  129. package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
  130. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
  131. package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
  132. package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
  133. package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
  134. package/src/state/selectors/combiners/combineStackedData.js +22 -0
  135. package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
  136. package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
  137. package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
  138. package/src/state/selectors/containerSelectors.js +6 -0
  139. package/src/state/selectors/dataSelectors.js +97 -0
  140. package/src/state/selectors/graphicalItemSelectors.js +25 -0
  141. package/src/state/selectors/legendSelectors.js +18 -0
  142. package/src/state/selectors/lineSelectors.js +106 -0
  143. package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
  144. package/src/state/selectors/pickAxisId.js +3 -0
  145. package/src/state/selectors/pickAxisType.js +3 -0
  146. package/src/state/selectors/polarAxisSelectors.js +237 -0
  147. package/src/state/selectors/rootPropsSelectors.js +13 -0
  148. package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
  149. package/src/state/selectors/selectAllAxes.js +15 -0
  150. package/src/state/selectors/selectChartOffset.js +12 -0
  151. package/src/state/selectors/selectChartOffsetInternal.js +174 -0
  152. package/src/state/selectors/selectPlotArea.js +19 -0
  153. package/src/state/selectors/selectTooltipAxisId.js +3 -0
  154. package/src/state/selectors/selectTooltipAxisType.js +25 -0
  155. package/src/state/selectors/selectTooltipEventType.js +27 -0
  156. package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
  157. package/src/state/selectors/selectTooltipSettings.js +3 -0
  158. package/src/state/selectors/selectTooltipState.js +3 -0
  159. package/src/state/selectors/selectors.js +222 -0
  160. package/src/state/selectors/tooltipSelectors.js +471 -0
  161. package/src/state/selectors/touchSelectors.js +31 -0
  162. package/src/state/store.js +101 -0
  163. package/src/state/tooltipSlice.js +237 -0
  164. package/src/state/touchEventsMiddleware.js +140 -0
  165. package/src/state/types/StackedGraphicalItem.js +18 -0
  166. package/src/state/zIndexSlice.js +167 -0
  167. package/src/synchronisation/syncSelectors.js +5 -0
  168. package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
  169. package/src/util/ActiveShapeUtils.tsrx +62 -0
  170. package/src/util/BarUtils.tsrx +35 -0
  171. package/src/util/CartesianUtils.js +66 -0
  172. package/src/util/ChartUtils.js +630 -0
  173. package/src/util/Constants.js +42 -0
  174. package/src/util/DOMUtils.js +180 -0
  175. package/src/util/DataUtils.js +199 -0
  176. package/src/util/Events.js +7 -0
  177. package/src/util/Global.js +13 -0
  178. package/src/util/LRUCache.js +58 -0
  179. package/src/util/LogUtils.js +29 -0
  180. package/src/util/PolarUtils.js +190 -0
  181. package/src/util/ReactUtils.ts +94 -0
  182. package/src/util/ReduceCSSCalc.js +260 -0
  183. package/src/util/TickUtils.js +43 -0
  184. package/src/util/YAxisUtils.js +43 -0
  185. package/src/util/axisPropsAreEqual.js +63 -0
  186. package/src/util/createEventProxy.js +18 -0
  187. package/src/util/excludeEventProps.js +172 -0
  188. package/src/util/getActiveCoordinate.js +253 -0
  189. package/src/util/getAxisTypeBasedOnLayout.js +17 -0
  190. package/src/util/getClassNameFromUnknown.js +8 -0
  191. package/src/util/getEveryNth.js +29 -0
  192. package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
  193. package/src/util/getRelativeCoordinate.js +96 -0
  194. package/src/util/getSliced.js +11 -0
  195. package/src/util/isDomainSpecifiedByUser.js +255 -0
  196. package/src/util/isWellBehavedNumber.js +8 -0
  197. package/src/util/propsAreEqual.js +96 -0
  198. package/src/util/resolveDefaultProps.js +131 -0
  199. package/src/util/round.js +39 -0
  200. package/src/util/scale/RechartsScale.js +68 -0
  201. package/src/util/scale/createCategoricalInverse.js +77 -0
  202. package/src/util/scale/getNiceTickValues.js +354 -0
  203. package/src/util/scale/index.js +3 -0
  204. package/src/util/scale/util/arithmetic.js +51 -0
  205. package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
  206. package/src/util/svgPropertiesAndEvents.ts +29 -0
  207. package/src/util/svgPropertiesNoEvents.js +383 -0
  208. package/src/util/types.ts +59 -0
  209. package/src/util/useAnimationId.ts +14 -0
  210. package/src/util/useId.ts +13 -0
  211. package/src/util/usePrefersReducedMotion.ts +30 -0
  212. package/src/util/useReportScale.ts +26 -0
  213. package/src/util/useUniqueId.js +34 -0
  214. package/src/zIndex/DefaultZIndexes.js +75 -0
  215. package/src/zIndex/ZIndexLayer.tsrx +80 -0
  216. package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
  217. package/src/zIndex/ZIndexPortal.tsrx +43 -0
  218. package/src/zIndex/getZIndexFromUnknown.js +15 -0
  219. package/src/zIndex/zIndexSelectors.js +45 -0
@@ -0,0 +1,294 @@
1
+ // Port of chart/RechartsWrapper.tsx — the outer <div class="recharts-wrapper">:
2
+ // hosts the tooltip/legend portals, reports container size (static, read-once,
3
+ // or ResizeObserver-driven), measures CSS scale, and feeds every user
4
+ // interaction into the store's event middlewares. Events are NATIVE delegated
5
+ // DOM events (octane has no synthetic layer); the middlewares read coordinates
6
+ // off the real event, and octane shadows `currentTarget` during delegated
7
+ // dispatch so `getRelativeCoordinate` sees the wrapper node as React would.
8
+ import { useCallback, useEffect, useRef, useState } from 'octane';
9
+ import { clsx } from 'clsx';
10
+ import { mouseLeaveChart } from '../state/tooltipSlice';
11
+ import { useAppDispatch } from '../state/hooks';
12
+ import { mouseClickAction, mouseMoveAction } from '../state/mouseEventsMiddleware';
13
+ import {
14
+ useSynchronisedEventsFromOtherCharts,
15
+ } from '../synchronisation/useChartSynchronisation.tsrx';
16
+ import { focusAction, keyDownAction, blurAction } from '../state/keyboardEventsMiddleware';
17
+ import { useReportScale } from '../util/useReportScale.ts';
18
+ import { externalEventAction } from '../state/externalEventsMiddleware';
19
+ import { touchEventAction } from '../state/touchEventsMiddleware';
20
+ import { TooltipPortalContext } from '../context/tooltipPortalContext.ts';
21
+ import { LegendPortalContext } from '../context/legendPortalContext.ts';
22
+ import { ReportChartSize } from '../context/chartLayoutContext.ts';
23
+ import { useResponsiveContainerContext } from '../component/ResponsiveContainer.ts';
24
+
25
+ function EventSynchronizer() {
26
+ useSynchronisedEventsFromOtherCharts();
27
+ return null;
28
+ }
29
+
30
+ function getNumberOrZero(value) {
31
+ if (typeof value === 'number') {
32
+ return value;
33
+ }
34
+ if (typeof value === 'string') {
35
+ const parsed = parseFloat(value);
36
+ if (!Number.isNaN(parsed)) {
37
+ return parsed;
38
+ }
39
+ }
40
+ return 0;
41
+ }
42
+
43
+ function ResponsiveDiv(props) {
44
+ const { ref, ...divProps } = props;
45
+ const observerRef = useRef(null);
46
+ const [sizes, setSizes] = useState({
47
+ containerWidth: getNumberOrZero(props.style?.width),
48
+ containerHeight: getNumberOrZero(props.style?.height),
49
+ });
50
+ const setContainerSize = useCallback((newWidth, newHeight) => {
51
+ setSizes((prevState) => {
52
+ const roundedWidth = Math.round(newWidth);
53
+ const roundedHeight = Math.round(newHeight);
54
+ if (
55
+ prevState.containerWidth === roundedWidth && prevState.containerHeight === roundedHeight
56
+ ) {
57
+ return prevState;
58
+ }
59
+ return { containerWidth: roundedWidth, containerHeight: roundedHeight };
60
+ });
61
+ }, []);
62
+ const innerRef = useCallback((node) => {
63
+ // 1. First, call the external ref if it was provided
64
+ if (typeof ref === 'function') {
65
+ ref(node);
66
+ }
67
+ // 2. Disconnect any previously active ResizeObserver
68
+ if (observerRef.current != null) {
69
+ observerRef.current.disconnect();
70
+ observerRef.current = null;
71
+ }
72
+ // 3. Observe the new node
73
+ if (node != null && typeof ResizeObserver !== 'undefined') {
74
+ const { width: containerWidth, height: containerHeight } = node.getBoundingClientRect();
75
+ setContainerSize(containerWidth, containerHeight);
76
+ const callback = (entries) => {
77
+ const entry = entries[0];
78
+ if (entry == null) {
79
+ return;
80
+ }
81
+ const { width, height } = entry.contentRect;
82
+ setContainerSize(width, height);
83
+ };
84
+ const observer = new ResizeObserver(callback);
85
+ observer.observe(node);
86
+ observerRef.current = observer;
87
+ }
88
+ }, [ref, setContainerSize]);
89
+ useEffect(() => {
90
+ return () => {
91
+ const observer = observerRef.current;
92
+ if (observer != null) {
93
+ observer.disconnect();
94
+ }
95
+ };
96
+ }, [setContainerSize]);
97
+ return <>
98
+ <ReportChartSize width={sizes.containerWidth} height={sizes.containerHeight} />
99
+ <div ref={innerRef} {...divProps} />
100
+ </>;
101
+ }
102
+
103
+ function ReadSizeOnceDiv(props) {
104
+ // Upstream spreads the FULL props onto the div — width/height included
105
+ // (they pass through as plain attributes).
106
+ const { ref, width, height, ...rest } = props;
107
+ const divProps = { width, height, ...rest };
108
+ const [sizes, setSizes] = useState({
109
+ containerWidth: getNumberOrZero(width),
110
+ containerHeight: getNumberOrZero(height),
111
+ });
112
+ const setContainerSize = useCallback((newWidth, newHeight) => {
113
+ setSizes((prevState) => {
114
+ const roundedWidth = Math.round(newWidth);
115
+ const roundedHeight = Math.round(newHeight);
116
+ if (
117
+ prevState.containerWidth === roundedWidth && prevState.containerHeight === roundedHeight
118
+ ) {
119
+ return prevState;
120
+ }
121
+ return { containerWidth: roundedWidth, containerHeight: roundedHeight };
122
+ });
123
+ }, []);
124
+ const innerRef = useCallback((node) => {
125
+ if (typeof ref === 'function') {
126
+ ref(node);
127
+ }
128
+ if (node != null) {
129
+ const { width: containerWidth, height: containerHeight } = node.getBoundingClientRect();
130
+ setContainerSize(containerWidth, containerHeight);
131
+ }
132
+ }, [ref, setContainerSize]);
133
+ return <>
134
+ <ReportChartSize width={sizes.containerWidth} height={sizes.containerHeight} />
135
+ <div ref={innerRef} {...divProps} />
136
+ </>;
137
+ }
138
+
139
+ function StaticDiv(props) {
140
+ const { ref, width, height, ...rest } = props;
141
+ const divProps = { width, height, ...rest };
142
+ return <>
143
+ <ReportChartSize width={width} height={height} />
144
+ <div ref={ref} {...divProps} />
145
+ </>;
146
+ }
147
+
148
+ function NonResponsiveDiv(props) {
149
+ const { width, height } = props;
150
+ // Percentage/CSS-string sizes: read the real size from the DOM once.
151
+ if (typeof width === 'string' || typeof height === 'string') {
152
+ return <ReadSizeOnceDiv {...props} />;
153
+ }
154
+ // Both numbers: use directly.
155
+ if (typeof width === 'number' && typeof height === 'number') {
156
+ return <StaticDiv {...props} width={width} height={height} />;
157
+ }
158
+ // Undefined sizes: report as-is (renders no SVG — intentional back-compat).
159
+ const { ref, ...divProps } = props;
160
+ // (width/height are undefined here, so nothing extra lands on the div.)
161
+ return <>
162
+ <ReportChartSize width={width} height={height} />
163
+ <div ref={ref} {...divProps} />
164
+ </>;
165
+ }
166
+
167
+ export function RechartsWrapper(props) {
168
+ const {
169
+ children,
170
+ className,
171
+ height: heightFromProps,
172
+ onClick,
173
+ onContextMenu,
174
+ onDoubleClick,
175
+ onMouseDown,
176
+ onMouseEnter,
177
+ onMouseLeave,
178
+ onMouseMove,
179
+ onMouseUp,
180
+ onTouchEnd,
181
+ onTouchMove,
182
+ onTouchStart,
183
+ style,
184
+ width: widthFromProps,
185
+ responsive,
186
+ dispatchTouchEvents = true,
187
+ ref,
188
+ } = props;
189
+ const containerRef = useRef(null);
190
+ const dispatch = useAppDispatch();
191
+ const [tooltipPortal, setTooltipPortal] = useState(null);
192
+ const [legendPortal, setLegendPortal] = useState(null);
193
+ const setScaleRef = useReportScale();
194
+ const responsiveContainerCalculations = useResponsiveContainerContext();
195
+ const width =
196
+ responsiveContainerCalculations?.width > 0
197
+ ? responsiveContainerCalculations.width
198
+ : widthFromProps;
199
+ const height =
200
+ responsiveContainerCalculations?.height > 0
201
+ ? responsiveContainerCalculations.height
202
+ : heightFromProps;
203
+ const innerRef = useCallback((node) => {
204
+ setScaleRef(node);
205
+ if (typeof ref === 'function') {
206
+ ref(node);
207
+ }
208
+ setTooltipPortal(node);
209
+ setLegendPortal(node);
210
+ if (node != null) {
211
+ containerRef.current = node;
212
+ }
213
+ }, [setScaleRef, ref, setTooltipPortal, setLegendPortal]);
214
+ const myOnClick = useCallback((e) => {
215
+ dispatch(mouseClickAction(e));
216
+ dispatch(externalEventAction({ handler: onClick, reactEvent: e }));
217
+ }, [dispatch, onClick]);
218
+ const myOnMouseEnter = useCallback((e) => {
219
+ dispatch(mouseMoveAction(e));
220
+ dispatch(externalEventAction({ handler: onMouseEnter, reactEvent: e }));
221
+ }, [dispatch, onMouseEnter]);
222
+ const myOnMouseLeave = useCallback((e) => {
223
+ dispatch(mouseLeaveChart());
224
+ dispatch(externalEventAction({ handler: onMouseLeave, reactEvent: e }));
225
+ }, [dispatch, onMouseLeave]);
226
+ const myOnMouseMove = useCallback((e) => {
227
+ dispatch(mouseMoveAction(e));
228
+ dispatch(externalEventAction({ handler: onMouseMove, reactEvent: e }));
229
+ }, [dispatch, onMouseMove]);
230
+ const onFocus = useCallback(() => {
231
+ dispatch(focusAction());
232
+ }, [dispatch]);
233
+ const onBlur = useCallback(() => {
234
+ dispatch(blurAction());
235
+ }, [dispatch]);
236
+ const onKeyDown = useCallback((e) => {
237
+ dispatch(keyDownAction(e.key));
238
+ }, [dispatch]);
239
+ const myOnContextMenu = useCallback((e) => {
240
+ dispatch(externalEventAction({ handler: onContextMenu, reactEvent: e }));
241
+ }, [dispatch, onContextMenu]);
242
+ const myOnDoubleClick = useCallback((e) => {
243
+ dispatch(externalEventAction({ handler: onDoubleClick, reactEvent: e }));
244
+ }, [dispatch, onDoubleClick]);
245
+ const myOnMouseDown = useCallback((e) => {
246
+ dispatch(externalEventAction({ handler: onMouseDown, reactEvent: e }));
247
+ }, [dispatch, onMouseDown]);
248
+ const myOnMouseUp = useCallback((e) => {
249
+ dispatch(externalEventAction({ handler: onMouseUp, reactEvent: e }));
250
+ }, [dispatch, onMouseUp]);
251
+ const myOnTouchStart = useCallback((e) => {
252
+ dispatch(externalEventAction({ handler: onTouchStart, reactEvent: e }));
253
+ }, [dispatch, onTouchStart]);
254
+ // Touch has no enter/leave; the middleware resolves the touched element via
255
+ // document.elementFromPoint.
256
+ const myOnTouchMove = useCallback((e) => {
257
+ if (dispatchTouchEvents) {
258
+ dispatch(touchEventAction(e));
259
+ }
260
+ dispatch(externalEventAction({ handler: onTouchMove, reactEvent: e }));
261
+ }, [dispatch, dispatchTouchEvents, onTouchMove]);
262
+ const myOnTouchEnd = useCallback((e) => {
263
+ dispatch(externalEventAction({ handler: onTouchEnd, reactEvent: e }));
264
+ }, [dispatch, onTouchEnd]);
265
+ const WrapperDiv = responsive ? ResponsiveDiv : NonResponsiveDiv;
266
+ return <TooltipPortalContext.Provider value={tooltipPortal}>
267
+ <LegendPortalContext.Provider value={legendPortal}>
268
+ <WrapperDiv
269
+ width={width ?? style?.width}
270
+ height={height ?? style?.height}
271
+ className={clsx('recharts-wrapper', className)}
272
+ style={{ position: 'relative', cursor: 'default', width, height, ...style }}
273
+ onClick={myOnClick}
274
+ onContextMenu={myOnContextMenu}
275
+ onDoubleClick={myOnDoubleClick}
276
+ onFocus={onFocus}
277
+ onBlur={onBlur}
278
+ onKeyDown={onKeyDown}
279
+ onMouseDown={myOnMouseDown}
280
+ onMouseEnter={myOnMouseEnter}
281
+ onMouseLeave={myOnMouseLeave}
282
+ onMouseMove={myOnMouseMove}
283
+ onMouseUp={myOnMouseUp}
284
+ onTouchEnd={myOnTouchEnd}
285
+ onTouchMove={myOnTouchMove}
286
+ onTouchStart={myOnTouchStart}
287
+ ref={innerRef}
288
+ >
289
+ <EventSynchronizer />
290
+ {children}
291
+ </WrapperDiv>
292
+ </LegendPortalContext.Provider>
293
+ </TooltipPortalContext.Provider>;
294
+ }
@@ -0,0 +1,76 @@
1
+ // Port of component/ActivePoints.tsx — the highlighted dot on the active
2
+ // tooltip data point (Line/Area/Scatter).
3
+ import { cloneElement, isValidElement } from 'octane';
4
+ import { adaptEventHandlers } from '../util/types.ts';
5
+ import { Dot } from '../shape/Dot.tsrx';
6
+ import { Layer } from '../container/Layer.tsrx';
7
+ import { useAppSelector } from '../state/hooks';
8
+ import { selectActiveTooltipIndex } from '../state/selectors/tooltipSelectors';
9
+ import { useActiveTooltipDataPoints } from '../hooks';
10
+ import { isNullish } from '../util/DataUtils';
11
+ import { svgPropertiesNoEventsFromUnknown } from '../util/svgPropertiesNoEvents';
12
+ import { ZIndexLayer } from '../zIndex/ZIndexLayer.tsrx';
13
+ import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
14
+
15
+ function ActivePoint(activePointProps) {
16
+ const { point, childIndex, mainColor, activeDot, dataKey, clipPath } = activePointProps;
17
+ if (activeDot === false || point.x == null || point.y == null) {
18
+ return null;
19
+ }
20
+ const dotPropsTyped = {
21
+ index: childIndex,
22
+ dataKey,
23
+ cx: point.x,
24
+ cy: point.y,
25
+ r: 4,
26
+ fill: mainColor ?? 'none',
27
+ strokeWidth: 2,
28
+ stroke: '#fff',
29
+ payload: point.payload,
30
+ value: point.value,
31
+ };
32
+ const dotProps = {
33
+ ...dotPropsTyped,
34
+ ...svgPropertiesNoEventsFromUnknown(activeDot),
35
+ ...adaptEventHandlers(activeDot),
36
+ };
37
+ let dot;
38
+ if (isValidElement(activeDot)) {
39
+ dot = cloneElement(activeDot, dotProps);
40
+ } else if (typeof activeDot === 'function') {
41
+ dot = activeDot(dotProps);
42
+ } else {
43
+ dot = <Dot {...dotProps} />;
44
+ }
45
+ return <Layer className="recharts-active-dot" clipPath={clipPath}>{dot}</Layer>;
46
+ }
47
+
48
+ export function ActivePoints(props) {
49
+ const {
50
+ points,
51
+ mainColor,
52
+ activeDot,
53
+ itemDataKey,
54
+ clipPath,
55
+ zIndex = DefaultZIndexes.activeDot,
56
+ } = props;
57
+ const activeTooltipIndex = useAppSelector(selectActiveTooltipIndex);
58
+ const activeDataPoints = useActiveTooltipDataPoints();
59
+ if (points == null || activeDataPoints == null) {
60
+ return null;
61
+ }
62
+ const activePoint = points.find((p) => activeDataPoints.includes(p.payload));
63
+ if (isNullish(activePoint)) {
64
+ return null;
65
+ }
66
+ return <ZIndexLayer zIndex={zIndex}>
67
+ <ActivePoint
68
+ point={activePoint}
69
+ childIndex={Number(activeTooltipIndex)}
70
+ mainColor={mainColor}
71
+ dataKey={itemDataKey}
72
+ activeDot={activeDot}
73
+ clipPath={clipPath}
74
+ />
75
+ </ZIndexLayer>;
76
+ }
@@ -0,0 +1,37 @@
1
+ // Port of component/Cell.tsx — the null-rendering per-datum props carrier.
2
+ // Upstream reads Cells out of `children` via findAllByType; octane children
3
+ // are opaque compiled blocks, so the octane Cell REGISTERS its props into the
4
+ // ambient CellsContext instead (provided by Bar/Pie/…), preserving mount
5
+ // order == data-index order. Rendering output is identical: nothing.
6
+ /**
7
+ * Cell component used to define colors and styles of chart elements.
8
+ *
9
+ * This component is now deprecated and will be removed in Recharts 4.0.
10
+ * Please use the `shape` or `content` prop on the chart components instead.
11
+ *
12
+ * @deprecated
13
+ * @consumes CellReader
14
+ */
15
+ import { useLayoutEffect, useRef } from 'octane';
16
+ import { useCellsRegistry } from '../context/CellsContext';
17
+
18
+ export function Cell(props: Record<string, unknown>): null {
19
+ const registry = useCellsRegistry();
20
+ const token = useRef({});
21
+ useLayoutEffect(() => {
22
+ if (registry == null) {
23
+ return;
24
+ }
25
+ registry.register(token.current, props);
26
+ }, [registry, props]);
27
+ useLayoutEffect(() => {
28
+ return () => {
29
+ if (registry != null) {
30
+ registry.unregister(token.current);
31
+ }
32
+ };
33
+ }, [registry]);
34
+ return null;
35
+ }
36
+
37
+ Cell.displayName = 'Cell';
@@ -0,0 +1,74 @@
1
+ // Port of component/Dots.tsx — the dot layer Line/Area/Radar render per data
2
+ // point; `dot` accepts boolean | props object | element | render function.
3
+ import { cloneElement, isValidElement } from 'octane';
4
+ import { clsx } from 'clsx';
5
+ import { Dot } from '../shape/Dot.tsrx';
6
+ import { Layer } from '../container/Layer.tsrx';
7
+ import { isClipDot } from '../util/ReactUtils';
8
+ import { svgPropertiesAndEventsFromUnknown } from '../util/svgPropertiesAndEvents.ts';
9
+ import { ZIndexLayer } from '../zIndex/ZIndexLayer.tsrx';
10
+ import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
11
+
12
+ function DotItem(props) {
13
+ const { option, dotProps, className } = props;
14
+ if (isValidElement(option)) {
15
+ return cloneElement(option, dotProps);
16
+ }
17
+ if (typeof option === 'function') {
18
+ return option(dotProps);
19
+ }
20
+ const finalClassName = clsx(className, typeof option !== 'boolean' ? option.className : '');
21
+ const { points, ...rest } = dotProps ?? {};
22
+ return <Dot {...rest} className={finalClassName} />;
23
+ }
24
+
25
+ function shouldRenderDots(points, dot) {
26
+ if (points == null) {
27
+ return false;
28
+ }
29
+ if (dot) {
30
+ return true;
31
+ }
32
+ return points.length === 1;
33
+ }
34
+
35
+ export function Dots(dotsProps) {
36
+ const {
37
+ points,
38
+ dot,
39
+ className,
40
+ dotClassName,
41
+ dataKey,
42
+ baseProps,
43
+ needClip,
44
+ clipPathId,
45
+ zIndex = DefaultZIndexes.scatter,
46
+ } = dotsProps;
47
+ if (!shouldRenderDots(points, dot)) {
48
+ return null;
49
+ }
50
+ const clipDot = isClipDot(dot);
51
+ const customDotProps = svgPropertiesAndEventsFromUnknown(dot);
52
+ const dots = points.map((entry, i) => {
53
+ const dotProps = {
54
+ r: 3,
55
+ ...baseProps,
56
+ ...customDotProps,
57
+ index: i,
58
+ cx: entry.x ?? undefined,
59
+ cy: entry.y ?? undefined,
60
+ dataKey,
61
+ value: entry.value,
62
+ payload: entry.payload,
63
+ points,
64
+ };
65
+ return <DotItem key={'dot-' + i} option={dot} dotProps={dotProps} className={dotClassName} />;
66
+ });
67
+ const layerProps = {};
68
+ if (needClip && clipPathId != null) {
69
+ layerProps.clipPath = 'url(#clipPath-' + (clipDot ? '' : 'dots-') + clipPathId + ')';
70
+ }
71
+ return <ZIndexLayer zIndex={zIndex}>
72
+ <Layer className={className} {...layerProps}>{dots}</Layer>
73
+ </ZIndexLayer>;
74
+ }