Skip to content

Commit

Permalink
feat: Expand available {viridis} palettes in colorNumeric() (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-davison authored Jul 26, 2024
1 parent 0d3bb3e commit c4aec69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# leaflet (development version)

* Color palette improvements. All color palette functions now support all `{viridisLite}` palettes ("magma", "inferno", "plasma", "viridis", "cividis", "rocket", "mako", and "turbo").

# leaflet 2.2.2

* Fixed #893: Correctly call `terra::crs()` when checking the CRS of a `SpatVector` object in `pointData()` or `polygonData()` (thanks @mkoohafkan, #894).
Expand Down
14 changes: 12 additions & 2 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ colorFactor <- function(palette, domain, levels = NULL, ordered = FALSE,
#' \enumerate{
#' \item{A character vector of RGB or named colors. Examples: `palette()`, `c("#000000", "#0000FF", "#FFFFFF")`, `topo.colors(10)`}
#' \item{The name of an RColorBrewer palette, e.g. `"BuPu"` or `"Greens"`.}
#' \item{The full name of a viridis palette: `"viridis"`, `"magma"`, `"inferno"`, or `"plasma"`.}
#' \item{The full name of a viridis palette: `"magma"`, `"inferno"`, `"plasma"`, `"viridis"`, `"cividis"`, `"rocket"`, `"mako"`, or `"turbo"`}
#' \item{A function that receives a single value between 0 and 1 and returns a color. Examples: `colorRamp(c("#000000", "#FFFFFF"), interpolate = "spline")`.}
#' }
#' @examples
Expand Down Expand Up @@ -330,7 +330,17 @@ toPaletteFunc.character <- function(pal, alpha, nlevels) {
} else {
colors <- brewer_pal(pal) # Get all colors
}
} else if (length(pal) == 1 && pal %in% c("viridis", "magma", "inferno", "plasma")) {
} else if (length(pal) == 1 &&
pal %in% c(
"magma",
"inferno",
"plasma",
"viridis",
"cividis",
"rocket",
"mako",
"turbo"
)) {
colors <- viridisLite::viridis(n = 256, option = pal)
} else {
colors <- pal
Expand Down
2 changes: 1 addition & 1 deletion man/colorNumeric.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/articles/colors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The four color functions all have two required arguments, `palette` and `domain`
The `palette` argument specifies the colors to map the data to. This argument can take one of several forms:

1. The name of a preset palette from the `RColorBrewer` package, e.g. `"RdYlBu"`, `"Accent"`, or `"Greens"`.
2. The full name of a `viridis` palette: `"viridis"`, `"magma"`, `"inferno"`, or `"plasma"`.
2. The full name of a `viridis` palette: `"magma"`, `"inferno"`, `"plasma"`, `"viridis"`, `"cividis"`, `"rocket"`, `"mako"`, or `"turbo"`.
3. A character vector of RGB or named colors, e.g. `palette()`, `c("#000000", "#0000FF", "#FFFFFF")`, `topo.colors(10)`.
4. A function that receives a single value between 0 and 1 and returns a color, e.g.:
`colorRamp(c("#000000", "#FFFFFF"), interpolate="spline")`
Expand Down

0 comments on commit c4aec69

Please sign in to comment.