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
|
@@ -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
|
|
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);
|
package/src/state/layoutSlice.ts
CHANGED
|
@@ -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
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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) {
|
package/src/state/legendSlice.ts
CHANGED
|
@@ -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
|
|
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
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
58
|
-
|
|
34
|
+
selectAxisWithScaleForGraphicalItem(state, "xAxis", id, isPanorama),
|
|
35
|
+
selectTicksForGraphicalItem(state, "xAxis", id, isPanorama),
|
|
59
36
|
false,
|
|
60
37
|
);
|
|
61
38
|
}
|
|
62
39
|
return getBandSizeOfAxis(
|
|
63
|
-
|
|
64
|
-
|
|
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 =
|
|
120
|
-
const yAxis =
|
|
121
|
-
const xAxisTicks =
|
|
122
|
-
const yAxisTicks =
|
|
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
|
-
//
|
|
1
|
+
// Ported from recharts 3.9.2 src/state/selectors/arrayEqualityCheck.ts.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
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
|
+
}
|