@slotform/react-ui 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import {
|
|
2
|
+
axisStride,
|
|
3
|
+
type Bar,
|
|
4
|
+
band,
|
|
5
|
+
type ChartUnit,
|
|
6
|
+
categoryGroups,
|
|
7
|
+
chartHead,
|
|
8
|
+
chartRegions,
|
|
9
|
+
chartScale,
|
|
10
|
+
chartShare,
|
|
11
|
+
currencyOf,
|
|
12
|
+
levelScale,
|
|
13
|
+
levelUnit,
|
|
14
|
+
lifts,
|
|
15
|
+
mark,
|
|
16
|
+
spanFlat,
|
|
17
|
+
spanText,
|
|
18
|
+
spanUnit,
|
|
19
|
+
TIME_SPACE,
|
|
20
|
+
timeSpace,
|
|
21
|
+
unitSymbol,
|
|
22
|
+
} from "@slotform/ui-core/chart";
|
|
23
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
24
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
25
|
+
import { useCollection } from "@slotform/ui-core/react/read";
|
|
26
|
+
import type { Datum } from "@slotform/ui-core/read";
|
|
27
|
+
import { CHART_SERIES } from "@slotform/ui-core/tokens";
|
|
28
|
+
import {
|
|
29
|
+
CHART,
|
|
30
|
+
CHART_BAR,
|
|
31
|
+
CHART_BODY,
|
|
32
|
+
CHART_DOT,
|
|
33
|
+
CHART_GRID,
|
|
34
|
+
CHART_HEAD,
|
|
35
|
+
CHART_KEY,
|
|
36
|
+
CHART_KEY_DOT,
|
|
37
|
+
CHART_KEYS,
|
|
38
|
+
CHART_LEVEL,
|
|
39
|
+
CHART_MAIN,
|
|
40
|
+
CHART_PARTIAL,
|
|
41
|
+
CHART_SELECTED,
|
|
42
|
+
CHART_TICK_LANE,
|
|
43
|
+
CHART_TOTAL,
|
|
44
|
+
chartBand,
|
|
45
|
+
chartFill,
|
|
46
|
+
FIGURES,
|
|
47
|
+
lineBox,
|
|
48
|
+
text,
|
|
49
|
+
textStrong,
|
|
50
|
+
} from "@slotform/ui-core/variants";
|
|
51
|
+
import { VIRTUAL_FROM } from "@slotform/ui-core/window";
|
|
52
|
+
import {
|
|
53
|
+
memo,
|
|
54
|
+
type ReactNode,
|
|
55
|
+
useLayoutEffect,
|
|
56
|
+
useMemo,
|
|
57
|
+
useRef,
|
|
58
|
+
useState,
|
|
59
|
+
} from "react";
|
|
60
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
61
|
+
import { textSize } from "../../lib/measure.ts";
|
|
62
|
+
import { PAINT_BOX, Painted } from "../../lib/paint.tsx";
|
|
63
|
+
import { FrameBody, FrameLine, stillOf } from "../../lib/read.tsx";
|
|
64
|
+
import { Decoded } from "../../lib/region.tsx";
|
|
65
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
66
|
+
import { Swap } from "../../lib/swap.tsx";
|
|
67
|
+
import { BAR_CHART_BODY } from "../../lib/walk-classes.ts";
|
|
68
|
+
import { Scroller, useScroller, Window } from "../../lib/window.tsx";
|
|
69
|
+
|
|
70
|
+
const STACK = "flex flex-col min-w-0";
|
|
71
|
+
const TOTAL = "flex items-baseline";
|
|
72
|
+
const HEAD = "flex flex-col";
|
|
73
|
+
const KEYS = "flex flex-wrap";
|
|
74
|
+
const KEY = "inline-flex items-center";
|
|
75
|
+
const DOT = "shrink-0";
|
|
76
|
+
// The body stands half a meta line below the head, so the top tick, centred
|
|
77
|
+
// on the plot's top edge, keeps the pair gap from the head's last line.
|
|
78
|
+
const BODY = BAR_CHART_BODY;
|
|
79
|
+
const AXIS = "flex flex-col shrink-0";
|
|
80
|
+
// With no tick to draw (a waiting chart, a chart of nothing but zeros) the
|
|
81
|
+
// axis is not drawn, and its lane and the gap after it are the body's padding
|
|
82
|
+
// and the plot's margin, so the plot stands where it will.
|
|
83
|
+
const NO_AXIS = "ps-figures";
|
|
84
|
+
const NO_AXIS_MAIN = "ms-gap";
|
|
85
|
+
const AXIS_BAND = "relative flex-1";
|
|
86
|
+
// A tick centres on its gridline; the last band's bottom is the baseline,
|
|
87
|
+
// whose tick is the floor: zero, or a level's floor under its readings.
|
|
88
|
+
const TICK =
|
|
89
|
+
"absolute end-0 top-0 -translate-y-1/2 max-w-measure-short truncate";
|
|
90
|
+
const ZERO = "absolute end-0 bottom-0 translate-y-1/2";
|
|
91
|
+
const MAIN = "grow min-w-0";
|
|
92
|
+
// The plot over its time line, the whole width the axis leaves.
|
|
93
|
+
const PLOT_MAIN = "flex flex-col";
|
|
94
|
+
// Past `VIRTUAL_FROM` bars the plot keeps a bar's width and scrolls sideways
|
|
95
|
+
// under the axis, which stays; the bars window along x.
|
|
96
|
+
const SCROLLS = "overflow-x-auto focus-visible:-outline-offset-2";
|
|
97
|
+
const WIDE = "w-max min-w-full";
|
|
98
|
+
const BAR_WIDE = "w-target shrink-0";
|
|
99
|
+
const PLOT = "relative";
|
|
100
|
+
// The gridlines stand behind the bars' regions, at the same height.
|
|
101
|
+
const GRID = "absolute inset-x-0 top-0 flex flex-col";
|
|
102
|
+
const GRID_BAND = "flex-1";
|
|
103
|
+
const BARS = "relative flex";
|
|
104
|
+
// A bar's region is its region: the plot's height, the bar standing on its
|
|
105
|
+
// floor.
|
|
106
|
+
const REGION = "flex flex-col justify-end items-center";
|
|
107
|
+
// A region is the plot's width over its regions (`chartRegions`, `--regions` on the
|
|
108
|
+
// plot): a short series stands in the first of them.
|
|
109
|
+
const BAR_FIT = "shrink-0 min-w-0 basis-[calc(100%/var(--regions))]";
|
|
110
|
+
// The bar's column: the region's full height, its parts laid over it, each the
|
|
111
|
+
// whole column scaled (`CHART_BAR`), or a level's dots travelled down it
|
|
112
|
+
// (`CHART_LEVEL`), so a value moves by transform.
|
|
113
|
+
const COLUMN = "relative h-full w-2/3";
|
|
114
|
+
// The time line under the plot, parted as the plot is: the first bar's time
|
|
115
|
+
// under the first bar and the last bar's under the last, each centred on its
|
|
116
|
+
// bar and whole. A time wider than its bar's region keeps the plot's edge: the
|
|
117
|
+
// first runs on toward the end and the last back toward the start. Each is a
|
|
118
|
+
// box a region wide at its bar's place, as the times between stand at theirs
|
|
119
|
+
// (`TIME_SPACE_BOX`), and the time is centred in it by auto margins, which a
|
|
120
|
+
// time wider than the region loses, standing flush at the region's start (the
|
|
121
|
+
// last's line reversed, at its end). The line is a meta line high whichever
|
|
122
|
+
// times it holds.
|
|
123
|
+
const TIMES = "relative flex min-h-lh";
|
|
124
|
+
const TIME =
|
|
125
|
+
"absolute top-0 flex min-w-0 w-[calc(100%/var(--regions))] whitespace-nowrap";
|
|
126
|
+
const TIME_FIRST = "start-0";
|
|
127
|
+
const TIME_LAST = "flex-row-reverse";
|
|
128
|
+
const TIME_TEXT = "mx-auto";
|
|
129
|
+
// A time between the ends stands at its bar's centre in a box as wide as its
|
|
130
|
+
// room (`timeSpace`, in regions) over `TIME_SPACE` times the longest time's
|
|
131
|
+
// characters (`--time`): the `time` container, whose one `ch` is the test
|
|
132
|
+
// `time-fits:` draws it by, so a stride's times appear together as the plot
|
|
133
|
+
// widens and none ever touches another. No measure: the container decides.
|
|
134
|
+
const TIME_SPACE_BOX =
|
|
135
|
+
"absolute top-0 @container/time w-[calc(100%*var(--space)/var(--regions)/var(--time))]";
|
|
136
|
+
const TIME_MID =
|
|
137
|
+
"absolute top-0 start-0 -translate-x-1/2 whitespace-nowrap hidden time-fits:block";
|
|
138
|
+
// A categorical axis: the names stand in groups of a stride's bars, each group
|
|
139
|
+
// as wide as the regions it spans (`--span` of the plot's `--regions`) and holding
|
|
140
|
+
// one name, centred in its first bar's region (the group's width over its span)
|
|
141
|
+
// and overflowing it to both sides, so a name wider than the region (the stride
|
|
142
|
+
// leaves room) is never cut and no bar without a name has an empty box under
|
|
143
|
+
// it.
|
|
144
|
+
const CATEGORIES = "flex";
|
|
145
|
+
const CATEGORY =
|
|
146
|
+
"flex shrink-0 min-w-0 basis-[calc(100%*var(--span)/var(--regions))]";
|
|
147
|
+
const CATEGORY_REGION =
|
|
148
|
+
"flex justify-center min-w-0 w-[calc(100%/var(--span))]";
|
|
149
|
+
const CATEGORY_NAME = "whitespace-nowrap";
|
|
150
|
+
|
|
151
|
+
// The plot's width as it resizes, and the meta size it is drawn at (read off
|
|
152
|
+
// the page, so the theme's size knob moves it), for a categorical axis's stride
|
|
153
|
+
// (`axisStride`): how many names fit side by side is a measure of the drawn
|
|
154
|
+
// width, which no container query can count. Undefined before it is measured.
|
|
155
|
+
// It measures only while `on` (an axis of names): a hook cannot stand behind
|
|
156
|
+
// the condition.
|
|
157
|
+
function usePlotWidth(
|
|
158
|
+
ref: { readonly current: HTMLElement | null },
|
|
159
|
+
on: boolean,
|
|
160
|
+
): { width: number | undefined; meta: number | undefined } {
|
|
161
|
+
const [measured, setMeasured] = useState<{
|
|
162
|
+
width: number | undefined;
|
|
163
|
+
meta: number | undefined;
|
|
164
|
+
}>({ width: undefined, meta: undefined });
|
|
165
|
+
useLayoutEffect(() => {
|
|
166
|
+
const node = ref.current;
|
|
167
|
+
if (!on || !node) return;
|
|
168
|
+
const measure = () => {
|
|
169
|
+
const meta = textSize("meta", node);
|
|
170
|
+
setMeasured({
|
|
171
|
+
width: node.clientWidth,
|
|
172
|
+
meta: Number.isFinite(meta) ? meta : undefined,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
measure();
|
|
176
|
+
const resize = new ResizeObserver(measure);
|
|
177
|
+
resize.observe(node);
|
|
178
|
+
return () => resize.disconnect();
|
|
179
|
+
}, [ref, on]);
|
|
180
|
+
return measured;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The waiting time line: two fillers, at its start and its end.
|
|
184
|
+
const PAINTED_TIMES = "flex";
|
|
185
|
+
const PAINTED_TIME_END = "ms-auto";
|
|
186
|
+
|
|
187
|
+
interface Figures {
|
|
188
|
+
// The head's and the keys' figures.
|
|
189
|
+
figure: Intl.NumberFormat;
|
|
190
|
+
// The axis's ticks, in the lane four figures wide.
|
|
191
|
+
tick: Intl.NumberFormat;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Every figure of one chart in one notation: compact once its axis reaches
|
|
195
|
+
// five figures, so a tick stays inside its four-figure lane. Money keeps its
|
|
196
|
+
// figures exact (the cents of "$30.97" are not the axis's step) and writes
|
|
197
|
+
// its ticks short: no cents when the step is whole.
|
|
198
|
+
function formatters(
|
|
199
|
+
top: number,
|
|
200
|
+
step: number,
|
|
201
|
+
unit: ChartUnit | undefined,
|
|
202
|
+
): Figures {
|
|
203
|
+
const compact = top >= 10_000;
|
|
204
|
+
const currency = currencyOf(unit);
|
|
205
|
+
if (currency === undefined) {
|
|
206
|
+
const plain = formatterFor(
|
|
207
|
+
"number",
|
|
208
|
+
undefined,
|
|
209
|
+
compact
|
|
210
|
+
? { notation: "compact", maximumFractionDigits: 1 }
|
|
211
|
+
: { maximumFractionDigits: 1 },
|
|
212
|
+
);
|
|
213
|
+
return { figure: plain, tick: plain };
|
|
214
|
+
}
|
|
215
|
+
const money = { style: "currency", currency } as const;
|
|
216
|
+
const whole = { minimumFractionDigits: 0, maximumFractionDigits: 0 };
|
|
217
|
+
return {
|
|
218
|
+
figure: formatterFor("number", undefined, money),
|
|
219
|
+
tick: formatterFor("number", undefined, {
|
|
220
|
+
...money,
|
|
221
|
+
...(compact
|
|
222
|
+
? {
|
|
223
|
+
notation: "compact",
|
|
224
|
+
minimumFractionDigits: 0,
|
|
225
|
+
maximumFractionDigits: 1,
|
|
226
|
+
}
|
|
227
|
+
: Number.isInteger(step)
|
|
228
|
+
? whole
|
|
229
|
+
: {}),
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** One function per bar region, each called with a loaded item. */
|
|
235
|
+
export interface BarRegions<T> {
|
|
236
|
+
/** The item's React key, unique in the chart. */
|
|
237
|
+
key: (item: T) => string;
|
|
238
|
+
/** The bar's total. */
|
|
239
|
+
value: (item: T) => number;
|
|
240
|
+
/** The bar's parts' values by the chart's `keys`; a key it lacks is 0. */
|
|
241
|
+
parts?: (item: T) => Readonly<Record<string, number>> | undefined;
|
|
242
|
+
/** The time drawn under its own bar (a word; never wraps or cuts): the first bar's and the last's always, and those between at evenly spaced strides (every 12th, 6th, 2nd bar, then each) as the plot's width holds them, so give every bar its time. */
|
|
243
|
+
at?: (item: T) => string | undefined;
|
|
244
|
+
/** The category under this bar, for an axis of buckets (hours, plans, countries) where `at` names times: every bar is named when the names fit under their bars, and every second, third… one when they would touch. Given, it takes the time line's place. A chart from `VIRTUAL_FROM` bars scrolls at a fixed bar width and draws its times (`at`) instead (a word; never wraps). */
|
|
245
|
+
label?: (item: T) => string | undefined;
|
|
246
|
+
/** The bar's period is not over (this month so far): it is drawn hatched, so a short last bar does not read as a fall. A flow's bar; a level's reading is drawn as any other. */
|
|
247
|
+
partial?: (item: T) => boolean;
|
|
248
|
+
/** The bar of the record open beside the chart (the month whose report stands in the next Pane): its region carries the selection wash, as a selected row does. */
|
|
249
|
+
selected?: (item: T) => boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Columns over time: one bar per item, stacked by one dimension when `keys` names its parts. */
|
|
253
|
+
export type BarChartProps<T = unknown> = Closed & {
|
|
254
|
+
/** The items the bars draw, oldest first: constants, or a selection, which paints the chart until its read lands. A selection is the chart's own frame: it holds its read and draws the failed, missing and empty shapes in its own box whatever stands above it. */
|
|
255
|
+
items: Datum<readonly T[]>;
|
|
256
|
+
/** What the chart counts, which names the plot (a short phrase; read aloud, never drawn). */
|
|
257
|
+
label: string;
|
|
258
|
+
/** The names a bar's parts stack by, bottom first (each a word; the legend wraps between names): present, the chart is stacked and draws them as its legend in every form, each name holding its series mark. */
|
|
259
|
+
keys?: readonly string[];
|
|
260
|
+
/** The bar regions, read from each item. */
|
|
261
|
+
bar: BarRegions<T>;
|
|
262
|
+
/** What the values count (`requests`, `minutes`), drawn after the total; a unit that takes a plural is `{ one, other }` (`{ one: "flag", other: "flags" }`), the form chosen by the figure it follows; money is `{ currency: "USD" }`, its figures written in the currency with no word after them. */
|
|
263
|
+
unit?: ChartUnit;
|
|
264
|
+
/** The bars are a level, not a flow (a reading each hour, open flags per round, not requests per day): the head draws their span, the lowest bar to the highest ("18.2–21°C", "1–3 flags"), and each key its part's span, never their sum and never the last bar, which is the thing's own reading its record says. A span whose ends are one reading (one bar, a flat day) is that reading, so it draws no figure: no total line, and a key its name and mark alone. The plot draws each reading as a dot (each key's its own, in its mark) against an axis around the readings, its floor a step under the lowest and its top over the highest, so the swing reads; a flow's bars stand on zero, a bar's length its value. A unit that never sums (a share, `%`, or a temperature, `°C`) is a level unless this is `false`. */
|
|
265
|
+
level?: boolean;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const NONE: readonly never[] = [];
|
|
269
|
+
|
|
270
|
+
const part = (bar: Bar, key: string) => bar.parts?.[key] ?? 0;
|
|
271
|
+
|
|
272
|
+
// One bar's region in the plot: the bar, or its parts stacked, standing on the
|
|
273
|
+
// plot's floor; a level's reading, or each key's, a dot at its place.
|
|
274
|
+
const BarRegion = memo(function BarRegion(props: {
|
|
275
|
+
bar: Bar;
|
|
276
|
+
keys: readonly string[] | undefined;
|
|
277
|
+
top: number;
|
|
278
|
+
floor: number;
|
|
279
|
+
level: boolean;
|
|
280
|
+
wide: boolean;
|
|
281
|
+
}) {
|
|
282
|
+
const { bar, keys, top, floor, level } = props;
|
|
283
|
+
// A part is the whole column scaled to its share of the axis top and lifted
|
|
284
|
+
// over the parts under it, one clear line higher for each of them that draws.
|
|
285
|
+
const fill = (value: number, under: number, gap: number): VarStyle => ({
|
|
286
|
+
"--fill": value / top,
|
|
287
|
+
"--stack": `calc(${(under / top) * 100}% + ${gap} * var(--spacing-hairline))`,
|
|
288
|
+
});
|
|
289
|
+
const values = keys?.map((key) => part(bar, key)) ?? [];
|
|
290
|
+
const gaps = lifts(values);
|
|
291
|
+
// A reading travels down from the plot's top by the share it stands under it.
|
|
292
|
+
const travel = (value: number): VarStyle => ({
|
|
293
|
+
"--travel": `${(1 - chartShare(value, { floor, top })) * 100}%`,
|
|
294
|
+
});
|
|
295
|
+
return (
|
|
296
|
+
<div
|
|
297
|
+
className={cn(
|
|
298
|
+
CHART_GRID,
|
|
299
|
+
REGION,
|
|
300
|
+
props.wide ? BAR_WIDE : BAR_FIT,
|
|
301
|
+
bar.selected && CHART_SELECTED,
|
|
302
|
+
)}
|
|
303
|
+
>
|
|
304
|
+
<div className={cn(COLUMN, bar.partial && !level && CHART_PARTIAL)}>
|
|
305
|
+
{level ? (
|
|
306
|
+
(keys ?? [undefined]).map((key, at) => (
|
|
307
|
+
<div
|
|
308
|
+
key={key ?? ""}
|
|
309
|
+
className={CHART_LEVEL}
|
|
310
|
+
style={travel(key === undefined ? bar.value : (values[at] ?? 0))}
|
|
311
|
+
>
|
|
312
|
+
<div
|
|
313
|
+
className={cn(
|
|
314
|
+
chartFill({
|
|
315
|
+
series: key === undefined ? CHART_SERIES[0] : mark(at),
|
|
316
|
+
}),
|
|
317
|
+
CHART_DOT,
|
|
318
|
+
)}
|
|
319
|
+
/>
|
|
320
|
+
</div>
|
|
321
|
+
))
|
|
322
|
+
) : keys ? (
|
|
323
|
+
// The first part stands on the baseline, each next one over it.
|
|
324
|
+
keys.map((key, at) => (
|
|
325
|
+
<div
|
|
326
|
+
key={key}
|
|
327
|
+
className={cn(chartFill({ series: mark(at) }), CHART_BAR)}
|
|
328
|
+
style={fill(
|
|
329
|
+
values[at] ?? 0,
|
|
330
|
+
values.slice(0, at).reduce((sum, one) => sum + one, 0),
|
|
331
|
+
gaps[at] ?? 0,
|
|
332
|
+
)}
|
|
333
|
+
/>
|
|
334
|
+
))
|
|
335
|
+
) : (
|
|
336
|
+
<div
|
|
337
|
+
className={cn(chartFill({ series: CHART_SERIES[0] }), CHART_BAR)}
|
|
338
|
+
style={fill(bar.value, 0, 0)}
|
|
339
|
+
/>
|
|
340
|
+
)}
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
/** The total (the bars' span with `level`, none where that span is one reading) at body 500 with its unit, the parts' keys under it, then the axis beside the plot, its four gridlines a hairline each with its tick centred on it and the baseline with its 0, the columns in the chip marks by part, each bar in its region of the plot (at least `CHART_REGIONS`, seven: a shorter series, a day's first hours, stands in the first of them, the rest of the plot its gridlines); with `level`, each reading a dot in its mark against an axis around the readings (`levelScale`: its floor a step under the lowest, its top over the highest), the baseline's tick that floor. The first bar's time stands centred under the first bar and the last bar's under the last, each kept whole inside the plot, and the times between at evenly spaced strides (`timeSpace`: every 12th bar, every 6th, every 2nd, then each), each stride's drawn where its room holds twice the longest time, a container query of the time line, never a measure. A chart given `bar.label` (under `VIRTUAL_FROM` bars) names its bars on that line in the times' place: every bar where the names fit under their bars, else every `n`th (`axisStride`, from the plot's width), each name centred under its bar in a group as wide as its stride's bars, so no bar without a name has a box of its own. From `VIRTUAL_FROM` bars the plot keeps a bar's width and scrolls sideways, the axis staying, and only the bars near the view are drawn, the time line spanning the scrolled width so the last time stands whole at the end. While the `items` selection's read waits, the total is a figure's filler, the legend stands (its names and marks declared, its figures painted), the plot is one painted box at its loaded height with the axis's lane kept and the time line is two fillers at its place, the chart inert. A bar given `bar.partial` (its period not over) is drawn hatched and one given `bar.selected` (its record open beside the chart) stands in the selection wash. The chart is a frame of its items: it draws the failed shape with Retry, the missing shape and the empty shape in its own box with the generic sentence, and the stale and paused line above itself while it holds its read, whatever stands above it. */
|
|
347
|
+
export function BarChart<T>(props: BarChartProps<T>) {
|
|
348
|
+
const { label, keys, unit, level } = props;
|
|
349
|
+
const { drawn, frame } = useCollection(props.items);
|
|
350
|
+
const { painted } = drawn;
|
|
351
|
+
const { bar } = props;
|
|
352
|
+
const items = painted ? NONE : drawn.value;
|
|
353
|
+
// The bars are read from their items once per answer, so a bar's region
|
|
354
|
+
// renders only when its own bar changed.
|
|
355
|
+
const series = useMemo<Bar[]>(
|
|
356
|
+
() =>
|
|
357
|
+
items.map((item) => ({
|
|
358
|
+
key: bar.key(item),
|
|
359
|
+
value: bar.value(item),
|
|
360
|
+
parts: bar.parts?.(item),
|
|
361
|
+
partial: bar.partial?.(item) === true,
|
|
362
|
+
selected: bar.selected?.(item) === true,
|
|
363
|
+
})),
|
|
364
|
+
[items, bar],
|
|
365
|
+
);
|
|
366
|
+
// The times: the first bar's and the last bar's, each under its bar, and
|
|
367
|
+
// the bars' between, each with its room (`timeSpace`).
|
|
368
|
+
const times = useMemo(
|
|
369
|
+
() =>
|
|
370
|
+
items.map((item, index) => ({
|
|
371
|
+
index,
|
|
372
|
+
time: bar.at?.(item),
|
|
373
|
+
space: timeSpace(index, items.length),
|
|
374
|
+
})),
|
|
375
|
+
[items, bar],
|
|
376
|
+
);
|
|
377
|
+
const first = times[0];
|
|
378
|
+
const last = times.length > 1 ? times[times.length - 1] : undefined;
|
|
379
|
+
const start = first?.time;
|
|
380
|
+
const end = last?.time;
|
|
381
|
+
const between = times.filter(
|
|
382
|
+
(time) => time.space !== undefined && time.time !== undefined,
|
|
383
|
+
);
|
|
384
|
+
const longest = Math.max(1, ...times.map((time) => time.time?.length ?? 0));
|
|
385
|
+
// A chart of buckets names its bars in the times' place, under a long
|
|
386
|
+
// chart's windowing, which draws its times instead.
|
|
387
|
+
const categories =
|
|
388
|
+
bar.label !== undefined && items.length < VIRTUAL_FROM
|
|
389
|
+
? items.map((item) => bar.label?.(item) ?? "")
|
|
390
|
+
: NONE;
|
|
391
|
+
const labels = keys ?? [];
|
|
392
|
+
const peaks = series.map((bar) =>
|
|
393
|
+
keys ? keys.reduce((sum, key) => sum + part(bar, key), 0) : bar.value,
|
|
394
|
+
);
|
|
395
|
+
const peak = Math.max(0, ...peaks);
|
|
396
|
+
const leveled = level ?? levelUnit(unit);
|
|
397
|
+
// A level stands against its readings' range, each key's its own; a flow
|
|
398
|
+
// on zero, its bars stacked.
|
|
399
|
+
const scale = leveled
|
|
400
|
+
? levelScale(
|
|
401
|
+
keys
|
|
402
|
+
? series.flatMap((bar) => keys.map((key) => part(bar, key)))
|
|
403
|
+
: series.map((bar) => bar.value),
|
|
404
|
+
)
|
|
405
|
+
: chartScale(
|
|
406
|
+
peaks,
|
|
407
|
+
series.flatMap((bar) => [
|
|
408
|
+
bar.value,
|
|
409
|
+
...labels.map((key) => part(bar, key)),
|
|
410
|
+
]),
|
|
411
|
+
);
|
|
412
|
+
const { step, top, bands, floor } = scale;
|
|
413
|
+
const { figure, tick } = formatters(top, step, unit);
|
|
414
|
+
const head = chartHead(series, labels, leveled);
|
|
415
|
+
const { total } = head;
|
|
416
|
+
// A level's figure that is one reading draws none: the record says it.
|
|
417
|
+
const said = (span: { low: number; high: number }) =>
|
|
418
|
+
painted || !leveled || !spanFlat(span, (value) => figure.format(value));
|
|
419
|
+
// The plot's regions: a short series stands in the first of them.
|
|
420
|
+
const regionCount = chartRegions(series.length);
|
|
421
|
+
const regions: VarStyle = { "--regions": regionCount };
|
|
422
|
+
const spanned = (span: number): VarStyle => ({ "--span": span });
|
|
423
|
+
const timed: VarStyle = { "--time": TIME_SPACE * longest };
|
|
424
|
+
const spaceAt = (index: number, space: number | undefined): VarStyle => ({
|
|
425
|
+
"--space": space,
|
|
426
|
+
insetInlineStart: `${((index + 0.5) / regionCount) * 100}%`,
|
|
427
|
+
});
|
|
428
|
+
const word = unit ? spanUnit(unit, total) : undefined;
|
|
429
|
+
const keyTotals = labels.map((label, at) => ({
|
|
430
|
+
label,
|
|
431
|
+
value: head.parts[at] ?? { low: 0, high: 0 },
|
|
432
|
+
}));
|
|
433
|
+
const totalLine = !said(total) ? null : (
|
|
434
|
+
<div className={cn(CHART_TOTAL, TOTAL)}>
|
|
435
|
+
<span
|
|
436
|
+
className={cn(
|
|
437
|
+
text({ role: "body" }),
|
|
438
|
+
textStrong({ role: "body" }),
|
|
439
|
+
FIGURES,
|
|
440
|
+
)}
|
|
441
|
+
>
|
|
442
|
+
<Decoded
|
|
443
|
+
role="figure"
|
|
444
|
+
painted={painted}
|
|
445
|
+
text={
|
|
446
|
+
spanText(total, (value) => figure.format(value)) +
|
|
447
|
+
(unitSymbol(unit) ?? "")
|
|
448
|
+
}
|
|
449
|
+
of={total.high}
|
|
450
|
+
/>
|
|
451
|
+
</span>
|
|
452
|
+
{word ? <span className={text({ role: "meta" })}>{word}</span> : null}
|
|
453
|
+
</div>
|
|
454
|
+
);
|
|
455
|
+
// A long chart keeps a bar's width and windows its bars (each with its
|
|
456
|
+
// time) along x, in a scroller of its own around the plot.
|
|
457
|
+
const windowed = series.length >= VIRTUAL_FROM;
|
|
458
|
+
// The axis draws its ticks, which a flow of nothing (every bar zero) and a
|
|
459
|
+
// waiting chart have none of; a level of zeros reads zero.
|
|
460
|
+
const ticks = !painted && (leveled ? series.length > 0 : peak > 0);
|
|
461
|
+
const scroll = useScroller();
|
|
462
|
+
const bars = useRef<HTMLDivElement>(null);
|
|
463
|
+
const plot = useRef<HTMLDivElement>(null);
|
|
464
|
+
const measured = usePlotWidth(plot, categories.length > 0);
|
|
465
|
+
const stride = axisStride(
|
|
466
|
+
regionCount,
|
|
467
|
+
measured.width,
|
|
468
|
+
Math.max(0, ...categories.map((name) => name.length)),
|
|
469
|
+
measured.meta,
|
|
470
|
+
);
|
|
471
|
+
return (
|
|
472
|
+
<FrameBody frame={frame}>
|
|
473
|
+
<FrameLine frame={frame} />
|
|
474
|
+
<div
|
|
475
|
+
data-wide=""
|
|
476
|
+
inert={painted || undefined}
|
|
477
|
+
data-still={stillOf(frame)}
|
|
478
|
+
className={cn(CHART, STACK)}
|
|
479
|
+
>
|
|
480
|
+
{labels.length > 0 ? (
|
|
481
|
+
<div className={cn(CHART_HEAD, HEAD)}>
|
|
482
|
+
{totalLine}
|
|
483
|
+
<div className={cn(CHART_KEYS, KEYS)}>
|
|
484
|
+
{keyTotals.map((key, at) => (
|
|
485
|
+
<Key key={key.label} name={key.label} at={at}>
|
|
486
|
+
{said(key.value) ? (
|
|
487
|
+
<span className={cn(text({ role: "meta" }), FIGURES)}>
|
|
488
|
+
<Decoded
|
|
489
|
+
role="figure"
|
|
490
|
+
at={at}
|
|
491
|
+
painted={painted}
|
|
492
|
+
text={spanText(key.value, (value) =>
|
|
493
|
+
figure.format(value),
|
|
494
|
+
)}
|
|
495
|
+
of={key.value.high}
|
|
496
|
+
/>
|
|
497
|
+
</span>
|
|
498
|
+
) : null}
|
|
499
|
+
</Key>
|
|
500
|
+
))}
|
|
501
|
+
</div>
|
|
502
|
+
</div>
|
|
503
|
+
) : (
|
|
504
|
+
totalLine
|
|
505
|
+
)}
|
|
506
|
+
<div
|
|
507
|
+
className={cn(
|
|
508
|
+
CHART_BODY,
|
|
509
|
+
BODY,
|
|
510
|
+
lineBox({ role: "meta" }),
|
|
511
|
+
!ticks && NO_AXIS,
|
|
512
|
+
)}
|
|
513
|
+
>
|
|
514
|
+
{ticks ? (
|
|
515
|
+
<div aria-hidden className={cn(CHART_GRID, CHART_TICK_LANE, AXIS)}>
|
|
516
|
+
{Array.from({ length: bands }, (_, index) => (
|
|
517
|
+
<div
|
|
518
|
+
key={index}
|
|
519
|
+
className={cn(
|
|
520
|
+
chartBand({ kind: "axis", rule: band(index, bands) }),
|
|
521
|
+
AXIS_BAND,
|
|
522
|
+
)}
|
|
523
|
+
>
|
|
524
|
+
<span className={cn(text({ role: "meta" }), FIGURES, TICK)}>
|
|
525
|
+
{/* A rescaled axis cross-fades its labels while its bars move together. */}
|
|
526
|
+
<Swap id={tick.format(top - step * index)}>
|
|
527
|
+
{tick.format(top - step * index)}
|
|
528
|
+
</Swap>
|
|
529
|
+
</span>
|
|
530
|
+
{index === bands - 1 ? (
|
|
531
|
+
<span className={cn(text({ role: "meta" }), FIGURES, ZERO)}>
|
|
532
|
+
{tick.format(floor)}
|
|
533
|
+
</span>
|
|
534
|
+
) : null}
|
|
535
|
+
</div>
|
|
536
|
+
))}
|
|
537
|
+
</div>
|
|
538
|
+
) : null}
|
|
539
|
+
<div
|
|
540
|
+
ref={scroll.ref}
|
|
541
|
+
// A plot that scrolls is a region the keyboard scrolls too.
|
|
542
|
+
{...(windowed
|
|
543
|
+
? { role: "group", "aria-label": label, tabIndex: 0 }
|
|
544
|
+
: {})}
|
|
545
|
+
className={cn(MAIN, windowed && SCROLLS, !ticks && NO_AXIS_MAIN)}
|
|
546
|
+
>
|
|
547
|
+
<Scroller value={scroll}>
|
|
548
|
+
<div
|
|
549
|
+
ref={plot}
|
|
550
|
+
style={regions}
|
|
551
|
+
className={cn(CHART_MAIN, PLOT_MAIN, windowed && WIDE)}
|
|
552
|
+
>
|
|
553
|
+
{painted ? (
|
|
554
|
+
<div className={cn(CHART_GRID, PAINT_BOX)} />
|
|
555
|
+
) : (
|
|
556
|
+
<div role="img" aria-label={label} className={PLOT}>
|
|
557
|
+
<div className={cn(CHART_GRID, GRID)}>
|
|
558
|
+
{Array.from({ length: bands }, (_, index) => (
|
|
559
|
+
<div
|
|
560
|
+
key={index}
|
|
561
|
+
className={cn(
|
|
562
|
+
chartBand({
|
|
563
|
+
kind: "grid",
|
|
564
|
+
rule: band(index, bands),
|
|
565
|
+
}),
|
|
566
|
+
GRID_BAND,
|
|
567
|
+
)}
|
|
568
|
+
/>
|
|
569
|
+
))}
|
|
570
|
+
</div>
|
|
571
|
+
<div ref={bars} className={BARS}>
|
|
572
|
+
{/* The window hands out indices under `count`, so each is in range: the `Bar` casts are what `noUncheckedIndexedAccess` cannot see. */}
|
|
573
|
+
<Window
|
|
574
|
+
horizontal
|
|
575
|
+
count={series.length}
|
|
576
|
+
keyOf={(index) => (series[index] as Bar).key}
|
|
577
|
+
row={(index) => (
|
|
578
|
+
<BarRegion
|
|
579
|
+
key={(series[index] as Bar).key}
|
|
580
|
+
bar={series[index] as Bar}
|
|
581
|
+
keys={keys}
|
|
582
|
+
top={top}
|
|
583
|
+
floor={floor}
|
|
584
|
+
level={leveled}
|
|
585
|
+
wide={windowed}
|
|
586
|
+
/>
|
|
587
|
+
)}
|
|
588
|
+
box={bars}
|
|
589
|
+
/>
|
|
590
|
+
</div>
|
|
591
|
+
</div>
|
|
592
|
+
)}
|
|
593
|
+
{!painted && categories.length > 0 ? (
|
|
594
|
+
<div aria-hidden className={CATEGORIES}>
|
|
595
|
+
{categoryGroups(categories.length, stride).map(
|
|
596
|
+
({ from, span }) => {
|
|
597
|
+
const name = categories[from];
|
|
598
|
+
return (
|
|
599
|
+
<span
|
|
600
|
+
key={series[from]?.key}
|
|
601
|
+
style={spanned(span)}
|
|
602
|
+
className={cn(
|
|
603
|
+
text({ role: "meta" }),
|
|
604
|
+
FIGURES,
|
|
605
|
+
CATEGORY,
|
|
606
|
+
)}
|
|
607
|
+
>
|
|
608
|
+
{name ? (
|
|
609
|
+
<span className={CATEGORY_REGION}>
|
|
610
|
+
<span className={CATEGORY_NAME}>{name}</span>
|
|
611
|
+
</span>
|
|
612
|
+
) : null}
|
|
613
|
+
</span>
|
|
614
|
+
);
|
|
615
|
+
},
|
|
616
|
+
)}
|
|
617
|
+
</div>
|
|
618
|
+
) : painted ? (
|
|
619
|
+
<div aria-hidden className={PAINTED_TIMES}>
|
|
620
|
+
{[0, 1].map((at) => (
|
|
621
|
+
<span
|
|
622
|
+
key={at}
|
|
623
|
+
className={cn(
|
|
624
|
+
text({ role: "meta" }),
|
|
625
|
+
FIGURES,
|
|
626
|
+
at === 1 && PAINTED_TIME_END,
|
|
627
|
+
)}
|
|
628
|
+
>
|
|
629
|
+
<Painted role="word" at={at} />
|
|
630
|
+
</span>
|
|
631
|
+
))}
|
|
632
|
+
</div>
|
|
633
|
+
) : start || end || between.length > 0 ? (
|
|
634
|
+
<div aria-hidden style={timed} className={TIMES}>
|
|
635
|
+
{start ? (
|
|
636
|
+
<span
|
|
637
|
+
className={cn(
|
|
638
|
+
text({ role: "meta" }),
|
|
639
|
+
FIGURES,
|
|
640
|
+
TIME,
|
|
641
|
+
TIME_FIRST,
|
|
642
|
+
)}
|
|
643
|
+
>
|
|
644
|
+
<span className={TIME_TEXT}>{start}</span>
|
|
645
|
+
</span>
|
|
646
|
+
) : null}
|
|
647
|
+
{end ? (
|
|
648
|
+
<span
|
|
649
|
+
style={{
|
|
650
|
+
insetInlineStart: `${((series.length - 1) / regionCount) * 100}%`,
|
|
651
|
+
}}
|
|
652
|
+
className={cn(
|
|
653
|
+
text({ role: "meta" }),
|
|
654
|
+
FIGURES,
|
|
655
|
+
TIME,
|
|
656
|
+
TIME_LAST,
|
|
657
|
+
)}
|
|
658
|
+
>
|
|
659
|
+
<span className={TIME_TEXT}>{end}</span>
|
|
660
|
+
</span>
|
|
661
|
+
) : null}
|
|
662
|
+
{between.map(({ index, time, space }) => (
|
|
663
|
+
<span
|
|
664
|
+
key={index}
|
|
665
|
+
style={spaceAt(index, space)}
|
|
666
|
+
className={cn(
|
|
667
|
+
text({ role: "meta" }),
|
|
668
|
+
FIGURES,
|
|
669
|
+
TIME_SPACE_BOX,
|
|
670
|
+
)}
|
|
671
|
+
>
|
|
672
|
+
<span className={TIME_MID}>{time}</span>
|
|
673
|
+
</span>
|
|
674
|
+
))}
|
|
675
|
+
</div>
|
|
676
|
+
) : null}
|
|
677
|
+
</div>
|
|
678
|
+
</Scroller>
|
|
679
|
+
</div>
|
|
680
|
+
</div>
|
|
681
|
+
</div>
|
|
682
|
+
</FrameBody>
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// A legend entry: the key's dot in its mark and its name, then its figure.
|
|
687
|
+
function Key(props: { name: string; at: number; children: ReactNode }) {
|
|
688
|
+
return (
|
|
689
|
+
<span className={cn(CHART_KEY, KEY)}>
|
|
690
|
+
<span
|
|
691
|
+
className={cn(
|
|
692
|
+
CHART_KEY_DOT,
|
|
693
|
+
chartFill({ series: mark(props.at) }),
|
|
694
|
+
DOT,
|
|
695
|
+
)}
|
|
696
|
+
/>
|
|
697
|
+
<span className={text({ role: "meta" })}>{props.name}</span>
|
|
698
|
+
{props.children}
|
|
699
|
+
</span>
|
|
700
|
+
);
|
|
701
|
+
}
|