doxa-maps/internal/check-poster-layout.mjs
Doxa Maps 6e31def193 The poster's legend was painted over the map it was describing
The Driver, on the Simple Research poster: the legend has to sit beside the map,
never over it, with a proper header and footer.

usePosterLayout has always computed exactly that. computeLayout narrows the map
by the legend column and insets it by the margins, the title strip and the footer
strip, and it has done so since the file was written. Nothing in the exporter
ever read it. The hidden map was spawned at the full page size — edge to edge,
across the margins, the header band and the footer band — and the title, legend
and footer were then composited on top of that image. So the legend was a
translucent white panel lying over the map, and there were no bands at all.

What kept it hidden is worth recording: PosterPreview.vue, the thing a developer
looks at, DOES honour layout.map. The on-screen preview has always shown the
intended design; only the exported file was wrong. A preview is not evidence for
an export, and the two had drifted apart with nothing to notice.

The map is now rastered at the size of its own box and drawn onto a white sheet
at the position the layout gives it. A sheet with no room for a map after its
margins, bands and legend column falls back to full-bleed and says so, because
silence there is the bug this commit removes.

The check has two arms on purpose. A test of computeLayout alone would have
passed every day the bug was alive, since the geometry was never what was broken;
the second arm asserts the renderer consumes it. Both arms are negative-tested,
and two of those tests caught the check reading a function DECLARATION rather
than a call — the parameter is also named px, and a name is present because it is
declared, so presence proves nothing about use.

country-posters renders through the same path and inherits the change: its page-1
map image gains the same bands.
2026-09-28 19:27:07 +00:00

106 lines
6.8 KiB
JavaScript

