Skip to content

Commit 183e7ad

Browse files
authored
Repurpose rect key (#6327)
* default linewidth to 0 * draw_key_rect treats NA-fill as missing * swap raster key * accept snapshots * lol at my incompetence * add news bullet * accept snapshot change
1 parent 2478406 commit 183e7ad

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@
333333
to retrieve the class via constructor functions (@teunbrand).
334334
* (internal) The ViewScale class has a `make_fixed_copy()` method to permit
335335
copying trained position scales (#3441).
336+
* `draw_key_rect()` replaces a `NA` fill by the `colour` aesthetic and
337+
`draw_key_polygon()` has 0 linewidth as internal default (@teunbrand, #5385).
336338
* Improved consistency of curve direction in `geom_curve()` (@teunbrand, #5069)
337339
* `linetype = NA` is now interpreted to mean 'no line' instead of raising errors
338340
(@teunbrand, #6269).

R/geom-raster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,5 @@ GeomRaster <- ggproto("GeomRaster", Geom,
127127
default.units = "native", interpolate = interpolate
128128
)
129129
},
130-
draw_key = draw_key_rect
130+
draw_key = draw_key_polygon
131131
)

R/legend-draw.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,18 @@ draw_key_abline <- function(data, params, size) {
5454
#' @export
5555
#' @rdname draw_key
5656
draw_key_rect <- function(data, params, size) {
57+
colour <- if (is.na(data$fill %||% NA)) data$colour
5758
rectGrob(gp = gg_par(
5859
col = NA,
59-
fill = fill_alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
60+
fill = fill_alpha(colour %||% "grey20", data$alpha),
6061
lty = data$linetype %||% 1
6162
))
6263
}
6364
#' @export
6465
#' @rdname draw_key
6566
draw_key_polygon <- function(data, params, size) {
66-
if (is.null(data$linewidth)) {
67-
data$linewidth <- 0.5
68-
}
6967

70-
lwd <- data$linewidth
68+
lwd <- data$linewidth %||% 0
7169

7270
grob <- rectGrob(
7371
width = unit(1, "npc") - unit(lwd, "mm"),

tests/testthat/_snaps/draw-key/time-series-and-polygon-key-glyphs.svg

Lines changed: 3 additions & 3 deletions
Loading

tests/testthat/_snaps/geom-raster/discrete-positions.svg

Lines changed: 4 additions & 4 deletions
Loading

tests/testthat/_snaps/geom-raster/irregular-categorical.svg

Lines changed: 3 additions & 3 deletions
Loading

tests/testthat/_snaps/geom-raster/rectangle-fallback.svg

Lines changed: 4 additions & 4 deletions
Loading

tests/testthat/_snaps/legend-draw/all-legend-keys.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)