-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix scale- and coord-related regressions #3566
Changes from all commits
e2e343f
0a98b65
b8768be
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 |
---|---|---|
|
@@ -444,10 +444,9 @@ Scale <- ggproto("Scale", NULL, | |
if (is.null(self$limits)) { | ||
self$range$range | ||
} else if (is.function(self$limits)) { | ||
# if limits is a function, it expects to work in data space | ||
self$trans$transform(self$limits(self$trans$inverse(self$range$range))) | ||
self$limits(self$range$range) | ||
} else { | ||
ifelse(is.na(self$limits), self$range$range, self$limits) | ||
self$limits | ||
} | ||
}, | ||
|
||
|
@@ -534,6 +533,12 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale, | |
self$range$train(x) | ||
}, | ||
|
||
is_empty = function(self) { | ||
has_data <- !is.null(self$range$range) | ||
has_limits <- is.function(self$limits) || (!is.null(self$limits) && all(is.finite(self$limits))) | ||
!has_data && !has_limits | ||
}, | ||
|
||
transform = function(self, x) { | ||
new_x <- self$trans$transform(x) | ||
axis <- if ("x" %in% self$aesthetics) "x" else "y" | ||
|
@@ -555,6 +560,22 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale, | |
self$rescaler(x, from = range) | ||
}, | ||
|
||
get_limits = function(self) { | ||
if (self$is_empty()) { | ||
return(c(0, 1)) | ||
} | ||
|
||
if (is.null(self$limits)) { | ||
self$range$range | ||
} else if (is.function(self$limits)) { | ||
# if limits is a function, it expects to work in data space | ||
self$trans$transform(self$limits(self$trans$inverse(self$range$range))) | ||
} else { | ||
# NA limits for a continuous scale mean replace with the min/max of data | ||
ifelse(is.na(self$limits), self$range$range, self$limits) | ||
} | ||
}, | ||
|
||
Comment on lines
+563
to
+578
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. Is this just the same as 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. It's different... 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. Can you test if it breaks anything in ScaleDiscrete? I don’t like having such a small method overwriting for no reason 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. The reason is that passing functions as limits for discrete scales errored before (#3448), because |
||
dimension = function(self, expand = expansion(0, 0), limits = self$get_limits()) { | ||
expand_limits_scale(self, expand, limits) | ||
}, | ||
|
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.
Can this be added to the
Scale
class instead or will it breakScaleDiscrete
?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.
I think this will cause errors in
ScaleDiscrete
, whereNA
is a perfectly valid limit (I think)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.
Whoops...I think that adding this implementation of
is_empty()
toScale
will cause errors inScaleDiscrete
.