Skip to content

feat: print stylesheet for printing and saving as PDF (#368) - #379

Merged
timdegroot1996 merged 1 commit into
mainfrom
feat/print-stylesheet
Oct 15, 2026
Merged

timdegroot1996 merged 1 commit into
mainfrom
feat/print-stylesheet

Conversation

@timdegroot1996

Copy link
Copy Markdown
Collaborator

Refs #368. This covers the print / PDF part (level 2) only. Per-graph PNG/CSV export (level 1) and data export (level 3) are left until someone asks for them.

What it does

Printing a page with Ctrl+P, or Save as PDF in the print dialog, now gives the page as it looks on screen (theme, filters, layout, custom graphs, widgets, notes), without the on-screen controls:

  • Hidden: the navbar, toasts, modals, graph/layout/widget buttons, info icons, note edit buttons, and the DataTables search, paging and sort arrows.
  • Kept: section filters, printed as plain values, so the PDF records what the graphs show.
  • Layout: the GridStack layout is rebuilt as a CSS grid from the --gs-x/y/w/h variables GridStack sets on each tile. Rows scale with the page width (cqw), so tiles keep their position and proportions and are never split over two pages. A section moves to a new page when it doesn't fit.
  • Charts: Chart.js doesn't redraw for print, so the on-screen drawing is scaled into each tile with object-fit: contain, without stretching. Graphs that scroll inside .vertical print whole.
  • Tables: tables (Test Notes, custom graphs in table view) let their row grow, so every row of their current page prints instead of being cut off.
  • Fullscreen: a graph open in fullscreen prints alone on one page.
  • Collapsed sections: print as the header only.
  • Pages are landscape. Setting this in CSS means the print dialog no longer offers an orientation choice.
  • Paper is white in both themes. Dark mode keeps its dark sections on the white paper.

Fixes

  • The old @media print block in 06-graphs.css never applied: its selector had a typo (.grid-stack-item-contentvas). Removed.
  • window.onbeforeprint in database.js returned a Promise, which browsers ignore. Removed.
  • gridstack.css ships print rules that size tiles to their content. The new stylesheet overrides them.

Files

  • New css/components/11-print.css, CSS only.
  • Docs: "Printing and PDF" section in docs/tabs-pages.md.

Testing

  • Generated the example dashboard from source. Set it up with notes switched on, a stat widget, a link widget and five custom graphs (one in table view), then saved the layout.
  • Rendered PDFs with Playwright's print emulation and checked every page. Covered the light and dark themes, a collapsed section, a fullscreen graph, and the Overview, Compare and Tables pages.
  • Only Chromium was checked, not Firefox.
  • Python unit tests: 434 passed.
  • JS unit tests were not run locally: vitest is missing from node_modules and Docker wasn't running. No JS test touches database.js.
  • No robot tests: the change is print-only CSS, and the screen rendering is unchanged.

🤖 Generated with Claude Code

Printing a page (or "Save as PDF" in the print dialog) now gives the page
as shown on screen without the on-screen chrome:

- hide the navbar, toasts, modals, graph/layout/widget controls, info
  icons, note edit buttons and the DataTables search, paging and sort
  arrows; section filters stay as plain values
- rebuild the GridStack layout as a CSS grid from the --gs-x/y/w/h
  variables, with rows scaled to the page width, so tiles keep their
  position and proportions and are never split over pages; this also
  overrides the print rules of gridstack.css, which size tiles to content
- scale the on-screen Chart.js drawing into each tile (object-fit), print
  graphs that scroll in .vertical whole, let tables grow their row
- a fullscreen graph prints alone on one page, collapsed sections print
  their header only, landscape pages, white paper in both themes
- remove the old print rules (their selector had a typo and never
  matched) and the no-op window.onbeforeprint in database.js
- docs: Printing and PDF section in tabs-pages.md

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@timdegroot1996 timdegroot1996 linked an issue Oct 15, 2026 that may be closed by this pull request
@timdegroot1996
timdegroot1996 merged commit 6a4b28d into main Oct 15, 2026
3 checks passed
@timdegroot1996
timdegroot1996 deleted the feat/print-stylesheet branch October 17, 2026 19:39
@timdegroot1996 timdegroot1996 mentioned this pull request Oct 17, 2026
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.

[Feature Request] Export graphs and data from the dashboard

1 participant