@leonardaustin/ui 0.27.0 → 0.29.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/charts/AreaChart.js +113 -114
- package/dist/components/charts/BarChart.d.ts +4 -2
- package/dist/components/charts/BarChart.js +69 -49
- package/dist/components/charts/Heatmap.d.ts +20 -0
- package/dist/components/charts/Heatmap.js +46 -0
- package/dist/components/charts/StackedBarChart.d.ts +3 -1
- package/dist/components/charts/StackedBarChart.js +103 -95
- package/dist/components/charts/VerticalBarChart.d.ts +3 -1
- package/dist/components/charts/VerticalBarChart.js +94 -83
- package/dist/components/charts/barChartUtils.d.ts +16 -0
- package/dist/components/charts/barChartUtils.js +24 -0
- package/dist/components/charts/chartUtils.d.ts +2 -0
- package/dist/components/charts/chartUtils.js +14 -9
- package/dist/components/charts/useChartSize.d.ts +13 -0
- package/dist/components/charts/useChartSize.js +27 -0
- package/dist/components/tables/Pagination.d.ts +3 -1
- package/dist/components/tables/Pagination.js +12 -12
- package/dist/components/tables/ResourceTable.d.ts +5 -0
- package/dist/components/tables/ResourceTable.js +11 -9
- package/dist/components/tables/Table.d.ts +22 -3
- package/dist/components/tables/Table.js +41 -35
- package/dist/components/ui/ActionLink.d.ts +14 -0
- package/dist/components/ui/ActionLink.js +12 -0
- package/dist/components/ui/DateRangePicker.js +107 -76
- package/dist/components/ui/EmptyState.d.ts +8 -6
- package/dist/components/ui/EmptyState.js +11 -10
- package/dist/components/ui/ErrorBoundary.d.ts +6 -0
- package/dist/components/ui/ErrorBoundary.js +11 -5
- package/dist/components/ui/Grid.d.ts +1 -1
- package/dist/components/ui/Icon.d.ts +91 -0
- package/dist/components/ui/Icon.js +98 -0
- package/dist/components/ui/Inline.d.ts +1 -1
- package/dist/components/ui/LoadingSpinner.d.ts +7 -3
- package/dist/components/ui/LoadingSpinner.js +19 -11
- package/dist/components/ui/MainAsideLayout.d.ts +10 -0
- package/dist/components/ui/MainAsideLayout.js +18 -0
- package/dist/components/ui/Meter.d.ts +11 -0
- package/dist/components/ui/Meter.js +7 -0
- package/dist/components/ui/MetricCard.d.ts +11 -8
- package/dist/components/ui/MetricCard.js +18 -15
- package/dist/components/ui/PaginationBar.d.ts +3 -3
- package/dist/components/ui/PaginationBar.js +35 -33
- package/dist/components/ui/SideSheet.d.ts +4 -2
- package/dist/components/ui/SideSheet.js +64 -52
- package/dist/components/ui/Stack.d.ts +1 -1
- package/dist/components/ui/Tabs.d.ts +5 -1
- package/dist/components/ui/Tabs.js +23 -21
- package/dist/components/ui/Text.d.ts +19 -0
- package/dist/components/ui/Text.js +20 -0
- package/dist/components/ui/Toolbar.js +13 -13
- package/dist/core.css +122 -0
- package/dist/hooks/useFocusTrap.js +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +135 -129
- package/dist/styles.css +123 -0
- package/package.json +1 -1
|
@@ -1,211 +1,210 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { mergeRefs as t } from "../../lib/mergeRefs.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { estimateTextWidth as n, estimateTooltipWidth as r, formatCompactValue as i, getFittingLabelCount as a, getLabelIndices as o, getSvgTooltipPosition as ee } from "./chartUtils.js";
|
|
4
|
+
import { useChartSize as s } from "./useChartSize.js";
|
|
5
|
+
import { useId as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
6
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
6
7
|
//#region src/components/charts/AreaChart.tsx
|
|
7
|
-
var
|
|
8
|
+
var h = {
|
|
8
9
|
top: 16,
|
|
9
10
|
right: 12,
|
|
10
11
|
bottom: 28,
|
|
11
12
|
left: 48
|
|
12
|
-
},
|
|
13
|
-
function
|
|
13
|
+
}, te = 600;
|
|
14
|
+
function g(e) {
|
|
14
15
|
return e === 0 ? 1 : Math.max(Math.abs(e) * .02, 1);
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
let
|
|
18
|
-
for (let e of
|
|
19
|
-
let
|
|
20
|
-
if (b && v === void 0 &&
|
|
17
|
+
function _({ data: _, height: ne = 240, minValue: v, maxValue: y, startAtZero: b = !1, valueFormatter: x, tooltipValueFormatter: re, xLabelCount: S = 5, "aria-label": C = "Area chart", className: w, onPointerMove: ie, onPointerLeave: ae, ref: T, ...oe }) {
|
|
18
|
+
let E = c(), D = u(null), O = l(() => t(D, T), [T]), [k, A] = d(null), j = s(D), M = j?.width ?? te, N = Math.max(h.top + h.bottom + 1, ne), P = j?.height ?? N, F = (e, t) => j && e && S > 0 ? Math.max(t, n(e) / 2 + 4) : t, I = F(_[0]?.date, h.left), L = F(_.at(-1)?.date, h.right), R = Math.max(1, M - I - L), z = Math.max(1, P - h.top - h.bottom), B = _.length > 0, V = _[0]?.value ?? 0, H = _[0]?.value ?? 0;
|
|
19
|
+
for (let e of _) e.value < V && (V = e.value), e.value > H && (H = e.value);
|
|
20
|
+
let U = v ?? V, W = y ?? H;
|
|
21
|
+
if (b && v === void 0 && V >= 0 && (U = 0), U === W) {
|
|
21
22
|
if (b || v !== void 0 || y !== void 0) {
|
|
22
|
-
let e =
|
|
23
|
-
v === void 0 && (
|
|
23
|
+
let e = g(H);
|
|
24
|
+
v === void 0 && (U = b && V >= 0 ? 0 : V >= 0 ? Math.max(0, V - e) : V - e), y === void 0 && (W = H + e);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
U === W && (W = U + 1);
|
|
26
27
|
}
|
|
27
|
-
let
|
|
28
|
-
function
|
|
29
|
-
return
|
|
28
|
+
let G = W - U, K = x ?? i, q = re ?? x ?? ((e) => e.toLocaleString());
|
|
29
|
+
function J(e) {
|
|
30
|
+
return I + e / Math.max(_.length - 1, 1) * R;
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
32
|
+
function Y(e) {
|
|
33
|
+
return h.top + z - (e - U) / G * z;
|
|
33
34
|
}
|
|
34
|
-
let
|
|
35
|
-
`${
|
|
36
|
-
...
|
|
37
|
-
`${
|
|
38
|
-
].join(" ") : "", X =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
35
|
+
let se = _.map((e, t) => `${J(t)},${Y(e.value)}`).join(" "), ce = B ? [
|
|
36
|
+
`${J(0)},${h.top + z}`,
|
|
37
|
+
..._.map((e, t) => `${J(t)},${Y(e.value)}`),
|
|
38
|
+
`${J(_.length - 1)},${h.top + z}`
|
|
39
|
+
].join(" ") : "", X = l(() => _.reduce((e, { date: t }) => Math.max(e, n(t)), 0), [_]), le = j ? Math.min(S, a(_.length, R, X)) : S, ue = o(_.length, le), Z = k === null ? void 0 : _[k], Q = Z && k !== null ? {
|
|
40
|
+
x: J(k),
|
|
41
|
+
y: Y(Z.value)
|
|
42
|
+
} : null;
|
|
43
|
+
function de(e) {
|
|
44
|
+
let t = D.current;
|
|
45
|
+
if (!t || _.length === 0) return;
|
|
46
|
+
let n = t.getScreenCTM(), r;
|
|
47
|
+
if (n) {
|
|
48
|
+
let i = t.createSVGPoint();
|
|
49
|
+
i.x = e.clientX, i.y = e.clientY, r = i.matrixTransform(n.inverse()).x;
|
|
50
|
+
} else {
|
|
51
|
+
let n = t.getBoundingClientRect();
|
|
52
|
+
if (n.width <= 0) return;
|
|
53
|
+
r = (e.clientX - n.left) / n.width * M;
|
|
54
|
+
}
|
|
55
|
+
let i = (r - I) / R, a = Math.round(i * (_.length - 1));
|
|
56
|
+
A(Math.max(0, Math.min(_.length - 1, a)));
|
|
57
57
|
}
|
|
58
58
|
function $() {
|
|
59
|
-
|
|
59
|
+
A(null);
|
|
60
60
|
}
|
|
61
|
-
return /* @__PURE__ */
|
|
62
|
-
...
|
|
63
|
-
ref:
|
|
61
|
+
return /* @__PURE__ */ m("svg", {
|
|
62
|
+
...oe,
|
|
63
|
+
ref: O,
|
|
64
64
|
width: "100%",
|
|
65
|
-
|
|
65
|
+
height: N,
|
|
66
|
+
viewBox: `0 0 ${M} ${P}`,
|
|
66
67
|
onPointerMove: (e) => {
|
|
67
|
-
|
|
68
|
+
ie?.(e), !e.defaultPrevented && de(e);
|
|
68
69
|
},
|
|
69
70
|
onPointerLeave: (e) => {
|
|
70
|
-
|
|
71
|
+
ae?.(e), !e.defaultPrevented && $();
|
|
71
72
|
},
|
|
72
|
-
className: e("select-none",
|
|
73
|
+
className: e("select-none", w),
|
|
73
74
|
role: "img",
|
|
74
|
-
"aria-label":
|
|
75
|
+
"aria-label": C,
|
|
75
76
|
children: [
|
|
76
|
-
/* @__PURE__ */
|
|
77
|
-
id:
|
|
77
|
+
/* @__PURE__ */ p("defs", { children: /* @__PURE__ */ m("linearGradient", {
|
|
78
|
+
id: E,
|
|
78
79
|
x1: "0",
|
|
79
80
|
y1: "0",
|
|
80
81
|
x2: "0",
|
|
81
82
|
y2: "1",
|
|
82
|
-
children: [/* @__PURE__ */
|
|
83
|
+
children: [/* @__PURE__ */ p("stop", {
|
|
83
84
|
offset: "0%",
|
|
84
85
|
stopColor: "var(--accent)",
|
|
85
86
|
stopOpacity: .3
|
|
86
|
-
}), /* @__PURE__ */
|
|
87
|
+
}), /* @__PURE__ */ p("stop", {
|
|
87
88
|
offset: "100%",
|
|
88
89
|
stopColor: "var(--accent)",
|
|
89
90
|
stopOpacity: 0
|
|
90
91
|
})]
|
|
91
92
|
}) }),
|
|
92
|
-
/* @__PURE__ */
|
|
93
|
-
x:
|
|
94
|
-
y:
|
|
93
|
+
/* @__PURE__ */ p("text", {
|
|
94
|
+
x: I - 8,
|
|
95
|
+
y: h.top,
|
|
95
96
|
textAnchor: "end",
|
|
96
97
|
dominantBaseline: "central",
|
|
97
98
|
fill: "var(--text-tertiary)",
|
|
98
99
|
fontSize: 10,
|
|
99
|
-
children: W
|
|
100
|
+
children: K(W)
|
|
100
101
|
}),
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
x:
|
|
103
|
-
y:
|
|
102
|
+
/* @__PURE__ */ p("text", {
|
|
103
|
+
x: I - 8,
|
|
104
|
+
y: h.top + z,
|
|
104
105
|
textAnchor: "end",
|
|
105
106
|
dominantBaseline: "central",
|
|
106
107
|
fill: "var(--text-tertiary)",
|
|
107
108
|
fontSize: 10,
|
|
108
|
-
children:
|
|
109
|
+
children: K(U)
|
|
109
110
|
}),
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
x1:
|
|
112
|
-
y1:
|
|
113
|
-
x2:
|
|
114
|
-
y2:
|
|
111
|
+
/* @__PURE__ */ p("line", {
|
|
112
|
+
x1: I,
|
|
113
|
+
y1: h.top + z,
|
|
114
|
+
x2: I + R,
|
|
115
|
+
y2: h.top + z,
|
|
115
116
|
stroke: "var(--border)",
|
|
116
117
|
strokeWidth: 1
|
|
117
118
|
}),
|
|
118
|
-
|
|
119
|
-
points:
|
|
120
|
-
fill: `url(#${
|
|
119
|
+
B && /* @__PURE__ */ p("polygon", {
|
|
120
|
+
points: ce,
|
|
121
|
+
fill: `url(#${E})`
|
|
121
122
|
}),
|
|
122
|
-
|
|
123
|
-
points:
|
|
123
|
+
B && /* @__PURE__ */ p("polyline", {
|
|
124
|
+
points: se,
|
|
124
125
|
fill: "none",
|
|
125
126
|
stroke: "var(--accent)",
|
|
126
127
|
strokeWidth: 2,
|
|
127
128
|
strokeLinecap: "round",
|
|
128
129
|
strokeLinejoin: "round"
|
|
129
130
|
}),
|
|
130
|
-
|
|
131
|
-
cx:
|
|
132
|
-
cy:
|
|
131
|
+
_.map((e, t) => /* @__PURE__ */ p("circle", {
|
|
132
|
+
cx: J(t),
|
|
133
|
+
cy: Y(e.value),
|
|
133
134
|
r: 8,
|
|
134
135
|
fill: "transparent",
|
|
135
136
|
tabIndex: 0,
|
|
136
137
|
role: "button",
|
|
137
|
-
"aria-label": `${e.date}: ${
|
|
138
|
-
onFocus: () =>
|
|
138
|
+
"aria-label": `${e.date}: ${q(e.value)}`,
|
|
139
|
+
onFocus: () => A(t),
|
|
139
140
|
onBlur: $
|
|
140
141
|
}, `${e.date}-${t}-hit`)),
|
|
141
|
-
|
|
142
|
-
x:
|
|
143
|
-
y:
|
|
142
|
+
ue.map((e) => /* @__PURE__ */ p("text", {
|
|
143
|
+
x: J(e),
|
|
144
|
+
y: P - 4,
|
|
144
145
|
textAnchor: "middle",
|
|
145
146
|
fill: "var(--text-tertiary)",
|
|
146
147
|
fontSize: 10,
|
|
147
|
-
children:
|
|
148
|
-
}, `${
|
|
149
|
-
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
x1:
|
|
152
|
-
y1:
|
|
153
|
-
x2:
|
|
154
|
-
y2:
|
|
148
|
+
children: _[e].date
|
|
149
|
+
}, `${_[e].date}-${e}`)),
|
|
150
|
+
Q && Z && /* @__PURE__ */ m(f, { children: [
|
|
151
|
+
/* @__PURE__ */ p("line", {
|
|
152
|
+
x1: Q.x,
|
|
153
|
+
y1: h.top,
|
|
154
|
+
x2: Q.x,
|
|
155
|
+
y2: h.top + z,
|
|
155
156
|
stroke: "var(--border-strong)",
|
|
156
157
|
strokeWidth: 1,
|
|
157
158
|
strokeDasharray: "3 3"
|
|
158
159
|
}),
|
|
159
|
-
/* @__PURE__ */
|
|
160
|
-
cx:
|
|
161
|
-
cy:
|
|
160
|
+
/* @__PURE__ */ p("circle", {
|
|
161
|
+
cx: Q.x,
|
|
162
|
+
cy: Q.y,
|
|
162
163
|
r: 4,
|
|
163
164
|
fill: "var(--accent)",
|
|
164
165
|
stroke: "var(--bg-secondary)",
|
|
165
166
|
strokeWidth: 2
|
|
166
167
|
}),
|
|
167
168
|
(() => {
|
|
168
|
-
let e =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
boundsHeight: F,
|
|
172
|
-
boundsWidth: m,
|
|
169
|
+
let e = Z.date, t = q(Z.value), n = ee(Q.x, Q.y, {
|
|
170
|
+
boundsHeight: P,
|
|
171
|
+
boundsWidth: M,
|
|
173
172
|
height: 28,
|
|
174
173
|
offset: 10,
|
|
175
|
-
width:
|
|
174
|
+
width: r([e, t], {
|
|
176
175
|
maxWidth: 180,
|
|
177
176
|
minWidth: 90
|
|
178
177
|
})
|
|
179
|
-
}),
|
|
180
|
-
return /* @__PURE__ */ f
|
|
181
|
-
/* @__PURE__ */
|
|
182
|
-
x:
|
|
183
|
-
y:
|
|
184
|
-
width:
|
|
185
|
-
height:
|
|
178
|
+
}), i = n.x + n.width / 2;
|
|
179
|
+
return /* @__PURE__ */ m(f, { children: [
|
|
180
|
+
/* @__PURE__ */ p("rect", {
|
|
181
|
+
x: n.x,
|
|
182
|
+
y: n.y,
|
|
183
|
+
width: n.width,
|
|
184
|
+
height: n.height,
|
|
186
185
|
rx: 4,
|
|
187
186
|
fill: "var(--bg-tooltip, var(--bg-tertiary))",
|
|
188
187
|
stroke: "var(--border)",
|
|
189
188
|
strokeWidth: 1
|
|
190
189
|
}),
|
|
191
|
-
/* @__PURE__ */
|
|
192
|
-
x:
|
|
193
|
-
y:
|
|
190
|
+
/* @__PURE__ */ p("text", {
|
|
191
|
+
x: i,
|
|
192
|
+
y: n.y + 10,
|
|
194
193
|
textAnchor: "middle",
|
|
195
194
|
dominantBaseline: "central",
|
|
196
195
|
fill: "var(--text-secondary)",
|
|
197
196
|
fontSize: 9,
|
|
198
|
-
children:
|
|
197
|
+
children: e
|
|
199
198
|
}),
|
|
200
|
-
/* @__PURE__ */
|
|
201
|
-
x:
|
|
202
|
-
y:
|
|
199
|
+
/* @__PURE__ */ p("text", {
|
|
200
|
+
x: i,
|
|
201
|
+
y: n.y + 22,
|
|
203
202
|
textAnchor: "middle",
|
|
204
203
|
dominantBaseline: "central",
|
|
205
204
|
fill: "var(--text-primary)",
|
|
206
205
|
fontSize: 11,
|
|
207
206
|
fontWeight: 600,
|
|
208
|
-
children:
|
|
207
|
+
children: t
|
|
209
208
|
})
|
|
210
209
|
] });
|
|
211
210
|
})()
|
|
@@ -214,4 +213,4 @@ function g({ data: g, height: _ = 240, minValue: v, maxValue: y, startAtZero: b
|
|
|
214
213
|
});
|
|
215
214
|
}
|
|
216
215
|
//#endregion
|
|
217
|
-
export {
|
|
216
|
+
export { _ as AreaChart };
|
|
@@ -6,6 +6,8 @@ export interface BarChartDatum {
|
|
|
6
6
|
export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
|
|
7
7
|
/** Bars to draw top to bottom, each with a `label` and numeric `value`. */
|
|
8
8
|
data: BarChartDatum[];
|
|
9
|
+
/** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
|
|
10
|
+
onDatumActivate?: (datum: BarChartDatum, index: number) => void;
|
|
9
11
|
/** Total chart height in SVG units; rows scale to fit. Defaults to the natural height from `barHeight` and `gap`. */
|
|
10
12
|
height?: number;
|
|
11
13
|
/** Explicit domain maximum. Defaults to the largest positive value. */
|
|
@@ -14,7 +16,7 @@ export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "child
|
|
|
14
16
|
valueFormatter?: (value: number) => string;
|
|
15
17
|
/** Format left-side labels before optional truncation. */
|
|
16
18
|
labelFormatter?: (label: string, datum: BarChartDatum, index: number) => string;
|
|
17
|
-
/** Maximum
|
|
19
|
+
/** Maximum label length before fitting the text to a scaled label column. */
|
|
18
20
|
maxLabelLength?: number;
|
|
19
21
|
/** Width reserved for left-side labels in the SVG viewBox. */
|
|
20
22
|
labelWidth?: number;
|
|
@@ -29,4 +31,4 @@ export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "child
|
|
|
29
31
|
/** Extra classes for the `<svg>`. */
|
|
30
32
|
className?: string;
|
|
31
33
|
}
|
|
32
|
-
export declare function BarChart({ data, height, maxValue, valueFormatter, labelFormatter, maxLabelLength, labelWidth, valueWidth, barHeight, gap, "aria-label": ariaLabel, className, ref, ...rest }: BarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare function BarChart({ data, onDatumActivate, height, maxValue, valueFormatter, labelFormatter, maxLabelLength, labelWidth, valueWidth, barHeight, gap, "aria-label": ariaLabel, className, ref, ...rest }: BarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,86 +1,106 @@
|
|
|
1
1
|
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
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useBarChartSize as i } from "./useChartSize.js";
|
|
5
|
+
import { getBarActivationProps as a } from "./barChartUtils.js";
|
|
6
|
+
import { useState as o } from "react";
|
|
7
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
8
|
//#region src/components/charts/BarChart.tsx
|
|
7
|
-
var
|
|
9
|
+
var u = [
|
|
8
10
|
1,
|
|
9
11
|
.85,
|
|
10
12
|
.7,
|
|
11
13
|
.55,
|
|
12
14
|
.45
|
|
13
|
-
]
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
];
|
|
16
|
+
function d(e, t, n, r) {
|
|
17
|
+
if (e) {
|
|
18
|
+
if (e.textContent = t, e.getComputedTextLength() > r) {
|
|
19
|
+
let n = Array.from(t.replace(/\.\.\.$/, "")), i = 0, a = n.length;
|
|
20
|
+
for (; i < a;) {
|
|
21
|
+
let t = Math.ceil((i + a) / 2);
|
|
22
|
+
e.textContent = n.slice(0, t).join("") + "…", e.getComputedTextLength() <= r ? i = t : a = t - 1;
|
|
23
|
+
}
|
|
24
|
+
e.textContent = n.slice(0, i).join("") + "…", i === 0 && e.getComputedTextLength() > r && (e.textContent = "");
|
|
25
|
+
}
|
|
26
|
+
if (e.textContent !== n) {
|
|
27
|
+
let t = document.createElementNS(e.namespaceURI, "title");
|
|
28
|
+
t.textContent = n, e.prepend(t);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function f({ data: f, onDatumActivate: p, height: m, maxValue: h, valueFormatter: g, labelFormatter: _, maxLabelLength: v, labelWidth: y = 160, valueWidth: b = 60, barHeight: x = 28, gap: S = 10, "aria-label": C = "Horizontal bar chart", className: w, ref: T, ...E }) {
|
|
33
|
+
let { rootRef: D, size: O, viewBoxWidth: k } = i(T), [A, j] = o(null), M = f.length, N = Math.max(1, x), P = Math.max(0, S), F = M > 0 ? M * N + Math.max(0, M - 1) * P : N, I = Math.max(1, m ?? F), L = O?.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 = h === void 0 ? Math.max(...f.map((e) => n(e.value)), 1) : Math.max(n(h), 1), W = Math.max(0, y), G = W + Math.max(0, b), K = Math.min(G, k * .6), q = G > 0 ? W / G * K : 0, J = k - K, Y = g ?? ((e) => e.toLocaleString());
|
|
34
|
+
return /* @__PURE__ */ c("svg", {
|
|
35
|
+
ref: D,
|
|
36
|
+
...E,
|
|
19
37
|
width: "100%",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
height: O && I,
|
|
39
|
+
viewBox: `0 0 ${k} ${L}`,
|
|
40
|
+
className: e("select-none", w),
|
|
41
|
+
role: p ? "group" : "img",
|
|
42
|
+
"aria-label": C,
|
|
43
|
+
children: f.map((e, i) => {
|
|
44
|
+
let o = i * (z + B), f = U > 0 ? t(n(e.value), 0, U) / U * J : 0, m = A === i, h = _?.(e.label, e, i) ?? e.label, g = r(h, v), y = g !== h, b = Y(e.value);
|
|
45
|
+
return /* @__PURE__ */ l("g", {
|
|
46
|
+
...a(p, e, i),
|
|
47
|
+
onMouseEnter: () => j(i),
|
|
48
|
+
onMouseLeave: () => j(null),
|
|
49
|
+
onPointerEnter: () => j(i),
|
|
50
|
+
onPointerDown: () => j(i),
|
|
51
|
+
onPointerLeave: () => j(null),
|
|
52
|
+
onFocus: () => j(i),
|
|
53
|
+
onBlur: () => j(null),
|
|
34
54
|
className: "cursor-pointer",
|
|
35
55
|
tabIndex: 0,
|
|
36
56
|
role: "button",
|
|
37
|
-
"aria-label": `${
|
|
57
|
+
"aria-label": `${h}: ${b}`,
|
|
38
58
|
children: [
|
|
39
|
-
/* @__PURE__ */
|
|
59
|
+
/* @__PURE__ */ c("rect", {
|
|
40
60
|
x: 0,
|
|
41
|
-
y:
|
|
42
|
-
width:
|
|
43
|
-
height:
|
|
61
|
+
y: o,
|
|
62
|
+
width: k,
|
|
63
|
+
height: z,
|
|
44
64
|
fill: "transparent"
|
|
45
65
|
}),
|
|
46
|
-
/* @__PURE__ */
|
|
66
|
+
/* @__PURE__ */ c("text", {
|
|
47
67
|
x: 0,
|
|
48
|
-
y:
|
|
68
|
+
y: o + z / 2,
|
|
49
69
|
dominantBaseline: "central",
|
|
50
|
-
fill:
|
|
70
|
+
fill: m ? "var(--text-primary)" : "var(--text-secondary)",
|
|
51
71
|
fontSize: 11,
|
|
52
|
-
fontWeight:
|
|
72
|
+
fontWeight: m ? 600 : 400,
|
|
53
73
|
style: { transition: "all 150ms" },
|
|
54
|
-
children:
|
|
74
|
+
children: O && K < G ? /* @__PURE__ */ c("tspan", { ref: (e) => d(e, g, h, q - 4) }) : /* @__PURE__ */ l(s, { children: [y && /* @__PURE__ */ c("title", { children: h }), g] })
|
|
55
75
|
}),
|
|
56
|
-
/* @__PURE__ */
|
|
57
|
-
x:
|
|
58
|
-
y:
|
|
59
|
-
width:
|
|
60
|
-
height:
|
|
76
|
+
/* @__PURE__ */ c("rect", {
|
|
77
|
+
x: q,
|
|
78
|
+
y: o + V,
|
|
79
|
+
width: J,
|
|
80
|
+
height: H,
|
|
61
81
|
fill: "var(--border)",
|
|
62
82
|
rx: 6,
|
|
63
83
|
opacity: .5
|
|
64
84
|
}),
|
|
65
|
-
/* @__PURE__ */
|
|
66
|
-
x:
|
|
67
|
-
y:
|
|
68
|
-
width:
|
|
69
|
-
height:
|
|
85
|
+
/* @__PURE__ */ c("rect", {
|
|
86
|
+
x: q,
|
|
87
|
+
y: o + V,
|
|
88
|
+
width: f,
|
|
89
|
+
height: H,
|
|
70
90
|
fill: "var(--accent)",
|
|
71
91
|
rx: 6,
|
|
72
|
-
opacity:
|
|
92
|
+
opacity: m ? 1 : u[i % u.length],
|
|
73
93
|
style: { transition: "all 150ms" }
|
|
74
94
|
}),
|
|
75
|
-
/* @__PURE__ */
|
|
76
|
-
x:
|
|
77
|
-
y:
|
|
95
|
+
/* @__PURE__ */ c("text", {
|
|
96
|
+
x: k,
|
|
97
|
+
y: o + z / 2,
|
|
78
98
|
dominantBaseline: "central",
|
|
79
99
|
textAnchor: "end",
|
|
80
100
|
fill: "var(--text-primary)",
|
|
81
101
|
fontSize: 11,
|
|
82
102
|
fontWeight: 600,
|
|
83
|
-
children:
|
|
103
|
+
children: b
|
|
84
104
|
})
|
|
85
105
|
]
|
|
86
106
|
}, e.label);
|
|
@@ -88,4 +108,4 @@ function l({ data: l, height: u, maxValue: d, valueFormatter: f, labelFormatter:
|
|
|
88
108
|
});
|
|
89
109
|
}
|
|
90
110
|
//#endregion
|
|
91
|
-
export {
|
|
111
|
+
export { f as BarChart };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef } from "react";
|
|
2
|
+
export interface HeatmapProps extends Omit<ComponentPropsWithRef<"figure">, "children"> {
|
|
3
|
+
/** Visible table caption and accessible name of the scrolling region. */
|
|
4
|
+
caption: string;
|
|
5
|
+
/** Labels down the left edge, in matrix order. */
|
|
6
|
+
rowLabels: readonly string[];
|
|
7
|
+
/** Labels across the top, in matrix order. */
|
|
8
|
+
columnLabels: readonly string[];
|
|
9
|
+
/** Non-negative readings by row and column. Missing rows, short rows and null readings display a dash for each absent value. */
|
|
10
|
+
values: readonly (readonly (number | null | undefined)[] | undefined)[];
|
|
11
|
+
/** Optional heading above the row labels. */
|
|
12
|
+
rowHeading?: string;
|
|
13
|
+
/** Positive upper bound for the four colour bands; higher readings use the top band. Defaults to the largest reading. */
|
|
14
|
+
max?: number;
|
|
15
|
+
/** Tooltip and accessible name for a numeric cell. Defaults to the displayed number. */
|
|
16
|
+
valueLabel?: (value: number, row: string, column: string) => string;
|
|
17
|
+
/** Tooltip and accessible name for an absent reading. */
|
|
18
|
+
missingLabel?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function Heatmap({ caption, rowLabels, columnLabels, values, rowHeading, max, valueLabel, missingLabel, className, ...props }: HeatmapProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { Table as t, TableBody as n, TableCell as r, TableHead as i, TableHeaderCell as a, TableRow as o } from "../tables/Table.js";
|
|
3
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/charts/Heatmap.tsx
|
|
5
|
+
function l(e) {
|
|
6
|
+
let t = 0;
|
|
7
|
+
for (let n of e) if (n !== void 0) for (let e of n) t = Math.max(t, e ?? 0);
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
function u({ caption: u, rowLabels: d, columnLabels: f, values: p, rowHeading: m, max: h, valueLabel: g, missingLabel: _ = "Unavailable", className: v, ...y }) {
|
|
11
|
+
let b = h ?? l(p);
|
|
12
|
+
return /* @__PURE__ */ c("figure", {
|
|
13
|
+
...y,
|
|
14
|
+
className: e("min-w-0", v),
|
|
15
|
+
children: [/* @__PURE__ */ c(t, {
|
|
16
|
+
caption: u,
|
|
17
|
+
className: "ui-heatmap",
|
|
18
|
+
wrapperProps: {
|
|
19
|
+
role: "region",
|
|
20
|
+
tabIndex: 0,
|
|
21
|
+
"aria-label": u
|
|
22
|
+
},
|
|
23
|
+
children: [/* @__PURE__ */ s(i, { children: /* @__PURE__ */ c(o, { children: [m ? /* @__PURE__ */ s(a, { children: m }) : /* @__PURE__ */ s("td", {}), f.map((e, t) => /* @__PURE__ */ s(a, { children: e }, t))] }) }), /* @__PURE__ */ s(n, { children: d.map((e, t) => /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(a, {
|
|
24
|
+
scope: "row",
|
|
25
|
+
children: e
|
|
26
|
+
}), f.map((n, i) => {
|
|
27
|
+
let a = p[t]?.[i], o = a == null ? _ : g?.(a, e, n) ?? String(a);
|
|
28
|
+
return /* @__PURE__ */ s(r, {
|
|
29
|
+
"data-intensity": a == null ? "missing" : a <= 0 ? 0 : Math.min(4, Math.ceil(4 * a / b)),
|
|
30
|
+
"aria-label": o,
|
|
31
|
+
title: o,
|
|
32
|
+
children: a ?? "—"
|
|
33
|
+
}, i);
|
|
34
|
+
})] }, t)) })]
|
|
35
|
+
}), /* @__PURE__ */ c("figcaption", {
|
|
36
|
+
className: "text-xs text-text-secondary",
|
|
37
|
+
children: [
|
|
38
|
+
"Colour scale from 0 to ",
|
|
39
|
+
b,
|
|
40
|
+
"."
|
|
41
|
+
]
|
|
42
|
+
})]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { u as Heatmap };
|
|
@@ -17,6 +17,8 @@ export interface StackedBarChartTooltipRow {
|
|
|
17
17
|
export interface StackedBarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
|
|
18
18
|
/** One entry per bar, with a `date` label and a numeric value for each segment `key`. */
|
|
19
19
|
data: StackedBarChartDatum[];
|
|
20
|
+
/** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
|
|
21
|
+
onDatumActivate?: (datum: StackedBarChartDatum, index: number) => void;
|
|
20
22
|
/** Stack layers in order; each maps a `key` in `data` to a `label`, `color`, and optional `opacity`. */
|
|
21
23
|
segments: StackedBarChartSegment[];
|
|
22
24
|
/** Chart height in SVG units; the width scales to the container. Defaults to 220. */
|
|
@@ -38,4 +40,4 @@ export interface StackedBarChartProps extends Omit<ComponentPropsWithRef<"svg">,
|
|
|
38
40
|
/** Extra classes for the `<svg>`. */
|
|
39
41
|
className?: string;
|
|
40
42
|
}
|
|
41
|
-
export declare function StackedBarChart({ data, segments, height, "aria-label": ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, ref, ...rest }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function StackedBarChart({ data, onDatumActivate, segments, height, "aria-label": ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, ref, ...rest }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;
|