solid-recharts 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/LICENSE +24 -0
  2. package/package.json +10 -7
  3. package/src/cartesian/Area.tsx +40 -55
  4. package/src/cartesian/Bar.tsx +66 -58
  5. package/src/cartesian/BarStack.tsx +5 -2
  6. package/src/cartesian/Brush.tsx +1 -1
  7. package/src/cartesian/Funnel.tsx +15 -19
  8. package/src/cartesian/Line.tsx +34 -51
  9. package/src/cartesian/LineDrawShape.tsx +8 -6
  10. package/src/cartesian/ReferenceArea.tsx +25 -35
  11. package/src/cartesian/ReferenceDot.tsx +24 -34
  12. package/src/cartesian/ReferenceLine.tsx +25 -34
  13. package/src/cartesian/Scatter.tsx +25 -37
  14. package/src/cartesian/XAxis.tsx +54 -67
  15. package/src/cartesian/YAxis.tsx +53 -66
  16. package/src/cartesian/ZAxis.tsx +27 -40
  17. package/src/chart/SunburstChart.tsx +1 -1
  18. package/src/component/ActivePoints.tsx +0 -9
  19. package/src/component/Customized.tsx +1 -1
  20. package/src/component/Dots.tsx +7 -3
  21. package/src/context/ErrorBarContext.tsx +15 -24
  22. package/src/polar/Pie.tsx +36 -48
  23. package/src/polar/PolarAngleAxis.tsx +41 -50
  24. package/src/polar/PolarRadiusAxis.tsx +40 -48
  25. package/src/polar/Radar.tsx +22 -34
  26. package/src/polar/RadialBar.tsx +21 -39
  27. package/src/shape/Curve.tsx +1 -1
  28. package/src/shape/Symbols.tsx +1 -1
  29. package/src/state/RechartsReduxContext.tsx +1 -1
  30. package/src/state/SetLegendPayload.ts +19 -27
  31. package/src/state/SetTooltipEntrySettings.tsx +9 -26
  32. package/src/state/cartesianAxisSlice.ts +40 -60
  33. package/src/state/createCollectionActions.ts +51 -0
  34. package/src/state/createSelector.ts +97 -0
  35. package/src/state/externalEventsMiddleware.ts +2 -11
  36. package/src/state/graphicalItemsSlice.ts +27 -40
  37. package/src/state/isEventThrottled.ts +12 -0
  38. package/src/state/keyboardEventsMiddleware.ts +2 -8
  39. package/src/state/layoutSlice.ts +8 -4
  40. package/src/state/legendSlice.ts +24 -26
  41. package/src/state/mouseEventsMiddleware.ts +2 -13
  42. package/src/state/patched.ts +19 -0
  43. package/src/state/referenceElementsSlice.ts +40 -31
  44. package/src/state/registerInStore.ts +68 -0
  45. package/src/state/selectors/areaSelectors.ts +13 -36
  46. package/src/state/selectors/arrayEqualityCheck.ts +32 -7
  47. package/src/state/selectors/axisSelectors.ts +215 -169
  48. package/src/state/selectors/barSelectors.ts +8 -36
  49. package/src/state/selectors/combiners/combineConfiguredScale.ts +1 -1
  50. package/src/state/selectors/combiners/combineRealScaleType.ts +1 -1
  51. package/src/state/selectors/dataSelectors.ts +35 -16
  52. package/src/state/selectors/numberDomainEqualityCheck.ts +16 -8
  53. package/src/state/selectors/selectAxisForGraphicalItem.ts +52 -0
  54. package/src/state/store.ts +0 -1
  55. package/src/state/tooltipSlice.ts +93 -64
  56. package/src/util/ActiveShapeUtils.tsx +0 -7
  57. package/src/util/BarUtils.tsx +27 -22
  58. package/src/util/ChartUtils.ts +69 -25
  59. package/src/util/propsAreEqual.ts +3 -33
  60. package/src/util/stacks/stackTypes.ts +1 -1
  61. package/src/util/types.ts +2 -2
  62. package/test/animation/CSSTransitionAnimate.timing.spec.tsx +1 -1
  63. package/test/animation/JavascriptAnimate.spec.tsx +1 -1
  64. package/test/animation/legacyAnimationLengthChange.spec.tsx +1 -1
  65. package/test/cartesian/Area.animation.spec.tsx +1 -1
  66. package/test/cartesian/Area.range.spec.tsx +1 -1
  67. package/test/cartesian/Area.spec.tsx +1 -1
  68. package/test/cartesian/Area.stacked.render.spec.tsx +1 -1
  69. package/test/cartesian/Area.typed.spec.tsx +1 -1
  70. package/test/cartesian/Axis.integration.spec.tsx +1 -1
  71. package/test/cartesian/Bar/Bar.csstransition.spec.tsx +1 -1
  72. package/test/cartesian/Bar/Bar.spec.tsx +1 -1
  73. package/test/cartesian/Bar/Bar.typed.spec.tsx +1 -1
  74. package/test/cartesian/Bar.animation.spec.tsx +1 -1
  75. package/test/cartesian/Bar.stackDomain.spec.tsx +1 -1
  76. package/test/cartesian/Bar.stacked.render.spec.tsx +1 -1
  77. package/test/cartesian/Bar.zeroDimensionFiltering.spec.tsx +1 -1
  78. package/test/cartesian/Brush.keyboard.spec.tsx +1 -1
  79. package/test/cartesian/Brush.panorama.spec.tsx +1 -1
  80. package/test/cartesian/Brush.props.spec.tsx +1 -1
  81. package/test/cartesian/Brush.render.spec.tsx +1 -1
  82. package/test/cartesian/Brush.spec.tsx +1 -1
  83. package/test/cartesian/Brush.stacked.spec.tsx +1 -1
  84. package/test/cartesian/CartesianAxis.render.spec.tsx +1 -1
  85. package/test/cartesian/CartesianAxis.spec.tsx +2 -2
  86. package/test/cartesian/CartesianGrid.render.spec.tsx +1 -1
  87. package/test/cartesian/CartesianGrid.spec.tsx +1 -1
  88. package/test/cartesian/ErrorBar.render.spec.tsx +1 -1
  89. package/test/cartesian/ErrorBar.spec.tsx +1 -1
  90. package/test/cartesian/Funnel.animation.spec.tsx +1 -1
  91. package/test/cartesian/Funnel.spec.tsx +1 -1
  92. package/test/cartesian/Funnel.typed.spec.tsx +1 -1
  93. package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +2 -2
  94. package/test/cartesian/Line.animation.spec.tsx +1 -1
  95. package/test/cartesian/Line.sparseAnimationPath.spec.tsx +1 -1
  96. package/test/cartesian/Line.spec.tsx +1 -1
  97. package/test/cartesian/Line.typed.spec.tsx +1 -1
  98. package/test/cartesian/ReferenceArea.render.spec.tsx +1 -1
  99. package/test/cartesian/ReferenceArea.spec.tsx +1 -1
  100. package/test/cartesian/ReferenceArea.typed.spec.tsx +1 -1
  101. package/test/cartesian/ReferenceDot.render.spec.tsx +1 -1
  102. package/test/cartesian/ReferenceDot.spec.tsx +1 -1
  103. package/test/cartesian/ReferenceDot.typed.spec.tsx +1 -1
  104. package/test/cartesian/ReferenceLine/ReferenceLine.panorama.spec.tsx +1 -1
  105. package/test/cartesian/ReferenceLine/ReferenceLine.spec.tsx +1 -1
  106. package/test/cartesian/ReferenceLine/ReferenceLine.typed.spec.tsx +1 -1
  107. package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +1 -1
  108. package/test/cartesian/ReferenceLine.render.spec.tsx +1 -1
  109. package/test/cartesian/Scatter.animation.spec.tsx +1 -1
  110. package/test/cartesian/Scatter.render.spec.tsx +1 -1
  111. package/test/cartesian/Scatter.spec.tsx +1 -1
  112. package/test/cartesian/Scatter.typed.spec.tsx +1 -1
  113. package/test/cartesian/XAxis/XAxis.barSize.spec.tsx +1 -1
  114. package/test/cartesian/XAxis/XAxis.brush.spec.tsx +1 -1
  115. package/test/cartesian/XAxis/XAxis.categorydomain.spec.tsx +1 -1
  116. package/test/cartesian/XAxis/XAxis.datatypes.spec.tsx +1 -1
  117. package/test/cartesian/XAxis/XAxis.hide.spec.tsx +1 -1
  118. package/test/cartesian/XAxis/XAxis.multiaxis.spec.tsx +1 -1
  119. package/test/cartesian/XAxis/XAxis.numberdomain.spec.tsx +1 -1
  120. package/test/cartesian/XAxis/XAxis.padding.spec.tsx +1 -1
  121. package/test/cartesian/XAxis/XAxis.padding_clip.spec.tsx +1 -1
  122. package/test/cartesian/XAxis/XAxis.state.spec.tsx +1 -1
  123. package/test/cartesian/XAxis/XAxis.tick.spec.tsx +1 -1
  124. package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +2 -2
  125. package/test/cartesian/XAxis/XAxis.typed.spec.tsx +1 -1
  126. package/test/cartesian/XAxis/XAxis.vertical.spec.tsx +1 -1
  127. package/test/cartesian/XAxis.tickFormatter.spec.tsx +1 -1
  128. package/test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx +1 -1
  129. package/test/cartesian/YAxis/YAxis.interval-zero.spec.tsx +1 -1
  130. package/test/cartesian/YAxis/YAxis.label.spec.tsx +1 -1
  131. package/test/cartesian/YAxis/YAxis.spec.tsx +1 -1
  132. package/test/cartesian/YAxis/YAxis.tick.spec.tsx +1 -1
  133. package/test/cartesian/YAxis/YAxis.tickFormatter.spec.tsx +1 -1
  134. package/test/cartesian/YAxis/YAxis.typed.spec.tsx +1 -1
  135. package/test/cartesian/ZAxis.spec.tsx +1 -1
  136. package/test/cartesian/ZAxis.typed.spec.tsx +1 -1
  137. package/test/cartesian/axisLineAndStroke.spec.tsx +1 -1
  138. package/test/cartesian/miscFeatureGaps.spec.tsx +1 -1
  139. package/test/chart/AccessibilityLayer.spec.tsx +1 -1
  140. package/test/chart/AccessibilityScans.spec.tsx +2 -2
  141. package/test/chart/AreaChart.spec.tsx +1 -1
  142. package/test/chart/AreaChart.typed.spec.tsx +1 -1
  143. package/test/chart/BarChart.spec.tsx +1 -1
  144. package/test/chart/BarChart.typed.spec.tsx +1 -1
  145. package/test/chart/CategoricalChart.spec.tsx +1 -1
  146. package/test/chart/ComposedChart.spec.tsx +1 -1
  147. package/test/chart/ComposedChart.typed.spec.tsx +1 -1
  148. package/test/chart/FunnelChart.spec.tsx +1 -1
  149. package/test/chart/FunnelChart.typed.spec.tsx +1 -1
  150. package/test/chart/LineChart.smoke.spec.tsx +1 -1
  151. package/test/chart/LineChart.spec.tsx +1 -1
  152. package/test/chart/LineChart.typed.spec.tsx +1 -1
  153. package/test/chart/NicheChartTooltip.spec.tsx +1 -1
  154. package/test/chart/PieChart.spec.tsx +1 -1
  155. package/test/chart/PieChart.typed.spec.tsx +1 -1
  156. package/test/chart/RadarChart.spec.tsx +1 -1
  157. package/test/chart/RadarChart.typed.spec.tsx +1 -1
  158. package/test/chart/RadialBarChart.spec.tsx +1 -1
  159. package/test/chart/RadialBarChart.typed.spec.tsx +1 -1
  160. package/test/chart/RechartsWrapper.spec.tsx +1 -1
  161. package/test/chart/Sankey.content.spec.tsx +1 -1
  162. package/test/chart/Sankey.spec.tsx +1 -1
  163. package/test/chart/ScatterChart.spec.tsx +1 -1
  164. package/test/chart/ScatterChart.typed.spec.tsx +1 -1
  165. package/test/chart/SunburstChart.spec.tsx +1 -1
  166. package/test/chart/Treemap.animation.spec.tsx +1 -1
  167. package/test/chart/Treemap.spec.tsx +1 -1
  168. package/test/chart/chartEvents.spec.tsx +1 -1
  169. package/test/chart/responsive.spec.tsx +1 -1
  170. package/test/component/Cell.render.spec.tsx +1 -1
  171. package/test/component/Cell.spec.tsx +1 -1
  172. package/test/component/Cursor.spec.tsx +1 -1
  173. package/test/component/DefaultTooltipContent.spec.tsx +1 -1
  174. package/test/component/Label.render.spec.tsx +1 -1
  175. package/test/component/Label.spec.tsx +1 -1
  176. package/test/component/LabelList.spec.tsx +1 -1
  177. package/test/component/Legend.itemSorter.spec.tsx +1 -1
  178. package/test/component/Legend.render.spec.tsx +1 -1
  179. package/test/component/Legend.spec.tsx +1 -1
  180. package/test/component/ResponsiveContainer.spec.tsx +1 -1
  181. package/test/component/ResponsiveContainerDataTest.spec.tsx +1 -1
  182. package/test/component/Text.spec.tsx +1 -1
  183. package/test/component/Tooltip/ActiveDot.spec.tsx +1 -1
  184. package/test/component/Tooltip/tooltipEventType.spec.tsx +1 -1
  185. package/test/component/Tooltip/tooltipTestHelpers.tsx +1 -1
  186. package/test/component/Tooltip.defaultIndex.spec.tsx +1 -1
  187. package/test/component/Tooltip.hover.spec.tsx +1 -1
  188. package/test/component/Tooltip.item.spec.tsx +1 -1
  189. package/test/component/Tooltip.keyboard.spec.tsx +1 -1
  190. package/test/component/Tooltip.payload.spec.tsx +1 -1
  191. package/test/component/Tooltip.touch.spec.tsx +1 -1
  192. package/test/component/Tooltip.visibility.spec.tsx +1 -1
  193. package/test/component/TooltipBoundingBox.spec.tsx +2 -2
  194. package/test/container/ClipPath.spec.tsx +1 -1
  195. package/test/context/chartLayoutContext.spec.tsx +1 -1
  196. package/test/helper/createSelectorTestCase.tsx +1 -1
  197. package/test/helper/mockAxes.ts +1 -1
  198. package/test/helper/selectorTestHelpers.tsx +1 -1
  199. package/test/hooks/useActiveTooltipDataPoints.spec.tsx +1 -1
  200. package/test/hooks/useOffset.spec.tsx +1 -1
  201. package/test/hooks/useTooltipStateHooks.spec.tsx +1 -1
  202. package/test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx +1 -1
  203. package/test/polar/Pie/Pie.spec.tsx +1 -1
  204. package/test/polar/Pie/Pie.typed.spec.tsx +1 -1
  205. package/test/polar/Pie.animation.spec.tsx +1 -1
  206. package/test/polar/PieWithLegend.animation.spec.tsx +1 -1
  207. package/test/polar/PolarAngleAxis/PolarAngleAxis.events.spec.tsx +1 -1
  208. package/test/polar/PolarAngleAxis/PolarAngleAxis.spec.tsx +1 -1
  209. package/test/polar/PolarAngleAxis/PolarAngleAxis.typed.spec.tsx +1 -1
  210. package/test/polar/PolarAngleAxis.render.spec.tsx +1 -1
  211. package/test/polar/PolarGrid.render.spec.tsx +1 -1
  212. package/test/polar/PolarGrid.spec.tsx +1 -1
  213. package/test/polar/PolarLegendPerRow.render.spec.tsx +1 -1
  214. package/test/polar/PolarRadiusAxis.events.spec.tsx +1 -1
  215. package/test/polar/PolarRadiusAxis.render.spec.tsx +1 -1
  216. package/test/polar/PolarRadiusAxis.spec.tsx +1 -1
  217. package/test/polar/PolarRadiusAxis.typed.spec.tsx +1 -1
  218. package/test/polar/PolarTooltipLegend.render.spec.tsx +1 -1
  219. package/test/polar/Radar.animation.spec.tsx +1 -1
  220. package/test/polar/Radar.render.spec.tsx +1 -1
  221. package/test/polar/Radar.spec.tsx +1 -1
  222. package/test/polar/Radar.typed.spec.tsx +1 -1
  223. package/test/polar/RadialBar/RadialBar.spec.tsx +1 -1
  224. package/test/polar/RadialBar/RadialBar.typed.spec.tsx +1 -1
  225. package/test/polar/RadialBar.animation.spec.tsx +1 -1
  226. package/test/polar/RadialBar.render.spec.tsx +1 -1
  227. package/test/polar/RadialBar.stacked.spec.tsx +1 -1
  228. package/test/setup.ts +1 -1
  229. package/test/shape/ActiveShape.spec.tsx +1 -1
  230. package/test/shape/Cross.spec.tsx +1 -1
  231. package/test/shape/Curve.spec.tsx +2 -2
  232. package/test/shape/Curve.typed.spec.tsx +1 -1
  233. package/test/shape/Dot.spec.tsx +1 -1
  234. package/test/shape/Polygon.spec.tsx +1 -1
  235. package/test/shape/Rectangle.animation.spec.tsx +1 -1
  236. package/test/shape/Rectangle.spec.tsx +1 -1
  237. package/test/shape/Sector.spec.tsx +1 -1
  238. package/test/shape/Symbols.spec.tsx +1 -1
  239. package/test/shape/Trapezoid.spec.tsx +1 -1
  240. package/test/state/createCollectionActions.spec.ts +87 -0
  241. package/test/state/createSelector.spec.ts +158 -0
  242. package/test/state/hooks.spec.tsx +1 -1
  243. package/test/state/registerInStore.spec.tsx +101 -0
  244. package/test/state/selectors/axisSelectors.spec.tsx +1 -1
  245. package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +1 -1
  246. package/test/state/selectors/combiners/combineRealScaleType.spec.ts +1 -1
  247. package/test/state/selectors/dataSelectors.spec.tsx +1 -1
  248. package/test/state/selectors/legendSelectors.spec.tsx +1 -1
  249. package/test/state/selectors/radarSelectors.spec.tsx +1 -1
  250. package/test/state/selectors/selectActiveTooltipIndex.spec.tsx +1 -1
  251. package/test/state/selectors/selectDisplayedData.spec.tsx +1 -1
  252. package/test/state/selectors/selectStackGroups.spec.tsx +1 -1
  253. package/test/state/selectors/selectorMemoization.spec.tsx +136 -0
  254. package/test/state/selectors/selectors.spec.tsx +1 -1
  255. package/test/util/CartesianUtils/CartesianUtils.spec.ts +1 -1
  256. package/test/util/ChartUtils/ChartUtils.spec.ts +1 -1
  257. package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +14 -0
  258. package/test/util/ChartUtils/getStackedData.spec.ts +1 -1
  259. package/test/util/ChartUtils/truncateByDomain.spec.ts +1 -1
  260. package/test/util/DomUtils.spec.tsx +1 -1
  261. package/test/util/FunnelUtils.spec.tsx +1 -1
  262. package/test/util/scale/createCategoricalInverse.spec.ts +1 -1
  263. package/test/util/useElementOffset.spec.tsx +1 -1
  264. package/test/util/usePrefersReducedMotion.spec.ts +1 -1
  265. package/test/util/useUniqueId.spec.ts +1 -1
  266. package/test/zIndex/AllZIndexPortals.spec.tsx +1 -1
  267. package/test/zIndex/DynamicZIndex.spec.tsx +1 -1
  268. package/test/zIndex/ZIndexLayer.portalOwner.spec.tsx +1 -1
  269. package/test/zIndex/componentZIndex.spec.tsx +1 -1
  270. package/test/zIndex/multiChartZIndexIsolation.spec.tsx +1 -1
  271. package/test-results/.last-run.json +4 -0
  272. package/NEXT_SESSION_PROMPT.md +0 -114
  273. package/src/state/reduxDevtoolsJsonStringifyReplacer.ts +0 -15
  274. package/src/util/axisPropsAreEqual.ts +0 -42
  275. package/src/util/resolveDefaultProps.tsx +0 -8
  276. package/src/util/typedDataKey.ts +0 -8
  277. package/test/helper/render.ts +0 -7
  278. package/test/state/reduxDevtoolsJsonStringifyReplacer.spec.ts +0 -25
  279. package/test/util/axisPropsAreEqual.spec.ts +0 -93
