Archived
dashboard: level the download glyph with the caption, measured not reasoned
The operator's intent, drawn rather than described: the bottom of the tray bar should sit on the same line as the bottom of the letters in REQUESTS. The previous commit claimed the viewBox-flush geometry achieved that. It did not. Headless Chrome, screenshotting the real header at 4x and finding the lowest inked pixel row of each: the caption's letters ended at device row 71 and the tray bar at 63 -- the icon floated 2.00 CSS px high. align-items:baseline puts the SVG's BOX on the text baseline, and the baseline sits above the box bottom, so filling the box was necessary but nowhere near sufficient. A 2px translateY on the glyph closes it; re-measured, both bottoms land on device row 63, gap 0.00. tests/js/render_align.js is that measurement, kept in the repo so the claim can be re-checked rather than trusted. It is manual and not wired into CMake -- it needs puppeteer and a Chrome binary, which are not repo dependencies -- and exits nonzero when the two bottoms differ. It fails on the pre-fix page (2.00px above, rc=1), which is the only reason to believe it. download.test.js's guard was the thing that gave false confidence here: it asserted the glyph "sits on the baseline" from the viewBox arithmetic alone, and passed while the icon floated. It now pins both halves -- the glyph fills its box AND the 2px nudge is present -- and the comment records that the earlier claim was wrong and why the test could not see it. A unit test cannot catch either of this session's two visual errors: the collapsed whitespace (zero width, not the 13px claimed) and this float. Neither is a property of the string the code builds. Both are properties of the rendered page, and only the rendered page was checked here. Suites: download 31, history 29, extremes 27, poll_spark 35, dashboard_test 241 over 8 cases, sched_test 62646 over 184, no failures. Alignment mutations caught: removing the nudge, making it 1px, re-insetting the bar in its box. Not deployed. Goes to review with the separator and export commits. Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
This commit is contained in:
1 parent
d537dc09aa
commit
51db1729b1
3 files changed
+133
-5
No files matched your search
@@ -594,6 +594,11 @@ h1 { margin:0; font-size:13.5px; font-weight:600; letter-spacing:-.005em; }
|
||||
display:inline-flex; align-items:center; }
|
||||
.pbtn:hover { color:var(--fg); }
|
||||
.pbtn:focus-visible { outline:1px solid var(--edge); outline-offset:3px; }
|
||||
/* The glyph is nudged down 2px so the tray bar's bottom lines up with the bottom of the
|
||||
* caption's letters. align-items:baseline puts the SVG's BOX on the text baseline, but the
|
||||
* baseline sits above the box bottom, so the bar floated ~2px high -- measured in headless
|
||||
* Chrome, not eyeballed. The viewBox-flush geometry alone does not fix this. */
|
||||
#reqjson svg { transform: translateY(2px); }
|
||||
.pbody { padding:14px 16px 16px; }
|
||||
|
||||
/* The control vector's switch: a checkbox row with its explanation under it. The two need a gap
|
||||
|
||||
@@ -9,6 +9,7 @@ const src = require("./page.js"); // the <script> block: the handler l
|
||||
reason to read it). Read the whole shipped page for markup assertions. */
|
||||
const cpp = fs.readFileSync(path.join(__dirname, "..", "..", "core", "server", "dashboard.cpp"), "utf8");
|
||||
const page = (cpp.match(/R"HTML\(([\s\S]*)\)HTML"/) || [, ""])[1];
|
||||
const css = (cpp.match(/<style>([\s\S]*?)<\/style>/) || [, ""])[1];
|
||||
const L = src.split("\n");
|
||||
let fails = 0, checks = 0;
|
||||
const ok = (c, m) => { checks++; if (!c) { fails++; console.log(" FAIL " + m); } };
|
||||
@@ -24,16 +25,29 @@ ok(/title="Download JSON file"/.test(btn), "the tooltip says 'Download JSON file
|
||||
ok(/aria-label="Download JSON file"/.test(btn), "and is labelled for assistive tech");
|
||||
ok(/<svg[\s\S]*<\/svg>/.test(btn), "it holds an icon, not a text label");
|
||||
ok(!/>\s*json\s*</.test(btn), "no leftover 'json' text label inside the button");
|
||||
/* The glyph must sit ON the baseline, not float above it. The header aligns items on the text
|
||||
baseline, and an inline SVG's baseline is its box bottom -- so the tray bar's STROKE bottom
|
||||
has to land on the viewBox bottom. An inset bar (the original sat at 13.5 of 16) leaves dead
|
||||
space below it and the icon floats a hair above the caps, which is what this replaced. */
|
||||
/* Two things put the tray bar level with the bottom of the caption's letters, and BOTH are
|
||||
load-bearing -- measured in headless Chrome, not reasoned out:
|
||||
|
||||
1. the glyph fills its box: the bar's STROKE bottom lands on the viewBox bottom, so there is
|
||||
no dead space inside the SVG. An inset bar (the original sat at 13.5 of 16) shifts the
|
||||
bar up and the nudge below would then be the wrong size.
|
||||
2. the glyph is nudged down 2px: align-items:baseline puts the SVG's BOX on the text
|
||||
baseline, but the baseline sits ABOVE the box bottom, so even a box-filling glyph floated
|
||||
~2px high. The nudge is what actually closes the gap.
|
||||
|
||||
The first version of this guard checked only (1) and asserted it "sits on the baseline" --
|
||||
that claim was false, and the passing test is why the float survived a commit. */
|
||||
const vb = +(btn.match(/viewBox="0 0 ([\d.]+) ([\d.]+)"/) || [, , 0])[2];
|
||||
const sw = +(btn.match(/stroke-width="([\d.]+)"/) || [, 0])[1];
|
||||
const bar = +(btn.match(/M[\d.]+ ([\d.]+)h/) || [, 0])[1];
|
||||
ok(vb > 0 && sw > 0 && bar > 0, "parsed the glyph geometry (viewBox " + vb + ", stroke " + sw + ", bar " + bar + ")");
|
||||
eq(Math.round((bar + sw / 2) * 1000) / 1000, vb,
|
||||
"the tray bar's stroke bottom is flush with the box bottom, so it sits on the baseline");
|
||||
"the glyph fills its box: the tray bar's stroke bottom is flush with the viewBox bottom");
|
||||
/* The nudge that actually delivers the alignment. Pinned because it is a measured value, not a
|
||||
taste value: at 2px the bar's bottom and the caption's bottom land on the same device row. */
|
||||
const nudge = css.match(/#reqjson svg \{[^}]*transform:\s*translateY\(([\d.]+)px\)/);
|
||||
ok(nudge, "the download glyph carries an explicit vertical nudge");
|
||||
eq(nudge ? +nudge[1] : NaN, 2, "the nudge is the measured 2px (removing it floats the bar ~2px high)");
|
||||
/* It must sit in the Requests header, in the LEFT group, before the right-hand aside. Index
|
||||
ordering is sturdier than a regex across the whole block. */
|
||||
const iLeft = page.indexOf('class="pleft"');
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/* MANUAL render check -- not part of the suite, and not wired into CMake.
|
||||
*
|
||||
* It loads the dashboard in headless Chrome, screenshots the Requests header at 4x, and finds
|
||||
* the lowest inked pixel row of the caption's letters and of the download glyph's tray bar.
|
||||
* That is the only way to answer "is the icon level with the text": the CSS says where the
|
||||
* BOX goes, and the box is not the glyph.
|
||||
*
|
||||
* Needs puppeteer + a Chrome binary, which are NOT repo dependencies:
|
||||
* npm i puppeteer && npx puppeteer browsers install chrome
|
||||
* Then, with the page served (the viewer on :8900, or production on :8800):
|
||||
* node tests/js/render_align.js [url]
|
||||
* Exits nonzero if the two bottoms are not on the same device pixel row.
|
||||
*
|
||||
* Why this exists: the separator and glyph work went through three commits that each asserted
|
||||
* an alignment from the geometry -- "13px per boundary", "flush with the viewBox bottom, so it
|
||||
* sits on the baseline" -- and both claims were false. The first collapsed to zero width in
|
||||
* HTML; the second aligned the SVG box to the baseline while the baseline sits above the box
|
||||
* bottom, leaving the bar 2px high. A unit test cannot see either, because neither is about the
|
||||
* string the code builds. Measure the pixels.
|
||||
*/
|
||||
const puppeteer = require("puppeteer");
|
||||
const URL0 = process.argv[2] || "http://127.0.0.1:8900/";
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: "new",
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox", "--font-render-hinting=none"],
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
await page.setViewport({ width: 1400, height: 900, deviceScaleFactor: 4 });
|
||||
await page.goto(URL0, { waitUntil: "networkidle2", timeout: 30000 });
|
||||
await page.waitForSelector("#reqjson", { timeout: 10000 });
|
||||
|
||||
// the Requests caption and the download glyph, as laid out on the real page
|
||||
const boxes = await page.evaluate(() => {
|
||||
const btn = document.getElementById("reqjson");
|
||||
const cap = btn.closest(".pleft").querySelector(".cap");
|
||||
const svg = btn.querySelector("svg");
|
||||
const cs = getComputedStyle(cap);
|
||||
const r = (e) => { const b = e.getBoundingClientRect(); return {x:b.x,y:b.y,w:b.width,h:b.height,bottom:b.bottom}; };
|
||||
return { cap: r(cap), svg: r(svg), btn: r(btn), font: cs.fontFamily, size: cs.fontSize,
|
||||
align: getComputedStyle(btn.closest(".pleft")).alignItems };
|
||||
});
|
||||
console.log("cap ", JSON.stringify(boxes.cap));
|
||||
console.log("svg ", JSON.stringify(boxes.svg));
|
||||
console.log("align-items:", boxes.align, " font:", boxes.size, boxes.font.slice(0, 40));
|
||||
|
||||
// screenshot the strip containing both, then decode IN THE BROWSER and find ink rows
|
||||
const x0 = Math.floor(boxes.cap.x) - 2, x1 = Math.ceil(boxes.svg.x + boxes.svg.w) + 2;
|
||||
const y0 = Math.floor(Math.min(boxes.cap.y, boxes.svg.y)) - 4;
|
||||
const y1 = Math.ceil(Math.max(boxes.cap.bottom, boxes.svg.bottom)) + 6;
|
||||
const shot = await page.screenshot({ encoding: "base64",
|
||||
clip: { x: x0, y: y0, width: x1 - x0, height: y1 - y0 } });
|
||||
|
||||
const res = await page.evaluate(async (b64, capX, svgX, x0, y0, scale) => {
|
||||
const img = new Image();
|
||||
img.src = "data:image/png;base64," + b64;
|
||||
await img.decode();
|
||||
const c = document.createElement("canvas");
|
||||
c.width = img.width; c.height = img.height;
|
||||
const g = c.getContext("2d", { willReadFrequently: true });
|
||||
g.drawImage(img, 0, 0);
|
||||
const d = g.getImageData(0, 0, c.width, c.height).data;
|
||||
// ink = pixel meaningfully brighter than the near-black background
|
||||
const rowInk = (xFrom, xTo) => {
|
||||
const xa = Math.max(0, Math.round((xFrom - x0) * scale));
|
||||
const xb = Math.min(c.width, Math.round((xTo - x0) * scale));
|
||||
const rows = [];
|
||||
for (let y = 0; y < c.height; y++) {
|
||||
let mx = 0;
|
||||
for (let x = xa; x < xb; x++) {
|
||||
const i = (y * c.width + x) * 4;
|
||||
mx = Math.max(mx, d[i], d[i + 1], d[i + 2]);
|
||||
}
|
||||
rows.push(mx);
|
||||
}
|
||||
return rows;
|
||||
};
|
||||
const lastInk = (rows, thr) => { for (let y = rows.length - 1; y >= 0; y--) if (rows[y] > thr) return y; return -1; };
|
||||
const firstInk = (rows, thr) => { for (let y = 0; y < rows.length; y++) if (rows[y] > thr) return y; return -1; };
|
||||
const capRows = rowInk(capX.x, capX.x + capX.w);
|
||||
const svgRows = rowInk(svgX.x, svgX.x + svgX.w);
|
||||
const T = 60; // background is ~#0a0a0a; text/icon are #7b7b7b / #4d4d4d
|
||||
return {
|
||||
imgH: c.height, scale,
|
||||
capFirst: firstInk(capRows, T), capLast: lastInk(capRows, T),
|
||||
svgFirst: firstInk(svgRows, T), svgLast: lastInk(svgRows, T),
|
||||
peakCap: Math.max(...capRows), peakSvg: Math.max(...svgRows),
|
||||
};
|
||||
}, shot, boxes.cap, boxes.svg, x0, y0, 4);
|
||||
|
||||
console.log("url:", URL0);
|
||||
console.log("decoded:", JSON.stringify(res));
|
||||
if (res.capLast < 0 || res.svgLast < 0) { console.log("MEASUREMENT FAILED: no ink found in a region"); }
|
||||
else {
|
||||
const gapDevice = res.svgLast - res.capLast;
|
||||
const gapCss = gapDevice / 4;
|
||||
console.log("\n bottom of REQUESTS ink : device row " + res.capLast);
|
||||
console.log(" bottom of tray-bar ink : device row " + res.svgLast);
|
||||
console.log(" GAP = " + gapDevice + " device px = " + gapCss.toFixed(2) + " CSS px");
|
||||
console.log(" " + (gapCss === 0 ? "PERFECTLY FLUSH" :
|
||||
(gapCss > 0 ? "icon sits " + gapCss.toFixed(2) + "px BELOW the letters"
|
||||
: "icon sits " + Math.abs(gapCss).toFixed(2) + "px ABOVE the letters")));
|
||||
}
|
||||
const flush = res.capLast >= 0 && res.svgLast >= 0 && res.svgLast === res.capLast;
|
||||
console.log(flush ? "\nPASS: tray bar and caption bottoms share a device row"
|
||||
: "\nFAIL: not level (see GAP above)");
|
||||
await browser.close();
|
||||
process.exit(flush ? 0 : 1);
|
||||
})().catch((e) => { console.log("ERROR: " + e.message); process.exit(1); });
|
||||
Reference in new issue
Block a user