Skip to content

Commit 1d4c573

Browse files
Allow specifying the limit of Coord in the opposite order to the Scale (#3958)
* Add a failing test * Sort the limits in ascending order
1 parent 568b6e4 commit 1d4c573

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

R/scale-view.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ view_scale_primary <- function(scale, limits = scale$get_limits(),
1616
continuous_range = scale$dimension(limits = limits)) {
1717

1818
if(!scale$is_discrete()) {
19-
breaks <- scale$get_breaks(continuous_range)
19+
# continuous_range can be specified in arbitrary order, but
20+
# continuous scales expect the one in ascending order.
21+
breaks <- scale$get_breaks(sort(continuous_range))
2022
minor_breaks <- scale$get_breaks_minor(b = breaks, limits = continuous_range)
2123
} else {
2224
breaks <- scale$get_breaks(limits)

tests/testthat/test-scales-breaks-labels.r

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ test_that("equal length breaks and labels can be passed to ViewScales with limit
264264

265265
test_view_scale <- view_scale_primary(test_scale)
266266
expect_identical(test_view_scale$get_breaks(), c(NA, 20, NA))
267-
expect_identical(test_scale$get_labels(), c(c("0", "20", "40")))
267+
expect_identical(test_view_scale$get_labels(), c(c("0", "20", "40")))
268+
269+
# ViewScale accepts the limits in the opposite order (#3952)
270+
test_view_scale_rev <- view_scale_primary(test_scale, limits = rev(test_scale$get_limits()))
271+
expect_identical(test_view_scale_rev$get_breaks(), c(NA, 20, NA))
272+
expect_identical(test_view_scale_rev$get_labels(), c(c("0", "20", "40")))
268273
})
269274

270275
# Visual tests ------------------------------------------------------------

0 commit comments

Comments
 (0)