Skip to content

Legend export: restyle the band in the app's theme - #498

Merged
CarsonDavis merged 2 commits into
developmentfrom
feature/328-5-export-legend-style
Sep 25, 2026
Merged

CarsonDavis merged 2 commits into
developmentfrom
feature/328-5-export-legend-style

Conversation

@sandesh-sp

@sandesh-sp sandesh-sp commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Line breakdown

Category Lines added %
Production code 572 82.7
Tests 120 17.3
Total 692 100.0

This PR restyles the legend band under an exported map so it reads as part of the dashboard rather than a generic grey panel: the app theme's typeface and colors on a plain white surface, a header that sits beside the rows on a wide export, and dates set as a small label over their value.

Part of #328

What this does

  • The band borrows the app theme. bandTheme.ts reads the typeface, ink, muted and hairline colors and the font weights off :root once per export, falling back per token to Public Sans and USWDS-like greys. The surface stays white regardless of theme, since the export is a printable artifact. Each weight is loaded with document.fonts.load before drawing, because a canvas silently substitutes a fallback face for a web font the page hasn't used yet.
  • The framed card is gone. The band is one white surface with 32px of padding; a hairline parts the header from the rows.
  • Header dates are labelled facts. The model hands the renderer headerFacts: { label, value }[] instead of pre-worded headerLines, and each prints as a small muted label (Time cursor, Exported) over its value.
  • On a wide export the header takes its own column. At 760px of content width or more, the header sits to the left of the rows behind a vertical hairline. The column is as wide as its longest line, capped at 25% of the band, and longer text wraps onto at most four lines, the last one ellipsized. The clear space either side of the hairline is 48px when the header fills its 25% and grows with the width a shorter header leaves unused, up to 96px. Below 760px the header stacks on top of the rows.
  • Type and spacing are larger and looser. Title 20px, row names 14px, dates 12px, labels 11px; 20px between lines of rows; a thinner 8px gradient bar.
  • Pale colors keep an edge. A swatch or ramp end whose relative luminance is above 0.85 gets a hairline outline so it doesn't vanish against the white.

Decisions to review

  1. The gap beside the header shrinks as the header grows. It rises to 96px beside a short title and falls to 48px when the header fills its column. The gap shrinks by a fifth of what the column gains, so a longer header still only ever moves the rows right. The alternatives were a fixed gap, or a gap that grows with the header.
  2. Theme tokens are read at export time, not baked in. A mission with a custom brand gets its own face and ink on the export. The alternative is a fixed print palette that ignores the brand.

Test plan

  • npx vitest run: all 3079 pass. The legend suite (55) covers the column sizing between a short and a capped header, header wrapping and ellipsis, and the measure and draw passes agreeing on the band's height in stacked, columned and wrapped layouts.
  • Export a PNG from a mission with a short name and one with a long name on a wide window; the header column hugs its text and the long name wraps within a quarter of the band.
  • Export at a narrow window width; the header stacks above the rows.
  • Export with a near-white categorical color; its swatch has a visible edge.

Note: a mission whose Time Format holds a moment-style pattern such as YYYY-MM-DDTHH:mm:ss[Z] prints that pattern literally in the header, because the format is d3-only. Set it to %Y-%m-%dT%H:%M:%SZ or clear it.

Draw the band on a plain white surface in the theme's typeface, ink and
hairline colors, read off :root per export, with the theme's font weights
loaded before drawing. The header prints each date as a small label over
its value, and on a wide export takes a column of its own to the left of
the rows, sized to its text up to a quarter of the band, with more clear
space beside a shorter header. Pale swatches and ramp ends get a hairline
edge so they don't vanish against the white.
@CarsonDavis
CarsonDavis merged commit ca3cfed into development Sep 25, 2026
4 checks passed
@CarsonDavis
CarsonDavis deleted the feature/328-5-export-legend-style branch September 25, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants