Archilyzer · Source

archilyzer

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

commit 833bfa33179f08466a8a57c7168f63758aae5ce7
parent 66ea851dd573ce573fcdd879d3a528b8bb348454
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri,  6 Nov 2026 20:17:45 -0500

Merge lane/shelf-overlap: the diet tags fan sideways like the goal stack (own colours, a running day count on the front tag); the goals on the shelf (headline goal in front when the measure state names one); the finale draws every diet on record with each weight at the day it applied, the peak and the low marked (operator, 6 Nov: "overlap the cards like the goals do but to the side", "a detailed variant of that timeline could be good as a finale render", "a timeline plotting every statement on the date it applied")

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

Diffstat:
Mumtool/docs/knobs.md | 21++++++++++++++++++---
Mumtool/e2e/play-measure.spec.ts | 48++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/serve.mjs | 2+-
Mumtool/report-to-video/chrome-measure-extras.mjs | 248+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Aumtool/report-to-video/chrome-runs-finale.mjs | 298+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/deck.mjs | 10++++++++--
Aumtool/report-to-video/diet-record.mjs | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/finale.mjs | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/measure-extras.mjs | 91++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mumtool/report-to-video/measure-slice.mjs | 6++++++
Mumtool/report-to-video/modules/diet.mjs | 6+++++-
Mumtool/report-to-video/modules/finale.mjs | 3++-
Mumtool/report-to-video/modules/goals.mjs | 1+
Mumtool/report-to-video/modules/index.mjs | 3++-
Mumtool/report-to-video/modules/measure-extras-settings.mjs | 32++++++++++++++++++++++++++++++--
Mumtool/report-to-video/modules/registry.test.mjs | 4++--
Aumtool/report-to-video/modules/runs-finale.mjs | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/shelf.mjs | 2+-
Aumtool/report-to-video/runs-finale.test.mjs | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/shelf.test.mjs | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
20 files changed, 1255 insertions(+), 49 deletions(-)

diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -1530,6 +1530,7 @@ filter. A knob absent is its default, and a module whose knobs are all absent dr | [Flips](#flips) `flips` | Pairs of what was said then and now, in the side panel. (a page over the whole cut) | `render.chrome.flips` | | [Chapters](#chapters) `chapter` | A section bumper over the first seconds of the clip it opens: title, subtitle, date. (pages at their own seconds) | `render.chrome.chapter` | | [Finale](#finale) `finale` | The cut's last clips under the rail redrawn large, the final totals and stats cards. (pages at their own seconds) | `render.chrome.deck.finale` | +| [Diet runs in the finale](#diet-runs-in-the-finale) `runs-finale` | The finale's detailed diet record: every run from the first row a bar in its diet's ink, the empty years a break, the stops and medication marked, his weights over it, the long runs and the open one labelled. (pages at their own seconds) | -- | | [Dial finale](#dial-finale) `dial-finale` | The finale with the dial and the odometer large: the needle drops to his last stated weight, the wheels roll to the total, NET holds. (pages at their own seconds) | -- | | [Promise clock](#promise-clock) `promise` | Days since a promise -- to the clip on screen, then to the render date -- with each check's words and whether it was kept. (a page over the whole cut) | `render.chrome.deck.promise` | @@ -1543,7 +1544,7 @@ it can be seeked. `POST /api/report/chrome/preview` returns every such module th build's predicate) as `layers: [{id, z, region, clock, ready, geometry, src | windows}]`; the client lays them by z over the deck's page, a whole-cut page for the whole cut, a window module's page only inside each window. -Declaring `play`: `stats`, `pair`, `status`, `fx`, `shelf`, `streak`, `diet`, `peak`, `goals`, `threads`, `dial`, `odometer`, `trail`, `flips`, `chapter`, `dial-finale`, `promise`. +Declaring `play`: `stats`, `pair`, `status`, `fx`, `shelf`, `streak`, `diet`, `peak`, `goals`, `threads`, `dial`, `odometer`, `trail`, `flips`, `chapter`, `runs-finale`, `dial-finale`, `promise`. Still drawn by their own paths (the response's `src`, `feed`, `posts`, `stamp` and `finale` keys), and what moving each onto `play` needs: the deck (`shell`) -- its typed words patched in live (`deck:text`) and the `deck:ready` @@ -1750,7 +1751,7 @@ Overlays on the picture -- receipts, a zoom, the scrubber, a kinetic quote, punc ### Shelf -A strip of the frame cleared beside the footage (`render.chrome.deck.shelf`, shelf-settings.mjs): the footage moves to the frame's top, `railGap` (24 px) in (`side: "below"`), or down onto the deck (`"above"`), and what it leaves -- as wide as the footage, 24 px clear of it and of the frame's edge or the deck -- is the shelf (beside the instruments' column, 1248×116 at (24, 750)). Everything that reads the footage box (the instruments, the posts, the chapter band, the finale, Play) follows it. Its occupants stand in it left to right in `items` order, `gap` apart, each at its own width scaled to the shelf's height (all a size down together when they would not fit): the measure extras that take `position: "shelf"` -- `diet` (its dated tags by default: `deck.diet.form`), `streak`, `goals`, `peak` -- and `note`, an entry's `shelfNote` in the width left (a chip that comes and goes with its entry; at least 160 px). Nothing covers the shelf, so its occupants never dodge a post card or a chapter band (an entry's `hideModules` still hides one). It needs 72 px of room or the deck refuses, naming the way out (a smaller `footageScale`, or `subtitle.lines 1`): with the instruments' column it is 116 px, 77 with `subtitle.lines: 2`; full-width footage at the default 0.82 leaves none. Off (absent, `false`), the footage stands where it always did. +A strip of the frame cleared beside the footage (`render.chrome.deck.shelf`, shelf-settings.mjs): the footage moves to the frame's top, `railGap` (24 px) in (`side: "below"`), or down onto the deck (`"above"`), and what it leaves -- as wide as the footage, 24 px clear of it and of the frame's edge or the deck -- is the shelf (beside the instruments' column, 1248×116 at (24, 750)). Everything that reads the footage box (the instruments, the posts, the chapter band, the finale, Play) follows it. Its occupants stand in it left to right in `items` order, `gap` apart, each at its own width scaled to the shelf's height (all a size down together when they would not fit; a goal stack on it takes the width left over, its notes fanning wider, so the shelf does not end in a gap): the measure extras that take `position: "shelf"` -- `diet` (its dated tags by default: `deck.diet.form`), `streak`, `goals`, `peak` -- and `note`, an entry's `shelfNote` in the width left (a chip that comes and goes with its entry; at least 160 px). Nothing covers the shelf, so its occupants never dodge a post card or a chapter band (an entry's `hideModules` still hides one). It needs 72 px of room or the deck refuses, naming the way out (a smaller `footageScale`, or `subtitle.lines 1`): with the instruments' column it is 116 px, 77 with `subtitle.lines: 2`; full-width footage at the default 0.82 leaves none. Off (absent, `false`), the footage stands where it always did. | Knob | Range · default | From a terminal | |---|---|---| @@ -1785,6 +1786,8 @@ The diet he names as a rubber stamp in a corner of the footage box (`render.chro | `deck.diet.position`, `.x`/`.y`, `.scale` | an anchor in the footage box · design px · 0.5–2 · default `bottom-left`, unset, 1 | `umtool look <p> deck.diet.position=top-right` | | `deck.diet.hold`, `.finale` | 0 (up from the first diet on) or 2–600 s · `hide` `show` · default 0, `hide` | `umtool look <p> deck.diet.hold=15` | | `deck.diet.form`, `.tags` | `stamp` · `tags`: the last `tags` diets as a row of dated tags -- each a small stamp with the regime's word in its ink, "DIET #n" and the ledger's words (less the regime they open with: "5 carbs a day"), and the day he switched to it (`state.diet.since`, "Mar 14, 2025"; new words for the same diet keep that day); at each change the new tag slams in at the left, the older slide right and dim, the one past `tags` falls off; a change of words alone fades the new tag over the old; a null diet is a grey "NO DIET" tag with its date · 1–4 · default `stamp` (`tags` on the shelf), 3 | `umtool look <p> deck.diet.form=tags deck.diet.tags=2` | +| `deck.diet.overlap` | 0–0.8, the share of each older tag hidden behind the one in front · default 0 (side by side, the slam and the dim). Above 0 the tags FAN sideways the way the goal stack's notes pile: the newest in front at the left, landing from above like a goal note, each older one a place to the right behind it with its own small turn, keeping its colours (the depth is the overlap and the shadow), showing its regime word and date in the strip beside the one in front; the one past `tags` slides off the back. The fan is narrower by what hides. An older tag's word and date need 110 design px of it, so it is refused past 0.5 (0.63 with `days`) | `umtool look <p> deck.diet.overlap=0.5` | +| `deck.diet.days` | `true` · `false`: the front tag's running count of days on its diet (to the in-record date at the playhead, the streak chain's "Day N"), in a column of its own -- the tag 300 design px wide · default `false` | `umtool look <p> deck.diet.days=true` | | `deck.diet.colors`, `.labels` | `{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names | `umtool look <p> deck.diet.labels='{"glp1":"Ozempic"}'` | | `deck.diet.onPosts`, `.onChapters` | `dodge` `hide` `show` · default `dodge`: while a post item's card (its card, slot and strip as postLayout lays them: the schedule's `covers`) or a chapter band is up where it stands, it moves to a free anchor of the footage box -- a size down to half if it must, never onto another measure extra that is up -- and hides when none fits; `hide` hides, `show` stays over it | `umtool look <p> deck.diet.onPosts=hide` | | `deck.diet.position=shelf` | in its own slot on the shelf (`deck.shelf`: under or over the footage), scaled to the shelf's height, left to right in `deck.shelf.items` order -- nothing covers it there, so it never dodges (`onPosts`, `onChapters`, `x`/`y`, `scale` and `avoid` do not apply), and it is over the finale as the shelf is (`deck.shelf.finale`) | `umtool look <p> deck.shelf=true deck.diet.position=shelf` | @@ -1812,6 +1815,7 @@ A sticky note per goal on a pile in a corner of the footage box, read off the sc |---|---|---| | `deck.goals` | `true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice | `umtool look <p> deck.goals=false` | | `deck.goals.position`, `.x`/`.y`, `.scale` | `top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1 | `umtool look <p> deck.goals.position=bottom-left` | +| `deck.goals.position=shelf` | its shelf form (`deck.shelf`): the count of goals set in a column, then the notes fanned sideways like the diet's tags -- the headline goal in front when the measure state names one (`goals.headline`: the closest goal in force) with "+N more" for the others in force, else the newest; a new goal landing from above as on the pile; each older one showing its goal's words in the strip beside it (all of each when there is room); a repeat comes to the front with its ×n. The fan takes the shelf's spare width (shelfLayout), up to its notes side by side. On the shelf it stays up from the first goal (`hold` unset). What the dial draws of the goal stays on the dial | `umtool look <p> deck.shelf.items='["diet","goals"]' deck.goals.position=shelf` | | `deck.goals.max`, `.color`, `.countdown` | 1–8 notes · #hex paper · bool · default 4, the palette's amber, `true` | `umtool look <p> deck.goals.max=6` | | `deck.goals.hold`, `.finale` | 0 (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide` | `umtool look <p> deck.goals.hold=0` | | `deck.goals.onPosts`, `.onChapters` | `dodge` `hide` `show` · default `dodge`: while a post item's card (its card, slot and strip as postLayout lays them: the schedule's `covers`) or a chapter band is up where it stands, it moves to a free anchor of the footage box -- a size down to half if it must, never onto another measure extra that is up -- and hides when none fits; `hide` hides, `show` stays over it | `umtool look <p> deck.goals.onPosts=hide` | @@ -1889,9 +1893,20 @@ The full reference is [The finale](#the-finale-the-timeline-in-primary-view). It | Knob | Range · default | From a terminal | |---|---|---| -| `deck.finale` | `{video, motion, totals, stats, statsTitle, railLabels, pips, timelineShare, claims}` | `umtool look <p> deck.finale='{…}'` | +| `deck.finale` | `{video, motion, totals, stats, statsTitle, railLabels, pips, timelineShare, claims, dietRuns}` -- `dietRuns`: the whole diet record under the rail ([Diet runs in the finale](#diet-runs-in-the-finale)) | `umtool look <p> deck.finale='{…}'` | | a clip's `layout` | `finale` on one run of clips at the end | `umtool set <p> <clip> layout=finale` | +### Diet runs in the finale + +With `deck.finale.dietRuns: true` (and a measure ledger with a regime track), the finale's timeline panel -- under the large rail's track, the rail's width, down to the panel's foot: with the weight layer (120, 202) 1704×220 at 1080p, the track staying where its labels put it and the timeline taking the room under it (up to `FINALE_SHARE.max`); without it 1704×122 -- carries the WHOLE record of his diets (the measure slice's `record`, diet-record.mjs: every regime row in scope, on camera or not, through the state's own rule): each run a bar in its diet's ink on a time axis from the earliest row; a stretch of more than two years with nothing on record squeezed to a marked break ("2013–2018"), and a run whose end the record does not have fading into it; a row that stopped a diet a grey tick under the bars, one naming the medication (GLP-1) a purple one; his stated weights a light line over the bars, the weights the video marks (`marks`: his heaviest as THE peak) and his low as labelled dots on it; the run still going and the longest ones labelled in two rows under the bars where they fit -- the diet's word (the run's own name when its row gives one: "WEIGHT WATCHERS"), its number when the cut showed it ("DIET #6", the shelf's), its dates and its days, the open one "N days and counting" to the in-record date. It sweeps in left to right over 2.6 s after the finale's grow, each label as the sweep reaches it, then holds; it stands clear of the side video, the lower column's instruments and the promise clock. It needs `deck.finale.railLabels` `sections` or `none` (the pips' labels and dates use that space) and at least 100 px under the rail. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `deck.finale.dietRuns` | `true` · `false` · `{weights, marks, low}` · default `false` | `umtool look <p> deck.finale.dietRuns=true` | +| `deck.finale.dietRuns.weights` | `applied` · `said` · `false` · default `applied`: the WEIGHT LAYER over the bars on the dial's scale (the panel 218 design px, the finale's timeline taking that room under the track) -- every weight he gave (a `current` or `past` row with a number) at the day it APPLIED (its asOf, else its date; `said`: the day he said it). Given at the time: solid, joined -- his claimed trajectory (a bound like "over 240" is a point, not joined). Told 30 days or more after it applied: hollow, with a thin leader to a tick at the day he said it, so a retold weight piles up at one period from its tellings. `>`/`<` a caret, `≈` a ring, a range a bar. A loss or gain (`delta`) and "N over" (`overweight_by`) name no weight the ledger resolves: left out (the record counts them, `record.leftOut`). `false`: the light line of his stated weights alone | `umtool look <p> deck.finale.dietRuns='{"weights":"said"}'` | +| `deck.finale.dietRuns.marks` | up to 8 `{row, label, peak?}`: a dot on the weight line at the row's day (its asOf, else its date) and value, the label -- his words, at most 60 characters -- and the month beside it; THE peak (the one marked `peak`, else the heaviest marked) a size up in the needle's red. A row the ledger lacks is left out | `umtool look <p> deck.finale.dietRuns='{"marks":[{"row":"w21","label":"his heaviest · \"almost 400\""}]}'` | +| `deck.finale.dietRuns.low` | `true` · `false` · its label · default `true`: the lowest weight he stated (never a bound like "over 240"; of one weigh-in told twice the same day, the fuller: 291.5 over "291.") marked in the accent, "his low · 291.5" | `umtool look <p> deck.finale.dietRuns='{"low":false}'` | + ### Dial finale With the dial on (`deck.dial`) and a finale (a run of `layout: "finale"` clips), the finale's lower column -- beside the clip, under the finale's totals when it draws them -- carries the instruments large over the finale's window: in over the finale's grow, the needle dropping (1.8 s, `back.out`) from his highest remembered weight (the measure's `totals.peakDrift` and remembered weights) to his last stated one (`totals.net.to`), every ghost tick and the latest goal on the bezel; the odometer rolling up from zero to the whole record's `totals.lost` (the rows the cut never shows included) with `ACROSS N RUNS`; NET (`totals.net`) held beside it; out through the finale's dissolve. Laid over the finale (z 95), in Play too. It needs the lower column clear: a finale with stats cards (`deck.finale.stats`) is refused -- set `deck.dial.finale` false, or drop the cards. diff --git a/umtool/e2e/play-measure.spec.ts b/umtool/e2e/play-measure.spec.ts @@ -150,3 +150,51 @@ test("on the shelf: the footage at the frame's top, the diet's dated tags and th await put(before); } }); + +test("the fan: the diet's tags overlapped with the day count on the front one, the goals' fan beside them on the shelf", async ({ page, request }) => { + await page.setViewportSize({ width: 1366, height: 1000 }); + const enc = encodeURIComponent; + const read = async () => (await (await request.get(`/api/report/chrome?project=${enc(PROJECT)}`)).json()) as { chrome: Record<string, any>; token: string }; + const put = async (chrome: unknown) => { + const { token } = await read(); + const r = await request.put("/api/report/chrome", { data: { project: PROJECT, chrome, token } }); + expect(r.ok(), await r.text()).toBeTruthy(); + }; + const before = (await read()).chrome; + const deck = before.deck ?? {}; + try { + await put({ + ...before, + deck: { + ...deck, shelf: { items: ["diet", "goals"] }, streak: false, + diet: { ...(deck.diet ?? {}), position: "shelf", overlap: 0.6, days: true }, + goals: { ...(deck.goals ?? {}), position: "shelf" }, + }, + }); + await page.goto(urls.playHref(PROJECT, { clip: "c04", at: 1 })); + await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); + for (const id of ["diet", "goals"]) { + await expect(page.getByTestId(`play-layer-${id}`)).toHaveAttribute("data-feed-ready", "1", { timeout: 30_000 }); + expect(await page.getByTestId(`play-layer-${id}`).evaluate((el) => parseFloat((el as HTMLElement).style.top))).toBeCloseTo((750 / 1080) * 100, 1); + } + await expect(page.locator('[data-play-layer="streak"]')).toHaveCount(0); + const diet = page.frameLocator('[data-testid="play-layer-diet-iframe"]').locator("#pn"); + // The front tag (carnivore, c03) with its running day count; keto behind it, still carnivore-free of a dim. + await expect.poll(() => diet.evaluate((pn) => { + const on = [...pn.querySelectorAll<HTMLElement>(".tg")].filter((e) => getComputedStyle(e).visibility !== "hidden" && Number(getComputedStyle(e).opacity) > 0.5) + .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left); + return on.map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 9)); + }), { timeout: 10_000 }).toEqual([expect.stringContaining("Carnivore"), expect.stringContaining("Keto")]); + const days = await diet.evaluate((pn) => [...pn.querySelectorAll<HTMLElement>(".dy")].filter((e) => getComputedStyle(e).visibility !== "hidden").map((e) => (e.textContent ?? "").trim())); + expect(days).toHaveLength(1); + expect(days[0]).toMatch(/^\d+days?$/); + const goals = page.frameLocator('[data-testid="play-layer-goals-iframe"]').locator("#pn"); + await expect.poll(() => goals.evaluate((pn) => { + const st = [...pn.querySelectorAll<HTMLElement>(".st")].find((e) => getComputedStyle(e).visibility !== "hidden"); + return st ? (st.querySelector(".gc")?.textContent ?? "").replace(/\s+/g, " ").trim() : null; + }), { timeout: 10_000 }).toBe("3goals set"); + await page.screenshot({ path: test.info().outputPath("play-measure-fan.png") }); + } finally { + await put(before); + } +}); diff --git a/umtool/lib/report/serve.mjs b/umtool/lib/report/serve.mjs @@ -982,7 +982,7 @@ export function previewDirFor(projectDir, variant, rest, segmentIds) { // (Every module that declares `play` must be here, or Play's iframe of its page is a 404: the measure // extras and the instruments too -- the dial's finale is a window its module names `dial-finale-preview`, // never confused with the dial's `dial-preview-<segment>`.) -export const LAYER_REGIONS = Object.freeze(["pair", "status", "chapter", "stats", "threads", "flips", "fx", "shelf", "diet", "peak", "goals", "promise", "streak", "dial", "odometer", "trail", "dial-finale"]); +export const LAYER_REGIONS = Object.freeze(["pair", "status", "chapter", "stats", "threads", "flips", "fx", "shelf", "diet", "peak", "goals", "promise", "streak", "dial", "odometer", "trail", "dial-finale", "runs-finale"]); /** The project name a layer preview is served under, or null when `head` is not one. */ export function layerPreviewOf(head, segmentIds = []) { diff --git a/umtool/report-to-video/chrome-measure-extras.mjs b/umtool/report-to-video/chrome-measure-extras.mjs @@ -16,10 +16,10 @@ import { formatDeckDate } from "./attribution.mjs"; import { rgba } from "./chrome-deck.mjs"; import { compileCues, cuePageHtml, esc, INSTANT, joinSpans, r4, spanEvents } from "./chrome-cues.mjs"; import { - daysBetween, daysLeftText, daysText, DIET_TAG, dietStates, goalStates, measureBox, measureExtraGeometry, measureOf, MEASURE_BOXES, promiseStripRect, promiseStripType, + daysBetween, daysLeftText, daysText, DIET_TAG, dietDays, dietStates, dietTagStep, goalStates, GOALS_SHELF, jitter, measureBox, measureExtraGeometry, measureOf, MEASURE_BOXES, promiseStripRect, promiseStripType, MEASURE_DODGE_MOVE, measurePlacements, monthYear, peakStates, promiseStates, shortDate, streakStates, upSpans, weightText, } from "./measure-extras.mjs"; -import { MEASURE_RED, resolveMeasureExtra } from "./modules/measure-extras-settings.mjs"; +import { dietTagWidth, MEASURE_RED, resolveMeasureExtra, SHELF_POSITION } from "./modules/measure-extras-settings.mjs"; import { dialFinaleGeometry, dialFinaleHandoff } from "./chrome-instruments.mjs"; /** How each module's panel comes in and goes out, s. */ @@ -30,7 +30,10 @@ const feedOf = (schedule) => schedule?.layout === "feed"; /** The page's frame: its region, its pixel scale against its design box, its fps. */ function frameOf(id, schedule, render) { const geo = measureExtraGeometry(id, render, { feed: feedOf(schedule) }); - const k = geo.width / measureBox(id, render).width; + // On the shelf a module is scaled to the shelf's HEIGHT: its slot may be wider than its box (the goals' fan + // takes the width left over) and is never narrower. + const box = measureBox(id, render); + const k = resolveMeasureExtra(id, render)?.position === SHELF_POSITION ? geo.height / box.height : geo.width / box.width; const px = (v) => Math.max(1, Math.round(v * k)); return { geo, k, px, fps: schedule.fps ?? render.fps ?? 30 }; } @@ -191,6 +194,7 @@ export function goalsHtml(schedule, render, opts = {}) { const m = measureOf(schedule); const states = goalStates(schedule, render); if (!cfg || !m || !states.length) throw new Error("goals: the schedule's measure slice has no goal on camera"); + if (cfg.position === SHELF_POSITION) return goalsShelfHtml(schedule, render, opts, cfg, states); const F = frameOf("goals", schedule, render); const { geo, px } = F; const H = geo.height; @@ -268,6 +272,131 @@ export function goalsHtml(schedule, render, opts = {}) { return { html: page("goals", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render), items }; } +/** + * The goal stack ON THE SHELF (`goals.position: "shelf"`): the count of goals + * set in a column at the left, then the notes -- the same paper, tape, shadow + * and ink as the pile in the footage -- fanned sideways like the diet's tags, + * the newest in front landing from above (the pile's own landing), the older + * ones a place to the right behind it, each showing its goal's words in the + * strip beside the one in front (all of each when the slot is wide enough: + * shelfLayout gives the fan the shelf's spare width). A block per state, as the + * pile's: a repeat comes to the front with its count; the number of goals set + * pops at each. + */ +function goalsShelfHtml(schedule, render, opts, cfg, states) { + const F = frameOf("goals", schedule, render); + const { geo, px } = F; + const pal = render.palette; + const paper = cfg.color ?? pal.amber ?? "#E8A33F"; + const G = GOALS_SHELF; + const max = cfg.max ?? 4; + const room = geo.width / F.k - G.count - G.gap - G.card; + const step = max > 1 ? Math.max(G.back, Math.min(G.card + G.step, room / (max - 1))) : 0; + const backs = step < G.card; + const place = (note, depth) => ({ + x: px(G.count + G.gap + depth * step), + y: Math.round(px(6) + note.dx * 0.15 * F.k + (depth ? px(1) : 0)), + rotation: r4(note.rot * 0.45 + (depth ? (depth % 2 ? -1.4 : 1.2) : 0)), + }); + const spans = upSpans(states.map((s) => s.at), cfg, schedule); + const items = []; + // THE ORDER ON THE SHELF: the headline goal in front when the state names one (the closest goal in force, + // goalStates' `headline`), the rest by how recently he set them; else the newest in front, as the pile. + let before = new Map(); + const shelfStates = states.map((st) => { + const recent = [...st.notes].sort((a, b) => a.depth - b.depth); + const lead = st.headline ? recent.find((n) => n.key === st.headline) : null; + const list = lead ? [lead, ...recent.filter((n) => n !== lead)] : recent; + const notes = list.map((n, i) => ({ ...n, depth: i, prev: before.has(n.key) ? before.get(n.key) : null })); + before = new Map(notes.map((n) => [n.key, n.depth])); + return { ...st, notes }; + }); + const { init, cues } = stateCues(shelfStates, spans, { + own: (st, j, init) => { + const ev = []; + for (const n of st.notes) { + const k = `s${j}.${n.id}`; + const to = place(n, n.depth); + if (n.key === st.top) { + // The pile's landing: from above, turned, a size up -- onto the fan. + init[k] = { x: to.x - px(30), y: to.y - px(140), rotation: r4(to.rotation + 13), scale: 1.12, opacity: 0 }; + ev.push({ k, at: st.at, dur: 0.42, to: { x: to.x, y: to.y, rotation: to.rotation, scale: 1, opacity: 1 }, ease: "back.out(1.3)" }); + } else if (n.prev !== null && n.prev !== n.depth) { + const from = place(n, n.prev); + init[k] = { x: from.x, y: from.y, rotation: from.rotation }; + ev.push({ k, at: st.at, dur: 0.36, to: { x: to.x, y: to.y, rotation: to.rotation }, ease: "power2.out" }); + // Out of the front: its whole face gives way to the strip that shows beside the new one. + if (backs && n.prev === 0 && n.depth > 0) { + init[`${k}f`] = { opacity: 1 }; + init[`${k}b`] = { opacity: 0 }; + ev.push({ k: `${k}f`, at: st.at, dur: 0.3, to: { opacity: 0 }, ease: "power1.out" }); + ev.push({ k: `${k}b`, at: st.at + 0.1, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + } + } else { + init[k] = { x: to.x, y: to.y, rotation: to.rotation }; + } + } + init[`s${j}.c`] = { scale: 1.6, opacity: 0 }; + ev.push({ k: `s${j}.c`, at: st.at + 0.25, dur: 0.3, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); + return ev; + }, + }); + const blocks = shelfStates.map((st, j) => { + const notes = st.notes.map((n) => { + const k = `s${j}.${n.id}`; + const dl = cfg.countdown && n.deadline + ? `<div class="dl">${esc(n.deadline)}${n.days !== null ? ` · ${esc(daysLeftText(n.days))}` : ""}${n.target !== null ? ` · needs ${esc(weightText(n.target))}` : ""}</div>` + : ""; + const count = n.count > 1 ? `<div class="ct">×${n.count}</div>` : ""; + // The ladder: how many more goals are in force beside the headline one, when the state says. + const more = n.depth === 0 && st.headline && Number.isFinite(st.active) && st.active > 1 ? `<div class="mo">+${st.active - 1} more</div>` : ""; + const front = n.depth === 0 || !backs; + const crossing = backs && n.prev === 0 && n.depth > 0; + const face = `<div class="nf"${crossing ? ` data-k="${k}f"` : ""} style="opacity:${front || crossing ? 1 : 0}"><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${dl}</div>`; + const back = backs && n.depth > 0 + ? `<div class="nb"${crossing ? ` data-k="${k}b"` : ""} style="opacity:${crossing ? 0 : 1}"><div class="bt">${esc(n.text)}</div>${n.date ? `<div class="bh">${esc(monthYear(n.date))}</div>` : ""}</div>` + : ""; + return `<div class="note" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div>${face}${back}${count}${more}</div>`; + }).join(""); + const html = `<div class="st" data-k="s${j}"><div class="gc"><div class="gn" data-k="s${j}.c">${st.goalsSet}</div><div class="gl">goal${st.goalsSet === 1 ? "" : "s"} set</div></div>${notes}</div>`; + items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); + return html; + }); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .gc { position: absolute; left: 0; top: 0; width: ${px(G.count)}px; height: ${px(G.height)}px; display: flex; flex-direction: column; + align-items: center; justify-content: center; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.88)}; } + .gn { font-family: ${DISPLAY}; font-size: ${px(46)}px; line-height: ${px(46)}px; color: ${paper}; font-variant-numeric: tabular-nums; } + .gl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(15)}px; letter-spacing: 0.12em; text-transform: uppercase; + color: ${pal.muted}; text-align: center; } + .note { position: absolute; left: 0; top: 0; width: ${px(G.card)}px; height: ${px(G.height - 12)}px; border-radius: ${px(3)}px; color: #2a1c06; + background: linear-gradient(168deg, ${paper} 0%, ${paper} 62%, ${rgba(paper, 0.86)} 100%); + box-shadow: 0 ${px(8)}px ${px(18)}px rgba(0, 0, 0, 0.45), ${px(-4)}px 0 ${px(10)}px rgba(0, 0, 0, 0.3), 0 ${px(1)}px ${px(2)}px rgba(0, 0, 0, 0.3); } + .tape { position: absolute; left: 50%; top: ${px(-6)}px; width: ${px(70)}px; height: ${px(18)}px; margin-left: ${px(-35)}px; + background: rgba(255, 255, 255, 0.38); transform: rotate(-3deg); } + .nf { position: absolute; inset: 0; padding: ${px(8)}px ${px(14)}px; display: flex; flex-direction: column; justify-content: center; gap: ${px(1)}px; overflow: hidden; } + .nb { position: absolute; right: 0; top: 0; bottom: 0; width: ${px(Math.min(step, G.card) - 14)}px; padding: 0 ${px(6)}px; + display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; } + .nh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; letter-spacing: 0.14em; + text-transform: uppercase; color: rgba(42, 28, 6, 0.62); white-space: nowrap; } + .nt { font-family: ${DISPLAY}; font-size: ${px(40)}px; line-height: ${px(44)}px; white-space: nowrap; letter-spacing: 0.01em; } + .dl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; color: #7d150c; white-space: nowrap; + overflow: hidden; text-overflow: ellipsis; } + .bt { font-family: ${DISPLAY}; font-size: ${px(24)}px; line-height: ${px(27)}px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; } + .bh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(15)}px; letter-spacing: 0.1em; text-transform: uppercase; + color: rgba(42, 28, 6, 0.62); white-space: nowrap; } + .mo { position: absolute; right: ${px(8)}px; bottom: ${px(6)}px; padding: 0 ${px(7)}px; height: ${px(20)}px; border-radius: ${px(10)}px; + background: rgba(42, 28, 6, 0.85); color: ${paper}; font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(20)}px; } + .ct { position: absolute; right: ${px(8)}px; top: ${px(5)}px; min-width: ${px(40)}px; height: ${px(24)}px; padding: 0 ${px(7)}px; + border-radius: ${px(12)}px; background: #2a1c06; color: ${paper}; text-align: center; + font-family: ${DISPLAY}; font-size: ${px(19)}px; line-height: ${px(24)}px; }`; + const body = `<div id="pn" data-k="pn"> + ${blocks.join("\n ")} + </div>`; + return { html: page("goals", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render), items }; +} + // --------------------------------------------------------------------------- // PEAK: the moving start. // --------------------------------------------------------------------------- @@ -727,7 +856,18 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { const SLIDE = 0.4; const DIM = 0.45; const n = cfg.tags ?? 3; - const slotX = (i) => px(i * (DIET_TAG.width + DIET_TAG.gap)); + const daysOn = cfg.days === true; + const W = dietTagWidth(daysOn); + const overlap = cfg.overlap ?? 0; + // FANNED (`overlap` > 0): the goal stack's look turned on its side -- each tag its own small turn and drop, + // the depth's tilt, the stack's shadow; the newest lands on top from above (the goal note's landing), the + // older ones slide a place right behind it and show their regime word and date in the strip beside it. They + // keep their colours: the depth is the overlap and the shadow. Side by side (0): the row, the slam and the dim. + const fan = overlap > 0; + const step = dietTagStep(overlap, daysOn); + const slotX = (i) => px(i * step); + const rotOf = (id, i) => (fan ? r4(jitter(`diet${id}`) * 1.8 + (i ? (i % 2 ? -1.6 : 1.3) : 0)) : 0); + const yOf = (id, i) => (fan ? Math.round(px(2) + jitter(`diet${id}`, 7) * px(2) + (i ? px(1) : 0)) : 0); const spans = upSpans(states.map((s) => s.at), cfg, schedule); const init = { pn: { autoAlpha: 0 } }; const ev = []; @@ -737,10 +877,11 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { states.forEach((st) => { for (const t of st.tags) if (!tags.has(t.id)) tags.set(t.id, t); }); for (const id of tags.keys()) { const k = `t${id}`; - init[k] = { x: 0, autoAlpha: 0 }; + init[k] = { x: 0, y: yOf(id, 0), rotation: rotOf(id, 0), scale: 1, autoAlpha: 0 }; init[`${k}.d`] = { opacity: 1 }; init[`${k}.w`] = { x: 0 }; - init[`${k}.s`] = { scale: 1, rotation: -3, opacity: 1 }; + init[`${k}.s`] = { scale: 1, rotation: fan ? 0 : -3, opacity: 1 }; + if (fan) { init[`${k}.f`] = { opacity: 1 }; init[`${k}.b`] = { opacity: 0 }; } } states.forEach((st, j) => { const prev = j ? states[j - 1].tags.map((t) => t.id) : []; @@ -749,23 +890,37 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { const front = cur[0]; if (!prev.includes(front)) { const k = `t${front}`; - ev.push({ k, at, dur: INSTANT, to: { x: 0, autoAlpha: 1 }, ease: "none" }); - if (st.slam) { - // The slam: in from big and turned, hard onto the shelf, then a shake. - init[`${k}.s`] = { scale: 2.3, rotation: -15, opacity: 0 }; - ev.push({ k: `${k}.s`, at, dur: SLAM, to: { scale: 1, rotation: -3, opacity: 1 }, ease: "power4.in" }); - [8, -6, 4, -2, 0].map((v) => Math.round(v * F.k)).forEach((x, m) => ev.push({ k: `${k}.w`, at: at + SLAM + m * 0.045, dur: 0.045, to: { x }, ease: "sine.inOut" })); + if (fan && !st.replaced && st.diet) { + // The goal note's landing: from above, turned, a size up -- onto the stack. + init[k] = { x: -px(30), y: yOf(front, 0) - px(140), rotation: r4(rotOf(front, 0) + 13), scale: 1.12, autoAlpha: 0 }; + ev.push({ k, at, dur: 0.42, to: { x: 0, y: yOf(front, 0), rotation: rotOf(front, 0), scale: 1, autoAlpha: 1 }, ease: "back.out(1.3)" }); } else { - init[`${k}.s`] = { scale: 1, rotation: -3, opacity: 0 }; - ev.push({ k: `${k}.s`, at, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + ev.push({ k, at, dur: INSTANT, to: { x: 0, autoAlpha: 1 }, ease: "none" }); + if (st.slam && !fan) { + // The slam: in from big and turned, hard onto the shelf, then a shake. + init[`${k}.s`] = { scale: 2.3, rotation: -15, opacity: 0 }; + ev.push({ k: `${k}.s`, at, dur: SLAM, to: { scale: 1, rotation: -3, opacity: 1 }, ease: "power4.in" }); + [8, -6, 4, -2, 0].map((v) => Math.round(v * F.k)).forEach((x, m) => ev.push({ k: `${k}.w`, at: at + SLAM + m * 0.045, dur: 0.045, to: { x }, ease: "sine.inOut" })); + } else { + init[`${k}.s`] = { scale: 1, rotation: fan ? 0 : -3, opacity: 0 }; + ev.push({ k: `${k}.s`, at, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + } } } - // The older ones a place to the right, dimmed. + // The older ones a place to the right: dimmed in the row; in the fan, behind the new one, its strip showing. cur.forEach((id, i) => { const p = prev.indexOf(id); if (p < 0 || p === i) return; - ev.push({ k: `t${id}`, at, dur: SLIDE, to: { x: slotX(i) }, ease: "power2.inOut" }); - ev.push({ k: `t${id}.d`, at, dur: SLIDE, to: { opacity: i === 0 ? 1 : DIM }, ease: "power1.out" }); + if (fan) { + ev.push({ k: `t${id}`, at, dur: 0.36, to: { x: slotX(i), y: yOf(id, i), rotation: rotOf(id, i) }, ease: "power2.out" }); + if (p === 0) { + ev.push({ k: `t${id}.f`, at, dur: 0.3, to: { opacity: 0 }, ease: "power1.out" }); + ev.push({ k: `t${id}.b`, at: at + 0.1, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + } + } else { + ev.push({ k: `t${id}`, at, dur: SLIDE, to: { x: slotX(i) }, ease: "power2.inOut" }); + ev.push({ k: `t${id}.d`, at, dur: SLIDE, to: { opacity: i === 0 ? 1 : DIM }, ease: "power1.out" }); + } }); // Off the row: the one replaced by new words fades where it stands; the one past `tags` slides off. for (const id of prev) { @@ -774,6 +929,34 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { else ev.push({ k: `t${id}`, at, dur: SLIDE, to: { x: slotX(n), autoAlpha: 0 }, ease: "power2.in" }); } }); + // THE RUNNING DAY COUNT (`days`): on the front tag, the days on its diet to the in-record date at the playhead + // (dietDays), a number per stretch it holds -- cut wherever the count or the front tag changes. + const dayBlocks = new Map(); + if (daysOn) { + const counts = dietDays(schedule, render); + const cuts = [...new Set([...counts.map((c) => c.at), ...states.map((s) => s.at)])].sort((a, b) => a - b); + const end = Number(schedule.total) || 0; + const valueAt = (list, t) => { let v = null; for (const x of list) { if (x.at <= t + 1e-6) v = x; else break; } return v; }; + const runs = []; + cuts.forEach((t, i) => { + const st = valueAt(states, t); + const c = valueAt(counts, t); + const card = st?.diet && c && c.days !== null ? st.tags[0].id : null; + const days = card === null ? null : c.days; + const last = runs[runs.length - 1]; + const to = cuts[i + 1] ?? end; + if (last && last.card === card && last.days === days) { last.to = to; return; } + runs.push({ from: t, to, card, days }); + }); + runs.filter((r) => r.card !== null).forEach((r, m) => { + const k = `t${r.card}.y${m}`; + init[k] = { autoAlpha: 0 }; + ev.push({ k, at: r.from, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); + if (r.to < end - 1e-6) ev.push({ k, at: r.to, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); + if (!dayBlocks.has(r.card)) dayBlocks.set(r.card, []); + dayBlocks.get(r.card).push(`<div class="dy" data-k="${k}"><div class="dyn">${r.days}</div><div class="dyl">day${r.days === 1 ? "" : "s"}</div></div>`); + }); + } const { cues } = compileCues(init, ev); const items = []; const room = DIET_TAG.width - 44; @@ -788,23 +971,38 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { const sub = d ? `<div class="sb"><span class="dn">Diet${d.n !== null ? ` #${d.n}` : ""}</span>${words ? `<span class="dd">${esc(words)}</span>` : ""}</div>` : `<div class="sb"><span class="dd">he says he is on none</span></div>`; - const html = `<div class="tg" data-k="${k}"><div class="dm" data-k="${k}.d"><div class="sw" data-k="${k}.w"><div class="sp${d ? "" : " off"}" data-k="${k}.s">` + - `<div class="ink" style="color:${ink};border-color:${ink}"><div class="lb" style="font-size:${px(size)}px;line-height:${px(Math.round(size * 1.02))}px">${esc(label)}</div>${sub}` + - `${date ? `<div class="dt">${esc(date)}</div>` : ""}</div></div></div></div></div>`; + const faceBody = `<div class="lb" style="font-size:${px(size)}px;line-height:${px(Math.round(size * 1.02))}px">${esc(label)}</div>${sub}` + + `${date ? `<div class="dt">${esc(date)}</div>` : ""}`; + const face = daysOn ? `<div class="fc">${faceBody}</div><div class="dc">${(dayBlocks.get(t.id) ?? []).join("")}</div>` : faceBody; + // The strip an older tag shows beside the one in front of it: its regime word and its date. + const back = fan + ? `<div class="bk" data-k="${k}.b"><div class="bl" style="font-size:${px(Math.min(32, tagWordSize(label, step - 30)))}px">${esc(label)}</div>${date ? `<div class="bd">${esc(date)}</div>` : ""}</div>` + : ""; + const html = `<div class="tg" data-k="${k}"${fan ? ` style="z-index:${10 + t.id}"` : ""}><div class="dm" data-k="${k}.d"><div class="sw" data-k="${k}.w"><div class="sp${d ? "" : " off"}" data-k="${k}.s">` + + `<div class="ink" style="color:${ink};border-color:${ink}"><div class="fr"${fan ? ` data-k="${k}.f"` : ""}>${face}</div>${back}</div></div></div></div></div>`; items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } - .tg { position: absolute; left: 0; top: 0; width: ${px(DIET_TAG.width)}px; height: ${px(DIET_TAG.height)}px; visibility: hidden; opacity: 0; } + .tg { position: absolute; left: 0; top: 0; width: ${px(W)}px; height: ${px(DIET_TAG.height)}px; visibility: hidden; opacity: 0;${fan ? " transform-origin: 30% 60%;" : ""} } .dm, .sw { position: absolute; inset: 0; } /* A tag: the stamp's plate and pressed ink, small. The plate is solid; only the ink is pressed. */ .sp { position: absolute; left: ${px(4)}px; top: ${px(4)}px; right: ${px(4)}px; bottom: ${px(4)}px; border-radius: ${px(8)}px; - background: ${rgba(pal.bg, 0.93)}; padding: ${px(4)}px; box-shadow: 0 ${px(6)}px ${px(16)}px rgba(0, 0, 0, 0.45); } - .ink { height: 100%; padding: ${px(3)}px ${px(10)}px ${px(4)}px; border: ${px(4)}px solid; border-radius: ${px(6)}px; - box-shadow: inset 0 0 0 ${px(2)}px ${rgba(pal.bg, 0.9)}, inset 0 0 0 ${px(3)}px currentColor; - display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; + background: ${rgba(pal.bg, fan ? 0.97 : 0.93)}; padding: ${px(4)}px; + box-shadow: ${fan ? `0 ${px(8)}px ${px(18)}px rgba(0, 0, 0, 0.5), ${px(-4)}px 0 ${px(10)}px rgba(0, 0, 0, 0.35)` : `0 ${px(6)}px ${px(16)}px rgba(0, 0, 0, 0.45)`}; } + .ink { position: relative; height: 100%; padding: ${px(3)}px ${px(10)}px ${px(4)}px; border: ${px(4)}px solid; border-radius: ${px(6)}px; + box-shadow: inset 0 0 0 ${px(2)}px ${rgba(pal.bg, 0.9)}, inset 0 0 0 ${px(3)}px currentColor; overflow: hidden; -webkit-mask-image: ${INK}; mask-image: ${INK}; -webkit-mask-size: ${px(240)}px ${px(120)}px; mask-size: ${px(240)}px ${px(120)}px; } + .fr { height: 100%; display: flex; ${daysOn ? "flex-direction: row; align-items: stretch;" : "flex-direction: column; align-items: center; justify-content: center;"} } + .fc { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; } + .dc { position: relative; flex: none; width: ${px(76)}px; margin-left: ${px(6)}px; border-left: ${px(2)}px solid ${rgba(pal.fg, 0.18)}; } + .dy { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; } + .dyn { font-family: ${DISPLAY}; font-size: ${px(40)}px; line-height: ${px(40)}px; font-variant-numeric: tabular-nums; } + .dyl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; letter-spacing: 0.16em; text-transform: uppercase; color: ${pal.fg}; } + .bk { position: absolute; right: 0; top: 0; bottom: 0; width: ${px(step - 20)}px; display: flex; flex-direction: column; align-items: center; justify-content: center; } + .bl { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; line-height: 1.05; } + .bd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(14)}px; line-height: ${px(18)}px; color: ${pal.fg}; white-space: nowrap; font-variant-numeric: tabular-nums; } .lb { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; } .sb { display: flex; align-items: baseline; justify-content: center; gap: ${px(8)}px; white-space: nowrap; max-width: 100%; } .dn { flex: none; font-family: 'DeckSansBold', sans-serif; font-size: ${px(14)}px; line-height: ${px(18)}px; letter-spacing: 0.14em; text-transform: uppercase; } diff --git a/umtool/report-to-video/chrome-runs-finale.mjs b/umtool/report-to-video/chrome-runs-finale.mjs @@ -0,0 +1,298 @@ +// THE FINALE'S DETAILED DIET RUNS (module `runs-finale`, `deck.finale.dietRuns`): +// the whole record of his diets drawn large in the finale -- the measure +// slice's `record` (diet-record.mjs), every run from the earliest row a bar in +// its diet's ink along a time axis, a stretch of years with nothing on record +// drawn as a break (compressed, marked), the rows that stopped a diet or named +// the medication as marks under the bars, his stated weights as a light line +// over them; the longest runs (and the one still going) labelled with the +// diet's word, its number when the cut showed it ("DIET #6", the shelf's), its +// dates and its days -- the open one "N days and counting" to the in-record +// date. It stands in the finale's timeline panel under the large rail (clear +// of the side video, the lower column's instruments and the promise clock that +// takes it over), sweeps in left to right over the finale's first seconds, +// then holds. +// +// PURE: a schedule and a render block in, `{ html, items }` out. +import { formatDeckDate } from "./attribution.mjs"; +import { finaleLayout } from "./chrome-finale.mjs"; +import { rgba } from "./chrome-deck.mjs"; +import { compileCues, cuePageHtml, esc, r4 } from "./chrome-cues.mjs"; +import { dietRunsOn, dietRunsWeights, FINALE_MOTION, resolveFinale } from "./finale.mjs"; +import { daysBetween, measureOf, shortDate } from "./measure-extras.mjs"; +import { DIET_COLORS, DIET_LABELS, MEASURE_RED, resolveMeasureExtra } from "./modules/measure-extras-settings.mjs"; + +/** A stretch with nothing on record longer than this is drawn as a break, days. */ +export const RUNS_BREAK_DAYS = 730; +/** The motion: in after the finale's grow, swept left to right, s. */ +export const RUNS_MOTION = Object.freeze({ delay: 0.2, sweep: 2.6, label: 0.3 }); +/** The panel's least height (1080p px) under the rail; less, and there is no room. */ +export const RUNS_MIN_HEIGHT = 100; + +const DESIGN = Object.freeze({ top: 5, weights: 34, barY: 36, barH: 18, rowA: 68, rowB: 95, rowH: 27, years: 12, brk: 44 }); +/** With the weight layer (`dietRuns.weights`): every weight he gave over the bars, on the dial's scale. */ +const LAYERED = Object.freeze({ ...DESIGN, top: 6, weights: 110, barY: 118, rowA: 152, rowB: 180 }); + +/** The record the slice carries, when the finale asks for it. */ +export const recordOf = (schedule) => { + const r = measureOf(schedule)?.record; + return r && Array.isArray(r.runs) && r.runs.length ? r : null; +}; + +/** + * Where it stands: the finale's timeline panel under the large rail's track, + * from the rail's left end to its right, down to the panel's foot -- or null + * when that is under RUNS_MIN_HEIGHT. + */ +export function runsFinaleGeometry(schedule, render) { + if (!schedule?.finale) return null; + const L = finaleLayout(schedule, render); + const kh = L.geo.H / 1080; + const y = Math.round(L.rail.track.y + 26 * kh); + const bottom = Math.round(L.rail.bottom - 4 * kh); + if (bottom - y < RUNS_MIN_HEIGHT * kh) return null; + const x = L.rail.track.x0; + const even = (v) => Math.round(v / 2) * 2; + return { x, y, width: even(L.rail.track.x1 - x), height: even(bottom - y) }; +} + +/** The in-record date at the finale: the latest date of anything the cut showed. */ +function recordDate(m) { + const ds = (m.events ?? []).map((e) => e.date).filter(Boolean).sort(); + return ds[ds.length - 1] ?? m.asOfRender ?? null; +} + +/** + * The time axis: dates to px, every stretch with nothing on record longer than + * RUNS_BREAK_DAYS squeezed to `brk` px and marked. `x(date)`, `breaks: [{ x, + * from, to }]`, the years' ticks. + */ +export function runsAxis(dates, width, { brk = DESIGN.brk, pad = 8 } = {}) { + const ds = [...new Set(dates.filter(Boolean))].sort(); + const spans = []; + for (let i = 1; i < ds.length; i += 1) spans.push({ a: ds[i - 1], b: ds[i], days: Math.max(0, daysBetween(ds[i - 1], ds[i]) ?? 0) }); + const broken = spans.filter((s) => s.days > RUNS_BREAK_DAYS); + const linear = spans.filter((s) => s.days <= RUNS_BREAK_DAYS).reduce((n, s) => n + s.days, 0); + const k = Math.max(0.01, (width - 2 * pad - broken.length * brk) / Math.max(1, linear)); + const stops = [{ date: ds[0], x: pad }]; + for (const s of spans) stops.push({ date: s.b, x: stops[stops.length - 1].x + (s.days > RUNS_BREAK_DAYS ? brk : s.days * k), broken: s.days > RUNS_BREAK_DAYS }); + const x = (d) => { + if (!d) return stops[stops.length - 1].x; + if (d <= stops[0].date) return stops[0].x; + for (let i = 1; i < stops.length; i += 1) { + if (d <= stops[i].date) { + const a = stops[i - 1], b = stops[i]; + if (b.broken) return a.x + (d === b.date ? b.x - a.x : Math.min(b.x - a.x, 6)); + return a.x + (daysBetween(a.date, d) ?? 0) * k; + } + } + return stops[stops.length - 1].x + (daysBetween(stops[stops.length - 1].date, d) ?? 0) * k; + }; + const breaks = stops.map((s, i) => (s.broken ? { x: r4((stops[i - 1].x + s.x) / 2), x0: stops[i - 1].x, x1: s.x, from: stops[i - 1].date, to: s.date } : null)).filter(Boolean); + const years = []; + const y0 = Number(String(ds[0]).slice(0, 4)), y1 = Number(String(ds[ds.length - 1]).slice(0, 4)); + for (let y = y0 + 1; y <= y1; y += 1) { + const d = `${y}-01-01`; + if (breaks.some((b) => d > b.from && d < b.to)) continue; + years.push({ year: y, x: r4(x(d)) }); + } + return { x, breaks, years, k }; +} + +/** The finale's detailed diet runs page over the finale's `window`: `{ html, items }`. */ +export function runsFinaleHtml(schedule, render, window, opts = {}) { + const m = measureOf(schedule); + const rec = recordOf(schedule); + const geo = runsFinaleGeometry(schedule, render); + if (!m || !rec || !geo) throw new Error("runs-finale: needs a finale, the measure slice's diet record (render.chrome.deck.finale.dietRuns) and room under the rail"); + const pal = render.palette; + // The weight layer (`dietRuns.weights`): every weight he gave, at the day it applied (or was said). + const layer = dietRunsWeights(resolveFinale(render).dietRuns); + const D = layer ? LAYERED : DESIGN; + const s = (render.width ?? 1920) / 1920; + const px = (v) => Math.max(1, Math.round(v * s)); + const cfg = resolveMeasureExtra("diet", render) ?? resolveMeasureExtra("diet", { chrome: { deck: {} } }); + const colors = { ...DIET_COLORS, ...(cfg?.colors ?? {}) }; + const labels = { ...DIET_LABELS, ...(cfg?.labels ?? {}) }; + const W = geo.width, H = geo.height; + const today = recordDate(m); + const points = Array.isArray(rec.points) ? rec.points : []; + const claims = layer && Array.isArray(rec.claims) ? rec.claims : []; + const dates = [rec.from, ...rec.runs.flatMap((r) => [r.since, r.end]), ...rec.marks.map((x) => x.date), ...rec.weights.map((w) => w.date), ...points.map((p) => p.date), + ...claims.flatMap((c) => [c.applied, c.said]), today].filter(Boolean); + const A = runsAxis(dates, W, { brk: px(D.brk), pad: px(layer ? 34 : 8) }); + // The number the cut gave a diet (the shelf's "DIET #6"): its state's, by regime and since. + const shownN = new Map(); + for (const st of m.state ?? []) if (st?.diet?.since) shownN.set(`${st.diet.regime}|${st.diet.since}`, st.diet.n); + const crossesBreak = (r) => A.breaks.some((b) => r.since <= b.from && (r.end ?? today) >= b.to); + const runs = rec.runs.map((r, i) => { + const end = r.end ?? today; + const x0 = A.x(r.since); + // A run across a break has no record of its end: drawn to the break, fading into it. + const brk = crossesBreak(r) ? A.breaks.find((b) => r.since <= b.from) : null; + const x1 = brk ? brk.x0 + px(4) : A.x(end); + const days = brk ? null : Math.max(0, daysBetween(r.since, end) ?? 0); + const word = (r.name ?? labels[r.key] ?? r.key).toUpperCase(); + const n = shownN.get(`${r.key}|${r.since}`) ?? null; + return { ...r, i, x0: r4(x0), x1: r4(Math.max(x0 + px(3), x1)), days, word, n, open: r.end === null, faded: !!brk, color: colors[r.key] ?? colors.other }; + }); + // THE LABELS: the run still going first, then the longest; each in the first of two rows under the bars where + // it meets no other (its words ~0.56 em a character), at its bar's middle, clamped to the panel. + const fs = px(13); + const est = (t, size, bold = 0.58) => t.length * size * bold; + const rows = [[], []]; + const placed = []; + const order = [...runs].sort((a, b) => (b.open - a.open) || ((b.days ?? 1e6) - (a.days ?? 1e6))); + for (const r of order) { + const l1 = `${r.word}${r.n !== null ? ` · DIET #${r.n}` : ""}`; + const from = formatDeckDate(r.since); + const l2 = r.days === null ? `from ${from}` : r.open ? `${shortDate(r.since, { year: true })} · ${r.days} days and counting` : `${shortDate(r.since, { year: true })} – ${shortDate(r.end, { year: true })} · ${r.days} day${r.days === 1 ? "" : "s"}`; + const w = Math.ceil(Math.max(est(l1, fs, 0.62), est(l2, px(12), 0.55))) + px(6); + if ((r.x1 - r.x0) < px(14) && !r.open) continue; + const mid = (r.x0 + r.x1) / 2; + const lx = Math.max(0, Math.min(W - w, Math.round(r.open ? r.x1 - w : mid - w / 2))); + const row = rows.findIndex((list) => list.every((o) => lx + w + px(10) <= o.x || o.x + o.w + px(10) <= lx)); + if (row < 0) continue; + rows[row].push({ x: lx, w }); + placed.push({ r, row, x: lx, w, l1, l2 }); + } + // THE WEIGHTS. Without the layer: a light line of his stated weights over the bars. With it (`weights`): + // EVERY weight he gave on the dial's scale -- at the day it applied ("applied") or was said ("said") -- the ones + // he gave at the time solid and joined (his claimed trajectory; a bound is no reading, so not joined), the ones told later hollow with a thin leader + // down to the day he said it, so a retold peak piles up at one period from its tellings; a bound (">") a caret + // over its point, an "about" (≈) a ring round it, a range a bar. + const ws = rec.weights.filter((w) => w.date); + const scale = m.scale ?? {}; + const vals = layer ? [...claims.map((c) => c.value), ...points.map((p) => p.value)] : [...ws.map((w) => w.value), ...points.map((p) => p.value)]; + const lo = layer ? Math.min(Number.isFinite(scale.min) ? scale.min : Infinity, ...vals) : Math.min(...vals); + const hi = layer ? Math.max(Number.isFinite(scale.max) ? scale.max : -Infinity, ...vals) : Math.max(...vals); + const wy = (v) => r4(px(D.top) + (hi > lo ? (hi - v) / (hi - lo) : 0.5) * px(D.weights - D.top - 4)); + const xOfClaim = (c) => r4(A.x(layer === "said" ? c.said : c.applied)); + const line = layer + ? claims.filter((c) => !c.retold && !["<", ">"].includes(c.qualifier)).map((c) => [xOfClaim(c), wy(c.value)]) + : ws.map((w) => [r4(A.x(w.date)), wy(w.value)]); + const pts = line; + const segs = []; + for (let i = 1; i < pts.length; i += 1) { + const broken = A.breaks.some((b) => pts[i - 1][0] <= b.x0 + 1 && pts[i][0] >= b.x1 - 1); + if (!broken) segs.push(`M${pts[i - 1][0]},${pts[i - 1][1]}L${pts[i][0]},${pts[i][1]}`); + } + const axisY = px(D.barY + D.barH + 1); + const grid = layer + ? [250, 300, 350, 400].filter((v) => v >= lo && v <= hi).map((v) => `<div class="gl" style="top:${wy(v)}px"></div><div class="gv" style="top:${r4(wy(v) - px(7))}px">${v}</div>`).join("") + : ""; + const claimSvg = layer + ? claims.map((c) => { + const x = xOfClaim(c); + const y = wy(c.value); + const leader = c.retold && layer === "applied" ? `<path d="M${x},${y}L${r4(A.x(c.said))},${axisY}" class="ldr"/><path d="M${r4(A.x(c.said))},${axisY - px(4)}V${axisY + px(3)}" class="said"/>` : ""; + const range = c.range ? `<path d="M${x},${wy(Math.max(...c.range))}V${wy(Math.min(...c.range))}" class="rg"/>` : ""; + const dot = c.retold ? `<circle cx="${x}" cy="${y}" r="${px(3.2)}" class="hol"/>` : `<circle cx="${x}" cy="${y}" r="${px(2.8)}" class="sol"/>`; + const q = c.qualifier === "≈" ? `<circle cx="${x}" cy="${y}" r="${px(6)}" class="apx"/>` + : c.qualifier === ">" ? `<path d="M${r4(x - px(4))},${r4(y - px(5))}L${x},${r4(y - px(9))}L${r4(x + px(4))},${r4(y - px(5))}" class="car"/>` + : c.qualifier === "<" ? `<path d="M${r4(x - px(4))},${r4(y + px(5))}L${x},${r4(y + px(9))}L${r4(x + px(4))},${r4(y + px(5))}" class="car"/>` : ""; + return `${leader}${range}${dot}${q}`; + }).join("") + : ""; + // The motion: the panel sweeps open left to right, each label coming in as the sweep reaches it. + const fps = schedule.fps ?? render.fps ?? 30; + const from = r4(Number(window.from)); + const dur = r4(Number(window.to) - from); + if (!(dur > 0)) throw new Error("runs-finale: the window is empty"); + const t0 = from + FINALE_MOTION.grow + RUNS_MOTION.delay; + const init = { rv: { width: 0 }, pn: { autoAlpha: 0 } }; + const ev = [ + { k: "pn", at: t0 - 0.1, dur: 0.25, to: { autoAlpha: 1 }, ease: "power1.out" }, + { k: "rv", at: t0, dur: RUNS_MOTION.sweep, to: { width: W }, ease: "none" }, + ]; + const items = []; + // THE MARKED WEIGHTS (`dietRuns.marks`, the low): a dot at the day it was his weight, his words and the month + // beside it -- THE peak in the needle's red, a size up; the low in the accent. + const pointHtml = points.map((p, j) => { + const key = `p${j}`; + const x = r4(A.x(p.date)); + const y = wy(p.value); + const text = `${p.label}${p.label ? " · " : ""}${shortDate(p.date, { year: true }).replace(/^\d+ /, "")}`; + const w = Math.ceil(text.length * px(p.kind === "peak" ? 13 : 12) * 0.56) + px(12); + const left = x + px(10) + w <= W ? x + px(10) : x - px(10) - w; + const top = Math.max(0, Math.min(px(D.weights) - px(14), Math.round(y - px(8)))); + init[key] = { autoAlpha: 0 }; + ev.push({ k: key, at: t0 + RUNS_MOTION.sweep * Math.min(1, x / W), dur: RUNS_MOTION.label, to: { autoAlpha: 1 }, ease: "power1.out" }); + const html = `<div class="pt ${p.kind}" data-k="${key}"><div class="pd" style="left:${x}px;top:${y}px"></div>` + + `<div class="pl" style="left:${r4(left)}px;top:${top}px;width:${w}px;${left < x ? "text-align:right;" : ""}"><span>${esc(text)}</span></div></div>`; + items.push({ key, gate: [key, "autoAlpha"], html }); + return html; + }); + const labelHtml = placed.map((p, j) => { + const key = `l${j}`; + init[key] = { autoAlpha: 0 }; + const at = t0 + RUNS_MOTION.sweep * Math.min(1, (p.r.x0 + p.r.x1) / 2 / W); + ev.push({ k: key, at, dur: RUNS_MOTION.label, to: { autoAlpha: 1 }, ease: "power1.out" }); + const top = px(p.row ? D.rowB : D.rowA); + const lead = Math.round((p.r.x0 + p.r.x1) / 2); + const html = `<div class="lb" data-k="${key}"><div class="ld" style="left:${lead}px;top:${px(D.barY + D.barH)}px;height:${top - px(D.barY + D.barH)}px;background:${p.r.color}"></div>` + + `<div class="lt" style="left:${p.x}px;top:${top}px;width:${p.w}px;${p.x + p.w >= W - 1 ? "text-align:right;" : ""}"><div class="l1" style="color:${p.r.color}">${esc(p.l1)}</div><div class="l2">${esc(p.l2)}</div></div></div>`; + items.push({ key, gate: [key, "autoAlpha"], html }); + return html; + }); + const bars = runs.map((r) => `<div class="bar${r.faded ? " fd" : ""}${r.open ? " op" : ""}" style="left:${r.x0}px;width:${r4(r.x1 - r.x0)}px;--c:${r.color}"></div>`).join(""); + const marks = rec.marks.map((x) => `<div class="mk ${x.kind}" style="left:${r4(A.x(x.date))}px"></div>`).join(""); + const years = A.years.map((y) => `<div class="yt" style="left:${y.x}px"></div><div class="yl" style="left:${r4(y.x + px(3))}px">${y.year}</div>`).join(""); + const breaks = A.breaks.map((b) => `<div class="bk" style="left:${r4(b.x0)}px;width:${r4(b.x1 - b.x0)}px"><span>${esc(String(b.from).slice(0, 4))}–${esc(String(b.to).slice(0, 4))}</span></div>`).join(""); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + #rv { position: absolute; left: 0; top: 0; height: ${H}px; overflow: hidden; } + #rw { position: absolute; left: 0; top: 0; width: ${W}px; height: ${H}px; } + .bar { position: absolute; top: ${px(D.barY)}px; height: ${px(D.barH)}px; background: var(--c); border-radius: ${px(2)}px; + box-shadow: inset 0 ${px(-3)}px 0 rgba(0, 0, 0, 0.18); } + .bar.fd { background: linear-gradient(90deg, var(--c) 0%, var(--c) 55%, transparent 100%); } + .bar.op { box-shadow: 0 0 ${px(10)}px var(--c); } + .ax { position: absolute; left: 0; width: ${W}px; top: ${px(D.barY + D.barH + 1)}px; height: ${px(2)}px; background: ${pal.muted}; opacity: 0.45; } + .mk { position: absolute; top: ${px(D.barY + D.barH + 2)}px; width: ${px(2)}px; height: ${px(6)}px; margin-left: ${px(-1)}px; background: ${pal.muted}; } + .mk.med { background: ${colors.glp1 ?? "#B168C6"}; height: ${px(8)}px; } + .bk { position: absolute; top: ${px(D.barY - 4)}px; height: ${px(D.barH + 10)}px; display: flex; align-items: center; justify-content: center; + background: repeating-linear-gradient(115deg, transparent 0 ${px(5)}px, ${pal.muted}55 ${px(5)}px ${px(7)}px); } + .bk span { font-family: 'DeckSansBold', sans-serif; font-size: ${px(10)}px; color: ${pal.fg}; background: ${pal.bg}; padding: 0 ${px(3)}px; white-space: nowrap; } + .yt { position: absolute; top: ${px(D.barY - 4)}px; width: 1px; height: ${px(D.barH + 8)}px; background: ${pal.muted}; opacity: 0.5; } + .yl { position: absolute; top: ${px(D.barY + D.barH + 4)}px; font-size: ${px(D.years)}px; line-height: ${px(14)}px; color: ${pal.muted}; } + svg.wt { position: absolute; left: 0; top: 0; overflow: visible; } + svg.wt .sol { fill: ${pal.fg}; } + svg.wt .hol { fill: ${pal.bg}; stroke: ${pal.fg}; stroke-opacity: 0.75; stroke-width: ${px(1.5)}; } + svg.wt .apx { fill: none; stroke: ${pal.amber ?? pal.fg}; stroke-opacity: 0.8; stroke-width: ${px(1)}; } + svg.wt .car { fill: none; stroke: ${pal.amber ?? pal.fg}; stroke-width: ${px(1.5)}; } + svg.wt .ldr { stroke: ${pal.fg}; stroke-opacity: 0.22; stroke-width: ${px(1)}; fill: none; } + svg.wt .said { stroke: ${pal.fg}; stroke-opacity: 0.6; stroke-width: ${px(1.5)}; } + svg.wt .rg { stroke: ${pal.fg}; stroke-opacity: 0.6; stroke-width: ${px(2)}; } + .gl { position: absolute; left: ${px(30)}px; right: 0; height: 1px; background: ${pal.muted}; opacity: 0.18; } + .gv { position: absolute; left: 0; width: ${px(26)}px; text-align: right; font-size: ${px(11)}px; line-height: ${px(14)}px; color: ${pal.muted}; } + .pt { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .pd { position: absolute; width: ${px(7)}px; height: ${px(7)}px; margin: ${px(-3.5)}px 0 0 ${px(-3.5)}px; border-radius: 50%; background: ${pal.fg}; + box-shadow: 0 0 0 ${px(2)}px ${pal.bg}; } + .pl { position: absolute; white-space: nowrap; font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(14)}px; color: ${pal.fg}; } + .pl span { background: ${rgba(pal.bg, 0.85)}; padding: 0 ${px(3)}px; border-radius: ${px(3)}px; } + .peak .pd { width: ${px(11)}px; height: ${px(11)}px; margin: ${px(-5.5)}px 0 0 ${px(-5.5)}px; background: ${MEASURE_RED}; box-shadow: 0 0 0 ${px(2)}px ${pal.bg}, 0 0 ${px(10)}px ${MEASURE_RED}; } + .peak .pl { font-size: ${px(13)}px; color: ${MEASURE_RED}; } + .low .pd { background: ${pal.accent}; } + .low .pl { color: ${pal.accent}; } + .lb { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .ld { position: absolute; width: ${px(2)}px; margin-left: ${px(-1)}px; opacity: 0.7; } + .lt { position: absolute; white-space: nowrap; } + .l1 { font-family: 'DeckSansBold', sans-serif; font-size: ${fs}px; line-height: ${px(14)}px; letter-spacing: 0.06em; text-transform: uppercase; } + .l2 { font-size: ${px(12)}px; line-height: ${px(14)}px; color: ${pal.fg}; font-variant-numeric: tabular-nums; } +`; + const body = `<div id="pn" data-k="pn"> + <div id="rv" data-k="rv"><div id="rw"> + ${grid}<svg class="wt" width="${W}" height="${H}"><path d="${segs.join("")}" fill="none" stroke="${pal.fg}" stroke-opacity="${layer ? 0.7 : 0.45}" stroke-width="${px(2)}"/>${layer ? claimSvg : pts.map(([x, y]) => `<circle cx="${x}" cy="${y}" r="${px(2)}" fill="${pal.fg}" fill-opacity="0.7"/>`).join("")}</svg> + ${years}<div class="ax"></div>${bars}${marks}${breaks} + </div></div> + ${labelHtml.join("\n ")} + ${pointHtml.join("\n ")} + </div>`; + const { cues } = compileCues(init, ev); + return { + html: cuePageHtml({ id: "runs-finale", W, H, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init, cues, window: { from, dur } }), + items, + }; +} + +/** Is the detailed finale asked for (`deck.finale.dietRuns`)? */ +export const runsFinaleWanted = (render) => dietRunsOn(resolveFinale(render).dietRuns); diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -58,7 +58,7 @@ import { overlayPointsOf, resolveStats, statsSchedule, statsWanted, validateStat import { fxOn, fxSchedule, validateFx } from "./fx.mjs"; import { estimatedNarratedCardSeconds, hasNarration } from "./narration.mjs"; import { - aboveTop, FINALE_MOTION, FINALE_SHARE, finaleClaims, finaleClaimSlots, finaleGeometry, finaleRunOf, finaleRunProblems, + aboveTop, dietRunsPanel, FINALE_MOTION, FINALE_SHARE, finaleClaims, finaleClaimSlots, finaleGeometry, finaleRunOf, finaleRunProblems, railLabelLayout, railMarkerLayout, resolveFinale, textWidth as finaleTextWidth, validateFinaleSettings, } from "./finale.mjs"; import { @@ -2071,12 +2071,18 @@ function finaleRailAt(schedule, render, railBottom, textScale) { if (typeof f.timelineShare === "number") B = Math.round(H * f.timelineShare) - py(36); else B = Math.max(rail.bottom, Math.min(Math.round(H * FINALE_SHARE.auto) - py(36), want)); } + // The finale's diet record (`dietRuns`, chrome-runs-finale.mjs) stands under the track: the track stays where + // its labels put it, and ("auto") the timeline takes the room the record needs under it, up to FINALE_SHARE.max. + const runsPanel = dietRunsPanel(f.dietRuns); + if (runsPanel && !Number.isFinite(railBottom) && typeof f.timelineShare !== "number") { + B = Math.max(B, Math.min(Math.round(H * FINALE_SHARE.max) - py(36), Yneed + py(26 + runsPanel + 6))); + } const geo = B === rail.bottom ? base : geoAt(B); // The labels again, cut to the room under the track; the track moves down // by half of what they leave. labels = labelsAt(xs, { ...geo, rail: { ...geo.rail, y: Yneed } }); const low = lowOf(labels, Yneed, false); - const Y = Yneed + Math.max(0, Math.floor((B - low) / 2)); + const Y = runsPanel ? Yneed : Yneed + Math.max(0, Math.floor((B - low) / 2)); return { geo, x0, xs, pips, labels, marks, claims, Y, railBottom: B, want, textScale, lay, fxs, pipped, bigSize, bigV, footSize }; } diff --git a/umtool/report-to-video/diet-record.mjs b/umtool/report-to-video/diet-record.mjs @@ -0,0 +1,156 @@ +// THE DIET RECORD (the finale's detailed diet runs, `deck.finale.dietRuns`): +// the WHOLE record of his diets in scope -- every regime row, on camera or +// not, from the earliest -- as RUNS, with the rows that stopped one or named a +// medication as marks, and his stated weights along it. measure-slice.mjs +// writes it into the slice as `record` only when the finale asks for it, so a +// cut without it writes the slice it always did; chrome-runs-finale.mjs draws it. +// +// The runs follow the state's own rule (panel-model.mjs nextRegime: "on" keeps +// when a regime opened, "start" opens it again, an "off" closes only what it +// names; the track's off key is no diet): a new run at each change of regime, +// numbered as the state numbers its diets. A run is named by its opening row's +// own words when they name it otherwise ("Weight Watchers" for `calories`). +// +// Pure: rows and the schema in, plain data out. +import { chronological, dateKey } from "./ledger-shared.mjs"; +import { measureDisplay, plotDate } from "./measure-totals.mjs"; +import { CLOSING, nextRegime, offOf } from "./panel-model.mjs"; + +const GENERIC = /^(some diet|no diet|something unnamed)$/i; + +/** + * A run's own name from its opening row's words, or null when they only + * repeat the regime ("Keto", "Keto · 5 carbs a day", "off keto", "Some diet"). + */ +export function runName(display, regime) { + const d = String(display ?? "").trim(); + if (!d || GENERIC.test(d) || /^off\b/i.test(d) || /[·+]/.test(d)) return null; + const names = [regime?.key, regime?.label].filter(Boolean).map((x) => String(x).toLowerCase()); + if (names.some((n) => d.toLowerCase() === n || d.toLowerCase().startsWith(`${n} `))) return null; + return d; +} + +/** + * The record: `{ from, to, runs: [{ key, n, since, end, ended, name, row }], + * marks: [{ date, key, kind: "off" | "med", display, row }], weights: [{ date, + * value }] }` -- `end` null for the run still open; `from`/`to` the earliest and + * latest dates any of it has. + * + * @param {any[]} own his rows in scope + * @param {any} schema the resolved measure schema + * @param {string | null} regimeTrack the regime track's key + * @param {any[]} readings his weight rows (current and past) + */ +export function dietRecord(own, schema, regimeTrack, readings = [], opts = {}) { + if (!regimeTrack) return null; + const off = offOf(schema, regimeTrack)?.key ?? null; + const regimes = new Map((schema.regimes ?? []).map((r) => [r.key, r])); + const runs = []; + const marks = []; + let open = null; + let cur = null; + let n = 0; + for (const row of chronological(own.filter((r) => r.scope === regimeTrack))) { + open = nextRegime(open, row, schema); + const date = plotDate(row); + const key = open && open.key !== off ? open.key : null; + if (key !== (cur?.key ?? null)) { + if (cur) { cur.end = date; cur.ended = key ? "new" : "off"; } + cur = null; + if (key) { + n += 1; + cur = { key, n, since: open.since ?? date, end: null, ended: null, name: runName(measureDisplay(row, schema), regimes.get(key)), row: row.id }; + runs.push(cur); + } + } + const value = String(row.value ?? ""); + if (CLOSING.has(row.event)) marks.push({ date, key: value, kind: "off", display: measureDisplay(row, schema), row: row.id }); + else if (regimes.get(value)?.key === "glp1" && !(cur && cur.row === row.id)) marks.push({ date, key: value, kind: "med", display: measureDisplay(row, schema), row: row.id }); + } + const weights = readings + .filter((r) => r.population === "current" && Number.isFinite(Number(r.value))) + .map((r) => ({ date: plotDate(r), value: Number(r.value) })) + .filter((w) => w.date) + .sort((a, b) => dateKey(a.date).localeCompare(dateKey(b.date))); + const points = recordPoints(own, readings, opts); + const { claims, leftOut } = weightClaims(own); + const dates = [...runs.flatMap((r) => [r.since, r.end]), ...marks.map((m) => m.date), ...weights.map((w) => w.date), ...points.map((p) => p.date)] + .filter(Boolean).map(dateKey); + for (const c of claims) dates.push(dateKey(c.applied), dateKey(c.said)); + dates.sort(); + return { from: dates[0] ?? null, to: dates[dates.length - 1] ?? null, runs, marks, weights, points, claims, leftOut }; +} + +/** A claim told at least this many days after the day it applied is drawn as told later (a retelling). */ +export const RETOLD_DAYS = 30; + +/** + * EVERY weight he gave, at the day it APPLIED: each weight-scope row of his + * with a number that is a weight -- what he weighs now (`current`) and what he + * weighed (`past`) -- `{ row, value, applied, said, retold, qualifier, range, + * population }`, `applied` its asOf (else its date), `said` its date, `retold` + * when he said it RETOLD_DAYS or more after it applied. A loss or gain + * (`delta`) or "N over" (`overweight_by`) names no weight the ledger resolves, + * so it is left out and counted (`leftOut`, by population); goals and promises + * are not weights. + */ +export function weightClaims(own) { + const claims = []; + const leftOut = {}; + for (const r of own) { + if (r.scope !== "weight") continue; + const value = Number(r.value); + if (r.population === "current" || r.population === "past") { + const said = r.date ?? null; + const applied = r.asOf ?? r.date ?? null; + if (!Number.isFinite(value) || !applied) { leftOut[r.population] = (leftOut[r.population] ?? 0) + 1; continue; } + const late = said && applied && dateKey(applied) < dateKey(said) && (Date.parse(dateKey(said)) - Date.parse(dateKey(applied))) / 86400000 >= RETOLD_DAYS; + claims.push({ + row: r.id, value, applied: dateKey(applied), said: said ? dateKey(said) : dateKey(applied), retold: !!late, + qualifier: typeof r.qualifier === "string" ? r.qualifier : null, + range: Array.isArray(r.range) && r.range.length === 2 ? r.range.map(Number) : null, + population: r.population, + }); + } else if ((r.population === "delta" || r.population === "overweight_by") && Number.isFinite(value)) { + leftOut[r.population] = (leftOut[r.population] ?? 0) + 1; + } + } + claims.sort((a, b) => a.applied.localeCompare(b.applied) || a.said.localeCompare(b.said)); + return { claims, leftOut }; +} + +/** + * The annotated weights on the record's line (`deck.finale.dietRuns.marks`): + * each named row at the day it was his weight (its asOf, else its date) and its + * value, with the author's label -- his words -- `kind` "peak" for THE peak (the + * one marked `peak`, else the heaviest marked), "mark" else; and, unless `low` + * is false, the lowest weight he stated at the time, "low" (its label `low` + * when it is words, else "his low · <value>") -- never a bound ("over 240"), + * and of one weigh-in told twice the same day ("291." and "291.5") the fuller. + * A row the ledger lacks, or with no number, is left out. + * + * @returns {Array<{ row: string, date: string, value: number, label: string, kind: "peak" | "mark" | "low" }>} + */ +export function recordPoints(own, readings, { marks = [], low = true } = {}) { + const byId = new Map(own.map((r) => [r.id, r])); + const points = []; + for (const m of Array.isArray(marks) ? marks : []) { + const row = byId.get(String(m?.row ?? "")); + const value = Number(row?.value); + if (!row || !Number.isFinite(value) || !plotDate(row)) continue; + points.push({ row: row.id, date: plotDate(row), value, label: String(m.label ?? "").trim(), kind: m.peak === true ? "peak" : "mark" }); + } + if (points.length && !points.some((p) => p.kind === "peak")) points.reduce((a, b) => (b.value > a.value ? b : a)).kind = "peak"; + if (low !== false) { + // A weight he STATED, as measured: no bound ("over 240" is a floor, not a weigh-in). + const stated = readings.filter((r) => r.population === "current" && Number.isFinite(Number(r.value)) && plotDate(r) && !["<", ">"].includes(r.qualifier)); + let lo = stated.reduce((a, b) => (!a || Number(b.value) < Number(a.value) || (Number(b.value) === Number(a.value) && dateKey(plotDate(b)) > dateKey(plotDate(a))) ? b : a), null); + // One weigh-in told twice ("291." on X, "291.5" on stream, the same day): the reading he gave in full. + const fuller = lo && stated.find((r) => r !== lo && dateKey(plotDate(r)) === dateKey(plotDate(lo)) && Math.abs(Number(r.value) - Number(lo.value)) < 1 && !Number.isInteger(Number(r.value)) && Number.isInteger(Number(lo.value))); + if (fuller) lo = fuller; + if (lo && !points.some((p) => p.row === lo.id)) { + points.push({ row: lo.id, date: plotDate(lo), value: Number(lo.value), label: typeof low === "string" && low.trim() ? low.trim() : `his low · ${Number(lo.value)}`, kind: "low" }); + } + } + return points.sort((a, b) => dateKey(a.date).localeCompare(dateKey(b.date))); +} diff --git a/umtool/report-to-video/finale.mjs b/umtool/report-to-video/finale.mjs @@ -18,6 +18,10 @@ // "pips": true | false false: the finale's own clips get no pip on the rail // (footer or large) -- the rail is the record alone; their // titles and dates stay in their own area (default true) +// "dietRuns": true | false | { marks, low } the whole diet record drawn under the rail (module runs-finale, +// chrome-runs-finale.mjs; needs railLabels sections|none; default false): +// `marks` [{row, label, peak?}] dots on its weight line with his words, +// the heaviest THE peak; `low` the lowest stated weight marked (default on) // "claims": "rotate" | "all" the claim checks (deck.claims) on the large rail: // one at a time, each for an even share of the page's // time (default "rotate"; all at once when there is @@ -87,6 +91,7 @@ export const FINALE_DEFAULTS = Object.freeze({ timelineShare: "auto", claims: "rotate", pips: true, + dietRuns: false, }); /** @@ -140,6 +145,11 @@ export function validateFinaleSettings(f, where = "render.chrome.deck.finale") { } if (f.totals !== undefined && typeof f.totals !== "boolean") errors.push(`${where}.totals must be true or false`); if (f.pips !== undefined && typeof f.pips !== "boolean") errors.push(`${where}.pips must be true or false`); + if (f.dietRuns !== undefined && typeof f.dietRuns !== "boolean") errors.push(...dietRunsProblems(f.dietRuns, `${where}.dietRuns`)); + // The diet runs stand under the rail, where "all" and "nodes" put the pips' labels and dates. + if (dietRunsOn(f.dietRuns) && !["sections", "none"].includes(f.railLabels ?? FINALE_DEFAULTS.railLabels)) { + errors.push(`${where}.dietRuns draws under the rail, where railLabels "${f.railLabels ?? FINALE_DEFAULTS.railLabels}" puts the pips' words: set ${where}.railLabels "sections" or "none"`); + } if (f.statsTitle !== undefined && f.statsTitle !== null) { const p = lineProblem(f.statsTitle, FINALE_LIMITS.statsTitle, `${where}.statsTitle`); if (p) errors.push(p); @@ -168,6 +178,53 @@ export function validateFinaleSettings(f, where = "render.chrome.deck.finale") { return errors; } +/** The finale's diet runs' marks: how many, and a label's characters. */ +export const DIET_RUNS_LIMITS = Object.freeze({ marks: 8, label: 60 }); + +/** Is the finale's diet record on (`dietRuns`: true, or its object)? */ +export const dietRunsOn = (v) => v === true || isObj(v); + +/** Where the record's weights stand (`dietRuns.weights`): at the date each APPLIED, the date each was SAID, or none. */ +export const DIET_RUNS_WEIGHTS = Object.freeze(["applied", "said"]); + +/** The record's weight layer: "applied" (the default when the record is on), "said", or false. */ +export const dietRunsWeights = (v) => (!dietRunsOn(v) ? false : isObj(v) && v.weights !== undefined ? v.weights : "applied"); + +/** + * The design px the finale's diet record takes under the large rail's track + * (chrome-runs-finale.mjs): 0 off; with the weight layer, the layer over the + * bars and their labels; without it, the bars and their labels alone. + */ +export const dietRunsPanel = (v) => (!dietRunsOn(v) ? 0 : dietRunsWeights(v) ? 218 : 122); + +/** Why `deck.finale.dietRuns` (an object) cannot be drawn. */ +export function dietRunsProblems(v, where) { + if (!isObj(v)) return [`${where} must be true, false or { marks, low, weights }`]; + const errors = []; + for (const k of Object.keys(v)) if (!["marks", "low", "weights"].includes(k)) errors.push(`${where}.${k} is not a diet-runs setting (marks, low, weights)`); + if (v.weights !== undefined && v.weights !== false && !DIET_RUNS_WEIGHTS.includes(v.weights)) errors.push(`${where}.weights must be "applied", "said" or false`); + if (v.low !== undefined && typeof v.low !== "boolean") { + const p = typeof v.low === "string" ? lineProblem(v.low, DIET_RUNS_LIMITS.label, `${where}.low`) : `${where}.low must be true, false or its label`; + if (p) errors.push(p); + } + if (v.marks !== undefined) { + if (!Array.isArray(v.marks)) errors.push(`${where}.marks must be a list of { row, label, peak? }`); + else { + if (v.marks.length > DIET_RUNS_LIMITS.marks) errors.push(`${where}.marks has ${v.marks.length} (at most ${DIET_RUNS_LIMITS.marks})`); + v.marks.forEach((m, i) => { + const at = `${where}.marks[${i}]`; + if (!isObj(m)) { errors.push(`${at} must be { row, label, peak? }`); return; } + for (const k of Object.keys(m)) if (!["row", "label", "peak"].includes(k)) errors.push(`${at}.${k} is not a mark field (row, label, peak)`); + if (typeof m.row !== "string" || !m.row.trim()) errors.push(`${at}.row must name a ledger row`); + const p = lineProblem(m.label, DIET_RUNS_LIMITS.label, `${at}.label`); + if (p) errors.push(p); + if (m.peak !== undefined && typeof m.peak !== "boolean") errors.push(`${at}.peak must be true or false`); + }); + } + } + return errors; +} + /** The finale settings with every default filled in (the stats trimmed, a number value as text). */ export function resolveFinale(render) { const f = isObj(render?.chrome?.deck?.finale) ? render.chrome.deck.finale : {}; diff --git a/umtool/report-to-video/measure-extras.mjs b/umtool/report-to-video/measure-extras.mjs @@ -27,7 +27,7 @@ // off-scope rule: this only draws state.diet). import { deckGeometry, feedGeometry, instrumentsGeometry } from "./deck.mjs"; import { chapterCover, chapterWindows } from "./chrome-story.mjs"; -import { MEASURE_EXTRAS, MEASURE_POSITIONS, resolveMeasureExtra, SHELF_POSITION } from "./modules/measure-extras-settings.mjs"; +import { dietTagWidth, MEASURE_EXTRAS, MEASURE_POSITIONS, resolveMeasureExtra, SHELF_POSITION } from "./modules/measure-extras-settings.mjs"; import { resolveShelf } from "./modules/shelf-settings.mjs"; const r4 = (v) => Math.round(v * 10000) / 10000; @@ -229,6 +229,7 @@ export function goalStates(schedule, render) { const states = []; let prevDepth = new Map(); let n = 0; + const rowKey = new Map(); for (const { e, s } of stepsOf(m)) { if (e.kind !== "goal" && e.kind !== "goalLoss") continue; n += 1; @@ -251,14 +252,22 @@ export function goalStates(schedule, render) { const target = s?.goal && s.goal.row === e.row && Number.isFinite(s.goal.value) ? s.goal.value : e.kind === "goal" && Number.isFinite(e.value) ? e.value : null; note.target = target; + rowKey.set(e.row, key); order = [...order.filter((k) => k !== key), key]; const shown = order.slice(-cfg.max); const depth = new Map(shown.map((k, i) => [k, shown.length - 1 - i])); + // The headline goal, when the state names one (the closest goal in force -- the measure state's + // `goals.headline`, a row or a goal carrying its row): its note's key, else null (the newest leads). + const hl = s?.goals && !Array.isArray(s.goals) ? s.goals.headline : s?.goalHeadline; + const hlRow = typeof hl === "string" ? hl : hl?.row ?? null; + const active = s?.goals && !Array.isArray(s.goals) && Array.isArray(s.goals.active) ? s.goals.active.length : null; states.push({ at: r4(e.t), top: key, repeat: note.count > 1, - goalsSet: Array.isArray(s?.goals) ? s.goals.length : n, + ...(hlRow && rowKey.has(hlRow) ? { headline: rowKey.get(hlRow) } : {}), + ...(active !== null ? { active } : {}), + goalsSet: Array.isArray(s?.goals) ? s.goals.length : Array.isArray(s?.goals?.set) ? s.goals.set.length : n, notes: shown.map((k) => { const x = notes.get(k); return { @@ -510,6 +519,34 @@ export function dietStates(schedule, render) { }); } +/** + * The diet's running day count (`diet.days`, on its front tag): `{ at, days, + * run }` wherever it changes -- the days on the current diet (dietRuns: its + * `since`, a new regime or diet number a new run) to the in-record date at the + * playhead (the running latest date of every event so far), the same number + * the streak chain's "Day N" reads; `run` null while no diet is on. + */ +export function dietDays(schedule, render) { + const m = measureOf(schedule); + const cfg = resolveMeasureExtra("diet", render); + if (!m || !cfg) return []; + const runs = dietRuns(m, cfg); + const out = []; + let date = null; + for (const { e } of stepsOf(m)) { + if (e.date) date = isoMax(date, e.date); + const t = e.t; + const run = runs.findIndex((r) => r.startT <= t + 1e-6 && (r.endT === null || r.endT > t + 1e-6)); + if (run < 0 && !out.length) continue; + const days = run >= 0 ? runDays(runs[run], isoMax(runs[run].start, date)) : null; + const last = out[out.length - 1]; + if (last && last.days === days && last.run === (run >= 0 ? run : null)) continue; + if (last && Math.abs(last.at - t) < 1e-6) out.pop(); + out.push({ at: r4(t), days, run: run >= 0 ? run : null }); + } + return out; +} + // --------------------------------------------------------------------------- // STREAK: a chain per run, cracked when it ends. // --------------------------------------------------------------------------- @@ -693,15 +730,41 @@ export const MEASURE_BOXES = Object.freeze({ /** One diet tag (`diet.form: "tags"`), design px: its width, the air between two, and the row's height. */ export const DIET_TAG = Object.freeze({ width: 220, gap: 12, height: 116 }); -/** The diet's row of `n` tags, design px. */ -export const dietTagsBox = (n) => ({ width: n * DIET_TAG.width + (n - 1) * DIET_TAG.gap, height: DIET_TAG.height }); +/** + * Where tag `i` (0 the newest) stands from the row's left, design px: side by + * side `gap` apart, or -- `overlap` above 0 -- fanned, each older one shifted + * right by the share of a tag that shows (`1 - overlap`). + */ +export const dietTagStep = (overlap = 0, days = false) => + (overlap > 0 ? Math.round(dietTagWidth(days) * (1 - overlap)) : dietTagWidth(days) + DIET_TAG.gap); + +/** The diet's row (or fan) of `n` tags, design px. */ +export const dietTagsBox = (n, overlap = 0, days = false) => ({ + width: dietTagWidth(days) + (n - 1) * dietTagStep(overlap, days), + height: DIET_TAG.height, +}); + +/** + * The goal stack ON THE SHELF (`goals.position: "shelf"`), design px: the + * count of goals set in a column at the left, then the notes fanned sideways + * like the diet's tags -- the newest in front -- each older one showing at + * least `back` (its goal's words), more when the shelf has width to give + * (shelfLayout). `natural` is that tightest fan, `widest` the notes side by side. + */ +export const GOALS_SHELF = Object.freeze({ count: 84, gap: 10, card: 250, back: 110, height: 116, step: 12 }); +export const goalsShelfWidth = (max, { widest = false } = {}) => + GOALS_SHELF.count + GOALS_SHELF.gap + GOALS_SHELF.card + (max - 1) * (widest ? GOALS_SHELF.card + GOALS_SHELF.step : GOALS_SHELF.back); -/** A module's design box: the promise clock's compact one in the column, the diet's row of tags. */ +/** A module's design box: the promise clock's compact one in the column, the diet's row of tags, the goals on the shelf. */ export function measureBox(id, render) { if (id === "promise" && resolveMeasureExtra("promise", render)?.slot === "column") return MEASURE_BOXES.promiseColumn; if (id === "diet") { const cfg = resolveMeasureExtra("diet", render); - if (cfg?.form === "tags") return dietTagsBox(cfg.tags ?? 3); + if (cfg?.form === "tags") return dietTagsBox(cfg.tags ?? 3, cfg.overlap ?? 0, cfg.days === true); + } + if (id === "goals") { + const cfg = resolveMeasureExtra("goals", render); + if (cfg?.position === SHELF_POSITION) return { width: goalsShelfWidth(cfg.max ?? 4), height: GOALS_SHELF.height }; } return MEASURE_BOXES[id]; } @@ -715,7 +778,9 @@ export const SHELF_NOTE_MIN = 160; * no shelf. Left to right in `items` order, `gap` apart: each measure extra on * it at its own design box scaled to the shelf's height (all of them a size * down together, centred in the height, when they would not fit its width); - * the note takes what width is left at its place (none under SHELF_NOTE_MIN). + * the goals' fan widens into what width is left (up to its notes side by + * side), then the note takes what is still left at its place (none under + * SHELF_NOTE_MIN). * An item that is off takes no slot. */ export function shelfLayout(render) { @@ -732,7 +797,17 @@ export function shelfLayout(render) { const fit = fixed > 0 ? Math.min(1, (rect.width - gaps) / fixed) : 1; const h = Math.max(2, evenDown(rect.height * fit)); const widths = boxes.map((b) => (b ? evenDown((b.width * h) / b.height) : 0)); - const rest = rect.width - widths.reduce((a, b) => a + b, 0) - gaps; + let rest = rect.width - widths.reduce((a, b) => a + b, 0) - gaps; + // The goals' fan takes the width left over, up to its notes side by side: its older notes show more of + // themselves rather than the shelf ending in a gap. (Then the note, in what is still left.) + const gi = items.indexOf("goals"); + if (gi >= 0 && rest > 0) { + const cfg = resolveMeasureExtra("goals", render); + const widest = evenDown((goalsShelfWidth(cfg.max ?? 4, { widest: true }) * h) / GOALS_SHELF.height); + const more = Math.max(0, Math.min(rest, widest - widths[gi])); + widths[gi] += evenDown(more); + rest -= evenDown(more); + } const noteW = items.includes("note") && rest >= SHELF_NOTE_MIN * k ? evenDown(rest) : 0; const slots = {}; let x = rect.x; diff --git a/umtool/report-to-video/measure-slice.mjs b/umtool/report-to-video/measure-slice.mjs @@ -24,6 +24,8 @@ import { chronological, dateKey, daysBetween } from "./ledger-shared.mjs"; import { PROMISE_FORMS, measureDisplay, measureQualifier, measureSchema, measureTotals, plotDate } from "./measure-totals.mjs"; import { goalCell, nextRegime, offOf } from "./panel-model.mjs"; import { offsetIn } from "./gaps.mjs"; +import { dietRecord } from "./diet-record.mjs"; +import { dietRunsOn } from "./finale.mjs"; export const MEASURE_SLICE_VERSION = 1; @@ -636,5 +638,9 @@ export function measureSlice(manifest, schedule, opts = {}) { hidden, state, totals, + // The whole diet record, for the finale's detailed runs (`deck.finale.dietRuns`): only when it asks. + ...(dietRunsOn(manifest?.render?.chrome?.deck?.finale?.dietRuns) + ? { record: dietRecord(own, s, regimeTrack, readings, isObj(manifest.render.chrome.deck.finale.dietRuns) ? manifest.render.chrome.deck.finale.dietRuns : {}) } + : {}), }; } diff --git a/umtool/report-to-video/modules/diet.mjs b/umtool/report-to-video/modules/diet.mjs @@ -8,7 +8,7 @@ import { dietHtml } from "../chrome-measure-extras.mjs"; import { dietStates } from "../measure-extras.mjs"; import { measureExtraModule } from "./measure-extras-module.mjs"; -import { DIET_FORMS, DIET_TAGS } from "./measure-extras-settings.mjs"; +import { DIET_BACK_MIN, DIET_FORMS, DIET_OVERLAP, DIET_TAGS, dietOverlapMax } from "./measure-extras-settings.mjs"; export default measureExtraModule({ id: "diet", @@ -23,6 +23,8 @@ export default measureExtraModule({ { key: "labels", type: "object", label: "Words per regime ({glp1: \"Ozempic\", …})" }, { key: "form", type: "enum", options: DIET_FORMS, label: "Drawn as (default: the stamp, the tags on the shelf)" }, { key: "tags", type: "number", min: DIET_TAGS[0], max: DIET_TAGS[1], step: 1, label: "Tags in the row", default: 3, when: { form: "tags" } }, + { key: "overlap", type: "number", min: DIET_OVERLAP[0], max: DIET_OVERLAP[1], step: 0.05, label: "Overlap (0: side by side; the share of each older tag behind the one in front)", default: 0, when: { form: "tags" } }, + { key: "days", type: "boolean", label: "Days on the diet, on the front tag", default: false, when: { form: "tags" } }, ], docs: { intro: "The diet he names as a rubber stamp in a corner of the footage box (`render.chrome.deck.diet`, measure-extras.mjs): at each change of the state's diet -- its regime or its diet number -- a new stamp slams on (in big and turned, onto the page, a shake), the regime's word in its ink and \"DIET #n\" under it with the ledger's words when they say more (\"Keto · 5 carbs a day\"); a change of words alone fades the new stamp in. A null diet after one fades to \"NO DIET\" in grey. It draws `state.diet` as the measure slice gives it -- the off-scope rule (\"off GLP-1\" while on keto is still keto) is the ledger's. The inks default to the quartering-diet regimes' (keto #E0913C, carnivore #C9534B, fasting #4E9BD8, calories #3FA9A0, glp1 #B168C6, other #8E97A8, off #98A29B).", @@ -31,6 +33,8 @@ export default measureExtraModule({ ["`deck.diet.position`, `.x`/`.y`, `.scale`", "an anchor in the footage box · design px · 0.5–2 · default `bottom-left`, unset, 1", "`umtool look <p> deck.diet.position=top-right`"], ["`deck.diet.hold`, `.finale`", "0 (up from the first diet on) or 2–600 s · `hide` `show` · default 0, `hide`", "`umtool look <p> deck.diet.hold=15`"], ["`deck.diet.form`, `.tags`", "`stamp` · `tags`: the last `tags` diets as a row of dated tags -- each a small stamp with the regime's word in its ink, \"DIET #n\" and the ledger's words (less the regime they open with: \"5 carbs a day\"), and the day he switched to it (`state.diet.since`, \"Mar 14, 2025\"; new words for the same diet keep that day); at each change the new tag slams in at the left, the older slide right and dim, the one past `tags` falls off; a change of words alone fades the new tag over the old; a null diet is a grey \"NO DIET\" tag with its date · 1–4 · default `stamp` (`tags` on the shelf), 3", "`umtool look <p> deck.diet.form=tags deck.diet.tags=2`"], + ["`deck.diet.overlap`", `${DIET_OVERLAP[0]}–${DIET_OVERLAP[1]}, the share of each older tag hidden behind the one in front · default 0 (side by side, the slam and the dim). Above 0 the tags FAN sideways the way the goal stack's notes pile: the newest in front at the left, landing from above like a goal note, each older one a place to the right behind it with its own small turn, keeping its colours (the depth is the overlap and the shadow), showing its regime word and date in the strip beside the one in front; the one past \`tags\` slides off the back. The fan is narrower by what hides. An older tag's word and date need ${DIET_BACK_MIN} design px of it, so it is refused past ${dietOverlapMax(false)} (${dietOverlapMax(true)} with \`days\`)`, "`umtool look <p> deck.diet.overlap=0.5`"], + ["`deck.diet.days`", "`true` · `false`: the front tag's running count of days on its diet (to the in-record date at the playhead, the streak chain's \"Day N\"), in a column of its own -- the tag 300 design px wide · default `false`", "`umtool look <p> deck.diet.days=true`"], ["`deck.diet.colors`, `.labels`", "`{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names", "`umtool look <p> deck.diet.labels='{\"glp1\":\"Ozempic\"}'`"], ], }, diff --git a/umtool/report-to-video/modules/finale.mjs b/umtool/report-to-video/modules/finale.mjs @@ -36,12 +36,13 @@ export default defineModule({ { key: "pips", type: "boolean", label: "The finale's clips on the rail", default: true }, { key: "timelineShare", type: "number", min: 0.38, max: 0.6, step: 0.01, label: "Timeline share (auto when unset)" }, { key: "claims", type: "enum", options: ["rotate", "all"], label: "Claim checks", default: "rotate" }, + { key: "dietRuns", type: "boolean", label: "Every diet on record under the rail (railLabels sections or none)", default: false }, ], docs: { heading: "Finale", intro: "The full reference is [The finale](#the-finale-the-timeline-in-primary-view). It reads the counter's totals (`counter.totals`) and the rail's layout (`rail.layout`); the counter reads its window (`finale.window`): a mark that would stamp inside it counts as it opens.", rows: [ - ["`deck.finale`", "`{video, motion, totals, stats, statsTitle, railLabels, pips, timelineShare, claims}`", "`umtool look <p> deck.finale='{…}'`"], + ["`deck.finale`", "`{video, motion, totals, stats, statsTitle, railLabels, pips, timelineShare, claims, dietRuns}` -- `dietRuns`: the whole diet record under the rail ([Diet runs in the finale](#diet-runs-in-the-finale))", "`umtool look <p> deck.finale='{…}'`"], ["a clip's `layout`", "`finale` on one run of clips at the end", "`umtool set <p> <clip> layout=finale`"], ], }, diff --git a/umtool/report-to-video/modules/goals.mjs b/umtool/report-to-video/modules/goals.mjs @@ -28,6 +28,7 @@ export default measureExtraModule({ rows: [ ["`deck.goals`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice", "`umtool look <p> deck.goals=false`"], ["`deck.goals.position`, `.x`/`.y`, `.scale`", "`top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1", "`umtool look <p> deck.goals.position=bottom-left`"], + ["`deck.goals.position=shelf`", "its shelf form (`deck.shelf`): the count of goals set in a column, then the notes fanned sideways like the diet's tags -- the headline goal in front when the measure state names one (\`goals.headline\`: the closest goal in force) with \"+N more\" for the others in force, else the newest; a new goal landing from above as on the pile; each older one showing its goal's words in the strip beside it (all of each when there is room); a repeat comes to the front with its ×n. The fan takes the shelf's spare width (shelfLayout), up to its notes side by side. On the shelf it stays up from the first goal (`hold` unset). What the dial draws of the goal stays on the dial", "`umtool look <p> deck.shelf.items='[\"diet\",\"goals\"]' deck.goals.position=shelf`"], ["`deck.goals.max`, `.color`, `.countdown`", "1–8 notes · #hex paper · bool · default 4, the palette's amber, `true`", "`umtool look <p> deck.goals.max=6`"], ["`deck.goals.hold`, `.finale`", "0 (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide`", "`umtool look <p> deck.goals.hold=0`"], ], diff --git a/umtool/report-to-video/modules/index.mjs b/umtool/report-to-video/modules/index.mjs @@ -41,12 +41,13 @@ import goals from "./goals.mjs"; import promise from "./promise.mjs"; import streak from "./streak.mjs"; import shelf from "./shelf.mjs"; +import runsFinale from "./runs-finale.mjs"; export { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, PLAY_CLOCKS, REGION_PLACEMENTS }; /** Every module, by z (stack order), then id. */ export const MODULES = Object.freeze( - [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur, pair, chapter, status, chat, shelf, diet, peak, goals, promise, streak, dial, odometer, trail, dialFinale] + [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur, pair, chapter, status, chat, shelf, diet, peak, goals, promise, streak, dial, odometer, trail, dialFinale, runsFinale] .sort((a, b) => a.z - b.z || a.id.localeCompare(b.id)), ); diff --git a/umtool/report-to-video/modules/measure-extras-settings.mjs b/umtool/report-to-video/modules/measure-extras-settings.mjs @@ -9,7 +9,7 @@ // render.chrome.deck.goals { show, position, x, y, scale, hold, finale, max, color, countdown } // render.chrome.deck.peak { show, position, x, y, scale, hold, finale, title, color, values } // render.chrome.deck.promise { show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks, speakers, claimVerb, claimColor } -// render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels, form, tags } +// render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels, form, tags, overlap, days } // render.chrome.deck.streak { show, position, x, y, scale, hold, finale, source, axis, title, color, colors, labels } // // Each is ON whenever the cut has a measure slice (the build writes one only @@ -70,6 +70,24 @@ export const DIET_FORMS = Object.freeze(["stamp", "tags"]); /** How many tags the diet's row keeps (`diet.tags`). */ export const DIET_TAGS = Object.freeze([1, 4]); +/** + * How much of each older tag hides behind the one in front (`diet.overlap`): + * 0 is the row of tags side by side; above it the tags fan sideways like the + * goal stack's notes, the newest in front at the left. The bounds a value is + * checked against; legibility caps it lower (dietOverlapMax: an older tag's + * regime word and date need DIET_BACK_MIN of it). + */ +export const DIET_OVERLAP = Object.freeze([0, 0.8]); + +/** The design px of an older tag that must show beside the one in front of it: its regime word and its date. */ +export const DIET_BACK_MIN = 110; + +/** A diet tag's width, design px: 220, or 300 with the running day count (`diet.days`) in a column of its own. */ +export const dietTagWidth = (days) => (days ? 300 : 220); + +/** The most overlap that keeps an older tag's regime word and date in view. */ +export const dietOverlapMax = (days) => Math.floor((1 - DIET_BACK_MIN / dietTagWidth(days)) * 100) / 100; + /** The diet regimes the ledger names (ledgerSchema.regimes), and what the badge calls each. */ export const DIET_LABELS = Object.freeze({ keto: "Keto", carnivore: "Carnivore", fasting: "Fasting", calories: "Counting calories", @@ -116,7 +134,7 @@ export const MEASURE_DEFAULTS = Object.freeze({ speakers: Object.freeze({}), claimVerb: "paid", claimColor: "#E37AB8", slot: "auto" }), // The diet badge: up from the first diet on, re-stamped at every change. // `form` "tags" (the default on the shelf): the last `tags` diets as dated tags, the newest slammed in at the left. - diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}), form: "stamp", tags: 3 }), + diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}), form: "stamp", tags: 3, overlap: 0, days: false }), // The streak chain: bottom-centre, between the diet badge and the goal // stack, so either or both can run. `title` null is the source's own word. streak: Object.freeze({ ...COMMON, position: "bottom-center", source: "diet", axis: "date", title: null, color: null, colors: Object.freeze({}), labels: Object.freeze({}) }), @@ -168,6 +186,8 @@ export function resolveMeasureExtra(id, render) { if (shelf && SHELF_EXTRAS.includes(id) && (shelf.items.includes(id) || own.position === SHELF_POSITION)) { out.position = SHELF_POSITION; out.finale = shelf.finale; + // The shelf is a HUD: what stands on it stays up from its first event (`hold` unset), the goals too. + if (own.hold === undefined) out.hold = null; if (id === "diet" && own.form === undefined) out.form = "tags"; } else if (out.position === SHELF_POSITION) { // No shelf to stand on (validateMeasureExtra says so): its default anchor, so a stray key draws something. @@ -279,6 +299,14 @@ export function validateMeasureExtra(id, v, where = `render.chrome.deck.${id}`, if (v.tags !== undefined && !(Number.isInteger(v.tags) && numIn(v.tags, DIET_TAGS[0], DIET_TAGS[1]))) { errors.push(`${where}.tags must be a whole number from ${DIET_TAGS[0]} to ${DIET_TAGS[1]}`); } + if (v.days !== undefined && typeof v.days !== "boolean") errors.push(`${where}.days must be true or false`); + if (v.overlap !== undefined) { + const max = dietOverlapMax(v.days === true); + if (!numIn(v.overlap, DIET_OVERLAP[0], DIET_OVERLAP[1])) errors.push(`${where}.overlap must be from ${DIET_OVERLAP[0]} to ${DIET_OVERLAP[1]}`); + else if (v.overlap > max) { + errors.push(`${where}.overlap ${v.overlap} hides an older tag's regime word and date: they need ${DIET_BACK_MIN} of its ${dietTagWidth(v.days === true)} design px (overlap at most ${max}${v.days === true ? "" : `, or ${dietOverlapMax(true)} with days`})`); + } + } } if (id === "diet" || id === "streak") { for (const k of ["colors", "labels"]) { diff --git a/umtool/report-to-video/modules/registry.test.mjs b/umtool/report-to-video/modules/registry.test.mjs @@ -49,7 +49,7 @@ test("the registry: unique ids and regions, sorted by z, the deck's overlays in // The order the build has always laid them in, the measure's instruments beside the side panel; the // finale over all of them but the dial's finale and the promise clock, drawn over it (z 95 both); the shelf's // note page under the measure extras (it never meets them: they stand in slots of their own beside it). - assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "chat", "stats", "pair", "status", "fx", "shelf", "streak", "diet", "peak", "goals", "threads", "dial", "odometer", "trail", "flips", "chapter", "finale", "dial-finale", "promise"]); + assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "chat", "stats", "pair", "status", "fx", "shelf", "streak", "diet", "peak", "goals", "threads", "dial", "odometer", "trail", "flips", "chapter", "finale", "runs-finale", "dial-finale", "promise"]); assert.equal(moduleOfRegion("deck").id, "shell"); assert.equal(regionModule("posts").id, "popup-posts"); assert.throws(() => regionModule("nope"), /unknown chrome region: nope/); @@ -153,7 +153,7 @@ test("play: a live-preview contract only an overlay with a page and regions decl assert.throws(() => defineModule({ ...base, play: { clock: "cut", ready: "x" } }), /play must be/); assert.throws(() => defineModule({ ...base, page: undefined, play: { clock: "cut", ready: "x:ready" } }), /only an overlay with a page/); assert.throws(() => defineModule({ ...base, kind: "segment", play: { clock: "cut", ready: "x:ready" } }), /only an overlay with a page/); - assert.deepEqual(playModules().map((m) => m.id), ["stats", "pair", "status", "fx", "shelf", "streak", "diet", "peak", "goals", "threads", "dial", "odometer", "trail", "flips", "chapter", "dial-finale", "promise"]); + assert.deepEqual(playModules().map((m) => m.id), ["stats", "pair", "status", "fx", "shelf", "streak", "diet", "peak", "goals", "threads", "dial", "odometer", "trail", "flips", "chapter", "runs-finale", "dial-finale", "promise"]); for (const m of playModules()) assert.equal(m.play.ready, `${m.region}:ready`, m.id); }); diff --git a/umtool/report-to-video/modules/runs-finale.mjs b/umtool/report-to-video/modules/runs-finale.mjs @@ -0,0 +1,71 @@ +// THE FINALE'S DETAILED DIET RUNS (module `runs-finale`, region `runs-finale`): +// with `deck.finale.dietRuns: true`, the whole record of his diets drawn large +// in the finale's timeline panel under the rail -- every run from the earliest +// row, the empty years a marked break, the stops and the medication marked, +// his stated weights over it, the longest runs and the one still going +// labelled (chrome-runs-finale.mjs, the measure slice's `record`). A window over +// the finale's, laid over it; off by default. +import path from "node:path"; + +import { snapWindow } from "../deck.mjs"; +import { recordOf, runsFinaleGeometry, runsFinaleHtml, runsFinaleWanted } from "../chrome-runs-finale.mjs"; +import { assertRegion, defineModule } from "./contract.mjs"; + +const drawn = (schedule, render) => !!schedule?.finale && runsFinaleWanted(render) && !!recordOf(schedule) && !!runsFinaleGeometry(schedule, render); + +export default defineModule({ + id: "runs-finale", + version: 1, + z: 94, + kind: "overlay-window", + slot: "full", + title: "Diet runs in the finale", + summary: "The finale's detailed diet record: every run from the first row a bar in its diet's ink, the empty years a break, the stops and medication marked, his weights over it, the long runs and the open one labelled.", + docs: { + heading: "Diet runs in the finale", + intro: "With `deck.finale.dietRuns: true` (and a measure ledger with a regime track), the finale's timeline panel -- under the large rail's track, the rail's width, down to the panel's foot: with the weight layer (120, 202) 1704×220 at 1080p, the track staying where its labels put it and the timeline taking the room under it (up to `FINALE_SHARE.max`); without it 1704×122 -- carries the WHOLE record of his diets (the measure slice's `record`, diet-record.mjs: every regime row in scope, on camera or not, through the state's own rule): each run a bar in its diet's ink on a time axis from the earliest row; a stretch of more than two years with nothing on record squeezed to a marked break (\"2013–2018\"), and a run whose end the record does not have fading into it; a row that stopped a diet a grey tick under the bars, one naming the medication (GLP-1) a purple one; his stated weights a light line over the bars, the weights the video marks (`marks`: his heaviest as THE peak) and his low as labelled dots on it; the run still going and the longest ones labelled in two rows under the bars where they fit -- the diet's word (the run's own name when its row gives one: \"WEIGHT WATCHERS\"), its number when the cut showed it (\"DIET #6\", the shelf's), its dates and its days, the open one \"N days and counting\" to the in-record date. It sweeps in left to right over 2.6 s after the finale's grow, each label as the sweep reaches it, then holds; it stands clear of the side video, the lower column's instruments and the promise clock. It needs `deck.finale.railLabels` `sections` or `none` (the pips' labels and dates use that space) and at least 100 px under the rail.", + rows: [ + ["`deck.finale.dietRuns`", "`true` · `false` · `{weights, marks, low}` · default `false`", "`umtool look <p> deck.finale.dietRuns=true`"], + ["`deck.finale.dietRuns.weights`", "`applied` · `said` · `false` · default `applied`: the WEIGHT LAYER over the bars on the dial's scale (the panel 218 design px, the finale's timeline taking that room under the track) -- every weight he gave (a `current` or `past` row with a number) at the day it APPLIED (its asOf, else its date; `said`: the day he said it). Given at the time: solid, joined -- his claimed trajectory (a bound like \"over 240\" is a point, not joined). Told 30 days or more after it applied: hollow, with a thin leader to a tick at the day he said it, so a retold weight piles up at one period from its tellings. `>`/`<` a caret, `≈` a ring, a range a bar. A loss or gain (`delta`) and \"N over\" (`overweight_by`) name no weight the ledger resolves: left out (the record counts them, `record.leftOut`). `false`: the light line of his stated weights alone", "`umtool look <p> deck.finale.dietRuns='{\"weights\":\"said\"}'`"], + ["`deck.finale.dietRuns.marks`", "up to 8 `{row, label, peak?}`: a dot on the weight line at the row's day (its asOf, else its date) and value, the label -- his words, at most 60 characters -- and the month beside it; THE peak (the one marked `peak`, else the heaviest marked) a size up in the needle's red. A row the ledger lacks is left out", "`umtool look <p> deck.finale.dietRuns='{\"marks\":[{\"row\":\"w21\",\"label\":\"his heaviest · \\\"almost 400\\\"\"}]}'`"], + ["`deck.finale.dietRuns.low`", "`true` · `false` · its label · default `true`: the lowest weight he stated (never a bound like \"over 240\"; of one weigh-in told twice the same day, the fuller: 291.5 over \"291.\") marked in the accent, \"his low · 291.5\"", "`umtool look <p> deck.finale.dietRuns='{\"low\":false}'`"], + ], + }, + region: "runs-finale", + workers: "narrow", + noun: "the finale's diet runs'", + on: drawn, + check: (schedule, render) => { + if (!schedule?.finale) return "the finale's diet runs need a schedule with a finale (a clip with layout \"finale\")"; + if (!runsFinaleWanted(render)) return "the finale's diet runs are off (render.chrome.deck.finale.dietRuns)"; + if (!recordOf(schedule)) return "the finale's diet runs need the measure slice's diet record (a measure ledger with a regime track, and render.chrome.deck.measure)"; + if (!runsFinaleGeometry(schedule, render)) return "the finale's diet runs need 100 px under the large rail (a larger deck.finale.timelineShare)"; + return null; + }, + window: (schedule, { fps, total }) => snapWindow({ segment: "runs-finale", from: schedule.finale.from, to: schedule.finale.to }, { fps, total }), + names: ({ preview }) => ({ project: `runs-finale${preview ? "-preview" : ""}`, stem: "runs-finale" }), + async page(ctx) { + const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); + return runsFinaleHtml(ctx.schedule, ctx.render, ctx.window, { fonts }); + }, + /** Over the finale's window, laid at its own second. */ + regions(schedule, { render, outDir, shift = 0, clip = null }) { + const f = schedule?.finale; + if (!f || !drawn(schedule, render)) return []; + const g = runsFinaleGeometry(schedule, render); + const fps = Number(schedule.fps ?? render.fps); + const s = snapWindow({ segment: "runs-finale", from: f.from, to: f.to }, { fps, total: schedule.total }); + if (clip && !(s.from < clip.at + clip.dur && s.to > clip.at)) return []; + return [assertRegion({ + name: "runs-finale", + frames: path.join(outDir, "chrome", "runs-finale-frames"), + ...g, + offset: s.from - shift, + frameCount: s.frames, + window: s, + }, "window")]; + }, + play: { clock: "cut", ready: "runs-finale:ready" }, + // A window of the cut, as the finale's: its frame n is cut time `from` + n / fps. + frameKeys: { data: "runs-finale-data", omit: ["init", "cues", "from", "dur"], offset: "from" }, +}); diff --git a/umtool/report-to-video/modules/shelf.mjs b/umtool/report-to-video/modules/shelf.mjs @@ -35,7 +35,7 @@ export default defineModule({ ], docs: { heading: "Shelf", - intro: `A strip of the frame cleared beside the footage (\`render.chrome.deck.shelf\`, shelf-settings.mjs): the footage moves to the frame's top, \`railGap\` (24 px) in (\`side: "below"\`), or down onto the deck (\`"above"\`), and what it leaves -- as wide as the footage, 24 px clear of it and of the frame's edge or the deck -- is the shelf (beside the instruments' column, 1248×116 at (24, 750)). Everything that reads the footage box (the instruments, the posts, the chapter band, the finale, Play) follows it. Its occupants stand in it left to right in \`items\` order, \`gap\` apart, each at its own width scaled to the shelf's height (all a size down together when they would not fit): the measure extras that take \`position: "shelf"\` -- \`diet\` (its dated tags by default: \`deck.diet.form\`), \`streak\`, \`goals\`, \`peak\` -- and \`note\`, an entry's \`shelfNote\` in the width left (a chip that comes and goes with its entry; at least 160 px). Nothing covers the shelf, so its occupants never dodge a post card or a chapter band (an entry's \`hideModules\` still hides one). It needs ${SHELF_MIN} px of room or the deck refuses, naming the way out (a smaller \`footageScale\`, or \`subtitle.lines 1\`): with the instruments' column it is 116 px, 77 with \`subtitle.lines: 2\`; full-width footage at the default 0.82 leaves none. Off (absent, \`false\`), the footage stands where it always did.`, + intro: `A strip of the frame cleared beside the footage (\`render.chrome.deck.shelf\`, shelf-settings.mjs): the footage moves to the frame's top, \`railGap\` (24 px) in (\`side: "below"\`), or down onto the deck (\`"above"\`), and what it leaves -- as wide as the footage, 24 px clear of it and of the frame's edge or the deck -- is the shelf (beside the instruments' column, 1248×116 at (24, 750)). Everything that reads the footage box (the instruments, the posts, the chapter band, the finale, Play) follows it. Its occupants stand in it left to right in \`items\` order, \`gap\` apart, each at its own width scaled to the shelf's height (all a size down together when they would not fit; a goal stack on it takes the width left over, its notes fanning wider, so the shelf does not end in a gap): the measure extras that take \`position: "shelf"\` -- \`diet\` (its dated tags by default: \`deck.diet.form\`), \`streak\`, \`goals\`, \`peak\` -- and \`note\`, an entry's \`shelfNote\` in the width left (a chip that comes and goes with its entry; at least 160 px). Nothing covers the shelf, so its occupants never dodge a post card or a chapter band (an entry's \`hideModules\` still hides one). It needs ${SHELF_MIN} px of room or the deck refuses, naming the way out (a smaller \`footageScale\`, or \`subtitle.lines 1\`): with the instruments' column it is 116 px, 77 with \`subtitle.lines: 2\`; full-width footage at the default 0.82 leaves none. Off (absent, \`false\`), the footage stands where it always did.`, rows: [ ["`deck.shelf`", "`true` · `false` · `{show, side, items, gap, finale}` · default off", "`umtool look <p> deck.shelf=true deck.diet.position=shelf deck.streak.position=shelf`"], ["`deck.shelf.side`", "`below` (the footage at the top) · `above` (the footage on the deck) · default `below`", "`umtool look <p> deck.shelf.side=above`"], diff --git a/umtool/report-to-video/runs-finale.test.mjs b/umtool/report-to-video/runs-finale.test.mjs @@ -0,0 +1,163 @@ +// The finale's detailed diet runs (`deck.finale.dietRuns`; diet-record.mjs, +// chrome-runs-finale.mjs, modules/runs-finale.mjs): the whole diet record from +// its earliest row, an empty stretch a break, the stops and the medication +// marked, in the finale's panel under the rail -- and nothing of it unless asked. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; + +import { dietRecord, runName } from "./diet-record.mjs"; +import { RUNS_BREAK_DAYS, runsAxis, runsFinaleGeometry, runsFinaleHtml } from "./chrome-runs-finale.mjs"; +import { validateFinaleSettings } from "./finale.mjs"; +import { measureSchema } from "./measure-totals.mjs"; +import { measureSlice } from "./measure-slice.mjs"; +import { moduleById } from "./modules/index.mjs"; + +const SCHEMA = { + kind: "measure", unit: "lb", yMin: 210, yMax: 400, bandGapDays: 60, + tracks: [ + { key: "weight", role: "value", label: "Weight" }, + { key: "regime", role: "regime", label: "Diet", regimes: ["keto", "carnivore", "calories", "glp1", "off"], offKey: "off" }, + ], + forms: ["current", "past", "delta", "goal", "goal_loss", "overweight_by", "status"], + regimes: [ + { key: "keto", label: "Keto" }, { key: "carnivore", label: "Carnivore" }, { key: "calories", label: "Counting calories" }, + { key: "glp1", label: "GLP-1" }, { key: "off", label: "No diet" }, + ], +}; +const row = (o) => ({ scope: "weight", scopeBasis: "his words", scopeConfidence: "read", valueKind: "uttered", flags: [], asOf: null, ...o }); +const LEDGER = [ + // 2013 (MeVsMe): Weight Watchers, three weights -- then nothing until 2018. + row({ id: "r105", date: "2013-02-22", scope: "regime", population: "status", value: "calories", event: "start", display: "Weight Watchers" }), + row({ id: "w127", date: "2013-03-09", asOf: "2013-03-02", population: "current", value: 345, display: "345 lb" }), + row({ id: "w130", date: "2013-03-21", population: "current", value: 342.9, display: "342.9 lb" }), + row({ id: "r07", date: "2021-09-14", scope: "regime", population: "status", value: "keto", event: "start", display: "Keto", entryId: "c1" }), + row({ id: "r11", date: "2022-07-27", scope: "regime", population: "status", value: "keto", event: "off", display: "off Keto" }), + row({ id: "r14", date: "2022-12-30", scope: "regime", population: "status", value: "carnivore", event: "on", display: "Carnivore", entryId: "c2" }), + row({ id: "r40", date: "2024-04-25", scope: "regime", population: "status", value: "glp1", event: "off", display: "off GLP-1" }), + row({ id: "w50", date: "2024-05-01", population: "current", value: 330, display: "330 lb", entryId: "c2" }), +]; +const TIMELINE = [ + { type: "clip", id: "c1", video: "v1", start: 0, end: 10, quoteStart: 1 }, + { type: "clip", id: "c2", video: "v2", start: 0, end: 10, quoteStart: 1, layout: "finale" }, +]; +const SEGMENTS = [{ id: "c1", start: 0, duration: 10 }, { id: "c2", start: 10, duration: 10 }]; +const PALETTE = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; +const renderOf = (finale = { railLabels: "sections", dietRuns: true }) => ({ + width: 1920, height: 1080, fps: 30, transition: 0, palette: PALETTE, + chrome: { engine: "hyperframes", layout: "deck", deck: { measure: { scopes: ["weight", "regime"], scale: { min: 220, max: 400 } }, finale } }, +}); +const manifest = (render = renderOf()) => ({ ledgerSchema: SCHEMA, ledger: LEDGER, timeline: TIMELINE, render }); + +test("the record: every regime row from the earliest, runs by the state's rule, named by their own words; stops and medication marked", () => { + const own = LEDGER; + const readings = LEDGER.filter((r) => r.scope === "weight"); + const rec = dietRecord(own, measureSchema(SCHEMA), "regime", readings); + assert.equal(rec.from, "2013-02-22"); + assert.deepEqual(rec.runs.map((r) => [r.n, r.key, r.since, r.end, r.ended, r.name]), [ + [1, "calories", "2013-02-22", "2021-09-14", "new", "Weight Watchers"], + [2, "keto", "2021-09-14", "2022-07-27", "off", null], + [3, "carnivore", "2022-12-30", null, null, null], + ]); + assert.deepEqual(rec.marks.map((m) => [m.row, m.kind]), [["r11", "off"], ["r40", "off"]]); + assert.deepEqual(rec.weights.map((w) => [w.date, w.value]), [["2013-03-02", 345], ["2013-03-21", 342.9], ["2024-05-01", 330]], "by the day it was his weight"); + assert.equal(runName("Keto · 5 carbs a day", { key: "keto", label: "Keto" }), null); + assert.equal(runName("off GLP-1", { key: "glp1", label: "GLP-1" }), null); +}); + +test("the slice carries the record only when the finale asks for it", () => { + const off = measureSlice(manifest(renderOf({ railLabels: "sections" })), { segments: SEGMENTS }, { asOf: "2026-11-03" }); + assert.equal("record" in off, false, "a cut without it writes the slice it always did"); + const on = measureSlice(manifest(), { segments: SEGMENTS }, { asOf: "2026-11-03" }); + assert.equal(on.record.runs.length, 3); +}); + +test("the axis: an empty stretch past two years squeezed to a marked break; the years on the rest", () => { + const A = runsAxis(["2013-02-22", "2013-03-21", "2021-09-14", "2022-07-27", "2024-05-01"], 1704, { brk: 44, pad: 8 }); + assert.equal(A.breaks.length, 1); + assert.deepEqual([A.breaks[0].from, A.breaks[0].to], ["2013-03-21", "2021-09-14"]); + assert.equal(Math.round(A.breaks[0].x1 - A.breaks[0].x0), 44); + assert.ok(A.x("2024-05-01") <= 1704 - 8 + 1e-6); + assert.deepEqual(A.years.map((y) => y.year), [2022, 2023, 2024], "no year ticks inside the break"); + assert.ok(RUNS_BREAK_DAYS === 730); +}); + +test("validation and the page: railLabels must leave the space; the page labels the open run 'and counting'", () => { + assert.match(validateFinaleSettings({ dietRuns: true }).join(), /dietRuns draws under the rail, where railLabels "all" puts the pips' words: set render\.chrome\.deck\.finale\.railLabels "sections" or "none"/); + assert.deepEqual(validateFinaleSettings({ dietRuns: true, railLabels: "none" }), []); + assert.match(validateFinaleSettings({ dietRuns: "yes" }).join(), /dietRuns must be true, false or \{ marks, low, weights \}/); + const r = renderOf(); + const m = measureSlice(manifest(r), { segments: SEGMENTS }, { asOf: "2026-11-03" }); + const schedule = { kind: "deck", fps: 30, total: 20, transition: 0, segments: SEGMENTS.map((s) => ({ ...s, end: s.start + s.duration, type: "clip", title: "", subtitle: "" })), finale: { segments: ["c2"], from: 10.5, to: 20, video: "side", motion: "grow", grow: 0.8 }, measure: m }; + const g = runsFinaleGeometry(schedule, r); + assert.ok(g && g.x === 120 && g.y > 200 && g.height >= 100, JSON.stringify(g)); + const { html, items } = runsFinaleHtml(schedule, r, { from: 10.5, to: 20 }, { fonts: {} }); + assert.match(html, /CARNIVORE/); + assert.match(html, /days and counting/); + assert.match(html, /WEIGHT WATCHERS/); + assert.match(html, /2013–2021/, "the break says what it spans"); + assert.ok(items.length >= 2); + const mod = moduleById("runs-finale"); + assert.equal(mod.on(schedule, r), true); + assert.equal(mod.on(schedule, renderOf({ railLabels: "sections" })), false, "off by default"); +}); + +test("marks on the weight line: the author's rows with his words, the heaviest THE peak; the low by default, never a bound", async () => { + const { recordPoints } = await import("./diet-record.mjs"); + const rows = [ + ...LEDGER, + row({ id: "w21", date: "2023-09-29", asOf: "2023-02-24", population: "past", value: 390, qualifier: "≈", display: "390 lb" }), + row({ id: "w07", date: "2022-06-15", population: "current", value: 240, qualifier: ">", display: "over 240" }), + row({ id: "w117", date: "2026-10-23", population: "current", value: 291, display: "291." }), + row({ id: "w118", date: "2026-10-26", asOf: "2026-10-23", population: "current", value: 291.5, display: "291.5 lb" }), + ]; + const readings = rows.filter((r) => r.scope === "weight"); + const pts = recordPoints(rows, readings, { marks: [{ row: "w21", label: "his heaviest · \"almost 400\"" }, { row: "w127", label: "2013 · 345" }, { row: "nope", label: "x" }] }); + assert.deepEqual(pts.map((p) => [p.row, p.date, p.value, p.kind]), [ + ["w127", "2013-03-02", 345, "mark"], + ["w21", "2023-02-24", 390, "peak"], + ["w118", "2026-10-23", 291.5, "low"], + ], "by the day it was his weight; the heaviest the peak; the low not 'over 240', and 291.5 over the same day's '291.'"); + assert.equal(pts[2].label, "his low · 291.5"); + assert.deepEqual(recordPoints(rows, readings, { low: false }), []); + assert.equal(recordPoints(rows, readings, { marks: [{ row: "w127", label: "a", peak: true }, { row: "w21", label: "b" }] })[0].kind, "peak", "the one marked peak"); + assert.deepEqual(validateFinaleSettings({ railLabels: "sections", dietRuns: { marks: [{ row: "w21", label: "his heaviest" }], low: "his low" } }), []); + assert.match(validateFinaleSettings({ railLabels: "sections", dietRuns: { marks: [{ row: "w21" }], lowest: true } }).join(), /dietRuns\.lowest is not a diet-runs setting.*marks\[0\]\.label/s); + const on = measureSlice({ ...manifest(renderOf({ railLabels: "none", dietRuns: { marks: [{ row: "w127", label: "2013" }] } })), ledger: rows }, { segments: SEGMENTS }, { asOf: "2026-11-03" }); + assert.deepEqual(on.record.points.map((p) => p.kind), ["peak", "low"]); +}); + +test("the weight layer: every weight he gave at the day it applied, the retold ones apart; losses and 'N over' left out and counted", async () => { + const { weightClaims } = await import("./diet-record.mjs"); + const rows = [ + ...LEDGER, + row({ id: "w21", date: "2023-09-29", asOf: "2023-02-24", population: "past", value: 390, qualifier: "≈", display: "390 lb" }), + row({ id: "w07", date: "2022-06-15", population: "current", value: 240, qualifier: ">", display: "over 240" }), + row({ id: "d1", date: "2024-02-01", population: "delta", value: -19.4, display: "-19.4" }), + row({ id: "o1", date: "2023-08-18", population: "overweight_by", value: 100, display: "100 over" }), + row({ id: "g1", date: "2023-08-18", population: "goal_loss", value: -100, display: "lose 100" }), + ]; + const { claims, leftOut } = weightClaims(rows); + assert.deepEqual(claims.map((c) => [c.row, c.applied, c.said, c.retold, c.qualifier]), [ + ["w127", "2013-03-02", "2013-03-09", false, null], + ["w130", "2013-03-21", "2013-03-21", false, null], + ["w07", "2022-06-15", "2022-06-15", false, ">"], + ["w21", "2023-02-24", "2023-09-29", true, "≈"], + ["w50", "2024-05-01", "2024-05-01", false, null], + ], "a week's asOf is still his weight then; seven months on is a retelling"); + assert.deepEqual(leftOut, { delta: 1, overweight_by: 1 }); + assert.match(validateFinaleSettings({ railLabels: "none", dietRuns: { weights: "both" } }).join(), /weights must be "applied", "said" or false/); + const r = renderOf({ railLabels: "sections", dietRuns: { weights: "applied" } }); + const m = measureSlice({ ...manifest(r), ledger: rows }, { segments: SEGMENTS }, { asOf: "2026-11-03" }); + const schedule = { kind: "deck", fps: 30, total: 20, transition: 0, segments: SEGMENTS.map((s) => ({ ...s, end: s.start + s.duration, type: "clip", title: "", subtitle: "" })), finale: { segments: ["c2"], from: 10.5, to: 20, video: "side", motion: "grow", grow: 0.8 }, measure: m }; + const g = runsFinaleGeometry(schedule, r); + assert.ok(g.height >= 200, `the layer has its room under the track (${g.height})`); + const { html } = runsFinaleHtml(schedule, r, { from: 10.5, to: 20 }, { fonts: {} }); + assert.match(html, /class="hol"/, "a retold weight hollow"); + assert.match(html, /class="ldr"/, "its leader to the day he said it"); + assert.match(html, /class="car"/, "a bound's caret"); + assert.match(html, /class="apx"/, "an about's ring"); + const off = runsFinaleHtml(schedule, renderOf({ railLabels: "sections", dietRuns: { weights: false } }), { from: 10.5, to: 20 }, { fonts: {} }).html; + assert.doesNotMatch(off, /class="hol"/); +}); diff --git a/umtool/report-to-video/shelf.test.mjs b/umtool/report-to-video/shelf.test.mjs @@ -10,10 +10,10 @@ import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; -import { dietHtml, tagWords, tagWordSize } from "./chrome-measure-extras.mjs"; +import { dietHtml, goalsHtml, tagWords, tagWordSize } from "./chrome-measure-extras.mjs"; import { shelfHtml, shelfNoteGeometry } from "./chrome-shelf.mjs"; import { deckGeometry, entryShelfNotes, estimateSchedule, instrumentsGeometry, parseShelfNote, validateChrome } from "./deck.mjs"; -import { dietStates, measureExtraGeometry, measurePlacements, shelfLayout } from "./measure-extras.mjs"; +import { dietDays, dietStates, goalStates, dietTagsBox, GOALS_SHELF, goalsShelfWidth, measureExtraGeometry, measurePlacements, shelfLayout, streakStates } from "./measure-extras.mjs"; import { slotRect } from "./modules/layout.mjs"; import { moduleById, moduleProblems, scheduleSlices } from "./modules/index.mjs"; import { resolveMeasureExtra, validateMeasureExtra } from "./modules/measure-extras-settings.mjs"; @@ -202,3 +202,81 @@ test("the shelf's note: an entry's shelfNote over its span, only with the shelf assert.match(html, /Weighed in on camera/); assert.match(mod.check(s, renderOf(INSTRUMENTS)), /shelf region is off/); }); + +// --------------------------------------------------------------------------- +// THE FAN (operator, 6 Nov: "overlap cards like the goals do but to the side, we can keep the cards the same +// color ... a 'x days' number showing on the diet card"; "put the goal alongside this new diet hud space"). +// --------------------------------------------------------------------------- + +const FAN = { ...INSTRUMENTS, shelf: { items: ["diet", "goals"] }, diet: { position: "shelf", overlap: 0.6, days: true }, goals: { position: "shelf" }, streak: false }; + +test("overlap: the tags fan sideways, the width shrinking by what hides; capped where an older tag's word and date still show", () => { + assert.deepEqual(dietTagsBox(3), { width: 684, height: 116 }, "0: the row as it was"); + assert.deepEqual(dietTagsBox(3, 0.5), { width: 220 + 2 * 110, height: 116 }); + assert.deepEqual(dietTagsBox(3, 0.6, true), { width: 300 + 2 * 120, height: 116 }, "with the day count a tag is 300 wide"); + assert.match(validateMeasureExtra("diet", { overlap: 0.6 }).join(), /overlap 0\.6 hides an older tag's regime word and date: they need 110 of its 220 design px \(overlap at most 0\.5, or 0\.63 with days\)/); + assert.deepEqual(validateMeasureExtra("diet", { overlap: 0.6, days: true }), []); + assert.match(validateMeasureExtra("diet", { overlap: 0.9, days: true }).join(), /overlap must be from 0 to 0\.8/); + assert.match(validateMeasureExtra("diet", { days: "yes" }).join(), /days must be true or false/); + assert.deepEqual(validateChrome(renderOf(FAN).chrome, renderOf(FAN)), []); +}); + +test("the page: older tags behind the newest, their own colours (no dim), each with its strip; the newest lands like a goal note", () => { + const r = renderOf(FAN); + const { html, items } = dietHtml(schedule(), r, { fonts: {} }); + assert.match(html, /class="tg" data-k="t3" style="z-index:13"/, "the newer, the nearer"); + assert.match(html, /<div class="bk" data-k="t0\.b">/, "the strip an older tag shows"); + assert.ok(!/"k":"t\d+\.d","at":[\d.]+,"dur":[\d.]+,"from":\{"opacity":1\},"to":\{"opacity":0\.45/.test(html), "nothing dims"); + assert.match(html, /"to":\{"x":0,"y":-?\d+,"rotation":-?[\d.]+,"scale":1,"autoAlpha":1\},"ease":"back\.out\(1\.3\)"/, "the goal note's landing"); + assert.ok(items.length > 0); + // The region is the fan's, at the shelf's height. + assert.deepEqual(measureExtraGeometry("diet", r), { x: 24, y: 750, width: 540, height: 116 }); +}); + +test("days: the front tag's running count is the streak chain's day count, to the in-record date at the playhead", () => { + const withStreak = renderOf({ ...FAN, streak: { position: "bottom-center" } }); + const days = dietDays(schedule(), withStreak); + const { states } = streakStates(schedule(), withStreak); + for (const st of states.filter((x) => x.live)) { + const d = [...days].reverse().find((x) => x.at <= st.at + 1e-6); + assert.equal(d.days, st.live.days, `at ${st.at}`); + } + const { html } = dietHtml(schedule(), renderOf(FAN), { fonts: {} }); + assert.match(html, /<div class="dy" data-k="t\d+\.y\d+"><div class="dyn">\d+<\/div><div class="dyl">days?<\/div><\/div>/); + // Off (the default): no count, the tag as it was. + assert.doesNotMatch(dietHtml(schedule(), renderOf(SHELF), { fonts: {} }).html, /class="dy"/); +}); + +test("goals on the shelf: the count and the fanned notes, the fan taking the shelf's spare width", () => { + const r = renderOf(FAN); + assert.equal(goalsShelfWidth(4), GOALS_SHELF.count + GOALS_SHELF.gap + 250 + 3 * 110); + const L = shelfLayout(r); + assert.deepEqual(L.slots.diet, { x: 24, y: 750, width: 540, height: 116 }); + assert.deepEqual(L.slots.goals, { x: 24 + 540 + 16, y: 750, width: 1248 - 540 - 16, height: 116 }, "no gap at the shelf's end"); + assert.equal(resolveMeasureExtra("goals", r).hold, null, "on the shelf it stays up"); + const { html, items } = goalsHtml(schedule(), r, { fonts: {} }); + assert.match(html, /<div class="gc"><div class="gn" data-k="s0\.c">1<\/div><div class="gl">goal set<\/div><\/div>/); + assert.match(html, /class="note" data-k="s\d+\.n\d+" style="z-index:19"><div class="tape"><\/div><div class="nf"/); + assert.match(html, /<div class="nb"[^>]*><div class="bt">LOSE 100<\/div>/, "an older note shows its words beside the one in front"); + assert.equal(items.length, goalStates(schedule(), r).length); + // Off the shelf: the pile in the footage, as it was. + assert.doesNotMatch(goalsHtml(schedule(), renderOf(INSTRUMENTS), { fonts: {} }).html, /class="gc"/); +}); + +test("goals on the shelf: the headline goal leads when the state names one (goals.headline), with the ladder's count; else the newest", () => { + const r = renderOf(FAN); + const m = clone(MEASURE); + // The state as the dial-ghosts lane writes it: goals an object with the headline (a goal carrying its row) and those in force. + const firstGoal = m.events.findIndex((e) => e.kind === "goal" || e.kind === "goalLoss"); + const lastGoal = m.events.map((e, i) => [e, i]).filter(([e]) => e.kind === "goal" || e.kind === "goalLoss").at(-1)[1]; + const hl = m.events[firstGoal].row; + const s = m.state[lastGoal + 1]; + s.goals = { set: Array.isArray(s.goals) ? s.goals : [], headline: { row: hl }, active: [hl, "x", "y"] }; + const states = goalStates(schedule({ measure: m }), r); + assert.equal(states.at(-1).headline, states[0].top, "the first goal's note heads the last state"); + assert.equal(states.at(-1).active, 3); + const { html } = goalsHtml(schedule({ measure: m }), r, { fonts: {} }); + assert.match(html, /<div class="mo">\+2 more<\/div>/); + // Without it, the newest leads, as before. + assert.equal("headline" in goalStates(schedule(), r).at(-1), false); +});