Skip to content

Add rasterization support for simple heatmap annotations - #1260

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

Add rasterization support for simple heatmap annotations#1260
brandonlukas wants to merge 4 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 4 commits July 23, 2026 21:01
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>
Remove the unreachable small-viewport fallback, the redundant size
rounding, the duplicated magick availability check, and the unused
ht_opt$annotation_use_raster global option.

Add roxygen documentation for the six new raster arguments on
HeatmapAnnotation() and SingleAnnotation(), and a test covering
raster parameter propagation and size stability across raster_quality.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
UpSet(), oncoPrint() and pheatmap() construct HeatmapAnnotation()
internally and never pass `use_raster`, so the global option is the only
way to rasterize those annotations. Declared as a plain nullable option
to match `annotation_border`, which also allows resetting it to NULL.

Add a test covering the internal path and argument precedence.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@brandonlukas
brandonlukas force-pushed the feature/rasterize-annotations branch from 3995cc7 to 26a5e0b Compare July 24, 2026 02:13
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