Skip to content

Commit 61b9ebc

Browse files
authored
Adapt to scales 1.4.0 (#6441)
* bump required version * update snapshot for scales#489 * tweak mixing proportions to preserve colours * remove shims * accept snapshot
1 parent 89b8f4d commit 61b9ebc

File tree

6 files changed

+31
-81
lines changed

6 files changed

+31
-81
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Imports:
3939
isoband,
4040
lifecycle (> 1.0.1),
4141
rlang (>= 1.1.0),
42-
scales (>= 1.3.0),
42+
scales (>= 1.4.0),
4343
stats,
4444
vctrs (>= 0.6.0),
4545
withr (>= 2.5.0)

R/geom-sf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ GeomSf <- ggproto("GeomSf", Geom,
171171
other_default <- modify_list(
172172
GeomPolygon$default_aes,
173173
aes(
174-
fill = from_theme(fill %||% col_mix(ink, paper, 0.9)),
174+
fill = from_theme(fill %||% col_mix(ink, paper, 0.899)),
175175
colour = from_theme(colour %||% col_mix(ink, paper, 0.35)),
176176
linewidth = from_theme(0.4 * borderwidth)
177177
)

R/theme-defaults.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ theme_grey <- function(base_size = 11, base_family = "",
167167
axis.line = element_blank(),
168168
axis.line.x = NULL,
169169
axis.line.y = NULL,
170-
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.305)),
170+
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.302)),
171171
axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1),
172172
axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0),
173173
axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1),
@@ -223,7 +223,7 @@ theme_grey <- function(base_size = 11, base_family = "",
223223
legend.box.background = element_blank(),
224224
legend.box.spacing = rel(2),
225225

226-
panel.background = element_rect(fill = col_mix(ink, paper, 0.925), colour = NA),
226+
panel.background = element_rect(fill = col_mix(ink, paper, 0.92), colour = NA),
227227
panel.border = element_blank(),
228228
panel.grid = element_line(colour = paper),
229229
panel.grid.minor = element_line(linewidth = rel(0.5)),
@@ -232,10 +232,10 @@ theme_grey <- function(base_size = 11, base_family = "",
232232
panel.spacing.y = NULL,
233233
panel.ontop = FALSE,
234234

235-
strip.background = element_rect(fill = col_mix(ink, paper, 0.854), colour = NA),
235+
strip.background = element_rect(fill = col_mix(ink, paper, 0.85), colour = NA),
236236
strip.clip = "on",
237237
strip.text = element_text(
238-
colour = col_mix(ink, paper, 0.105),
238+
colour = col_mix(ink, paper, 0.1),
239239
size = rel(0.8),
240240
margin = margin_auto(0.8 * half_line)
241241
),
@@ -303,7 +303,7 @@ theme_bw <- function(base_size = 11, base_family = "",
303303
panel.background = element_rect(fill = paper, colour = NA),
304304
panel.border = element_rect(colour = col_mix(ink, paper, 0.2)),
305305
# make gridlines dark, same contrast with white as in theme_grey
306-
panel.grid = element_line(colour = col_mix(ink, paper, 0.925)),
306+
panel.grid = element_line(colour = col_mix(ink, paper, 0.92)),
307307
panel.grid.minor = element_line(linewidth = rel(0.5)),
308308
# contour strips to match panel contour
309309
strip.background = element_rect(
@@ -380,18 +380,18 @@ theme_light <- function(base_size = 11, base_family = "",
380380
theme(
381381
# white panel with light grey border
382382
panel.background = element_rect(fill = paper, colour = NA),
383-
panel.border = element_rect(colour = col_mix(ink, paper, 0.705), linewidth = rel(1)),
383+
panel.border = element_rect(colour = col_mix(ink, paper, 0.702), linewidth = rel(1)),
384384
# light grey, thinner gridlines
385385
# => make them slightly darker to keep acceptable contrast
386386
panel.grid = element_line(colour = col_mix(ink, paper, 0.871)),
387387
panel.grid.major = element_line(linewidth = rel(0.5)),
388388
panel.grid.minor = element_line(linewidth = rel(0.25)),
389389

390390
# match axes ticks thickness to gridlines and colour to panel border
391-
axis.ticks = element_line(colour = col_mix(ink, paper, 0.705), linewidth = rel(0.5)),
391+
axis.ticks = element_line(colour = col_mix(ink, paper, 0.702), linewidth = rel(0.5)),
392392

393393
# dark strips with light text (inverse contrast compared to theme_grey)
394-
strip.background = element_rect(fill = col_mix(ink, paper, 0.705), colour = NA),
394+
strip.background = element_rect(fill = col_mix(ink, paper, 0.702), colour = NA),
395395
strip.text = element_text(
396396
colour = paper,
397397
size = rel(0.8),
@@ -423,7 +423,7 @@ theme_dark <- function(base_size = 11, base_family = "",
423423
) %+replace%
424424
theme(
425425
# dark panel
426-
panel.background = element_rect(fill = col_mix(ink, paper, 0.5), colour = NA),
426+
panel.background = element_rect(fill = col_mix(ink, paper, 0.499), colour = NA),
427427
# inverse grid lines contrast compared to theme_grey
428428
# make them thinner and try to keep the same visual contrast as in theme_light
429429
panel.grid = element_line(colour = col_mix(ink, paper, 0.42)),
@@ -436,7 +436,7 @@ theme_dark <- function(base_size = 11, base_family = "",
436436
# dark strips with light text (inverse contrast compared to theme_grey)
437437
strip.background = element_rect(fill = col_mix(ink, paper, 0.15), colour = NA),
438438
strip.text = element_text(
439-
colour = col_mix(ink, paper, 0.9),
439+
colour = col_mix(ink, paper, 0.899),
440440
size = rel(0.8),
441441
margin = margin_auto(0.8 * half_line)
442442
),
@@ -649,7 +649,7 @@ theme_test <- function(base_size = 11, base_family = "",
649649
axis.line = element_blank(),
650650
axis.line.x = NULL,
651651
axis.line.y = NULL,
652-
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.305)),
652+
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.302)),
653653
axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1),
654654
axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0),
655655
axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1),
@@ -715,12 +715,12 @@ theme_test <- function(base_size = 11, base_family = "",
715715
panel.ontop = FALSE,
716716

717717
strip.background = element_rect(
718-
fill = col_mix(ink, paper, 0.851),
718+
fill = col_mix(ink, paper, 0.85),
719719
colour = col_mix(ink, paper, 0.2)
720720
),
721721
strip.clip = "on",
722722
strip.text = element_text(
723-
colour = col_mix(ink, paper, 0.105),
723+
colour = col_mix(ink, paper, 0.1),
724724
size = rel(0.8),
725725
margin = margin_auto(0.8 * half_line)
726726
),

R/utilities.R

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -852,56 +852,6 @@ warn_dots_used <- function(env = caller_env(), call = caller_env()) {
852852
)
853853
}
854854

855-
# TODO: delete shims when {scales} releases >1.3.0.9000
856-
# and bump {scales} version requirements
857-
# Shim for scales/#424
858-
col_mix <- function(a, b, amount = 0.5) {
859-
input <- vec_recycle_common(a = a, b = b, amount = amount)
860-
a <- grDevices::col2rgb(input$a, TRUE)
861-
b <- grDevices::col2rgb(input$b, TRUE)
862-
new <- (a * (1 - input$amount) + b * input$amount)
863-
grDevices::rgb(
864-
new["red", ], new["green", ], new["blue", ],
865-
alpha = new["alpha", ], maxColorValue = 255
866-
)
867-
}
868-
869-
# Shim for scales/#427
870-
as_discrete_pal <- function(x, ...) {
871-
if (is.function(x)) {
872-
return(x)
873-
}
874-
pal_manual(x)
875-
}
876-
877-
# Shim for scales/#427
878-
as_continuous_pal <- function(x, ...) {
879-
if (is.function(x)) {
880-
return(x)
881-
}
882-
is_color <- grepl("^#(([[:xdigit:]]{2}){3,4}|([[:xdigit:]]){3,4})$", x) |
883-
x %in% grDevices::colours()
884-
if (all(is_color)) {
885-
colour_ramp(x)
886-
} else {
887-
stats::approxfun(seq(0, 1, length.out = length(x)), x)
888-
}
889-
}
890-
891-
# Replace shims by actual scales function when available
892-
on_load({
893-
nse <- getNamespaceExports("scales")
894-
if ("col_mix" %in% nse) {
895-
col_mix <- scales::col_mix
896-
}
897-
if ("as_discrete_pal" %in% nse) {
898-
as_discrete_pal <- scales::as_discrete_pal
899-
}
900-
if ("as_continuous_pal" %in% nse) {
901-
as_continuous_pal <- scales::as_continuous_pal
902-
}
903-
})
904-
905855
# TODO: Replace me if rlang/#1730 gets implemented
906856
# Similar to `rlang::check_installed()` but returns boolean and misses
907857
# features such as versions, comparisons and using {pak}.

tests/testthat/_snaps/scale-date.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
---
77

88
A <numeric> value was passed to a Datetime scale.
9-
i The value was converted to a <POSIXt> object.
9+
i The value was converted to a <POSIXct> object.
1010

1111
---
1212

tests/testthat/_snaps/theme/theme-with-inverted-colours.svg

Lines changed: 15 additions & 15 deletions
Loading

0 commit comments

Comments
 (0)