Skip to content

Add rasterization support for simple heatmap annotations#1260

Open
brandonlukas wants to merge 2 commits into
jokergoo:masterfrom
brandonlukas:feature/rasterize-annotations
Open

Add rasterization support for simple heatmap annotations#1260
brandonlukas wants to merge 2 commits into
jokergoo:masterfrom
brandonlukas:feature/rasterize-annotations

Conversation

@brandonlukas

Copy link
Copy Markdown

Previously only the heatmap body (matrix) supported rasterization via use_raster. This adds the same capability to simple annotations (vector/matrix values drawn as colored cells via anno_simple), reducing PDF/SVG file sizes for large annotations.

Changes:

  • Add rasterize_in_viewport() helper to utils.R, encapsulating the temp-device rasterization pattern from draw_heatmap_body()
  • Add raster_param slot to SingleAnnotation class with use_raster, raster_device, raster_quality, and related parameters
  • Wrap annotation drawing in SingleAnnotation draw() with rasterization when use_raster=TRUE (annotation names remain vector graphics)
  • Pass raster params through HeatmapAnnotation constructor to each SingleAnnotation
  • Add annotation_use_raster global option to ht_opt

brandonlukas and others added 2 commits March 12, 2026 01:41
Previously only the heatmap body (matrix) supported rasterization via
use_raster. This adds the same capability to simple annotations
(vector/matrix values drawn as colored cells via anno_simple), reducing
PDF/SVG file sizes for large annotations.

Changes:
- Add rasterize_in_viewport() helper to utils.R, encapsulating the
  temp-device rasterization pattern from draw_heatmap_body()
- Add raster_param slot to SingleAnnotation class with use_raster,
  raster_device, raster_quality, and related parameters
- Wrap annotation drawing in SingleAnnotation draw() with rasterization
  when use_raster=TRUE (annotation names remain vector graphics)
- Pass raster params through HeatmapAnnotation constructor to each
  SingleAnnotation
- Add annotation_use_raster global option to ht_opt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When raster_quality > 1, the temp raster device grew in pixels but kept
the default res=72, making its physical size (inches) grow proportionally.
AnnotationFunction::draw() pushes a viewport with absolute units (e.g.
unit(5, "mm")), which then only filled 1/raster_quality of the enlarged
device, causing the annotation to appear vertically shrunken.

Fix by scaling res with raster_quality so the device's physical size
stays constant regardless of quality level.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant