From afff326f69047e9117aaee6956af54a67cfef463 Mon Sep 17 00:00:00 2001
From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Date: Mon, 20 Nov 2023 10:12:09 +0100
Subject: [PATCH 1/2] Fix `ticks.length` not working
---
R/guide-colorbar.R | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/R/guide-colorbar.R b/R/guide-colorbar.R
index 7e71eaba0c..57f9d02757 100644
--- a/R/guide-colorbar.R
+++ b/R/guide-colorbar.R
@@ -439,14 +439,11 @@ GuideColourbar <- ggproto(
"horizontal" = c("bottom", "top"),
"vertical" = c("right", "left")
)
- elements$ticks_length <- rep(elements$ticks_length, length.out = 2)
- elem1 <- elem2 <- elements
- elem1$ticks_length <- elements$ticks_length[2]
- elem2$ticks_length <- elements$ticks_length[1]
+ ticks_length <- rep(elements$ticks_length, length.out = 2)
grobTree(
- Guide$build_ticks(pos, elem1, params, position[1]),
- Guide$build_ticks(pos, elem2, params, position[2])
+ Guide$build_ticks(pos, elements, params, position[1], ticks_length[1]),
+ Guide$build_ticks(pos, elements, params, position[2], ticks_length[2])
)
},
From 45781c942f6dd5647aba46945582d2304c1ff101 Mon Sep 17 00:00:00 2001
From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Date: Mon, 20 Nov 2023 10:12:48 +0100
Subject: [PATCH 2/2] include tick length in test
---
...ar-long-thick-black-ticks-green-frame.svg} | 22 +++++++++----------
tests/testthat/test-guides.R | 5 +++--
2 files changed, 14 insertions(+), 13 deletions(-)
rename tests/testthat/_snaps/guides/{white-to-red-colorbar-thick-black-ticks-green-frame.svg => white-to-red-colorbar-long-thick-black-ticks-green-frame.svg} (89%)
diff --git a/tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg b/tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
similarity index 89%
rename from tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg
rename to tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
index a10cf6f3e1..e5839bc3ff 100644
--- a/tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg
+++ b/tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
@@ -59,21 +59,21 @@
x
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
0.0
0.5
1.0
1.5
2.0
-white-to-red colorbar, thick black ticks, green frame
+white-to-red colorbar, long thick black ticks, green frame
diff --git a/tests/testthat/test-guides.R b/tests/testthat/test-guides.R
index 2ea4d3a696..8b44ffaf5c 100644
--- a/tests/testthat/test-guides.R
+++ b/tests/testthat/test-guides.R
@@ -708,14 +708,15 @@ test_that("colorbar can be styled", {
p + scale_color_gradient(low = 'white', high = 'red')
)
- expect_doppelganger("white-to-red colorbar, thick black ticks, green frame",
+ expect_doppelganger("white-to-red colorbar, long thick black ticks, green frame",
p + scale_color_gradient(
low = 'white', high = 'red',
guide = guide_colorbar(
frame = element_rect(colour = "green"),
frame.linewidth = 1.5 / .pt,
ticks.colour = "black",
- ticks.linewidth = 2.5 / .pt
+ ticks.linewidth = 2.5 / .pt,
+ ticks.length = unit(0.4, "npc")
)
)
)