From add408eee40283568bc856151025b14ceab63c40 Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Wed, 20 May 2026 05:18:39 +0200 Subject: [PATCH] feat(pdf): smaller single-SVG layout + halo glow on main-view selections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single image ------------ When an observation only has one SVG to render (no detail-popup zones), the image now occupies half the available column width and is centered horizontally. Two-image observations keep the existing 2-column grid unchanged. The text-section reservation logic and aspect-driven row budget still apply, so the layout stays balanced regardless of the chosen cell size. Halo glow on whole-animal view ------------------------------ Whole-animal SVGs use small point markers on a large silhouette, so the previous flat fill was hard to spot at print scale. The colorized SVG now carries a Gaussian-blur SVG filter ("osteo-halo") which is applied to every selected zone on main views only — detail views are already zoomed in and don't need it. The filter widens each selection into a soft accent-coloured halo while keeping the original shape crisp on top via feMerge. Fill opacity bumped from 0.65 to 0.85 to sharpen the focal mark itself. The filter is injected once into the SVG defs per export, so multiple selected zones share the same definition with no duplication cost. Co-Authored-By: Claude --- src/pdf/render/observationPage.ts | 75 ++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/src/pdf/render/observationPage.ts b/src/pdf/render/observationPage.ts index a4865656..a6caf17b 100644 --- a/src/pdf/render/observationPage.ts +++ b/src/pdf/render/observationPage.ts @@ -54,6 +54,55 @@ function wrapLines(text: string, font: PDFFont, size: number, max: number): stri return lines } +const SVG_NS = 'http://www.w3.org/2000/svg' +const HALO_FILTER_ID = 'osteo-halo' + +/** + * Adds a Gaussian-blur "halo" filter to the SVG defs the first time it + * is called on a root. The filter widens the visible footprint of the + * highlighted zones on the whole-animal view, where individual point + * markers are otherwise tiny relative to the full body silhouette. + */ +function ensureHaloFilter(root: SVGSVGElement): void { + const doc = root.ownerDocument + if (!doc) return + if (doc.getElementById(HALO_FILTER_ID)) return + + let defs = root.querySelector('defs') + if (!defs) { + defs = doc.createElementNS(SVG_NS, 'defs') + root.insertBefore(defs, root.firstChild) + } + + const filter = doc.createElementNS(SVG_NS, 'filter') + filter.setAttribute('id', HALO_FILTER_ID) + filter.setAttribute('x', '-100%') + filter.setAttribute('y', '-100%') + filter.setAttribute('width', '300%') + filter.setAttribute('height', '300%') + filter.setAttribute('filterUnits', 'userSpaceOnUse') + + const blur = doc.createElementNS(SVG_NS, 'feGaussianBlur') + blur.setAttribute('in', 'SourceGraphic') + blur.setAttribute('stdDeviation', '6') + blur.setAttribute('result', 'halo') + filter.appendChild(blur) + + const merge = doc.createElementNS(SVG_NS, 'feMerge') + const m1 = doc.createElementNS(SVG_NS, 'feMergeNode') + m1.setAttribute('in', 'halo') + const m2 = doc.createElementNS(SVG_NS, 'feMergeNode') + m2.setAttribute('in', 'halo') + const m3 = doc.createElementNS(SVG_NS, 'feMergeNode') + m3.setAttribute('in', 'SourceGraphic') + merge.appendChild(m1) + merge.appendChild(m2) + merge.appendChild(m3) + filter.appendChild(merge) + + defs.appendChild(filter) +} + async function colorizedSvgString( speciesSvgPath: string, observation: Observation, @@ -67,12 +116,21 @@ async function colorizedSvgString( .map((z) => z.boneId), ) + // Whole-animal view: zone hitboxes are tiny markers on a big + // silhouette, so we apply a blurred halo to make selections pop. + // Detail views are already zoomed in and don't need it. + const applyHalo = sourceDetailId === undefined + if (applyHalo) ensureHaloFilter(root) + bones.forEach((bone, id) => { const selected = selectedIds.has(id) bone.els.forEach((el) => { if (selected) { el.setAttribute('fill', '#b85a3f') - el.setAttribute('fill-opacity', '0.65') + el.setAttribute('fill-opacity', '0.85') + if (applyHalo) { + el.setAttribute('filter', `url(#${HALO_FILTER_ID})`) + } } else { el.setAttribute('display', 'none') } @@ -250,9 +308,16 @@ export async function addObservationPage( let cursorY = titleY - IMAGE_TOP_GAP if (rendered.length > 0) { - const cols = rendered.length === 1 ? 1 : 2 + const isSingle = rendered.length === 1 + const cols = isSingle ? 1 : 2 const rows = Math.ceil(rendered.length / cols) - const cellW = (width - MARGIN_X * 2 - IMAGE_COL_GAP * (cols - 1)) / cols + const fullCellW = + (width - MARGIN_X * 2 - IMAGE_COL_GAP * (cols - 1)) / cols + // Single-image observations get rendered at half the available width + // and centered, so they don't dominate the page when the surrounding + // text is short. + const cellW = isSingle ? fullCellW / 2 : fullCellW + const singleOffsetX = isSingle ? (fullCellW - cellW) / 2 : 0 const reservedBottom = MARGIN_BOTTOM + estimateTextHeight() + IMAGE_BOTTOM_GAP const availH = Math.max(IMAGE_MIN_CELL_H, cursorY - reservedBottom) const rowBudget = Math.max( @@ -267,7 +332,7 @@ export async function addObservationPage( ) const rowH = Math.max(0, ...cellHs) rowItems.forEach((it, c) => { - const x = MARGIN_X + c * (cellW + IMAGE_COL_GAP) + const x = MARGIN_X + singleOffsetX + c * (cellW + IMAGE_COL_GAP) page.drawText(it.label, { x, y: cursorY, @@ -278,7 +343,7 @@ export async function addObservationPage( }) cursorY -= IMAGE_LABEL_GAP rowItems.forEach((it, c) => { - const x = MARGIN_X + c * (cellW + IMAGE_COL_GAP) + const x = MARGIN_X + singleOffsetX + c * (cellW + IMAGE_COL_GAP) page.drawImage(it.img, { x, y: cursorY - cellHs[c],