@eifi1/ui-kit 0.7.1 → 0.8.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/README.md +32 -17
- package/dist/chart.d.ts +3 -2
- package/dist/components/alert-banner.d.ts +59 -10
- package/dist/components/alert-banner.js +114 -8
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +3 -0
- package/dist/components/button-group.d.ts +26 -0
- package/dist/components/button-group.js +49 -0
- package/dist/components/button-group.js.map +1 -0
- package/dist/components/calculator.d.ts +3 -0
- package/dist/components/chart-zoom.d.ts +63 -14
- package/dist/components/chart-zoom.js +82 -16
- package/dist/components/chart-zoom.js.map +1 -1
- package/dist/components/chip.d.ts +67 -2
- package/dist/components/chip.js +73 -8
- package/dist/components/chip.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +120 -0
- package/dist/components/confirm-dialog.js +96 -0
- package/dist/components/confirm-dialog.js.map +1 -0
- package/dist/components/copy-button.d.ts +62 -0
- package/dist/components/copy-button.js +95 -0
- package/dist/components/copy-button.js.map +1 -0
- package/dist/components/data-table-filter-popover.d.ts +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-pagination.d.ts +5 -1
- package/dist/components/data-table-pagination.js +71 -58
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table-sort.d.ts +28 -5
- package/dist/components/data-table-sort.js +11 -7
- package/dist/components/data-table-sort.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +544 -423
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +51 -5
- package/dist/components/date-picker.js +152 -40
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/description-list.d.ts +60 -0
- package/dist/components/description-list.js +112 -0
- package/dist/components/description-list.js.map +1 -0
- package/dist/components/disclosure.d.ts +37 -2
- package/dist/components/disclosure.js +14 -5
- package/dist/components/disclosure.js.map +1 -1
- package/dist/components/facing-pair.d.ts +2 -0
- package/dist/components/file-button.d.ts +17 -1
- package/dist/components/file-button.js +8 -1
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +54 -9
- package/dist/components/file-dropzone.js +100 -70
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/floating-panel.d.ts +107 -0
- package/dist/components/floating-panel.js +206 -0
- package/dist/components/floating-panel.js.map +1 -0
- package/dist/components/full-bleed-dialog.d.ts +12 -1
- package/dist/components/full-bleed-dialog.js +28 -5
- package/dist/components/full-bleed-dialog.js.map +1 -1
- package/dist/components/modal.d.ts +6 -2
- package/dist/components/modal.js +2 -1
- package/dist/components/modal.js.map +1 -1
- package/dist/components/number-field.d.ts +3 -0
- package/dist/components/number-input.d.ts +3 -0
- package/dist/components/numpad-sheet.d.ts +3 -0
- package/dist/components/progress-bar.d.ts +54 -0
- package/dist/components/progress-bar.js +94 -0
- package/dist/components/progress-bar.js.map +1 -0
- package/dist/components/scroll-area.d.ts +53 -0
- package/dist/components/scroll-area.js +86 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/separator.d.ts +23 -0
- package/dist/components/separator.js +24 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/series-chart-ticks.d.ts +34 -1
- package/dist/components/series-chart-ticks.js +83 -1
- package/dist/components/series-chart-ticks.js.map +1 -1
- package/dist/components/series-chart.d.ts +314 -19
- package/dist/components/series-chart.js +510 -120
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/skeleton.d.ts +36 -0
- package/dist/components/skeleton.js +35 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/stat-tile.d.ts +60 -6
- package/dist/components/stat-tile.js +60 -26
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/table.d.ts +83 -0
- package/dist/components/table.js +166 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/toggle-legend.d.ts +3 -2
- package/dist/components/toggle-legend.js +1 -1
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/tree-view.d.ts +129 -0
- package/dist/components/tree-view.js +376 -0
- package/dist/components/tree-view.js.map +1 -0
- package/dist/components/treemap.d.ts +9 -2
- package/dist/components/treemap.js +6 -2
- package/dist/components/treemap.js.map +1 -1
- package/dist/components/ui.d.ts +94 -13
- package/dist/components/ui.js +111 -29
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -1
- package/dist/{data-table-filters-noy0Abvi.d.ts → data-table-filters-CF1PXqjQ.d.ts} +73 -3
- package/dist/data-table.d.ts +2 -2
- package/dist/data-table.js.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +28 -0
- package/dist/hooks/use-copy-to-clipboard.js +81 -0
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
- package/dist/hooks/use-debounce.d.ts +43 -0
- package/dist/hooks/use-debounce.js +56 -0
- package/dist/hooks/use-debounce.js.map +1 -0
- package/dist/hooks/use-file-drop.d.ts +72 -0
- package/dist/hooks/use-file-drop.js +57 -0
- package/dist/hooks/use-file-drop.js.map +1 -0
- package/dist/i18n/defaults.d.ts +3 -0
- package/dist/i18n/defaults.js +7 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -0
- package/dist/i18n/kit-labels.js +6 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +43 -0
- package/dist/i18n/locales/de-CH-informal.js +8 -0
- package/dist/i18n/locales/de-CH-informal.js.map +1 -0
- package/dist/i18n/locales/de-CH.d.ts +3 -0
- package/dist/i18n/locales/de-CH.js +1 -14
- package/dist/i18n/locales/de-CH.js.map +1 -1
- package/dist/i18n/locales/de-informal.d.ts +64 -0
- package/dist/i18n/locales/de-informal.js +37 -0
- package/dist/i18n/locales/de-informal.js.map +1 -0
- package/dist/i18n/locales/de.d.ts +3 -0
- package/dist/i18n/locales/de.js +25 -0
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +3 -0
- package/dist/i18n/locales/es.js +25 -0
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +3 -0
- package/dist/i18n/locales/fr.js +25 -0
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +3 -0
- package/dist/i18n/locales/hu.js +25 -0
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +3 -0
- package/dist/i18n/locales/it.js +25 -0
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +3 -0
- package/dist/i18n/locales/zh.js +25 -0
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/swiss.d.ts +13 -0
- package/dist/i18n/swiss.js +19 -0
- package/dist/i18n/swiss.js.map +1 -0
- package/dist/index.d.ts +25 -10
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/dates.d.ts +37 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/search/command-palette.d.ts +15 -1
- package/dist/search/command-palette.js +10 -2
- package/dist/search/command-palette.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +35 -2
- package/dist/wizard/stepper-nav.js +54 -22
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.d.ts +107 -5
- package/dist/wizard/types.js +2 -1
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.js +141 -21
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/wizard-summary.d.ts +10 -2
- package/dist/wizard/wizard-summary.js +3 -1
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/dist/wizard.d.ts +4 -1
- package/dist/wizard.js.map +1 -1
- package/package.json +1 -1
- package/src/components/alert-banner.tsx +211 -20
- package/src/components/button-group.tsx +75 -0
- package/src/components/chart-zoom.tsx +158 -20
- package/src/components/chip.tsx +160 -9
- package/src/components/confirm-dialog.tsx +242 -0
- package/src/components/copy-button.tsx +158 -0
- package/src/components/data-table-pagination.tsx +19 -6
- package/src/components/data-table-sort.ts +49 -10
- package/src/components/data-table.tsx +293 -24
- package/src/components/date-picker.tsx +262 -57
- package/src/components/description-list.tsx +174 -0
- package/src/components/disclosure.tsx +58 -5
- package/src/components/file-button.tsx +22 -2
- package/src/components/file-dropzone.tsx +198 -100
- package/src/components/floating-panel.tsx +341 -0
- package/src/components/full-bleed-dialog.tsx +53 -5
- package/src/components/modal.tsx +9 -2
- package/src/components/progress-bar.tsx +163 -0
- package/src/components/scroll-area.tsx +129 -0
- package/src/components/separator.tsx +37 -0
- package/src/components/series-chart-ticks.ts +135 -0
- package/src/components/series-chart.tsx +934 -67
- package/src/components/skeleton.tsx +65 -0
- package/src/components/stat-tile.tsx +160 -27
- package/src/components/table.tsx +263 -0
- package/src/components/toggle-legend.tsx +4 -3
- package/src/components/tree-view.tsx +589 -0
- package/src/components/treemap.tsx +13 -2
- package/src/components/ui.tsx +270 -39
- package/src/data-table.ts +2 -0
- package/src/hooks/use-copy-to-clipboard.ts +122 -0
- package/src/hooks/use-debounce.ts +105 -0
- package/src/hooks/use-file-drop.ts +123 -0
- package/src/i18n/defaults.ts +6 -0
- package/src/i18n/kit-labels.tsx +19 -0
- package/src/i18n/locales/de-CH-informal.ts +10 -0
- package/src/i18n/locales/de-CH.ts +1 -16
- package/src/i18n/locales/de-informal.ts +61 -0
- package/src/i18n/locales/de.ts +25 -0
- package/src/i18n/locales/es.ts +25 -0
- package/src/i18n/locales/fr.ts +25 -0
- package/src/i18n/locales/hu.ts +25 -0
- package/src/i18n/locales/it.ts +25 -0
- package/src/i18n/locales/zh.ts +25 -0
- package/src/i18n/swiss.ts +25 -0
- package/src/index.ts +29 -0
- package/src/lib/dates.ts +48 -0
- package/src/search/command-palette.tsx +29 -3
- package/src/wizard/stepper-nav.tsx +102 -28
- package/src/wizard/types.ts +106 -4
- package/src/wizard/use-wizard.ts +211 -31
- package/src/wizard/wizard-summary.tsx +24 -12
- package/src/wizard.ts +3 -2
|
@@ -18,7 +18,11 @@ declare const ZOOM_MIN_DRAG = 0.02;
|
|
|
18
18
|
type ZoomAxes = "both" | "x" | "y";
|
|
19
19
|
/** Which axes a drag zooms — or `null` for a drag too small to mean one, or a plot
|
|
20
20
|
* that has not been laid out yet. Direction does not matter; proportion does. */
|
|
21
|
-
declare function zoomAxesFor(dx: number, dy: number, width: number, height: number, threshold?: number
|
|
21
|
+
declare function zoomAxesFor(dx: number, dy: number, width: number, height: number, threshold?: number,
|
|
22
|
+
/** A chart that zooms ONE axis only (see {@link ZoomTarget.zoomAxes}): every drag is
|
|
23
|
+
* a band along it, however it was drawn, and a drag with no extent along it is
|
|
24
|
+
* nothing — a tall narrow drag over a bar chart names no stretch of the abscissa. */
|
|
25
|
+
only?: "x" | "y"): ZoomAxes | null;
|
|
22
26
|
/** What a drag chose, in DATA coordinates, and which axes it actually named — the
|
|
23
27
|
* caller needs the second to know which of the two it may derive from the other. */
|
|
24
28
|
interface ZoomSelection {
|
|
@@ -44,20 +48,46 @@ interface ZoomDrag {
|
|
|
44
48
|
declare function selectionFromDrag(drag: ZoomDrag, plot: {
|
|
45
49
|
width: number;
|
|
46
50
|
height: number;
|
|
47
|
-
}, xInverse: InverseScaleFunction | undefined, yInverse: (axisId: string) => InverseScaleFunction | undefined, axisIds: readonly string[]): ZoomSelection | null;
|
|
51
|
+
}, xInverse: InverseScaleFunction | undefined, yInverse: (axisId: string) => InverseScaleFunction | undefined, axisIds: readonly string[], only?: "x" | "y"): ZoomSelection | null;
|
|
52
|
+
/** One row of a zoomable chart. Loose on purpose: a row also carries what the chart
|
|
53
|
+
* does not plot — keksdose's `rawPeriod` for a drilldown, a label for a category axis —
|
|
54
|
+
* and only the finite NUMBERS in it are ever read as samples. */
|
|
55
|
+
type ZoomRow = Readonly<Record<string, unknown>>;
|
|
56
|
+
/** A series as the fit sees it. `stack` groups bars/areas drawn on top of each other
|
|
57
|
+
* (recharts' `stackId`), whose extent is their SUM, not any one of them. */
|
|
58
|
+
interface ZoomFitSeries {
|
|
59
|
+
key: string;
|
|
60
|
+
axis?: string;
|
|
61
|
+
stack?: string;
|
|
62
|
+
/** Only `"line"` matters here: recharts cannot stack a line, so a line's `stack` is
|
|
63
|
+
* ignored rather than summed into a height nothing on the chart reaches. */
|
|
64
|
+
type?: string;
|
|
65
|
+
}
|
|
48
66
|
/** What a band refit needs to know about the chart — a subset of `SeriesChart`'s own
|
|
49
67
|
* props, so a chart hands its data straight over. */
|
|
50
68
|
interface ZoomFitSource {
|
|
51
|
-
rows:
|
|
52
|
-
series:
|
|
53
|
-
|
|
54
|
-
axis?: string;
|
|
55
|
-
}[];
|
|
56
|
-
axes: {
|
|
69
|
+
rows: readonly ZoomRow[];
|
|
70
|
+
series: readonly ZoomFitSeries[];
|
|
71
|
+
axes: readonly {
|
|
57
72
|
id: string;
|
|
58
73
|
}[];
|
|
59
74
|
xKey: string;
|
|
60
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The lowest and highest value an axis DRAWS over the rows whose abscissa is inside
|
|
78
|
+
* `window` (every row when there is none) — `undefined` when it draws nothing finite.
|
|
79
|
+
*
|
|
80
|
+
* Stack-aware, and that is why it exists: a stack of three bars reaches the SUM of
|
|
81
|
+
* them, and fitting the axis to the tallest single layer (what fitting on values did)
|
|
82
|
+
* cuts the top two thirds of every stack off. Positive and negative layers are summed
|
|
83
|
+
* apart, as recharts draws them under `stackOffset="sign"` — a month with 900 income
|
|
84
|
+
* and −300 expense stacks up to 900 and down to −300, not to 600. A stacked extent
|
|
85
|
+
* therefore always contains the zero its layers stand on.
|
|
86
|
+
*
|
|
87
|
+
* `SeriesChart` fits its axes with this and the zoom refits them with it, so the two
|
|
88
|
+
* cannot disagree about how tall a stack is.
|
|
89
|
+
*/
|
|
90
|
+
declare function axisExtent(source: ZoomFitSource, axisId: string, window?: readonly [number, number]): [number, number] | undefined;
|
|
61
91
|
/**
|
|
62
92
|
* Each y axis fitted to the samples inside an x window — what a band across x leaves
|
|
63
93
|
* the axes nobody dragged showing. Zoom into a tenth of a sweep and a y axis still
|
|
@@ -106,6 +136,26 @@ interface ZoomBinding {
|
|
|
106
136
|
yDomains: Record<string, [number, number]>;
|
|
107
137
|
layer: ReactNode;
|
|
108
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Which axes a chart lets a drag zoom. `"none"` draws no drag layer and no reset.
|
|
141
|
+
* A drag on a one-axis chart is always a band along that axis (see {@link zoomAxesFor}).
|
|
142
|
+
*/
|
|
143
|
+
type ZoomAxesSetting = ZoomAxes | "none";
|
|
144
|
+
/**
|
|
145
|
+
* The zoom a chart gets when it does not say, read off what its series ARE.
|
|
146
|
+
*
|
|
147
|
+
* - Only lines: `"both"` — lenkbank's measurement plots, unchanged.
|
|
148
|
+
* - Any area: `"x"`. An area's height is a length from zero, and a y window that cuts
|
|
149
|
+
* the baseline off draws a band of 40 as three times one of 20 — so its y axis refits
|
|
150
|
+
* to the x window (still from zero), and a drag never names a y range.
|
|
151
|
+
* - Any bar: `"none"`. A bar chart is a handful of periods read one bar at a time, and
|
|
152
|
+
* in keksdose every one of them is CLICKED — to drill into a payee, a month, a budget
|
|
153
|
+
* line — which a drag layer over the plot would swallow. A chart of many bars opts
|
|
154
|
+
* back in with `zoomAxes: "x"`; a click then reports the period, not the bar.
|
|
155
|
+
*/
|
|
156
|
+
declare function defaultZoomAxes(series: readonly {
|
|
157
|
+
type?: string;
|
|
158
|
+
}[] | undefined): ZoomAxesSetting;
|
|
109
159
|
/** The props `withChartZoom` reads off the chart it wraps. */
|
|
110
160
|
interface ZoomTarget {
|
|
111
161
|
/** Default: the single axis {@link DEFAULT_Y_AXIS}. */
|
|
@@ -115,16 +165,15 @@ interface ZoomTarget {
|
|
|
115
165
|
}[];
|
|
116
166
|
/** The chart's own data, so a band can refit the axis it did not name. Optional: a
|
|
117
167
|
* chart with nothing plotted has nothing to fit to. */
|
|
118
|
-
rows?:
|
|
119
|
-
series?: readonly
|
|
120
|
-
key: string;
|
|
121
|
-
axis?: string;
|
|
122
|
-
}[];
|
|
168
|
+
rows?: readonly ZoomRow[];
|
|
169
|
+
series?: readonly ZoomFitSeries[];
|
|
123
170
|
x?: {
|
|
124
171
|
key?: string;
|
|
125
172
|
};
|
|
126
173
|
zoom?: ZoomBinding;
|
|
127
174
|
labels?: Partial<SeriesChartLabels>;
|
|
175
|
+
/** Which axes a drag may zoom. Default: {@link defaultZoomAxes} of `series`. */
|
|
176
|
+
zoomAxes?: ZoomAxesSetting;
|
|
128
177
|
}
|
|
129
178
|
/**
|
|
130
179
|
* One x window for several charts.
|
|
@@ -153,4 +202,4 @@ declare function withChartZoom<P extends ZoomTarget>(Chart: ComponentType<P>): {
|
|
|
153
202
|
displayName: string;
|
|
154
203
|
};
|
|
155
204
|
|
|
156
|
-
export { DEFAULT_Y_AXIS, NO_ZOOM, SharedXZoom, ZOOM_MIN_DRAG, ZOOM_SQUARE_ENOUGH, type ZoomAxes, type ZoomBinding, type ZoomDrag, type ZoomFitSource, type ZoomSelection, type ZoomState, type ZoomTarget, fitXToY, fitYToX, selectionFromDrag, withChartZoom, zoomAfter, zoomAxesFor, zoomDomains };
|
|
205
|
+
export { DEFAULT_Y_AXIS, NO_ZOOM, SharedXZoom, ZOOM_MIN_DRAG, ZOOM_SQUARE_ENOUGH, type ZoomAxes, type ZoomAxesSetting, type ZoomBinding, type ZoomDrag, type ZoomFitSeries, type ZoomFitSource, type ZoomRow, type ZoomSelection, type ZoomState, type ZoomTarget, axisExtent, defaultZoomAxes, fitXToY, fitYToX, selectionFromDrag, withChartZoom, zoomAfter, zoomAxesFor, zoomDomains };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
4
4
|
import {
|
|
5
5
|
usePlotArea,
|
|
6
6
|
useXAxisInverseScale,
|
|
@@ -12,10 +12,12 @@ import { DEFAULT_SERIES_CHART_LABELS } from "./series-chart-labels.js";
|
|
|
12
12
|
const DEFAULT_Y_AXIS = "y";
|
|
13
13
|
const ZOOM_SQUARE_ENOUGH = 0.5;
|
|
14
14
|
const ZOOM_MIN_DRAG = 0.02;
|
|
15
|
-
function zoomAxesFor(dx, dy, width, height, threshold = ZOOM_SQUARE_ENOUGH) {
|
|
15
|
+
function zoomAxesFor(dx, dy, width, height, threshold = ZOOM_SQUARE_ENOUGH, only) {
|
|
16
16
|
if (!(width > 0) || !(height > 0)) return null;
|
|
17
17
|
const across = Math.abs(dx) / width;
|
|
18
18
|
const down = Math.abs(dy) / height;
|
|
19
|
+
if (only === "x") return across < ZOOM_MIN_DRAG ? null : "x";
|
|
20
|
+
if (only === "y") return down < ZOOM_MIN_DRAG ? null : "y";
|
|
19
21
|
if (across < ZOOM_MIN_DRAG && down < ZOOM_MIN_DRAG) return null;
|
|
20
22
|
const longer = Math.max(across, down);
|
|
21
23
|
const shorter = Math.min(across, down);
|
|
@@ -25,8 +27,15 @@ function zoomAxesFor(dx, dy, width, height, threshold = ZOOM_SQUARE_ENOUGH) {
|
|
|
25
27
|
function ordered(a, b) {
|
|
26
28
|
return a <= b ? [a, b] : [b, a];
|
|
27
29
|
}
|
|
28
|
-
function selectionFromDrag(drag, plot, xInverse, yInverse, axisIds) {
|
|
29
|
-
const which = zoomAxesFor(
|
|
30
|
+
function selectionFromDrag(drag, plot, xInverse, yInverse, axisIds, only) {
|
|
31
|
+
const which = zoomAxesFor(
|
|
32
|
+
drag.toX - drag.fromX,
|
|
33
|
+
drag.toY - drag.fromY,
|
|
34
|
+
plot.width,
|
|
35
|
+
plot.height,
|
|
36
|
+
ZOOM_SQUARE_ENOUGH,
|
|
37
|
+
only
|
|
38
|
+
);
|
|
30
39
|
if (!which) return null;
|
|
31
40
|
const next = { which, y: {} };
|
|
32
41
|
if (which !== "y" && xInverse) {
|
|
@@ -52,7 +61,7 @@ function airy(low, high) {
|
|
|
52
61
|
return [low - air, high + air];
|
|
53
62
|
}
|
|
54
63
|
function widen(span, value) {
|
|
55
|
-
if (!Number.isFinite(value)) return span;
|
|
64
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return span;
|
|
56
65
|
if (!span) return [value, value];
|
|
57
66
|
if (value < span[0]) span[0] = value;
|
|
58
67
|
else if (value > span[1]) span[1] = value;
|
|
@@ -61,17 +70,45 @@ function widen(span, value) {
|
|
|
61
70
|
function keysOn(source, axisId) {
|
|
62
71
|
return source.series.filter((entry) => (entry.axis ?? DEFAULT_Y_AXIS) === axisId).map((entry) => entry.key);
|
|
63
72
|
}
|
|
73
|
+
const layer = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
74
|
+
function axisExtent(source, axisId, window) {
|
|
75
|
+
const mine = source.series.filter((entry) => (entry.axis ?? DEFAULT_Y_AXIS) === axisId);
|
|
76
|
+
const loose = [];
|
|
77
|
+
const stacks = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const entry of mine) {
|
|
79
|
+
if (entry.stack === void 0 || entry.type === "line" || entry.type === void 0) {
|
|
80
|
+
loose.push(entry.key);
|
|
81
|
+
} else {
|
|
82
|
+
stacks.set(entry.stack, [...stacks.get(entry.stack) ?? [], entry.key]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let span;
|
|
86
|
+
for (const row of source.rows) {
|
|
87
|
+
if (window) {
|
|
88
|
+
const at = row[source.xKey];
|
|
89
|
+
if (typeof at !== "number" || !(at >= window[0] && at <= window[1])) continue;
|
|
90
|
+
}
|
|
91
|
+
for (const key of loose) span = widen(span, row[key]);
|
|
92
|
+
for (const keys of stacks.values()) {
|
|
93
|
+
let up = 0;
|
|
94
|
+
let down = 0;
|
|
95
|
+
let any = false;
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
const value = layer(row[key]);
|
|
98
|
+
any ||= typeof row[key] === "number" && Number.isFinite(row[key]);
|
|
99
|
+
if (value >= 0) up += value;
|
|
100
|
+
else down += value;
|
|
101
|
+
}
|
|
102
|
+
if (!any) continue;
|
|
103
|
+
span = widen(widen(span, down), up);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return span;
|
|
107
|
+
}
|
|
64
108
|
function fitYToX(source, window) {
|
|
65
|
-
const [from, to] = window;
|
|
66
109
|
const fitted = {};
|
|
67
110
|
for (const axis of source.axes) {
|
|
68
|
-
const
|
|
69
|
-
let span;
|
|
70
|
-
for (const row of source.rows) {
|
|
71
|
-
const at = row[source.xKey];
|
|
72
|
-
if (!(at >= from && at <= to)) continue;
|
|
73
|
-
for (const key of keys) span = widen(span, row[key]);
|
|
74
|
-
}
|
|
111
|
+
const span = axisExtent(source, axis.id, window);
|
|
75
112
|
if (span) fitted[axis.id] = airy(span[0], span[1]);
|
|
76
113
|
}
|
|
77
114
|
return fitted;
|
|
@@ -82,7 +119,7 @@ function fitXToY(source, windows) {
|
|
|
82
119
|
for (const key of keysOn(source, axisId)) {
|
|
83
120
|
for (const row of source.rows) {
|
|
84
121
|
const value = row[key];
|
|
85
|
-
if (Number.isFinite(value) && value >= low && value <= high) {
|
|
122
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= low && value <= high) {
|
|
86
123
|
hits = widen(hits, row[source.xKey]);
|
|
87
124
|
}
|
|
88
125
|
}
|
|
@@ -102,6 +139,11 @@ function zoomDomains(state, source) {
|
|
|
102
139
|
yDomains: state.y ?? (state.x ? fitYToX(source, state.x) : {})
|
|
103
140
|
};
|
|
104
141
|
}
|
|
142
|
+
function defaultZoomAxes(series) {
|
|
143
|
+
if (series?.some((entry) => entry.type === "bar")) return "none";
|
|
144
|
+
if (series?.some((entry) => entry.type === "area")) return "x";
|
|
145
|
+
return "both";
|
|
146
|
+
}
|
|
105
147
|
const SharedX = createContext(null);
|
|
106
148
|
function SharedXZoom({ children }) {
|
|
107
149
|
const [window, set] = useState(void 0);
|
|
@@ -116,6 +158,8 @@ function withChartZoom(Chart) {
|
|
|
116
158
|
const xWindow = group ? group.window : ownX;
|
|
117
159
|
const setXWindow = group ? group.set : setOwnX;
|
|
118
160
|
const axes = props.axes ?? [{ id: DEFAULT_Y_AXIS }];
|
|
161
|
+
const setting = props.zoomAxes ?? defaultZoomAxes(props.series);
|
|
162
|
+
const only = setting === "x" || setting === "y" ? setting : void 0;
|
|
119
163
|
const source = {
|
|
120
164
|
rows: props.rows ?? [],
|
|
121
165
|
series: [...props.series ?? []],
|
|
@@ -129,12 +173,16 @@ function withChartZoom(Chart) {
|
|
|
129
173
|
setXWindow(void 0);
|
|
130
174
|
setOwnY(null);
|
|
131
175
|
};
|
|
176
|
+
if (setting === "none") {
|
|
177
|
+
return /* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsx(Chart, { ...props, zoom: { yDomains: {}, layer: null } }) });
|
|
178
|
+
}
|
|
132
179
|
const binding = {
|
|
133
180
|
...zoomDomains(state, source),
|
|
134
181
|
layer: /* @__PURE__ */ jsx(
|
|
135
182
|
ZoomLayer,
|
|
136
183
|
{
|
|
137
184
|
axisIds: axes.map((axis) => axis.id),
|
|
185
|
+
only,
|
|
138
186
|
label: labels.zoomHint,
|
|
139
187
|
onZoom: (selection) => {
|
|
140
188
|
const next = zoomAfter(state, selection, source);
|
|
@@ -167,6 +215,7 @@ function withChartZoom(Chart) {
|
|
|
167
215
|
}
|
|
168
216
|
function ZoomLayer({
|
|
169
217
|
axisIds,
|
|
218
|
+
only,
|
|
170
219
|
label,
|
|
171
220
|
onZoom,
|
|
172
221
|
onReset
|
|
@@ -175,6 +224,7 @@ function ZoomLayer({
|
|
|
175
224
|
const xInverse = useXAxisInverseScale();
|
|
176
225
|
const [scales] = useState(() => /* @__PURE__ */ new Map());
|
|
177
226
|
const [drag, setDrag] = useState(null);
|
|
227
|
+
const draggedRef = useRef(false);
|
|
178
228
|
if (!plot || plot.width <= 0 || plot.height <= 0) return null;
|
|
179
229
|
const at = (event) => {
|
|
180
230
|
const box = event.currentTarget.getBoundingClientRect();
|
|
@@ -183,10 +233,18 @@ function ZoomLayer({
|
|
|
183
233
|
const finish = () => {
|
|
184
234
|
if (!drag) return;
|
|
185
235
|
setDrag(null);
|
|
186
|
-
const selection = selectionFromDrag(drag, plot, xInverse, (id) => scales.get(id), axisIds);
|
|
236
|
+
const selection = selectionFromDrag(drag, plot, xInverse, (id) => scales.get(id), axisIds, only);
|
|
237
|
+
draggedRef.current = selection !== null;
|
|
187
238
|
if (selection) onZoom(selection);
|
|
188
239
|
};
|
|
189
|
-
const which = drag ? zoomAxesFor(
|
|
240
|
+
const which = drag ? zoomAxesFor(
|
|
241
|
+
drag.toX - drag.fromX,
|
|
242
|
+
drag.toY - drag.fromY,
|
|
243
|
+
plot.width,
|
|
244
|
+
plot.height,
|
|
245
|
+
ZOOM_SQUARE_ENOUGH,
|
|
246
|
+
only
|
|
247
|
+
) : null;
|
|
190
248
|
return /* @__PURE__ */ jsxs("g", { children: [
|
|
191
249
|
axisIds.map((id) => /* @__PURE__ */ jsx(AxisProbe, { axisId: id, scales }, id)),
|
|
192
250
|
drag && which && /* @__PURE__ */ jsx(
|
|
@@ -214,6 +272,7 @@ function ZoomLayer({
|
|
|
214
272
|
style: { cursor: "crosshair" },
|
|
215
273
|
onPointerDown: (event) => {
|
|
216
274
|
if (event.button !== 0) return;
|
|
275
|
+
draggedRef.current = false;
|
|
217
276
|
const point = at(event);
|
|
218
277
|
try {
|
|
219
278
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
@@ -228,6 +287,11 @@ function ZoomLayer({
|
|
|
228
287
|
},
|
|
229
288
|
onPointerUp: finish,
|
|
230
289
|
onPointerCancel: () => setDrag(null),
|
|
290
|
+
onClick: (event) => {
|
|
291
|
+
if (!draggedRef.current) return;
|
|
292
|
+
draggedRef.current = false;
|
|
293
|
+
event.stopPropagation();
|
|
294
|
+
},
|
|
231
295
|
onDoubleClick: onReset
|
|
232
296
|
}
|
|
233
297
|
)
|
|
@@ -252,6 +316,8 @@ export {
|
|
|
252
316
|
SharedXZoom,
|
|
253
317
|
ZOOM_MIN_DRAG,
|
|
254
318
|
ZOOM_SQUARE_ENOUGH,
|
|
319
|
+
axisExtent,
|
|
320
|
+
defaultZoomAxes,
|
|
255
321
|
fitXToY,
|
|
256
322
|
fitYToX,
|
|
257
323
|
selectionFromDrag,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/chart-zoom.tsx"],"sourcesContent":["// Drag-to-zoom for cartesian charts — the HOC, the shared x window, and the arithmetic.\n// Lifted out of lenkbank, where every plot in the app is one `SeriesChart` and zoom is\n// therefore wired in exactly once.\n//\n// **Which axes a drag zooms is read off the drag itself.** A selection that is roughly\n// square is a box: the reader framed a REGION and means both axes. A long thin one is a\n// band, and its own direction says which: a wide flat drag means \"this stretch of the\n// abscissa\", a tall narrow one \"this range of values\". Asking with a modifier key\n// instead would be asking people to remember a convention for something they have\n// already drawn.\n//\n// Squareness is measured **in fractions of the plot**, not pixels. These charts are\n// three times wider than they are tall, so a pixel-square selection is a very wide\n// slice of the data and would read as a band to anybody looking at it.\n//\n// The zoom is VIEW state and lives here, never in a query or a store: it is where\n// somebody is looking, and a chart whose data reloads should not lose it. It is cleared\n// by the reset button, by a double click, and by nothing else.\n//\n// Everything with a decision in it is a pure exported function below (`zoomAxesFor`,\n// `selectionFromDrag`, `zoomAfter`, `zoomDomains`, `fitYToX`, `fitXToY`); the\n// components are plumbing between a pointer and those.\nimport { createContext, useContext, useEffect, useState } from \"react\";\nimport type { ComponentType, Dispatch, ReactNode, SetStateAction } from \"react\";\nimport {\n usePlotArea,\n useXAxisInverseScale,\n useYAxisInverseScale,\n type InverseScaleFunction,\n} from \"recharts\";\nimport { X } from \"lucide-react\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_SERIES_CHART_LABELS, type SeriesChartLabels } from \"./series-chart-labels\";\n\n/** The y axis a series lands on when it names none — the single shared scale most\n * charts have. `SeriesChart` and the fit below agree on it by importing this. */\nexport const DEFAULT_Y_AXIS = \"y\";\n\n/* ── The arithmetic ─────────────────────────────────────────────────────── */\n\n/**\n * How square a selection has to be before it counts as a box: the shorter side\n * against the longer, both as fractions of the plot. At 0.5 a selection twice as wide\n * as it is tall is still a box and one three times as wide is a band.\n */\nexport const ZOOM_SQUARE_ENOUGH = 0.5;\n\n/** Below this a drag is a click that moved, not a selection. In fractions of the plot,\n * so it is the same gesture on a phone and on a wall display. */\nexport const ZOOM_MIN_DRAG = 0.02;\n\nexport type ZoomAxes = \"both\" | \"x\" | \"y\";\n\n/** Which axes a drag zooms — or `null` for a drag too small to mean one, or a plot\n * that has not been laid out yet. Direction does not matter; proportion does. */\nexport function zoomAxesFor(\n dx: number,\n dy: number,\n width: number,\n height: number,\n threshold: number = ZOOM_SQUARE_ENOUGH,\n): ZoomAxes | null {\n if (!(width > 0) || !(height > 0)) return null;\n const across = Math.abs(dx) / width;\n const down = Math.abs(dy) / height;\n if (across < ZOOM_MIN_DRAG && down < ZOOM_MIN_DRAG) return null;\n const longer = Math.max(across, down);\n const shorter = Math.min(across, down);\n if (shorter / longer >= threshold) return \"both\";\n return across > down ? \"x\" : \"y\";\n}\n\n/** What a drag chose, in DATA coordinates, and which axes it actually named — the\n * caller needs the second to know which of the two it may derive from the other. */\nexport interface ZoomSelection {\n which: ZoomAxes;\n x?: [number, number];\n /** One window per y axis, keyed by axis id: they are in different units. */\n y: Record<string, [number, number]>;\n}\n\n/** A drag, in the chart's own pixel coordinates. */\nexport interface ZoomDrag {\n fromX: number;\n fromY: number;\n toX: number;\n toY: number;\n}\n\n/** A pair as a domain, smallest first. Recharts wants an ascending domain whichever\n * way the drag went, and a y axis counts downward in pixels while its values count\n * upward — so both ends are read and sorted rather than one assumed to be low. */\nfunction ordered(a: number, b: number): [number, number] {\n return a <= b ? [a, b] : [b, a];\n}\n\n/**\n * A finished drag as a selection, or `null` when it selects nothing.\n *\n * `xInverse` and `yInverse(axisId)` are recharts' pixel→value functions; an axis whose\n * function is missing, or whose ends come back non-finite, is left out rather than\n * handed a NaN window.\n */\nexport function selectionFromDrag(\n drag: ZoomDrag,\n plot: { width: number; height: number },\n xInverse: InverseScaleFunction | undefined,\n yInverse: (axisId: string) => InverseScaleFunction | undefined,\n axisIds: readonly string[],\n): ZoomSelection | null {\n const which = zoomAxesFor(drag.toX - drag.fromX, drag.toY - drag.fromY, plot.width, plot.height);\n if (!which) return null;\n const next: ZoomSelection = { which, y: {} };\n if (which !== \"y\" && xInverse) {\n const from = Number(xInverse(drag.fromX));\n const to = Number(xInverse(drag.toX));\n if (Number.isFinite(from) && Number.isFinite(to)) next.x = ordered(from, to);\n }\n if (which !== \"x\") {\n for (const id of axisIds) {\n const inverse = yInverse(id);\n if (!inverse) continue;\n const from = Number(inverse(drag.fromY));\n const to = Number(inverse(drag.toY));\n if (Number.isFinite(from) && Number.isFinite(to)) next.y[id] = ordered(from, to);\n }\n }\n return next.x || Object.keys(next.y).length ? next : null;\n}\n\n/** What a band refit needs to know about the chart — a subset of `SeriesChart`'s own\n * props, so a chart hands its data straight over. */\nexport interface ZoomFitSource {\n rows: Record<string, number>[];\n series: { key: string; axis?: string }[];\n axes: { id: string }[];\n xKey: string;\n}\n\n/** How much of a refitted span to leave as air, top and bottom. Without it the\n * highest sample sits exactly on the frame, where a line is half drawn and reads as\n * clipped rather than as the maximum. */\nconst FIT_AIR = 0.05;\n\n/** A span with air around it — and a real span for a flat channel, which would\n * otherwise be a zero-height window recharts cannot scale. */\nfunction airy(low: number, high: number): [number, number] {\n const span = high - low;\n const air = span > 0 ? span * FIT_AIR : Math.max(Math.abs(high), 1) * FIT_AIR;\n return [low - air, high + air];\n}\n\n/** A running low/high pair. A pair rather than an array to take `Math.min(...)` of:\n * the spread passes one argument per sample, and V8 faults past ~125,000 of them. */\ntype Span = [number, number] | undefined;\n\n/** A pair widened by one value. A non-finite one is not a value — one NaN would\n * otherwise take the whole window with it. */\nfunction widen(span: Span, value: number): Span {\n if (!Number.isFinite(value)) return span;\n if (!span) return [value, value];\n if (value < span[0]) span[0] = value;\n else if (value > span[1]) span[1] = value;\n return span;\n}\n\n/** Which series are measured on an axis. */\nfunction keysOn(source: ZoomFitSource, axisId: string): string[] {\n return source.series\n .filter((entry) => (entry.axis ?? DEFAULT_Y_AXIS) === axisId)\n .map((entry) => entry.key);\n}\n\n/**\n * Each y axis fitted to the samples inside an x window — what a band across x leaves\n * the axes nobody dragged showing. Zoom into a tenth of a sweep and a y axis still\n * scaled to the whole run draws that tenth as a flat line, which is the one thing the\n * zoom was for; so the unnamed axes are refitted, which is what \"zoom\" means everywhere\n * else.\n *\n * An axis with nothing inside the window is left OUT rather than collapsed: a window\n * between two samples is one where the chart should keep drawing the line across.\n */\nexport function fitYToX(\n source: ZoomFitSource,\n window: readonly [number, number],\n): Record<string, [number, number]> {\n const [from, to] = window;\n const fitted: Record<string, [number, number]> = {};\n for (const axis of source.axes) {\n const keys = keysOn(source, axis.id);\n let span: Span;\n for (const row of source.rows) {\n const at = row[source.xKey];\n if (!(at >= from && at <= to)) continue;\n for (const key of keys) span = widen(span, row[key]);\n }\n if (span) fitted[axis.id] = airy(span[0], span[1]);\n }\n return fitted;\n}\n\n/**\n * The x window that holds every sample inside a set of y windows — the other direction\n * of the same idea. A channel crossing its band once gives a tight window; one that\n * oscillates through it gives back most of the sweep, which is the truthful answer.\n * `undefined` when no sample qualifies, rather than a guess.\n */\nexport function fitXToY(\n source: ZoomFitSource,\n windows: Readonly<Record<string, readonly [number, number]>>,\n): [number, number] | undefined {\n let hits: Span;\n for (const [axisId, [low, high]] of Object.entries(windows)) {\n for (const key of keysOn(source, axisId)) {\n for (const row of source.rows) {\n const value = row[key];\n if (Number.isFinite(value) && value >= low && value <= high) {\n hits = widen(hits, row[source.xKey]);\n }\n }\n }\n }\n return hits ? airy(hits[0], hits[1]) : undefined;\n}\n\n/**\n * What a chart remembers about its zoom: the x window, and the y windows the reader\n * DRAGGED. `y: null` means \"derive y from x\" — the split is the whole design: what was\n * dragged is kept, and what follows from it is recomputed on every render, so a band\n * across x refits y here and in every chart sharing the window.\n */\nexport interface ZoomState {\n x?: [number, number];\n y: Record<string, [number, number]> | null;\n}\n\nexport const NO_ZOOM: ZoomState = { x: undefined, y: null };\n\n/**\n * The state after a selection. Two band drags COMPOSE rather than the second undoing\n * the first: a band down y keeps the x window when the band holds no samples, and\n * otherwise pulls x in to where they are.\n */\nexport function zoomAfter(\n state: ZoomState,\n selection: ZoomSelection,\n source: ZoomFitSource,\n): ZoomState {\n if (selection.which === \"both\") return { x: selection.x, y: selection.y };\n // Leave y derived, so it fits itself to what is inside the new window.\n if (selection.which === \"x\") return { x: selection.x, y: null };\n return { x: fitXToY(source, selection.y) ?? state.x, y: selection.y };\n}\n\n/** The domains a chart draws for a state: the x window as is, and each y axis either\n * as dragged or fitted to the x window. `{}` means \"fit your own data\". */\nexport function zoomDomains(\n state: ZoomState,\n source: ZoomFitSource,\n): { xDomain?: [number, number]; yDomains: Record<string, [number, number]> } {\n return {\n xDomain: state.x,\n yDomains: state.y ?? (state.x ? fitYToX(source, state.x) : {}),\n };\n}\n\n/* ── The components ─────────────────────────────────────────────────────── */\n\n/** What the wrapped chart is handed. It applies the domains to its own axes and renders\n * `layer` INSIDE the recharts chart, where recharts' hooks answer. */\nexport interface ZoomBinding {\n xDomain?: [number, number];\n yDomains: Record<string, [number, number]>;\n layer: ReactNode;\n}\n\n/** The props `withChartZoom` reads off the chart it wraps. */\nexport interface ZoomTarget {\n /** Default: the single axis {@link DEFAULT_Y_AXIS}. */\n axes?: readonly { id: string; hide?: boolean }[];\n /** The chart's own data, so a band can refit the axis it did not name. Optional: a\n * chart with nothing plotted has nothing to fit to. */\n rows?: Record<string, number>[];\n series?: readonly { key: string; axis?: string }[];\n x?: { key?: string };\n zoom?: ZoomBinding;\n labels?: Partial<SeriesChartLabels>;\n}\n\nconst SharedX = createContext<{\n window?: [number, number];\n set: Dispatch<SetStateAction<[number, number] | undefined>>;\n} | null>(null);\n\n/**\n * One x window for several charts.\n *\n * A column of charts over one abscissa is one picture, and zooming one of them and not\n * the rest turns it into several pictures of different things. Every zoomable chart\n * inside this shares the x window: any drag in any of them moves all of them.\n *\n * **Only x.** The y axes stay each chart's own — they are in different units — and\n * each refits its own y to what is inside the shared window.\n */\nexport function SharedXZoom({ children }: { children: ReactNode }) {\n const [window, set] = useState<[number, number] | undefined>(undefined);\n return <SharedX.Provider value={{ window, set }}>{children}</SharedX.Provider>;\n}\n\n/**\n * Wrap a chart in drag-to-zoom.\n *\n * The chart receives a `zoom` binding: it applies `xDomain`/`yDomains` to its axes\n * (with `allowDataOverflow`, so recharts clips to the window instead of widening it\n * back out) and renders `layer` as a child of its recharts chart. A reset button\n * appears over the chart's top end corner while it is zoomed — a real button, so the\n * keyboard can undo what the pointer did.\n */\nexport function withChartZoom<P extends ZoomTarget>(Chart: ComponentType<P>) {\n function Zoomable(props: P) {\n const labels = useKitLabels(\"seriesChart\", DEFAULT_SERIES_CHART_LABELS, props.labels);\n const group = useContext(SharedX);\n const [ownX, setOwnX] = useState<[number, number] | undefined>(undefined);\n const [ownY, setOwnY] = useState<Record<string, [number, number]> | null>(null);\n const xWindow = group ? group.window : ownX;\n const setXWindow = group ? group.set : setOwnX;\n const axes = props.axes ?? [{ id: DEFAULT_Y_AXIS }];\n\n // Every axis, hidden ones included: a hidden axis still scales its lines, and a\n // line whose axis did not refit is drawn as a flat streak inside the window.\n const source: ZoomFitSource = {\n rows: props.rows ?? [],\n series: [...(props.series ?? [])],\n axes: [...axes],\n xKey: props.x?.key ?? \"x\",\n };\n const state: ZoomState = { x: xWindow, y: ownY };\n const zoomed = xWindow !== undefined || ownY !== null;\n // A chart handed no rows or no series draws its empty state, not a plot — and a\n // \"Reset zoom\" floating over \"No data\" (every line toggled off while zoomed) offers\n // to undo something the reader cannot see. The zoom itself is KEPT: it is where they\n // were looking, and it applies again the moment a line comes back. Only an array\n // that is there and empty counts; a chart that does not pass its data is not known\n // to be empty.\n const empty = props.rows?.length === 0 || props.series?.length === 0;\n\n const clear = () => {\n setXWindow(undefined);\n setOwnY(null);\n };\n\n const binding: ZoomBinding = {\n ...zoomDomains(state, source),\n layer: (\n <ZoomLayer\n axisIds={axes.map((axis) => axis.id)}\n label={labels.zoomHint}\n onZoom={(selection) => {\n const next = zoomAfter(state, selection, source);\n if (next.x !== xWindow) setXWindow(next.x);\n setOwnY(next.y);\n }}\n onReset={clear}\n />\n ),\n };\n\n return (\n <div className=\"relative\">\n <Chart {...props} zoom={binding} />\n {zoomed && !empty && (\n <button\n type=\"button\"\n onClick={clear}\n className=\"absolute end-1 top-1 z-10 inline-flex items-center gap-1 rounded border border-[var(--border)] bg-[var(--bg-surface)]/90 px-1.5 py-0.5 text-[10px] text-[var(--text-muted)] backdrop-blur transition-colors hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\"\n >\n <X aria-hidden className=\"size-3\" /> {labels.resetZoom}\n </button>\n )}\n </div>\n );\n }\n Zoomable.displayName = `withChartZoom(${Chart.displayName ?? Chart.name ?? \"Chart\"})`;\n return Zoomable;\n}\n\n/**\n * The part that lives INSIDE the recharts chart, where recharts will say where the plot\n * is and what value a pixel is.\n *\n * A transparent rectangle over the plot area that reads the drag. It does NOT stop the\n * event: recharts drives its tooltip from the same pointer move bubbling up to its own\n * wrapper, so swallowing it here would trade the tooltip for the zoom.\n */\nfunction ZoomLayer({\n axisIds,\n label,\n onZoom,\n onReset,\n}: {\n axisIds: string[];\n label: string;\n onZoom: (selection: ZoomSelection) => void;\n onReset: () => void;\n}) {\n const plot = usePlotArea();\n const xInverse = useXAxisInverseScale();\n // One probe COMPONENT per axis rather than a hook in a loop: the number of axes\n // changes as series are toggled, and a hook count that changes with the data is the\n // one thing React will not forgive.\n const [scales] = useState(() => new Map<string, InverseScaleFunction | undefined>());\n const [drag, setDrag] = useState<ZoomDrag | null>(null);\n\n if (!plot || plot.width <= 0 || plot.height <= 0) return null;\n\n const at = (event: { clientX: number; clientY: number; currentTarget: Element }) => {\n // Against the overlay's own screen box, so padding around the container cannot\n // shift every reading — plus the plot's offset, because the scales are in the\n // chart's coordinates rather than the plot's.\n const box = event.currentTarget.getBoundingClientRect();\n return { x: event.clientX - box.left + plot.x, y: event.clientY - box.top + plot.y };\n };\n\n const finish = () => {\n if (!drag) return;\n setDrag(null);\n const selection = selectionFromDrag(drag, plot, xInverse, (id) => scales.get(id), axisIds);\n if (selection) onZoom(selection);\n };\n\n // What the drag would do, shown while it is being made: a band paints the full width\n // or height, so the reader sees it is about to let the other axis refit.\n const which = drag\n ? zoomAxesFor(drag.toX - drag.fromX, drag.toY - drag.fromY, plot.width, plot.height)\n : null;\n\n return (\n <g>\n {axisIds.map((id) => (\n <AxisProbe key={id} axisId={id} scales={scales} />\n ))}\n {drag && which && (\n <rect\n x={which === \"y\" ? plot.x : Math.min(drag.fromX, drag.toX)}\n y={which === \"x\" ? plot.y : Math.min(drag.fromY, drag.toY)}\n width={which === \"y\" ? plot.width : Math.abs(drag.toX - drag.fromX)}\n height={which === \"x\" ? plot.height : Math.abs(drag.toY - drag.fromY)}\n className=\"fill-[var(--brand)]/15 stroke-[var(--brand)]\"\n strokeDasharray=\"4 3\"\n pointerEvents=\"none\"\n />\n )}\n <rect\n x={plot.x}\n y={plot.y}\n width={plot.width}\n height={plot.height}\n // `transparent`, not `none`: an unpainted shape takes no pointer events.\n fill=\"transparent\"\n role=\"application\"\n aria-label={label}\n style={{ cursor: \"crosshair\" }}\n onPointerDown={(event) => {\n if (event.button !== 0) return;\n const point = at(event);\n // Best effort: capture keeps a drag alive past the plot's edge, but a\n // pointer id the environment does not know throws — jsdom refuses them all —\n // and a zoom that threw on pointer-down would be a chart nobody could click.\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n /* the drag still works; it just stops at the edge of the plot */\n }\n setDrag({ fromX: point.x, fromY: point.y, toX: point.x, toY: point.y });\n }}\n onPointerMove={(event) => {\n if (!drag) return;\n const point = at(event);\n setDrag({ ...drag, toX: point.x, toY: point.y });\n }}\n onPointerUp={finish}\n onPointerCancel={() => setDrag(null)}\n onDoubleClick={onReset}\n />\n </g>\n );\n}\n\n/** One axis's pixel→value function, parked where the pointer handler can reach it. */\nfunction AxisProbe({\n axisId,\n scales,\n}: {\n axisId: string;\n scales: Map<string, InverseScaleFunction | undefined>;\n}) {\n const inverse = useYAxisInverseScale(axisId);\n useEffect(() => {\n scales.set(axisId, inverse);\n return () => {\n scales.delete(axisId);\n };\n }, [axisId, inverse, scales]);\n return null;\n}\n"],"mappings":";AAmTS,cAiEC,YAjED;AA7RT,SAAS,eAAe,YAAY,WAAW,gBAAgB;AAE/D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS;AAClB,SAAS,oBAAoB;AAC7B,SAAS,mCAA2D;AAI7D,MAAM,iBAAiB;AASvB,MAAM,qBAAqB;AAI3B,MAAM,gBAAgB;AAMtB,SAAS,YACd,IACA,IACA,OACA,QACA,YAAoB,oBACH;AACjB,MAAI,EAAE,QAAQ,MAAM,EAAE,SAAS,GAAI,QAAO;AAC1C,QAAM,SAAS,KAAK,IAAI,EAAE,IAAI;AAC9B,QAAM,OAAO,KAAK,IAAI,EAAE,IAAI;AAC5B,MAAI,SAAS,iBAAiB,OAAO,cAAe,QAAO;AAC3D,QAAM,SAAS,KAAK,IAAI,QAAQ,IAAI;AACpC,QAAM,UAAU,KAAK,IAAI,QAAQ,IAAI;AACrC,MAAI,UAAU,UAAU,UAAW,QAAO;AAC1C,SAAO,SAAS,OAAO,MAAM;AAC/B;AAsBA,SAAS,QAAQ,GAAW,GAA6B;AACvD,SAAO,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AAChC;AASO,SAAS,kBACd,MACA,MACA,UACA,UACA,SACsB;AACtB,QAAM,QAAQ,YAAY,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,KAAK,OAAO,KAAK,OAAO,KAAK,MAAM;AAC/F,MAAI,CAAC,MAAO,QA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AAS;AAAA,UACvD,QAAQ;AAAA,UAER;AACA,kBAAQ,EAAE,OAAO,MAAM,GAAG,OAAO,MAAM,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAAA,QACxE;AAAA,QACA,eAAe,CAAC,UAAU;AACxB,cAAI,CAAC,KAAM;AACX,gBAAM,QAAQ,GAAG,KAAK;AACtB,kBAAQ,EAAE,GAAG,MAAM,KAAK,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAAA,QACjD;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB,MAAM,QAAQ,IAAI;AAAA,QACnC,eAAe;AAAA;AAAA,IACjB;AAAA,KACF;AAEJ;AAGA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA;AACF,GAGG;AACD,QAAM,UAAU,qBAAqB,MAAM;AAC3C,YAAU,MAAM;AACd,WAAO,IAAI,QAAQ,OAAO;AAC1B,WAAO,MAAM;AACX,aAAO,OAAO,MAAM;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,QAAQ,SAAS,MAAM,CAAC;AAC5B,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/chart-zoom.tsx"],"sourcesContent":["// Drag-to-zoom for cartesian charts — the HOC, the shared x window, and the arithmetic.\n// Lifted out of lenkbank, where every plot in the app is one `SeriesChart` and zoom is\n// therefore wired in exactly once.\n//\n// **Which axes a drag zooms is read off the drag itself.** A selection that is roughly\n// square is a box: the reader framed a REGION and means both axes. A long thin one is a\n// band, and its own direction says which: a wide flat drag means \"this stretch of the\n// abscissa\", a tall narrow one \"this range of values\". Asking with a modifier key\n// instead would be asking people to remember a convention for something they have\n// already drawn.\n//\n// Squareness is measured **in fractions of the plot**, not pixels. These charts are\n// three times wider than they are tall, so a pixel-square selection is a very wide\n// slice of the data and would read as a band to anybody looking at it.\n//\n// The zoom is VIEW state and lives here, never in a query or a store: it is where\n// somebody is looking, and a chart whose data reloads should not lose it. It is cleared\n// by the reset button, by a double click, and by nothing else.\n//\n// Everything with a decision in it is a pure exported function below (`zoomAxesFor`,\n// `selectionFromDrag`, `zoomAfter`, `zoomDomains`, `fitYToX`, `fitXToY`); the\n// components are plumbing between a pointer and those.\nimport { createContext, useContext, useEffect, useRef, useState } from \"react\";\nimport type { ComponentType, Dispatch, ReactNode, SetStateAction } from \"react\";\nimport {\n usePlotArea,\n useXAxisInverseScale,\n useYAxisInverseScale,\n type InverseScaleFunction,\n} from \"recharts\";\nimport { X } from \"lucide-react\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_SERIES_CHART_LABELS, type SeriesChartLabels } from \"./series-chart-labels\";\n\n/** The y axis a series lands on when it names none — the single shared scale most\n * charts have. `SeriesChart` and the fit below agree on it by importing this. */\nexport const DEFAULT_Y_AXIS = \"y\";\n\n/* ── The arithmetic ─────────────────────────────────────────────────────── */\n\n/**\n * How square a selection has to be before it counts as a box: the shorter side\n * against the longer, both as fractions of the plot. At 0.5 a selection twice as wide\n * as it is tall is still a box and one three times as wide is a band.\n */\nexport const ZOOM_SQUARE_ENOUGH = 0.5;\n\n/** Below this a drag is a click that moved, not a selection. In fractions of the plot,\n * so it is the same gesture on a phone and on a wall display. */\nexport const ZOOM_MIN_DRAG = 0.02;\n\nexport type ZoomAxes = \"both\" | \"x\" | \"y\";\n\n/** Which axes a drag zooms — or `null` for a drag too small to mean one, or a plot\n * that has not been laid out yet. Direction does not matter; proportion does. */\nexport function zoomAxesFor(\n dx: number,\n dy: number,\n width: number,\n height: number,\n threshold: number = ZOOM_SQUARE_ENOUGH,\n /** A chart that zooms ONE axis only (see {@link ZoomTarget.zoomAxes}): every drag is\n * a band along it, however it was drawn, and a drag with no extent along it is\n * nothing — a tall narrow drag over a bar chart names no stretch of the abscissa. */\n only?: \"x\" | \"y\",\n): ZoomAxes | null {\n if (!(width > 0) || !(height > 0)) return null;\n const across = Math.abs(dx) / width;\n const down = Math.abs(dy) / height;\n if (only === \"x\") return across < ZOOM_MIN_DRAG ? null : \"x\";\n if (only === \"y\") return down < ZOOM_MIN_DRAG ? null : \"y\";\n if (across < ZOOM_MIN_DRAG && down < ZOOM_MIN_DRAG) return null;\n const longer = Math.max(across, down);\n const shorter = Math.min(across, down);\n if (shorter / longer >= threshold) return \"both\";\n return across > down ? \"x\" : \"y\";\n}\n\n/** What a drag chose, in DATA coordinates, and which axes it actually named — the\n * caller needs the second to know which of the two it may derive from the other. */\nexport interface ZoomSelection {\n which: ZoomAxes;\n x?: [number, number];\n /** One window per y axis, keyed by axis id: they are in different units. */\n y: Record<string, [number, number]>;\n}\n\n/** A drag, in the chart's own pixel coordinates. */\nexport interface ZoomDrag {\n fromX: number;\n fromY: number;\n toX: number;\n toY: number;\n}\n\n/** A pair as a domain, smallest first. Recharts wants an ascending domain whichever\n * way the drag went, and a y axis counts downward in pixels while its values count\n * upward — so both ends are read and sorted rather than one assumed to be low. */\nfunction ordered(a: number, b: number): [number, number] {\n return a <= b ? [a, b] : [b, a];\n}\n\n/**\n * A finished drag as a selection, or `null` when it selects nothing.\n *\n * `xInverse` and `yInverse(axisId)` are recharts' pixel→value functions; an axis whose\n * function is missing, or whose ends come back non-finite, is left out rather than\n * handed a NaN window.\n */\nexport function selectionFromDrag(\n drag: ZoomDrag,\n plot: { width: number; height: number },\n xInverse: InverseScaleFunction | undefined,\n yInverse: (axisId: string) => InverseScaleFunction | undefined,\n axisIds: readonly string[],\n only?: \"x\" | \"y\",\n): ZoomSelection | null {\n const which = zoomAxesFor(\n drag.toX - drag.fromX,\n drag.toY - drag.fromY,\n plot.width,\n plot.height,\n ZOOM_SQUARE_ENOUGH,\n only,\n );\n if (!which) return null;\n const next: ZoomSelection = { which, y: {} };\n if (which !== \"y\" && xInverse) {\n const from = Number(xInverse(drag.fromX));\n const to = Number(xInverse(drag.toX));\n if (Number.isFinite(from) && Number.isFinite(to)) next.x = ordered(from, to);\n }\n if (which !== \"x\") {\n for (const id of axisIds) {\n const inverse = yInverse(id);\n if (!inverse) continue;\n const from = Number(inverse(drag.fromY));\n const to = Number(inverse(drag.toY));\n if (Number.isFinite(from) && Number.isFinite(to)) next.y[id] = ordered(from, to);\n }\n }\n return next.x || Object.keys(next.y).length ? next : null;\n}\n\n/** One row of a zoomable chart. Loose on purpose: a row also carries what the chart\n * does not plot — keksdose's `rawPeriod` for a drilldown, a label for a category axis —\n * and only the finite NUMBERS in it are ever read as samples. */\nexport type ZoomRow = Readonly<Record<string, unknown>>;\n\n/** A series as the fit sees it. `stack` groups bars/areas drawn on top of each other\n * (recharts' `stackId`), whose extent is their SUM, not any one of them. */\nexport interface ZoomFitSeries {\n key: string;\n axis?: string;\n stack?: string;\n /** Only `\"line\"` matters here: recharts cannot stack a line, so a line's `stack` is\n * ignored rather than summed into a height nothing on the chart reaches. */\n type?: string;\n}\n\n/** What a band refit needs to know about the chart — a subset of `SeriesChart`'s own\n * props, so a chart hands its data straight over. */\nexport interface ZoomFitSource {\n rows: readonly ZoomRow[];\n series: readonly ZoomFitSeries[];\n axes: readonly { id: string }[];\n xKey: string;\n}\n\n/** How much of a refitted span to leave as air, top and bottom. Without it the\n * highest sample sits exactly on the frame, where a line is half drawn and reads as\n * clipped rather than as the maximum. */\nconst FIT_AIR = 0.05;\n\n/** A span with air around it — and a real span for a flat channel, which would\n * otherwise be a zero-height window recharts cannot scale. */\nfunction airy(low: number, high: number): [number, number] {\n const span = high - low;\n const air = span > 0 ? span * FIT_AIR : Math.max(Math.abs(high), 1) * FIT_AIR;\n return [low - air, high + air];\n}\n\n/** A running low/high pair. A pair rather than an array to take `Math.min(...)` of:\n * the spread passes one argument per sample, and V8 faults past ~125,000 of them. */\ntype Span = [number, number] | undefined;\n\n/** A pair widened by one value. A non-finite one is not a value — one NaN would\n * otherwise take the whole window with it. */\nfunction widen(span: Span, value: unknown): Span {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return span;\n if (!span) return [value, value];\n if (value < span[0]) span[0] = value;\n else if (value > span[1]) span[1] = value;\n return span;\n}\n\n/** Which series are measured on an axis. */\nfunction keysOn(source: ZoomFitSource, axisId: string): string[] {\n return source.series\n .filter((entry) => (entry.axis ?? DEFAULT_Y_AXIS) === axisId)\n .map((entry) => entry.key);\n}\n\n/** A row's value as a sample, or 0 for a stack's missing layer — a stacked bar with no\n * value for one series draws the rest of the stack from where that one would end. */\nconst layer = (value: unknown) => (typeof value === \"number\" && Number.isFinite(value) ? value : 0);\n\n/**\n * The lowest and highest value an axis DRAWS over the rows whose abscissa is inside\n * `window` (every row when there is none) — `undefined` when it draws nothing finite.\n *\n * Stack-aware, and that is why it exists: a stack of three bars reaches the SUM of\n * them, and fitting the axis to the tallest single layer (what fitting on values did)\n * cuts the top two thirds of every stack off. Positive and negative layers are summed\n * apart, as recharts draws them under `stackOffset=\"sign\"` — a month with 900 income\n * and −300 expense stacks up to 900 and down to −300, not to 600. A stacked extent\n * therefore always contains the zero its layers stand on.\n *\n * `SeriesChart` fits its axes with this and the zoom refits them with it, so the two\n * cannot disagree about how tall a stack is.\n */\nexport function axisExtent(\n source: ZoomFitSource,\n axisId: string,\n window?: readonly [number, number],\n): [number, number] | undefined {\n const mine = source.series.filter((entry) => (entry.axis ?? DEFAULT_Y_AXIS) === axisId);\n const loose: string[] = [];\n const stacks = new Map<string, string[]>();\n for (const entry of mine) {\n if (entry.stack === undefined || entry.type === \"line\" || entry.type === undefined) {\n loose.push(entry.key);\n } else {\n stacks.set(entry.stack, [...(stacks.get(entry.stack) ?? []), entry.key]);\n }\n }\n let span: Span;\n for (const row of source.rows) {\n if (window) {\n const at = row[source.xKey];\n if (typeof at !== \"number\" || !(at >= window[0] && at <= window[1])) continue;\n }\n for (const key of loose) span = widen(span, row[key]);\n for (const keys of stacks.values()) {\n let up = 0;\n let down = 0;\n let any = false;\n for (const key of keys) {\n const value = layer(row[key]);\n any ||= typeof row[key] === \"number\" && Number.isFinite(row[key]);\n if (value >= 0) up += value;\n else down += value;\n }\n if (!any) continue;\n span = widen(widen(span, down), up);\n }\n }\n return span;\n}\n\n/**\n * Each y axis fitted to the samples inside an x window — what a band across x leaves\n * the axes nobody dragged showing. Zoom into a tenth of a sweep and a y axis still\n * scaled to the whole run draws that tenth as a flat line, which is the one thing the\n * zoom was for; so the unnamed axes are refitted, which is what \"zoom\" means everywhere\n * else.\n *\n * An axis with nothing inside the window is left OUT rather than collapsed: a window\n * between two samples is one where the chart should keep drawing the line across.\n */\nexport function fitYToX(\n source: ZoomFitSource,\n window: readonly [number, number],\n): Record<string, [number, number]> {\n const fitted: Record<string, [number, number]> = {};\n for (const axis of source.axes) {\n const span = axisExtent(source, axis.id, window);\n if (span) fitted[axis.id] = airy(span[0], span[1]);\n }\n return fitted;\n}\n\n/**\n * The x window that holds every sample inside a set of y windows — the other direction\n * of the same idea. A channel crossing its band once gives a tight window; one that\n * oscillates through it gives back most of the sweep, which is the truthful answer.\n * `undefined` when no sample qualifies, rather than a guess.\n */\nexport function fitXToY(\n source: ZoomFitSource,\n windows: Readonly<Record<string, readonly [number, number]>>,\n): [number, number] | undefined {\n let hits: Span;\n for (const [axisId, [low, high]] of Object.entries(windows)) {\n for (const key of keysOn(source, axisId)) {\n for (const row of source.rows) {\n const value = row[key];\n if (typeof value === \"number\" && Number.isFinite(value) && value >= low && value <= high) {\n hits = widen(hits, row[source.xKey]);\n }\n }\n }\n }\n return hits ? airy(hits[0], hits[1]) : undefined;\n}\n\n/**\n * What a chart remembers about its zoom: the x window, and the y windows the reader\n * DRAGGED. `y: null` means \"derive y from x\" — the split is the whole design: what was\n * dragged is kept, and what follows from it is recomputed on every render, so a band\n * across x refits y here and in every chart sharing the window.\n */\nexport interface ZoomState {\n x?: [number, number];\n y: Record<string, [number, number]> | null;\n}\n\nexport const NO_ZOOM: ZoomState = { x: undefined, y: null };\n\n/**\n * The state after a selection. Two band drags COMPOSE rather than the second undoing\n * the first: a band down y keeps the x window when the band holds no samples, and\n * otherwise pulls x in to where they are.\n */\nexport function zoomAfter(\n state: ZoomState,\n selection: ZoomSelection,\n source: ZoomFitSource,\n): ZoomState {\n if (selection.which === \"both\") return { x: selection.x, y: selection.y };\n // Leave y derived, so it fits itself to what is inside the new window.\n if (selection.which === \"x\") return { x: selection.x, y: null };\n return { x: fitXToY(source, selection.y) ?? state.x, y: selection.y };\n}\n\n/** The domains a chart draws for a state: the x window as is, and each y axis either\n * as dragged or fitted to the x window. `{}` means \"fit your own data\". */\nexport function zoomDomains(\n state: ZoomState,\n source: ZoomFitSource,\n): { xDomain?: [number, number]; yDomains: Record<string, [number, number]> } {\n return {\n xDomain: state.x,\n yDomains: state.y ?? (state.x ? fitYToX(source, state.x) : {}),\n };\n}\n\n/* ── The components ─────────────────────────────────────────────────────── */\n\n/** What the wrapped chart is handed. It applies the domains to its own axes and renders\n * `layer` INSIDE the recharts chart, where recharts' hooks answer. */\nexport interface ZoomBinding {\n xDomain?: [number, number];\n yDomains: Record<string, [number, number]>;\n layer: ReactNode;\n}\n\n/**\n * Which axes a chart lets a drag zoom. `\"none\"` draws no drag layer and no reset.\n * A drag on a one-axis chart is always a band along that axis (see {@link zoomAxesFor}).\n */\nexport type ZoomAxesSetting = ZoomAxes | \"none\";\n\n/**\n * The zoom a chart gets when it does not say, read off what its series ARE.\n *\n * - Only lines: `\"both\"` — lenkbank's measurement plots, unchanged.\n * - Any area: `\"x\"`. An area's height is a length from zero, and a y window that cuts\n * the baseline off draws a band of 40 as three times one of 20 — so its y axis refits\n * to the x window (still from zero), and a drag never names a y range.\n * - Any bar: `\"none\"`. A bar chart is a handful of periods read one bar at a time, and\n * in keksdose every one of them is CLICKED — to drill into a payee, a month, a budget\n * line — which a drag layer over the plot would swallow. A chart of many bars opts\n * back in with `zoomAxes: \"x\"`; a click then reports the period, not the bar.\n */\nexport function defaultZoomAxes(series: readonly { type?: string }[] | undefined): ZoomAxesSetting {\n if (series?.some((entry) => entry.type === \"bar\")) return \"none\";\n if (series?.some((entry) => entry.type === \"area\")) return \"x\";\n return \"both\";\n}\n\n/** The props `withChartZoom` reads off the chart it wraps. */\nexport interface ZoomTarget {\n /** Default: the single axis {@link DEFAULT_Y_AXIS}. */\n axes?: readonly { id: string; hide?: boolean }[];\n /** The chart's own data, so a band can refit the axis it did not name. Optional: a\n * chart with nothing plotted has nothing to fit to. */\n rows?: readonly ZoomRow[];\n series?: readonly ZoomFitSeries[];\n x?: { key?: string };\n zoom?: ZoomBinding;\n labels?: Partial<SeriesChartLabels>;\n /** Which axes a drag may zoom. Default: {@link defaultZoomAxes} of `series`. */\n zoomAxes?: ZoomAxesSetting;\n}\n\nconst SharedX = createContext<{\n window?: [number, number];\n set: Dispatch<SetStateAction<[number, number] | undefined>>;\n} | null>(null);\n\n/**\n * One x window for several charts.\n *\n * A column of charts over one abscissa is one picture, and zooming one of them and not\n * the rest turns it into several pictures of different things. Every zoomable chart\n * inside this shares the x window: any drag in any of them moves all of them.\n *\n * **Only x.** The y axes stay each chart's own — they are in different units — and\n * each refits its own y to what is inside the shared window.\n */\nexport function SharedXZoom({ children }: { children: ReactNode }) {\n const [window, set] = useState<[number, number] | undefined>(undefined);\n return <SharedX.Provider value={{ window, set }}>{children}</SharedX.Provider>;\n}\n\n/**\n * Wrap a chart in drag-to-zoom.\n *\n * The chart receives a `zoom` binding: it applies `xDomain`/`yDomains` to its axes\n * (with `allowDataOverflow`, so recharts clips to the window instead of widening it\n * back out) and renders `layer` as a child of its recharts chart. A reset button\n * appears over the chart's top end corner while it is zoomed — a real button, so the\n * keyboard can undo what the pointer did.\n */\nexport function withChartZoom<P extends ZoomTarget>(Chart: ComponentType<P>) {\n function Zoomable(props: P) {\n const labels = useKitLabels(\"seriesChart\", DEFAULT_SERIES_CHART_LABELS, props.labels);\n const group = useContext(SharedX);\n const [ownX, setOwnX] = useState<[number, number] | undefined>(undefined);\n const [ownY, setOwnY] = useState<Record<string, [number, number]> | null>(null);\n const xWindow = group ? group.window : ownX;\n const setXWindow = group ? group.set : setOwnX;\n const axes = props.axes ?? [{ id: DEFAULT_Y_AXIS }];\n const setting = props.zoomAxes ?? defaultZoomAxes(props.series);\n const only = setting === \"x\" || setting === \"y\" ? setting : undefined;\n\n // Every axis, hidden ones included: a hidden axis still scales its lines, and a\n // line whose axis did not refit is drawn as a flat streak inside the window.\n const source: ZoomFitSource = {\n rows: props.rows ?? [],\n series: [...(props.series ?? [])],\n axes: [...axes],\n xKey: props.x?.key ?? \"x\",\n };\n const state: ZoomState = { x: xWindow, y: ownY };\n const zoomed = xWindow !== undefined || ownY !== null;\n // A chart handed no rows or no series draws its empty state, not a plot — and a\n // \"Reset zoom\" floating over \"No data\" (every line toggled off while zoomed) offers\n // to undo something the reader cannot see. The zoom itself is KEPT: it is where they\n // were looking, and it applies again the moment a line comes back. Only an array\n // that is there and empty counts; a chart that does not pass its data is not known\n // to be empty.\n const empty = props.rows?.length === 0 || props.series?.length === 0;\n\n const clear = () => {\n setXWindow(undefined);\n setOwnY(null);\n };\n\n // Switched off, the chart still gets a binding — with no window and no layer — so a\n // chart whose series change type mid-life is not remounted by a different tree.\n if (setting === \"none\") {\n return (\n <div className=\"relative\">\n <Chart {...props} zoom={{ yDomains: {}, layer: null }} />\n </div>\n );\n }\n\n const binding: ZoomBinding = {\n ...zoomDomains(state, source),\n layer: (\n <ZoomLayer\n axisIds={axes.map((axis) => axis.id)}\n only={only}\n label={labels.zoomHint}\n onZoom={(selection) => {\n const next = zoomAfter(state, selection, source);\n if (next.x !== xWindow) setXWindow(next.x);\n setOwnY(next.y);\n }}\n onReset={clear}\n />\n ),\n };\n\n return (\n <div className=\"relative\">\n <Chart {...props} zoom={binding} />\n {zoomed && !empty && (\n <button\n type=\"button\"\n onClick={clear}\n className=\"absolute end-1 top-1 z-10 inline-flex items-center gap-1 rounded border border-[var(--border)] bg-[var(--bg-surface)]/90 px-1.5 py-0.5 text-[10px] text-[var(--text-muted)] backdrop-blur transition-colors hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\"\n >\n <X aria-hidden className=\"size-3\" /> {labels.resetZoom}\n </button>\n )}\n </div>\n );\n }\n Zoomable.displayName = `withChartZoom(${Chart.displayName ?? Chart.name ?? \"Chart\"})`;\n return Zoomable;\n}\n\n/**\n * The part that lives INSIDE the recharts chart, where recharts will say where the plot\n * is and what value a pixel is.\n *\n * A transparent rectangle over the plot area that reads the drag. It does NOT stop the\n * event: recharts drives its tooltip from the same pointer move bubbling up to its own\n * wrapper, so swallowing it here would trade the tooltip for the zoom.\n */\nfunction ZoomLayer({\n axisIds,\n only,\n label,\n onZoom,\n onReset,\n}: {\n axisIds: string[];\n only?: \"x\" | \"y\";\n label: string;\n onZoom: (selection: ZoomSelection) => void;\n onReset: () => void;\n}) {\n const plot = usePlotArea();\n const xInverse = useXAxisInverseScale();\n // One probe COMPONENT per axis rather than a hook in a loop: the number of axes\n // changes as series are toggled, and a hook count that changes with the data is the\n // one thing React will not forgive.\n const [scales] = useState(() => new Map<string, InverseScaleFunction | undefined>());\n const [drag, setDrag] = useState<ZoomDrag | null>(null);\n // A finished drag is followed by a click on the same element, and a chart with an\n // `onClick` (keksdose opens a drilldown on one) would read the zoom as a pick.\n const draggedRef = useRef(false);\n\n if (!plot || plot.width <= 0 || plot.height <= 0) return null;\n\n const at = (event: { clientX: number; clientY: number; currentTarget: Element }) => {\n // Against the overlay's own screen box, so padding around the container cannot\n // shift every reading — plus the plot's offset, because the scales are in the\n // chart's coordinates rather than the plot's.\n const box = event.currentTarget.getBoundingClientRect();\n return { x: event.clientX - box.left + plot.x, y: event.clientY - box.top + plot.y };\n };\n\n const finish = () => {\n if (!drag) return;\n setDrag(null);\n const selection = selectionFromDrag(drag, plot, xInverse, (id) => scales.get(id), axisIds, only);\n draggedRef.current = selection !== null;\n if (selection) onZoom(selection);\n };\n\n // What the drag would do, shown while it is being made: a band paints the full width\n // or height, so the reader sees it is about to let the other axis refit.\n const which = drag\n ? zoomAxesFor(\n drag.toX - drag.fromX,\n drag.toY - drag.fromY,\n plot.width,\n plot.height,\n ZOOM_SQUARE_ENOUGH,\n only,\n )\n : null;\n\n return (\n <g>\n {axisIds.map((id) => (\n <AxisProbe key={id} axisId={id} scales={scales} />\n ))}\n {drag && which && (\n <rect\n x={which === \"y\" ? plot.x : Math.min(drag.fromX, drag.toX)}\n y={which === \"x\" ? plot.y : Math.min(drag.fromY, drag.toY)}\n width={which === \"y\" ? plot.width : Math.abs(drag.toX - drag.fromX)}\n height={which === \"x\" ? plot.height : Math.abs(drag.toY - drag.fromY)}\n className=\"fill-[var(--brand)]/15 stroke-[var(--brand)]\"\n strokeDasharray=\"4 3\"\n pointerEvents=\"none\"\n />\n )}\n <rect\n x={plot.x}\n y={plot.y}\n width={plot.width}\n height={plot.height}\n // `transparent`, not `none`: an unpainted shape takes no pointer events.\n fill=\"transparent\"\n role=\"application\"\n aria-label={label}\n style={{ cursor: \"crosshair\" }}\n onPointerDown={(event) => {\n if (event.button !== 0) return;\n draggedRef.current = false;\n const point = at(event);\n // Best effort: capture keeps a drag alive past the plot's edge, but a\n // pointer id the environment does not know throws — jsdom refuses them all —\n // and a zoom that threw on pointer-down would be a chart nobody could click.\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n /* the drag still works; it just stops at the edge of the plot */\n }\n setDrag({ fromX: point.x, fromY: point.y, toX: point.x, toY: point.y });\n }}\n onPointerMove={(event) => {\n if (!drag) return;\n const point = at(event);\n setDrag({ ...drag, toX: point.x, toY: point.y });\n }}\n onPointerUp={finish}\n onPointerCancel={() => setDrag(null)}\n onClick={(event) => {\n if (!draggedRef.current) return;\n draggedRef.current = false;\n event.stopPropagation();\n }}\n onDoubleClick={onReset}\n />\n </g>\n );\n}\n\n/** One axis's pixel→value function, parked where the pointer handler can reach it. */\nfunction AxisProbe({\n axisId,\n scales,\n}: {\n axisId: string;\n scales: Map<string, InverseScaleFunction | undefined>;\n}) {\n const inverse = useYAxisInverseScale(axisId);\n useEffect(() => {\n scales.set(axisId, inverse);\n return () => {\n scales.delete(axisId);\n };\n }, [axisId, inverse, scales]);\n return null;\n}\n"],"mappings":";AA6ZS,cA8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,YAAY;AAAA,QAC7B,eAAe,CAAC,UAAU;AACxB,cAAI,MAAM,WAAW,EAAG;AACxB,qBAAW,UAAU;AACrB,gBAAM,QAAQ,GAAG,KAAK;AAItB,cAAI;AACF,kBAAM,cAAc,kBAAkB,MAAM,SAAS;AAAA,UACvD,QAAQ;AAAA,UAER;AACA,kBAAQ,EAAE,OAAO,MAAM,GAAG,OAAO,MAAM,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAAA,QACxE;AAAA,QACA,eAAe,CAAC,UAAU;AACxB,cAAI,CAAC,KAAM;AACX,gBAAM,QAAQ,GAAG,KAAK;AACtB,kBAAQ,EAAE,GAAG,MAAM,KAAK,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAAA,QACjD;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB,MAAM,QAAQ,IAAI;AAAA,QACnC,SAAS,CAAC,UAAU;AAClB,cAAI,CAAC,WAAW,QAAS;AACzB,qBAAW,UAAU;AACrB,gBAAM,gBAAgB;AAAA,QACxB;AAAA,QACA,eAAe;AAAA;AAAA,IACjB;AAAA,KACF;AAEJ;AAGA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA;AACF,GAGG;AACD,QAAM,UAAU,qBAAqB,MAAM;AAC3C,YAAU,MAAM;AACd,WAAO,IAAI,QAAQ,OAAO;AAC1B,WAAO,MAAM;AACX,aAAO,OAAO,MAAM;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,QAAQ,SAAS,MAAM,CAAC;AAC5B,SAAO;AACT;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, KeyboardEvent, MouseEvent, ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
import { ReactNode, KeyboardEvent, Ref, ReactElement, MouseEvent, ComponentPropsWithoutRef } from 'react';
|
|
3
3
|
import { LucideIcon } from 'lucide-react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -19,10 +19,54 @@ import { LucideIcon } from 'lucide-react';
|
|
|
19
19
|
type ChipTone = "neutral" | "brand" | "danger" | "warning" | "success" | "info" | "income" | "expense";
|
|
20
20
|
/** `lg` is the 44px touch target (`min-h-11`) a phone surface wants; `md` is ~28px. */
|
|
21
21
|
type ChipSize = "sm" | "md" | "lg";
|
|
22
|
+
/**
|
|
23
|
+
* How much of the tone the chip wears.
|
|
24
|
+
*
|
|
25
|
+
* - `soft` (default): the tinted surface every chip has had.
|
|
26
|
+
* - `outline`: the tone's border and text on NO surface — keksdose's DEV badge in the
|
|
27
|
+
* account menu and kastlan's 27 shadcn `variant="outline"` badges, which sit on
|
|
28
|
+
* coloured rows where a second tint would muddy the row.
|
|
29
|
+
* - `solid`: the tone as a fill under contrasting text — the "count" pill (unread
|
|
30
|
+
* messages, open tasks). It centres its content and sets figures tabular, so a
|
|
31
|
+
* one-digit count is a round dot and "9" → "10" does not jiggle the row.
|
|
32
|
+
*/
|
|
33
|
+
type ChipVariant = "soft" | "outline" | "solid";
|
|
34
|
+
/** `pill` (default) is fully rounded; `square` has the small radius of a field or a
|
|
35
|
+
* button — for a chip that sits in a table cell or beside square controls. */
|
|
36
|
+
type ChipShape = "pill" | "square";
|
|
37
|
+
/** What {@link ChipProps.renderLink} is handed: everything the chip would have put on
|
|
38
|
+
* its own `<a>`. Spread it onto your router's link, mapping `href` to what the link
|
|
39
|
+
* calls it — `renderLink={({ href, ...p }) => <Link to={href} {...p} />}`. */
|
|
40
|
+
interface ChipLinkProps {
|
|
41
|
+
href: string;
|
|
42
|
+
/** The chip's whole look — keep it, or the pill is a bare link. */
|
|
43
|
+
className: string;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
/** The chip's forwarded ref. React 19 passes it to a function component as a prop. */
|
|
46
|
+
ref?: Ref<HTMLAnchorElement>;
|
|
47
|
+
"aria-current"?: "true";
|
|
48
|
+
id?: string;
|
|
49
|
+
title?: string;
|
|
50
|
+
[key: `aria-${string}`]: string | boolean | number | undefined;
|
|
51
|
+
[key: `data-${string}`]: unknown;
|
|
52
|
+
}
|
|
22
53
|
interface ChipBaseProps {
|
|
23
54
|
children: ReactNode;
|
|
24
55
|
tone?: ChipTone;
|
|
25
56
|
size?: ChipSize;
|
|
57
|
+
/** See {@link ChipVariant}. Default `soft`. */
|
|
58
|
+
variant?: ChipVariant;
|
|
59
|
+
/** See {@link ChipShape}. Default `pill`. */
|
|
60
|
+
shape?: ChipShape;
|
|
61
|
+
/**
|
|
62
|
+
* The uppercase, tracked "status badge" type — keksdose's ~25 PAID / DRAFT /
|
|
63
|
+
* OVERDUE / ADMIN badges, each spelling `uppercase tracking-wide text-[10px]` by
|
|
64
|
+
* hand. A flag rather than a fourth `variant` because it is TYPE, not surface: a
|
|
65
|
+
* status badge is soft, outlined or solid as the row needs, and a `variant="tag"`
|
|
66
|
+
* would have had to pick one. Screen readers read the text as written, not as
|
|
67
|
+
* drawn, so write it in normal case.
|
|
68
|
+
*/
|
|
69
|
+
caps?: boolean;
|
|
26
70
|
icon?: LucideIcon;
|
|
27
71
|
/**
|
|
28
72
|
* Marks the chip as the current one — `aria-current` on a link, `aria-pressed` on a
|
|
@@ -46,6 +90,11 @@ interface ChipBaseProps {
|
|
|
46
90
|
/** Accessible name for the dismiss button. Default: `common.remove` from the
|
|
47
91
|
* {@link UiKitProvider}, else "Remove". */
|
|
48
92
|
removeLabel?: string;
|
|
93
|
+
/** Disables the × ONLY — the chip itself stays a working link or toggle. For the
|
|
94
|
+
* value that may not be removed right now (the last filter of a required set, a
|
|
95
|
+
* tag the user may read but not edit) where `disabled` would also kill the chip's
|
|
96
|
+
* own action. */
|
|
97
|
+
removeDisabled?: boolean;
|
|
49
98
|
disabled?: boolean;
|
|
50
99
|
className?: string;
|
|
51
100
|
/**
|
|
@@ -78,8 +127,24 @@ type ChipProps = ChipBaseProps & ({
|
|
|
78
127
|
/** Renders the chip as a link. Mutually exclusive with `onClick`. */
|
|
79
128
|
href?: string;
|
|
80
129
|
onClick?: never;
|
|
130
|
+
/**
|
|
131
|
+
* Renders the link for `href` — pass your router's `<Link>` here, since a
|
|
132
|
+
* plain `<a>` reloads a single-page app (keksdose's account-menu admin pill).
|
|
133
|
+
* Default: `<a>`. Ignored without `href`.
|
|
134
|
+
*
|
|
135
|
+
* A render function rather than an `as={Link}`, for three reasons. It is the
|
|
136
|
+
* API `StatTile` already has (`renderLink`), so a consumer learns it once.
|
|
137
|
+
* Router links do not take `href` — react-router's takes `to` — so an `as`
|
|
138
|
+
* would either have to pass props through untyped or teach the kit about one
|
|
139
|
+
* router; here the caller maps `href` onto its own link in one line, fully
|
|
140
|
+
* typed. And it keeps `href` as THE link prop, which is what the `href` /
|
|
141
|
+
* `onClick` exclusion below is typed on: the pill is a link because it has an
|
|
142
|
+
* href, whichever element draws it.
|
|
143
|
+
*/
|
|
144
|
+
renderLink?: (props: ChipLinkProps) => ReactElement;
|
|
81
145
|
} | {
|
|
82
146
|
href?: never;
|
|
147
|
+
renderLink?: never;
|
|
83
148
|
/** Renders the chip as a toggle button. Mutually exclusive with `href`. Receives
|
|
84
149
|
* the click, so a chip inside a clickable row can `stopPropagation()`. */
|
|
85
150
|
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
@@ -160,4 +225,4 @@ interface ChipInputProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange
|
|
|
160
225
|
*/
|
|
161
226
|
declare function ChipInput({ value, onChange, placeholder, label, ariaLabel, validate, separators, allowDuplicates, max, tone, size, disabled, invalid, error, labels, className, "aria-label": ariaLabelAttr, ...rest }: ChipInputProps): react.JSX.Element;
|
|
162
227
|
|
|
163
|
-
export { Chip, ChipInput, type ChipInputLabels, type ChipInputProps, type ChipProps, type ChipSize, type ChipTone, DEFAULT_CHIP_INPUT_LABELS, resolveChipInputLabels };
|
|
228
|
+
export { Chip, ChipInput, type ChipInputLabels, type ChipInputProps, type ChipLinkProps, type ChipProps, type ChipShape, type ChipSize, type ChipTone, type ChipVariant, DEFAULT_CHIP_INPUT_LABELS, resolveChipInputLabels };
|