frontend: Rugnux live in both modes - the image, the collection image by image, one palette

The live page follows the app's mode instead of bringing its own dark theme, and shows everything at
once: left to right the hero numbers, the diffraction image the broker is on (the preview JPEG with
spots, beam centre and resolution estimate, polled while images come in; wheel to zoom, three pills:
last/indexed, spots, predictions), the placed model, and the triage badges over the per-shell plots.
Under the image and the model, the collection image by image: spots and background from the receiver's
plots, and the per-image scale with the frames the merge downgraded or rejected as amber and red bands
labelled with the reason (serial data: the indexing rate instead).

livePalette.ts holds the page's colours for both modes, all drawn from the app's indigo and lime: the
two phases, the three verdicts (the theme's own), the kinds of step (Okabe-Ito, apart for colour-blind
readers), the plot traces and the frame bands. The rail, the image and the type of the strip scale with
the screen so a 4k display gets no 11 px labels.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK
This commit is contained in:
leonarski_fandClaude Fable 5.1 committed 2026-11-11 22:24:06 +01:00
1 parent b9d6959adb
commit fe541ebff5
11 files changed
+364 -115

No files matched your search

@@ -0,0 +1,97 @@
import {Box, Typography, useTheme} from "@mui/material";
import {useQuery} from "@tanstack/react-query";
import {plot_type, rugnux_live_status} from "../client";
import {getPreviewPlotOptions} from "../client/@tanstack/react-query.gen";
import Plot from "./Plot";
import {livePalette} from "../livePalette";
// The collection image by image, in two small panels on one image axis: the spots found and the background
// of every image as the broker's spot finder saw them (the receiver's plots), and what the merge made of the
// frames - rotation: the per-image scale factor of the merge with the stretches it downgraded (amber) or
// rejected (red) as bands over both panels, each with the reason it saw; serial: the indexing rate. The
// second panel is empty until there is a merge.
const PLOT_MARGIN = {t: 6, b: 22, l: 42, r: 42};
// Points of one receiver plot, polled while the run is on; coarser bins on a long serial collection
function useCollectionPlot(type: plot_type, s: rugnux_live_status) {
const binning = Math.max(1, Math.ceil(s.images_expected / 3000));
const {data} = useQuery({
...getPreviewPlotOptions({query: {type, binning}}),
refetchInterval: s.state === "Running" ? 2000 : false,
});
const p = data?.plot?.[0];
return p && p.x.length > 0 ? {x: p.x, y: p.y} : undefined;
}
function Empty({text}: { text: string }) {
return <Typography sx={{m: "auto", color: "text.disabled", fontSize: "0.85rem"}}>{text}</Typography>;
}
function RugnuxCollectionPlots({s, height}: { s: rugnux_live_status, height: number }) {
const theme = useTheme();
const pal = livePalette(theme.palette.mode);
// type that grows with the strip, so a 4k screen does not get 11 px labels
const size = Math.round(Math.min(16, Math.max(10, height / 15)));
const font = {color: theme.palette.text.secondary, size};
const axis = {gridcolor: pal.grid, zerolinecolor: pal.grid, tickfont: {size: size - 1}};
const title = (text: string, color: string) => ({text, standoff: 4, font: {size: size - 1, color}});
const spots = useCollectionPlot(plot_type.SPOT_COUNT, s);
const bkg = useCollectionPlot(plot_type.BKG_ESTIMATE, s);
const indexing = useCollectionPlot(plot_type.INDEXING_RATE, s);
const scales = s.frame_scales;
const images = Math.max(s.images_expected, s.images_received, 1);
const common = {paper_bgcolor: "rgba(0,0,0,0)", plot_bgcolor: "rgba(0,0,0,0)", font, height, margin: PLOT_MARGIN,
showlegend: false, xaxis: {...axis, range: [0, images - 1], title: {text: "image", standoff: 2, font: {size: size - 1}}}};
const config = {responsive: true, displayModeBar: false};
const panelSx = {display: "flex", minWidth: 0, bgcolor: pal.panel, borderRadius: 1, height};
// amber and red bands where the merge downgraded or rejected the frames, their reason written over them
const bands = (s.frame_ranges ?? []).map(r => ({
type: "rect" as const, xref: "x" as const, yref: "paper" as const, x0: r.first_image - 0.5, x1: r.last_image + 0.5, y0: 0, y1: 1,
fillcolor: r.disposition === "rejected" ? pal.bands.rejected : pal.bands.downgraded, line: {width: 0}, layer: "below" as const,
}));
const bandLabels = (s.frame_ranges ?? []).map(r => ({
x: (r.first_image + r.last_image) / 2, y: 1, xref: "x" as const, yref: "paper" as const, yanchor: "top" as const,
text: r.reason || r.disposition, showarrow: false, font: {size: size - 2, color: r.disposition === "rejected" ? pal.serious : pal.attention},
}));
return (
<Box sx={{display: "grid", gridTemplateColumns: "1fr 1fr", gap: 1.5}}>
<Box sx={panelSx}>
{spots || bkg
? <Plot style={{width: "100%", height}} config={config}
data={[
...(spots ? [{x: spots.x, y: spots.y, type: "scatter" as const, mode: "lines" as const, name: "spots",
line: {color: pal.traces[0], width: 1.2}}] : []),
...(bkg ? [{x: bkg.x, y: bkg.y, type: "scatter" as const, mode: "lines" as const, name: "background",
yaxis: "y2", line: {color: pal.traces[1], width: 1.2}}] : []),
]}
layout={{...common, uirevision: "collection", shapes: bands,
yaxis: {...axis, rangemode: "tozero", title: title("spots", pal.traces[0])},
yaxis2: {overlaying: "y", side: "right", rangemode: "tozero", showgrid: false, tickfont: {size: size - 1},
title: title("background", pal.traces[1])}}}/>
: <Empty text="waiting for images"/>}
</Box>
<Box sx={panelSx}>
{s.stills
? (indexing
? <Plot style={{width: "100%", height}} config={config}
data={[{x: indexing.x, y: indexing.y, type: "scatter", mode: "lines", name: "indexed", line: {color: pal.traces[2], width: 1.2}}]}
layout={{...common, uirevision: "indexing",
yaxis: {...axis, range: [0, 1], title: title("indexed", pal.traces[2])}}}/>
: <Empty text="after the pre-pass"/>)
: (scales && scales.length > 0
? <Plot style={{width: "100%", height}} config={config}
data={[{x: scales.map((_, i) => i), y: scales.map(g => g > 0 ? g : null), type: "scatter", mode: "lines",
name: "scale", line: {color: pal.traces[2], width: 1.2}, connectgaps: false}]}
layout={{...common, uirevision: "scales", shapes: bands, annotations: bandLabels,
yaxis: {...axis, rangemode: "tozero", title: title("scale", pal.traces[2])}}}/>
: <Empty text="scale and rejected frames after the run"/>)}
</Box>
</Box>
);
}
export default RugnuxCollectionPlots;
+6 -7
View File
@@ -1,5 +1,4 @@
import {Box, Tooltip, Typography} from "@mui/material";
import {green, red} from "@mui/material/colors";
import {keyframes} from "@mui/system";
import {rugnux_live_status} from "../client";
@@ -35,19 +34,19 @@ export function SpaceGroup({hm}: { hm: string }) {
type Tone = "plain" | "pending" | "good" | "bad";
const VALUE_COLOUR: Record<Tone, string> = {plain: "text.primary", pending: "text.disabled", good: green[300], bad: red[300]};
const VALUE_COLOUR: Record<Tone, string> = {plain: "text.primary", pending: "text.disabled", good: "success.main", bad: "error.main"};
function Tile({value, caption, tip, tone}: { value: React.ReactNode, caption: string, tip: React.ReactNode, tone: Tone }) {
return (
<Tooltip title={tip} arrow placement="right">
<Box sx={{px: 1.5, py: 0.5, minWidth: 0, borderLeft: "3px solid",
borderColor: tone === "good" ? green[400] : tone === "bad" ? red[400] : "divider"}}>
<Typography sx={{fontSize: "0.7rem", fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase",
color: "text.secondary", whiteSpace: "nowrap"}}>
<Box sx={{px: 1.5, py: 0.25, minWidth: 0, borderLeft: "3px solid",
borderColor: tone === "good" ? "success.main" : tone === "bad" ? "error.main" : "divider"}}>
<Typography sx={{fontSize: "0.65rem", fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase",
color: "text.secondary", whiteSpace: "nowrap", lineHeight: 1.3}}>
{caption}
</Typography>
<Typography key={String(value)} component="div"
sx={{fontSize: "clamp(1.5rem, 1.6vw, 3rem)", lineHeight: 1.15, fontWeight: 800,
sx={{fontSize: "clamp(1.2rem, 1.3vw, 2.8rem)", lineHeight: 1.1, fontWeight: 800,
color: VALUE_COLOUR[tone], fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap",
overflow: "hidden", textOverflow: "ellipsis", animation: `${fadeIn} 500ms ease-out`,
"@media (prefers-reduced-motion: reduce)": {animation: "none"}}}>
+92
View File
@@ -0,0 +1,92 @@
import {useEffect, useRef, useState} from "react";
import {Box, Tooltip, Typography, useTheme} from "@mui/material";
import {TransformComponent, TransformWrapper} from "react-zoom-pan-pinch";
import {color_scale} from "../client";
import {authHeaders, noteResponse} from "../auth";
// The diffraction image the broker is on, as a square window of the live page: the last image of the buffer
// (or the last indexed one), with its spots, the beam centre and the resolution estimate drawn by the broker
// (`/image_buffer/image.jpeg`), fetched every two seconds while images come in. Wheel to zoom, drag to pan,
// nothing else on screen but three pills: which image, spots on or off, predictions on or off. White with
// indigo by day, black with white by night.
type Props = { measuring: boolean };
const POLL_MS = 2000;
function Pill({on, label, tip, onClick}: { on: boolean, label: string, tip: string, onClick: () => void }) {
return (
<Tooltip title={tip} arrow>
<Box component="button" type="button" onClick={onClick}
sx={{px: 1, height: 22, borderRadius: "11px", border: "1px solid", cursor: "pointer", fontFamily: "inherit",
fontSize: "0.7rem", fontWeight: 600, lineHeight: 1, whiteSpace: "nowrap",
borderColor: on ? "primary.main" : "divider", bgcolor: "background.paper",
color: on ? "primary.main" : "text.secondary", opacity: on ? 1 : 0.8}}>
{label}
</Box>
</Tooltip>
);
}
function RugnuxImage({measuring}: Props) {
const dark = useTheme().palette.mode === "dark";
const [indexed, setIndexed] = useState(false);
const [spots, setSpots] = useState(true);
const [predictions, setPredictions] = useState(false);
const [url, setUrl] = useState<string>();
const [missing, setMissing] = useState(false);
const urlRef = useRef<string | undefined>(undefined);
const query = `id=${indexed ? -2 : -1}&show_spots=${spots}&show_predictions=${predictions}&show_beam_center=true`
+ `&show_res_est=true&jpeg_quality=85&color=${dark ? color_scale.WB : color_scale.INDIGO}`;
// One fetch per change of the query, then every POLL_MS while measuring; the object URL of the image on
// screen is released as the next one replaces it, and on unmount.
useEffect(() => {
let alive = true;
const fetchImage = () => fetch(`/image_buffer/image.jpeg?${query}`, {headers: authHeaders()})
.then(r => { noteResponse(r); if (!r.ok) throw new Error(r.statusText); return r.blob(); })
.then(blob => {
if (!alive)
return;
const next = URL.createObjectURL(blob);
if (urlRef.current)
URL.revokeObjectURL(urlRef.current);
urlRef.current = next;
setUrl(next);
setMissing(false);
})
.catch(() => { if (alive) setMissing(true); });
fetchImage();
const timer = measuring ? setInterval(fetchImage, POLL_MS) : undefined;
return () => {
alive = false;
if (timer)
clearInterval(timer);
};
}, [query, measuring]);
useEffect(() => () => { if (urlRef.current) URL.revokeObjectURL(urlRef.current); }, []);
return (
<Box sx={{position: "relative", aspectRatio: "1", width: "100%", maxHeight: "100%", borderRadius: 1, overflow: "hidden",
bgcolor: dark ? "#000" : "#fff", border: "1px solid", borderColor: "divider"}}>
{url && !missing
? <TransformWrapper maxScale={24} wheel={{step: 0.15}}>
<TransformComponent wrapperStyle={{width: "100%", height: "100%"}} contentStyle={{width: "100%", height: "100%"}}>
<img src={url} alt="Diffraction image" draggable={false}
style={{width: "100%", height: "100%", objectFit: "contain", display: "block"}}/>
</TransformComponent>
</TransformWrapper>
: <Typography sx={{position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center",
color: "text.disabled"}}>no image</Typography>}
<Box sx={{position: "absolute", left: 8, bottom: 8, display: "flex", gap: 0.5}}>
<Pill on={indexed} label={indexed ? "indexed" : "last"} onClick={() => setIndexed(i => !i)}
tip={indexed ? "The last image that indexed; click for the last image" : "The last image; click for the last that indexed"}/>
<Pill on={spots} label="spots" onClick={() => setSpots(s => !s)} tip="The spots found on the image"/>
<Pill on={predictions} label="pred" onClick={() => setPredictions(p => !p)} tip="Where the lattice predicts reflections"/>
</Box>
</Box>
);
}
export default RugnuxImage;
+69 -63
View File
@@ -1,10 +1,10 @@
import {Alert, Box, Button, Collapse, Paper, Stack, ThemeProvider, Typography, createTheme} from "@mui/material";
import {green, indigo, lime, orange, red, grey} from "@mui/material/colors";
import {Alert, Box, Button, Collapse, Paper, Stack, Typography, useTheme} from "@mui/material";
import {keyframes} from "@mui/system";
import {useQuery} from "@tanstack/react-query";
import {getConfigRugnuxOptions, getRugnuxStatusOptions} from "../client/@tanstack/react-query.gen";
import {rugnux_live_status} from "../client";
import {useTokenRequired} from "../auth";
import {LivePalette, livePalette} from "../livePalette";
import EmptyState from "./EmptyState";
import RugnuxTriage from "./RugnuxTriage";
import RugnuxTimeline from "./RugnuxTimeline";
@@ -13,35 +13,26 @@ import RugnuxHero from "./RugnuxHero";
import RugnuxStills from "./RugnuxStills";
import RugnuxShellPlots from "./RugnuxShellPlots";
import RugnuxProgress from "./RugnuxProgress";
import RugnuxImage from "./RugnuxImage";
import RugnuxCollectionPlots from "./RugnuxCollectionPlots";
import {lastImageTime, ModelScores, StepTable, VerdictAlert} from "./RugnuxParts";
import BoltIcon from "@mui/icons-material/Bolt";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import {lazy, Suspense, useEffect, useRef, useState} from "react";
// The live page as one control-room screen: a dark stage the height of the window, edged in the colour of the
// run's phase. Across the top, the phase, the two progress bars (the detector's and rugnux's) and the clock the
// run is judged by. Below, three columns: the hero numbers of the merge as a rail at the left, the placed model
// in Mol* filling the centre (the run's steps until there is one), and at the right the triage list over the
// merging statistics by shell. Everything else - the timeline, step notes, summary rows, warnings, the serial
// pre-pass geometry - sits under a "Details" fold below the stage, and the settings under that, on the page's
// ordinary light background.
// The live page as one control-room screen, in the app's own light or dark: a stage the height of the window,
// edged in the colour of the run's phase, that shows everything at once - images, structure, statistics.
// Across the top, the phase, the two progress bars (the detector's and rugnux's) and the clock the run is
// judged by. Below, left to right: the hero numbers of the merge as a rail, the diffraction image the broker
// is on, the placed model in Mol* (the run's step until there is one), and the triage badges over the merging
// statistics by shell. Under the image and the model, the collection image by image: spots and background,
// and the per-image scale with the frames the merge left out. Everything else - the timeline, step notes,
// summary rows, warnings, the serial pre-pass geometry - sits under a "Details" fold below the stage, and the
// settings under that.
// Mol* is large: loaded only when there is a model to show.
const RugnuxStructureViewer = lazy(() => import("./RugnuxStructureViewer"));
// The dark room: the app's indigo/lime, on a navy stage the viewer's black blends into.
const liveTheme = createTheme({
palette: {
mode: "dark",
primary: {main: indigo[300]},
secondary: {main: lime[500]},
background: {default: "#0b0f1d", paper: "#151c33"},
text: {primary: "#e9edf7", secondary: "#9aa5c4", disabled: "#596483"},
divider: "rgba(154,165,196,.2)",
},
shape: {borderRadius: 8},
});
const pulse = keyframes`
0%, 100% { opacity: 1; }
50% { opacity: .45; }
@@ -51,30 +42,30 @@ const LABEL_SX = {fontSize: "0.7rem", fontWeight: 700, letterSpacing: ".1em", te
color: "text.secondary", whiteSpace: "nowrap" as const, overflow: "hidden", textOverflow: "ellipsis"};
// What the run is doing, in one word, with the colour the rest of the screen takes from it.
function phase(s: rugnux_live_status): { label: string, colour: string } {
function phase(s: rugnux_live_status, pal: LivePalette): { label: string, colour: string } {
if (s.state === "Running")
return lastImageTime(s) === undefined
? {label: "Collecting", colour: lime[500]} : {label: "Processing", colour: indigo[300]};
? {label: "Collecting", colour: pal.collecting} : {label: "Processing", colour: pal.processing};
if (s.state === "Done")
return s.verdict === "OK" ? {label: "Done", colour: green[400]}
: s.verdict === "WARNINGS" ? {label: "Done · warnings", colour: orange[400]}
: {label: `Done · ${s.verdict.toLowerCase()}`, colour: red[400]};
return s.verdict === "OK" ? {label: "Done", colour: pal.ok}
: s.verdict === "WARNINGS" ? {label: "Done · warnings", colour: pal.attention}
: {label: `Done · ${s.verdict.toLowerCase()}`, colour: pal.serious};
if (s.state === "Failed")
return {label: "Failed", colour: red[400]};
return {label: s.state, colour: grey[500]};
return {label: "Failed", colour: pal.serious};
return {label: s.state, colour: "text.disabled"};
}
// Phase, the progress block and the clock: the number the run is judged by - seconds since the first image
// while it runs, from the last image to all results written once it is over.
function Header({s, deadline_s}: { s: rugnux_live_status, deadline_s: number }) {
const p = phase(s);
function Header({s, deadline_s, pal}: { s: rugnux_live_status, deadline_s: number, pal: LivePalette }) {
const p = phase(s, pal);
const running = s.state === "Running";
const lastImage = lastImageTime(s);
const latency = s.last_image_to_written_s;
const clock = latency !== undefined
? {caption: "last image → written", value: latency, colour: p.colour}
: lastImage !== undefined
? {caption: "since last image", value: s.elapsed_s - lastImage, colour: indigo[200]}
? {caption: "since last image", value: s.elapsed_s - lastImage, colour: pal.processing}
: {caption: "since first image", value: s.elapsed_s, colour: "text.primary"};
const deadline = running && lastImage !== undefined && deadline_s > 0 ? lastImage + deadline_s - s.elapsed_s : undefined;
@@ -97,7 +88,7 @@ function Header({s, deadline_s}: { s: rugnux_live_status, deadline_s: number })
<Typography sx={{fontSize: "3.6rem", lineHeight: 1, fontWeight: 900, color: clock.colour, fontVariantNumeric: "tabular-nums"}}>
{clock.value.toFixed(1)}<Box component="span" sx={{fontSize: "1.4rem", ml: 0.5, color: "text.secondary"}}>s</Box>
</Typography>
<Typography sx={{fontSize: "0.8rem", color: deadline !== undefined && deadline < 10 ? orange[300] : "text.secondary", minHeight: "1.3em"}}>
<Typography sx={{fontSize: "0.8rem", color: deadline !== undefined && deadline < 10 ? pal.attention : "text.secondary", minHeight: "1.3em"}}>
{deadline !== undefined ? `deadline in ${Math.max(0, deadline).toFixed(0)} s` : ""}
</Typography>
</Box>
@@ -111,7 +102,7 @@ function Later({text}: { text: string }) {
// The step rugnux is on, large with its progress, filling the centre until there is a model to show; the
// steps behind it are on the strip under the bars.
function RunConsole({s}: { s: rugnux_live_status }) {
function RunConsole({s, pal}: { s: rugnux_live_status, pal: LivePalette }) {
const running = s.state === "Running";
const current = running && s.steps.length > 0 && s.steps[s.steps.length - 1].duration_s === undefined
? s.steps[s.steps.length - 1] : undefined;
@@ -119,10 +110,10 @@ function RunConsole({s}: { s: rugnux_live_status }) {
return <Later text={running ? "waiting for images" : s.state === "Failed" ? "failed" : "no model"}/>;
return (
<Box sx={{py: 2}}>
<Typography sx={{...LABEL_SX, color: indigo[300]}}>now</Typography>
<Typography sx={{...LABEL_SX, color: pal.processing}}>now</Typography>
<Typography sx={{fontSize: "2rem", fontWeight: 800, lineHeight: 1.1, animation: `${pulse} 2.4s ease-in-out infinite`,
"@media (prefers-reduced-motion: reduce)": {animation: "none"}}}>
{current.title}{s.step_progress !== undefined && <Box component="span" sx={{color: indigo[300], ml: 2}}>{(100 * s.step_progress).toFixed(0)} %</Box>}
{current.title}{s.step_progress !== undefined && <Box component="span" sx={{color: pal.processing, ml: 2}}>{(100 * s.step_progress).toFixed(0)} %</Box>}
</Typography>
</Box>
);
@@ -138,7 +129,7 @@ function Division({label, children, sx}: { label?: React.ReactNode, children: Re
);
}
function Centre({s}: { s: rugnux_live_status }) {
function Centre({s, pal}: { s: rugnux_live_status, pal: LivePalette }) {
const m = s.model;
// The model shows once a rotation run is over; serial data place it on each provisional merge, and the viewer
// reloads when the model step has a new result, not every time the status is polled.
@@ -157,10 +148,10 @@ function Centre({s}: { s: rugnux_live_status }) {
</Division>
);
}
return <Division sx={{flexGrow: 1}} label="Run"><RunConsole s={s}/></Division>;
return <Division sx={{flexGrow: 1}} label="Run"><RunConsole s={s} pal={pal}/></Division>;
}
// Height of an element in px, kept up to date as the page resizes: the shell plots need theirs in pixels.
// Height of an element in px, kept up to date as the page resizes: the plots need theirs in pixels.
function useHeight() {
const ref = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState(0);
@@ -174,42 +165,58 @@ function useHeight() {
return [ref, height] as const;
}
function Dashboard({s, deadline_s, modelLoaded}: { s: rugnux_live_status, deadline_s: number, modelLoaded: boolean }) {
// The height of the collection strip and the side of the image window, from the window's height so the
// stage holds everything without scrolling: the image takes what the header and the strip leave.
const STRIP = "clamp(150px, 11vh, 260px)";
const IMAGE = "clamp(240px, min(calc(88vh - 430px), 30vw), 1500px)";
const RAIL = "clamp(200px, 12vw, 420px)";
function Dashboard({s, deadline_s, modelLoaded, measuring, pal}:
{ s: rugnux_live_status, deadline_s: number, modelLoaded: boolean, measuring: boolean, pal: LivePalette }) {
const [plotsRef, plotsHeight] = useHeight();
const [stripRef, stripHeight] = useHeight();
const later = s.stills ? "after the first merge" : "after the run";
const hairline = {borderLeft: {lg: "1px solid"}, borderColor: {lg: "divider"}, pl: {lg: 2.5}};
const hairline = {borderLeft: {xl: "1px solid"}, borderColor: {xl: "divider"}, pl: {xl: 2.5}};
return (
<Box sx={{display: "grid", gridTemplateRows: "auto minmax(0, 1fr)", gap: 2.5, height: "100%", minHeight: 0}}>
<Header s={s} deadline_s={deadline_s}/>
<Header s={s} deadline_s={deadline_s} pal={pal}/>
<Box sx={{display: "grid", gap: 2.5, minHeight: 0,
gridTemplateColumns: {xs: "1fr", lg: "220px minmax(0, 1fr) minmax(380px, 30%)"},
gridTemplateRows: {xs: "auto", lg: "minmax(0, 1fr)"}}}>
<Division label="Merge">
gridTemplateColumns: {xs: "1fr", md: `${RAIL} minmax(0, 1fr)`, xl: `${RAIL} ${IMAGE} minmax(0, 1fr) minmax(360px, 27%)`},
gridTemplateRows: {xs: "auto", xl: `minmax(0, 1fr) ${STRIP}`}}}>
<Division label="Merge" sx={{gridColumn: {xl: 1}, gridRow: {xl: "1 / 3"}}}>
<RugnuxHero s={s} modelLoaded={modelLoaded} column/>
</Division>
<Box sx={{minHeight: {xs: 520, lg: 0}, display: "flex", flexDirection: "column", ...hairline}}>
<Centre s={s}/>
<Division label="Image" sx={{...hairline, gridColumn: {xl: 2}, minHeight: {xs: 320, xl: 0}}}>
<RugnuxImage measuring={measuring}/>
</Division>
<Box sx={{gridColumn: {xl: 3}, minHeight: {xs: 480, xl: 0}, display: "flex", flexDirection: "column"}}>
<Centre s={s} pal={pal}/>
</Box>
<Box sx={{display: "flex", flexDirection: "column", gap: 2.5, minHeight: 0, ...hairline}}>
<Box sx={{display: "flex", flexDirection: "column", gap: 2.5, minHeight: 0, gridColumn: {xl: 4}, gridRow: {xl: "1 / 3"}, ...hairline}}>
<Division sx={{flex: "0 1 auto", maxHeight: "40%", overflowY: "auto", "& > *": {flexShrink: 0}}}>
{s.triage && s.triage.length > 0 ? <RugnuxTriage items={s.triage}/> : <Later text={later}/>}
</Division>
<Division sx={{flex: "1 1 0"}} label={<>By resolution{s.stills && s.shells_merge && ` · ${s.shells_merge}`}</>}>
<Box ref={plotsRef} sx={{flexGrow: 1, minHeight: {xs: 400, lg: 0}, display: "flex"}}>
<Box ref={plotsRef} sx={{flexGrow: 1, minHeight: {xs: 400, xl: 0}, display: "flex"}}>
{s.shells && s.shells.length > 0
? <Box sx={{width: "100%"}}>
<RugnuxShellPlots shells={s.shells} height={Math.max(170, (plotsHeight - 16) / 2)}/>
<RugnuxShellPlots shells={s.shells} height={Math.max(150, (plotsHeight - 16) / 2)}/>
</Box>
: <Later text={later}/>}
</Box>
</Division>
</Box>
<Division label="Collection" sx={{gridColumn: {md: "1 / 3", xl: "2 / 4"}, gridRow: {xl: 2}, ...hairline, minHeight: {xs: 200, xl: 0}}}>
<Box ref={stripRef} sx={{flexGrow: 1, minHeight: 0}}>
<RugnuxCollectionPlots s={s} height={Math.max(130, stripHeight)}/>
</Box>
</Division>
</Box>
</Box>
);
}
// What the stage leaves out, on the light page: the timeline, the steps with their notes, the summary rows
// What the stage leaves out, below it: the timeline, the steps with their notes, the summary rows
// and warnings, the model's scores, and the serial pre-pass geometry.
function Details({s, deadline_s}: { s: rugnux_live_status, deadline_s: number }) {
const [open, setOpen] = useState(false);
@@ -254,6 +261,7 @@ function RugnuxPage({measuring}: { measuring: boolean }) {
enabled,
});
const tokenRequired = useTokenRequired();
const pal = livePalette(useTheme().palette.mode);
let empty;
if (settings !== undefined && !enabled)
@@ -264,20 +272,18 @@ function RugnuxPage({measuring}: { measuring: boolean }) {
empty = "No rugnux run yet - start a collection with live processing enabled";
// The stage is the height of the window less the app's bars, so the essentials never scroll on a desktop
// screen; below the lg breakpoint it flows.
// screen; below the xl breakpoint it flows.
return (
<Stack spacing={2}>
<ThemeProvider theme={liveTheme}>
<Box sx={{bgcolor: "background.default", color: "text.primary", borderRadius: 2, p: 2.5, pt: 2,
borderTop: "4px solid", borderColor: s && !empty ? phase(s).colour : "divider",
height: {lg: "calc(100vh - 196px)"}, minHeight: {lg: 720}, overflow: "hidden"}}>
{empty || !s
? <Box sx={{height: "100%", display: "flex", "& .MuiSvgIcon-root, & p": {color: "text.secondary"}}}>
<Box sx={{m: "auto"}}><EmptyState icon={<BoltIcon fontSize="inherit"/>} text={empty ?? ""}/></Box>
</Box>
: <Dashboard s={s} deadline_s={settings?.deadline_s ?? 0} modelLoaded={settings?.model_loaded === true}/>}
</Box>
</ThemeProvider>
<Paper sx={{p: 2.5, pt: 2, borderTop: "4px solid", borderColor: s && !empty ? phase(s, pal).colour : "divider",
height: {xl: "calc(100vh - 196px)"}, minHeight: {xl: 720}, overflow: "hidden"}}>
{empty || !s
? <Box sx={{height: "100%", display: "flex", "& .MuiSvgIcon-root, & p": {color: "text.secondary"}}}>
<Box sx={{m: "auto"}}><EmptyState icon={<BoltIcon fontSize="inherit"/>} text={empty ?? ""}/></Box>
</Box>
: <Dashboard s={s} deadline_s={settings?.deadline_s ?? 0} modelLoaded={settings?.model_loaded === true}
measuring={measuring} pal={pal}/>}
</Paper>
{s && !empty && <Details s={s} deadline_s={settings?.deadline_s ?? 0}/>}
<RugnuxSettings measuring={measuring}/>
</Stack>
+4 -3
View File
@@ -1,6 +1,6 @@
import {Alert, AlertTitle, Box, Chip, Paper, Table, TableBody, TableCell, TableContainer, TableRow, Typography} from "@mui/material";
import {indigo, lime, deepOrange, grey} from "@mui/material/colors";
import {SxProps, Theme} from "@mui/material/styles";
import {alpha, SxProps, Theme} from "@mui/material/styles";
import {rugnux_live_model, rugnux_live_status, rugnux_live_step} from "../client";
// Pieces of the rugnux live status shared by the dashboard card and the Rugnux page.
@@ -119,10 +119,11 @@ export function StepTable({steps}: { steps: rugnux_live_step[] }) {
function ScoreTile({label, value, sub, accent}: { label: string, value: string, sub?: string, accent?: boolean }) {
return (
<Box sx={{p: 1.5, borderRadius: 2, border: "1px solid", minWidth: 0,
bgcolor: accent ? indigo[50] : grey[50], borderColor: accent ? indigo[100] : grey[200]}}>
bgcolor: t => accent ? alpha(t.palette.primary.main, 0.08) : "action.hover",
borderColor: t => accent ? alpha(t.palette.primary.main, 0.2) : "divider"}}>
<Typography sx={{fontSize: "0.72rem", fontWeight: 700, letterSpacing: ".06em", textTransform: "uppercase",
color: accent ? "primary.main" : "text.secondary", whiteSpace: "nowrap"}}>{label}</Typography>
<Typography sx={{fontSize: "1.6rem", lineHeight: 1.2, fontWeight: 700, color: "primary.dark",
<Typography sx={{fontSize: "1.6rem", lineHeight: 1.2, fontWeight: 700, color: "primary.main",
fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis"}}>
{value}</Typography>
{sub && <Typography sx={{fontSize: "0.8rem", color: "text.secondary"}}>{sub}</Typography>}
+18 -27
View File
@@ -1,9 +1,9 @@
import {useEffect, useRef, useState} from "react";
import {Box, Tooltip, Typography} from "@mui/material";
import {Box, Tooltip, Typography, useTheme} from "@mui/material";
import {keyframes} from "@mui/system";
import {deepOrange, grey, indigo, lime} from "@mui/material/colors";
import {rugnux_live_status, rugnux_live_step} from "../client";
import {lastImageTime} from "./RugnuxParts";
import {inkOn, LivePalette, livePalette} from "../livePalette";
// The detector's and rugnux's progress one under the other on one time axis (seconds since the first image):
// the detector's bar fills as images arrive, up to the collection's expected end; rugnux's bar is its steps,
@@ -38,28 +38,18 @@ const TAGS: [RegExp, string][] = [
];
const tagOf = (title: string) => TAGS.find(([re]) => re.test(title))?.[1] ?? title.split(/[\s,]/)[0].slice(0, 6);
// One colour per kind of step - Okabe-Ito, which keeps its kinds apart for colour-blind readers too, with
// its blue lightened for the dark stage; a kind not in the table takes the next free one.
const KIND_COLOURS: Record<string, string> = {
Pre: "#56B4E9", Spots: "#E69F00", Idx: "#F0E442", Int: "#3C8DD6", GPU: "#3C8DD6", Scale: "#009E73",
Merge: "#009E73", MR: "#CC79A7", Ref: "#D55E00", Out: "#9E9E9E",
};
const SPARE_COLOURS = ["#8DD3C7", "#BEBADA", "#FB8072", "#FDB462", "#B3DE69"];
function kindColours(steps: rugnux_live_step[]) {
const colours: Record<string, string> = {...KIND_COLOURS};
// One colour per kind of step (livePalette: Okabe-Ito, which keeps its kinds apart for colour-blind readers
// too); a kind not in the table takes the next free one.
function kindColours(steps: rugnux_live_step[], pal: LivePalette) {
const colours: Record<string, string> = {...pal.kinds};
let spare = 0;
for (const st of steps) {
const tag = tagOf(st.title);
if (!(tag in colours))
colours[tag] = SPARE_COLOURS[spare++ % SPARE_COLOURS.length];
colours[tag] = pal.spare[spare++ % pal.spare.length];
}
return colours;
}
// dark text on the light colours
const inkOn = (hex: string) => {
const [r, g, b] = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16));
return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? "rgba(0,0,0,.85)" : "#fff";
};
const BAR = 20;
const GAP = 6;
@@ -92,6 +82,7 @@ function useWidth() {
const seconds = (t: number) => `${t.toFixed(1)} s`;
function RugnuxProgress({s, deadline_s}: { s: rugnux_live_status, deadline_s: number }) {
const pal = livePalette(useTheme().palette.mode);
const running = s.state === "Running";
const lastImage = lastImageTime(s);
const collecting = running && lastImage === undefined;
@@ -117,7 +108,7 @@ function RugnuxProgress({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
: s.cut ? `cut (${s.cut})` : `${s.steps.length} steps · ${seconds(s.elapsed_s)}`;
const stepEnd = (i: number) => s.steps[i].duration_s === undefined ? s.elapsed_s : s.steps[i].started_s + s.steps[i].duration_s!;
const colours = kindColours(s.steps);
const colours = kindColours(s.steps, pal);
const tags = s.steps.map(st => tagOf(st.title));
// consecutive steps of one kind (the passes) as one chip, with their time together
const kinds: { tag: string, titles: string[], seconds: number, open: boolean }[] = [];
@@ -137,20 +128,20 @@ function RugnuxProgress({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
<Box sx={{display: "grid", gridTemplateColumns: "72px minmax(0, 1fr) auto", columnGap: 2, alignItems: "start"}}>
{/* captions */}
<Box sx={{display: "grid", rowGap: `${GAP}px`}}>
<Typography sx={{...LABEL_SX, color: lime[500]}}>Detector</Typography>
<Typography sx={{...LABEL_SX, color: indigo[300]}}>Rugnux</Typography>
<Typography sx={{...LABEL_SX, color: pal.collecting}}>Detector</Typography>
<Typography sx={{...LABEL_SX, color: pal.processing}}>Rugnux</Typography>
</Box>
{/* the two bars on one axis, the axis under them */}
<Box ref={laneRef} sx={{position: "relative"}}>
<Box sx={{position: "relative", height: BAR, borderRadius: 1, bgcolor: "rgba(255,255,255,.07)", overflow: "hidden"}}>
<Box sx={{position: "absolute", left: 0, top: 0, bottom: 0, width: `${pct(collectionEnd)}%`, bgcolor: lime[700],
<Box sx={{position: "relative", height: BAR, borderRadius: 1, bgcolor: pal.track, overflow: "hidden"}}>
<Box sx={{position: "absolute", left: 0, top: 0, bottom: 0, width: `${pct(collectionEnd)}%`, bgcolor: pal.collectingFill,
borderRadius: 1, transition: "width 400ms linear", ...(collecting && runningSx)}}/>
{collecting && expectedEnd > collectionEnd &&
<Box sx={{position: "absolute", left: `${pct(collectionEnd)}%`, width: `${pct(expectedEnd) - pct(collectionEnd)}%`,
top: 0, bottom: 0, border: `1px dashed ${lime[800]}`, borderLeft: "none", borderRadius: "0 4px 4px 0"}}/>}
top: 0, bottom: 0, border: `1px dashed ${pal.collecting}`, borderLeft: "none", borderRadius: "0 4px 4px 0"}}/>}
</Box>
<Box sx={{position: "relative", height: BAR, mt: `${GAP}px`, borderRadius: 1, bgcolor: "rgba(255,255,255,.07)", overflow: "hidden"}}>
<Box sx={{position: "relative", height: BAR, mt: `${GAP}px`, borderRadius: 1, bgcolor: pal.track, overflow: "hidden"}}>
{s.steps.map((st, i) => {
const open = st.duration_s === undefined;
const width = Math.max(pct(stepEnd(i)) - pct(st.started_s), 0.3);
@@ -185,12 +176,12 @@ function RugnuxProgress({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
{lastImage !== undefined &&
<Tooltip arrow title={`last image · ${seconds(lastImage)}`}>
<Box sx={{position: "absolute", left: `${pct(lastImage)}%`, top: -3, height: 2 * BAR + GAP + 6, width: 0,
borderLeft: `2px solid ${grey[300]}`}}/>
borderLeft: "2px solid", borderColor: "text.secondary"}}/>
</Tooltip>}
{deadline !== undefined &&
<Tooltip arrow title={`deadline · ${seconds(deadline)}`}>
<Box sx={{position: "absolute", left: `${pct(deadline)}%`, top: -3, height: 2 * BAR + GAP + 6, width: 0,
borderLeft: `2px dashed ${deepOrange[400]}`}}/>
borderLeft: `2px dashed ${pal.attention}`}}/>
</Tooltip>}
</Box>
@@ -210,7 +201,7 @@ function RugnuxProgress({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
{kinds.map((k, i) => (
<Tooltip key={i} arrow title={k.titles.join(" · ")}>
<Box sx={{display: "inline-flex", alignItems: "center", gap: 0.75, px: 1, height: 22, borderRadius: "11px",
bgcolor: "rgba(255,255,255,.06)", fontSize: "0.75rem", whiteSpace: "nowrap",
bgcolor: pal.track, fontSize: "0.75rem", whiteSpace: "nowrap",
...(k.open && running && {animation: `${pulse} 1.6s ease-in-out infinite`,
"@media (prefers-reduced-motion: reduce)": {animation: "none"}})}}>
<Box sx={{width: 8, height: 8, borderRadius: "2px", bgcolor: colours[k.tag]}}/>
+6 -3
View File
@@ -1,6 +1,7 @@
import {Box, Typography, useTheme} from "@mui/material";
import {rugnux_live_shell} from "../client";
import Plot from "./Plot";
import {livePalette} from "../livePalette";
// Merging statistics by resolution shell, the shell table of rugnux's _report.txt. Each shell is drawn at
// 1/d^2 of its d_min (the label of its row in the report), with the axis labelled in d. A quantity the run
@@ -28,8 +29,8 @@ const PANELS: { title: string, percent: boolean, legendLeft?: boolean, series: S
// same on the light dashboard card and on the dark live page.
function RugnuxShellPlots({shells, merge, height = 300}: { shells: rugnux_live_shell[], merge?: string, height?: number }) {
const theme = useTheme();
const dark = theme.palette.mode === "dark";
const grid = dark ? "rgba(255,255,255,.12)" : "#eee";
const pal = livePalette(theme.palette.mode);
const grid = pal.grid;
// type that grows with the panel, so a 4k screen does not get 11 px labels
const font = Math.round(Math.min(17, Math.max(11, height / 24)));
const x = shells.map(sh => 1 / (sh.d_min * sh.d_min));
@@ -44,7 +45,7 @@ function RugnuxShellPlots({shells, merge, height = 300}: { shells: rugnux_live_s
{PANELS.map(panel => {
const data = panel.series
.filter(s => shells.some(sh => s.value(sh) !== undefined))
.map(s => ({
.map((s, i) => ({
x: x,
y: shells.map(sh => {
const v = s.value(sh);
@@ -53,6 +54,8 @@ function RugnuxShellPlots({shells, merge, height = 300}: { shells: rugnux_live_s
type: "scatter" as const,
mode: "lines+markers" as const,
name: s.name,
line: {color: pal.traces[i % pal.traces.length]},
marker: {color: pal.traces[i % pal.traces.length], size: 5},
}));
if (data.length === 0)
return null;
+5 -4
View File
@@ -1,5 +1,5 @@
import {Box, Chip, LinearProgress, Stack, Table, TableBody, TableCell, TableHead, TableRow, Typography} from "@mui/material";
import {grey, indigo} from "@mui/material/colors";
import {alpha} from "@mui/material/styles";
import {rugnux_live_stills} from "../client";
// Serial frames analysed on the GPU: the pre-pass on the first images - the beam
@@ -9,12 +9,13 @@ const PREPASS_COLOUR = {Holding: "default", Running: "primary", Done: "success",
function Tile({label, value, sub}: { label: string, value: string, sub?: string }) {
return (
<Box sx={{p: 1.5, borderRadius: 2, bgcolor: indigo[50], border: "1px solid", borderColor: indigo[100]}}>
<Box sx={{p: 1.5, borderRadius: 2, border: "1px solid", bgcolor: t => alpha(t.palette.primary.main, 0.08),
borderColor: t => alpha(t.palette.primary.main, 0.2)}}>
<Typography sx={{fontSize: "0.75rem", fontWeight: 700, letterSpacing: ".06em", textTransform: "uppercase",
color: "primary.main"}}>
{label}
</Typography>
<Typography sx={{fontSize: "1.2rem", fontWeight: 700, color: "primary.dark"}}>{value}</Typography>
<Typography sx={{fontSize: "1.2rem", fontWeight: 700, color: "primary.main"}}>{value}</Typography>
{sub && <Typography sx={{fontSize: "0.85rem", color: "text.secondary"}}>{sub}</Typography>}
</Box>
);
@@ -88,7 +89,7 @@ function RugnuxStills({st}: { st: rugnux_live_stills }) {
<Tile label="GPU analysis" value={st.analysis_rate_hz !== undefined ? `${st.analysis_rate_hz.toFixed(0)} Hz` : "—"}
sub="since the pre-pass"/>
</Box>
<Typography sx={{fontSize: "0.85rem", color: grey[600]}}>
<Typography sx={{fontSize: "0.85rem", color: "text.secondary"}}>
Every image is analysed with the pre-pass's beam centre, distance and mask; images arriving
during the pre-pass are held and analysed after it.
</Typography>
@@ -162,8 +162,8 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill}:
<Box component="button" type="button" onClick={() => toggleLayer('fofc', !show.fofc)} disabled={mapsLoading}
sx={{position: 'absolute', top: 8, right: 8, display: 'inline-flex', alignItems: 'center', gap: 0.75,
px: 1, height: 26, borderRadius: '13px', border: '1px solid', cursor: 'pointer',
borderColor: show.fofc ? 'primary.main' : 'divider', bgcolor: 'rgba(8,12,26,.8)',
color: show.fofc ? 'text.primary' : 'text.secondary', fontSize: '0.75rem', fontFamily: 'inherit'}}>
borderColor: show.fofc ? 'primary.main' : 'rgba(154,165,196,.3)', bgcolor: 'rgba(8,12,26,.8)',
color: show.fofc ? '#e9edf7' : '#9aa5c4', fontSize: '0.75rem', fontFamily: 'inherit'}}>
<Box sx={{width: 8, height: 8, borderRadius: '2px', bgcolor: hex(MAP_COLORS.fofcPos)}}/>
Fo−Fc
</Box>
+6 -6
View File
@@ -22,7 +22,7 @@ const runningSx = {
animation: `${stripes} 1s linear infinite`,
};
const STEP_COLOURS = [indigo[500], indigo[300], indigo[700], lightBlue[700], indigo[400], lightBlue[900]];
const STEP_COLOURS = [indigo[500], indigo[300], indigo[700], lightBlue[700], indigo[400], lightBlue[800]];
const LABEL_WIDTH = 120;
const LANE_HEIGHT = 64;
@@ -128,7 +128,7 @@ function RugnuxTimeline({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
markers.push({x: pct(s.probe_s), label: `probe ${s.probe_s.toFixed(1)} s`,
colour: s.probe.startsWith("no lattice") ? orange[800] : lightBlue[800]});
if (lastImage !== undefined)
markers.push({x: pct(lastImage), dashed: true, colour: grey[800], label: "last image"});
markers.push({x: pct(lastImage), dashed: true, colour: grey[500], label: "last image"});
if (deadline !== undefined && s.cut !== 'deadline')
markers.push({x: pct(deadline), dashed: true, colour: deepOrange[700], label: `deadline ${deadline.toFixed(1)} s`});
if (s.cut && s.cut_s !== undefined)
@@ -153,11 +153,11 @@ function RugnuxTimeline({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
{/* grid lines */}
{ticks.map(t => (
<Box key={t} sx={{position: "absolute", left: `${pct(t)}%`, top: 0,
height: 2 * LANE_HEIGHT + 12, borderLeft: `1px solid ${grey[200]}`}}/>
height: 2 * LANE_HEIGHT + 12, borderLeft: "1px solid", borderColor: "divider"}}/>
))}
{/* detector lane */}
<Box sx={{position: "relative", height: LANE_HEIGHT, mb: 1.5, bgcolor: grey[100], borderRadius: 2}}>
<Box sx={{position: "relative", height: LANE_HEIGHT, mb: 1.5, bgcolor: "action.hover", borderRadius: 2}}>
<Box sx={{position: "absolute", left: 0, top: 0, bottom: 0, width: `${pct(collectionEnd)}%`,
bgcolor: lime[600], borderRadius: 2, display: "flex", alignItems: "center", px: 2,
overflow: "hidden", ...(collecting && runningSx)}}>
@@ -177,7 +177,7 @@ function RugnuxTimeline({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
</Box>
{/* rugnux lane */}
<Box sx={{position: "relative", height: LANE_HEIGHT, bgcolor: grey[100], borderRadius: 2}}>
<Box sx={{position: "relative", height: LANE_HEIGHT, bgcolor: "action.hover", borderRadius: 2}}>
{s.steps.map((step, i) => {
const open = step.duration_s === undefined;
const end = open ? s.elapsed_s : step.started_s + step.duration_s!;
@@ -227,7 +227,7 @@ function RugnuxTimeline({s, deadline_s}: { s: rugnux_live_status, deadline_s: nu
borderBottom: `4px solid ${lime[700]}`, borderLeft: `4px solid ${lime[700]}`,
borderRight: `4px solid ${lime[700]}`, borderRadius: "0 0 8px 8px"}}>
<Typography sx={{position: "absolute", right: 0, top: "100%", mt: 0.5, fontWeight: 800,
fontSize: "1.4rem", color: lime[900], whiteSpace: "nowrap"}}>
fontSize: "1.4rem", color: t => t.palette.mode === "dark" ? lime[300] : lime[900], whiteSpace: "nowrap"}}>
+{latency.toFixed(1)} s → all written
</Typography>
</Box>
+59
View File
@@ -0,0 +1,59 @@
import {PaletteMode} from "@mui/material";
import {indigo, lime} from "@mui/material/colors";
import {SEMANTIC} from "./theme";
// The colours of the Rugnux live page, one set per mode, all drawn from the app's indigo and lime:
// - the two phases: collecting is lime (the detector's colour everywhere in the app), processing is indigo;
// - the three verdicts: the theme's success / warning / error (SEMANTIC in theme.ts);
// - the kinds of step: Okabe-Ito, which stays apart for colour-blind readers; its blue is lightened at night;
// - the plot traces, in the order a panel uses them: indigo, vermillion, bluish green, pink - again Okabe-Ito
// apart from the indigo, which is the brand's; and the bands of frames the merge rejected (red) or
// downgraded (amber), translucent so the traces stay readable through them.
export type LivePalette = {
collecting: string; // the detector's colour, as a label or an edge
collectingFill: string; // the same as a bar
processing: string;
ok: string;
attention: string;
serious: string;
// the surfaces of the stage: the panel the image and plots sit in, the progress tracks, the plot grid
panel: string;
track: string;
grid: string;
kinds: Record<string, string>;
spare: string[];
traces: string[];
bands: {rejected: string, downgraded: string};
};
const KINDS_LIGHT: Record<string, string> = {
Pre: "#56B4E9", Spots: "#E69F00", Idx: "#F0E442", Int: "#0072B2", GPU: "#0072B2", Scale: "#009E73",
Merge: "#009E73", MR: "#CC79A7", Ref: "#D55E00", Out: "#8E8E8E",
};
const KINDS_DARK: Record<string, string> = {...KINDS_LIGHT, Int: "#3C8DD6", GPU: "#3C8DD6", Out: "#9E9E9E"};
export function livePalette(mode: PaletteMode): LivePalette {
const sem = SEMANTIC[mode];
if (mode === "dark")
return {
collecting: lime[400], collectingFill: lime[700], processing: indigo[300], ...sem,
panel: "rgba(255,255,255,.04)", track: "rgba(255,255,255,.08)", grid: "rgba(255,255,255,.1)",
kinds: KINDS_DARK, spare: ["#8DD3C7", "#BEBADA", "#FB8072", "#FDB462", "#B3DE69"],
traces: [indigo[300], "#FF8A50", "#3EC9A0", "#E4A0CF"],
bands: {rejected: "rgba(255,107,107,.22)", downgraded: "rgba(255,179,71,.2)"},
};
return {
collecting: lime[800], collectingFill: lime[500], processing: indigo[500], ...sem,
panel: "rgba(63,81,181,.04)", track: "rgba(63,81,181,.1)", grid: "#e6e8f0",
kinds: KINDS_LIGHT, spare: ["#66C2A5", "#8DA0CB", "#FC8D62", "#E5C494", "#A6D854"],
traces: [indigo[500], "#D55E00", "#009E73", "#CC79A7"],
bands: {rejected: "rgba(215,38,61,.16)", downgraded: "rgba(224,138,0,.16)"},
};
}
// dark or light ink on a colour
export const inkOn = (hex: string) => {
const [r, g, b] = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16));
return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? "rgba(0,0,0,.85)" : "#fff";
};