Skip to content

Commit 92aacca

Browse files
committed
FEAT/PERF: ScaleContinuous accepts palette capability may_return_na
We can extend palettes with attributes to improve the mapping efficiency. With this commit a palette may define an attribute `may_return_na` to `FALSE`. If it does, `ScaleContinuous` will assume the palette may not return missing values, and it will skip checking for those and replacing them.
1 parent 6f921ef commit 92aacca

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

R/scale-.r

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,14 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
659659
scaled <- colormap[findInterval(x, breaks, rightmost.closed = TRUE) + 1L]
660660
}
661661

662-
ifelse(!is.na(scaled), scaled, self$na.value)
662+
# A specific palette can have as attribute "may_return_NA = FALSE"
663+
# If it has such attribute, we will skip the ifelse(!is.na(scaled), ...)
664+
pal_may_return_na <- ggproto_attr(self$palette, "may_return_NA", default = TRUE)
665+
if (pal_may_return_na) {
666+
scaled <- ifelse(!is.na(scaled), scaled, self$na.value)
667+
}
668+
669+
scaled
663670
},
664671

665672
rescale = function(self, x, limits = self$get_limits(), range = limits) {

0 commit comments

Comments
 (0)