@leonardaustin/ui 0.30.0 → 0.32.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/README.md +2 -0
- package/dist/components/app-shell/Sidebar.js +125 -123
- package/dist/components/app-shell/ThemeMenu.js +44 -42
- package/dist/components/charts/BarChart.d.ts +1 -1
- package/dist/components/charts/BarChart.js +39 -42
- package/dist/components/charts/StackedBarChart.js +66 -68
- package/dist/components/charts/VerticalBarChart.js +49 -51
- package/dist/components/charts/barChartUtils.d.ts +6 -7
- package/dist/components/charts/barChartUtils.js +51 -11
- package/dist/config/theme.js +49 -7
- package/dist/core.css +120 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +117 -116
- package/dist/providers/SettingsContext.d.ts +1 -1
- package/dist/providers/SettingsProvider.js +4 -2
- package/dist/providers/ThemeContext.d.ts +2 -2
- package/dist/providers/accentColors.d.ts +3 -1
- package/dist/providers/accentColors.js +20 -6
- package/dist/providers/themeClasses.js +2 -0
- package/dist/styles.css +254 -1
- package/dist/themes/studio-dark.css +68 -0
- package/dist/themes/studio-light.css +68 -0
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { mergeRefs as t } from "../../lib/mergeRefs.js";
|
|
3
3
|
import { usePortalContainer as n } from "../../hooks/usePortalContainer.js";
|
|
4
|
-
import { accentItems as r, darkThemes as i, fontOptions as a, lightThemes as
|
|
5
|
-
import { useAnchoredPopup as
|
|
6
|
-
import { useDismiss as
|
|
7
|
-
import { useSettings as
|
|
4
|
+
import { accentItems as r, darkThemes as i, fontOptions as a, lightThemes as ee, themeItems as te } from "../../config/theme.js";
|
|
5
|
+
import { useAnchoredPopup as ne } from "../../hooks/useAnchoredPopup.js";
|
|
6
|
+
import { useDismiss as o } from "../../hooks/useDismiss.js";
|
|
7
|
+
import { useSettings as s } from "../../hooks/useSettings.js";
|
|
8
|
+
import { usesThemeAccent as c } from "../../providers/accentColors.js";
|
|
8
9
|
import { useToast as l } from "../ui/Toast.js";
|
|
9
10
|
import { useApplyTheme as u } from "../../hooks/useApplyTheme.js";
|
|
10
11
|
import { Button as d } from "../ui/Button.js";
|
|
@@ -16,8 +17,8 @@ import { Toggle as g } from "../ui/Toggle.js";
|
|
|
16
17
|
import { THEME_MENU_EVENT as _ } from "./themeMenuEvents.js";
|
|
17
18
|
import { useCallback as v, useEffect as y, useMemo as b, useRef as x, useState as S } from "react";
|
|
18
19
|
import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
|
|
19
|
-
import { Monitor as E, Moon as D, Palette as
|
|
20
|
-
import { createPortal as
|
|
20
|
+
import { Monitor as E, Moon as D, Palette as re, Sun as O } from "lucide-react";
|
|
21
|
+
import { createPortal as ie } from "react-dom";
|
|
21
22
|
//#region src/components/app-shell/ThemeMenu.tsx
|
|
22
23
|
var k = [
|
|
23
24
|
{
|
|
@@ -37,10 +38,10 @@ var k = [
|
|
|
37
38
|
}
|
|
38
39
|
];
|
|
39
40
|
function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j }) {
|
|
40
|
-
let [M, N] = S(!1), P = n(), [F, I] = S(!1), L = x(null), R = b(() => t(L, A), [A]), z = x(null), B =
|
|
41
|
+
let [M, N] = S(!1), P = n(), [F, I] = S(!1), L = x(null), R = b(() => t(L, A), [A]), z = x(null), B = s(), V = u(), { toast: H } = l(), U = v(() => {
|
|
41
42
|
N(!1), I(!1);
|
|
42
43
|
}, []);
|
|
43
|
-
|
|
44
|
+
o(M, U, [z], [L], { outsideClick: !F }), ne(M, L, z, {
|
|
44
45
|
side: "bottom",
|
|
45
46
|
align: "end",
|
|
46
47
|
gap: 6,
|
|
@@ -60,7 +61,7 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
60
61
|
};
|
|
61
62
|
return document.addEventListener(_, e), () => document.removeEventListener(_, e);
|
|
62
63
|
}, [D]);
|
|
63
|
-
let { colorMode: G, setColorMode: K, preferredDarkTheme: q, preferredLightTheme: J, accentColor: Y, setAccentColor:
|
|
64
|
+
let { colorMode: G, setColorMode: K, preferredDarkTheme: q, preferredLightTheme: J, accentColor: Y, setAccentColor: ae, fontSize: oe, setFontSize: se, uiFont: ce, setUiFont: le, headingFont: ue, setHeadingFont: de, proseFont: fe, setProseFont: pe, codeFont: me, setCodeFont: he, borderRadius: ge, setBorderRadius: _e, borderWidth: ve, setBorderWidth: ye, tracking: be, setTracking: xe, lineHeight: Se, setLineHeight: Ce, density: X, setDensity: we, reducedMotion: Te, setReducedMotion: Ee, saveThemeCustomization: De, resetThemeCustomization: Oe, hasThemeOverrides: ke, isCustomized: Z, resolvedTheme: Q } = B, $ = c(Q);
|
|
64
65
|
return /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w("button", {
|
|
65
66
|
type: "button",
|
|
66
67
|
...j,
|
|
@@ -73,8 +74,8 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
73
74
|
"aria-expanded": M,
|
|
74
75
|
title: "Theme",
|
|
75
76
|
className: e("flex h-7 w-7 cursor-pointer items-center justify-center rounded transition-colors duration-[100ms]", M ? "text-accent-fg bg-accent-muted" : "text-text-tertiary hover:text-text-primary hover:bg-bg-hover", E),
|
|
76
|
-
children: /* @__PURE__ */ w(
|
|
77
|
-
}), M &&
|
|
77
|
+
children: /* @__PURE__ */ w(re, { className: "h-4 w-4" })
|
|
78
|
+
}), M && ie(/* @__PURE__ */ w("div", {
|
|
78
79
|
ref: z,
|
|
79
80
|
role: "dialog",
|
|
80
81
|
"aria-label": "Theme settings",
|
|
@@ -119,7 +120,7 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
119
120
|
children: "Light themes"
|
|
120
121
|
}), /* @__PURE__ */ w("div", {
|
|
121
122
|
className: "grid grid-cols-2 gap-2",
|
|
122
|
-
children:
|
|
123
|
+
children: ee.map((e) => /* @__PURE__ */ w(h, {
|
|
123
124
|
label: e.label,
|
|
124
125
|
icon: e.icon,
|
|
125
126
|
preview: e.preview,
|
|
@@ -131,16 +132,17 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
131
132
|
as: "h3",
|
|
132
133
|
border: !1,
|
|
133
134
|
className: "mb-2",
|
|
134
|
-
children: "Accent"
|
|
135
|
+
children: $ ? "Studio uses its own accent" : "Accent"
|
|
135
136
|
}), /* @__PURE__ */ w("div", {
|
|
136
137
|
className: "flex flex-wrap gap-1.5",
|
|
137
138
|
children: r.map((t) => /* @__PURE__ */ w("button", {
|
|
138
139
|
type: "button",
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
disabled: $,
|
|
141
|
+
onClick: () => ae(t.value),
|
|
142
|
+
className: e("h-6 w-6 cursor-pointer rounded-full transition-transform duration-[100ms] hover:scale-110 disabled:cursor-not-allowed disabled:opacity-40", !$ && Y === t.value && "ring-offset-bg-tertiary scale-110 ring-2 ring-offset-1"),
|
|
141
143
|
style: {
|
|
142
144
|
backgroundColor: t.color,
|
|
143
|
-
|
|
145
|
+
...!$ && Y === t.value ? { "--utility-ring-color": t.color } : {}
|
|
144
146
|
},
|
|
145
147
|
title: t.value.charAt(0).toUpperCase() + t.value.slice(1),
|
|
146
148
|
"aria-label": t.value
|
|
@@ -158,29 +160,29 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
158
160
|
label: "UI / Body",
|
|
159
161
|
size: "sm",
|
|
160
162
|
options: a,
|
|
161
|
-
value:
|
|
162
|
-
onValueChange: (e) =>
|
|
163
|
+
value: ce,
|
|
164
|
+
onValueChange: (e) => le(e)
|
|
163
165
|
}),
|
|
164
166
|
/* @__PURE__ */ w(p, {
|
|
165
167
|
label: "Headings",
|
|
166
168
|
size: "sm",
|
|
167
169
|
options: a,
|
|
168
|
-
value:
|
|
169
|
-
onValueChange: (e) =>
|
|
170
|
+
value: ue,
|
|
171
|
+
onValueChange: (e) => de(e)
|
|
170
172
|
}),
|
|
171
173
|
/* @__PURE__ */ w(p, {
|
|
172
174
|
label: "Prose",
|
|
173
175
|
size: "sm",
|
|
174
176
|
options: a,
|
|
175
|
-
value:
|
|
176
|
-
onValueChange: (e) =>
|
|
177
|
+
value: fe,
|
|
178
|
+
onValueChange: (e) => pe(e)
|
|
177
179
|
}),
|
|
178
180
|
/* @__PURE__ */ w(p, {
|
|
179
181
|
label: "Code",
|
|
180
182
|
size: "sm",
|
|
181
183
|
options: a,
|
|
182
|
-
value:
|
|
183
|
-
onValueChange: (e) =>
|
|
184
|
+
value: me,
|
|
185
|
+
onValueChange: (e) => he(e)
|
|
184
186
|
})
|
|
185
187
|
]
|
|
186
188
|
})] }),
|
|
@@ -191,24 +193,24 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
191
193
|
label: "Font size",
|
|
192
194
|
min: 11,
|
|
193
195
|
max: 18,
|
|
194
|
-
value:
|
|
195
|
-
onValueChange:
|
|
196
|
+
value: oe,
|
|
197
|
+
onValueChange: se,
|
|
196
198
|
showValue: !0
|
|
197
199
|
}),
|
|
198
200
|
/* @__PURE__ */ w(m, {
|
|
199
201
|
label: "Corner radius",
|
|
200
202
|
min: 0,
|
|
201
203
|
max: 16,
|
|
202
|
-
value:
|
|
203
|
-
onValueChange:
|
|
204
|
+
value: ge,
|
|
205
|
+
onValueChange: _e,
|
|
204
206
|
showValue: !0
|
|
205
207
|
}),
|
|
206
208
|
/* @__PURE__ */ w(m, {
|
|
207
209
|
label: "Border width",
|
|
208
210
|
min: 1,
|
|
209
211
|
max: 3,
|
|
210
|
-
value:
|
|
211
|
-
onValueChange:
|
|
212
|
+
value: ve,
|
|
213
|
+
onValueChange: ye,
|
|
212
214
|
showValue: !0
|
|
213
215
|
}),
|
|
214
216
|
/* @__PURE__ */ w(m, {
|
|
@@ -216,8 +218,8 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
216
218
|
min: 0,
|
|
217
219
|
max: .3,
|
|
218
220
|
step: .01,
|
|
219
|
-
value:
|
|
220
|
-
onValueChange:
|
|
221
|
+
value: be,
|
|
222
|
+
onValueChange: xe,
|
|
221
223
|
showValue: !0
|
|
222
224
|
}),
|
|
223
225
|
/* @__PURE__ */ w(m, {
|
|
@@ -225,8 +227,8 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
225
227
|
min: 1.2,
|
|
226
228
|
max: 2,
|
|
227
229
|
step: .05,
|
|
228
|
-
value:
|
|
229
|
-
onValueChange:
|
|
230
|
+
value: Se,
|
|
231
|
+
onValueChange: Ce,
|
|
230
232
|
showValue: !0
|
|
231
233
|
}),
|
|
232
234
|
/* @__PURE__ */ w(m, {
|
|
@@ -234,33 +236,33 @@ function A({ className: E, respondToOpenEvent: D = !0, onClick: O, ref: A, ...j
|
|
|
234
236
|
min: .18,
|
|
235
237
|
max: .32,
|
|
236
238
|
step: .01,
|
|
237
|
-
value:
|
|
238
|
-
onValueChange:
|
|
239
|
+
value: X,
|
|
240
|
+
onValueChange: we,
|
|
239
241
|
showValue: !0
|
|
240
242
|
})
|
|
241
243
|
]
|
|
242
244
|
}),
|
|
243
245
|
/* @__PURE__ */ w(g, {
|
|
244
246
|
label: "Reduced motion",
|
|
245
|
-
checked:
|
|
246
|
-
onCheckedChange:
|
|
247
|
+
checked: Te,
|
|
248
|
+
onCheckedChange: Ee
|
|
247
249
|
}),
|
|
248
250
|
/* @__PURE__ */ T("div", {
|
|
249
251
|
className: "border-border flex items-center gap-2 border-t pt-3",
|
|
250
252
|
children: [/* @__PURE__ */ w(d, {
|
|
251
253
|
variant: "primary",
|
|
252
254
|
size: "sm",
|
|
253
|
-
disabled: !
|
|
255
|
+
disabled: !Z,
|
|
254
256
|
onClick: () => {
|
|
255
|
-
|
|
257
|
+
De(), H("success", `Saved customization for ${te.find((e) => e.value === Q)?.label ?? Q}`);
|
|
256
258
|
},
|
|
257
259
|
children: "Save for theme"
|
|
258
260
|
}), /* @__PURE__ */ w(d, {
|
|
259
261
|
variant: "secondary",
|
|
260
262
|
size: "sm",
|
|
261
|
-
disabled: !
|
|
263
|
+
disabled: !ke && !Z,
|
|
262
264
|
onClick: () => {
|
|
263
|
-
|
|
265
|
+
Oe(), H("info", "Reset to theme defaults");
|
|
264
266
|
},
|
|
265
267
|
children: "Reset"
|
|
266
268
|
})]
|
|
@@ -2,18 +2,17 @@ import { cn as e } from "../../lib/cn.js";
|
|
|
2
2
|
import { clamp as t } from "../../lib/math.js";
|
|
3
3
|
import { getPositiveValue as n, truncateChartLabel as r } from "./chartUtils.js";
|
|
4
4
|
import { useBarChartSize as i } from "./useChartSize.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
5
|
+
import { useBarNavigation as a } from "./barChartUtils.js";
|
|
6
|
+
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
7
|
//#region src/components/charts/BarChart.tsx
|
|
9
|
-
var
|
|
8
|
+
var l = [
|
|
10
9
|
1,
|
|
11
10
|
.85,
|
|
12
11
|
.7,
|
|
13
12
|
.55,
|
|
14
13
|
.45
|
|
15
14
|
];
|
|
16
|
-
function
|
|
15
|
+
function u(e, t, n, r) {
|
|
17
16
|
if (e) {
|
|
18
17
|
if (e.textContent = t, e.getComputedTextLength() > r) {
|
|
19
18
|
let n = Array.from(t.replace(/\.\.\.$/, "")), i = 0, a = n.length;
|
|
@@ -29,21 +28,21 @@ function d(e, t, n, r) {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
function
|
|
33
|
-
let { rootRef:
|
|
34
|
-
return /* @__PURE__ */
|
|
35
|
-
ref:
|
|
36
|
-
...
|
|
31
|
+
function d({ data: d, onDatumActivate: f, height: p, maxValue: m, valueFormatter: h, labelFormatter: g, maxLabelLength: _, labelWidth: v = 160, valueWidth: y = 60, barHeight: b = 28, gap: x = 10, "aria-label": S = "Horizontal bar chart", className: C, ref: w, ...T }) {
|
|
32
|
+
let { rootRef: E, size: D, viewBoxWidth: O } = i(w), k = a(d, f, T), { hoverIndex: A, setHoverIndex: j } = k, M = d.length, N = Math.max(1, b), P = Math.max(0, x), F = M > 0 ? M * N + Math.max(0, M - 1) * P : N, I = Math.max(1, p ?? F), L = D?.height ?? I, R = L / F, z = N * R, B = P * R, V = Math.min(3, z / 3), H = Math.max(0, z - V * 2), U = m === void 0 ? Math.max(...d.map((e) => n(e.value)), 1) : Math.max(n(m), 1), W = Math.max(0, v), G = W + Math.max(0, y), K = Math.min(G, O * .6), q = G > 0 ? W / G * K : 0, J = O - K, Y = h ?? ((e) => e.toLocaleString());
|
|
33
|
+
return /* @__PURE__ */ s("svg", {
|
|
34
|
+
ref: E,
|
|
35
|
+
...T,
|
|
37
36
|
width: "100%",
|
|
38
|
-
height:
|
|
39
|
-
viewBox: `0 0 ${
|
|
40
|
-
className: e("select-none",
|
|
41
|
-
|
|
42
|
-
"aria-label":
|
|
43
|
-
children:
|
|
44
|
-
let
|
|
45
|
-
return /* @__PURE__ */
|
|
46
|
-
...
|
|
37
|
+
height: D && I,
|
|
38
|
+
viewBox: `0 0 ${O} ${L}`,
|
|
39
|
+
className: e("select-none", C),
|
|
40
|
+
...k.chartProps,
|
|
41
|
+
"aria-label": S,
|
|
42
|
+
children: d.map((e, i) => {
|
|
43
|
+
let a = i * (z + B), d = U > 0 ? t(n(e.value), 0, U) / U * J : 0, p = A === i, m = g?.(e.label, e, i) ?? e.label, h = r(m, _), v = h !== m, y = Y(e.value);
|
|
44
|
+
return /* @__PURE__ */ c("g", {
|
|
45
|
+
...k.barProps(i),
|
|
47
46
|
onMouseEnter: () => j(i),
|
|
48
47
|
onMouseLeave: () => j(null),
|
|
49
48
|
onPointerEnter: () => j(i),
|
|
@@ -51,56 +50,54 @@ function f({ data: f, onDatumActivate: p, height: m, maxValue: h, valueFormatter
|
|
|
51
50
|
onPointerLeave: () => j(null),
|
|
52
51
|
onFocus: () => j(i),
|
|
53
52
|
onBlur: () => j(null),
|
|
54
|
-
className: "cursor-pointer",
|
|
55
|
-
|
|
56
|
-
role: "button",
|
|
57
|
-
"aria-label": `${h}: ${b}`,
|
|
53
|
+
className: f ? "cursor-pointer" : void 0,
|
|
54
|
+
"aria-label": `${m}: ${y}`,
|
|
58
55
|
children: [
|
|
59
|
-
/* @__PURE__ */
|
|
56
|
+
/* @__PURE__ */ s("rect", {
|
|
60
57
|
x: 0,
|
|
61
|
-
y:
|
|
62
|
-
width:
|
|
58
|
+
y: a,
|
|
59
|
+
width: O,
|
|
63
60
|
height: z,
|
|
64
61
|
fill: "transparent"
|
|
65
62
|
}),
|
|
66
|
-
/* @__PURE__ */
|
|
63
|
+
/* @__PURE__ */ s("text", {
|
|
67
64
|
x: 0,
|
|
68
|
-
y:
|
|
65
|
+
y: a + z / 2,
|
|
69
66
|
dominantBaseline: "central",
|
|
70
|
-
fill:
|
|
67
|
+
fill: p ? "var(--text-primary)" : "var(--text-secondary)",
|
|
71
68
|
fontSize: 11,
|
|
72
|
-
fontWeight:
|
|
69
|
+
fontWeight: p ? 600 : 400,
|
|
73
70
|
style: { transition: "all 150ms" },
|
|
74
|
-
children:
|
|
71
|
+
children: D && K < G ? /* @__PURE__ */ s("tspan", { ref: (e) => u(e, h, m, q - 4) }) : /* @__PURE__ */ c(o, { children: [v && /* @__PURE__ */ s("title", { children: m }), h] })
|
|
75
72
|
}),
|
|
76
|
-
/* @__PURE__ */
|
|
73
|
+
/* @__PURE__ */ s("rect", {
|
|
77
74
|
x: q,
|
|
78
|
-
y:
|
|
75
|
+
y: a + V,
|
|
79
76
|
width: J,
|
|
80
77
|
height: H,
|
|
81
78
|
fill: "var(--border)",
|
|
82
79
|
rx: 6,
|
|
83
80
|
opacity: .5
|
|
84
81
|
}),
|
|
85
|
-
/* @__PURE__ */
|
|
82
|
+
/* @__PURE__ */ s("rect", {
|
|
86
83
|
x: q,
|
|
87
|
-
y:
|
|
88
|
-
width:
|
|
84
|
+
y: a + V,
|
|
85
|
+
width: d,
|
|
89
86
|
height: H,
|
|
90
87
|
fill: "var(--accent)",
|
|
91
88
|
rx: 6,
|
|
92
|
-
opacity:
|
|
89
|
+
opacity: p ? 1 : l[i % l.length],
|
|
93
90
|
style: { transition: "all 150ms" }
|
|
94
91
|
}),
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
x:
|
|
97
|
-
y:
|
|
92
|
+
/* @__PURE__ */ s("text", {
|
|
93
|
+
x: O,
|
|
94
|
+
y: a + z / 2,
|
|
98
95
|
dominantBaseline: "central",
|
|
99
96
|
textAnchor: "end",
|
|
100
97
|
fill: "var(--text-primary)",
|
|
101
98
|
fontSize: 11,
|
|
102
99
|
fontWeight: 600,
|
|
103
|
-
children:
|
|
100
|
+
children: y
|
|
104
101
|
})
|
|
105
102
|
]
|
|
106
103
|
}, e.label);
|
|
@@ -108,4 +105,4 @@ function f({ data: f, onDatumActivate: p, height: m, maxValue: h, valueFormatter
|
|
|
108
105
|
});
|
|
109
106
|
}
|
|
110
107
|
//#endregion
|
|
111
|
-
export {
|
|
108
|
+
export { d as BarChart };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { estimateTooltipWidth as t, formatCompactValue as n, getSvgTooltipPosition as r } from "./chartUtils.js";
|
|
3
3
|
import { useBarChartSize as i } from "./useChartSize.js";
|
|
4
|
-
import {
|
|
5
|
-
import { useMemo as s
|
|
6
|
-
import { Fragment as
|
|
4
|
+
import { getBarAxisLayout as a, useBarNavigation as o } from "./barChartUtils.js";
|
|
5
|
+
import { useMemo as s } from "react";
|
|
6
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
7
7
|
//#region src/components/charts/StackedBarChart.tsx
|
|
8
|
-
var
|
|
8
|
+
var d = {
|
|
9
9
|
top: 20,
|
|
10
10
|
right: 12,
|
|
11
11
|
bottom: 30,
|
|
12
12
|
left: 48
|
|
13
|
-
},
|
|
14
|
-
function
|
|
13
|
+
}, ee = 4;
|
|
14
|
+
function f(e) {
|
|
15
15
|
let t = /^(\d{4})-(\d{2})-(\d{2})T(\d{2})/.exec(e);
|
|
16
16
|
if (t) {
|
|
17
17
|
let [, e, n, r, i] = t;
|
|
@@ -31,7 +31,7 @@ function m(e) {
|
|
|
31
31
|
timeZone: "UTC"
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function p(e, t) {
|
|
35
35
|
let n = e[t];
|
|
36
36
|
if (typeof n == "number") return Number.isFinite(n) ? n : 0;
|
|
37
37
|
if (typeof n == "string") {
|
|
@@ -40,10 +40,10 @@ function h(e, t) {
|
|
|
40
40
|
}
|
|
41
41
|
return 0;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
return t.reduce((t, n) => t + Math.max(0,
|
|
43
|
+
function m(e, t) {
|
|
44
|
+
return t.reduce((t, n) => t + Math.max(0, p(e, n.key)), 0);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function h(e, t, n, r, i) {
|
|
47
47
|
let a = Math.min(i, Math.max(0, n / 2), Math.max(0, r));
|
|
48
48
|
return a <= 0 ? `M ${e} ${t} H ${e + n} V ${t + r} H ${e} Z` : [
|
|
49
49
|
`M ${e} ${t + r}`,
|
|
@@ -55,80 +55,80 @@ function ee(e, t, n, r, i) {
|
|
|
55
55
|
"Z"
|
|
56
56
|
].join(" ");
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
let { rootRef:
|
|
58
|
+
function g({ data: g, onDatumActivate: _, segments: v, height: y = 220, "aria-label": b = "Stacked bar chart", tooltipRows: x, valueFormatter: S, tooltipValueFormatter: te, xLabelCount: C = 6, barGap: ne, minBarWidth: w = 1, className: T, ref: E, ...D }) {
|
|
59
|
+
let { rootRef: O, size: k, viewBoxWidth: A } = i(E), j = o(g, _, D), { hoverIndex: M, setHoverIndex: N } = j, P = Math.max(d.top + d.bottom + 1, y), F = k?.height ?? P, I = s(() => g.map((e) => f(e.date)), [g]), { left: L, plotWidth: R, indices: z } = s(() => a(I, C, k?.width, d), [
|
|
60
60
|
I,
|
|
61
61
|
C,
|
|
62
|
-
|
|
63
|
-
]), B = Math.max(1, F -
|
|
62
|
+
k?.width
|
|
63
|
+
]), B = Math.max(1, F - d.top - d.bottom), V = g.reduce((e, t) => Math.max(e, m(t, v)), 1), H = Math.ceil(V / 2), U = H > 0 && H < V, W = ne ?? (g.length > 60 ? 2 : g.length > 30 ? 3 : 6), G = Math.max(1, w), K = g.length > 1 ? Math.max(0, (R - g.length * G) / Math.max(g.length - 1, 1)) : 0, q = g.length > 1 ? Math.min(Math.max(0, W), K) : 0, J = g.length > 0 ? (R - q * Math.max(g.length - 1, 0)) / g.length : 0, Y = M === null ? null : g[M], X = S ?? n, Z = te ?? ((e) => e.toLocaleString());
|
|
64
64
|
function Q(e) {
|
|
65
65
|
return L + e * (J + q);
|
|
66
66
|
}
|
|
67
67
|
function $(e) {
|
|
68
68
|
return e / V * B;
|
|
69
69
|
}
|
|
70
|
-
return /* @__PURE__ */
|
|
71
|
-
ref:
|
|
72
|
-
...
|
|
70
|
+
return /* @__PURE__ */ u("svg", {
|
|
71
|
+
ref: O,
|
|
72
|
+
...D,
|
|
73
73
|
width: "100%",
|
|
74
|
-
height:
|
|
75
|
-
viewBox: `0 0 ${
|
|
76
|
-
className: e("select-none",
|
|
77
|
-
|
|
78
|
-
"aria-label":
|
|
74
|
+
height: k && P,
|
|
75
|
+
viewBox: `0 0 ${A} ${F}`,
|
|
76
|
+
className: e("select-none", T),
|
|
77
|
+
...j.chartProps,
|
|
78
|
+
"aria-label": b,
|
|
79
79
|
children: [
|
|
80
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ l("text", {
|
|
81
81
|
x: L - 8,
|
|
82
|
-
y:
|
|
82
|
+
y: d.top,
|
|
83
83
|
textAnchor: "end",
|
|
84
84
|
dominantBaseline: "central",
|
|
85
85
|
fill: "var(--text-tertiary)",
|
|
86
86
|
fontSize: 10,
|
|
87
87
|
children: X(V)
|
|
88
88
|
}),
|
|
89
|
-
U && /* @__PURE__ */
|
|
89
|
+
U && /* @__PURE__ */ l("text", {
|
|
90
90
|
x: L - 8,
|
|
91
|
-
y:
|
|
91
|
+
y: d.top + B / 2,
|
|
92
92
|
textAnchor: "end",
|
|
93
93
|
dominantBaseline: "central",
|
|
94
94
|
fill: "var(--text-tertiary)",
|
|
95
95
|
fontSize: 10,
|
|
96
96
|
children: X(H)
|
|
97
97
|
}),
|
|
98
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ l("text", {
|
|
99
99
|
x: L - 8,
|
|
100
|
-
y:
|
|
100
|
+
y: d.top + B,
|
|
101
101
|
textAnchor: "end",
|
|
102
102
|
dominantBaseline: "central",
|
|
103
103
|
fill: "var(--text-tertiary)",
|
|
104
104
|
fontSize: 10,
|
|
105
105
|
children: "0"
|
|
106
106
|
}),
|
|
107
|
-
/* @__PURE__ */
|
|
107
|
+
/* @__PURE__ */ l("line", {
|
|
108
108
|
x1: L,
|
|
109
|
-
y1:
|
|
109
|
+
y1: d.top + B,
|
|
110
110
|
x2: L + R,
|
|
111
|
-
y2:
|
|
111
|
+
y2: d.top + B,
|
|
112
112
|
stroke: "var(--border)",
|
|
113
113
|
strokeWidth: 1
|
|
114
114
|
}),
|
|
115
|
-
/* @__PURE__ */
|
|
115
|
+
/* @__PURE__ */ l("line", {
|
|
116
116
|
x1: L,
|
|
117
|
-
y1:
|
|
117
|
+
y1: d.top + B / 2,
|
|
118
118
|
x2: L + R,
|
|
119
|
-
y2:
|
|
119
|
+
y2: d.top + B / 2,
|
|
120
120
|
stroke: "var(--border)",
|
|
121
121
|
strokeWidth: 1,
|
|
122
122
|
strokeDasharray: "3 3",
|
|
123
123
|
opacity: .5
|
|
124
124
|
}),
|
|
125
|
-
|
|
126
|
-
let n = Q(t), r = M === t, i = 0,
|
|
125
|
+
g.map((e, t) => {
|
|
126
|
+
let n = Q(t), r = M === t, i = 0, a = v.map((t) => ({
|
|
127
127
|
segment: t,
|
|
128
|
-
value: Math.max(0,
|
|
128
|
+
value: Math.max(0, p(e, t.key))
|
|
129
129
|
})).filter(({ value: e }) => e > 0);
|
|
130
|
-
return /* @__PURE__ */
|
|
131
|
-
...
|
|
130
|
+
return /* @__PURE__ */ u("g", {
|
|
131
|
+
...j.barProps(t),
|
|
132
132
|
onMouseEnter: () => N(t),
|
|
133
133
|
onMouseLeave: () => N(null),
|
|
134
134
|
onPointerEnter: () => N(t),
|
|
@@ -136,24 +136,22 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
136
136
|
onPointerLeave: () => N(null),
|
|
137
137
|
onFocus: () => N(t),
|
|
138
138
|
onBlur: () => N(null),
|
|
139
|
-
|
|
140
|
-
role: "button",
|
|
141
|
-
"aria-label": `${I[t]}: ${Z(g(e, y))}`,
|
|
139
|
+
"aria-label": `${I[t]}: ${Z(m(e, v))}`,
|
|
142
140
|
children: [
|
|
143
|
-
/* @__PURE__ */
|
|
141
|
+
/* @__PURE__ */ l("rect", {
|
|
144
142
|
x: n,
|
|
145
|
-
y:
|
|
143
|
+
y: d.top,
|
|
146
144
|
width: J,
|
|
147
145
|
height: B,
|
|
148
146
|
fill: "transparent"
|
|
149
147
|
}),
|
|
150
|
-
|
|
151
|
-
let s = $(t), c =
|
|
152
|
-
return i += s,
|
|
153
|
-
d:
|
|
148
|
+
a.map(({ segment: e, value: t }, o) => {
|
|
149
|
+
let s = $(t), c = d.top + B - i - s, u = o === a.length - 1;
|
|
150
|
+
return i += s, u ? /* @__PURE__ */ l("path", {
|
|
151
|
+
d: h(n, c, J, s, ee),
|
|
154
152
|
fill: e.color,
|
|
155
153
|
opacity: r ? 1 : e.opacity ?? .9
|
|
156
|
-
}, e.key) : /* @__PURE__ */
|
|
154
|
+
}, e.key) : /* @__PURE__ */ l("rect", {
|
|
157
155
|
x: n,
|
|
158
156
|
y: c,
|
|
159
157
|
width: J,
|
|
@@ -162,7 +160,7 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
162
160
|
opacity: r ? 1 : e.opacity ?? .9
|
|
163
161
|
}, e.key);
|
|
164
162
|
}),
|
|
165
|
-
z.has(t) && /* @__PURE__ */
|
|
163
|
+
z.has(t) && /* @__PURE__ */ l("text", {
|
|
166
164
|
x: n + J / 2,
|
|
167
165
|
y: F - 5,
|
|
168
166
|
textAnchor: "middle",
|
|
@@ -173,34 +171,34 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
173
171
|
]
|
|
174
172
|
}, `${e.date}-${t}`);
|
|
175
173
|
}),
|
|
176
|
-
Y && M !== null && /* @__PURE__ */
|
|
174
|
+
Y && M !== null && /* @__PURE__ */ l("g", {
|
|
177
175
|
pointerEvents: "none",
|
|
178
176
|
children: (() => {
|
|
179
|
-
let e = Q(M) + J / 2, n =
|
|
177
|
+
let e = Q(M) + J / 2, n = x?.(Y) ?? v.map((e) => ({
|
|
180
178
|
color: e.color,
|
|
181
179
|
label: e.label,
|
|
182
|
-
value:
|
|
183
|
-
})), i =
|
|
180
|
+
value: p(Y, e.key)
|
|
181
|
+
})), i = m(Y, v), a = r(e, d.top + B - $(i), {
|
|
184
182
|
boundsHeight: F,
|
|
185
|
-
boundsWidth:
|
|
183
|
+
boundsWidth: A,
|
|
186
184
|
height: 28 + n.length * 15,
|
|
187
185
|
offset: 8,
|
|
188
|
-
width: t([
|
|
186
|
+
width: t([f(Y.date), ...n.map((e) => `${e.label} ${Z(e.value)}`)], {
|
|
189
187
|
maxWidth: 240,
|
|
190
188
|
minWidth: 150
|
|
191
189
|
})
|
|
192
190
|
}), o = a.x + 10, s = a.x + a.width - 10;
|
|
193
|
-
return /* @__PURE__ */
|
|
194
|
-
/* @__PURE__ */
|
|
191
|
+
return /* @__PURE__ */ u(c, { children: [
|
|
192
|
+
/* @__PURE__ */ l("line", {
|
|
195
193
|
x1: e,
|
|
196
|
-
y1:
|
|
194
|
+
y1: d.top,
|
|
197
195
|
x2: e,
|
|
198
|
-
y2:
|
|
196
|
+
y2: d.top + B,
|
|
199
197
|
stroke: "var(--border-strong)",
|
|
200
198
|
strokeWidth: 1,
|
|
201
199
|
strokeDasharray: "3 3"
|
|
202
200
|
}),
|
|
203
|
-
/* @__PURE__ */
|
|
201
|
+
/* @__PURE__ */ l("rect", {
|
|
204
202
|
x: a.x,
|
|
205
203
|
y: a.y,
|
|
206
204
|
width: a.width,
|
|
@@ -210,18 +208,18 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
210
208
|
stroke: "var(--border)",
|
|
211
209
|
strokeWidth: 1
|
|
212
210
|
}),
|
|
213
|
-
/* @__PURE__ */
|
|
211
|
+
/* @__PURE__ */ l("text", {
|
|
214
212
|
x: o,
|
|
215
213
|
y: a.y + 14,
|
|
216
214
|
fill: "var(--text-primary)",
|
|
217
215
|
fontSize: 10,
|
|
218
216
|
fontWeight: 600,
|
|
219
|
-
children:
|
|
217
|
+
children: f(Y.date)
|
|
220
218
|
}),
|
|
221
219
|
n.map((e, t) => {
|
|
222
220
|
let n = a.y + 30 + t * 15;
|
|
223
|
-
return /* @__PURE__ */
|
|
224
|
-
e.color && /* @__PURE__ */
|
|
221
|
+
return /* @__PURE__ */ u("g", { children: [
|
|
222
|
+
e.color && /* @__PURE__ */ l("rect", {
|
|
225
223
|
x: o,
|
|
226
224
|
y: n - 6,
|
|
227
225
|
width: 6,
|
|
@@ -229,14 +227,14 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
229
227
|
rx: 1,
|
|
230
228
|
fill: e.color
|
|
231
229
|
}),
|
|
232
|
-
/* @__PURE__ */
|
|
230
|
+
/* @__PURE__ */ l("text", {
|
|
233
231
|
x: e.color ? o + 12 : o,
|
|
234
232
|
y: n,
|
|
235
233
|
fill: "var(--text-secondary)",
|
|
236
234
|
fontSize: 10,
|
|
237
235
|
children: e.label
|
|
238
236
|
}),
|
|
239
|
-
/* @__PURE__ */
|
|
237
|
+
/* @__PURE__ */ l("text", {
|
|
240
238
|
x: s,
|
|
241
239
|
y: n,
|
|
242
240
|
textAnchor: "end",
|
|
@@ -254,4 +252,4 @@ function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-la
|
|
|
254
252
|
});
|
|
255
253
|
}
|
|
256
254
|
//#endregion
|
|
257
|
-
export {
|
|
255
|
+
export { g as StackedBarChart };
|