Commit 4022bbb
viewer: Lit chart spike + CSS tokens + charts.css extraction (#913)
* docs: TODO entry for embed-friendly charts with swappable data backend
Sketch a path to web-component-wrapped charts/sections that consume the
existing crates/dashboard/ JSON descriptors via a pluggable data
adapter, enabling both an in-browser WASM backend and a Datastar/SSE
backend without forking the frontend.
* viewer: <rezolus-chart> Lit web component spike
Vendor lit@3.2.1 (16 KB self-contained ESM bundle) into
src/viewer/assets/lib/lit/ and add a minimal <rezolus-chart> custom
element that consumes the Plot descriptor shape produced by
crates/dashboard/ with inline series data ([[timestamps_ms], [values]]).
Scope is deliberately narrow — validates that a Lit component can wrap
the existing echarts global, render inside a Shadow DOM root, and react
to property updates. Future adapters (HTTP, WASM, SSE) will feed the
same .plot property without changing the component contract.
Demo at /lib/embed/demo.html mounts the component twice (synthetic
single-series and an empty-data placeholder) against the existing
lib/charts/echarts.min.js global. No build step introduced; everything
loads as raw modules from /lib like the rest of the viewer assets.
Not browser-verified in this sandbox (rezolus binary not built).
* viewer: promote chart palette to CSS custom properties
Move the three palettes that were hardcoded in colormap.js into the
:root token block in style.css:
--chart-blue … --chart-purple (10 series accent colors)
--chart-1 … --chart-10 (default cycling palette,
d3 schemeCategory10)
--cgroup-1 … --cgroup-16 (hash-indexed cgroup palette,
d3 schemeCategory20 minus the
muted brown + gray pairs)
colormap.js reads these via getComputedStyle at access time (already
the pattern for theme-sensitive tokens) with the previous hex values
retained as fallbacks. The COLORS Proxy now maps every key to a CSS
variable; no more split between theme-sensitive and series-constant
branches.
Two side-effects worth noting:
* style.css:993 referenced var(--chart-cyan) but the token was never
declared — the linear-gradient fell back to nothing. Now resolved
by the new --chart-cyan declaration.
* Embedders (incl. the upcoming <rezolus-chart>) can override any
palette slot via host-page CSS without touching JS.
No light-theme overrides for these tokens — series colors stay
theme-invariant, matching previous behavior. JS-side colormap ramps
(viridis, inferno, RdYlGn, diverging blue/green) deliberately remain
as JS constants since they're perceptual ramps, not theme decisions.
* viewer: extract chart-specific styles into charts.css
Move 8 chart-related sections (1136 lines) out of style.css into a new
lib/charts.css, loaded immediately after style.css from both
src/viewer/assets/index.html and site/viewer/index.html so the cascade
is preserved:
- Chart Groups
- Chart Cards
- Single Chart View
- Cgroups Section
- CPU Topology Diagram
- Compare mode (3 sub-sections: side-by-side/diff, header badge, landing)
style.css keeps design tokens, light-theme overrides, app chrome (nav,
sidebar, modals, toasts), Selection Section, Query Explorer, System
Info Section, and the responsive @media blocks. A few intentionally
borderline rules remain in style.css where extracting them would
fragment a coherent block: chart-wrapper-unavailable styling lives
inside Selection Section, compare-badge :has() rules live inside the
TopNav block, mobile @media overrides for chart classes stay inside
the responsive section. Worth a follow-up if we ever want a fully
self-contained charts.css.
Site-viewer (WASM/static) gets the same wiring. New symlinks under
site/viewer/lib/ for charts.css, lit/, and embed/ mirror the in-place
files from src/viewer/assets/lib/.
No selector renames, no rule changes — pure relocation. Visual output
should be byte-identical (not browser-verified in this sandbox).
* viewer: wire embed demo to a real plot from the rezolus self-report
Replace the synthetic single-series demo with the Rezolus → Resource
Usage → CPU % plot — the first plot of the rezolus self-report section
defined in crates/dashboard/src/dashboard/rezolus.rs.
Behavior:
- On load, fetches /data/rezolus.json from same origin (works when
the page is served by a viewer process).
- If the response has series data, renders it. Status banner
confirms the data-point count.
- If the descriptor is there but data is empty (no recording
loaded), synthesizes a series on top of the real descriptor.
- If the fetch fails entirely (page opened standalone, no viewer),
falls back to a hand-authored descriptor matching what rezolus.rs
would emit, plus synthetic data, so the demo still renders.
rezolus-chart.js: multiply timestamps by 1000 before passing to
echarts. PromQL emits seconds-since-epoch; echarts time axis expects
ms. line.js already does the same conversion (line 72) — moving it
into the component means the .plot property contract is now the
verbatim Plot JSON shape that crates/dashboard/ produces.
* viewer: fix orphan separator + unreachable systeminfo on mobile
Two narrow-viewport bugs:
1. The mobile @media block hides .query-explorer-link but leaves the
.sidebar-separator that precedes it in the DOM, producing a
visible horizontal divider that separates nothing. Extend the same
rule with :has(+ .query-explorer-link) so the orphan separator is
hidden alongside its link.
2. #sidebar uses `height: calc(100vh - var(--header-height))`. On iOS
Safari (and other mobile browsers with retracting chrome) 100vh
includes the area beneath the address bar, so the sidebar's bottom
edge sits below the visible viewport and the last items (System
Info, Metadata) become unreachable. Add a 100dvh declaration as
a second value, so browsers that support dvh use the visible
viewport while older ones fall back to vh. Also pad the bottom by
env(safe-area-inset-bottom) for iOS home-indicator clearance.
:has() and dvh are already used in the codebase (charts.css and
elsewhere), so no support-matrix change.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent adadf55 commit 4022bbb
12 files changed
Lines changed: 1601 additions & 1248 deletions
File tree
- docs
- site/viewer
- lib
- src/viewer/assets
- lib
- charts/util
- embed
- lit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
0 commit comments