Skip to content

Commit

Permalink
Palettes based on colour_ramp support and handling of NA values optim…
Browse files Browse the repository at this point in the history
…izations

Related to tidyverse/ggplot2#4989
  • Loading branch information
zeehio committed Sep 21, 2022
1 parent d869b71 commit b7da3f9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions R/colour-ramp.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ colour_ramp <- function(colors, na.color = NA, alpha = TRUE) {
}

structure(
function(x) {
lab_out <- cbind(l_interp(x), u_interp(x), v_interp(x))
out <- farver::encode_colour(lab_out, alpha = alpha_interp(x), from = "lab")
out[is.na(out)] <- na.color
function(x, color_fmt = "character") {
lab_out <- list(l_interp(x), u_interp(x), v_interp(x))
if (color_fmt == "character") {
out <- farver::encode_colour(lab_out, alpha = alpha_interp(x), from = "lab", na_value = na.color)
} else {
out <- farver::encode_native(lab_out, alpha = alpha_interp(x), from = "lab", na_value = na.color)
}
out
},
safe_palette_func = TRUE
safe_palette_func = TRUE,
accepts_native_output = TRUE,
may_return_NA = is.na(na.color)
)
}

0 comments on commit b7da3f9

Please sign in to comment.