Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 331d42ddac2d7031859434d9ca631fb22db12eb3
parent d3c7a01baa54384419feaeb9a9762068df29fe45
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri,  6 Nov 2026 02:48:14 -0500

umtool: the dial's as-of label never sits on a scale figure

"≈390 · AS OF FEB 2025 · TOLD 4×" sat on the 380. The face's figures are now
one geometry (dialFigures in measure-draw.mjs, which dialFaceSvg draws from --
its markup byte-identical), each with a slightly generous glyph box. An as-of
label measures its own box from its css and takes the first clear place: along
its ghost at half the radius, its small words on two lines when the count is
on, then stepping in toward the hub; never below just under the hub, and never
on the hub itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/report-to-video/chrome-instruments.mjs | 69++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mumtool/report-to-video/measure-draw.mjs | 40++++++++++++++++++++++++++++++++++------
2 files changed, 96 insertions(+), 13 deletions(-)

diff --git a/umtool/report-to-video/chrome-instruments.mjs b/umtool/report-to-video/chrome-instruments.mjs @@ -21,7 +21,7 @@ import { resolveDial, resolveOdometer, resolveTrail } from "./instruments.mjs"; import { promiseStates, upSpans } from "./measure-extras.mjs"; import { resolveMeasureExtra } from "./modules/measure-extras-settings.mjs"; import { - cueList, dayNumber, dialAngle, dialFaceSvg, DIAL_SWEEP, esc, fmtDate, fmtSigned, fmtWeight, INSTANT, measureTrack, + cueList, dayNumber, dialAngle, dialFaceSvg, dialFigures, DIAL_SWEEP, esc, fmtDate, fmtSigned, fmtWeight, INSTANT, measureTrack, pageHtml, polar, qualifierMark, r4, sectorPath, wedgeRange, weightWords, wheelCount, wheelRoll, wheelStrip, } from "./measure-draw.mjs"; @@ -123,6 +123,56 @@ export const goalWords = (g) => { // The dial. // --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- +// Words on the face, kept off its figures. +// --------------------------------------------------------------------------- + +/** Whether boxes `a` and `b` ({x0, x1, y0, y1}) come within `m` px of each other. */ +const boxesTouch = (a, b, m = 0) => a.x0 < b.x1 + m && b.x0 < a.x1 + m && a.y0 < b.y1 + m && b.y0 < a.y1 + m; + +/** How far boxes `a` and `b` overlap, with `m` px between them counted in: 0 when they are clear. */ +const touchArea = (a, b, m = 0) => + Math.max(0, Math.min(a.x1, b.x1 + m) - Math.max(a.x0, b.x0 - m)) * Math.max(0, Math.min(a.y1, b.y1 + m) - Math.max(a.y0, b.y0 - m)); + +/** + * The first of `spots` (each {box, ...}, in order of preference) whose box clears every one of `obstacles` by `m` + * px; when none does, the one that touches them least. The words' boxes are estimates in the face's px (see + * dialFigures), deliberately a little wide. + */ +export function clearSpot(spots, obstacles, m = 0) { + let best = null, least = Infinity; + for (const s of spots) { + if (!obstacles.some((o) => boxesTouch(s.box, o, m))) return s; + const t = obstacles.reduce((n, o) => n + touchArea(s.box, o, m), 0); + if (t < least) { least = t; best = s; } + } + return best; +} + +/** A centred box `w` x `h` at (x, y). */ +const boxAt = (x, y, w, h) => ({ x0: x - w / 2, x1: x + w / 2, y0: y - h / 2, y1: y + h / 2 }); + +/** + * An as-of label's places, best first: along its ghost (angle `a`) at half the face's radius, each of its `forms` + * (its small words on one line, then on two), then stepping in toward the hub; never lower than just under the hub, + * where the readout's words are. Its box from its css (.asof: the head 24, the small words 13 condensed with + * 0.08em spacing, 3/7 padding). + */ +function asofSpots({ C, Rf, u, a, head, forms, px, fpx }) { + const hb = px(24), hs = fpx(13); + const spots = []; + for (let r = Rf * 0.52; r >= Rf * 0.26 - 1e-9; r -= Rf * 0.04) { + const [x, y0] = polar(C, C, r, a); + const y = Math.min(y0, Math.round((C + 30 * u) * 100) / 100); + for (const lines of forms) { + const w = Math.max(head.length * hb * 0.6, ...lines.map((l) => l.length * hs * 0.66)) + 2 * px(7); + const h = hb * 1.05 + lines.length * hs * 1.05 + 2 * px(3); + spots.push({ x, y, lines, box: boxAt(x, y, w, h) }); + } + } + return spots; +} + /** * The dial's face and everything on it, `size` px square at (ox, oy) in the * page: the static face, the ghosts, the wedges, the goal tick, the needles, @@ -178,16 +228,21 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, prefix = "" `<polygon points="${C - 6 * u},${C + 34 * u} ${C + 6 * u},${C + 34 * u} ${C + 1.8 * u},${C - Rf + 30 * u} ${C - 1.8 * u},${C - Rf + 30 * u}" fill="${colors.needle}"/>` + `<circle cx="${C}" cy="${C + 34 * u}" r="${px(9)}" fill="${colors.needle}"/>`)); parts.push(`<div class="ly"><svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><circle cx="${C}" cy="${C}" r="${px(16)}" fill="${colors.needle}"/><circle cx="${C}" cy="${C}" r="${px(6)}" fill="${colors.face}"/></svg></div>`); - // The as-of labels, each by its ghost, up while it is the latest. + // The as-of labels, each by its ghost, up while it is the latest -- and never on a scale figure (rev 9: "≈390 · + // AS OF FEB 2025 · TOLD 4×" sat on the 380). Along its ghost, never down into the readout's words under the hub; + // where its box would touch a figure's, its words go on two lines, then it steps in toward the hub. if (cfg.ghosts) { + const figures = dialFigures({ size, scale, mark: cfg.mark }); + const hub = { x0: C - 18 * u, x1: C + 18 * u, y0: C - 18 * u, y1: C + 18 * u }; track.remembered.forEach((g, j) => { const a = dialAngle(g.value, scale); - // Along its ghost, but never down into the readout's words under the hub. - const [x, y0] = polar(C, C, Rf * 0.52, a); - const y = Math.min(y0, Math.round((C + 30 * u) * 100) / 100); + const head = weightWords(g); + const asOf = g.asOf ? `AS OF ${fmtDate(g.asOf)}` : "REMEMBERED"; // The moving start's count rides on its ghost (rev 9: "≈390 · TOLD 5×", the peak module off beside the dial). - const told = g.told > 1 ? ` · TOLD ${g.told}×` : ""; - parts.push(`<div class="asof" data-k="${prefix}ga${j}" style="left:${x}px; top:${y}px"><b>${esc(weightWords(g))}</b><span>${g.asOf ? `AS OF ${esc(fmtDate(g.asOf))}` : "REMEMBERED"}${told}</span></div>`); + const told = g.told > 1 ? `TOLD ${g.told}×` : ""; + const forms = told ? [[`${asOf} · ${told}`], [asOf, told]] : [[asOf]]; + const spot = clearSpot(asofSpots({ C, Rf, u, a, head, forms, px, fpx }), [...figures.map((f) => f.box), hub], 3 * u); + parts.push(`<div class="asof" data-k="${prefix}ga${j}" style="left:${spot.x}px; top:${spot.y}px"><b>${esc(head)}</b>${spot.lines.map((l) => `<span>${esc(l)}</span>`).join("")}</div>`); }); } // The readout under the hub: the words, the weight, the weighing's date, the goal. diff --git a/umtool/report-to-video/measure-draw.mjs b/umtool/report-to-video/measure-draw.mjs @@ -236,6 +236,35 @@ export function wedgeRange(value, q, range = null) { } /** + * The dial face's scale figures -- a label every 20 lb and the mark's -- where + * dialFaceSvg draws them: each its value, its anchor (`x` its middle, `y` its + * baseline), its font size and its `box` in the face's px. The box is the + * glyphs' estimate, a little generous (a digit of the condensed face is about + * half an em wide, the cap height about three quarters of one), so a word laid + * beside it on the face keeps clear of the figure whichever font is loaded. + * The one geometry for both the face and whatever must stay off its figures. + */ +export function dialFigures({ size, scale, mark = 300 }) { + const C = size / 2; + const R = C - Math.round(size * 0.012); + const Rf = R - Math.round(size * 0.026); + const u = size / 524; + const fig = (v, r, lift, font, isMark) => { + const [x, y0] = polar(C, C, r, dialAngle(v, scale)); + const y = r2(y0 + lift * u), fs = r2(font * u); + const w = String(v).length * fs * 0.6; + return { v, x, y, fs, mark: isMark, box: { x0: x - w / 2, x1: x + w / 2, y0: y - fs * 0.78, y1: y + fs * 0.06 } }; + }; + const out = []; + for (let v = Math.ceil(scale.min / 20) * 20; v <= scale.max + 1e-9; v += 20) { + if (Number.isFinite(mark) && v === mark) continue; + out.push(fig(v, Rf - 54 * u, 8, 24, false)); + } + if (Number.isFinite(mark) && mark >= scale.min && mark <= scale.max) out.push(fig(mark, Rf - 58 * u, 9, 28, true)); + return out; +} + +/** * The dial face as SVG markup, `size` px square: the bezel, the face, a tick * every 2 lb (longer every 10, longest every 20), a label every 20, the * `mark` weight (300) accented. Static: nothing on it moves. @@ -256,18 +285,17 @@ export function dialFaceSvg({ size, scale, mark = 300, colors, labelFont = "sans const [x2, y2] = polar(C, C, Rf - (major ? 30 : mid ? 22 : 14) * u, a); out.push(`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${colors.ink}" stroke-width="${r2((major ? 3 : mid ? 2 : 1.2) * u)}" stroke-opacity="${major ? 1 : mid ? 0.85 : 0.6}"/>`); } - for (let v = Math.ceil(scale.min / 20) * 20; v <= scale.max + 1e-9; v += 20) { - if (Number.isFinite(mark) && v === mark) continue; - const [x, y] = polar(C, C, Rf - 54 * u, dialAngle(v, scale)); - out.push(`<text x="${x}" y="${r2(y + 8 * u)}" text-anchor="middle" font-family="${labelFont}" font-size="${r2(24 * u)}" fill="${colors.ink}">${v}</text>`); + const figures = dialFigures({ size, scale, mark }); + for (const f of figures.filter((g) => !g.mark)) { + out.push(`<text x="${f.x}" y="${f.y}" text-anchor="middle" font-family="${labelFont}" font-size="${f.fs}" fill="${colors.ink}">${f.v}</text>`); } if (Number.isFinite(mark) && mark >= scale.min && mark <= scale.max) { const a = dialAngle(mark, scale); const [x1, y1] = polar(C, C, Rf - 3 * u, a); const [x2, y2] = polar(C, C, Rf - 36 * u, a); out.push(`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${colors.mark}" stroke-width="${r2(6 * u)}" stroke-linecap="round"/>`); - const [x, y] = polar(C, C, Rf - 58 * u, a); - out.push(`<text x="${x}" y="${r2(y + 9 * u)}" text-anchor="middle" font-family="${labelFont}" font-size="${r2(28 * u)}" fill="${colors.mark}">${mark}</text>`); + const f = figures.find((g) => g.mark); + out.push(`<text x="${f.x}" y="${f.y}" text-anchor="middle" font-family="${labelFont}" font-size="${f.fs}" fill="${colors.mark}">${mark}</text>`); } return { svg: `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}">${out.join("")}</svg>`, C, R, Rf, u }; }