Skip to content

Commit 764a2ce

Browse files
committed
resolve merge conflict
Merge branch 'main' into S7_elements # Conflicts: # DESCRIPTION
2 parents 924b8b6 + 295f5cb commit 764a2ce

File tree

11 files changed

+73
-97
lines changed

11 files changed

+73
-97
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Imports:
4040
lifecycle (> 1.0.1),
4141
rlang (>= 1.1.0),
4242
S7,
43-
scales (>= 1.3.0),
43+
scales (>= 1.4.0),
4444
stats,
4545
vctrs (>= 0.6.0),
4646
withr (>= 2.5.0)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* (internal) New `Facet$draw_panel_content()` method for delegating panel
4+
assembly (@Yunuuuu, #6406).
35
* Facet gains a new method `setup_panel_params` to interact with the
46
panel_params setted by Coord object (@Yunuuuu, #6397, #6380)
57
* `position_fill()` avoids stacking observations of zero (@teunbrand, #6338)

R/facet-.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ NULL
6868
#' between the layer stack and the foreground defined by the Coord object
6969
#' (usually empty). The default is, as above, to return an empty grob.
7070
#'
71+
#' - `draw_panel_content`: Draws each panel for the facet. Should return a list
72+
#' of grobs, one for each panel. The output is used by the `draw_panels`
73+
#' method.
74+
#'
7175
#' - `draw_labels`: Given the gtable returned by `draw_panels`,
7276
#' add axis titles to the gtable. The default is to add one title at each side
7377
#' depending on the position and existence of axes.
@@ -138,6 +142,34 @@ Facet <- ggproto("Facet", NULL,
138142
draw_front = function(data, layout, x_scales, y_scales, theme, params) {
139143
rep(list(zeroGrob()), vec_unique_count(layout$PANEL))
140144
},
145+
draw_panel_content = function(self, panels, layout, x_scales, y_scales,
146+
ranges, coord, data, theme, params, ...) {
147+
facet_bg <- self$draw_back(
148+
data,
149+
layout,
150+
x_scales,
151+
y_scales,
152+
theme,
153+
params
154+
)
155+
facet_fg <- self$draw_front(
156+
data,
157+
layout,
158+
x_scales,
159+
y_scales,
160+
theme,
161+
params
162+
)
163+
164+
# Draw individual panels, then call `$draw_panels()` method to
165+
# assemble into gtable
166+
lapply(seq_along(panels[[1]]), function(i) {
167+
panel <- lapply(panels, `[[`, i)
168+
panel <- c(facet_bg[i], panel, facet_fg[i])
169+
panel <- coord$draw_panel(panel, ranges[[i]], theme)
170+
ggname(paste("panel", i, sep = "-"), panel)
171+
})
172+
},
141173
draw_panels = function(self, panels, layout, x_scales = NULL, y_scales = NULL,
142174
ranges, coord, data = NULL, theme, params) {
143175

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/layout.R

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,17 @@ Layout <- ggproto("Layout", NULL,
6060
# Assemble the facet fg & bg, the coord fg & bg, and the layers
6161
# Returns a gtable
6262
render = function(self, panels, data, theme, labels) {
63-
facet_bg <- self$facet$draw_back(data,
63+
panels <- self$facet$draw_panel_content(
64+
panels,
6465
self$layout,
6566
self$panel_scales_x,
6667
self$panel_scales_y,
67-
theme,
68-
self$facet_params
69-
)
70-
facet_fg <- self$facet$draw_front(
68+
self$panel_params,
69+
self$coord,
7170
data,
72-
self$layout,
73-
self$panel_scales_x,
74-
self$panel_scales_y,
7571
theme,
7672
self$facet_params
7773
)
78-
79-
# Draw individual panels, then assemble into gtable
80-
panels <- lapply(seq_along(panels[[1]]), function(i) {
81-
panel <- lapply(panels, `[[`, i)
82-
panel <- c(facet_bg[i], panel, facet_fg[i])
83-
panel <- self$coord$draw_panel(panel, self$panel_params[[i]], theme)
84-
ggname(paste("panel", i, sep = "-"), panel)
85-
})
8674
plot_table <- self$facet$draw_panels(
8775
panels,
8876
self$layout,

R/theme-defaults.R

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

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

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

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

394394
# dark strips with light text (inverse contrast compared to theme_grey)
395-
strip.background = element_rect(fill = col_mix(ink, paper, 0.705), colour = NA),
395+
strip.background = element_rect(fill = col_mix(ink, paper, 0.702), colour = NA),
396396
strip.text = element_text(
397397
colour = paper,
398398
size = rel(0.8),
@@ -424,7 +424,7 @@ theme_dark <- function(base_size = 11, base_family = "",
424424
) %+replace%
425425
theme(
426426
# dark panel
427-
panel.background = element_rect(fill = col_mix(ink, paper, 0.5), colour = NA),
427+
panel.background = element_rect(fill = col_mix(ink, paper, 0.499), colour = NA),
428428
# inverse grid lines contrast compared to theme_grey
429429
# make them thinner and try to keep the same visual contrast as in theme_light
430430
panel.grid = element_line(colour = col_mix(ink, paper, 0.42)),
@@ -437,7 +437,7 @@ theme_dark <- function(base_size = 11, base_family = "",
437437
# dark strips with light text (inverse contrast compared to theme_grey)
438438
strip.background = element_rect(fill = col_mix(ink, paper, 0.15), colour = NA),
439439
strip.text = element_text(
440-
colour = col_mix(ink, paper, 0.9),
440+
colour = col_mix(ink, paper, 0.899),
441441
size = rel(0.8),
442442
margin = margin_auto(0.8 * half_line)
443443
),
@@ -650,7 +650,7 @@ theme_test <- function(base_size = 11, base_family = "",
650650
axis.line = element_blank(),
651651
axis.line.x = NULL,
652652
axis.line.y = NULL,
653-
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.305)),
653+
axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.302)),
654654
axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1),
655655
axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0),
656656
axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1),
@@ -716,12 +716,12 @@ theme_test <- function(base_size = 11, base_family = "",
716716
panel.ontop = FALSE,
717717

718718
strip.background = element_rect(
719-
fill = col_mix(ink, paper, 0.851),
719+
fill = col_mix(ink, paper, 0.85),
720720
colour = col_mix(ink, paper, 0.2)
721721
),
722722
strip.clip = "on",
723723
strip.text = element_text(
724-
colour = col_mix(ink, paper, 0.105),
724+
colour = col_mix(ink, paper, 0.1),
725725
size = rel(0.8),
726726
margin = margin_auto(0.8 * half_line)
727727
),

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}.

man/ggplot2-ggproto.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)