solid-recharts 0.2.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.
- package/package.json +5 -3
- package/src/cartesian/Area.tsx +40 -55
- package/src/cartesian/Bar.tsx +66 -58
- package/src/cartesian/BarStack.tsx +5 -2
- package/src/cartesian/Brush.tsx +1 -1
- package/src/cartesian/Funnel.tsx +15 -19
- package/src/cartesian/Line.tsx +34 -51
- package/src/cartesian/LineDrawShape.tsx +8 -6
- package/src/cartesian/ReferenceArea.tsx +25 -35
- package/src/cartesian/ReferenceDot.tsx +24 -34
- package/src/cartesian/ReferenceLine.tsx +25 -34
- package/src/cartesian/Scatter.tsx +25 -37
- package/src/cartesian/XAxis.tsx +54 -67
- package/src/cartesian/YAxis.tsx +53 -66
- package/src/cartesian/ZAxis.tsx +27 -40
- package/src/chart/SunburstChart.tsx +1 -1
- package/src/component/ActivePoints.tsx +0 -9
- package/src/component/Dots.tsx +7 -3
- package/src/context/ErrorBarContext.tsx +15 -24
- package/src/polar/Pie.tsx +36 -48
- package/src/polar/PolarAngleAxis.tsx +41 -50
- package/src/polar/PolarRadiusAxis.tsx +40 -48
- package/src/polar/Radar.tsx +22 -34
- package/src/polar/RadialBar.tsx +21 -39
- package/src/shape/Curve.tsx +1 -1
- package/src/shape/Symbols.tsx +1 -1
- package/src/state/SetLegendPayload.ts +19 -27
- package/src/state/SetTooltipEntrySettings.tsx +9 -26
- package/src/state/cartesianAxisSlice.ts +40 -60
- package/src/state/createCollectionActions.ts +51 -0
- package/src/state/createSelector.ts +97 -0
- package/src/state/externalEventsMiddleware.ts +2 -11
- package/src/state/graphicalItemsSlice.ts +27 -40
- package/src/state/isEventThrottled.ts +12 -0
- package/src/state/keyboardEventsMiddleware.ts +2 -8
- package/src/state/layoutSlice.ts +8 -4
- package/src/state/legendSlice.ts +24 -26
- package/src/state/mouseEventsMiddleware.ts +2 -13
- package/src/state/patched.ts +19 -0
- package/src/state/referenceElementsSlice.ts +40 -31
- package/src/state/registerInStore.ts +68 -0
- package/src/state/selectors/areaSelectors.ts +13 -36
- package/src/state/selectors/arrayEqualityCheck.ts +32 -7
- package/src/state/selectors/axisSelectors.ts +215 -169
- package/src/state/selectors/barSelectors.ts +8 -36
- package/src/state/selectors/combiners/combineConfiguredScale.ts +1 -1
- package/src/state/selectors/combiners/combineRealScaleType.ts +1 -1
- package/src/state/selectors/dataSelectors.ts +35 -16
- package/src/state/selectors/numberDomainEqualityCheck.ts +16 -8
- package/src/state/selectors/selectAxisForGraphicalItem.ts +52 -0
- package/src/state/tooltipSlice.ts +93 -64
- package/src/util/ActiveShapeUtils.tsx +0 -7
- package/src/util/BarUtils.tsx +27 -22
- package/src/util/ChartUtils.ts +69 -25
- package/src/util/propsAreEqual.ts +3 -33
- package/src/util/stacks/stackTypes.ts +1 -1
- package/src/util/types.ts +1 -1
- package/test/cartesian/CartesianAxis.spec.tsx +1 -1
- package/test/cartesian/GraphicalItemClipPath.scale-behavior.spec.tsx +1 -1
- package/test/cartesian/ReferenceLine/getEndPoints.spec.ts +1 -1
- package/test/cartesian/XAxis/XAxis.timescale.spec.tsx +1 -1
- package/test/helper/mockAxes.ts +1 -1
- package/test/shape/Curve.spec.tsx +1 -1
- package/test/state/createCollectionActions.spec.ts +87 -0
- package/test/state/createSelector.spec.ts +158 -0
- package/test/state/registerInStore.spec.tsx +101 -0
- package/test/state/selectors/combiners/combineConfiguredScale.spec.ts +1 -1
- package/test/state/selectors/combiners/combineRealScaleType.spec.ts +1 -1
- package/test/state/selectors/selectorMemoization.spec.tsx +136 -0
- package/test/util/CartesianUtils/CartesianUtils.spec.ts +1 -1
- package/test/util/ChartUtils/ChartUtils.spec.ts +1 -1
- package/test/util/ChartUtils/getCateCoordinateOfLine.spec.ts +14 -0
- package/test/util/ChartUtils/getStackedData.spec.ts +1 -1
- package/test/util/ChartUtils/truncateByDomain.spec.ts +1 -1
- package/test/util/scale/createCategoricalInverse.spec.ts +1 -1
- package/test-results/.last-run.json +4 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.ts +0 -15
- package/src/util/axisPropsAreEqual.ts +0 -42
- package/src/util/resolveDefaultProps.tsx +0 -8
- package/src/util/typedDataKey.ts +0 -8
- package/test/state/reduxDevtoolsJsonStringifyReplacer.spec.ts +0 -25
- package/test/util/axisPropsAreEqual.spec.ts +0 -93
package/src/polar/RadialBar.tsx
CHANGED
|
@@ -30,11 +30,15 @@
|
|
|
30
30
|
// (final frame), element-form shape, per-sector item-hover dispatch (sectors lack
|
|
31
31
|
// tooltipPosition).
|
|
32
32
|
// Cells ARE wired: a <Cell> child overrides the per-sector fill/stroke/class.
|
|
33
|
-
import {
|
|
33
|
+
import { createMemo, For, merge, Show, untrack } from "solid-js";
|
|
34
34
|
import type { JSX } from "@solidjs/web";
|
|
35
35
|
import { useAppSelector, useAppStore } from "../state/hooks";
|
|
36
36
|
import { useUniqueId } from "../util/useUniqueId";
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
AnimatedItems,
|
|
39
|
+
useAnimationCallbacks,
|
|
40
|
+
type AnimationInterpolateFn,
|
|
41
|
+
} from "../animation/AnimatedItems";
|
|
38
42
|
import { matchAppend, type AnimationMatchByProp } from "../animation/matchBy";
|
|
39
43
|
import type { MutableRef } from "../animation/useAnimationStartSnapshot";
|
|
40
44
|
import { usePolarChartLayout } from "../context/chartLayoutContext";
|
|
@@ -96,7 +100,7 @@ import {
|
|
|
96
100
|
} from "../util/ChartUtils";
|
|
97
101
|
import { interpolate, isNumber, mathSign } from "../util/DataUtils";
|
|
98
102
|
import type { StackSeries } from "../util/stacks/stackTypes";
|
|
99
|
-
import {
|
|
103
|
+
import { registerInStore } from "../state/registerInStore";
|
|
100
104
|
|
|
101
105
|
export type RadialBarDataItem = SectorProps &
|
|
102
106
|
PolarViewBoxRequired &
|
|
@@ -494,29 +498,14 @@ export function RadialBar<DataPointType = Record<string, unknown>, DataValueType
|
|
|
494
498
|
maxBarSize: merged.maxBarSize,
|
|
495
499
|
});
|
|
496
500
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if (prev === null) {
|
|
506
|
-
store.actions.graphicalItems.addPolarGraphicalItem(s);
|
|
507
|
-
} else if (prev !== s) {
|
|
508
|
-
store.actions.graphicalItems.replacePolarGraphicalItem({ prev, next: s });
|
|
509
|
-
}
|
|
510
|
-
prev = s;
|
|
511
|
-
},
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
unregisterOnCleanup(() => {
|
|
515
|
-
if (prev && store != null) {
|
|
516
|
-
store.actions.graphicalItems.removePolarGraphicalItem(prev);
|
|
517
|
-
prev = null;
|
|
518
|
-
}
|
|
519
|
-
});
|
|
501
|
+
if (store != null) {
|
|
502
|
+
registerInStore<RadialBarSettings>(() => settings(), {
|
|
503
|
+
add: (next) => store.actions.graphicalItems.addPolarGraphicalItem(next),
|
|
504
|
+
replace: (prev, next) =>
|
|
505
|
+
store.actions.graphicalItems.replacePolarGraphicalItem({ prev, next }),
|
|
506
|
+
remove: (prev) => store.actions.graphicalItems.removePolarGraphicalItem(prev),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
520
509
|
|
|
521
510
|
// Per-sector <Cell> overrides (collected from children, in data order).
|
|
522
511
|
const cells = collectCells(() => props.children);
|
|
@@ -574,17 +563,10 @@ export function RadialBar<DataPointType = Record<string, unknown>, DataValueType
|
|
|
574
563
|
current: null,
|
|
575
564
|
};
|
|
576
565
|
// Labels are hidden while the sectors animate (recharts' showLabels={!isAnimating}).
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
props.onAnimationStart?.();
|
|
582
|
-
setShowLabels(false);
|
|
583
|
-
};
|
|
584
|
-
const handleAnimationEnd = (): void => {
|
|
585
|
-
props.onAnimationEnd?.();
|
|
586
|
-
setShowLabels(true);
|
|
587
|
-
};
|
|
566
|
+
const { isAnimating, handleAnimationStart, handleAnimationEnd } = useAnimationCallbacks(
|
|
567
|
+
() => props.onAnimationStart?.(),
|
|
568
|
+
() => props.onAnimationEnd?.(),
|
|
569
|
+
);
|
|
588
570
|
|
|
589
571
|
// User pointer handlers are forwarded to each sector's wrapping <Layer>: the
|
|
590
572
|
// mouse handlers wrap into the tooltip-item dispatch (called props-first), and
|
|
@@ -669,7 +651,7 @@ export function RadialBar<DataPointType = Record<string, unknown>, DataValueType
|
|
|
669
651
|
<Layer class={layerClass()}>
|
|
670
652
|
<PolarLabelListContextProvider
|
|
671
653
|
value={() =>
|
|
672
|
-
|
|
654
|
+
!isAnimating()
|
|
673
655
|
? secs().map(
|
|
674
656
|
(sector): PolarLabelListEntry => ({
|
|
675
657
|
value: sector.value,
|
|
@@ -730,7 +712,7 @@ export function RadialBar<DataPointType = Record<string, unknown>, DataValueType
|
|
|
730
712
|
isActive={isSectorActiveShape(i())}
|
|
731
713
|
option={sectorOption(i())}
|
|
732
714
|
animationElapsedTime={animationElapsedTime}
|
|
733
|
-
isAnimating={
|
|
715
|
+
isAnimating={isAnimating() || animationElapsedTime < 1}
|
|
734
716
|
isEntrance={isEntrance}
|
|
735
717
|
class={`recharts-radial-bar-sector ${entry.class ?? ""}`}
|
|
736
718
|
fill={entry.fill ?? merged.fill}
|
package/src/shape/Curve.tsx
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
curveStepBefore,
|
|
39
39
|
line as shapeLine,
|
|
40
40
|
type Line as D3LineCurve,
|
|
41
|
-
} from "
|
|
41
|
+
} from "d3-shape";
|
|
42
42
|
import { isNumber, upperFirst } from "../util/DataUtils";
|
|
43
43
|
import { isWellBehavedNumber } from "../util/isWellBehavedNumber";
|
|
44
44
|
import { svgPropertiesNoEvents } from "../util/svgPropertiesNoEvents";
|
package/src/shape/Symbols.tsx
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
symbolTriangle,
|
|
21
21
|
symbolWye,
|
|
22
22
|
type SymbolType as D3SymbolType,
|
|
23
|
-
} from "
|
|
23
|
+
} from "d3-shape";
|
|
24
24
|
import { SymbolType } from "../util/types";
|
|
25
25
|
import { isNumber, upperFirst } from "../util/DataUtils";
|
|
26
26
|
import { svgPropertiesAndEvents } from "../util/svgPropertiesAndEvents";
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
// explicit `id` prop (the graphical item's id) keys the entry so replace/remove are
|
|
6
6
|
// proxy-safe (recharts matches the array by reference, which Solid stores break).
|
|
7
7
|
// `SetPolarLegendPayload` lands with the polar vertical. Returns nothing.
|
|
8
|
-
import { createEffect } from "solid-js";
|
|
9
8
|
import type { JSX } from "@solidjs/web";
|
|
10
9
|
import { useAppStore } from "./hooks";
|
|
11
10
|
import { useIsPanorama } from "../context/PanoramaContext";
|
|
12
11
|
import { LegendPayload } from "../component/DefaultLegendContent";
|
|
13
|
-
import {
|
|
12
|
+
import { registerInStore } from "./registerInStore";
|
|
13
|
+
|
|
14
|
+
interface LegendPayloadEntry {
|
|
15
|
+
id: string;
|
|
16
|
+
items: ReadonlyArray<LegendPayload>;
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
export function SetLegendPayload(props: {
|
|
16
20
|
id: string;
|
|
@@ -19,32 +23,20 @@ export function SetLegendPayload(props: {
|
|
|
19
23
|
const store = useAppStore();
|
|
20
24
|
const isPanorama = useIsPanorama();
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (prevId === null) {
|
|
31
|
-
store.actions.legend.addLegendPayload(entry);
|
|
32
|
-
} else {
|
|
26
|
+
// Panorama mirrors never contribute to the legend. The entry is keyed by id
|
|
27
|
+
// (recharts matches the array by reference, which Solid stores break), so
|
|
28
|
+
// replace/remove rebuild the `{ id, items: [] }` lookup key from prev.
|
|
29
|
+
if (store != null && !isPanorama) {
|
|
30
|
+
registerInStore<LegendPayloadEntry>(() => ({ id: props.id, items: props.legendPayload }), {
|
|
31
|
+
add: (next) => store.actions.legend.addLegendPayload(next),
|
|
32
|
+
replace: (prev, next) =>
|
|
33
33
|
store.actions.legend.replaceLegendPayload({
|
|
34
|
-
prev: { id:
|
|
35
|
-
next
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
unregisterOnCleanup(() => {
|
|
43
|
-
if (prevId != null && store != null) {
|
|
44
|
-
store.actions.legend.removeLegendPayload({ id: prevId, items: [] });
|
|
45
|
-
prevId = null;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
34
|
+
prev: { id: prev.id, items: [] },
|
|
35
|
+
next,
|
|
36
|
+
}),
|
|
37
|
+
remove: (prev) => store.actions.legend.removeLegendPayload({ id: prev.id, items: [] }),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
48
40
|
|
|
49
41
|
return null;
|
|
50
42
|
}
|
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
// on change) + onCleanup (remove), the same effect-dispatch idiom Line/Bar/Area
|
|
5
5
|
// use for their graphical-item registration. Returns null (renders nothing) — it
|
|
6
6
|
// exists purely to register the item's tooltip payload entry in the store.
|
|
7
|
-
import { createEffect } from "solid-js";
|
|
8
7
|
import type { JSX } from "@solidjs/web";
|
|
9
8
|
import { useAppStore } from "./hooks";
|
|
10
9
|
import { TooltipPayloadConfiguration } from "./tooltipSlice";
|
|
11
10
|
import { useIsPanorama } from "../context/PanoramaContext";
|
|
12
|
-
import {
|
|
11
|
+
import { registerInStore } from "./registerInStore";
|
|
13
12
|
|
|
14
13
|
export function SetTooltipEntrySettings(props: {
|
|
15
14
|
tooltipEntrySettings: TooltipPayloadConfiguration;
|
|
@@ -17,30 +16,14 @@ export function SetTooltipEntrySettings(props: {
|
|
|
17
16
|
const store = useAppStore();
|
|
18
17
|
const isPanorama = useIsPanorama();
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (prev === null) {
|
|
30
|
-
store.actions.tooltip.addTooltipEntrySettings(settings);
|
|
31
|
-
} else if (prev !== settings) {
|
|
32
|
-
store.actions.tooltip.replaceTooltipEntrySettings({ prev, next: settings });
|
|
33
|
-
}
|
|
34
|
-
prev = settings;
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
unregisterOnCleanup(() => {
|
|
39
|
-
if (prev && store != null) {
|
|
40
|
-
store.actions.tooltip.removeTooltipEntrySettings(prev);
|
|
41
|
-
prev = null;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
19
|
+
// Panorama graphical items never contribute to the Tooltip payload.
|
|
20
|
+
if (store != null && !isPanorama) {
|
|
21
|
+
registerInStore<TooltipPayloadConfiguration>(() => props.tooltipEntrySettings, {
|
|
22
|
+
add: (next) => store.actions.tooltip.addTooltipEntrySettings(next),
|
|
23
|
+
replace: (prev, next) => store.actions.tooltip.replaceTooltipEntrySettings({ prev, next }),
|
|
24
|
+
remove: (prev) => store.actions.tooltip.removeTooltipEntrySettings(prev),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
44
27
|
|
|
45
28
|
return null;
|
|
46
29
|
}
|
|
@@ -195,67 +195,47 @@ export function createCartesianAxisSlice(
|
|
|
195
195
|
zAxis: { ...initialState.zAxis },
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
});
|
|
218
|
-
},
|
|
219
|
-
addYAxis(axis) {
|
|
220
|
-
setState((s) => {
|
|
221
|
-
s.yAxis[axis.id] = axis;
|
|
222
|
-
});
|
|
223
|
-
},
|
|
224
|
-
replaceYAxis({ prev, next }) {
|
|
225
|
-
setState((s) => {
|
|
226
|
-
if (s.yAxis[prev.id] !== undefined) {
|
|
227
|
-
if (prev.id !== next.id) {
|
|
228
|
-
delete s.yAxis[prev.id];
|
|
198
|
+
// The x/y/z axis maps are Record<AxisId, …> (not arrays), and their
|
|
199
|
+
// add/replace/remove mutate the draft IN PLACE — preserving each map's reference
|
|
200
|
+
// identity, which downstream reads rely on. So this is a local record helper, not
|
|
201
|
+
// the shared array `createCollectionActions`; `pick` selects the map to touch.
|
|
202
|
+
// Concentrates the replace body that was written verbatim three times (x/y/z).
|
|
203
|
+
function axisCollection<A extends { id: AxisId }>(pick: (s: AxisMapState) => Record<AxisId, A>) {
|
|
204
|
+
return {
|
|
205
|
+
add: (axis: A) =>
|
|
206
|
+
setState((s) => {
|
|
207
|
+
pick(s)[axis.id] = axis;
|
|
208
|
+
}),
|
|
209
|
+
replace: ({ prev, next }: { prev: A; next: A }) =>
|
|
210
|
+
setState((s) => {
|
|
211
|
+
const map = pick(s);
|
|
212
|
+
if (map[prev.id] !== undefined) {
|
|
213
|
+
if (prev.id !== next.id) {
|
|
214
|
+
delete map[prev.id];
|
|
215
|
+
}
|
|
216
|
+
map[next.id] = next;
|
|
229
217
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
removeZAxis(axis) {
|
|
255
|
-
setState((s) => {
|
|
256
|
-
delete s.zAxis[axis.id];
|
|
257
|
-
});
|
|
258
|
-
},
|
|
218
|
+
}),
|
|
219
|
+
remove: (axis: A) =>
|
|
220
|
+
setState((s) => {
|
|
221
|
+
delete pick(s)[axis.id];
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const x = axisCollection<XAxisSettings>((s) => s.xAxis);
|
|
226
|
+
const y = axisCollection<YAxisSettings>((s) => s.yAxis);
|
|
227
|
+
const z = axisCollection<ZAxisSettings>((s) => s.zAxis);
|
|
228
|
+
|
|
229
|
+
const actions: CartesianAxisActions = {
|
|
230
|
+
addXAxis: x.add,
|
|
231
|
+
replaceXAxis: x.replace,
|
|
232
|
+
removeXAxis: x.remove,
|
|
233
|
+
addYAxis: y.add,
|
|
234
|
+
replaceYAxis: y.replace,
|
|
235
|
+
removeYAxis: y.remove,
|
|
236
|
+
addZAxis: z.add,
|
|
237
|
+
replaceZAxis: z.replace,
|
|
238
|
+
removeZAxis: z.remove,
|
|
259
239
|
updateYAxisWidth({ id, width }) {
|
|
260
240
|
setState((s) => {
|
|
261
241
|
const axis = s.yAxis[id];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The add / replace / remove algebra for a store-held array collection.
|
|
2
|
+
//
|
|
3
|
+
// Several slices keep a keyed collection as an array and expose the same three
|
|
4
|
+
// writes: append on add, swap-by-key on replace, filter-by-key on remove. Each
|
|
5
|
+
// used to hand-write that algebra (once per collection: cartesian + polar
|
|
6
|
+
// graphical items, reference dots/areas/lines, legend payload, tooltip entries).
|
|
7
|
+
// This concentrates it so the slice immutability contract (ADR-0002) lives in one
|
|
8
|
+
// place: every change produces a NEW array reference, so reference-equality
|
|
9
|
+
// selector caches invalidate; a future in-place slip can only regress here.
|
|
10
|
+
//
|
|
11
|
+
// The slice supplies `update`, which MUST read the current array and assign the
|
|
12
|
+
// result inside its own `setState` draft — the current-array read has to happen
|
|
13
|
+
// in the write batch, not in the caller's scope. Actions register from inside
|
|
14
|
+
// registerInStore's effect apply phase; a store read there (outside setState)
|
|
15
|
+
// would trip STRICT_READ_UNTRACKED. `update` returning the same reference from its
|
|
16
|
+
// updater is a no-op (matches the hand-written `index > -1` guard on replace).
|
|
17
|
+
//
|
|
18
|
+
// `keyOf` extracts the match key (an id field for most collections, a nested
|
|
19
|
+
// `settings.graphicalItemId` for tooltip entries). Slices without a replace action
|
|
20
|
+
// (reference elements) simply wire `add` and `remove`.
|
|
21
|
+
|
|
22
|
+
export interface CollectionActions<T> {
|
|
23
|
+
// Arrow-property signatures (not `add(item): void`) so consumers can reference
|
|
24
|
+
// these without the unbound-method lint firing — they carry no `this`.
|
|
25
|
+
add: (item: T) => void;
|
|
26
|
+
replace: (payload: { prev: T; next: T }) => void;
|
|
27
|
+
remove: (item: T) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createCollectionActions<T>(
|
|
31
|
+
update: (updater: (arr: ReadonlyArray<T>) => ReadonlyArray<T>) => void,
|
|
32
|
+
// Match key — compared only with `===`, so any value type is fine (an id
|
|
33
|
+
// field for most collections, a nested `settings.graphicalItemId` for tooltip).
|
|
34
|
+
keyOf: (item: T) => unknown,
|
|
35
|
+
): CollectionActions<T> {
|
|
36
|
+
return {
|
|
37
|
+
add: (item) => update((arr) => [...arr, item]),
|
|
38
|
+
replace: ({ prev, next }) =>
|
|
39
|
+
update((arr) => {
|
|
40
|
+
const index = arr.findIndex((it) => keyOf(it) === keyOf(prev));
|
|
41
|
+
// Absent key → return the same reference so `update` writes nothing.
|
|
42
|
+
if (index < 0) {
|
|
43
|
+
return arr;
|
|
44
|
+
}
|
|
45
|
+
const nextItems = arr.slice();
|
|
46
|
+
nextItems[index] = next;
|
|
47
|
+
return nextItems;
|
|
48
|
+
}),
|
|
49
|
+
remove: (item) => update((arr) => arr.filter((it) => keyOf(it) !== keyOf(item))),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Hand-rolled replacement for reselect v5 `createSelector` (ADR-0002).
|
|
2
|
+
//
|
|
3
|
+
// The port initially replaced reselect with plain functions memoized only by
|
|
4
|
+
// each consumer's `createMemo` (ADR-0001), which lost *shared* memoization:
|
|
5
|
+
// every consumer re-ran the full selector chain. This module restores
|
|
6
|
+
// upstream's caching contract without the dependency:
|
|
7
|
+
//
|
|
8
|
+
// - Cache nodes live per store (WeakMap keyed on the root state object, so
|
|
9
|
+
// they are GC'd with the chart) and per primitive args (nested Maps, i.e.
|
|
10
|
+
// SameValueZero keying — `0` and `"0"` are distinct axis ids), mirroring
|
|
11
|
+
// reselect v5's `weakMapMemoize`.
|
|
12
|
+
// - A node recomputes its combiner only when one of its extracted input
|
|
13
|
+
// values changes by reference (`===`, reselect's default equality). This
|
|
14
|
+
// is sound because every slice follows the slice immutability contract:
|
|
15
|
+
// writes replace the objects along the written path.
|
|
16
|
+
// - Input selectors run tracked on EVERY evaluation — they are the sole
|
|
17
|
+
// reactive surface, so a consumer's `createMemo` subscribes identically on
|
|
18
|
+
// cache hits and misses. The combiner runs `untrack`ed and must be pure
|
|
19
|
+
// over its inputs (reselect's own contract; combiners never read state).
|
|
20
|
+
// - `resultEqualityCheck` (upstream's `memoizeOptions.resultEqualityCheck`)
|
|
21
|
+
// keeps the previous reference when a recompute produces a value-equal
|
|
22
|
+
// result, so downstream reference comparisons — and `useAppSelector`'s
|
|
23
|
+
// `createMemo` equality — stop propagation.
|
|
24
|
+
import { untrack } from "solid-js";
|
|
25
|
+
|
|
26
|
+
export type CreateSelectorOptions<Result> = {
|
|
27
|
+
/** When a recompute yields a value-equal result, return the previous reference. */
|
|
28
|
+
resultEqualityCheck?: (previous: Result, next: Result) => boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type InputSelector<State> = (state: State, ...args: never[]) => unknown;
|
|
32
|
+
|
|
33
|
+
type CacheNode = {
|
|
34
|
+
entry?: { inputs: readonly unknown[]; result: unknown };
|
|
35
|
+
children?: Map<unknown, CacheNode>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Memoizing selector factory — the Solid-native stand-in for reselect's
|
|
40
|
+
* `createSelector([inputs], combiner)`. The returned selector stays a plain
|
|
41
|
+
* function callable with or without a reactive owner; all callers of the same
|
|
42
|
+
* store share one cache node per argument combination.
|
|
43
|
+
*
|
|
44
|
+
* Input selectors must read every state path segment leading to the value they
|
|
45
|
+
* extract; the combiner must be pure over the extracted values. The returned
|
|
46
|
+
* function takes `...args: unknown[]` — callers annotate the exported const's
|
|
47
|
+
* type (e.g. `(state, axisType, axisId) => X`), which narrows this signature.
|
|
48
|
+
*
|
|
49
|
+
* Typed via a precise public overload + a loose implementation signature (the
|
|
50
|
+
* reselect approach): the body operates entirely on `unknown`, so it needs no
|
|
51
|
+
* type assertions while callers still get full input/combiner type checking.
|
|
52
|
+
*/
|
|
53
|
+
export function createSelector<
|
|
54
|
+
State extends object,
|
|
55
|
+
Inputs extends readonly InputSelector<State>[],
|
|
56
|
+
Result,
|
|
57
|
+
>(
|
|
58
|
+
inputs: readonly [...Inputs],
|
|
59
|
+
combiner: (...values: { [K in keyof Inputs]: ReturnType<Inputs[K]> }) => Result,
|
|
60
|
+
options?: CreateSelectorOptions<Result>,
|
|
61
|
+
): (state: State, ...args: unknown[]) => Result;
|
|
62
|
+
export function createSelector(
|
|
63
|
+
inputs: ReadonlyArray<(state: object, ...args: unknown[]) => unknown>,
|
|
64
|
+
combiner: (...values: unknown[]) => unknown,
|
|
65
|
+
options?: CreateSelectorOptions<unknown>,
|
|
66
|
+
): (state: object, ...args: unknown[]) => unknown {
|
|
67
|
+
const cache = new WeakMap<object, CacheNode>();
|
|
68
|
+
const resultEqualityCheck = options?.resultEqualityCheck;
|
|
69
|
+
|
|
70
|
+
return (state: object, ...args: unknown[]): unknown => {
|
|
71
|
+
let node: CacheNode = cache.get(state) ?? {};
|
|
72
|
+
cache.set(state, node);
|
|
73
|
+
for (const arg of args) {
|
|
74
|
+
const children: Map<unknown, CacheNode> = node.children ?? new Map<unknown, CacheNode>();
|
|
75
|
+
node.children = children;
|
|
76
|
+
const child: CacheNode = children.get(arg) ?? {};
|
|
77
|
+
children.set(arg, child);
|
|
78
|
+
node = child;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Tracked: the input reads are the selector's whole reactive surface.
|
|
82
|
+
const values: readonly unknown[] = inputs.map((input) => input(state, ...args));
|
|
83
|
+
|
|
84
|
+
const entry = node.entry;
|
|
85
|
+
if (entry != null && values.every((value, i) => value === entry.inputs[i])) {
|
|
86
|
+
return entry.result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const result = untrack(() => combiner(...values));
|
|
90
|
+
if (entry != null && resultEqualityCheck != null && resultEqualityCheck(entry.result, result)) {
|
|
91
|
+
entry.inputs = values;
|
|
92
|
+
return entry.result;
|
|
93
|
+
}
|
|
94
|
+
node.entry = { inputs: values, result };
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -13,21 +13,13 @@ import {
|
|
|
13
13
|
} from "./selectors/tooltipSelectors";
|
|
14
14
|
import { selectTooltipEventType } from "./selectors/selectTooltipEventType";
|
|
15
15
|
import type { RechartsStore } from "./store";
|
|
16
|
+
import { isEventThrottled } from "./isEventThrottled";
|
|
16
17
|
|
|
17
18
|
export type ExternalEventActionPayload<E = Event> = {
|
|
18
19
|
reactEvent: E;
|
|
19
20
|
handler: CategoricalChartFunc<E> | undefined;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
export type ExternalEventAction = {
|
|
23
|
-
type: "externalEvent";
|
|
24
|
-
payload: ExternalEventActionPayload;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export function externalEventAction(payload: ExternalEventActionPayload): ExternalEventAction {
|
|
28
|
-
return { type: "externalEvent", payload };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
23
|
const rafIdMap = new Map<string, number>();
|
|
32
24
|
const timeoutIdMap = new Map<string, ReturnType<typeof setTimeout>>();
|
|
33
25
|
const latestEventMap = new Map<
|
|
@@ -65,8 +57,7 @@ export function dispatchExternalEvent<E extends Event & { currentTarget: unknown
|
|
|
65
57
|
|
|
66
58
|
const state = store.state;
|
|
67
59
|
const { throttleDelay, throttledEvents } = state.eventSettings;
|
|
68
|
-
const
|
|
69
|
-
const isThrottled = eventListAsString === "all" || eventListAsString?.includes(eventType);
|
|
60
|
+
const isThrottled = isEventThrottled(throttledEvents, eventType);
|
|
70
61
|
|
|
71
62
|
const existingTimeoutId = timeoutIdMap.get(eventType);
|
|
72
63
|
if (existingTimeoutId !== undefined && (typeof throttleDelay !== "number" || !isThrottled)) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// unique `id` instead, which is the items' real identity and gives identical
|
|
12
12
|
// ordering/replacement semantics.
|
|
13
13
|
import { createStore } from "solid-js";
|
|
14
|
+
import { createCollectionActions } from "./createCollectionActions";
|
|
14
15
|
import { ChartData } from "./chartDataSlice";
|
|
15
16
|
import { AxisId } from "./cartesianAxisSlice";
|
|
16
17
|
import { DataKey } from "../util/types";
|
|
@@ -112,50 +113,36 @@ export function createGraphicalItemsSlice(
|
|
|
112
113
|
polarItems: [...initialState.polarItems],
|
|
113
114
|
});
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
addCartesianGraphicalItem(item) {
|
|
120
|
-
setState((s) => {
|
|
121
|
-
s.cartesianItems = [...s.cartesianItems, item];
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
replaceCartesianGraphicalItem({ prev, next }) {
|
|
116
|
+
// State arrays are typed ReadonlyArray (immutable external API); the collection
|
|
117
|
+
// actions reassign the whole array rather than mutate in place (see ADR-0002).
|
|
118
|
+
const cartesian = createCollectionActions<CartesianGraphicalItemSettings>(
|
|
119
|
+
(updater) =>
|
|
125
120
|
setState((s) => {
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
nextItems[index] = next;
|
|
130
|
-
s.cartesianItems = nextItems;
|
|
121
|
+
const next = updater(s.cartesianItems);
|
|
122
|
+
if (next !== s.cartesianItems) {
|
|
123
|
+
s.cartesianItems = next;
|
|
131
124
|
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
addPolarGraphicalItem(item) {
|
|
140
|
-
setState((s) => {
|
|
141
|
-
s.polarItems = [...s.polarItems, item];
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
replacePolarGraphicalItem({ prev, next }) {
|
|
125
|
+
}),
|
|
126
|
+
(it) => it.id,
|
|
127
|
+
);
|
|
128
|
+
const polar = createCollectionActions<PolarGraphicalItemSettings>(
|
|
129
|
+
(updater) =>
|
|
145
130
|
setState((s) => {
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
nextItems[index] = next;
|
|
150
|
-
s.polarItems = nextItems;
|
|
131
|
+
const next = updater(s.polarItems);
|
|
132
|
+
if (next !== s.polarItems) {
|
|
133
|
+
s.polarItems = next;
|
|
151
134
|
}
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
}),
|
|
136
|
+
(it) => it.id,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const actions: GraphicalItemsActions = {
|
|
140
|
+
addCartesianGraphicalItem: cartesian.add,
|
|
141
|
+
replaceCartesianGraphicalItem: cartesian.replace,
|
|
142
|
+
removeCartesianGraphicalItem: cartesian.remove,
|
|
143
|
+
addPolarGraphicalItem: polar.add,
|
|
144
|
+
replacePolarGraphicalItem: polar.replace,
|
|
145
|
+
removePolarGraphicalItem: polar.remove,
|
|
159
146
|
};
|
|
160
147
|
|
|
161
148
|
return { state, actions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The "is this event in the throttle allowlist" decision, shared verbatim by the
|
|
2
|
+
// mouse, keyboard, and external event middleware. Only the DECISION is shared:
|
|
3
|
+
// the timer-lifecycle downstream genuinely differs per middleware (mouse is
|
|
4
|
+
// trailing-only; keyboard and external are leading+trailing; external keys its
|
|
5
|
+
// timers per event type), so unifying the scheduling would change behavior and is
|
|
6
|
+
// deliberately left alone.
|
|
7
|
+
export function isEventThrottled(
|
|
8
|
+
throttledEvents: ReadonlyArray<string> | "all" | undefined,
|
|
9
|
+
eventName: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
return throttledEvents === "all" || (throttledEvents?.includes(eventName) ?? false);
|
|
12
|
+
}
|