Skip to content

Allow specifying the limit of Coord in the opposite order to the Scale #3958

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/scale-view.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ view_scale_primary <- function(scale, limits = scale$get_limits(),
continuous_range = scale$dimension(limits = limits)) {

if(!scale$is_discrete()) {
breaks <- scale$get_breaks(continuous_range)
# continuous_range can be specified in arbitrary order, but
# continuous scales expect the one in ascending order.
breaks <- scale$get_breaks(sort(continuous_range))
minor_breaks <- scale$get_breaks_minor(b = breaks, limits = continuous_range)
} else {
breaks <- scale$get_breaks(limits)
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-scales-breaks-labels.r
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ test_that("equal length breaks and labels can be passed to ViewScales with limit

test_view_scale <- view_scale_primary(test_scale)
expect_identical(test_view_scale$get_breaks(), c(NA, 20, NA))
expect_identical(test_scale$get_labels(), c(c("0", "20", "40")))
expect_identical(test_view_scale$get_labels(), c(c("0", "20", "40")))

# ViewScale accepts the limits in the opposite order (#3952)
test_view_scale_rev <- view_scale_primary(test_scale, limits = rev(test_scale$get_limits()))
expect_identical(test_view_scale_rev$get_breaks(), c(NA, 20, NA))
expect_identical(test_view_scale_rev$get_labels(), c(c("0", "20", "40")))
})

# Visual tests ------------------------------------------------------------
Expand Down