// THE TRAIL'S PLAN (trail-plan.mjs; chrome-instruments.mjs trailHtml): the by-date chart shows every weight said // so far -- stated and remembered -- on axes that fit them and reflow as each lands, its time axis broken across // long empty stretches (rev9-a7, 11 Nov: a 2013 dot pinned at the left edge for minutes, 2008 and ≈390 never drawn, // one line across a decade to the 2025–26 points squeezed at the right). import assert from "node:assert/strict"; import test from "node:test"; import { trailHtml } from "./chrome-instruments.mjs"; import { estimateSchedule } from "./deck.mjs"; import { clustersOf, GAP_FLOOR_DAYS, gapThreshold, trailLayout, trailLine, trailPoints, trailStates } from "./trail-plan.mjs"; import { dayNumber } from "./measure-draw.mjs"; import { validateTrail } from "./instruments.mjs"; /** The a7 sequence: a 2013 weigh-in and a second 2013 weight; a remembered ≈390 (as of Feb 2023) above them; a * remembered 368 as of 2008 -- before everything and above the old top; then the dense 2025–26 run. */ const ev = (t, kind, value, date, extra = {}) => ({ t, kind, value, date, row: `r${t}`, scope: "weight", qualifier: null, asOf: null, ...extra }); const EVENTS = [ ev(9, "stated", 346.7, "2013-03-09"), ev(31, "stated", 342.9, "2013-03-21"), ev(60, "remembered", 390, "2023-09-29", { asOf: "2023-02-24", qualifier: "≈" }), ev(100, "remembered", 368, "2025-01-10", { asOf: "2008-06-30" }), ev(175, "stated", 349, "2025-04-08"), ev(204, "stated", 341, "2025-06-02"), ev(225, "stated", 336, "2025-07-15"), ev(230, "stated", 331.5, "2025-08-01"), ev(280, "stated", 322, "2025-10-08"), ev(293, "stated", 318, "2025-11-20"), ev(320, "stated", 305, "2026-01-16"), ev(324, "stated", 299, "2026-03-02"), ev(337, "stated", 296, "2026-06-01", { qualifier: "≈" }), ev(347, "goal", 250, "2026-07-01"), ]; const MEASURE = { unit: "lb", scale: { min: 220, max: 400 }, events: EVENTS, state: [{ t: 0 }], totals: {} }; const BOX = { x0: 54, x1: 582, y0: 38, y1: 174, gapPx: 22, yearPx: 34 }; test("the trail's points: stated and remembered, each at its own date (asOf first), in the cut's order", () => { const pts = trailPoints(MEASURE); assert.equal(pts.length, 13, "the goal is not a weight"); assert.deepEqual(pts.map((p) => p.kind).slice(0, 5), ["stated", "stated", "remembered", "remembered", "stated"]); assert.equal(pts[3].day, dayNumber("2008-06-30"), "a remembered weight stands at the day it was his weight"); assert.equal(trailPoints(MEASURE, { remembered: false }).length, 11); }); test("at every moment the chart shows exactly the weights said by then, on axes that contain all of them", () => { const pts = trailPoints(MEASURE); const states = trailStates(pts, BOX, { mark: 300 }); assert.equal(states.length, 13); for (const st of states) { const shown = pts.filter((p) => p.t <= st.at); assert.equal(st.shown.length, shown.length, `at ${st.at}`); for (const p of shown) { assert.ok(st.layout.lo <= p.value && p.value <= st.layout.hi, `at ${st.at}: ${p.value} inside ${st.layout.lo}–${st.layout.hi}`); const { x, y } = st.pos.get(p.n); assert.ok(x !== null && x >= BOX.x0 && x <= BOX.x1, `at ${st.at}: ${p.value} on the x axis (${x})`); assert.ok(y >= BOX.y0 && y <= BOX.y1, `at ${st.at}: ${p.value} on the y axis (${y})`); } } // The first weigh-in alone: in the middle of the strip, not pinned to its left edge. const one = states[0].pos.get(0).x; assert.ok(one > BOX.x0 + 100 && one < BOX.x1 - 100, `a lone point stands mid-strip (${one})`); // The remembered ≈390 raises the top; the 2008 one moves the start of time back and keeps 390 in. assert.ok(states[1].layout.hi < 390 && states[2].layout.hi >= 390); assert.ok(states[3].pos.get(3).x < states[3].pos.get(0).x, "2008 stands left of 2013"); // The axes advance with the story: no 2026 on the axis until a 2026 weight is said. const years = (st) => st.layout.years.map((y) => y.text); assert.ok(!years(states[4]).includes("2026")); assert.ok(years(states.at(-1)).includes("2026")); }); test("the gap rule: a stretch longer than a year (or 8× the median spacing) breaks the time axis; the dense run gets the width", () => { const pts = trailPoints(MEASURE); // The median step between the dates here is 57 days: 8× is 456, past the year's floor. assert.equal(gapThreshold(pts), 456); assert.equal(gapThreshold([0, 7, 14, 21, 28].map((day) => ({ day }))), GAP_FLOOR_DAYS, "weekly statements: the year's floor rules"); assert.equal(gapThreshold(pts, 540), 540); assert.equal(gapThreshold(pts, 0), Infinity); // Spacing of 100 days: 8× is 800, past the floor. const sparse = [0, 100, 200, 300, 400].map((day) => ({ day })); assert.equal(gapThreshold(sparse), 800); assert.deepEqual(clustersOf([1, 2, 500, 900, 901], 365), [{ first: 1, last: 2 }, { first: 500, last: 500 }, { first: 900, last: 901 }]); const last = trailStates(pts, BOX, { mark: 300 }).at(-1); // 2008 | 2013 | 2023 | 2025–26: three breaks, each a narrow band. assert.equal(last.layout.clusters.length, 4); assert.equal(last.layout.gaps.length, 3); const dense = last.layout.clusters.at(-1); assert.ok(dense.x1 - dense.x0 > 0.5 * (BOX.x1 - BOX.x0), `the 2025–26 run has most of the width (${dense.x1 - dense.x0} px)`); // The line (12 Nov): through EVERY weight shown, stated and remembered, in date order -- 2008, 2013, 2013, 2023, // then the 2025–26 run -- dotted across each break, quiet where a remembered weight is an end. const byN = new Map(pts.map((p) => [p.n, p])); assert.deepEqual(last.line, [3, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12]); assert.deepEqual(last.pairs.map((pr) => pr.key).slice(0, 4), ["3_0", "0_1", "1_2", "2_4"]); const across = last.pairs.find((pr) => byN.get(pr.a).value === 342.9); assert.deepEqual([across.b, across.gap, across.quiet], [2, true, true], "2013 to the remembered 2023 is a quiet dotted connector"); assert.deepEqual(last.pairs.filter((pr) => pr.gap).map((pr) => pr.key), ["3_0", "1_2", "2_4"], "one dotted pair per break"); for (const pr of last.pairs) assert.equal(pr.quiet, byN.get(pr.a).kind !== "stated" || byN.get(pr.b).kind !== "stated", pr.key); assert.ok(last.pairs.filter((pr) => !pr.gap && !pr.quiet).length >= 8, "the stated run keeps the accent"); // gap: 0 -- one cluster, no breaks. assert.equal(trailStates(pts, BOX, { gap: 0, mark: 300 }).at(-1).layout.gaps.length, 0); // bounds: "fixed" -- every moment on the whole cut's axes. const fixed = trailStates(pts, BOX, { bounds: "fixed", mark: 300 }); assert.equal(fixed[0].layout.hi, fixed.at(-1).layout.hi); }); test("the page: points pop in where their moment puts them and move with every reflow, seek-safe; the knobs validate", () => { const timeline = Array.from({ length: 4 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "v", start: 0, end: 100 })); const render = { width: 1920, height: 1080, fps: 30, transition: 0.4, palette: { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }, chrome: { engine: "hyperframes", layout: "deck", deck: { dial: true, odometer: true, trail: true } } }; const schedule = { ...estimateSchedule({ slug: "m", title: "M", provenance: {}, render, timeline }), measure: MEASURE }; const html = trailHtml(schedule, render, { fonts: {} }); const data = JSON.parse(/