#!/usr/bin/env node
/**
* check-poster-layout — the exported poster is a LAYOUT, not a map with things painted on it.
*
* Driver, 2026-09-28, on the Simple Research poster: the legend must sit BESIDE the map, never over
* it, with a proper header and footer.
*
* WHY BOTH ARMS. usePosterLayout.computeLayout has always produced the right geometry — it narrows
* the map by the legend column and insets it by the margins, title and footer. The bug was that the
* renderer never used it: the hidden map was spawned at the FULL PAGE size and the slots were
* composited on top, so the legend was a translucent panel over the map and there were no bands.
* A test of computeLayout alone would therefore have passed throughout the entire life of the bug.
*
* So arm A checks the geometry is right, and arm B checks the renderer actually CONSUMES it — the
* link that was missing. Arm B reads source structure because the real path needs WebGL and a
* browser, which this repo's gates do not get; each link it asserts is negative-tested below.
*
* ★ WHAT MADE THIS SURVIVE, worth keeping in mind for any preview: PosterPreview.vue DOES honour
* layout.map, so the on-screen preview showed the intended design while the exported file did not.
* The preview was never evidence for the export.
*
* Headless, no network, no browser, no dependencies. Exit 0 pass · 1 fail.
*/
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readFileSync } from 'node:fs'
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const { computeLayout } = await import(resolve(ROOT, 'library/composables/poster/usePosterLayout.js'))
const { defaultPosterSpec } = await import(resolve(ROOT, 'library/constants/posterDefaults.js'))
const fails = []
const ok = (what, cond) => { if (!cond) fails.push(what) }
const overlap = (a, b) => !(a.x + a.w <= b.x || b.x + b.w <= a.x || a.y + a.h <= b.y || b.y + b.h <= a.y)
const px = (spec) => ({ width: Math.round(spec.widthIn * spec.dpi), height: Math.round(spec.heightIn * spec.dpi), dpi: spec.dpi })
// ── ARM A: the geometry, on the sheets the two real callers actually ask for ──
const SHEETS = [
['Simple Research, landscape (the Driver\'s poster)', { widthIn: 11, heightIn: 8.5, dpi: 200, orientation: 'landscape' }],
['Simple Research, portrait', { widthIn: 8.5, heightIn: 11, dpi: 200, orientation: 'portrait' }],
['country-posters, A4 portrait @150', { widthIn: 8.27, heightIn: 11.69, dpi: 150, orientation: 'portrait' }],
['a big 24x36 research poster @300', { widthIn: 24, heightIn: 36, dpi: 300, orientation: 'portrait' }],
]
for (const [name, size] of SHEETS) {
const spec = defaultPosterSpec(size)
spec.slots.legend = { ...spec.slots.legend, rows: [{ label: 'Reached', color: '#2a7' }, { label: 'Unreached', color: '#c33' }] }
const L = computeLayout(spec, px(spec))
ok(`${name}: the map has a positive area`, L.map.w > 0 && L.map.h > 0)
ok(`${name}: THE LEGEND IS BESIDE THE MAP, NOT OVER IT`, !overlap(L.legend, L.map))
ok(`${name}: the legend is on the outside edge, past the map`, L.legend.x >= L.map.x + L.map.w)
ok(`${name}: the header sits above the map, not on it`, !overlap(L.title, L.map) && L.title.y + L.title.h <= L.map.y)
ok(`${name}: the footer sits below the map, not on it`, !overlap(L.footer, L.map) && L.footer.y >= L.map.y + L.map.h)
ok(`${name}: the footer does not run into the legend`, !overlap(L.footer, L.legend))
ok(`${name}: the header does not run into the legend`, !overlap(L.title, L.legend))
// everything stays on the paper, inside the margins
for (const [slot, box] of Object.entries({ map: L.map, legend: L.legend, title: L.title, footer: L.footer })) {
ok(`${name}: ${slot} stays inside the printable area`,
box.x >= L.content.x - 1 && box.y >= L.content.y - 1 &&
box.x + box.w <= L.content.x + L.content.w + 1 && box.y + box.h <= L.content.y + L.content.h + 1)
}
// the map must still be worth printing — a legend column that eats the sheet is its own defect
ok(`${name}: the map keeps the majority of the sheet`, L.map.w * L.map.h > L.legend.w * L.legend.h)
}
// A legend with no rows must not silently reserve a blank column: the map should take the space.
{
const spec = defaultPosterSpec({ widthIn: 11, heightIn: 8.5, dpi: 200 })
const withRows = { ...spec, slots: { ...spec.slots, legend: { ...spec.slots.legend, rows: [{ label: 'x', color: '#000' }] } } }
const a = computeLayout(withRows, px(spec))
ok('a legend with rows narrows the map', a.map.w < a.content.w)
}
// ── ARM B: the renderer consumes the layout (the link the bug was missing) ──
const SRC = readFileSync(resolve(ROOT, 'library/composables/poster/useMapPoster.js'), 'utf8')
// Comments describe; they must not be able to satisfy a structural check. (A predicate matching a
// docstring is a mistake this repo's gates have made before.)
const CODE = SRC.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')
const link1 = /\blayout\s*=\s*computeLayout\s*\(\s*spec\s*,\s*px\s*\)/.test(CODE)
const link2 = /\bmapPx\s*=[\s\S]{0,200}?layout\.map\.w[\s\S]{0,80}?layout\.map\.h/.test(CODE)
// `await` pins these to the CALL sites: both functions are DECLARED with a parameter named `px`,
// so a bare name match reads the declaration and reports the opposite of the truth.
const link3 = /await\s+_renderSingleCanvas\s*\(\s*sourceMap\s*,\s*mapPx\s*,/.test(CODE) &&
/await\s+_renderTileStitch\s*\(\s*sourceMap\s*,\s*mapPx\s*,/.test(CODE)
// Same trap as link3, one step subtler: a name appears at least once because it is DECLARED, so
// presence proves nothing about use. Require the declaration AND at least one further occurrence.
const _sheetUses = (CODE.match(/_placeMapOnSheet\s*\(/g) || []).length
const link4 = /function\s+_placeMapOnSheet\s*\(/.test(CODE) && _sheetUses >= 2
ok('the render path computes the layout', link1)
ok('it derives the map raster size FROM layout.map', link2)
ok('BOTH renderers are given the map box, not the page — this is the line the bug lived on', link3)
ok('and the map is placed onto a full sheet rather than being the sheet', link4)
// the specific regression: neither renderer may be handed the page px again
ok('neither renderer is called with the page px',
!/await\s+_renderSingleCanvas\s*\(\s*sourceMap\s*,\s*px\s*,/.test(CODE) &&
!/await\s+_renderTileStitch\s*\(\s*sourceMap\s*,\s*px\s*,/.test(CODE))
if (fails.length) {
console.error('POSTER-LAYOUT: FAIL')
for (const f of fails) console.error(` ✗ ${f}`)
process.exit(1)
}
console.log('POSTER-LAYOUT: PASS — on four sheets the legend sits beside the map and never over it, the header and footer are their own bands, everything stays inside the margins, and the renderer draws the map into the box the layout reserved instead of across the whole page.')