From f0965ac1487f20bbc2bc0fe8a1fc44aaa7e3173b Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 10 Feb 2025 10:06:20 +0100 Subject: [PATCH 1/7] default linewidth to 0 --- R/legend-draw.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/legend-draw.R b/R/legend-draw.R index d08c6c6c93..1e04597db8 100644 --- a/R/legend-draw.R +++ b/R/legend-draw.R @@ -67,11 +67,8 @@ draw_key_rect <- function(data, params, size) { #' @export #' @rdname draw_key draw_key_polygon <- function(data, params, size) { - if (is.null(data$linewidth)) { - data$linewidth <- 0.5 - } - lwd <- data$linewidth + lwd <- data$linewidth %||% 0 grob <- rectGrob( width = unit(1, "npc") - unit(lwd, "mm"), From e9f511fdcff724c20b1646a1ee5e38cc28f302e3 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 10 Feb 2025 10:06:46 +0100 Subject: [PATCH 2/7] draw_key_rect treats NA-fill as missing --- R/legend-draw.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/legend-draw.R b/R/legend-draw.R index 1e04597db8..e9b83eb1be 100644 --- a/R/legend-draw.R +++ b/R/legend-draw.R @@ -58,9 +58,10 @@ draw_key_abline <- function(data, params, size) { #' @export #' @rdname draw_key draw_key_rect <- function(data, params, size) { + colour <- if (is.na(data$fill %||% NA)) data$colour rectGrob(gp = gg_par( col = NA, - fill = fill_alpha(data$fill %||% data$colour %||% "grey20", data$alpha), + fill = fill_alpha(col %||% "grey20", data$alpha), lty = data$linetype %||% 1 )) } From eae0a7992b9edcdbeb0626f3d6418c8a15ff1755 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 10 Feb 2025 10:06:59 +0100 Subject: [PATCH 3/7] swap raster key --- R/geom-raster.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-raster.R b/R/geom-raster.R index 94b1775373..c51a01ff54 100644 --- a/R/geom-raster.R +++ b/R/geom-raster.R @@ -124,5 +124,5 @@ GeomRaster <- ggproto("GeomRaster", Geom, default.units = "native", interpolate = interpolate ) }, - draw_key = draw_key_rect + draw_key = draw_key_polygon ) From 578cec438211ca31280d1a7efac85bc9bdcd1912 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 10 Feb 2025 10:07:09 +0100 Subject: [PATCH 4/7] accept snapshots --- .../draw-key/time-series-and-polygon-key-glyphs.svg | 6 +++--- tests/testthat/_snaps/geom-raster/discrete-positions.svg | 8 ++++---- .../testthat/_snaps/geom-raster/irregular-categorical.svg | 6 +++--- tests/testthat/_snaps/geom-raster/rectangle-fallback.svg | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg b/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg index 90a5b755d2..5e3b176475 100644 --- a/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg +++ b/tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg @@ -59,11 +59,11 @@ z - + - + - + a b c diff --git a/tests/testthat/_snaps/geom-raster/discrete-positions.svg b/tests/testthat/_snaps/geom-raster/discrete-positions.svg index ee3e5a1491..5aca7daef6 100644 --- a/tests/testthat/_snaps/geom-raster/discrete-positions.svg +++ b/tests/testthat/_snaps/geom-raster/discrete-positions.svg @@ -44,13 +44,13 @@ interaction(x, y) - + - + - + - + A.C B.C A.D diff --git a/tests/testthat/_snaps/geom-raster/irregular-categorical.svg b/tests/testthat/_snaps/geom-raster/irregular-categorical.svg index 68dda93cfe..dc12288875 100644 --- a/tests/testthat/_snaps/geom-raster/irregular-categorical.svg +++ b/tests/testthat/_snaps/geom-raster/irregular-categorical.svg @@ -56,11 +56,11 @@ factor(col) - + - + - + 0 1 NA diff --git a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg index efb96b5c87..b2c818b6a0 100644 --- a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg +++ b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg @@ -62,13 +62,13 @@ fill - + - + - + - + A B C From ee8bd00b932f0b574103f69ce8f5998e35259f1b Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 10 Feb 2025 10:11:09 +0100 Subject: [PATCH 5/7] lol at my incompetence --- R/legend-draw.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/legend-draw.R b/R/legend-draw.R index e9b83eb1be..e49f3ad318 100644 --- a/R/legend-draw.R +++ b/R/legend-draw.R @@ -61,7 +61,7 @@ draw_key_rect <- function(data, params, size) { colour <- if (is.na(data$fill %||% NA)) data$colour rectGrob(gp = gg_par( col = NA, - fill = fill_alpha(col %||% "grey20", data$alpha), + fill = fill_alpha(colour %||% "grey20", data$alpha), lty = data$linetype %||% 1 )) } From f9a990473218c6640ab16808477ca4e23ca73d60 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 25 Mar 2025 13:54:10 +0100 Subject: [PATCH 6/7] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 2f490a4d33..82218e91f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -327,6 +327,8 @@ to retrieve the class via constructor functions (@teunbrand). * (internal) The ViewScale class has a `make_fixed_copy()` method to permit copying trained position scales (#3441). +* `draw_key_rect()` replaces a `NA` fill by the `colour` aesthetic and + `draw_key_polygon()` has 0 linewidth as internal default (@teunbrand, #5385). # ggplot2 3.5.1 From 1d9443cb379d74dd616a4b55682465a20340d6a7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 25 Mar 2025 16:35:20 +0100 Subject: [PATCH 7/7] accept snapshot change --- tests/testthat/_snaps/legend-draw/all-legend-keys.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/legend-draw/all-legend-keys.svg b/tests/testthat/_snaps/legend-draw/all-legend-keys.svg index c1ea77a335..e535bebe99 100644 --- a/tests/testthat/_snaps/legend-draw/all-legend-keys.svg +++ b/tests/testthat/_snaps/legend-draw/all-legend-keys.svg @@ -23,7 +23,7 @@ abline rect - + polygon blank