Skip to content

Commit 9f3eb1a

Browse files
authored
Fix colourbar's ticks.length argument not working (#5529)
* Fix `ticks.length` not working * include tick length in test
1 parent 0a434ea commit 9f3eb1a

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

R/guide-colorbar.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,11 @@ GuideColourbar <- ggproto(
429429
"horizontal" = c("bottom", "top"),
430430
"vertical" = c("right", "left")
431431
)
432-
elements$ticks_length <- rep(elements$ticks_length, length.out = 2)
433-
elem1 <- elem2 <- elements
434-
elem1$ticks_length <- elements$ticks_length[2]
435-
elem2$ticks_length <- elements$ticks_length[1]
432+
ticks_length <- rep(elements$ticks_length, length.out = 2)
436433

437434
grobTree(
438-
Guide$build_ticks(pos, elem1, params, position[1]),
439-
Guide$build_ticks(pos, elem2, params, position[2])
435+
Guide$build_ticks(pos, elements, params, position[1], ticks_length[1]),
436+
Guide$build_ticks(pos, elements, params, position[2], ticks_length[2])
440437
)
441438
},
442439

tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg renamed to tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg

Lines changed: 11 additions & 11 deletions
Loading

tests/testthat/test-guides.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,14 +811,15 @@ test_that("colorbar can be styled", {
811811
p + scale_color_gradient(low = 'white', high = 'red')
812812
)
813813

814-
expect_doppelganger("white-to-red colorbar, thick black ticks, green frame",
814+
expect_doppelganger("white-to-red colorbar, long thick black ticks, green frame",
815815
p + scale_color_gradient(
816816
low = 'white', high = 'red',
817817
guide = guide_colorbar(
818818
frame = element_rect(colour = "green"),
819819
frame.linewidth = 1.5 / .pt,
820820
ticks.colour = "black",
821-
ticks.linewidth = 2.5 / .pt
821+
ticks.linewidth = 2.5 / .pt,
822+
ticks.length = unit(0.4, "npc")
822823
)
823824
)
824825
)

0 commit comments

Comments
 (0)