Skip to content

Commit

Permalink
ensure expand is also obeyed by scale_thickness_shared
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Apr 5, 2024
1 parent 9b34704 commit 67d80ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ggdist (development version)

New features and enhancements:

* To complement the `subguide`s for `geom_slab()`, there are now `subscale`s,
which can be used to adjust the `limits` or the `expand` parameter of the
`thickness` per-geometry sub-scales (in much the same way those
parameters can be set on `scale_thickness_shared()`) (#219).
* Allow use of square `shape`s in `geom_blur_dots()`.


Expand Down
5 changes: 3 additions & 2 deletions R/scale_thickness.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ scale_thickness_shared = function(
renormalize = FALSE,
oob = scales::oob_keep,
guide = "none",
expand = c(0, 0),
...
) {
sc = continuous_scale(
Expand All @@ -104,7 +105,7 @@ scale_thickness_shared = function(
limits = limits,
oob = oob,
guide = guide,
expand = expansion(0, 0),
expand = expand,
...,
super = ScaleThicknessShared
)
Expand All @@ -115,7 +116,7 @@ scale_thickness_shared = function(
ScaleThicknessShared = ggproto("ScaleThicknessShared", ScaleContinuous,
renormalize = FALSE,

map = function(self, x, limits = self$get_limits()) {
map = function(self, x, limits = self$dimension(expand = self$expand)) {
out = if (is_thickness(x)) {
x
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test.scale_thickness.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ test_that("infinite thickness is squished", {
expect_equal(slab_grob$y, unit(c(0, 0.9, 0, 0, 0, 0), "native"))
})

test_that("expand works", {
p = ggplot() +
geom_slab(aes(x = 1:2, thickness = 1:2)) +
scale_thickness_shared(expand = expansion(c(0,0.25)))

expect_equal(layer_data(p)$thickness, thickness(1:2 / 2.5, 0, 2.5))
})


# scale_type --------------------------------------------------------------

Expand Down

0 comments on commit 67d80ce

Please sign in to comment.