Rework the dashboard into two looks over one behaviour
A dashboard is a wall panel somebody hangs in their own hallway, so it now wears what they choose: a look, and a palette of their own colours. Two complete component sets live under `Dashboard/ui/` — `glass` (translucent panes over a slowly moving ground) and `material` (Material 3 tonal cards) — behind one prop contract. Every control's state, keyboard and `aria-` live in `ui/core` and are shared, so the two sets are the same dashboard drawn twice rather than two products: a set only decides what a control looks like while doing it. Four settings join the channel, each drivable by a flow like any other: `look`, `palette`, `background` and `touch`. A palette is an ordered list of hex colours — background, surface, primary, accent, text, then more chart colours — pasted from a coolors.co link or typed, written onto the canvas as the token variables everything already reads. Trailing roles are derived, so three colours are a whole dashboard, and derived text is held to AA rather than trusted (`theme.check.ts` measures it). A palette also decides light or dark, since its first colour is the ground. Widgets are measured against their own tile with container queries rather than against the viewport, animate through `motion`, and can be drawn without their title. The three reworks: - a bar draws a row per reading, up to eight, each in the dashboard's own data colours and each able to carry its own scale — replacing readings nested in one fill, which could only ever share one colour and stop at three. Documents written the old way are read as rows. - a chart's range picker moved to a column down its right-hand edge, which gives the plot back a whole row of a short tile. - the colour wheel became a disc: hue is the angle and saturation the distance from the middle, so a colour is one gesture rather than three, with brightness on a slider beside it. `index.css` and `lib/motion.ts` are untouched — the dashboard overrides token *values* on its canvas, never the blocks the two repos share.
This commit is contained in:
@@ -6,13 +6,13 @@ import {
|
||||
DEFAULT_RANGE,
|
||||
RANGES,
|
||||
type Range,
|
||||
RangePicker,
|
||||
} from "@/components/Common/RangePicker"
|
||||
import { MAX_SERIES, UplotChart } from "@/components/Common/UplotChart"
|
||||
import { useLiveValue } from "@/components/Flow/liveStore"
|
||||
import { useLiveValue, useLiveValues } from "@/components/Flow/liveStore"
|
||||
import { messageHistoryQueryOptions, usePublishMessage } from "./queries"
|
||||
import { usePalette } from "./settings"
|
||||
import { type Series, useHeaderSlot, type WidgetProps } from "./widgets"
|
||||
import { useUi } from "./ui"
|
||||
import type { Series, WidgetProps } from "./widgets"
|
||||
|
||||
// The five-series ceiling is the chart host's, and the panel reads it here.
|
||||
export { MAX_SERIES }
|
||||
@@ -128,14 +128,7 @@ function LiveChart({ widget }: WidgetProps) {
|
||||
queries: names.map((name) => messageHistoryQueryOptions(name)),
|
||||
})
|
||||
|
||||
// A fixed set: hooks cannot be called in a loop, and five is the ceiling.
|
||||
const live = [
|
||||
useLiveValue(names[0]),
|
||||
useLiveValue(names[1]),
|
||||
useLiveValue(names[2]),
|
||||
useLiveValue(names[3]),
|
||||
useLiveValue(names[4]),
|
||||
]
|
||||
const live = useLiveValues(names)
|
||||
|
||||
// What arrived over the socket since the history was fetched. Appending beats
|
||||
// refetching the whole series every time a value lands.
|
||||
@@ -179,7 +172,7 @@ function LiveChart({ widget }: WidgetProps) {
|
||||
const labels = series.map((entry, index) => entry.label || names[index])
|
||||
|
||||
if (names.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground">Pick a message.</p>
|
||||
return <p className="text-muted-foreground">Pick a message.</p>
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -269,30 +262,54 @@ function QueryChart({ widget, dashboard }: WidgetProps) {
|
||||
// signal that something arrived — no timestamp needed beside it.
|
||||
}, [live?.value, request, rangeS, intervalS])
|
||||
|
||||
// Drawn on the title's line rather than above the plot: a tile is short, and
|
||||
// a row of its own costs the chart about a tenth of its height. Nothing to
|
||||
// pick a window for until the chart is wired, so a half-configured tile says
|
||||
// that and nothing else.
|
||||
const bound = Boolean(request && message)
|
||||
useHeaderSlot(
|
||||
bound ? <RangePicker value={range} onChange={setRange} /> : null,
|
||||
[range, bound],
|
||||
)
|
||||
|
||||
if (!request || !message) {
|
||||
return <p className="text-sm text-muted-foreground">Pick a message.</p>
|
||||
return <p className="text-muted-foreground">Pick a message.</p>
|
||||
}
|
||||
|
||||
const lines = (answer?.lines ?? []).slice(0, MAX_SERIES)
|
||||
return (
|
||||
<UplotChart
|
||||
labels={lines.map((line, index) => line.label || `Series ${index + 1}`)}
|
||||
plots={lines.map((line) =>
|
||||
(line.points ?? []).map(([ts, value]) => ({ ts, value })),
|
||||
// The window sits down the right-hand edge rather than on the title's
|
||||
// line: a tile is short, and every row the chrome takes is a row the plot
|
||||
// does not get. A column costs it about a fortieth of its width instead.
|
||||
<div className="dui-chart grid h-full min-h-0 grid-cols-[minmax(0,1fr)_auto] gap-2">
|
||||
<UplotChart
|
||||
labels={lines.map((line, index) => line.label || `Series ${index + 1}`)}
|
||||
plots={lines.map((line) =>
|
||||
(line.points ?? []).map(([ts, value]) => ({ ts, value })),
|
||||
)}
|
||||
empty="Waiting for an answer."
|
||||
palette={palette}
|
||||
{...presentation(cfg)}
|
||||
/>
|
||||
<RangeRail range={range} onChange={setRange} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The window a chart is showing, as a column beside it. */
|
||||
function RangeRail({
|
||||
range,
|
||||
onChange,
|
||||
}: {
|
||||
range: Range
|
||||
onChange: (range: Range) => void
|
||||
}) {
|
||||
const { Segmented } = useUi()
|
||||
return (
|
||||
<Segmented
|
||||
orientation="vertical"
|
||||
testId="range-picker"
|
||||
label="Time range"
|
||||
value={String(range.hours)}
|
||||
options={RANGES.map(
|
||||
(entry) => [String(entry.hours), entry.label] as const,
|
||||
)}
|
||||
empty="Waiting for an answer."
|
||||
palette={palette}
|
||||
{...presentation(cfg)}
|
||||
onChange={(hours) =>
|
||||
onChange(
|
||||
RANGES.find((entry) => String(entry.hours) === hours) ??
|
||||
DEFAULT_RANGE,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user