commit 1902340059e057c9663a07560e7d8325520a48ff
parent 44c0ddd4974708b3ec41750fd6ebc5afd6ed0efa
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 22:58:35 -0500
umtool: the counter holds up to 12 series -- past 8 the cells narrow into one row -- and `labels: "as-written"` sets each cell's words in their own case, in up to two lines
Operator, 6 Nov: groups "with the literal spoken label e.g. 'moderate', 'moderate
conservative', 'close to MAGA'". The counter's cap was 8 cells of 124 px, each word
capitalised on one line and cut to its last words when it did not fit -- so
"moderate conservative" read CONSERVATIVE, the same as "conservative".
- design.mjs counterCell: up to 8 series the cells are what they were; past 8 they
share a row of 1040 px (9 -> 108 px, 10 -> 96, 12 -> 79), so the deck's title keeps
a column of about 520 px beside the QR. COUNTER_LIMITS.series 8 -> 12.
- deck.counter.labels: "caps" (the default, byte for byte what it was) or
"as-written": the label in its own case, letter-spaced 0.02 em, broken between words
into at most two lines, never cut. A written label or cell word may be 32 characters
(a stamp's word still 24).
- The fit check (factcheck.mjs counterLabelProblem / tallyLabelLines /
writtenLabelLines) measures in the cell the row gives it, with Fira Sans Bold's
lower-case advances added to its table, and refuses by name.
- The deck page draws the lines the check passed; the count gives a second line room.
- Docs: knobs.md's Counter rows (generated); unit tests for the cells, the lines, the
checks and the page.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
9 files changed, 215 insertions(+), 38 deletions(-)
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -1644,7 +1644,8 @@ The deck's tally as named series (`render.chrome.deck.counter`). A clip's mark n
| Knob | Range · default | From a terminal |
|---|---|---|
-| `deck.counter.series[]` | 1–8 `{id, label, color?, stampLabel?, tallyLabel?, showAt?, shape?, unit?}` -- an `id` a letter then letters, digits, `_` `-`; a verdict's id (`CORROBORATED` …) takes its default label, colour and shape; `label` ≤ 24 and fitting the cell, as the verdicts' are | `umtool look <p> deck.counter='{"series":[{"id":"seizures","label":"Seizures","color":"#e5534b","stampLabel":"Seizure"}]}'` |
+| `deck.counter.series[]` | 1–12 `{id, label, color?, stampLabel?, tallyLabel?, showAt?, shape?, unit?}` -- an `id` a letter then letters, digits, `_` `-`; a verdict's id (`CORROBORATED` …) takes its default label, colour and shape; `label` ≤ 24 (≤ 32 as written) and fitting the cell, as the verdicts' are. Up to 8 the cells are 124 px; past 8 they narrow into one row of 1040 px (9 → 108 px, 10 → 96, 12 → 79), so the title keeps a column of about 520 px, and a label must fit the narrower cell (refused by name, never cut) | `umtool look <p> deck.counter='{"series":[{"id":"seizures","label":"Seizures","color":"#e5534b","stampLabel":"Seizure"}]}'` |
+| `deck.counter.labels` | `caps` `as-written` · default `caps`: each cell's word capitalised on one line (its `tallyLabel`, else its label or the last words of it that fit). `as-written`: the label in its own case ("close to MAGA"), letter-spaced 0.02 em, broken between words into at most two lines, never cut to its last words -- a word wider than the cell, or a third line, is refused by name | `umtool look <p> deck.counter.labels=as-written` |
| `deck.counter.series[].shape` | `circle` `diamond` `square` `triangle` `ring` · default by place (a verdict's own) | same |
| `deck.counter.series[].unit` | ≤ 24 · the noun a count claim's number reads (default its label, lower-cased) | same |
| `deck.counter.show`, `.position`, `.showAt` | bool · `right` `left` · `always` `first` (a series' own `showAt` wins) · defaults `true`, `right`, `always`. A series that SAYS `always` (its own `showAt`, else the counter's) is a cell from the first frame, dim at 0, whether or not a mark ever counts it ("Left 0"); one with no `showAt` said, or `first`, is a cell once it is counted, so one never counted is not drawn. The cells show once the cut counts anything | same |
diff --git a/umtool/report-to-video/chrome-deck.mjs b/umtool/report-to-video/chrome-deck.mjs
@@ -43,7 +43,7 @@ import {
} from "./deck.mjs";
import { contrast } from "./chrome-intro.mjs";
import { claimsCues, claimsMarkup } from "./chrome-claims.mjs";
-import { resolveFactcheck, tallyCues, tallyFinals, tallyKey, tallyLabelOf, tallyOf, tallyPopIns } from "./factcheck.mjs";
+import { resolveFactcheck, TALLY_WRITTEN, tallyCues, tallyFinals, tallyKey, tallyLabelLines, tallyOf, tallyPopIns } from "./factcheck.mjs";
import { resolveCounter } from "./counter.mjs";
import { SUBSECTION_SEPARATOR } from "./marker-limits.mjs";
@@ -841,11 +841,22 @@ export function deckHtml(schedule, render, opts = {}) {
// will show stacked in one box (`n0` … `n<final>`), its label under it.
const tb = lay.tally ?? null;
const verdictSet = tb ? resolveFactcheck(render).verdicts : null;
- const countSize = tb ? Math.round(tb.height * 0.42) : 0;
+ // Each cell's words (factcheck.mjs tallyLabelLines): the cell's own short word, else the label (or its last
+ // words) that fits, capitalised -- never an ellipsis; AS WRITTEN (`counter.labels`), the label in up to two
+ // lines, its own case. Past 8 series the cells are narrower (design.mjs counterCell).
+ const written = counter.labels === "as-written";
+ const fontBold = render.fontBold ?? null;
+ const cellWords = tb
+ ? Object.fromEntries(tally.map((v) => [v, tallyLabelLines(verdictSet[v], { fontBold, n: tally.length, labels: counter.labels }) ?? [verdictSet[v].label]]))
+ : {};
+ const labelLines = written ? Math.max(1, ...Object.values(cellWords).map((l) => l.length)) : 1;
+ // As written in two lines, the count gives the second line its room.
+ const countSize = tb ? Math.round(tb.height * (labelLines > 1 ? 0.36 : 0.42)) : 0;
const countBox = Math.round(countSize * 1.12);
- const labelSize = 13;
- const labelBox = 17;
- const cellTop = tb ? Math.round((tb.height - (countBox + 8 + labelBox)) / 2) + 2 : 0;
+ const labelSize = written ? TALLY_WRITTEN.size : 13;
+ const labelBox = written ? TALLY_WRITTEN.lineBox : 17;
+ const labelBlock = labelBox * labelLines;
+ const cellTop = tb ? Math.round((tb.height - (countBox + 8 + labelBlock)) / 2) + 2 : 0;
const tallyHtml = tb
? `<div class="tally">` +
tally
@@ -865,9 +876,8 @@ export function deckHtml(schedule, render, opts = {}) {
(byVerdict
? `<div class="tshape" data-shape="${shapes[v]}" style="${shapeCss(shapes[v], 12, esc(color))}"></div>`
: "") +
- // tallyLabelOf: the cell's own short word, else the label (or its
- // last words) that fits -- never an ellipsis.
- `<div class="tlabel">${esc(tallyLabelOf(verdictSet[v], { fontBold: render.fontBold ?? null }) ?? verdictSet[v].label)}</div>` +
+ // cellWords: its line, or (as written) its lines.
+ `<div class="tlabel">${cellWords[v].map(esc).join("<br>")}</div>` +
`<div class="tflash" data-k="${tallyKey(v, "flash")}"></div></div>`
);
})
@@ -1037,7 +1047,7 @@ export function deckHtml(schedule, render, opts = {}) {
font-size: ${countSize}px; line-height: ${countBox}px; color: var(--vc); font-variant-numeric: tabular-nums; }
.tlabel { position: absolute; left: 6px; top: ${cellTop + countBox + 8}px; width: ${tb.cell - 12}px; text-align: center;
font-family: 'DeckSansBold', sans-serif; font-size: ${labelSize}px; line-height: ${labelBox}px;
- letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; overflow: hidden;
+ letter-spacing: ${written ? TALLY_WRITTEN.tracking : 0.08}em; text-transform: ${written ? "none" : "uppercase"}; white-space: nowrap; overflow: hidden;
text-overflow: ellipsis; color: var(--vl); }
.tflash { position: absolute; inset: 0; border-radius: 8px; opacity: 0; pointer-events: none;
box-shadow: inset 0 0 0 2px var(--vc), inset 0 0 22px var(--vg); }` : ""}${tb && byVerdict ? `
diff --git a/umtool/report-to-video/counter.mjs b/umtool/report-to-video/counter.mjs
@@ -37,8 +37,17 @@ export const COUNTER_SHOW_AT = Object.freeze(["always", "first"]);
/** Which end of the deck's text column the counter takes. */
export const COUNTER_POSITIONS = Object.freeze(["right", "left"]);
-/** The counter's limits: how many series, an id's and a unit's characters. */
-export const COUNTER_LIMITS = Object.freeze({ series: 8, id: 32, unit: 24, label: VERDICT_LABEL_MAX });
+/** How a series' words are set in its cell: capitalised (as the verdicts always were), or as written. */
+export const COUNTER_LABELS = Object.freeze(["caps", "as-written"]);
+
+/**
+ * The counter's limits: how many series, an id's and a unit's characters, a
+ * label's (`writtenLabel`: a label or cell word set as written, which may take
+ * two lines). Past 8 series the cells narrow into one row (design.mjs
+ * counterCell, lane leaflit-labels): 12 is the most whose cells still hold a
+ * short word at the deck's own label size.
+ */
+export const COUNTER_LIMITS = Object.freeze({ series: 12, id: 32, unit: 24, label: VERDICT_LABEL_MAX, writtenLabel: 32 });
/** A series id: what a mark names. A letter, then letters, digits, `_` or `-`. */
export const SERIES_ID_RE = /^[A-Za-z][A-Za-z0-9_-]{0,31}$/;
@@ -50,7 +59,7 @@ export const SERIES_COLORS = Object.freeze(["#e5534b", "#e3b23c", "#3fbf7f", "#7
export const SERIES_KEYS = Object.freeze(["id", "label", "color", "stampLabel", "tallyLabel", "showAt", "unit", "shape"]);
/** The keys `deck.counter` may carry. */
-export const COUNTER_KEYS = Object.freeze(["series", "show", "position", "showAt"]);
+export const COUNTER_KEYS = Object.freeze(["series", "show", "position", "showAt", "labels"]);
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
@@ -93,6 +102,7 @@ export function resolveCounter(render) {
showAt: Object.fromEntries(series.map((s) => [s.id, s.showAt])),
show: c.show !== false,
position: COUNTER_POSITIONS.includes(c.position) ? c.position : "right",
+ labels: COUNTER_LABELS.includes(c.labels) ? c.labels : "caps",
};
}
// The fact-check verdicts, as the tally always counted them.
@@ -111,6 +121,7 @@ export function resolveCounter(render) {
showAt,
show: tally.show !== false,
position: COUNTER_POSITIONS.includes(tally.position) ? tally.position : "right",
+ labels: "caps",
};
}
@@ -141,6 +152,10 @@ export function validateCounter(c, { factcheck = undefined, labelFits = null, wh
if (c.showAt !== undefined && !COUNTER_SHOW_AT.includes(c.showAt)) {
errors.push(`${where}.showAt must be ${COUNTER_SHOW_AT.map((p) => `"${p}"`).join(" or ")}`);
}
+ if (c.labels !== undefined && !COUNTER_LABELS.includes(c.labels)) {
+ errors.push(`${where}.labels must be ${COUNTER_LABELS.map((p) => `"${p}"`).join(" or ")}`);
+ }
+ const written = c.labels === "as-written";
if (!Array.isArray(c.series) || !c.series.length) {
errors.push(`${where}.series must list at least one series { id, label }`);
return errors;
@@ -161,7 +176,11 @@ export function validateCounter(c, { factcheck = undefined, labelFits = null, wh
if (word === undefined) continue;
if (typeof word !== "string" || !word.trim()) errors.push(`${w}.${key} must be words, not empty`);
else if (/[\r\n]/.test(word)) errors.push(`${w}.${key} must be one line`);
- else if (word.trim().length > COUNTER_LIMITS.label) errors.push(`${w}.${key} is ${word.trim().length} characters (at most ${COUNTER_LIMITS.label})`);
+ else {
+ // A label or cell word set as written may run to two lines; a stamp's word is one line, as ever.
+ const max = written && key !== "stampLabel" ? COUNTER_LIMITS.writtenLabel : COUNTER_LIMITS.label;
+ if (word.trim().length > max) errors.push(`${w}.${key} is ${word.trim().length} characters (at most ${max})`);
+ }
}
if (s.color !== undefined && !(typeof s.color === "string" && VERDICT_COLOR_RE.test(s.color))) errors.push(`${w}.color must be a hex colour, #rgb or #rrggbb`);
if (s.showAt !== undefined && !COUNTER_SHOW_AT.includes(s.showAt)) errors.push(`${w}.showAt must be ${COUNTER_SHOW_AT.map((p) => `"${p}"`).join(" or ")}`);
@@ -170,7 +189,7 @@ export function validateCounter(c, { factcheck = undefined, labelFits = null, wh
errors.push(`${w}.unit must be a word, 1 to ${COUNTER_LIMITS.unit} characters`);
}
if (labelFits && !errors.some((e) => e.startsWith(`${w}.`))) {
- const problem = labelFits(s, w);
+ const problem = labelFits(s, w, { n: c.series.length, labels: written ? "as-written" : "caps" });
if (problem) errors.push(problem);
}
});
diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs
@@ -31,7 +31,7 @@ import {
import { resolveCounter } from "./counter.mjs";
import { INSTRUMENT_COLUMN, instrumentsOn, instrumentsPlacement, instrumentsWanted, resolveDial } from "./instruments.mjs";
import { TRAILER_HIT_TIERS, TRAILER_SWELL } from "./trailer-hits.mjs";
-import { DECK_PAD_X, COUNTER_CELL } from "./modules/design.mjs";
+import { DECK_PAD_X, counterCell } from "./modules/design.mjs";
import { parseShelfNote, resolveShelf, SHELF_MIN } from "./modules/shelf-settings.mjs";
// An entry's note on the shelf, as written (`umtool set <p> <entry> shelfNote=…`; manifest.mjs checks it here).
@@ -646,7 +646,8 @@ export function deckLayout(render, { tally = null, schedule = null } = {}) {
// A cell per verdict the cut uses: its count over its label. Beside the
// QR's cell (whose plate starts 46 px before the code) on the right, or
// ahead of the title on the left; 40 px of air to the text either way.
- const { cell, gap } = COUNTER_CELL;
+ // Past 8 series the cells narrow into one row's budget (design.mjs counterCell).
+ const { cell, gap } = counterCell(tally.length);
const width = tally.length * cell + (tally.length - 1) * gap;
const height = Math.min(bodyH - 8, 118);
const y = Math.round(bodyTop + (bodyH - height) / 2);
diff --git a/umtool/report-to-video/factcheck.mjs b/umtool/report-to-video/factcheck.mjs
@@ -37,7 +37,7 @@
import { offsetIn } from "./gaps.mjs";
import { isIsoDate } from "./claims.mjs";
import { resolveCounter, VERDICT_SHAPES } from "./counter.mjs";
-import { COUNTER_CELL } from "./modules/design.mjs";
+import { COUNTER_CELL, counterCell } from "./modules/design.mjs";
import {
VERDICT_DEFAULTS,
VERDICT_LABEL_MAX,
@@ -135,12 +135,26 @@ function unknownKeys(obj, allowed, where, errors) {
*/
export const TALLY_LABEL = Object.freeze({ size: 13, tracking: 0.08, width: COUNTER_CELL.cell - 2 * COUNTER_CELL.labelPad });
+/**
+ * A label AS WRITTEN (`deck.counter.labels: "as-written"`, lane leaflit-labels:
+ * "the literal spoken label e.g. 'moderate', 'close to MAGA'"): not capitalised,
+ * letter-spaced 0.02 em, in up to two lines of `lineBox` px -- broken between
+ * words, never inside one, never cut to its last words.
+ */
+export const TALLY_WRITTEN = Object.freeze({ size: 13, tracking: 0.02, lines: 2, lineBox: 15 });
+
+/** The label's room in the cell for `n` series (design.mjs counterCell): the cell less its pad a side. */
+export const tallyLabelRoom = (n) => {
+ const c = counterCell(n);
+ return c.cell - 2 * c.labelPad;
+};
+
// Fira Sans Bold's advances (the deck's bold unless a brand sets one), per
// character a capitalised label can hold, in 1/1000 em, rounded UP --
// measured from /usr/share/fonts/TTF/FiraSans-Bold.ttf. Kerning is not
// counted; the 2 % margin below covers it.
-const FIRA_BOLD_CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~’‘“”…–—ÀÁÂÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÖØÙÚÛÜ";
-const FIRA_BOLD_ADV = "237,240,439,557,549,859,760,238,325,325,449,531,240,407,240,520,585,464,517,520,565,536,564,468,581,560,240,240,519,519,519,481,1020,590,617,575,651,526,487,645,666,293,317,633,513,786,663,691,600,690,617,572,540,651,570,847,581,594,544,324,520,324,559,520,340,324,376,324,514,243,243,448,448,727,520,796,590,590,590,590,590,575,526,526,526,526,293,293,293,293,663,691,691,691,691,691,651,651,651,651";
+const FIRA_BOLD_CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~’‘“”…–—ÀÁÂÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÖØÙÚÛÜabcdefghijklmnopqrstuvwxyz";
+const FIRA_BOLD_ADV = "237,240,439,557,549,859,760,238,325,325,449,531,240,407,240,520,585,464,517,520,565,536,564,468,581,560,240,240,519,519,519,481,1020,590,617,575,651,526,487,645,666,293,317,633,513,786,663,691,600,690,617,572,540,651,570,847,581,594,544,324,520,324,559,520,340,324,376,324,514,243,243,448,448,727,520,796,590,590,590,590,590,575,526,526,526,526,293,293,293,293,663,691,691,691,691,691,651,651,651,651,546,591,479,594,554,356,551,573,280,280,551,300,841,573,584,591,594,400,480,386,568,513,749,512,518,454";
/**
* How wide a tally label draws, px, as the page sets it (upper-cased, the
@@ -150,16 +164,18 @@ const FIRA_BOLD_ADV = "237,240,439,557,549,859,760,238,325,325,449,531,240,407,2
* counted at 1.02 em (wider than any capital Fira draws but @), so a label
* called fitting fits. 2 % over the sum, for kerning.
*/
-export function tallyLabelWidth(label, { fontBold = null, size = TALLY_LABEL.size } = {}) {
+export function tallyLabelWidth(label, { fontBold = null, size = TALLY_LABEL.size, caps = true } = {}) {
const mono = typeof fontBold === "string" && /mono/i.test(fontBold);
const fira = !fontBold || /fira ?sans[-_ ]?bold/i.test(String(fontBold).split("/").pop() ?? "");
const adv = FIRA_BOLD_ADV.split(",");
+ // As written (TALLY_WRITTEN): the label's own case, and its tighter spacing.
+ const tracking = caps ? TALLY_LABEL.tracking : TALLY_WRITTEN.tracking;
let em = 0;
- const chars = [...String(label ?? "").toUpperCase()];
+ const chars = [...(caps ? String(label ?? "").toUpperCase() : String(label ?? ""))];
for (const ch of chars) {
const i = FIRA_BOLD_CHARS.indexOf(ch);
em += mono ? 0.6 : fira && i >= 0 ? Number(adv[i]) / 1000 : 1.02;
- em += TALLY_LABEL.tracking;
+ em += tracking;
}
return Math.ceil(em * size * 1.02);
}
@@ -169,12 +185,13 @@ export function tallyLabelWidth(label, { fontBold = null, size = TALLY_LABEL.siz
* `tallyLabel`, else its `label` when that fits the cell, else the longest run
* of the label's LAST words that does ("Huck's Blend pitches" → "pitches"),
* else null (validateFactcheck refuses it). The finale and the stamp keep
- * their own words.
+ * their own words. `width` is the label's room (TALLY_LABEL's, or a dense
+ * row's: tallyLabelRoom).
*
* @returns {string|null}
*/
-export function tallyLabelOf(v, { fontBold = null } = {}) {
- const fits = (s) => tallyLabelWidth(s, { fontBold }) <= TALLY_LABEL.width;
+export function tallyLabelOf(v, { fontBold = null, width = TALLY_LABEL.width } = {}) {
+ const fits = (s) => tallyLabelWidth(s, { fontBold }) <= width;
if (typeof v?.tallyLabel === "string" && v.tallyLabel.trim()) return fits(v.tallyLabel.trim()) ? v.tallyLabel.trim() : null;
const label = String(v?.label ?? "");
if (fits(label)) return label;
@@ -187,21 +204,74 @@ export function tallyLabelOf(v, { fontBold = null } = {}) {
}
/**
+ * A label AS WRITTEN in its lines (TALLY_WRITTEN): its words filled into lines
+ * of at most `width` px, at most two; null when a word alone is wider or it
+ * needs a third line. Its own case, never cut.
+ *
+ * @returns {string[]|null}
+ */
+export function writtenLabelLines(label, { fontBold = null, width = TALLY_LABEL.width } = {}) {
+ const words = String(label ?? "").trim().split(/\s+/).filter(Boolean);
+ if (!words.length) return null;
+ const fits = (x) => tallyLabelWidth(x, { fontBold, size: TALLY_WRITTEN.size, caps: false }) <= width;
+ const lines = [];
+ for (const w of words) {
+ if (!fits(w)) return null;
+ const last = lines.length ? `${lines[lines.length - 1]} ${w}` : null;
+ if (last !== null && fits(last)) lines[lines.length - 1] = last;
+ else lines.push(w);
+ }
+ return lines.length <= TALLY_WRITTEN.lines ? lines : null;
+}
+
+/**
+ * The lines a counter's cell shows for series `v` (`{ label, tallyLabel? }`):
+ * as written (`labels: "as-written"`), its `tallyLabel` else its label in up to
+ * two lines; else the one line tallyLabelOf picks, capitalised by the page.
+ * `n` is how many cells the row holds (a dense row's are narrower). null: no
+ * words of it fit.
+ *
+ * @param {{ label?: string, tallyLabel?: string }} v
+ * @param {{ fontBold?: string | null, n?: number, labels?: string }} [opts]
+ * @returns {string[]|null}
+ */
+export function tallyLabelLines(v, { fontBold = null, n = 1, labels = "caps" } = {}) {
+ const width = tallyLabelRoom(n);
+ if (labels === "as-written") {
+ const words = typeof v?.tallyLabel === "string" && v.tallyLabel.trim() ? v.tallyLabel : v?.label;
+ return writtenLabelLines(words, { fontBold, width });
+ }
+ const one = tallyLabelOf(v, { fontBold, width });
+ return one === null ? null : [one];
+}
+
+/**
* Why a counter series' words do not fit its tally cell (`deck.counter`,
* counter.mjs), as the verdicts' are held: its `tallyLabel` must fit, else
- * its label or a run of its last words must. null when they fit.
+ * its label or a run of its last words must -- in the cell a row of `n` gives
+ * it (design.mjs counterCell). As written (`labels: "as-written"`), its
+ * tallyLabel or label must fill at most two lines, no word wider than the
+ * cell. null when they fit.
*/
-export function counterLabelProblem(s, w, { fontBold = null } = {}) {
+export function counterLabelProblem(s, w, { fontBold = null, n = 1, labels = "caps" } = {}) {
const label = s.label ?? VERDICT_DEFAULTS[s.id]?.label ?? s.id;
+ const room = tallyLabelRoom(n);
+ const cells = room !== TALLY_LABEL.width ? ` (${n} cells in the row)` : "";
+ if (labels === "as-written") {
+ const key = typeof s.tallyLabel === "string" ? "tallyLabel" : "label";
+ const words = key === "tallyLabel" ? s.tallyLabel : label;
+ if (writtenLabelLines(words, { fontBold, width: room }) !== null) return null;
+ return `${w}.${key} "${String(words).trim()}" does not fit the tally's cell${cells} in two lines of ${room} px: set ${w}.tallyLabel to fewer or shorter words`;
+ }
if (typeof s.tallyLabel === "string") {
const px = tallyLabelWidth(s.tallyLabel.trim(), { fontBold });
- return px > TALLY_LABEL.width
- ? `${w}.tallyLabel "${s.tallyLabel.trim()}" is ${px} px wide in the tally's cell, which has ${TALLY_LABEL.width} px: shorten it`
+ return px > room
+ ? `${w}.tallyLabel "${s.tallyLabel.trim()}" is ${px} px wide in the tally's cell${cells}, which has ${room} px: shorten it`
: null;
}
- if (tallyLabelOf({ label }, { fontBold }) !== null) return null;
+ if (tallyLabelOf({ label }, { fontBold, width: room }) !== null) return null;
const px = tallyLabelWidth(label, { fontBold });
- return `${w}.label "${String(label).trim()}" is ${px} px wide in the tally's cell, which has ${TALLY_LABEL.width} px, and no run of its last words fits: set ${w}.tallyLabel to a shorter word`;
+ return `${w}.label "${String(label).trim()}" is ${px} px wide in the tally's cell${cells}, which has ${room} px, and no run of its last words fits: set ${w}.tallyLabel to a shorter word`;
}
/**
diff --git a/umtool/report-to-video/modules/counter.mjs b/umtool/report-to-video/modules/counter.mjs
@@ -3,7 +3,7 @@
// a mark's stamp lands (report-to-video counter.mjs; factcheck.mjs
// `tallyCues`; chrome-deck.mjs draws the cells). The finale reads its totals
// (`counter.totals`); the claim checks name its series.
-import { COUNTER_POSITIONS, COUNTER_SHAPES, COUNTER_SHOW_AT, resolveCounter } from "../counter.mjs";
+import { COUNTER_LABELS, COUNTER_POSITIONS, COUNTER_SHAPES, COUNTER_SHOW_AT, resolveCounter } from "../counter.mjs";
import { settingsOf } from "./settings.mjs";
import { defineModule } from "./contract.mjs";
@@ -17,7 +17,7 @@ export default defineModule({
title: "Counter",
summary: "A running tally of named series in the deck, each cell stepping as a mark's stamp lands.",
configKey: "render.chrome.deck.counter",
- defaults: { series: [], show: true, position: "right", showAt: "always" },
+ defaults: { series: [], show: true, position: "right", showAt: "always", labels: "caps" },
validate: settingsOf("counter").validate,
resolve: resolveCounter,
provides: ["counter.totals", "counter.series"],
@@ -35,12 +35,14 @@ export default defineModule({
{ key: "show", type: "boolean", label: "Show the cells", default: true },
{ key: "position", type: "enum", options: COUNTER_POSITIONS, label: "Side", default: "right" },
{ key: "showAt", type: "enum", options: COUNTER_SHOW_AT, label: "Cells appear", default: "always" },
+ { key: "labels", type: "enum", options: COUNTER_LABELS, label: "Cell words", default: "caps" },
],
docs: {
heading: "Counter",
intro: "The deck's tally as named series (`render.chrome.deck.counter`). A clip's mark names the series it counts (`claim.verdict`, or its alias `claim.counter`); a deck claim's `tally` names one by id or label. Without `counter` the series are the fact-check verdicts with `factcheck.verdicts`' relabels and `factcheck.tally`'s settings, as ever; `umtool migrate <p>` writes those as a `counter` (the render is the same) and the two are not set together.",
rows: [
- ["`deck.counter.series[]`", "1–8 `{id, label, color?, stampLabel?, tallyLabel?, showAt?, shape?, unit?}` -- an `id` a letter then letters, digits, `_` `-`; a verdict's id (`CORROBORATED` …) takes its default label, colour and shape; `label` ≤ 24 and fitting the cell, as the verdicts' are", "`umtool look <p> deck.counter='{\"series\":[{\"id\":\"seizures\",\"label\":\"Seizures\",\"color\":\"#e5534b\",\"stampLabel\":\"Seizure\"}]}'`"],
+ ["`deck.counter.series[]`", "1–12 `{id, label, color?, stampLabel?, tallyLabel?, showAt?, shape?, unit?}` -- an `id` a letter then letters, digits, `_` `-`; a verdict's id (`CORROBORATED` …) takes its default label, colour and shape; `label` ≤ 24 (≤ 32 as written) and fitting the cell, as the verdicts' are. Up to 8 the cells are 124 px; past 8 they narrow into one row of 1040 px (9 → 108 px, 10 → 96, 12 → 79), so the title keeps a column of about 520 px, and a label must fit the narrower cell (refused by name, never cut)", "`umtool look <p> deck.counter='{\"series\":[{\"id\":\"seizures\",\"label\":\"Seizures\",\"color\":\"#e5534b\",\"stampLabel\":\"Seizure\"}]}'`"],
+ ["`deck.counter.labels`", "`caps` `as-written` · default `caps`: each cell's word capitalised on one line (its `tallyLabel`, else its label or the last words of it that fit). `as-written`: the label in its own case (\"close to MAGA\"), letter-spaced 0.02 em, broken between words into at most two lines, never cut to its last words -- a word wider than the cell, or a third line, is refused by name", "`umtool look <p> deck.counter.labels=as-written`"],
["`deck.counter.series[].shape`", "`circle` `diamond` `square` `triangle` `ring` · default by place (a verdict's own)", "same"],
["`deck.counter.series[].unit`", "≤ 24 · the noun a count claim's number reads (default its label, lower-cased)", "same"],
["`deck.counter.show`, `.position`, `.showAt`", "bool · `right` `left` · `always` `first` (a series' own `showAt` wins) · defaults `true`, `right`, `always`. A series that SAYS `always` (its own `showAt`, else the counter's) is a cell from the first frame, dim at 0, whether or not a mark ever counts it (\"Left 0\"); one with no `showAt` said, or `first`, is a cell once it is counted, so one never counted is not drawn. The cells show once the cut counts anything", "same"],
diff --git a/umtool/report-to-video/modules/counter.test.mjs b/umtool/report-to-video/modules/counter.test.mjs
@@ -5,9 +5,11 @@ import assert from "node:assert/strict";
import { counterOrder, resolveCounter, validateCounter, VERDICT_SHAPES } from "../counter.mjs";
import {
- claimOf, marksOf, normalizeClaim, resolveFactcheck, tallyAlways, tallyCells, tallyCellsFrom, tallyCues, tallyFinals, tallyOf, tallyShowAt, validateClaims,
+ claimOf, counterLabelProblem, marksOf, normalizeClaim, resolveFactcheck, tallyAlways, tallyCells, tallyCellsFrom, tallyCues, tallyFinals, tallyLabelLines,
+ tallyOf, tallyShowAt, validateClaims, writtenLabelLines,
} from "../factcheck.mjs";
-import { estimateSchedule, validateChrome } from "../deck.mjs";
+import { deckLayout, estimateSchedule, validateChrome } from "../deck.mjs";
+import { counterCell } from "./design.mjs";
import { deckHtml } from "../chrome-deck.mjs";
import counter from "./counter.mjs";
import { moduleProblems } from "./index.mjs";
@@ -156,6 +158,62 @@ test("a series that says `showAt: always` is drawn at 0 though no mark uses it (
assert.deepEqual(tallyCellsFrom([{ verdict: "c" }], ["a", "b", "c"]), ["c"]);
});
+test("past 8 series the cells narrow into one row (up to 12); as written, a label keeps its case in up to two lines (lane leaflit-labels)", () => {
+ // The cell: 124 px up to 8, then the dense row's share of 1040 px.
+ assert.deepEqual(counterCell(8), { cell: 124, gap: 10, labelPad: 6 });
+ assert.deepEqual(counterCell(9), { cell: 108, gap: 8, labelPad: 6 });
+ assert.deepEqual(counterCell(10), { cell: 96, gap: 8, labelPad: 6 });
+ assert.deepEqual(counterCell(12), { cell: 79, gap: 8, labelPad: 6 });
+ const twelve = Array.from({ length: 12 }, (_, i) => ({ id: `s${i}`, label: `S${i}` }));
+ assert.deepEqual(validateCounter({ series: twelve }), []);
+ assert.match(validateCounter({ series: [...twelve, { id: "s12", label: "S12" }] }).join(), /series holds 13 \(at most 12\)/);
+ assert.match(validateCounter({ series: SERIES, labels: "lower" })[0], /labels must be "caps" or "as-written"/);
+ // Her phrases, as said: two lines in a 10-cell row's 84 px, no word cut, no last-words fallback.
+ assert.deepEqual(writtenLabelLines("slightly more conservative", { width: 84 }), ["slightly more", "conservative"]);
+ assert.deepEqual(writtenLabelLines("close to MAGA", { width: 84 }), ["close to", "MAGA"]);
+ assert.deepEqual(writtenLabelLines("moderate", { width: 84 }), ["moderate"]);
+ assert.equal(writtenLabelLines("a b c d e f g h i j k l m n o p q r s t", { width: 40 }), null, "never a third line");
+ assert.equal(writtenLabelLines("conservatively", { width: 60 }), null, "never inside a word");
+ assert.deepEqual(tallyLabelLines({ label: "moderate center right" }, { n: 10, labels: "as-written" }), ["moderate", "center right"]);
+ // Capitalised (the default), the one line it always was -- in a 9-cell row's narrower room.
+ assert.deepEqual(tallyLabelLines({ label: "Seizures" }, { n: 4 }), ["Seizures"]);
+ assert.deepEqual(tallyLabelLines({ label: "Moderate center right" }, { n: 10 }), ["right"]);
+ // Its fit check, in the row it stands in: a word wider than a 12-cell row's room is refused by name.
+ assert.equal(counterLabelProblem({ id: "a", label: "slightly more conservative" }, "w", { n: 10, labels: "as-written" }), null);
+ assert.match(counterLabelProblem({ id: "a", label: "conservative" }, "w", { n: 12, labels: "as-written" }) ?? "", /does not fit the tally's cell \(12 cells in the row\) in two lines of 67 px/);
+ // Through the deck's validator: 10 phrases as written, a written label to 32 characters, a stamp word still 24.
+ const PHRASES = ["moderate", "moderate conservative", "centrist", "moderate right", "centered conservative", "slightly more conservative", "moderate center right", "socially moderate", "conservative", "close to MAGA"];
+ const series = PHRASES.map((label, i) => ({ id: `p${i}`, label }));
+ const asWritten = render({ counter: { series, labels: "as-written" } });
+ assert.deepEqual(validateChrome(asWritten.chrome, asWritten), []);
+ const capped = render({ counter: { series } });
+ assert.match(validateChrome(capped.chrome, capped).join("\n"), /series\[5\]\.label is 26 characters \(at most 24\)/);
+ const stampy = render({ counter: { series: [{ id: "a", label: "slightly more conservative", stampLabel: "slightly more conservative" }], labels: "as-written" } });
+ assert.match(validateChrome(stampy.chrome, stampy).join("\n"), /stampLabel is 26 characters \(at most 24\)/);
+ // The deck: one row of 10 narrower cells, each label as written in its lines, the count over them.
+ const manifest = {
+ provenance: {}, posts: [], render: asWritten,
+ timeline: series.map((x, i) => ({ type: "clip", id: `c${i}`, video: `v${i}`, start: 0, end: 5, claim: { id: `k${i}`, verdict: x.id } })),
+ };
+ assert.deepEqual(validateClaims(manifest), []);
+ const s = estimateSchedule(manifest);
+ const lay = deckLayout(asWritten, { tally: tallyOf(s, asWritten), schedule: s });
+ assert.equal(lay.tally?.cell, 96);
+ assert.equal(lay.tally?.width, 10 * 96 + 9 * 8);
+ assert.ok((lay.text.width ?? 0) > 500, `the title keeps a column (${lay.text.width} px)`);
+ const html = deckHtml(s, asWritten, {});
+ assert.match(html, /<div class="tlabel">slightly more<br>conservative<\/div>/);
+ assert.match(html, /<div class="tlabel">close to<br>MAGA<\/div>/);
+ assert.match(html, /<div class="tlabel">moderate<\/div>/);
+ assert.match(html, /letter-spacing: 0\.02em; text-transform: none;/);
+ // Capitalised up to 8 series: the page it always was.
+ const four = render({ counter: { series: SERIES } });
+ const s4 = estimateSchedule({ ...manifest, render: four, timeline: [{ type: "clip", id: "a", video: "v", start: 0, end: 5, claim: { id: "k", verdict: "seizures" } }] });
+ const h4 = deckHtml(s4, four, {});
+ assert.match(h4, /letter-spacing: 0\.08em; text-transform: uppercase;/);
+ assert.match(h4, /<div class="tlabel">Seizures<\/div>/);
+});
+
test("the counter module: its home, its validator, its docs", () => {
assert.equal(counter.kind, "part");
assert.equal(counter.host, "shell");
diff --git a/umtool/report-to-video/modules/design.mjs b/umtool/report-to-video/modules/design.mjs
@@ -21,5 +21,21 @@ export const DECK_PAD_X = 48;
*/
export const COUNTER_CELL = Object.freeze({ cell: 124, gap: 10, labelPad: 6 });
+/**
+ * THE DENSE COUNTER (lane leaflit-labels): past 8 series (up to 12, counter.mjs
+ * COUNTER_LIMITS) the cells share `budget` px -- the room 8 cells took less a
+ * cell, so the deck's title keeps a column -- `gap` apart. 9 cells are 99 px,
+ * 12 are 72; a label that does not fit its narrower cell is refused by the
+ * counter's fit check, never cut.
+ */
+export const COUNTER_DENSE = Object.freeze({ budget: 1040, gap: 8, from: 9 });
+
+/** The counter's cell for `n` series: COUNTER_CELL's up to 8, else the dense row's. */
+export function counterCell(n) {
+ if (!(n >= COUNTER_DENSE.from)) return { cell: COUNTER_CELL.cell, gap: COUNTER_CELL.gap, labelPad: COUNTER_CELL.labelPad };
+ const { budget, gap } = COUNTER_DENSE;
+ return { cell: Math.floor((budget - gap * (n - 1)) / n), gap, labelPad: COUNTER_CELL.labelPad };
+}
+
/** A design-unit length at this render's width (what the scaled geometry multiplies by). */
export const designScale = (render) => (render?.width ?? DESIGN.width) / DESIGN.width;
diff --git a/umtool/report-to-video/modules/settings.mjs b/umtool/report-to-video/modules/settings.mjs
@@ -476,7 +476,7 @@ export const SETTINGS = Object.freeze([
validate: (v, { where }) => validateMeasureSettings(v, `${where}.measure`) },
{ id: "counter", key: "deck.counter", configKey: "render.chrome.deck.counter", deck: true,
validate: (v, { chrome, render }) => validateCounter(v, {
- factcheck: chrome.factcheck, labelFits: (s, where) => counterLabelProblem(s, where, { fontBold: render.fontBold ?? null }),
+ factcheck: chrome.factcheck, labelFits: (s, where, fit) => counterLabelProblem(s, where, { fontBold: render.fontBold ?? null, ...fit }),
}) },
{ id: "shell", key: "deck", configKey: "render.chrome.deck", deck: true, whole: true, validate: validateShellSettings },
{ id: "rail", key: "deck", configKey: "render.chrome.deck.pip", deck: true, whole: true, validate: validateRailSettings },