@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,15 +1,17 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
|
-
import { estimateTooltipWidth as t, formatCompactValue as n,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { estimateTooltipWidth as t, formatCompactValue as n, getSvgTooltipPosition as r } from "./chartUtils.js";
|
|
3
|
+
import { useBarChartSize as i } from "./useChartSize.js";
|
|
4
|
+
import { getBarActivationProps as a, getBarAxisLayout as o } from "./barChartUtils.js";
|
|
5
|
+
import { useMemo as s, useState as c } from "react";
|
|
6
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
5
7
|
//#region src/components/charts/StackedBarChart.tsx
|
|
6
|
-
var
|
|
8
|
+
var f = {
|
|
7
9
|
top: 20,
|
|
8
10
|
right: 12,
|
|
9
11
|
bottom: 30,
|
|
10
12
|
left: 48
|
|
11
|
-
},
|
|
12
|
-
function
|
|
13
|
+
}, p = 4;
|
|
14
|
+
function m(e) {
|
|
13
15
|
let t = /^(\d{4})-(\d{2})-(\d{2})T(\d{2})/.exec(e);
|
|
14
16
|
if (t) {
|
|
15
17
|
let [, e, n, r, i] = t;
|
|
@@ -29,7 +31,7 @@ function f(e) {
|
|
|
29
31
|
timeZone: "UTC"
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
function
|
|
34
|
+
function h(e, t) {
|
|
33
35
|
let n = e[t];
|
|
34
36
|
if (typeof n == "number") return Number.isFinite(n) ? n : 0;
|
|
35
37
|
if (typeof n == "string") {
|
|
@@ -38,10 +40,10 @@ function p(e, t) {
|
|
|
38
40
|
}
|
|
39
41
|
return 0;
|
|
40
42
|
}
|
|
41
|
-
function
|
|
42
|
-
return t.reduce((t, n) => t + Math.max(0,
|
|
43
|
+
function g(e, t) {
|
|
44
|
+
return t.reduce((t, n) => t + Math.max(0, h(e, n.key)), 0);
|
|
43
45
|
}
|
|
44
|
-
function
|
|
46
|
+
function ee(e, t, n, r, i) {
|
|
45
47
|
let a = Math.min(i, Math.max(0, n / 2), Math.max(0, r));
|
|
46
48
|
return a <= 0 ? `M ${e} ${t} H ${e + n} V ${t + r} H ${e} Z` : [
|
|
47
49
|
`M ${e} ${t + r}`,
|
|
@@ -53,146 +55,152 @@ function h(e, t, n, r, i) {
|
|
|
53
55
|
"Z"
|
|
54
56
|
].join(" ");
|
|
55
57
|
}
|
|
56
|
-
function
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-label": x = "Stacked bar chart", tooltipRows: S, valueFormatter: te, tooltipValueFormatter: ne, xLabelCount: C = 6, barGap: w, minBarWidth: T = 1, className: E, ref: D, ...O }) {
|
|
59
|
+
let { rootRef: k, size: A, viewBoxWidth: j } = i(D), [M, N] = c(null), P = Math.max(f.top + f.bottom + 1, b), F = A?.height ?? P, I = s(() => _.map((e) => m(e.date)), [_]), { left: L, plotWidth: R, indices: z } = s(() => o(I, C, A?.width, f), [
|
|
60
|
+
I,
|
|
61
|
+
C,
|
|
62
|
+
A?.width
|
|
63
|
+
]), B = Math.max(1, F - f.top - f.bottom), V = _.reduce((e, t) => Math.max(e, g(t, y)), 1), H = Math.ceil(V / 2), U = H > 0 && H < V, W = w ?? (_.length > 60 ? 2 : _.length > 30 ? 3 : 6), G = Math.max(1, T), K = _.length > 1 ? Math.max(0, (R - _.length * G) / Math.max(_.length - 1, 1)) : 0, q = _.length > 1 ? Math.min(Math.max(0, W), K) : 0, J = _.length > 0 ? (R - q * Math.max(_.length - 1, 0)) / _.length : 0, Y = M === null ? null : _[M], X = te ?? n, Z = ne ?? ((e) => e.toLocaleString());
|
|
64
|
+
function Q(e) {
|
|
65
|
+
return L + e * (J + q);
|
|
60
66
|
}
|
|
61
|
-
function
|
|
62
|
-
return e /
|
|
67
|
+
function $(e) {
|
|
68
|
+
return e / V * B;
|
|
63
69
|
}
|
|
64
|
-
return /* @__PURE__ */
|
|
65
|
-
ref:
|
|
70
|
+
return /* @__PURE__ */ d("svg", {
|
|
71
|
+
ref: k,
|
|
66
72
|
...O,
|
|
67
73
|
width: "100%",
|
|
68
|
-
|
|
74
|
+
height: A && P,
|
|
75
|
+
viewBox: `0 0 ${j} ${F}`,
|
|
69
76
|
className: e("select-none", E),
|
|
70
|
-
role: "img",
|
|
71
|
-
"aria-label":
|
|
77
|
+
role: v ? "group" : "img",
|
|
78
|
+
"aria-label": x,
|
|
72
79
|
children: [
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
x:
|
|
75
|
-
y:
|
|
80
|
+
/* @__PURE__ */ u("text", {
|
|
81
|
+
x: L - 8,
|
|
82
|
+
y: f.top,
|
|
76
83
|
textAnchor: "end",
|
|
77
84
|
dominantBaseline: "central",
|
|
78
85
|
fill: "var(--text-tertiary)",
|
|
79
86
|
fontSize: 10,
|
|
80
|
-
children:
|
|
87
|
+
children: X(V)
|
|
81
88
|
}),
|
|
82
|
-
|
|
83
|
-
x:
|
|
84
|
-
y:
|
|
89
|
+
U && /* @__PURE__ */ u("text", {
|
|
90
|
+
x: L - 8,
|
|
91
|
+
y: f.top + B / 2,
|
|
85
92
|
textAnchor: "end",
|
|
86
93
|
dominantBaseline: "central",
|
|
87
94
|
fill: "var(--text-tertiary)",
|
|
88
95
|
fontSize: 10,
|
|
89
|
-
children:
|
|
96
|
+
children: X(H)
|
|
90
97
|
}),
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
x:
|
|
93
|
-
y:
|
|
98
|
+
/* @__PURE__ */ u("text", {
|
|
99
|
+
x: L - 8,
|
|
100
|
+
y: f.top + B,
|
|
94
101
|
textAnchor: "end",
|
|
95
102
|
dominantBaseline: "central",
|
|
96
103
|
fill: "var(--text-tertiary)",
|
|
97
104
|
fontSize: 10,
|
|
98
105
|
children: "0"
|
|
99
106
|
}),
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
x1:
|
|
102
|
-
y1:
|
|
103
|
-
x2:
|
|
104
|
-
y2:
|
|
107
|
+
/* @__PURE__ */ u("line", {
|
|
108
|
+
x1: L,
|
|
109
|
+
y1: f.top + B,
|
|
110
|
+
x2: L + R,
|
|
111
|
+
y2: f.top + B,
|
|
105
112
|
stroke: "var(--border)",
|
|
106
113
|
strokeWidth: 1
|
|
107
114
|
}),
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
-
x1:
|
|
110
|
-
y1:
|
|
111
|
-
x2:
|
|
112
|
-
y2:
|
|
115
|
+
/* @__PURE__ */ u("line", {
|
|
116
|
+
x1: L,
|
|
117
|
+
y1: f.top + B / 2,
|
|
118
|
+
x2: L + R,
|
|
119
|
+
y2: f.top + B / 2,
|
|
113
120
|
stroke: "var(--border)",
|
|
114
121
|
strokeWidth: 1,
|
|
115
122
|
strokeDasharray: "3 3",
|
|
116
123
|
opacity: .5
|
|
117
124
|
}),
|
|
118
|
-
|
|
119
|
-
let n =
|
|
125
|
+
_.map((e, t) => {
|
|
126
|
+
let n = Q(t), r = M === t, i = 0, o = y.map((t) => ({
|
|
120
127
|
segment: t,
|
|
121
|
-
value: Math.max(0,
|
|
128
|
+
value: Math.max(0, h(e, t.key))
|
|
122
129
|
})).filter(({ value: e }) => e > 0);
|
|
123
|
-
return /* @__PURE__ */
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
return /* @__PURE__ */ d("g", {
|
|
131
|
+
...a(v, e, t),
|
|
132
|
+
onMouseEnter: () => N(t),
|
|
133
|
+
onMouseLeave: () => N(null),
|
|
134
|
+
onPointerEnter: () => N(t),
|
|
135
|
+
onPointerDown: () => N(t),
|
|
136
|
+
onPointerLeave: () => N(null),
|
|
137
|
+
onFocus: () => N(t),
|
|
138
|
+
onBlur: () => N(null),
|
|
131
139
|
tabIndex: 0,
|
|
132
140
|
role: "button",
|
|
133
|
-
"aria-label": `${
|
|
141
|
+
"aria-label": `${I[t]}: ${Z(g(e, y))}`,
|
|
134
142
|
children: [
|
|
135
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ u("rect", {
|
|
136
144
|
x: n,
|
|
137
|
-
y:
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
145
|
+
y: f.top,
|
|
146
|
+
width: J,
|
|
147
|
+
height: B,
|
|
140
148
|
fill: "transparent"
|
|
141
149
|
}),
|
|
142
|
-
|
|
143
|
-
let
|
|
144
|
-
return i +=
|
|
145
|
-
d:
|
|
150
|
+
o.map(({ segment: e, value: t }, a) => {
|
|
151
|
+
let s = $(t), c = f.top + B - i - s, l = a === o.length - 1;
|
|
152
|
+
return i += s, l ? /* @__PURE__ */ u("path", {
|
|
153
|
+
d: ee(n, c, J, s, p),
|
|
146
154
|
fill: e.color,
|
|
147
155
|
opacity: r ? 1 : e.opacity ?? .9
|
|
148
|
-
}, e.key) : /* @__PURE__ */
|
|
156
|
+
}, e.key) : /* @__PURE__ */ u("rect", {
|
|
149
157
|
x: n,
|
|
150
|
-
y:
|
|
151
|
-
width:
|
|
152
|
-
height:
|
|
158
|
+
y: c,
|
|
159
|
+
width: J,
|
|
160
|
+
height: s,
|
|
153
161
|
fill: e.color,
|
|
154
162
|
opacity: r ? 1 : e.opacity ?? .9
|
|
155
163
|
}, e.key);
|
|
156
164
|
}),
|
|
157
|
-
|
|
158
|
-
x: n +
|
|
159
|
-
y:
|
|
165
|
+
z.has(t) && /* @__PURE__ */ u("text", {
|
|
166
|
+
x: n + J / 2,
|
|
167
|
+
y: F - 5,
|
|
160
168
|
textAnchor: "middle",
|
|
161
169
|
fill: "var(--text-tertiary)",
|
|
162
170
|
fontSize: 10,
|
|
163
|
-
children:
|
|
171
|
+
children: I[t]
|
|
164
172
|
})
|
|
165
173
|
]
|
|
166
174
|
}, `${e.date}-${t}`);
|
|
167
175
|
}),
|
|
168
|
-
|
|
176
|
+
Y && M !== null && /* @__PURE__ */ u("g", {
|
|
169
177
|
pointerEvents: "none",
|
|
170
178
|
children: (() => {
|
|
171
|
-
let e =
|
|
179
|
+
let e = Q(M) + J / 2, n = S?.(Y) ?? y.map((e) => ({
|
|
172
180
|
color: e.color,
|
|
173
181
|
label: e.label,
|
|
174
|
-
value:
|
|
175
|
-
})),
|
|
176
|
-
boundsHeight:
|
|
177
|
-
boundsWidth:
|
|
182
|
+
value: h(Y, e.key)
|
|
183
|
+
})), i = g(Y, y), a = r(e, f.top + B - $(i), {
|
|
184
|
+
boundsHeight: F,
|
|
185
|
+
boundsWidth: j,
|
|
178
186
|
height: 28 + n.length * 15,
|
|
179
187
|
offset: 8,
|
|
180
|
-
width: t([
|
|
188
|
+
width: t([m(Y.date), ...n.map((e) => `${e.label} ${Z(e.value)}`)], {
|
|
181
189
|
maxWidth: 240,
|
|
182
190
|
minWidth: 150
|
|
183
191
|
})
|
|
184
|
-
}),
|
|
185
|
-
return /* @__PURE__ */
|
|
186
|
-
/* @__PURE__ */
|
|
192
|
+
}), o = a.x + 10, s = a.x + a.width - 10;
|
|
193
|
+
return /* @__PURE__ */ d(l, { children: [
|
|
194
|
+
/* @__PURE__ */ u("line", {
|
|
187
195
|
x1: e,
|
|
188
|
-
y1:
|
|
196
|
+
y1: f.top,
|
|
189
197
|
x2: e,
|
|
190
|
-
y2:
|
|
198
|
+
y2: f.top + B,
|
|
191
199
|
stroke: "var(--border-strong)",
|
|
192
200
|
strokeWidth: 1,
|
|
193
201
|
strokeDasharray: "3 3"
|
|
194
202
|
}),
|
|
195
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ u("rect", {
|
|
196
204
|
x: a.x,
|
|
197
205
|
y: a.y,
|
|
198
206
|
width: a.width,
|
|
@@ -202,40 +210,40 @@ function g({ data: g, segments: _, height: v = 220, "aria-label": y = "Stacked b
|
|
|
202
210
|
stroke: "var(--border)",
|
|
203
211
|
strokeWidth: 1
|
|
204
212
|
}),
|
|
205
|
-
/* @__PURE__ */
|
|
206
|
-
x:
|
|
213
|
+
/* @__PURE__ */ u("text", {
|
|
214
|
+
x: o,
|
|
207
215
|
y: a.y + 14,
|
|
208
216
|
fill: "var(--text-primary)",
|
|
209
217
|
fontSize: 10,
|
|
210
218
|
fontWeight: 600,
|
|
211
|
-
children:
|
|
219
|
+
children: m(Y.date)
|
|
212
220
|
}),
|
|
213
221
|
n.map((e, t) => {
|
|
214
222
|
let n = a.y + 30 + t * 15;
|
|
215
|
-
return /* @__PURE__ */
|
|
216
|
-
e.color && /* @__PURE__ */
|
|
217
|
-
x:
|
|
223
|
+
return /* @__PURE__ */ d("g", { children: [
|
|
224
|
+
e.color && /* @__PURE__ */ u("rect", {
|
|
225
|
+
x: o,
|
|
218
226
|
y: n - 6,
|
|
219
227
|
width: 6,
|
|
220
228
|
height: 6,
|
|
221
229
|
rx: 1,
|
|
222
230
|
fill: e.color
|
|
223
231
|
}),
|
|
224
|
-
/* @__PURE__ */
|
|
225
|
-
x: e.color ?
|
|
232
|
+
/* @__PURE__ */ u("text", {
|
|
233
|
+
x: e.color ? o + 12 : o,
|
|
226
234
|
y: n,
|
|
227
235
|
fill: "var(--text-secondary)",
|
|
228
236
|
fontSize: 10,
|
|
229
237
|
children: e.label
|
|
230
238
|
}),
|
|
231
|
-
/* @__PURE__ */
|
|
232
|
-
x:
|
|
239
|
+
/* @__PURE__ */ u("text", {
|
|
240
|
+
x: s,
|
|
233
241
|
y: n,
|
|
234
242
|
textAnchor: "end",
|
|
235
243
|
fill: "var(--text-primary)",
|
|
236
244
|
fontSize: 10,
|
|
237
245
|
fontWeight: 600,
|
|
238
|
-
children:
|
|
246
|
+
children: Z(e.value)
|
|
239
247
|
})
|
|
240
248
|
] }, e.label);
|
|
241
249
|
})
|
|
@@ -246,4 +254,4 @@ function g({ data: g, segments: _, height: v = 220, "aria-label": y = "Stacked b
|
|
|
246
254
|
});
|
|
247
255
|
}
|
|
248
256
|
//#endregion
|
|
249
|
-
export {
|
|
257
|
+
export { _ as StackedBarChart };
|
|
@@ -7,6 +7,8 @@ export interface VerticalBarChartDatum {
|
|
|
7
7
|
export interface VerticalBarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
|
|
8
8
|
/** Bars to draw left to right, each with a `label`, numeric `value`, and optional `color`. */
|
|
9
9
|
data: VerticalBarChartDatum[];
|
|
10
|
+
/** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
|
|
11
|
+
onDatumActivate?: (datum: VerticalBarChartDatum, index: number) => void;
|
|
10
12
|
/** Chart height in SVG units; the width scales to the container. Defaults to 180. */
|
|
11
13
|
height?: number;
|
|
12
14
|
/** Explicit domain maximum. Defaults to the largest positive value. */
|
|
@@ -30,4 +32,4 @@ export interface VerticalBarChartProps extends Omit<ComponentPropsWithRef<"svg">
|
|
|
30
32
|
/** Extra classes for the `<svg>`. */
|
|
31
33
|
className?: string;
|
|
32
34
|
}
|
|
33
|
-
export declare function VerticalBarChart({ data, height, maxValue, valueFormatter, tooltipValueFormatter, labelFormatter, maxLabelLength, xLabelCount, barGap, minBarWidth, "aria-label": ariaLabel, className, ref, ...rest }: VerticalBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function VerticalBarChart({ data, onDatumActivate, height, maxValue, valueFormatter, tooltipValueFormatter, labelFormatter, maxLabelLength, xLabelCount, barGap, minBarWidth, "aria-label": ariaLabel, className, ref, ...rest }: VerticalBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { clamp as t } from "../../lib/math.js";
|
|
3
|
-
import { estimateTooltipWidth as n, formatCompactValue as r,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { estimateTooltipWidth as n, formatCompactValue as r, getPositiveValue as i, getSvgTooltipPosition as a, resolveChartColor as o, truncateChartLabel as s } from "./chartUtils.js";
|
|
4
|
+
import { useBarChartSize as c } from "./useChartSize.js";
|
|
5
|
+
import { getBarActivationProps as l, getBarAxisLayout as u } from "./barChartUtils.js";
|
|
6
|
+
import { useMemo as d, useState as f } from "react";
|
|
7
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
6
8
|
//#region src/components/charts/VerticalBarChart.tsx
|
|
7
|
-
var
|
|
9
|
+
var h = [
|
|
8
10
|
1,
|
|
9
11
|
.85,
|
|
10
12
|
.7,
|
|
@@ -12,126 +14,135 @@ var p = [
|
|
|
12
14
|
.45,
|
|
13
15
|
.35,
|
|
14
16
|
.25
|
|
15
|
-
],
|
|
17
|
+
], g = {
|
|
16
18
|
top: 20,
|
|
17
19
|
right: 8,
|
|
18
20
|
bottom: 24,
|
|
19
21
|
left: 40
|
|
20
|
-
}
|
|
21
|
-
function
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
};
|
|
23
|
+
function _({ data: _, onDatumActivate: v, height: y = 180, maxValue: b, valueFormatter: x, tooltipValueFormatter: S, labelFormatter: C, maxLabelLength: w, xLabelCount: T = 7, barGap: E = 6, minBarWidth: D = 4, "aria-label": O = "Vertical bar chart", className: k, ref: A, ...j }) {
|
|
24
|
+
let { rootRef: M, size: N, viewBoxWidth: P } = c(A), [F, I] = f(null), L = Math.max(g.top + g.bottom + 1, y), R = N?.height ?? L, z = d(() => _.map((e, t) => C?.(e.label, e, t) ?? e.label), [_, C]), B = d(() => z.map((e) => s(e, w)), [z, w]), { left: V, plotWidth: H, indices: U } = d(() => u(B, T, N?.width, g), [
|
|
25
|
+
B,
|
|
26
|
+
T,
|
|
27
|
+
N?.width
|
|
28
|
+
]), W = Math.max(1, R - g.top - g.bottom), G = b === void 0 ? Math.max(..._.map((e) => i(e.value)), 1) : Math.max(i(b), 1), K = Math.max(0, E), q = Math.max(1, D), J = _.length > 1 ? Math.max(0, (H - _.length * q) / Math.max(_.length - 1, 1)) : 0, Y = _.length > 1 ? Math.min(K, J) : 0, X = _.length > 0 ? Math.max(0, (H - Y * Math.max(_.length - 1, 0)) / _.length) : 0, Z = x ?? r, Q = S ?? ((e) => e.toLocaleString());
|
|
29
|
+
return /* @__PURE__ */ m("svg", {
|
|
30
|
+
ref: M,
|
|
31
|
+
...j,
|
|
26
32
|
width: "100%",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
33
|
+
height: N && L,
|
|
34
|
+
viewBox: `0 0 ${P} ${R}`,
|
|
35
|
+
className: e("select-none", k),
|
|
36
|
+
role: v ? "group" : "img",
|
|
37
|
+
"aria-label": O,
|
|
31
38
|
children: [
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
x:
|
|
34
|
-
y:
|
|
39
|
+
/* @__PURE__ */ p("text", {
|
|
40
|
+
x: V - 6,
|
|
41
|
+
y: g.top + 4,
|
|
35
42
|
textAnchor: "end",
|
|
36
43
|
fill: "var(--text-tertiary)",
|
|
37
44
|
fontSize: 10,
|
|
38
|
-
children:
|
|
45
|
+
children: Z(G)
|
|
39
46
|
}),
|
|
40
|
-
/* @__PURE__ */
|
|
41
|
-
x:
|
|
42
|
-
y:
|
|
47
|
+
/* @__PURE__ */ p("text", {
|
|
48
|
+
x: V - 6,
|
|
49
|
+
y: g.top + W,
|
|
43
50
|
textAnchor: "end",
|
|
44
51
|
dominantBaseline: "central",
|
|
45
52
|
fill: "var(--text-tertiary)",
|
|
46
53
|
fontSize: 10,
|
|
47
54
|
children: "0"
|
|
48
55
|
}),
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
x1:
|
|
51
|
-
y1:
|
|
52
|
-
x2:
|
|
53
|
-
y2:
|
|
56
|
+
/* @__PURE__ */ p("line", {
|
|
57
|
+
x1: V,
|
|
58
|
+
y1: g.top + W,
|
|
59
|
+
x2: V + H,
|
|
60
|
+
y2: g.top + W,
|
|
54
61
|
stroke: "var(--border)",
|
|
55
62
|
strokeWidth: 1
|
|
56
63
|
}),
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
x1:
|
|
59
|
-
y1:
|
|
60
|
-
x2:
|
|
61
|
-
y2:
|
|
64
|
+
/* @__PURE__ */ p("line", {
|
|
65
|
+
x1: V,
|
|
66
|
+
y1: g.top + W / 2,
|
|
67
|
+
x2: V + H,
|
|
68
|
+
y2: g.top + W / 2,
|
|
62
69
|
stroke: "var(--border)",
|
|
63
70
|
strokeWidth: 1,
|
|
64
71
|
strokeDasharray: "3 3",
|
|
65
72
|
opacity: .5
|
|
66
73
|
}),
|
|
67
|
-
|
|
68
|
-
let
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
_.map((e, r) => {
|
|
75
|
+
let s = V + r * (X + Y), c = t(i(e.value), 0, G) / G * W, u = g.top + W - c, d = F === r, f = z[r], _ = B[r], y = _ !== f, b = Q(e.value);
|
|
76
|
+
return /* @__PURE__ */ m("g", {
|
|
77
|
+
...l(v, e, r),
|
|
78
|
+
onMouseEnter: () => I(r),
|
|
79
|
+
onMouseLeave: () => I(null),
|
|
80
|
+
onPointerEnter: () => I(r),
|
|
81
|
+
onPointerDown: () => I(r),
|
|
82
|
+
onPointerLeave: () => I(null),
|
|
83
|
+
onFocus: () => I(r),
|
|
84
|
+
onBlur: () => I(null),
|
|
77
85
|
tabIndex: 0,
|
|
78
86
|
role: "button",
|
|
79
|
-
"aria-label": `${
|
|
87
|
+
"aria-label": `${f}: ${b}`,
|
|
80
88
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
x:
|
|
83
|
-
y:
|
|
84
|
-
width:
|
|
85
|
-
height:
|
|
89
|
+
/* @__PURE__ */ p("rect", {
|
|
90
|
+
x: s,
|
|
91
|
+
y: g.top,
|
|
92
|
+
width: X,
|
|
93
|
+
height: W,
|
|
86
94
|
fill: "transparent"
|
|
87
95
|
}),
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
x:
|
|
90
|
-
y:
|
|
91
|
-
width:
|
|
92
|
-
height:
|
|
93
|
-
fill:
|
|
96
|
+
/* @__PURE__ */ p("rect", {
|
|
97
|
+
x: s,
|
|
98
|
+
y: u,
|
|
99
|
+
width: X,
|
|
100
|
+
height: c,
|
|
101
|
+
fill: o(e.color),
|
|
94
102
|
rx: 6,
|
|
95
|
-
opacity:
|
|
103
|
+
opacity: d ? 1 : h[r % h.length],
|
|
96
104
|
style: { transition: "all 150ms" }
|
|
97
105
|
}),
|
|
98
|
-
U.has(r) && /* @__PURE__ */
|
|
99
|
-
x:
|
|
100
|
-
y:
|
|
106
|
+
U.has(r) && /* @__PURE__ */ m("text", {
|
|
107
|
+
x: s + X / 2,
|
|
108
|
+
y: R - 4,
|
|
101
109
|
textAnchor: "middle",
|
|
102
110
|
fill: "var(--text-tertiary)",
|
|
103
111
|
fontSize: 10,
|
|
104
|
-
children: [
|
|
112
|
+
children: [y && /* @__PURE__ */ p("title", { children: f }), _]
|
|
105
113
|
}),
|
|
106
|
-
|
|
107
|
-
let e =
|
|
108
|
-
boundsHeight:
|
|
109
|
-
boundsWidth:
|
|
114
|
+
d && (() => {
|
|
115
|
+
let e = a(s + X / 2, u, {
|
|
116
|
+
boundsHeight: R,
|
|
117
|
+
boundsWidth: P,
|
|
110
118
|
height: 24,
|
|
111
119
|
offset: 8,
|
|
112
|
-
width: n([
|
|
120
|
+
width: n([f, b], {
|
|
113
121
|
maxWidth: 180,
|
|
114
122
|
minWidth: 72
|
|
115
123
|
})
|
|
116
124
|
}), t = e.x + e.width / 2;
|
|
117
|
-
return /* @__PURE__ */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
return /* @__PURE__ */ m("g", {
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
children: [/* @__PURE__ */ p("rect", {
|
|
128
|
+
x: e.x,
|
|
129
|
+
y: e.y,
|
|
130
|
+
width: e.width,
|
|
131
|
+
height: e.height,
|
|
132
|
+
rx: 4,
|
|
133
|
+
fill: "var(--bg-tooltip, var(--bg-tertiary))",
|
|
134
|
+
stroke: "var(--border)",
|
|
135
|
+
strokeWidth: 1
|
|
136
|
+
}), /* @__PURE__ */ p("text", {
|
|
137
|
+
x: t,
|
|
138
|
+
y: e.y + 15,
|
|
139
|
+
textAnchor: "middle",
|
|
140
|
+
fill: "var(--text-primary)",
|
|
141
|
+
fontSize: 10,
|
|
142
|
+
fontWeight: 600,
|
|
143
|
+
children: b
|
|
144
|
+
})]
|
|
145
|
+
});
|
|
135
146
|
})()
|
|
136
147
|
]
|
|
137
148
|
}, e.label);
|
|
@@ -140,4 +151,4 @@ function g({ data: g, height: _ = 180, maxValue: v, valueFormatter: y, tooltipVa
|
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
153
|
//#endregion
|
|
143
|
-
export {
|
|
154
|
+
export { _ as VerticalBarChart };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KeyboardEvent } from "react";
|
|
2
|
+
export declare function getBarActivationProps<T>(activate: ((datum: T, index: number) => void) | undefined, datum: T, index: number): {
|
|
3
|
+
onClick?: undefined;
|
|
4
|
+
onKeyDown?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
onKeyDown(event: KeyboardEvent<SVGGElement>): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function getBarAxisLayout(labels: string[], cap: number, measuredWidth: number | undefined, padding: {
|
|
10
|
+
left: number;
|
|
11
|
+
right: number;
|
|
12
|
+
}): {
|
|
13
|
+
left: number;
|
|
14
|
+
plotWidth: number;
|
|
15
|
+
indices: Set<number>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { estimateTextWidth as e, getFittingLabelCount as t, getLabelIndices as n } from "./chartUtils.js";
|
|
2
|
+
//#region src/components/charts/barChartUtils.ts
|
|
3
|
+
function r(e, t, n) {
|
|
4
|
+
return e ? {
|
|
5
|
+
onClick: () => e(t, n),
|
|
6
|
+
onKeyDown(r) {
|
|
7
|
+
r.key !== "Enter" && r.key !== " " || (r.preventDefault(), r.repeat || e(t, n));
|
|
8
|
+
}
|
|
9
|
+
} : {};
|
|
10
|
+
}
|
|
11
|
+
function i(r, i, a, o) {
|
|
12
|
+
let s = a ?? 600, c = (t, n) => a && i > 0 && t ? Math.max(n, Math.min(s / 4, e(t) / 2 + 4)) : n, l = c(r[0], o.left), u = Math.max(0, s - l - c(r.at(-1), o.right)), d = i;
|
|
13
|
+
if (a && r.length > 1 && i > 1) {
|
|
14
|
+
let n = r.reduce((t, n) => Math.max(t, e(n)), 0), a = u * (1 - 1 / r.length);
|
|
15
|
+
d = Math.min(i, t(r.length, a, n));
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
left: l,
|
|
19
|
+
plotWidth: u,
|
|
20
|
+
indices: new Set(n(r.length, d))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { r as getBarActivationProps, i as getBarAxisLayout };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare function formatCompactValue(value: number): string;
|
|
2
2
|
export declare function resolveChartColor(color: string | undefined): string;
|
|
3
3
|
export declare function getLabelIndices(length: number, labelCount: number): number[];
|
|
4
|
+
/** Limit evenly sampled ticks to whole intervals that fit a label plus a gap. */
|
|
5
|
+
export declare function getFittingLabelCount(length: number, plotWidth: number, labelWidth: number): number;
|
|
4
6
|
export declare function getPositiveValue(value: number): number;
|
|
5
7
|
export interface ChartTooltipPosition {
|
|
6
8
|
height: number;
|