Skip to content

Commit

Permalink
Compatibility with ggplot2 3.5.0 (#148)
Browse files Browse the repository at this point in the history
* deal with elements with dual parentage

* Avoid filling some specific settings

* Update snapshots

* Update snapshots again (with latest ggplot2)

* Get rid of unnecessary subsetting

* Update news

---------

Co-authored-by: Carson <cpsievert1@gmail.com>
  • Loading branch information
teunbrand and cpsievert authored Feb 12, 2024
1 parent 07d4aae commit 3db4490
Show file tree
Hide file tree
Showing 63 changed files with 2,917 additions and 8,181 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# thematic 0.1.4

* Accommodate for breaking changes in ggplot2 v3.5.0. (#148)
* The `{httpgd}` graphics device (and thus, Github codespaces) is now supported. (#143)
* `{thematic}` now works with recent versions of the `{vdiffr}` package. (#149)

Expand Down
17 changes: 14 additions & 3 deletions R/ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ ggthematic_build <- function(p, ggplot_build = NULL, theme = NULL) {
new = theme_user[[name]], old = theme_final[[name]]
)
}

# There are some theme settings that are best not filled in yet.
# These gain different internal defaults based on the text position and
# setting them here would disrupt that mechanism.
restore <- c("hjust", "vjust", "margin")
for (name in c("title", "legend.title", "legend.text")) {
theme_final[[name]][restore] <- p$theme[[name]][restore] %||% list(NULL)
}
p$theme <- theme_final

ggplot_build(p)
Expand Down Expand Up @@ -320,9 +328,12 @@ resolve_theme_inheritance <- function(p_theme) {

# TODO: could consider memoising if this proves to be a bottleneck
theme_relationships <- function() {
inherits <- vapply(ggplot2::get_element_tree(), function(x) { x$inherit %||% "" }, character(1))
relations <- data.frame(child = names(inherits), parent = inherits, stringsAsFactors = FALSE)
relations[relations$parent != "", ]
inherits <- lapply(ggplot2::get_element_tree(), function(x) x$inherit)
data.frame(
child = rep(names(inherits), lengths(inherits)),
parent = unlist(inherits),
stringsAsFactors = FALSE
)
}

# It's not safe to calc all elements (e.g., plot.margin)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geomabline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
303 changes: 152 additions & 151 deletions tests/testthat/_snaps/ggplot/geombin2d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
222 changes: 111 additions & 111 deletions tests/testthat/_snaps/ggplot/geomcount.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 66 additions & 68 deletions tests/testthat/_snaps/ggplot/geomcurve.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 74 additions & 74 deletions tests/testthat/_snaps/ggplot/geomdensitycolor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geomdotplot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 50 additions & 50 deletions tests/testthat/_snaps/ggplot/geomerror.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 43 additions & 41 deletions tests/testthat/_snaps/ggplot/geomerrorbar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
534 changes: 267 additions & 267 deletions tests/testthat/_snaps/ggplot/geomhistogram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 32 additions & 32 deletions tests/testthat/_snaps/ggplot/geomlabel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geomline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 87 additions & 87 deletions tests/testthat/_snaps/ggplot/geomline2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 21 additions & 21 deletions tests/testthat/_snaps/ggplot/geompoint2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 68 additions & 67 deletions tests/testthat/_snaps/ggplot/geompointcolor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geompolygon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 57 additions & 56 deletions tests/testthat/_snaps/ggplot/geompolygon2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geomribbon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
674 changes: 337 additions & 337 deletions tests/testthat/_snaps/ggplot/geomsmooth2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot/geomspoke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 40 additions & 40 deletions tests/testthat/_snaps/ggplot/geomtile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
632 changes: 318 additions & 314 deletions tests/testthat/_snaps/ggplot/grid-arrange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
322 changes: 162 additions & 160 deletions tests/testthat/_snaps/ggplot/patchwork.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 87 additions & 87 deletions tests/testthat/_snaps/ggplot/qualitative-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions tests/testthat/_snaps/ggplot/qualitative-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 68 additions & 67 deletions tests/testthat/_snaps/ggplot/sequential-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 60 additions & 59 deletions tests/testthat/_snaps/ggplot/sequential-fill.svg

Large diffs are not rendered by default.

428 changes: 214 additions & 214 deletions tests/testthat/_snaps/ggthemes/base.svg

Large diffs are not rendered by default.

284 changes: 0 additions & 284 deletions tests/testthat/_snaps/ggthemes/calc.svg
Diff not rendered.
3 changes: 3 additions & 0 deletions tests/testthat/_snaps/ggthemes/classic.svg

Large diffs are not rendered by default.

285 changes: 0 additions & 285 deletions tests/testthat/_snaps/ggthemes/clean.svg
Diff not rendered.
279 changes: 0 additions & 279 deletions tests/testthat/_snaps/ggthemes/economist-white.svg
Diff not rendered.
279 changes: 0 additions & 279 deletions tests/testthat/_snaps/ggthemes/economist.svg
Diff not rendered.
248 changes: 0 additions & 248 deletions tests/testthat/_snaps/ggthemes/excel-new.svg
Diff not rendered.
284 changes: 0 additions & 284 deletions tests/testthat/_snaps/ggthemes/excel.svg
Diff not rendered.
278 changes: 0 additions & 278 deletions tests/testthat/_snaps/ggthemes/few.svg
Diff not rendered.
255 changes: 0 additions & 255 deletions tests/testthat/_snaps/ggthemes/fivethirtyeight.svg
Diff not rendered.
297 changes: 0 additions & 297 deletions tests/testthat/_snaps/ggthemes/foundation.svg
Diff not rendered.
279 changes: 0 additions & 279 deletions tests/testthat/_snaps/ggthemes/gdocs.svg
Diff not rendered.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggthemes/ggtheme-minimal-off.svg
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggthemes/ggtheme-minimal.svg
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggthemes/ggtheme-void.svg
Loading

0 comments on commit 3db4490

Please sign in to comment.