@asanchez-sa/abby 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +2 -1
- package/dist/components/alert-dialog/alert-dialog.d.ts +10 -1
- package/dist/components/alert-dialog/alert-dialog.js +80 -3
- package/dist/components/badge/badge.d.ts +3 -2
- package/dist/components/badge/badge.js +27 -11
- package/dist/components/button/button.d.ts +1 -1
- package/dist/components/button/button.js +3 -2
- package/dist/components/calendar/calendar.d.ts +26 -5
- package/dist/components/calendar/calendar.js +387 -72
- package/dist/components/chart/chart.d.ts +76 -0
- package/dist/components/chart/chart.js +565 -0
- package/dist/components/chart/parts/axes.js +126 -0
- package/dist/components/chart/parts/frame.d.ts +31 -0
- package/dist/components/chart/parts/frame.js +278 -0
- package/dist/components/chart/parts/legend.d.ts +16 -0
- package/dist/components/chart/parts/legend.js +82 -0
- package/dist/components/chart/parts/points.d.ts +1 -0
- package/dist/components/chart/parts/points.js +139 -0
- package/dist/components/chart/parts/scale.js +139 -0
- package/dist/components/chart/parts/table.js +105 -0
- package/dist/components/chart/parts/types.d.ts +44 -0
- package/dist/components/chart/parts/types.js +8 -0
- package/dist/components/dialog/dialog.d.ts +9 -1
- package/dist/components/dialog/dialog.js +82 -3
- package/dist/components/field/field.d.ts +5 -1
- package/dist/components/field/field.js +25 -21
- package/dist/components/filter-chip/filter-chip.d.ts +36 -0
- package/dist/components/filter-chip/filter-chip.js +97 -0
- package/dist/components/graph/graph.d.ts +151 -0
- package/dist/components/graph/graph.js +959 -0
- package/dist/components/input/input.d.ts +8 -1
- package/dist/components/input/input.js +2 -2
- package/dist/components/meter/meter.d.ts +52 -3
- package/dist/components/meter/meter.js +535 -33
- package/dist/components/model-selector/model-selector.d.ts +38 -3
- package/dist/components/model-selector/model-selector.js +331 -73
- package/dist/components/note-editor/parts/suggestions.js +2 -2
- package/dist/components/number-input/number-input.d.ts +14 -3
- package/dist/components/number-input/number-input.js +193 -34
- package/dist/components/otp-input/otp-input.d.ts +6 -2
- package/dist/components/otp-input/otp-input.js +40 -20
- package/dist/components/sheet/sheet.js +1 -1
- package/dist/components/spinner/spinner.d.ts +7 -1
- package/dist/components/spinner/spinner.js +86 -26
- package/dist/components/switch/switch.d.ts +9 -2
- package/dist/components/switch/switch.js +23 -17
- package/dist/components/toast/toast.d.ts +19 -2
- package/dist/components/toast/toast.js +211 -49
- package/dist/components/toggle/toggle.d.ts +18 -4
- package/dist/components/toggle/toggle.js +167 -32
- package/dist/components/week-strip/week-strip.d.ts +27 -5
- package/dist/components/week-strip/week-strip.js +288 -134
- package/package.json +4 -1
- package/skills/agent-ready-ui/SKILL.md +1 -1
- package/skills/blocks/SKILL.md +1 -1
- package/skills/compose-screens/SKILL.md +97 -10
- package/skills/compose-screens/references/calendar-week.md +77 -0
- package/skills/compose-screens/references/charts-and-maps.md +183 -0
- package/skills/compose-screens/references/filter-chips.md +61 -0
- package/skills/compose-screens/references/number-units.md +52 -0
- package/skills/note-editor/SKILL.md +1 -1
- package/skills/note-status/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "./points.js";
|
|
2
|
+
import { ChartName, ChartRow, ChartSeries, ChartTexts } from "./types.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
export type ChartFrameProps = ChartName & ChartTexts & {
|
|
5
|
+
data: ChartRow[];
|
|
6
|
+
series: ChartSeries[];
|
|
7
|
+
/** The category that is the current one (today, this week): its `id` or `label`. */
|
|
8
|
+
highlight?: string;
|
|
9
|
+
/** The plot's height in px. */
|
|
10
|
+
height?: number;
|
|
11
|
+
/** Shows the value of each tick to the left of the plot. */
|
|
12
|
+
yAxis?: boolean;
|
|
13
|
+
/** Draws a line at each tick. */
|
|
14
|
+
grid?: boolean;
|
|
15
|
+
/** Options of `Intl.NumberFormat`, for the axis, the tooltip and the table. */
|
|
16
|
+
format?: Intl.NumberFormatOptions;
|
|
17
|
+
/** The locale of `format`. Defaults to the page's. */
|
|
18
|
+
locale?: string;
|
|
19
|
+
/** Shows the category labels under the plot. */
|
|
20
|
+
xAxis?: boolean;
|
|
21
|
+
/** The most x labels shown; with more categories only some get one. */
|
|
22
|
+
maxLabels?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Which categories get a label: spread evenly (`auto`), or only the first
|
|
25
|
+
* and the last (`ends`). The highlighted one is always labeled.
|
|
26
|
+
*/
|
|
27
|
+
labels?: "auto" | "ends";
|
|
28
|
+
/** Replaces the top of the scale, when two charts must share one. */
|
|
29
|
+
max?: number;
|
|
30
|
+
className?: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../../utilities/cn/index.js";
|
|
3
|
+
import { ChartGrid, ChartXAxis, ChartYAxis } from "./axes.js";
|
|
4
|
+
import { ChartTooltip, useChartTooltip } from "./points.js";
|
|
5
|
+
import { labelIndices, plotScale, rowId, valueFormatter } from "./scale.js";
|
|
6
|
+
import { ChartTable } from "./table.js";
|
|
7
|
+
import { defaultTexts } from "./types.js";
|
|
8
|
+
import { c } from "react/compiler-runtime";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
// src/components/chart/parts/frame.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Whether the app was built for production. A bundler replaces
|
|
14
|
+
* `process.env.NODE_ENV` with a string; where nothing does and `process`
|
|
15
|
+
* doesn't exist (a browser loading the module as is), reading it throws and
|
|
16
|
+
* the chart counts as in development. Read once, never during render.
|
|
17
|
+
*/
|
|
18
|
+
const production = (() => {
|
|
19
|
+
try {
|
|
20
|
+
return process.env.NODE_ENV === "production";
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
/** The width of an element in px, kept up to date as it resizes. */
|
|
26
|
+
function useWidth() {
|
|
27
|
+
const $ = c(4);
|
|
28
|
+
const [width, setWidth] = useState(0);
|
|
29
|
+
let t0;
|
|
30
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
31
|
+
t0 = () => (node) => {
|
|
32
|
+
if (!node) return;
|
|
33
|
+
setWidth(node.getBoundingClientRect().width);
|
|
34
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
35
|
+
const observer = new ResizeObserver(() => setWidth(node.getBoundingClientRect().width));
|
|
36
|
+
observer.observe(node);
|
|
37
|
+
return () => observer.disconnect();
|
|
38
|
+
};
|
|
39
|
+
$[0] = t0;
|
|
40
|
+
} else t0 = $[0];
|
|
41
|
+
const [ref] = useState(t0);
|
|
42
|
+
let t1;
|
|
43
|
+
if ($[1] !== ref || $[2] !== width) {
|
|
44
|
+
t1 = {
|
|
45
|
+
width,
|
|
46
|
+
ref
|
|
47
|
+
};
|
|
48
|
+
$[1] = ref;
|
|
49
|
+
$[2] = width;
|
|
50
|
+
$[3] = t1;
|
|
51
|
+
} else t1 = $[3];
|
|
52
|
+
return t1;
|
|
53
|
+
}
|
|
54
|
+
function ChartFrame(t0) {
|
|
55
|
+
const $ = c(45);
|
|
56
|
+
let children;
|
|
57
|
+
let className;
|
|
58
|
+
let data;
|
|
59
|
+
let domain;
|
|
60
|
+
let format;
|
|
61
|
+
let highlight;
|
|
62
|
+
let locale;
|
|
63
|
+
let max;
|
|
64
|
+
let name;
|
|
65
|
+
let series;
|
|
66
|
+
let t1;
|
|
67
|
+
let t10;
|
|
68
|
+
let t11;
|
|
69
|
+
let t12;
|
|
70
|
+
let t13;
|
|
71
|
+
let t2;
|
|
72
|
+
let t3;
|
|
73
|
+
let t4;
|
|
74
|
+
let t5;
|
|
75
|
+
let t6;
|
|
76
|
+
let t7;
|
|
77
|
+
let t8;
|
|
78
|
+
let t9;
|
|
79
|
+
if ($[0] !== t0) {
|
|
80
|
+
({data, series, highlight, height: t1, yAxis: t2, xAxis: t3, grid: t4, format, locale, maxLabels: t5, labels: t6, max, empty: t7, categoryHeader: t8, missing: t9, totalHeader: t10, stack: t11, room: t12, bottom: t13, domain, className, children, ...name} = t0);
|
|
81
|
+
$[0] = t0;
|
|
82
|
+
$[1] = children;
|
|
83
|
+
$[2] = className;
|
|
84
|
+
$[3] = data;
|
|
85
|
+
$[4] = domain;
|
|
86
|
+
$[5] = format;
|
|
87
|
+
$[6] = highlight;
|
|
88
|
+
$[7] = locale;
|
|
89
|
+
$[8] = max;
|
|
90
|
+
$[9] = name;
|
|
91
|
+
$[10] = series;
|
|
92
|
+
$[11] = t1;
|
|
93
|
+
$[12] = t10;
|
|
94
|
+
$[13] = t11;
|
|
95
|
+
$[14] = t12;
|
|
96
|
+
$[15] = t13;
|
|
97
|
+
$[16] = t2;
|
|
98
|
+
$[17] = t3;
|
|
99
|
+
$[18] = t4;
|
|
100
|
+
$[19] = t5;
|
|
101
|
+
$[20] = t6;
|
|
102
|
+
$[21] = t7;
|
|
103
|
+
$[22] = t8;
|
|
104
|
+
$[23] = t9;
|
|
105
|
+
} else {
|
|
106
|
+
children = $[1];
|
|
107
|
+
className = $[2];
|
|
108
|
+
data = $[3];
|
|
109
|
+
domain = $[4];
|
|
110
|
+
format = $[5];
|
|
111
|
+
highlight = $[6];
|
|
112
|
+
locale = $[7];
|
|
113
|
+
max = $[8];
|
|
114
|
+
name = $[9];
|
|
115
|
+
series = $[10];
|
|
116
|
+
t1 = $[11];
|
|
117
|
+
t10 = $[12];
|
|
118
|
+
t11 = $[13];
|
|
119
|
+
t12 = $[14];
|
|
120
|
+
t13 = $[15];
|
|
121
|
+
t2 = $[16];
|
|
122
|
+
t3 = $[17];
|
|
123
|
+
t4 = $[18];
|
|
124
|
+
t5 = $[19];
|
|
125
|
+
t6 = $[20];
|
|
126
|
+
t7 = $[21];
|
|
127
|
+
t8 = $[22];
|
|
128
|
+
t9 = $[23];
|
|
129
|
+
}
|
|
130
|
+
const height = t1 === void 0 ? 96 : t1;
|
|
131
|
+
const yAxis = t2 === void 0 ? true : t2;
|
|
132
|
+
const xAxis = t3 === void 0 ? true : t3;
|
|
133
|
+
const grid = t4 === void 0 ? true : t4;
|
|
134
|
+
const maxLabels = t5 === void 0 ? 8 : t5;
|
|
135
|
+
const labels = t6 === void 0 ? "auto" : t6;
|
|
136
|
+
const empty = t7 === void 0 ? defaultTexts.empty : t7;
|
|
137
|
+
const categoryHeader = t8 === void 0 ? defaultTexts.categoryHeader : t8;
|
|
138
|
+
const missing = t9 === void 0 ? defaultTexts.missing : t9;
|
|
139
|
+
const totalHeader = t10 === void 0 ? defaultTexts.totalHeader : t10;
|
|
140
|
+
const stack = t11 === void 0 ? false : t11;
|
|
141
|
+
const room = t12 === void 0 ? 0 : t12;
|
|
142
|
+
const bottom = t13 === void 0 ? 0 : t13;
|
|
143
|
+
if (!production && !name["aria-label"] && !name["aria-labelledby"]) throw new Error("A chart needs a name: pass aria-label or aria-labelledby");
|
|
144
|
+
const tooltip = useChartTooltip();
|
|
145
|
+
const plot = plotScale(data, series, height, max, {
|
|
146
|
+
stack,
|
|
147
|
+
room,
|
|
148
|
+
bottom,
|
|
149
|
+
domain
|
|
150
|
+
});
|
|
151
|
+
const { width, ref } = useWidth();
|
|
152
|
+
const text = valueFormatter(locale, format);
|
|
153
|
+
const show = (value) => text(value, missing);
|
|
154
|
+
const highlighted = highlight === void 0 ? -1 : data.findIndex((row) => rowId(row) === highlight);
|
|
155
|
+
const shown = labels === "ends" ? Array.from(/* @__PURE__ */ new Set([
|
|
156
|
+
0,
|
|
157
|
+
data.length - 1,
|
|
158
|
+
...highlighted >= 0 ? [highlighted] : []
|
|
159
|
+
])).sort(_temp) : labelIndices(data.length, maxLabels, highlighted);
|
|
160
|
+
const t14 = name["aria-label"];
|
|
161
|
+
const t15 = name["aria-labelledby"];
|
|
162
|
+
let t16;
|
|
163
|
+
if ($[24] !== t14 || $[25] !== t15) {
|
|
164
|
+
t16 = {
|
|
165
|
+
"aria-label": t14,
|
|
166
|
+
"aria-labelledby": t15
|
|
167
|
+
};
|
|
168
|
+
$[24] = t14;
|
|
169
|
+
$[25] = t15;
|
|
170
|
+
$[26] = t16;
|
|
171
|
+
} else t16 = $[26];
|
|
172
|
+
const labelled = t16;
|
|
173
|
+
const t17 = "group";
|
|
174
|
+
const t18 = "chart";
|
|
175
|
+
let t19;
|
|
176
|
+
if ($[27] !== className) {
|
|
177
|
+
t19 = cn("flex w-full min-w-0 flex-col gap-1.5", className);
|
|
178
|
+
$[27] = className;
|
|
179
|
+
$[28] = t19;
|
|
180
|
+
} else t19 = $[28];
|
|
181
|
+
const t20 = data.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
182
|
+
"data-slot": "chart-empty",
|
|
183
|
+
className: "flex items-center justify-center text-sm text-muted-foreground",
|
|
184
|
+
style: { height },
|
|
185
|
+
children: empty
|
|
186
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
187
|
+
className: "grid grid-cols-[auto_minmax(0,1fr)]",
|
|
188
|
+
children: [
|
|
189
|
+
yAxis ? /* @__PURE__ */ jsx(ChartYAxis, {
|
|
190
|
+
plot,
|
|
191
|
+
format: (value_0) => text(value_0, "")
|
|
192
|
+
}) : /* @__PURE__ */ jsx("div", {}),
|
|
193
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
194
|
+
ref,
|
|
195
|
+
"data-slot": "chart-plot",
|
|
196
|
+
width: "100%",
|
|
197
|
+
height,
|
|
198
|
+
className: "block overflow-visible",
|
|
199
|
+
children: [grid ? /* @__PURE__ */ jsx(ChartGrid, { plot }) : /* @__PURE__ */ jsx("line", {
|
|
200
|
+
"aria-hidden": "true",
|
|
201
|
+
x1: "0",
|
|
202
|
+
x2: "100%",
|
|
203
|
+
y1: plot.baseline + .5,
|
|
204
|
+
y2: plot.baseline + .5,
|
|
205
|
+
className: "stroke-border",
|
|
206
|
+
shapeRendering: "crispEdges"
|
|
207
|
+
}), children({
|
|
208
|
+
plot,
|
|
209
|
+
tooltip,
|
|
210
|
+
text: show,
|
|
211
|
+
highlighted,
|
|
212
|
+
width
|
|
213
|
+
})]
|
|
214
|
+
}),
|
|
215
|
+
xAxis ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {}), /* @__PURE__ */ jsx(ChartXAxis, {
|
|
216
|
+
labels: data.map(_temp2),
|
|
217
|
+
count: data.length,
|
|
218
|
+
shown,
|
|
219
|
+
highlighted
|
|
220
|
+
})] }) : null
|
|
221
|
+
]
|
|
222
|
+
});
|
|
223
|
+
const t21 = stack ? totalHeader : void 0;
|
|
224
|
+
let t22;
|
|
225
|
+
if ($[29] !== categoryHeader || $[30] !== data || $[31] !== labelled || $[32] !== missing || $[33] !== series || $[34] !== t21 || $[35] !== text) {
|
|
226
|
+
t22 = /* @__PURE__ */ jsx(ChartTable, {
|
|
227
|
+
rows: data,
|
|
228
|
+
series,
|
|
229
|
+
categoryHeader,
|
|
230
|
+
missing,
|
|
231
|
+
format: text,
|
|
232
|
+
name: labelled,
|
|
233
|
+
totalHeader: t21
|
|
234
|
+
});
|
|
235
|
+
$[29] = categoryHeader;
|
|
236
|
+
$[30] = data;
|
|
237
|
+
$[31] = labelled;
|
|
238
|
+
$[32] = missing;
|
|
239
|
+
$[33] = series;
|
|
240
|
+
$[34] = t21;
|
|
241
|
+
$[35] = text;
|
|
242
|
+
$[36] = t22;
|
|
243
|
+
} else t22 = $[36];
|
|
244
|
+
let t23;
|
|
245
|
+
if ($[37] !== tooltip) {
|
|
246
|
+
t23 = /* @__PURE__ */ jsx(ChartTooltip, { controller: tooltip });
|
|
247
|
+
$[37] = tooltip;
|
|
248
|
+
$[38] = t23;
|
|
249
|
+
} else t23 = $[38];
|
|
250
|
+
let t24;
|
|
251
|
+
if ($[39] !== labelled || $[40] !== t19 || $[41] !== t20 || $[42] !== t22 || $[43] !== t23) {
|
|
252
|
+
t24 = /* @__PURE__ */ jsxs("div", {
|
|
253
|
+
role: t17,
|
|
254
|
+
"data-slot": t18,
|
|
255
|
+
className: t19,
|
|
256
|
+
...labelled,
|
|
257
|
+
children: [
|
|
258
|
+
t20,
|
|
259
|
+
t22,
|
|
260
|
+
t23
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
$[39] = labelled;
|
|
264
|
+
$[40] = t19;
|
|
265
|
+
$[41] = t20;
|
|
266
|
+
$[42] = t22;
|
|
267
|
+
$[43] = t23;
|
|
268
|
+
$[44] = t24;
|
|
269
|
+
} else t24 = $[44];
|
|
270
|
+
return t24;
|
|
271
|
+
}
|
|
272
|
+
function _temp2(row_0) {
|
|
273
|
+
return row_0.label;
|
|
274
|
+
}
|
|
275
|
+
function _temp(a, b) {
|
|
276
|
+
return a - b;
|
|
277
|
+
}
|
|
278
|
+
export { ChartFrame };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChartRow, ChartSeries } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A legend: a swatch in each series' color and its name. With `data` each entry
|
|
4
|
+
* also shows what its series adds up to over all the categories. The names are
|
|
5
|
+
* in the chart's table too, so a legend is plain text for a screen reader.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ChartLegend({ series, data, format, locale, className }: {
|
|
8
|
+
series: ChartSeries[];
|
|
9
|
+
/** When given, each entry shows its series' total over these rows. */
|
|
10
|
+
data?: ChartRow[];
|
|
11
|
+
/** Options of `Intl.NumberFormat` for the totals. */
|
|
12
|
+
format?: Intl.NumberFormatOptions;
|
|
13
|
+
/** The locale of `format`. Defaults to the page's. */
|
|
14
|
+
locale?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../../utilities/cn/index.js";
|
|
3
|
+
import { seriesColor, stackTotal, valueFormatter } from "./scale.js";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/chart/parts/legend.tsx
|
|
7
|
+
/** The total of one series over every category. */
|
|
8
|
+
function seriesTotal(data, series) {
|
|
9
|
+
return data.reduce((sum, row) => sum + stackTotal(row, [series]), 0);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A legend: a swatch in each series' color and its name. With `data` each entry
|
|
13
|
+
* also shows what its series adds up to over all the categories. The names are
|
|
14
|
+
* in the chart's table too, so a legend is plain text for a screen reader.
|
|
15
|
+
*/
|
|
16
|
+
function ChartLegend(t0) {
|
|
17
|
+
const $ = c(14);
|
|
18
|
+
const { series, data, format, locale, className } = t0;
|
|
19
|
+
let t1;
|
|
20
|
+
let t2;
|
|
21
|
+
let t3;
|
|
22
|
+
if ($[0] !== className || $[1] !== data || $[2] !== format || $[3] !== locale || $[4] !== series) {
|
|
23
|
+
const text = valueFormatter(locale, format);
|
|
24
|
+
t1 = "chart-legend";
|
|
25
|
+
if ($[8] !== className) {
|
|
26
|
+
t2 = cn("flex flex-wrap items-center gap-x-4 gap-y-1", className);
|
|
27
|
+
$[8] = className;
|
|
28
|
+
$[9] = t2;
|
|
29
|
+
} else t2 = $[9];
|
|
30
|
+
t3 = series.map((each, index) => {
|
|
31
|
+
const color = seriesColor(each, index);
|
|
32
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
33
|
+
"data-slot": "chart-legend-item",
|
|
34
|
+
className: "flex items-center gap-1.5 text-supporting",
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ jsx("span", {
|
|
37
|
+
"aria-hidden": "true",
|
|
38
|
+
className: "size-2 shrink-0 rounded-2xs",
|
|
39
|
+
style: each.variant === "forecast" ? {
|
|
40
|
+
background: `color-mix(in srgb, ${color} 20%, transparent)`,
|
|
41
|
+
border: `1px dashed ${color}`
|
|
42
|
+
} : { background: color }
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: data ? "text-foreground" : "text-muted-foreground",
|
|
46
|
+
children: each.name
|
|
47
|
+
}),
|
|
48
|
+
data ? /* @__PURE__ */ jsx("span", {
|
|
49
|
+
className: "text-muted-foreground tabular-nums",
|
|
50
|
+
children: text(seriesTotal(data, each), "")
|
|
51
|
+
}) : null
|
|
52
|
+
]
|
|
53
|
+
}, each.key);
|
|
54
|
+
});
|
|
55
|
+
$[0] = className;
|
|
56
|
+
$[1] = data;
|
|
57
|
+
$[2] = format;
|
|
58
|
+
$[3] = locale;
|
|
59
|
+
$[4] = series;
|
|
60
|
+
$[5] = t1;
|
|
61
|
+
$[6] = t2;
|
|
62
|
+
$[7] = t3;
|
|
63
|
+
} else {
|
|
64
|
+
t1 = $[5];
|
|
65
|
+
t2 = $[6];
|
|
66
|
+
t3 = $[7];
|
|
67
|
+
}
|
|
68
|
+
let t4;
|
|
69
|
+
if ($[10] !== t1 || $[11] !== t2 || $[12] !== t3) {
|
|
70
|
+
t4 = /* @__PURE__ */ jsx("ul", {
|
|
71
|
+
"data-slot": t1,
|
|
72
|
+
className: t2,
|
|
73
|
+
children: t3
|
|
74
|
+
});
|
|
75
|
+
$[10] = t1;
|
|
76
|
+
$[11] = t2;
|
|
77
|
+
$[12] = t3;
|
|
78
|
+
$[13] = t4;
|
|
79
|
+
} else t4 = $[13];
|
|
80
|
+
return t4;
|
|
81
|
+
}
|
|
82
|
+
export { ChartLegend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Tooltip as Tooltip$1, TooltipContent as TooltipContent$1 } from "../../tooltip/tooltip.js";
|
|
3
|
+
import { cn } from "../../../utilities/cn/index.js";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { TooltipTrigger, createTooltipController } from "@ui-sdk/react/tooltip";
|
|
8
|
+
// src/components/chart/parts/points.tsx
|
|
9
|
+
/** The controller of the chart's one tooltip. */
|
|
10
|
+
function useChartTooltip() {
|
|
11
|
+
const [tooltip] = useState(_temp);
|
|
12
|
+
return tooltip;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The chart has one tab stop: the active point takes `tabIndex` 0 and the
|
|
16
|
+
* others -1. Arrows, Home and End move focus to another point; focusing one
|
|
17
|
+
* (by click too) makes it the active. The chart isn't mirrored right to left
|
|
18
|
+
* (a time axis keeps its direction), so the arrows follow the screen there
|
|
19
|
+
* too: ArrowRight goes to the point on the right.
|
|
20
|
+
*/
|
|
21
|
+
function _temp() {
|
|
22
|
+
return createTooltipController();
|
|
23
|
+
}
|
|
24
|
+
function useRovingPoints(count) {
|
|
25
|
+
const $ = c(3);
|
|
26
|
+
const [chosen, setChosen] = useState(0);
|
|
27
|
+
const active = Math.min(chosen, Math.max(0, count - 1));
|
|
28
|
+
let t0;
|
|
29
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
30
|
+
t0 = function onKeyDown(event) {
|
|
31
|
+
const points = Array.from(event.currentTarget.querySelectorAll("[data-chart-point]"));
|
|
32
|
+
const current = points.indexOf(event.target);
|
|
33
|
+
if (current < 0 || points.length === 0) return;
|
|
34
|
+
const next = event.key === "ArrowRight" ? current + 1 : event.key === "ArrowLeft" ? current - 1 : event.key === "Home" ? 0 : event.key === "End" ? points.length - 1 : null;
|
|
35
|
+
if (next === null) return;
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
points[Math.min(points.length - 1, Math.max(0, next))]?.focus();
|
|
38
|
+
};
|
|
39
|
+
$[0] = t0;
|
|
40
|
+
} else t0 = $[0];
|
|
41
|
+
const onKeyDown = t0;
|
|
42
|
+
let t1;
|
|
43
|
+
if ($[1] !== active) {
|
|
44
|
+
t1 = {
|
|
45
|
+
active,
|
|
46
|
+
setChosen,
|
|
47
|
+
onKeyDown
|
|
48
|
+
};
|
|
49
|
+
$[1] = active;
|
|
50
|
+
$[2] = t1;
|
|
51
|
+
} else t1 = $[2];
|
|
52
|
+
return t1;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The transparent area of one mark that takes the pointer and the focus. The
|
|
56
|
+
* mark is drawn under it, so a bar of zero height can still be reached. It is
|
|
57
|
+
* an image for a screen reader, named "category: value".
|
|
58
|
+
*/
|
|
59
|
+
function ChartPoint(t0) {
|
|
60
|
+
const $ = c(14);
|
|
61
|
+
const { controller, index, active, onActivate, label, x, width, height } = t0;
|
|
62
|
+
let t1;
|
|
63
|
+
if ($[0] !== height || $[1] !== width || $[2] !== x) {
|
|
64
|
+
t1 = /* @__PURE__ */ jsx("rect", {
|
|
65
|
+
x,
|
|
66
|
+
y: 0,
|
|
67
|
+
width,
|
|
68
|
+
height,
|
|
69
|
+
strokeWidth: 1
|
|
70
|
+
});
|
|
71
|
+
$[0] = height;
|
|
72
|
+
$[1] = width;
|
|
73
|
+
$[2] = x;
|
|
74
|
+
$[3] = t1;
|
|
75
|
+
} else t1 = $[3];
|
|
76
|
+
const t2 = index === active ? 0 : -1;
|
|
77
|
+
let t3;
|
|
78
|
+
if ($[4] !== index || $[5] !== onActivate) {
|
|
79
|
+
t3 = () => onActivate(index);
|
|
80
|
+
$[4] = index;
|
|
81
|
+
$[5] = onActivate;
|
|
82
|
+
$[6] = t3;
|
|
83
|
+
} else t3 = $[6];
|
|
84
|
+
let t4;
|
|
85
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
86
|
+
t4 = cn("cursor-default fill-transparent outline-none transition-colors hover:fill-accent focus-visible:fill-accent motion-reduce:transition-none", "focus-visible:stroke-(--focus-ring,var(--ring))");
|
|
87
|
+
$[7] = t4;
|
|
88
|
+
} else t4 = $[7];
|
|
89
|
+
let t5;
|
|
90
|
+
if ($[8] !== controller || $[9] !== label || $[10] !== t1 || $[11] !== t2 || $[12] !== t3) {
|
|
91
|
+
t5 = /* @__PURE__ */ jsx(TooltipTrigger, {
|
|
92
|
+
controller,
|
|
93
|
+
payload: label,
|
|
94
|
+
render: t1,
|
|
95
|
+
role: "img",
|
|
96
|
+
"aria-label": label,
|
|
97
|
+
tabIndex: t2,
|
|
98
|
+
"data-chart-point": "",
|
|
99
|
+
"data-agent-hidden": "",
|
|
100
|
+
onFocus: t3,
|
|
101
|
+
className: t4
|
|
102
|
+
});
|
|
103
|
+
$[8] = controller;
|
|
104
|
+
$[9] = label;
|
|
105
|
+
$[10] = t1;
|
|
106
|
+
$[11] = t2;
|
|
107
|
+
$[12] = t3;
|
|
108
|
+
$[13] = t5;
|
|
109
|
+
} else t5 = $[13];
|
|
110
|
+
return t5;
|
|
111
|
+
}
|
|
112
|
+
/** The one tooltip, showing the payload of the point that opened it. */
|
|
113
|
+
function ChartTooltip(t0) {
|
|
114
|
+
const $ = c(4);
|
|
115
|
+
const { controller, children } = t0;
|
|
116
|
+
let t1;
|
|
117
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
118
|
+
t1 = /* @__PURE__ */ jsx(TooltipContent$1, {
|
|
119
|
+
"data-agent-hidden": "",
|
|
120
|
+
children: _temp2
|
|
121
|
+
});
|
|
122
|
+
$[0] = t1;
|
|
123
|
+
} else t1 = $[0];
|
|
124
|
+
let t2;
|
|
125
|
+
if ($[1] !== children || $[2] !== controller) {
|
|
126
|
+
t2 = /* @__PURE__ */ jsxs(Tooltip$1, {
|
|
127
|
+
controller,
|
|
128
|
+
children: [t1, children]
|
|
129
|
+
});
|
|
130
|
+
$[1] = children;
|
|
131
|
+
$[2] = controller;
|
|
132
|
+
$[3] = t2;
|
|
133
|
+
} else t2 = $[3];
|
|
134
|
+
return t2;
|
|
135
|
+
}
|
|
136
|
+
function _temp2(state) {
|
|
137
|
+
return state.payload ?? "";
|
|
138
|
+
}
|
|
139
|
+
export { ChartPoint, ChartTooltip, useChartTooltip, useRovingPoints };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/components/chart/parts/scale.ts
|
|
2
|
+
/** Room above the tallest bar, as in Alma's chart. */
|
|
3
|
+
const topGap = 3;
|
|
4
|
+
const steps = [
|
|
5
|
+
1,
|
|
6
|
+
2,
|
|
7
|
+
2.5,
|
|
8
|
+
5,
|
|
9
|
+
10
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* A round top for the scale and its ticks: 3 to 5 evenly spaced marks from 0.
|
|
13
|
+
* A chart with nothing to show (no values, or all of them zero) still gets a
|
|
14
|
+
* scale from 0 to 1, so the grid has somewhere to be.
|
|
15
|
+
*/
|
|
16
|
+
function niceScale(largest, wanted = 4) {
|
|
17
|
+
if (!(largest > 0) || !Number.isFinite(largest)) return {
|
|
18
|
+
max: 1,
|
|
19
|
+
ticks: [
|
|
20
|
+
0,
|
|
21
|
+
.5,
|
|
22
|
+
1
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
const raw = largest / Math.max(1, wanted - 1);
|
|
26
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
27
|
+
const step = (steps.find((each) => each * power >= raw) ?? 10) * power;
|
|
28
|
+
const count = Math.ceil(largest / step - 1e-9);
|
|
29
|
+
const ticks = Array.from({ length: count + 1 }, (_, index) => Number((index * step).toPrecision(12)));
|
|
30
|
+
return {
|
|
31
|
+
max: ticks[ticks.length - 1] ?? step,
|
|
32
|
+
ticks
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** A value that can be drawn: a finite number. */
|
|
36
|
+
function present(value) {
|
|
37
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What a category adds up to when its series are stacked: the sum of its
|
|
41
|
+
* values. A value that isn't above zero adds nothing, since a bar can't go
|
|
42
|
+
* below its baseline.
|
|
43
|
+
*/
|
|
44
|
+
function stackTotal(row, series) {
|
|
45
|
+
let total = 0;
|
|
46
|
+
for (const each of series) {
|
|
47
|
+
const value = row.values[each.key];
|
|
48
|
+
if (present(value) && value > 0) total += value;
|
|
49
|
+
}
|
|
50
|
+
return total;
|
|
51
|
+
}
|
|
52
|
+
function plotScale(rows, series, height, override, options = {}) {
|
|
53
|
+
let largest = 0;
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
if (options.stack) {
|
|
56
|
+
largest = Math.max(largest, stackTotal(row, series));
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (const each of series) {
|
|
60
|
+
const value = row.values[each.key];
|
|
61
|
+
if (present(value) && value > largest) largest = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let min = 0;
|
|
65
|
+
let { max, ticks } = niceScale(override ?? largest);
|
|
66
|
+
if (options.domain) {
|
|
67
|
+
const [first, second] = options.domain;
|
|
68
|
+
min = Math.min(first, second);
|
|
69
|
+
const top = Math.max(first, second);
|
|
70
|
+
max = top > min ? top : min + 1;
|
|
71
|
+
ticks = [
|
|
72
|
+
min,
|
|
73
|
+
(min + max) / 2,
|
|
74
|
+
max
|
|
75
|
+
].map((tick) => Number(tick.toPrecision(12)));
|
|
76
|
+
}
|
|
77
|
+
const top = topGap + (options.room ?? 0);
|
|
78
|
+
const baseline = height - 1 - (options.bottom ?? 0);
|
|
79
|
+
const usable = Math.max(0, baseline - top);
|
|
80
|
+
return {
|
|
81
|
+
max,
|
|
82
|
+
ticks,
|
|
83
|
+
height,
|
|
84
|
+
top,
|
|
85
|
+
baseline,
|
|
86
|
+
min,
|
|
87
|
+
rise: (value) => {
|
|
88
|
+
if (!Number.isFinite(value) || value <= min) return 0;
|
|
89
|
+
return Math.min(usable, (value - min) / (max - min) * usable);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The category's identity, which `highlight` names. */
|
|
94
|
+
function rowId(row) {
|
|
95
|
+
return row.id ?? row.label;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The categories that get a label on the x axis: at most `wanted` of them,
|
|
99
|
+
* evenly spaced, so two never touch. The highlighted one is always labeled,
|
|
100
|
+
* and the labels next to it make room for it.
|
|
101
|
+
*/
|
|
102
|
+
function labelIndices(count, wanted, highlighted = -1) {
|
|
103
|
+
if (count <= 0) return [];
|
|
104
|
+
const stride = Math.max(1, Math.ceil(count / Math.max(1, wanted)));
|
|
105
|
+
const shown = [];
|
|
106
|
+
for (let index = 0; index < count; index += stride) {
|
|
107
|
+
if (highlighted >= 0 && index !== highlighted && Math.abs(index - highlighted) < stride) continue;
|
|
108
|
+
shown.push(index);
|
|
109
|
+
}
|
|
110
|
+
if (highlighted >= 0 && !shown.includes(highlighted)) shown.push(highlighted);
|
|
111
|
+
return shown.sort((a, b) => a - b);
|
|
112
|
+
}
|
|
113
|
+
const tokens = /* @__PURE__ */ new Set([
|
|
114
|
+
"chart-1",
|
|
115
|
+
"chart-2",
|
|
116
|
+
"chart-3",
|
|
117
|
+
"chart-4",
|
|
118
|
+
"chart-5",
|
|
119
|
+
"primary",
|
|
120
|
+
"muted",
|
|
121
|
+
"warning",
|
|
122
|
+
"success",
|
|
123
|
+
"destructive"
|
|
124
|
+
]);
|
|
125
|
+
/** The CSS color of a series: its token's variable, or the app's own color. */
|
|
126
|
+
function seriesColor(series, index) {
|
|
127
|
+
const color = series.color ?? `chart-${index % 5 + 1}`;
|
|
128
|
+
return tokens.has(color) ? `var(--${color})` : color;
|
|
129
|
+
}
|
|
130
|
+
/** The faint version of a color: Alma's tint, the color at 20%. */
|
|
131
|
+
function tintOf(color) {
|
|
132
|
+
return `color-mix(in srgb, ${color} 20%, transparent)`;
|
|
133
|
+
}
|
|
134
|
+
/** Formats a value with `Intl.NumberFormat`; a missing one is `missing`. */
|
|
135
|
+
function valueFormatter(locale, options) {
|
|
136
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
137
|
+
return (value, missing) => typeof value === "number" && Number.isFinite(value) ? formatter.format(value) : missing;
|
|
138
|
+
}
|
|
139
|
+
export { labelIndices, niceScale, plotScale, rowId, seriesColor, stackTotal, tintOf, valueFormatter };
|