Sort series statistics table by run number, drop worst-first toggle

The per-run dialog previously defaulted to worst-first with a button to
switch to run order. Run order is the useful view, so the table now always
sorts by ascending run number and the toggle button and toolbar are removed.
This commit is contained in:
salman committed 2026-09-10 14:17:38 +02:00
1 parent 59e6dd12ea
commit 6d6caf0fd8
4 files changed
+10 -52

No files matched your search

-8
View File
@@ -2652,14 +2652,6 @@ button:not(.tablinks):not(.action-btn):not(.editor-source-tab):not(.status-state
border-bottom: 1px solid var(--mu-green-muted);
}
.series-statistic-toolbar {
padding: 6px 10px;
}
.series-statistic-toolbar button {
font-size: 88%;
}
.series-statistic-table {
border-collapse: collapse;
display: block;
-4
View File
@@ -600,10 +600,6 @@
title="Close statistics" aria-label="Close statistics">&times;</button>
</div>
</div>
<div class="series-statistic-toolbar">
<button type="button" id="seriesStatisticSort" onclick="toggleSeriesStatisticSort();"
title="Toggle between worst-first and run-number order">Worst first</button>
</div>
<table class="series-statistic-table">
<thead>
<tr>
+1 -27
View File
@@ -3003,11 +3003,6 @@ function showSeriesStatisticsDialog() {
let dialog = document.getElementById("seriesStatisticDialog");
if (!dialog) return;
renderSeriesStatisticsTable(window.MusrfitJob.seriesStatistic);
let sortButton = document.getElementById("seriesStatisticSort");
if (sortButton) {
sortButton.textContent = seriesStatisticSortLabel(
window.MusrfitSeriesStatisticSort === "run" ? "run" : "worst");
}
if (typeof dialog.showModal === "function") {
if (!dialog.open) dialog.showModal();
} else if ("hidden" in dialog) {
@@ -3015,20 +3010,6 @@ function showSeriesStatisticsDialog() {
}
}
function toggleSeriesStatisticSort() {
window.MusrfitSeriesStatisticSort = window.MusrfitSeriesStatisticSort === "run"
? "worst" : "run";
renderSeriesStatisticsTable(window.MusrfitJob.seriesStatistic);
let sortButton = document.getElementById("seriesStatisticSort");
if (sortButton) {
sortButton.textContent = seriesStatisticSortLabel(window.MusrfitSeriesStatisticSort);
}
}
function seriesStatisticSortLabel(mode) {
return mode === "run" ? "Sort by run" : "Worst first";
}
function renderSeriesStatisticsTable(rows) {
if (typeof document === "undefined") return;
let container = document.getElementById("seriesStatisticTable");
@@ -3048,18 +3029,11 @@ function renderSeriesStatisticsTable(rows) {
? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
}
let sortMode = window.MusrfitSeriesStatisticSort === "run" ? "run" : "worst";
let ordered = (Array.isArray(rows) ? rows : []).slice();
ordered.sort(function(a, b) {
let runA = Number(a && a.run) || 0;
let runB = Number(b && b.run) || 0;
if (sortMode === "run") return runA - runB;
let va = seriesStatisticValue(a);
let vb = seriesStatisticValue(b);
if (va === null && vb === null) return runA - runB;
if (va === null) return 1;
if (vb === null) return -1;
return vb - va;
return runA - runB;
});
container.textContent = "";
+9 -13
View File
@@ -268,9 +268,8 @@ function makeTableHarness() {
return { dom: dom, appended: appended, cells: function(tr) { return tr.childElements; } };
}
function testRenderSeriesStatisticsTableOrdering() {
function testRenderSeriesStatisticsTableRunOrder() {
const h = makeTableHarness();
h.dom.window.MusrfitSeriesStatisticSort = "worst";
h.dom.renderSeriesStatisticsTable([
chisqRow(2531, "1.01"),
Object.assign(chisqRow(2534, "0.5"), { fresh: true }),
@@ -280,19 +279,21 @@ function testRenderSeriesStatisticsTableOrdering() {
]);
assert.strictEqual(h.appended.length, 4);
const runOf = function(index) { return h.cells(h.appended[index])[0].textContent; };
assert.strictEqual(runOf(0), "2536", "the worst comparator sorts first");
assert.strictEqual(runOf(1), "2531");
assert.strictEqual(runOf(2), "2534");
assert.strictEqual(runOf(0), "2531", "run order sorts by number");
assert.strictEqual(runOf(1), "2534");
assert.strictEqual(runOf(2), "2536");
assert.strictEqual(runOf(3), "2538");
assert.ok(/series-stat-outlier/.test(h.appended[0].className),
assert.ok(/series-stat-outlier/.test(h.appended[2].className),
"a value beyond twice the median is flagged as an outlier");
assert.ok(/series-stat-notconverged/.test(h.appended[3].className),
"a non-converged row is highlighted");
assert.ok(h.appended[3].className.indexOf("series-stat-stale") < 0,
"a row without a comparable statistic is not marked stale");
assert.ok(h.appended[2].className.indexOf("series-stat-stale") < 0,
assert.ok(h.appended[1].className.indexOf("series-stat-stale") < 0,
"a freshly fitted row is not stale");
assert.ok(/series-stat-stale/.test(h.appended[0].className),
"a reused row with an on-disk statistic is flagged stale");
const empty = makeTableHarness();
empty.dom.renderSeriesStatisticsTable([]);
@@ -303,7 +304,6 @@ function testRenderSeriesStatisticsTableOrdering() {
function testRenderSeriesStatisticsTableRows() {
const h = makeTableHarness();
h.dom.window.MusrfitSeriesStatisticSort = "run";
h.dom.renderSeriesStatisticsTable([
Object.assign(chisqRow(2536, "5.0"), { action: "fit", fresh: true }),
chisqRow(2534, "0.5"),
@@ -330,22 +330,18 @@ function testShowSeriesStatisticsDialog(lib) {
open: false,
showModal: function() { shown = true; }
};
const sortButton = { textContent: "" };
let tableRenders = 0;
const dom = loadLibrary({
getElementById: function(id) {
if (id === "seriesStatisticDialog") return dialog;
if (id === "seriesStatisticSort") return sortButton;
if (id === "seriesStatisticTable") {
return { textContent: "", appendChild: function() { tableRenders++; } };
}
return null;
}
});
dom.window.MusrfitSeriesStatisticSort = "worst";
dom.showSeriesStatisticsDialog();
assert.strictEqual(shown, true, "the series dialog must open as a modal");
assert.strictEqual(sortButton.textContent, "Worst first");
assert.ok(tableRenders > 0, "the table must be rendered before opening");
}
@@ -359,7 +355,7 @@ function testShowSeriesStatisticsDialog(lib) {
testApplySeriesFitStatistic(lib);
testRenderJobStatusSeries(lib);
testRenderSeriesStatisticsTableOrdering();
testRenderSeriesStatisticsTableRunOrder();
testRenderSeriesStatisticsTableRows();
testShowSeriesStatisticsDialog(lib);
console.log("series statistic tests passed");