Skip to content

Commit

Permalink
Preserve aesthetics in colourbar merge
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jun 17, 2023
1 parent 5fea610 commit 9f1f73f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
* `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
* `guide_axis()` gains a `cap` argument that can be used to trim the
axis line to extreme breaks (#4907).
* `guide_colourbar()` and `guide_coloursteps()` merge properly when one
of aesthetics is dropped (#5324).

* `geom_label()` now uses the `angle` aesthetic (@teunbrand, #2785)
* 'lines' units in `geom_label()`, often used in the `label.padding` argument,
Expand Down
2 changes: 2 additions & 0 deletions R/guide-colorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ GuideColourbar <- ggproto(
},

merge = function(self, params, new_guide, new_params) {
new_params$key$.label <- new_params$key$.value <- NULL
params$key <- vec_cbind(params$key, new_params$key)
return(list(guide = self, params = params))
},

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,26 @@ test_that("guide_coloursteps and guide_bins return ordered breaks", {
expect_true(all(diff(key$.value) < 0))
})

test_that("guide_colourbar merging preserves both aesthetics", {
# See issue 5324

scale1 <- scale_colour_viridis_c()
scale1$train(c(0, 2))

scale2 <- scale_fill_viridis_c()
scale2$train(c(0, 2))

g <- guide_colourbar()
p <- g$params

p1 <- g$train(p, scale1, "colour")
p2 <- g$train(p, scale2, "fill")

merged <- g$merge(p1, g, p2)

expect_true(all(c("colour", "fill") %in% names(merged$params$key)))
})

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

test_that("axis guides are drawn correctly", {
Expand Down

0 comments on commit 9f1f73f

Please sign in to comment.