Skip to content

Commit

Permalink
Fix calculation of theme defaults
Browse files Browse the repository at this point in the history
**Issue**
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.

**Solution**
Be more specific when calculating the theme defaults.

**Clean Up**
`theme_void` was insufficiently specified. The solution exposed
missing elements that had to be specified.

Fixes tidyverse#2058
Fixes tidyverse#2079
  • Loading branch information
has2k1 committed Aug 1, 2017
1 parent d3321f9 commit a4184d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@

* `position_jitter()` gains a `seed` argument that allows specifying a random seed for reproducible jittering (#1996, @krlmlr).

* Fixed bug where a new complete `theme` may fail to override all elements of the default `theme`.
(@has2k1, #2058, #2079)

### sf

Expand Down
3 changes: 3 additions & 0 deletions R/theme-defaults.r
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,12 @@ theme_void <- function(base_size = 11, base_family = "",
),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks.length = unit(0, "pt"),
legend.position = "right",
legend.text = element_text(size = rel(0.8)),
legend.title = element_text(hjust = 0),
strip.text = element_text(size = rel(0.8)),
panel.ontop = FALSE,
plot.margin = unit(c(0, 0, 0, 0), "lines"),

complete = TRUE
Expand Down
9 changes: 8 additions & 1 deletion R/theme.r
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ theme <- function(line,

# Combine plot defaults with current theme to get complete theme for a plot
plot_theme <- function(x) {
defaults(x$theme, theme_get())
complete <- attr(x$theme, "complete")
if (is.null(complete)) {
theme_get()
} else if (complete) {
x$theme
} else {
defaults(x$theme, theme_get())
}
}

#' Modify properties of an element in a theme object
Expand Down

0 comments on commit a4184d5

Please sign in to comment.