-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Smarter keys #5302
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
Smarter keys #5302
Changes from all commits
8eb0d80
7927b6d
eeadca8
e01b693
bf06916
3cf3f3e
d2d8ff1
d0f4eaa
9522540
a1f396d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,37 @@ ScalesList <- ggproto("ScalesList", NULL, | |
data_frame0(!!!mapped, df[setdiff(names(df), names(mapped))]) | ||
}, | ||
|
||
key_data = function(self, data) { | ||
|
||
scales <- self$scales | ||
|
||
lapply(scales, function(s) { | ||
if (!s$is_discrete()) { | ||
return(NULL) | ||
} | ||
n <- s$n.breaks.cache %||% sum(!is.na(s$limits %|W|% s$get_limits())) | ||
if (n < 1) { | ||
return(NULL) | ||
} | ||
pal <- s$palette.cache %||% s$palette(n) | ||
pal <- c(pal, s$na.value) | ||
aes <- s$aesthetics | ||
out <- vapply(data, function(d) { | ||
if (!any(aes %in% names(d))) { | ||
return(rep.int(FALSE, length(pal))) | ||
} | ||
present <- vapply(aes, function(a) { | ||
vec_in(pal, d[[a]]) | ||
}, logical(length(pal))) | ||
if (length(dim(present)) > 1) { | ||
present <- rowSums(present) > 0 | ||
} | ||
present | ||
}, logical(length(pal))) | ||
list(aesthetics = aes, data = data_frame0(pal = pal, member = out)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
}) | ||
}, | ||
|
||
transform_df = function(self, df) { | ||
if (empty(df)) { | ||
return(df) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the data has to happen before the defaults are filled in and
after_scale()
modifications are applied. Otherwise the information might be lost. I gave the scales list a method to check the data. The downside is that we have to check all the data regardless of whether the scale has a legend guide, as that isn't resolved at this point.