feat(web): print or download a single chart - #502
Conversation
Every interactive chart gets a Print action that opens a preview of the chart laid out as a page (A4 or Letter, portrait or landscape, best fit by default), which can be printed or saved as PDF, PNG or JPG. * Add a print preview drawn at printed size from the chart's own switches, legend and render function, so chart type and selections carry over * State title, filters, date range and legend on the page, and print values on the marks * Fit each chart kind to the page; long selections run onto further pages instead of being clipped * Show a message instead of an empty preview when no data is selected * Print the page alone, with no page margin for the browser's own header and footer * Add PDF, PNG and JPG downloads rendered in the browser at 288 dpi * Scope tab-print rules so Print tab is unchanged * Cover with Vitest and Playwright; document in docs/printing.md Fixes #501 Signed-off-by: Ntege Daniel <danientege785@gmail.com>
📊 Dashboard previewThe dashboard was built for this PR. ➡️ Download
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Warning Review limit reachedNext included review available in 30 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: hiero-hackers/analytics/.coderabbit.yml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
WalkthroughInteractive charts now have a print preview with chart-specific layout, selection details, and paper settings. The preview can print the chart sheet or download it as PDF, PNG, or JPG. Chart-specific rendering and tests cover paper sizing, pagination, empty selections, and separation from dashboard printing. ChangesChart Printing
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to Multi-page chart PDFs can split rows, labels, and bars across pages. Preserve complete rows in downloaded PDFs before merging; the existing page-count checks do not catch this problem. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Downloads are generated locally and exclude external avatar images. A delayed print may fall back to printing the dashboard if its chart preview is closed first. Browser print confirmation limits the impact, while some rendering behavior remains unverified. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 52.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 21 files. (4 skipped: 4 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: hiero-hackers/analytics/.coderabbit.yml
Review profile: CHILL
Plan: Advanced
Run ID: 78fc3ce6-0664-4044-9cb6-0b9b62ee8af2
⛔ Files ignored due to path filters (1)
web/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (25)
docs/printing.mdweb/e2e/chartPrint.spec.tsweb/package.jsonweb/src/app.cssweb/src/chartExport.tsweb/src/chartPrint.tsweb/src/components/ChartSectionCard.tsxweb/src/components/ContributorCell.tsxweb/src/components/PrintFilter.tsxweb/src/components/VariantTabs.tsxweb/src/components/charts/AdjacencyMatrix.tsxweb/src/components/charts/ChartPrintDialog.tsxweb/src/components/charts/ChartShell.tsxweb/src/components/charts/EventsView.tsxweb/src/components/charts/MatrixView.tsxweb/src/components/charts/NetworkView.tsxweb/src/components/charts/SeriesView.tsxweb/src/components/charts/format.tsweb/src/components/charts/leading.tsweb/src/hooks/use-element-size.tsweb/src/print.cssweb/src/printContext.tsweb/src/printing.tsxweb/src/test/chartPrint.test.tsxweb/src/test/printComponents.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
A downloaded PDF that ran past one page was cut at fixed heights, so a page could end through a ranking bar, its label or a heatmap row. * Find the safe breaks on the sheet: under its header, footer notes and heatmap rows, and midway between two rows of a ranking or timeline * End each PDF page at the last break that fits, leaving white space rather than splitting a row * Draw the preview's page-break guides from the same breaks, recomputed as the charts inside redraw * Check in Chromium and Firefox that a long ranking's page break falls between two rows Signed-off-by: Ntege Daniel <danientege785@gmail.com>
Description:
Print or download any single chart on the dashboard. Each chart gets a Print action that opens a preview of the chart as a page (A4 or Letter, portrait or landscape). The preview can be printed, or saved as PDF, PNG or JPG without the browser's print dialog.
modern-screenshot(loaded only when a file is saved), and a small PDF writer (one losslessly compressed image per page, viaCompressionStream, no PDF library):where(), no specificity change), so Print tab behaves exactly as beforedocs/printing.mdRelated issue(s):
Fixes #501
Notes for reviewer:
ChartShellhands its own view's switches, legend andchart()render function toChartPrintDialog. Views take an optionalsheetsize and lay themselves out for paper. The alternative, re-rendering the chart from a copy of its URL state, would duplicate every view's derivation and drift.<html data-print-scope="chart">and a per-paper@pagerule are set, andPrintProviderskips tab print mode.foreignObjectonto a canvas. Onlydata:images and same-origin fonts are used, which the existing policy already allows.connect-src 'self', so saved files show their initials instead.translate: noneinto thetransformshorthand, which left the dialog's centring offset on paper in the production build.print.cssresets Tailwind's--tw-translate-*variables instead.modern-screenshot(MIT), 22 kB, in its own chunk, loaded only when a file is saved.npm test: 180 tests, 13 new.npm run lint: existing warnings only, none added.npm run format:checkandnpm run buildpass.Checklist
/assignbefore starting (see contributing guide)uv run pytestanduv run ruff check src testspass locally — not applicable, no Python changes (npm test,npm run lintandnpm run buildpass inweb/)src/layout)git commit -S -s