Skip to content

Commit 38ae287

Browse files
committed
resolve merge conflict
Merge branch 'main' into S7_objects # Conflicts: # DESCRIPTION
2 parents 67dae2d + 295f5cb commit 38ae287

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

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

tests/testthat/test-coord-map.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ test_that("coord map throws error when limits are badly specified", {
5252
})
5353

5454
test_that("coord_map throws informative warning about guides", {
55+
skip_if_not_installed("mapproj")
5556
expect_snapshot_warning(
5657
ggplot_build(ggplot() + coord_map() + guides(x = guide_axis()))
5758
)

0 commit comments

Comments
 (0)