Files
alkane-os/third-party/flare-ui/docs/live.md
T
x ad31cfbafa Vendor flare-ui v0.2.9 and prove the schema-driven UI in an image
Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's
on-box pages, and what it costs.

What works:

- schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs);
- src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so
  the unified sidebar, ordering and surface filtering come from the schema
  rather than from hand-written HTML;
- the render uses the shared bf- design tokens, the same ones the rest of the
  suite uses.

Size, measured rather than assumed (armv7, release, stripped):

  ui-baseline   323 KiB   (maud + serde_json, no flare-ui)
  ui-spike      771 KiB   (flare-ui + wschema + sha2)
  marginal      448 KiB

Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in
flare-ui/flare-ui.lock (a partial archive does not compile, since the crate
include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo
directory source with the new registry dependencies (maud, sha2, typenum,
digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build
still works offline. third-party/README.md records how to re-pin.
2026-11-04 14:06:25 -06:00

5.5 KiB

Live client

crates/flare-ui/assets/js/live.js (embedded as flare_ui::live::LIVE_JS).

Setting Default Meaning
ringCap 600 samples kept per series; oldest overwritten
maxSeries 64 series per stream; further keys are counted in dropped
staleAfterMs 15000 silence before the stream is marked stale
backoffMinMs / backoffMaxMs 1000 / 30000 reconnect delay doubles up to the cap; reset on open

Payload per SSE message: JSON {"k": key, "v": value, "t": ms} or an array of those. Malformed items are dropped and counted. bindStaleMarker(live, document) marks [data-live] elements immediately and toggles bf-stale as the stream changes. Rejected packets leave the freshness timestamp, watchdog and readings unchanged. A valid appended sample clears stale state.

Tests: node --test crates/flare-ui/tests/js/live.test.js, also run by cargo test when node is installed.

Islands and page assets

assets/js/islands.js (flare_ui::assets::ISLANDS_JS): table sort kept in the URL (sort, dir; both are in the closed query set) and column width clamp (40 to 800 px). th[data-sort] cells navigate to the toggled query.

flare_ui::assets::PageAssets renders head tags (styles, then deferred scripts). lint rejects, on plain HTTP only: more than 5 SSE streams per page (browsers allow 6 connections per origin; one stays free), and scripts that use secure-context-only APIs (crypto.subtle, navigator.clipboard, serviceWorker, mediaDevices, geolocation).

Typed charts

flare_ui::chart::Chart builds the D63 island. props() validates and returns the data contract; render(path) escapes it into data-chart, adds the canvas and emits normal ?tier=min, ?tier=hour and ?tier=day links. The canonical page path must start with one slash and contain no query, fragment, backslash or control character.

Prop Meaning
id Chart identity, also carried by its live events
series Up to 64 unique key, label, unit and hexadecimal RGB color definitions
tiers min, hour, day, each with n:60 and a positive step_s
tier Selected tier
points Selected-tier seed samples by key: oldest-first [timestamp_ms, value] pairs, at most 60 per series

Keys must belong to a declared series. Samples must be finite with strictly increasing timestamps. Empty or missing histories are valid. Invalid props return flare_ui::chart::Error; labels and units are rendered as text.

use std::collections::BTreeMap;
use flare_ui::chart::{Chart, Series, Tier, TierSpec};

let chart = Chart {
    id: "traffic".into(),
    label: "Network traffic".into(),
    series: vec![Series {
        key: "rx".into(), label: "Receive".into(),
        unit: "B/s".into(), color: "#3776BE".into(),
    }],
    tiers: [
        TierSpec { n: 60, step_s: 60 },
        TierSpec { n: 60, step_s: 3600 },
        TierSpec { n: 60, step_s: 86400 },
    ],
    tier: Tier::Min,
    points: BTreeMap::from([("rx".into(), vec![(1000.0, 42.0)])]),
};
let html = chart.render("/network/traffic");

The server emits a bf-vh latest-values table for assistive technology and JavaScript-free reading. It stays outside the visible chart. Empty histories display -- with the unit. Tier links work without JavaScript.

Named SSE events append points to their chart and series:

event: series
data: {"id":"traffic","key":"rx","p":[2000,43]}

Live keeps these rings separate from legacy reading keys and other chart identities. They share the stream's maxSeries limit. The binding merges seed and live samples by timestamp, keeps the newest 60 and updates the accessible values. Exact numeric formatting uses up to 3 decimals and rounds exact ties away from zero. Structured reading values display --.

The retained canvas engine handles geometry and sliding. The adapter scales extreme finite magnitudes before painting and keeps raw values in the table. Stale data and histories shorter than 4 samples draw without sliding so seed points remain visible. Reduced motion also disables sliding. Normal motion resumes when the data is fresh and every nonempty series has enough history.

Reading glue

assets/js/chart.js (flare_ui::assets::CHART_JS): bindCharts(live, document) also supports legacy [data-island="chart"][data-key] canvases. On each data event it writes the latest value into matching [data-live][data-key] readings (.bf-kv-value keeps its units, .bf-hero-value, meter). Non-numeric samples are not plotted. Pure helpers (bounds, plotPoints, formatValue, withValue) are covered by crates/flare-ui/tests/js/chart.test.js.

Browser check

scripts/e2e/live-sse.mjs runs headless Chromium against a stub SSE server: readings update, the chart canvas draws, a dropped stream marks readings stale, and a reconnect clears the marker. Set PLAYWRIGHT_DIR to a directory whose node_modules holds Playwright; without it the script skips. The check found that timers must run unbound (issue #17).

Page glue

assets/js/boot.js (flare_ui::assets::BOOT_JS) runs on DOMContentLoaded and wires the page from two optional meta tags:

Meta name Effect
bf-stream Path-absolute SSE URL. Opens the stream, binds the stale marker and chart islands. Protocol-relative, absolute, backslash and unescaped whitespace/control URLs are ignored.
bf-csrf Token sent as X-CSRF-Token on every htmx request (htmx:configRequest).

Table sort binds regardless. Load order: live.js, chart.js, islands.js, boot.js (all deferred). Tests: crates/flare-ui/tests/js/boot.test.js.