@@ -14,6 +14,7 @@ import {
14
14
  import { selectChartDirection } from "./selectors/axisSelectors";
15
15
  import { combineActiveTooltipIndex } from "./selectors/combiners/combineActiveTooltipIndex";
16
16
  import { selectTooltipEventType } from "./selectors/selectTooltipEventType";
17
+ import { isEventThrottled } from "./isEventThrottled";
17
18
 
18
19
  const mkInteraction = (index: number): TooltipInteractionState => ({
19
20
  active: false,
@@ -23,12 +24,6 @@ const mkInteraction = (index: number): TooltipInteractionState => ({
23
24
  coordinate: undefined,
24
25
  });
25
26
 
26
- export type KeyDownAction = { type: "keyDown"; payload: KeyboardEvent["key"] };
27
-
28
- export function keyDownAction(payload: KeyboardEvent["key"]): KeyDownAction {
29
- return { type: "keyDown", payload };
30
- }
31
-
32
27
  let rafId: number | null = null;
33
28
  let timeoutId: ReturnType<typeof setTimeout> | null = null;
34
29
  let latestKeyboardActionPayload: KeyboardEvent["key"] | null = null;
@@ -43,8 +38,7 @@ export function dispatchKeyDown(store: RechartsStore, key: KeyboardEvent["key"])
43
38
 
44
39
  const state = store.state;
45
40
  const { throttleDelay, throttledEvents } = state.eventSettings;
46
- const eventListAsString: "all" | ReadonlyArray<string> | undefined = throttledEvents;
47
- const isThrottled = eventListAsString === "all" || eventListAsString?.includes("keydown");
41
+ const isThrottled = isEventThrottled(throttledEvents, "keydown");
48
42
 
49
43
  if (timeoutId !== null && (typeof throttleDelay !== "number" || !isThrottled)) {
50
44
  clearTimeout(timeoutId);
@@ -1,6 +1,7 @@
1
1
  // Ported from recharts 3.8.1 src/state/layoutSlice.ts (commit 7a23854).
2
2
  // Solid-native slice (no Redux): createStore + draft-first action setters.
3
3
  import { createStore } from "solid-js";
4
+ import { patched } from "./patched";
4
5
  import { LayoutType, Margin, Size } from "../util/types";
5
6
 
6
7
  export type ChartLayoutState = {
@@ -53,11 +54,14 @@ export function createChartLayoutSlice(
53
54
  });
54
55
  },
55
56
  setMargin(margin) {
57
+ // Slice immutability contract (ADR-0002): replace the margin node.
56
58
  setState((s) => {
57
- s.margin.top = margin.top ?? 0;
58
- s.margin.right = margin.right ?? 0;
59
- s.margin.bottom = margin.bottom ?? 0;
60
- s.margin.left = margin.left ?? 0;
59
+ s.margin = patched(s.margin, {
60
+ top: margin.top ?? 0,
61
+ right: margin.right ?? 0,
62
+ bottom: margin.bottom ?? 0,
63
+ left: margin.left ?? 0,
64
+ });
61
65
  });
62
66
  },
63
67
  setScale(scale) {
@@ -8,6 +8,8 @@
8
8
  // match by it (the same proxy-safe strategy as graphicalItemsSlice/tooltipSlice).
9
9
  // `selectLegendPayload` flattens `items` back to the reference's flat shape.
10
10
  import { createStore } from "solid-js";
11
+ import { createCollectionActions } from "./createCollectionActions";
12
+ import { patched } from "./patched";
11
13
  import { LayoutType, Size } from "../util/types";
12
14
  import {
13
15
  HorizontalAlignmentType,
@@ -66,41 +68,37 @@ export function createLegendSlice(initialState: LegendState = initialLegendState
66
68
  payload: [...initialState.payload],
67
69
  });
68
70
 
71
+ const payload = createCollectionActions<LegendPayloadEntry>(
72
+ (updater) =>
73
+ setState((s) => {
74
+ const next = updater(s.payload);
75
+ if (next !== s.payload) {
76
+ s.payload = next;
77
+ }
78
+ }),
79
+ (e) => e.id,
80
+ );
81
+
69
82
  const actions: LegendActions = {
70
83
  setLegendSize(payload) {
84
+ // Slice immutability contract (ADR-0002): replace the node, not leaves.
71
85
  setState((s) => {
72
- s.size.width = payload.width;
73
- s.size.height = payload.height;
86
+ s.size = patched(s.size, { width: payload.width, height: payload.height });
74
87
  });
75
88
  },
76
89
  setLegendSettings(payload) {
77
90
  setState((s) => {
78
- s.settings.align = payload.align;
79
- s.settings.layout = payload.layout;
80
- s.settings.verticalAlign = payload.verticalAlign;
81
- s.settings.itemSorter = payload.itemSorter;
82
- });
83
- },
84
- addLegendPayload(payload) {
85
- setState((s) => {
86
- s.payload = [...s.payload, payload];
87
- });
88
- },
89
- replaceLegendPayload({ prev, next }) {
90
- setState((s) => {
91
- const index = s.payload.findIndex((e) => e.id === prev.id);
92
- if (index > -1) {
93
- const nextItems = s.payload.slice();
94
- nextItems[index] = next;
95
- s.payload = nextItems;
96
- }
97
- });
98
- },
99
- removeLegendPayload(payload) {
100
- setState((s) => {
101
- s.payload = s.payload.filter((e) => e.id !== payload.id);
91
+ s.settings = patched(s.settings, {
92
+ align: payload.align,
93
+ layout: payload.layout,
94
+ verticalAlign: payload.verticalAlign,
95
+ itemSorter: payload.itemSorter,
96
+ });
102
97
  });
103
98
  },
99
+ addLegendPayload: payload.add,
100
+ replaceLegendPayload: payload.replace,
101
+ removeLegendPayload: payload.remove,
104
102
  };
105
103
 
106
104
  return { state, actions };
@@ -7,17 +7,7 @@ import type { HTMLMousePointer, RelativePointer } from "../util/types";
7
7
  import { selectActivePropsFromChartPointer } from "./selectors/tooltipSelectors";
8
8
  import { selectTooltipEventType } from "./selectors/selectTooltipEventType";
9
9
  import type { RechartsStore } from "./store";
10
-
11
- export type MouseMoveAction = { type: "mouseMove"; payload: HTMLMousePointer };
12
- export type MouseClickAction = { type: "mouseClick"; payload: HTMLMousePointer };
13
-
14
- export function mouseMoveAction(payload: HTMLMousePointer): MouseMoveAction {
15
- return { type: "mouseMove", payload };
16
- }
17
-
18
- export function mouseClickAction(payload: HTMLMousePointer): MouseClickAction {
19
- return { type: "mouseClick", payload };
20
- }
10
+ import { isEventThrottled } from "./isEventThrottled";
21
11
 
22
12
  /*
23
13
  * This single rafId is safe because:
@@ -46,8 +36,7 @@ export function dispatchMouseClick(store: RechartsStore, mousePointer: HTMLMouse
46
36
  export function dispatchMouseMove(store: RechartsStore, mousePointer: HTMLMousePointer): void {
47
37
  const state = store.state;
48
38
  const { throttleDelay, throttledEvents } = state.eventSettings;
49
- const eventListAsString: "all" | ReadonlyArray<string> | undefined = throttledEvents;
50
- const isThrottled = eventListAsString === "all" || eventListAsString?.includes("mousemove");
39
+ const isThrottled = isEventThrottled(throttledEvents, "mousemove");
51
40
 
52
41
  if (rafId !== null) {
53
42
  cancelAnimationFrame(rafId);
@@ -0,0 +1,19 @@
1
+ // Slice immutability contract helper (ADR-0002).
2
+ //
3
+ // Slices must not mutate nested state in place — a changed value must have a
4
+ // new reference all the way up to the slice-root property, because the
5
+ // selector graph invalidates by input-reference comparison. `patched` is the
6
+ // replacement write: it returns `{ ...current, ...patch }` when some patched
7
+ // field actually differs, and `current` itself when nothing does — mirroring
8
+ // immer, which skips same-value assignments, so untouched state keeps its
9
+ // reference and downstream caches stay warm. Nest calls to replace along a
10
+ // path: `s.a = patched(s.a, { b: patched(s.a.b, { c: 1 }) })`.
11
+
12
+ export function patched<T extends object>(current: T, patch: Partial<T>): T {
13
+ for (const key in patch) {
14
+ if (!Object.is(current[key], patch[key])) {
15
+ return { ...current, ...patch };
16
+ }
17
+ }
18
+ return current;
19
+ }
@@ -12,6 +12,7 @@
12
12
  // useUniqueId) and we match by `id`, the same proxy-safe strategy as
13
13
  // graphicalItemsSlice / tooltipSlice / legendSlice.
14
14
  import { createStore } from "solid-js";
15
+ import { createCollectionActions } from "./createCollectionActions";
15
16
  import type { AxisId } from "./cartesianAxisSlice";
16
17
  import type { IfOverflow } from "../util/IfOverflow";
17
18
  import type { ReferenceLineSegment } from "../cartesian/ReferenceLine";
@@ -81,40 +82,48 @@ export function createReferenceElementsSlice(
81
82
  lines: [...initialState.lines],
82
83
  });
83
84
 
84
- const actions: ReferenceElementsActions = {
85
- // State arrays are typed ReadonlyArray (immutable external API), so actions
86
- // REASSIGN the whole array rather than mutate in place Solid's fine-grained
87
- // store still tracks the change, and the readonly type stays honest.
88
- addDot(dot) {
89
- setState((s) => {
90
- s.dots = [...s.dots, dot];
91
- });
92
- },
93
- removeDot(dot) {
94
- setState((s) => {
95
- s.dots = s.dots.filter((d) => d.id !== dot.id);
96
- });
97
- },
98
- addArea(area) {
85
+ // State arrays are typed ReadonlyArray (immutable external API); the collection
86
+ // actions reassign the whole array rather than mutate in place (see ADR-0002).
87
+ // Reference elements have no replace action a change is remove-then-add at the
88
+ // call site (ReferenceLine/Dot/Area), so only add + remove are wired.
89
+ const dots = createCollectionActions<ReferenceDotSettings>(
90
+ (updater) =>
99
91
  setState((s) => {
100
- s.areas = [...s.areas, area];
101
- });
102
- },
103
- removeArea(area) {
92
+ const next = updater(s.dots);
93
+ if (next !== s.dots) {
94
+ s.dots = next;
95
+ }
96
+ }),
97
+ (d) => d.id,
98
+ );
99
+ const areas = createCollectionActions<ReferenceAreaSettings>(
100
+ (updater) =>
104
101
  setState((s) => {
105
- s.areas = s.areas.filter((a) => a.id !== area.id);
106
- });
107
- },
108
- addLine(line) {
102
+ const next = updater(s.areas);
103
+ if (next !== s.areas) {
104
+ s.areas = next;
105
+ }
106
+ }),
107
+ (a) => a.id,
108
+ );
109
+ const lines = createCollectionActions<ReferenceLineSettings>(
110
+ (updater) =>
109
111
  setState((s) => {
110
- s.lines = [...s.lines, line];
111
- });
112
- },
113
- removeLine(line) {
114
- setState((s) => {
115
- s.lines = s.lines.filter((l) => l.id !== line.id);
116
- });
117
- },
112
+ const next = updater(s.lines);
113
+ if (next !== s.lines) {
114
+ s.lines = next;
115
+ }
116
+ }),
117
+ (l) => l.id,
118
+ );
119
+
120
+ const actions: ReferenceElementsActions = {
121
+ addDot: dots.add,
122
+ removeDot: dots.remove,
123
+ addArea: areas.add,
124
+ removeArea: areas.remove,
125
+ addLine: lines.add,
126
+ removeLine: lines.remove,
118
127
  };
119
128
 
120
129
  return { state, actions };
@@ -0,0 +1,68 @@
1
+ // The register-while-mounted idiom, concentrated.
2
+ //
3
+ // A graphical item / axis / reference element / tooltip / legend entry adds its
4
+ // settings to the chart store while it is mounted and removes them on unmount.
5
+ // Every such component used to hand-roll the identical dance: a two-argument
6
+ // `createEffect(compute, apply)` (the compute phase builds the settings, the
7
+ // apply phase adds-or-replaces — this shape is what keeps the reactive reads out
8
+ // of the apply body, avoiding STRICT_READ_UNTRACKED), reference-based add/replace
9
+ // tracking through a `let prev`, and an `unregisterOnCleanup` removal (which runs
10
+ // the store write owner-free via `runWithOwner(null)`, avoiding
11
+ // SIGNAL_WRITE_IN_OWNED_SCOPE on subtree disposal).
12
+ //
13
+ // This module owns that shell so every caller states only what genuinely varies:
14
+ // how to compute its settings, and the three store actions. Both Solid
15
+ // invariants above are now true by construction at every call site.
16
+ //
17
+ // Control signal: `compute` returning `undefined` skips the tick without touching
18
+ // `prev` — exactly the early-return the sites used for every guard (store absent,
19
+ // inside a Panorama, an axis whose type is not yet resolved). Callers fold those
20
+ // guards into the compute closure, so there is a single skip path.
21
+ import { createEffect } from "solid-js";
22
+ import { unregisterOnCleanup } from "./unregisterOnCleanup";
23
+
24
+ /**
25
+ * The three store writes a registration performs. `add` runs on first registration,
26
+ * `replace` when the computed settings change, `remove` on unmount.
27
+ *
28
+ * Slices without a dedicated replace action compose one: reference elements pass
29
+ * `replace: (prev, next) => { remove(prev); add(next); }`, and slices whose `add`
30
+ * overwrites by id (the polar axes) pass `replace: (_prev, next) => add(next)`.
31
+ */
32
+ export interface StoreRegistrationHandlers<T> {
33
+ add(next: T): void;
34
+ replace(prev: T, next: T): void;
35
+ remove(prev: T): void;
36
+ }
37
+
38
+ /**
39
+ * Register `compute()`'s value in the store for as long as the calling component
40
+ * is mounted. Returns `undefined` from `compute` to skip (no write, `prev`
41
+ * untouched). Must be called synchronously during component setup so the effect
42
+ * and cleanup bind to the component's owner.
43
+ */
44
+ export function registerInStore<T>(
45
+ compute: () => T | undefined,
46
+ handlers: StoreRegistrationHandlers<T>,
47
+ ): void {
48
+ let prev: T | null = null;
49
+
50
+ createEffect(compute, (next: T | undefined) => {
51
+ if (next == null) {
52
+ return;
53
+ }
54
+ if (prev === null) {
55
+ handlers.add(next);
56
+ } else if (prev !== next) {
57
+ handlers.replace(prev, next);
58
+ }
59
+ prev = next;
60
+ });
61
+
62
+ unregisterOnCleanup(() => {
63
+ if (prev !== null) {
64
+ handlers.remove(prev);
65
+ prev = null;
66
+ }
67
+ });
68
+ }
@@ -3,12 +3,7 @@
3
3
  // `selectGraphicalItemStackedData` reads this area's stack series off the numeric
4
4
  // axis' stack groups, and computeArea turns it into a per-point baseLine.
5
5
  import { RechartsRootState } from "../store";
6
- import {
7
- selectAxisWithScale,
8
- selectStackGroups,
9
- selectTicksOfGraphicalItem,
10
- selectUnfilteredCartesianItems,
11
- } from "./axisSelectors";
6
+ import { selectStackGroups, selectUnfilteredCartesianItems } from "./axisSelectors";
12
7
  import { getBandSizeOfAxis, isCategoricalAxis } from "../../util/ChartUtils";
13
8
  import { ChartData } from "../chartDataSlice";
14
9
  import { selectChartLayout } from "../../context/chartLayoutContext";
@@ -19,33 +14,15 @@ import {
19
14
  selectXAxisIdFromGraphicalItemId,
20
15
  selectYAxisIdFromGraphicalItemId,
21
16
  } from "./graphicalItemSelectors";
17
+ import {
18
+ selectAxisWithScaleForGraphicalItem,
19
+ selectTicksForGraphicalItem,
20
+ } from "./selectAxisForGraphicalItem";
22
21
  import { AreaSettings } from "../types/AreaSettings";
23
22
  import { computeArea, ComputedArea } from "../../cartesian/Area";
24
23
  import { combineStackedData } from "./combiners/combineStackedData";
25
24
  import { AllStackGroups, StackDataPoint } from "../../util/stacks/stackTypes";
26
25
 
27
- const selectXAxisWithScale = (state: RechartsRootState, id: GraphicalItemId, isPanorama: boolean) =>
28
- selectAxisWithScale(state, "xAxis", selectXAxisIdFromGraphicalItemId(state, id), isPanorama);
29
-
30
- const selectXAxisTicks = (state: RechartsRootState, id: GraphicalItemId, isPanorama: boolean) =>
31
- selectTicksOfGraphicalItem(
32
- state,
33
- "xAxis",
34
- selectXAxisIdFromGraphicalItemId(state, id),
35
- isPanorama,
36
- );
37
-
38
- const selectYAxisWithScale = (state: RechartsRootState, id: GraphicalItemId, isPanorama: boolean) =>
39
- selectAxisWithScale(state, "yAxis", selectYAxisIdFromGraphicalItemId(state, id), isPanorama);
40
-
41
- const selectYAxisTicks = (state: RechartsRootState, id: GraphicalItemId, isPanorama: boolean) =>
42
- selectTicksOfGraphicalItem(
43
- state,
44
- "yAxis",
45
- selectYAxisIdFromGraphicalItemId(state, id),
46
- isPanorama,
47
- );
48
-
49
26
  const selectBandSize = (
50
27
  state: RechartsRootState,
51
28
  id: GraphicalItemId,
@@ -54,14 +31,14 @@ const selectBandSize = (
54
31
  const layout = selectChartLayout(state);
55
32
  if (isCategoricalAxis(layout, "xAxis")) {
56
33
  return getBandSizeOfAxis(
57
- selectXAxisWithScale(state, id, isPanorama),
58
- selectXAxisTicks(state, id, isPanorama),
34
+ selectAxisWithScaleForGraphicalItem(state, "xAxis", id, isPanorama),
35
+ selectTicksForGraphicalItem(state, "xAxis", id, isPanorama),
59
36
  false,
60
37
  );
61
38
  }
62
39
  return getBandSizeOfAxis(
63
- selectYAxisWithScale(state, id, isPanorama),
64
- selectYAxisTicks(state, id, isPanorama),
40
+ selectAxisWithScaleForGraphicalItem(state, "yAxis", id, isPanorama),
41
+ selectTicksForGraphicalItem(state, "yAxis", id, isPanorama),
65
42
  false,
66
43
  );
67
44
  };
@@ -116,10 +93,10 @@ export const selectArea = (
116
93
  isPanorama: boolean,
117
94
  ): ComputedArea | undefined => {
118
95
  const layout = selectChartLayout(state);
119
- const xAxis = selectXAxisWithScale(state, id, isPanorama);
120
- const yAxis = selectYAxisWithScale(state, id, isPanorama);
121
- const xAxisTicks = selectXAxisTicks(state, id, isPanorama);
122
- const yAxisTicks = selectYAxisTicks(state, id, isPanorama);
96
+ const xAxis = selectAxisWithScaleForGraphicalItem(state, "xAxis", id, isPanorama);
97
+ const yAxis = selectAxisWithScaleForGraphicalItem(state, "yAxis", id, isPanorama);
98
+ const xAxisTicks = selectTicksForGraphicalItem(state, "xAxis", id, isPanorama);
99
+ const yAxisTicks = selectTicksForGraphicalItem(state, "yAxis", id, isPanorama);
123
100
  const { chartData, dataStartIndex, dataEndIndex } =
124
101
  selectChartDataWithIndexesIfNotInPanoramaPosition3(state, id, isPanorama);
125
102
  const bandSize = selectBandSize(state, id, isPanorama);
@@ -1,8 +1,33 @@
1
- // SKIPPED intentionally NOT ported to the SolidJS port.
1
+ // Ported from recharts 3.9.2 src/state/selectors/arrayEqualityCheck.ts.
2
2
  //
3
- // Reason: reselect resultEqualityCheck Solid memoizes via createMemo, not needed
4
- //
5
- // TODO: do not port this file as-is. The Solid-native port replaces it (see the
6
- // reason above). If a consumer needs this path, wire it to the Solid equivalent
7
- // instead. Tracked in scripts/porting-queue.mjs SKIP list and project memory.
8
- export {};
3
+ // Previously skipped under ADR-0001's reading that Solid's createMemo made
4
+ // reselect's resultEqualityCheck unnecessary. ADR-0002 restores shared
5
+ // memoization via `createSelector`, which takes the same resultEqualityCheck
6
+ // option so these are ported and passed to the wrapped selectors exactly
7
+ // where upstream passes them.
8
+
9
+ /**
10
+ * Checks if two arrays are equal, treating empty arrays as equal regardless of
11
+ * reference. If both arrays are non-empty, it checks for reference equality.
12
+ */
13
+ export function emptyArraysAreEqualCheck<T>(a: ReadonlyArray<T>, b: ReadonlyArray<T>): boolean {
14
+ if (Array.isArray(a) && Array.isArray(b) && a.length === 0 && b.length === 0) {
15
+ return true;
16
+ }
17
+ return a === b;
18
+ }
19
+
20
+ /**
21
+ * Checks if two arrays have the same contents in the same order.
22
+ */
23
+ export function arrayContentsAreEqualCheck<T>(a: ReadonlyArray<T>, b: ReadonlyArray<T>): boolean {
24
+ if (a.length === b.length) {
25
+ for (let i = 0; i < a.length; i++) {
26
+ if (a[i] !== b[i]) {
27
+ return false;
28
+ }
29
+ }
30
+ return true;
31
+ }
32
+ return false;
33
+ }