Stabilize GUI status metric row

This commit is contained in:
Meta Vens 2026-04-25 03:35:02 +01:00
commit 69a3d1f385
3 changed files with 198 additions and 144 deletions

View file

@ -417,6 +417,37 @@ function formatNumber(value: number | null, digits = 3): string {
return value.toFixed(digits);
}
type StatusMetricItem = {
label: string;
value: string;
};
function formatGridValue(width: number | null | undefined, height: number | null | undefined, fallback = "pending"): string {
if (!width || !height) {
return fallback;
}
return `${width} x ${height}`;
}
function formatPhaseValue(phaseX: number | null | undefined, phaseY: number | null | undefined, fallback = "pending"): string {
if (phaseX === null || phaseX === undefined || phaseY === null || phaseY === undefined) {
return fallback;
}
return `${formatNumber(phaseX, 2)}, ${formatNumber(phaseY, 2)}`;
}
function renderStatusMetricItems(items: StatusMetricItem[]): void {
statusMetrics.innerHTML = "";
statusMetrics.style.setProperty("--status-metric-count", String(Math.max(items.length, 1)));
for (const { label, value } of items) {
const node = document.createElement("div");
node.className = "status-metric";
node.title = `${label}: ${value}`;
node.innerHTML = `<strong>${label}</strong><span>${value}</span>`;
statusMetrics.appendChild(node);
}
}
function getSelectedFrame(): FramePayload | null {
if (state.frames.length === 0) {
return null;
@ -460,87 +491,85 @@ function renderInference(): void {
}
function renderStatusMetrics(): void {
statusMetrics.innerHTML = "";
statusMetrics.classList.toggle("status-metrics-fixed", state.stageKey === "solver");
const items: Array<[string, string]> = [];
const items: StatusMetricItem[] = [];
const frame = getSelectedFrame();
if (state.stageKey === "inference") {
if (state.latticeSearch) {
items.push(["Sizes", `${state.latticeSearch.completedCandidates} / ${state.latticeSearch.candidateCount}`]);
items.push(["Phase samples", String(state.latticeSearch.phaseSampleCount)]);
if (state.latticeSearch.currentTargetWidth && state.latticeSearch.currentTargetHeight) {
items.push(["Current grid", `${state.latticeSearch.currentTargetWidth} x ${state.latticeSearch.currentTargetHeight}`]);
}
if (state.latticeSearch.device) {
items.push(["Device", state.latticeSearch.device]);
}
if (state.latticeSearch.bestScore !== null) {
items.push(["Best score", formatNumber(state.latticeSearch.bestScore, 3)]);
}
items.push({ label: "Sizes", value: `${state.latticeSearch.completedCandidates} / ${state.latticeSearch.candidateCount}` });
items.push({ label: "Phases", value: String(state.latticeSearch.phaseSampleCount) });
items.push({
label: "Grid",
value: formatGridValue(state.latticeSearch.currentTargetWidth, state.latticeSearch.currentTargetHeight),
});
items.push({ label: "Device", value: state.latticeSearch.device ?? "pending" });
items.push({ label: "Best", value: formatNumber(state.latticeSearch.bestScore, 3) });
}
} else if (state.stageKey === "analysis" || state.stageKey === "selection") {
if (state.inference) {
items.push(["Mode", state.inferenceMode === "fixed" ? "pinned" : state.inferenceMode ?? "search"]);
items.push(["Grid", `${state.inference.target_width} x ${state.inference.target_height}`]);
items.push(["Phase", `${formatNumber(state.inference.phase_x, 2)}, ${formatNumber(state.inference.phase_y, 2)}`]);
items.push(["Confidence", formatNumber(state.inference.confidence, 3)]);
items.push({ label: "Mode", value: state.inferenceMode === "fixed" ? "pinned" : state.inferenceMode ?? "search" });
items.push({ label: "Grid", value: `${state.inference.target_width} x ${state.inference.target_height}` });
items.push({ label: "Phase", value: `${formatNumber(state.inference.phase_x, 2)}, ${formatNumber(state.inference.phase_y, 2)}` });
items.push({ label: "Confidence", value: formatNumber(state.inference.confidence, 3) });
}
} else if (state.stageKey === "rerank") {
if (state.phaseRerank) {
items.push(["Candidates", `${state.phaseRerank.completedCandidates} / ${state.phaseRerank.candidateCount}`]);
if (state.phaseRerank.currentCandidateIndex > 0) {
items.push(["Active candidate", `${state.phaseRerank.currentCandidateIndex} / ${state.phaseRerank.candidateCount}`]);
}
items.push([
"Preview step",
state.phaseRerank.currentTotalSteps > 0
? `${state.phaseRerank.currentStep} / ${state.phaseRerank.currentTotalSteps}`
: String(state.phaseRerank.previewSteps),
]);
if (state.phaseRerank.currentTargetWidth && state.phaseRerank.currentTargetHeight) {
items.push(["Grid", `${state.phaseRerank.currentTargetWidth} x ${state.phaseRerank.currentTargetHeight}`]);
}
if (state.phaseRerank.currentPhaseX !== null && state.phaseRerank.currentPhaseY !== null) {
items.push(["Phase", `${formatNumber(state.phaseRerank.currentPhaseX, 2)}, ${formatNumber(state.phaseRerank.currentPhaseY, 2)}`]);
}
if (state.phaseRerank.currentLoss !== null) {
items.push(["Loss", formatNumber(state.phaseRerank.currentLoss, 4)]);
}
items.push(["Confidence", formatNumber(state.phaseRerank.confidence, 3)]);
items.push({
label: "Done",
value: `${state.phaseRerank.completedCandidates} / ${state.phaseRerank.candidateCount}`,
});
items.push({
label: "Candidate",
value:
state.phaseRerank.currentCandidateIndex > 0
? `${state.phaseRerank.currentCandidateIndex} / ${state.phaseRerank.candidateCount}`
: `0 / ${state.phaseRerank.candidateCount}`,
});
items.push({
label: "Preview",
value:
state.phaseRerank.currentTotalSteps > 0
? `${state.phaseRerank.currentStep} / ${state.phaseRerank.currentTotalSteps}`
: state.phaseRerank.previewSteps > 0
? `0 / ${state.phaseRerank.previewSteps}`
: "skipped",
});
items.push({
label: "Grid",
value: formatGridValue(state.phaseRerank.currentTargetWidth, state.phaseRerank.currentTargetHeight),
});
items.push({
label: "Phase",
value: formatPhaseValue(state.phaseRerank.currentPhaseX, state.phaseRerank.currentPhaseY),
});
items.push({ label: "Loss", value: formatNumber(state.phaseRerank.currentLoss, 4) });
items.push({ label: "Confidence", value: formatNumber(state.phaseRerank.confidence, 3) });
}
} else if (state.stageKey === "solver") {
const solverTerms: Array<[string, number | null]> = [
["Coherence", frame?.terms.local_coherence ?? null],
["Edge", frame?.terms.local_edge ?? null],
["Smoothness", frame?.terms.smoothness ?? null],
["Collapse", frame?.terms.collapse ?? null],
["Magnitude", frame?.terms.magnitude ?? null],
const solverTerms: StatusMetricItem[] = [
{ label: "Coherence", value: formatNumber(frame?.terms.local_coherence ?? null, 4) },
{ label: "Edge", value: formatNumber(frame?.terms.local_edge ?? null, 4) },
{ label: "Smoothness", value: formatNumber(frame?.terms.smoothness ?? null, 4) },
{ label: "Collapse", value: formatNumber(frame?.terms.collapse ?? null, 4) },
{ label: "Magnitude", value: formatNumber(frame?.terms.magnitude ?? null, 4) },
];
items.push([
"Grid",
state.phaseFieldPrep ? `${state.phaseFieldPrep.targetWidth} x ${state.phaseFieldPrep.targetHeight}` : "pending",
]);
items.push([
"Step",
frame ? `${frame.step} / ${frame.totalSteps}` : `0 / ${Math.max(0, state.solverStepBudget)}`,
]);
items.push([
"Cell pitch",
state.phaseFieldPrep
? `${formatNumber(state.phaseFieldPrep.cellX, 1)} x ${formatNumber(state.phaseFieldPrep.cellY, 1)} px`
items.push({
label: "Grid",
value: state.phaseFieldPrep ? `${state.phaseFieldPrep.targetWidth} x ${state.phaseFieldPrep.targetHeight}` : "pending",
});
items.push({
label: "Step",
value: frame ? `${frame.step} / ${frame.totalSteps}` : `0 / ${Math.max(0, state.solverStepBudget)}`,
});
items.push({
label: "Cell pitch",
value: state.phaseFieldPrep
? `${formatNumber(state.phaseFieldPrep.cellX, 1)}x${formatNumber(state.phaseFieldPrep.cellY, 1)} px`
: "pending",
]);
items.push(["Loss", frame?.loss === null || frame?.loss === undefined ? "n/a" : formatNumber(frame.loss, 4)]);
for (const [label, value] of solverTerms) {
items.push([label, formatNumber(value, 4)]);
}
}
for (const [label, value] of items) {
const node = document.createElement("div");
node.className = "status-metric";
node.innerHTML = `<strong>${label}</strong><span>${value}</span>`;
statusMetrics.appendChild(node);
});
items.push({ label: "Loss", value: frame?.loss === null || frame?.loss === undefined ? "n/a" : formatNumber(frame.loss, 4) });
items.push(...solverTerms);
}
renderStatusMetricItems(items);
}
function renderSummary(): void {