Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend palette contract: Palette capabilities #5032

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zeehio
Copy link
Contributor

@zeehio zeehio commented Nov 6, 2022

The goal of this pull request is to improve the performance of checking for missing values when mapping values to colours using a palette.

Some palettes may be able to guarantee that they never return missing values as colours. For those palettes it does not make sense that we check if there are missing values in their output.

In this pull request, I use (although I don't depend on it):

Basically, that pull request extends the palette contract by adding attributes to it. One of those attributes is may_return_NA which, if set to FALSE, then ggplot2 can assume the output of the palette has no missing values and skip the corresponding check.

The relevant part of this pull request is:

# A specific palette can have as attribute "may_return_NA = FALSE"
# If it has such attribute, we will skip the ifelse(!is.na(scaled), ...)
pal_may_return_na <- ggproto_attr(self$palette, "may_return_NA", default = TRUE)
if (pal_may_return_na) {
  scaled <- ifelse(!is.na(scaled), scaled, self$na.value)
}

Related to:

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.
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