From 6d6caf0fd84cc95c48b00bf31cd737bd5bcbeb00 Mon Sep 17 00:00:00 2001 From: salman Date: Thu, 10 Sep 2026 14:17:38 +0200 Subject: [PATCH] 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. --- ZGUI.css | 8 -------- index.html | 4 ---- muSRFitlib.js | 28 +--------------------------- tests/series-statistic.test.js | 22 +++++++++------------- 4 files changed, 10 insertions(+), 52 deletions(-) diff --git a/ZGUI.css b/ZGUI.css index 68cc6d5..0a9f2f3 100644 --- a/ZGUI.css +++ b/ZGUI.css @@ -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; diff --git a/index.html b/index.html index 694fc50..0360d40 100644 --- a/index.html +++ b/index.html @@ -600,10 +600,6 @@ title="Close statistics" aria-label="Close statistics">× -
- -
diff --git a/muSRFitlib.js b/muSRFitlib.js index 646e859..b9c6c57 100644 --- a/muSRFitlib.js +++ b/muSRFitlib.js @@ -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 = ""; diff --git a/tests/series-statistic.test.js b/tests/series-statistic.test.js index 786d814..ff9b662 100644 --- a/tests/series-statistic.test.js +++ b/tests/series-statistic.test.js @@ -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");