@tristan2828/ui-foundation 4.131.0 → 4.133.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/conventions/docs/design-language.md +112 -39
- package/dist/components/app/entity-view.js +4 -3
- package/dist/components/app/stacked-area-chart.d.ts +29 -0
- package/dist/components/app/stacked-area-chart.js +91 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lib/line-chart-layout.d.ts +16 -0
- package/dist/lib/line-chart-layout.js +24 -0
- package/package.json +1 -1
- package/styles/index.css +6 -0
|
@@ -3,43 +3,45 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [Palettes](#palettes) · lines
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Status marks](#status-marks) · lines
|
|
11
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
12
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
13
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
14
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
15
|
-
- [Heat scale](#heat-scale) · lines
|
|
16
|
-
- [Depth ramps](#depth-ramps) · lines
|
|
17
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
18
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
19
|
-
- [Typography](#typography) · lines
|
|
20
|
-
- [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines
|
|
21
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
22
|
-
- [Density](#density) · lines
|
|
23
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [A list as
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
37
|
-
- [A
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
42
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 54–163
|
|
7
|
+
- [Glow](#glow) · lines 165–184
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 186–214
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 216–233
|
|
10
|
+
- [Status marks](#status-marks) · lines 235–280
|
|
11
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 282–311
|
|
12
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 313–326
|
|
13
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 328–372
|
|
14
|
+
- [Categorical colour](#categorical-colour) · lines 374–444
|
|
15
|
+
- [Heat scale](#heat-scale) · lines 446–507
|
|
16
|
+
- [Depth ramps](#depth-ramps) · lines 509–594
|
|
17
|
+
- [A stored colour](#a-stored-colour) · lines 596–653
|
|
18
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 655–676
|
|
19
|
+
- [Typography](#typography) · lines 678–849
|
|
20
|
+
- [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 712–745
|
|
21
|
+
- [Written text (notes)](#written-text-notes) · lines 747–849
|
|
22
|
+
- [Density](#density) · lines 851–971
|
|
23
|
+
- [Rows on this device](#rows-on-this-device) · lines 917–944
|
|
24
|
+
- [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 946–971
|
|
25
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 973–1087
|
|
26
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1089–1166
|
|
27
|
+
- [Notices](#notices) · lines 1168–1196
|
|
28
|
+
- [A value over time](#a-value-over-time) · lines 1198–1328
|
|
29
|
+
- [Several values over time](#several-values-over-time) · lines 1247–1285
|
|
30
|
+
- [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1287–1328
|
|
31
|
+
- [A list as a board](#a-list-as-a-board) · lines 1330–1446
|
|
32
|
+
- [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1383–1446
|
|
33
|
+
- [A list as cards](#a-list-as-cards) · lines 1448–1494
|
|
34
|
+
- [Images full screen](#images-full-screen) · lines 1496–1542
|
|
35
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1544–1580
|
|
36
|
+
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1582–1652
|
|
37
|
+
- [A few equal things](#a-few-equal-things) · lines 1654–1774
|
|
38
|
+
- [An overview page](#an-overview-page) · lines 1776–1847
|
|
39
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1848–1914
|
|
40
|
+
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1916–2053
|
|
41
|
+
- [Picking at random](#picking-at-random) · lines 2055–2086
|
|
42
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 2088–2155
|
|
43
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2157–2182
|
|
44
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2184–2280
|
|
43
45
|
|
|
44
46
|
<!-- /index -->
|
|
45
47
|
|
|
@@ -941,6 +943,33 @@ toggle in an app without a palette).
|
|
|
941
943
|
- Content inside cells (an inline editor, a button, a badge) must fit both
|
|
942
944
|
heights; check a cell like that at both.
|
|
943
945
|
|
|
946
|
+
### Page width (a record on a wide screen)
|
|
947
|
+
|
|
948
|
+
A record page (`EntityView`) keeps a reading width: its column is at most
|
|
949
|
+
`max-w-4xl`, and with a facts rail the page is that plus the 300px rail.
|
|
950
|
+
On a TV the right of the page is then empty. `data-width="wide"` on
|
|
951
|
+
`<html>` (4.133) lifts the cap: the column fills the page and the rail
|
|
952
|
+
stays 300px, moving right with it.
|
|
953
|
+
|
|
954
|
+
```ts
|
|
955
|
+
// The app's own Page Width setting, kept per browser, applied before first paint.
|
|
956
|
+
document.documentElement.dataset.width = wide ? 'wide' : ''
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
- **The app owns the setting**, as it owns Text Size: a field on its
|
|
960
|
+
settings page, kept in `localStorage`, set on `<html>` by a script in
|
|
961
|
+
`index.html` so the first paint has it. Regular (no attribute) is the
|
|
962
|
+
layout as it always was.
|
|
963
|
+
- **Only the record page widens.** A record in a dialog over its list
|
|
964
|
+
keeps the dialog's size (the rule skips anything inside
|
|
965
|
+
`role="dialog"`); a phone is unchanged, since the column already fills
|
|
966
|
+
it; lists already take the content's width.
|
|
967
|
+
- **Long text reflows to the column**: notes and tabs fill it; the
|
|
968
|
+
Details tab keeps its own 42rem.
|
|
969
|
+
- Anything else of the package's that should follow it uses the
|
|
970
|
+
`page-wide:` variant (`page-wide:max-w-none`), which has the same
|
|
971
|
+
dialog rule.
|
|
972
|
+
|
|
944
973
|
## Widget cards (hub pages)
|
|
945
974
|
|
|
946
975
|
A hub page (an app's home screen) shows a few small widgets from
|
|
@@ -1251,8 +1280,52 @@ balance's history beside low, middle and high projections.
|
|
|
1251
1280
|
when no series has a point, a dot for a series of one point.
|
|
1252
1281
|
- **A screen reader gets a summary** (each series from first to last
|
|
1253
1282
|
value, and the target) and a table with a column per series.
|
|
1254
|
-
- Up to four or five series. More than that, or bars
|
|
1255
|
-
|
|
1283
|
+
- Up to four or five series. More than that, or bars, are a request for
|
|
1284
|
+
the foundation. Amounts that add up to a total are a stacked area:
|
|
1285
|
+
`StackedAreaChart`, "Parts of a whole over time" below.
|
|
1286
|
+
|
|
1287
|
+
### Parts of a whole over time
|
|
1288
|
+
|
|
1289
|
+
`StackedAreaChart` (4.132) shows several amounts that add up to a total,
|
|
1290
|
+
each a category, over time: a portfolio by asset class, a budget by
|
|
1291
|
+
envelope. Each band is stacked on the one below, from zero, so the top
|
|
1292
|
+
edge is the total and both the growth and the mix show.
|
|
1293
|
+
|
|
1294
|
+
```tsx
|
|
1295
|
+
<StackedAreaChart
|
|
1296
|
+
label="Allocation over time"
|
|
1297
|
+
xs={snapshotDates}
|
|
1298
|
+
series={[
|
|
1299
|
+
{ label: 'US stocks', values: usStocks },
|
|
1300
|
+
{ label: 'International', values: international },
|
|
1301
|
+
{ label: 'Bonds', values: bonds },
|
|
1302
|
+
{ label: 'Cash', values: cash },
|
|
1303
|
+
]}
|
|
1304
|
+
formatY={usd}
|
|
1305
|
+
formatX={month}
|
|
1306
|
+
isLoading={isLoading}
|
|
1307
|
+
/>
|
|
1308
|
+
```
|
|
1309
|
+
|
|
1310
|
+
- **Colours are categorical slots**, in order (band 1 takes
|
|
1311
|
+
`category-1`, unless it gives its own `category`), opaque, with a 1px
|
|
1312
|
+
card-coloured line between neighbouring bands. Keep it to about six:
|
|
1313
|
+
the first six slots stay apart for colour-blind readers.
|
|
1314
|
+
- **Amounts, stacked from zero:** the range is 0 to the largest total,
|
|
1315
|
+
with room above. There is no share (100%) mode.
|
|
1316
|
+
- **One shared `xs`**, oldest first; each band's `values` line up with
|
|
1317
|
+
it. A missing or negative value counts as 0 everywhere (the plot, the
|
|
1318
|
+
legend, the table), so a gap is a 0, not a hole.
|
|
1319
|
+
- **The legend** lists the top band first, as the picture reads, each
|
|
1320
|
+
with its latest value and its share of the latest total (rounded, so
|
|
1321
|
+
they may not add to exactly 100), then the total.
|
|
1322
|
+
- **The states:** a skeleton at its height while loading; one quiet line
|
|
1323
|
+
when there are no xs, no bands, or only zeros; one stacked column
|
|
1324
|
+
mid-plot for a single snapshot (it turns into bands at the second);
|
|
1325
|
+
the bands.
|
|
1326
|
+
- **A screen reader gets a summary** (the total from first to last, each
|
|
1327
|
+
band's latest value and share) and a table with a column per band and
|
|
1328
|
+
a Total column.
|
|
1256
1329
|
|
|
1257
1330
|
## A list as a board
|
|
1258
1331
|
|
|
@@ -213,7 +213,8 @@ const RAIL_LAYOUT = {
|
|
|
213
213
|
// first section of the open tab (beside the tab's content, never its bar),
|
|
214
214
|
// or the first card when the record's first content isn't the tabs (4.108).
|
|
215
215
|
const FACTS_RAIL = {
|
|
216
|
-
|
|
216
|
+
// Page width wide (data-width="wide" on <html>): no cap, the column fills the page.
|
|
217
|
+
page: 'max-w-[calc(var(--container-4xl)+var(--spacing)*6+300px)] page-wide:max-w-none',
|
|
217
218
|
columns: 'grid grid-cols-[minmax(0,1fr)_300px] items-start gap-6',
|
|
218
219
|
main: 'flex min-w-0 flex-col gap-6',
|
|
219
220
|
rail: 'col-start-2 row-start-1 flex min-w-0 flex-col gap-6',
|
|
@@ -236,7 +237,7 @@ function EntityViewSkeleton({ layout, mobileOrder }) {
|
|
|
236
237
|
const main = (_jsx("div", { className: RAIL_LAYOUT.main, children: _jsx(SkeletonCard, { rows: 6, stacked: false }) }));
|
|
237
238
|
return (_jsxs("div", { className: RAIL_LAYOUT.page, "data-state": "loading", "data-layout": "rail", children: [header, _jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, _jsx("div", { className: cn(RAIL_LAYOUT.rail, 'flex flex-col gap-6'), children: _jsx(SkeletonCard, { rows: 4, stacked: true }) }), mobileOrder === 'rail-first' && main] })] }));
|
|
238
239
|
}
|
|
239
|
-
return (_jsxs("div", { className: "flex max-w-4xl flex-col gap-6", "data-state": "loading", children: [header, Array.from({ length: 2 }, (_, section) => (_jsx(SkeletonCard, { rows: 4, stacked: false }, section)))] }));
|
|
240
|
+
return (_jsxs("div", { className: "flex max-w-4xl flex-col gap-6 page-wide:max-w-none", "data-state": "loading", children: [header, Array.from({ length: 2 }, (_, section) => (_jsx(SkeletonCard, { rows: 4, stacked: false }, section)))] }));
|
|
240
241
|
}
|
|
241
242
|
// The rail's top offset (top-6) plus as much again below it.
|
|
242
243
|
const RAIL_MARGIN_PX = 48;
|
|
@@ -469,5 +470,5 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
469
470
|
}
|
|
470
471
|
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsx(BesideFactsRailContext.Provider, { value: railFacts.length > 0, children: _jsxs("div", { ref: setRoot, className: layout === 'rail' && !card
|
|
471
472
|
? RAIL_LAYOUT.page
|
|
472
|
-
: cn('flex flex-col', railFacts.length > 0 ? FACTS_RAIL.page : 'max-w-4xl', card ? 'gap-4' : 'gap-6'), "data-facts-rail": railFacts.length > 0 ? '' : undefined, "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx(KeepPencilRoomContext.Provider, { value: true, children: _jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }) }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 has-[[data-slot=action-hint]]:items-start sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && (!card || cardStrip) && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), body, footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }) }));
|
|
473
|
+
: cn('flex flex-col', railFacts.length > 0 ? FACTS_RAIL.page : 'max-w-4xl page-wide:max-w-none', card ? 'gap-4' : 'gap-6'), "data-facts-rail": railFacts.length > 0 ? '' : undefined, "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx(KeepPencilRoomContext.Provider, { value: true, children: _jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }) }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 has-[[data-slot=action-hint]]:items-start sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && (!card || cardStrip) && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), body, footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }) }));
|
|
473
474
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CategorySlot } from "./module-card.js";
|
|
2
|
+
import { type LineChartPoint } from "../../lib/line-chart-layout.js";
|
|
3
|
+
export type StackedSeries = {
|
|
4
|
+
/** The band's name in the legend and the table: "US stocks". */
|
|
5
|
+
label: string;
|
|
6
|
+
/** One amount per x, in xs' order: 0 or more. A missing or negative value counts as 0. */
|
|
7
|
+
values: readonly number[];
|
|
8
|
+
/** Its colour, a categorical slot. Defaults to its place in `series` + 1 (1, 2, 3…). */
|
|
9
|
+
category?: CategorySlot;
|
|
10
|
+
};
|
|
11
|
+
export type StackedAreaChartProps = {
|
|
12
|
+
/** The figure's name: "Allocation over time". */
|
|
13
|
+
label: string;
|
|
14
|
+
/** The shared x of every band, oldest first: days ('YYYY-MM-DD'), numbers or names. */
|
|
15
|
+
xs: readonly LineChartPoint["x"][];
|
|
16
|
+
/** The bands, bottom first. Keep it to about six: the slots that stay apart for colour-blind readers. */
|
|
17
|
+
series: readonly StackedSeries[];
|
|
18
|
+
/** A value as shown: `usd`. Defaults to the number as the browser writes it. */
|
|
19
|
+
formatY?: (y: number) => string;
|
|
20
|
+
/** An x as shown: `formatPlainDate`. Defaults to x as given. */
|
|
21
|
+
formatX?: (x: LineChartPoint["x"]) => string;
|
|
22
|
+
/** The plot's height in px; the chart fills its container's width. */
|
|
23
|
+
height?: number;
|
|
24
|
+
isLoading?: boolean;
|
|
25
|
+
/** What shows when there is nothing to stack. */
|
|
26
|
+
emptyMessage?: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function StackedAreaChart({ label, xs, series, formatY, formatX, height, isLoading, emptyMessage, className, }: StackedAreaChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Parts of a whole over time (4.132): several amounts that add up to a
|
|
3
|
+
// total, each a category (a portfolio by asset class), stacked from zero
|
|
4
|
+
// so the top edge is the total and both the growth and the mix show.
|
|
5
|
+
// MultiLineChart's sibling, plain SVG the same way: each band is its own
|
|
6
|
+
// <svg> drawing in currentColor in a categorical slot's text class, so the
|
|
7
|
+
// package's glyph check measures it like any icon, and a 1px card-coloured
|
|
8
|
+
// line runs between neighbours. A legend under the plot lists the top band
|
|
9
|
+
// first with its latest value and share, then the total, so the colours
|
|
10
|
+
// never carry the meaning alone.
|
|
11
|
+
//
|
|
12
|
+
// The bands share one `xs`; each band's `values` line up with it, and a
|
|
13
|
+
// missing or negative value counts as 0. The picture is for the eye: a
|
|
14
|
+
// screen reader gets the figure's name, a summary (the total from first to
|
|
15
|
+
// last, each band's latest value and share) and a table with a column per
|
|
16
|
+
// band and a Total column, all visually hidden. The states: a skeleton at
|
|
17
|
+
// `height` while loading, one quiet line when there is nothing to stack,
|
|
18
|
+
// one stacked column mid-plot for a single snapshot, and the bands.
|
|
19
|
+
import { cn } from "cn";
|
|
20
|
+
import { Skeleton } from "../ui/skeleton.js";
|
|
21
|
+
import { stackedLayout } from "../../lib/line-chart-layout.js";
|
|
22
|
+
// Whole class names, so Tailwind sees each one.
|
|
23
|
+
const CATEGORY = {
|
|
24
|
+
1: "text-category-1",
|
|
25
|
+
2: "text-category-2",
|
|
26
|
+
3: "text-category-3",
|
|
27
|
+
4: "text-category-4",
|
|
28
|
+
5: "text-category-5",
|
|
29
|
+
6: "text-category-6",
|
|
30
|
+
7: "text-category-7",
|
|
31
|
+
8: "text-category-8",
|
|
32
|
+
9: "text-category-9",
|
|
33
|
+
10: "text-category-10",
|
|
34
|
+
11: "text-category-11",
|
|
35
|
+
12: "text-category-12",
|
|
36
|
+
};
|
|
37
|
+
const defaultY = (y) => y.toLocaleString();
|
|
38
|
+
const defaultX = (x) => String(x);
|
|
39
|
+
const percent = (fraction) => `${fraction * 100}%`;
|
|
40
|
+
const slotOf = (one, index) => one.category ?? ((index % 12) + 1);
|
|
41
|
+
export function StackedAreaChart({ label, xs, series, formatY = defaultY, formatX = defaultX, height = 160, isLoading = false, emptyMessage = "No points yet", className, }) {
|
|
42
|
+
if (isLoading) {
|
|
43
|
+
return (_jsxs("div", { "data-slot": "stacked-area-chart", "data-state": "loading", "aria-busy": "true", className: cn("min-w-0", className), children: [_jsxs("span", { className: "sr-only", children: ["Loading ", label] }), _jsx(Skeleton, { style: { height }, className: "w-full" })] }));
|
|
44
|
+
}
|
|
45
|
+
// Cleaned once: what the plot, the legend, the summary and the table use.
|
|
46
|
+
const values = series.map((one) => xs.map((_, i) => Math.max(0, one.values[i] ?? 0)));
|
|
47
|
+
const layout = stackedLayout(xs, values);
|
|
48
|
+
if (xs.length === 0 ||
|
|
49
|
+
series.length === 0 ||
|
|
50
|
+
layout.totals.every((total) => total === 0)) {
|
|
51
|
+
return (_jsx("figure", { "data-slot": "stacked-area-chart", "data-state": "empty", "aria-label": label, className: cn("min-w-0", className), children: _jsx("p", { style: { height }, className: "flex items-center justify-center rounded-md border border-dashed border-border type-body text-muted-foreground", children: emptyMessage }) }));
|
|
52
|
+
}
|
|
53
|
+
const last = xs.length - 1;
|
|
54
|
+
const lastTotal = layout.totals[last];
|
|
55
|
+
const share = (s) => lastTotal === 0
|
|
56
|
+
? undefined
|
|
57
|
+
: Math.round((values[s][last] / lastTotal) * 100);
|
|
58
|
+
const withShare = (s) => {
|
|
59
|
+
const part = share(s);
|
|
60
|
+
return part === undefined
|
|
61
|
+
? formatY(values[s][last])
|
|
62
|
+
: `${formatY(values[s][last])} (${part}%)`;
|
|
63
|
+
};
|
|
64
|
+
const summary = [
|
|
65
|
+
xs.length === 1
|
|
66
|
+
? `Total ${formatY(layout.totals[0])} on ${formatX(xs[0])}`
|
|
67
|
+
: `Total from ${formatY(layout.totals[0])} on ${formatX(xs[0])} to ${formatY(lastTotal)} on ${formatX(xs[last])}`,
|
|
68
|
+
...series.map((one, s) => `${one.label} ${withShare(s)}`),
|
|
69
|
+
].join("; ");
|
|
70
|
+
const edge = (row) => row.map((y, i) => `${layout.across[i] * 100},${y * 100}`);
|
|
71
|
+
return (_jsxs("figure", { "data-slot": "stacked-area-chart", "data-state": "success", "aria-label": label, className: cn("flex min-w-0 flex-col gap-1.5", className), children: [_jsx("div", { "aria-hidden": "true", className: "relative border-b border-border", style: { height }, children: xs.length === 1 ? (_jsx("div", { "data-slot": "stacked-area-chart-column", className: "absolute inset-y-0 left-1/2 w-3 -translate-x-1/2", children: series.map((one, s) => {
|
|
72
|
+
if (values[s][0] === 0)
|
|
73
|
+
return null;
|
|
74
|
+
const { top, bottom } = layout.bands[s];
|
|
75
|
+
return (_jsxs("svg", { "data-slot": "stacked-area-chart-segment", className: cn("absolute inset-x-0 w-full overflow-visible", CATEGORY[slotOf(one, s)]), style: {
|
|
76
|
+
top: percent(top[0]),
|
|
77
|
+
height: percent(bottom[0] - top[0]),
|
|
78
|
+
}, children: [_jsx("rect", { width: "100%", height: "100%", fill: "currentColor" }), _jsx("line", { x1: "0", x2: "100%", y1: "0", y2: "0", strokeWidth: 1, className: "stroke-card" })] }, s));
|
|
79
|
+
}) })) : (series.map((one, s) => {
|
|
80
|
+
if (values[s].every((value) => value === 0))
|
|
81
|
+
return null;
|
|
82
|
+
const { top, bottom } = layout.bands[s];
|
|
83
|
+
return (_jsxs("svg", { "data-slot": "stacked-area-chart-band", viewBox: "0 0 100 100", preserveAspectRatio: "none", className: cn("absolute inset-0 size-full overflow-visible", CATEGORY[slotOf(one, s)]), children: [_jsx("polygon", { points: [...edge(top), ...edge(bottom).reverse()].join(" "), fill: "currentColor" }), _jsx("polyline", { points: edge(top).join(" "), fill: "none", strokeWidth: 1, vectorEffect: "non-scaling-stroke", className: "stroke-card" })] }, s));
|
|
84
|
+
})) }), _jsxs("div", { "aria-hidden": "true", className: cn("flex gap-3 type-caption text-muted-foreground tabular-nums", xs.length === 1 ? "justify-center" : "justify-between"), children: [_jsx("span", { children: formatX(xs[0]) }), xs.length > 1 && _jsx("span", { children: formatX(xs[last]) })] }), _jsxs("ul", { "aria-hidden": "true", "data-slot": "stacked-area-chart-legend", className: "flex flex-wrap gap-x-4 gap-y-1 type-caption text-foreground", children: [series
|
|
85
|
+
.map((one, s) => ({ one, s }))
|
|
86
|
+
.reverse()
|
|
87
|
+
.map(({ one, s }) => {
|
|
88
|
+
const part = share(s);
|
|
89
|
+
return (_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("svg", { viewBox: "0 0 10 10", className: cn("size-2.5 shrink-0", CATEGORY[slotOf(one, s)]), children: _jsx("rect", { width: "10", height: "10", rx: "2", fill: "currentColor" }) }), _jsx("span", { children: one.label }), _jsxs("span", { className: "font-medium tabular-nums", children: [formatY(values[s][last]), part !== undefined && ` · ${part}%`] })] }, s));
|
|
90
|
+
}), _jsxs("li", { className: "flex items-center gap-1.5 text-muted-foreground", children: [_jsx("span", { children: "Total" }), _jsx("span", { className: "font-medium tabular-nums", children: formatY(lastTotal) })] })] }), _jsx("figcaption", { className: "sr-only", children: summary }), _jsx("div", { className: "sr-only", children: _jsxs("table", { children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "When" }), series.map((one, s) => (_jsx("th", { scope: "col", children: one.label }, s))), _jsx("th", { scope: "col", children: "Total" })] }) }), _jsx("tbody", { children: xs.map((x, i) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatX(x) }), series.map((_, s) => (_jsx("td", { children: formatY(values[s][i]) }, s))), _jsx("td", { children: formatY(layout.totals[i]) })] }, `${String(x)}-${i}`))) })] }) })] }));
|
|
91
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ export { SourceCredit, type Source, type SourceCreditProps } from './components/
|
|
|
95
95
|
export { ProgressRing, type ProgressRingProps } from './components/app/progress-ring.js';
|
|
96
96
|
export { LineChart, type LineChartMark, type LineChartPoint, type LineChartProps, } from './components/app/line-chart.js';
|
|
97
97
|
export { MultiLineChart, type ChartSeries, type ChartTone, type MultiLineChartProps, } from './components/app/multi-line-chart.js';
|
|
98
|
+
export { StackedAreaChart, type StackedAreaChartProps, type StackedSeries, } from './components/app/stacked-area-chart.js';
|
|
99
|
+
export type { StackedLayout } from './lib/line-chart-layout.js';
|
|
98
100
|
export { StepBar, type StepBarProps } from './components/app/step-bar.js';
|
|
99
101
|
export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
|
|
100
102
|
export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
|
package/dist/index.js
CHANGED
|
@@ -106,6 +106,7 @@ export { SourceCredit } from './components/app/source-credit.js';
|
|
|
106
106
|
export { ProgressRing } from './components/app/progress-ring.js';
|
|
107
107
|
export { LineChart, } from './components/app/line-chart.js';
|
|
108
108
|
export { MultiLineChart, } from './components/app/multi-line-chart.js';
|
|
109
|
+
export { StackedAreaChart, } from './components/app/stacked-area-chart.js';
|
|
109
110
|
export { StepBar } from './components/app/step-bar.js';
|
|
110
111
|
export { RatingStar } from './components/app/rating-star.js';
|
|
111
112
|
export { RatingScore } from './components/app/rating-score.js';
|
|
@@ -43,3 +43,19 @@ export type SeriesLayout = {
|
|
|
43
43
|
targetY?: number;
|
|
44
44
|
};
|
|
45
45
|
export declare function seriesLayout(series: readonly (readonly LineChartPoint[])[], target?: number): SeriesLayout;
|
|
46
|
+
export type StackedLayout = {
|
|
47
|
+
/** Each x's place across the plot, 0…1. */
|
|
48
|
+
across: number[];
|
|
49
|
+
/** Each band's top and bottom edge at each x, as fractions from the plot's top, bottom band first. */
|
|
50
|
+
bands: {
|
|
51
|
+
top: number[];
|
|
52
|
+
bottom: number[];
|
|
53
|
+
}[];
|
|
54
|
+
/** Each x's total. */
|
|
55
|
+
totals: number[];
|
|
56
|
+
domain: {
|
|
57
|
+
min: 0;
|
|
58
|
+
max: number;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export declare function stackedLayout(xs: readonly LineChartPoint['x'][], values: readonly (readonly number[])[]): StackedLayout;
|
|
@@ -77,3 +77,27 @@ export function seriesLayout(series, target) {
|
|
|
77
77
|
targetY: shared.targetY,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
+
// Amounts stacked from zero (StackedAreaChart, 4.132): every band shares
|
|
81
|
+
// `xs`, a band's bottom is the sum of the bands below it and its top adds
|
|
82
|
+
// its own value, so the top band's top is the total. The range is 0 to the
|
|
83
|
+
// largest total with room above only. `values` are already cleaned: one per
|
|
84
|
+
// x, 0 or more. x is placed as seriesLayout places it.
|
|
85
|
+
export function stackedLayout(xs, values) {
|
|
86
|
+
const totals = xs.map((_, i) => values.reduce((sum, band) => sum + (band[i] ?? 0), 0));
|
|
87
|
+
const max = (Math.max(0, ...totals) || 1) * (1 + PAD);
|
|
88
|
+
const height = (y) => (max - y) / max;
|
|
89
|
+
const times = xs.map(along);
|
|
90
|
+
const timed = times.every(Number.isFinite) && new Set(times).size > 1;
|
|
91
|
+
const first = timed ? Math.min(...times) : 0;
|
|
92
|
+
const span = timed ? Math.max(...times) - first : xs.length - 1;
|
|
93
|
+
const across = xs.map((_, i) => (span === 0 ? 0.5 : ((timed ? times[i] : i) - first) / span));
|
|
94
|
+
const below = xs.map(() => 0);
|
|
95
|
+
const bands = values.map((band) => {
|
|
96
|
+
const bottom = below.map(height);
|
|
97
|
+
xs.forEach((_, i) => {
|
|
98
|
+
below[i] += band[i] ?? 0;
|
|
99
|
+
});
|
|
100
|
+
return { top: below.map(height), bottom };
|
|
101
|
+
});
|
|
102
|
+
return { across, bands, totals, domain: { min: 0, max } };
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.133.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/styles/index.css
CHANGED
|
@@ -28,6 +28,12 @@
|
|
|
28
28
|
|
|
29
29
|
@custom-variant density-compact (&:where([data-density="compact"], [data-density="compact"] *));
|
|
30
30
|
|
|
31
|
+
/* Page width (4.133): data-width="wide" on <html> (an app's own setting,
|
|
32
|
+
kept per browser as Text Size's data-density is) lifts a record page's
|
|
33
|
+
reading cap, so its column fills a wide screen; the facts rail stays
|
|
34
|
+
300px. A record in a dialog keeps the dialog's size. `page-wide:max-w-none`. */
|
|
35
|
+
@custom-variant page-wide (&:where([data-width="wide"] *):not(:where([role="dialog"] *, [role="alertdialog"] *)));
|
|
36
|
+
|
|
31
37
|
@theme inline {
|
|
32
38
|
--font-heading: var(--font-sans);
|
|
33
39
|
--font-sans: 'Geist Variable', sans-serif;
|