Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ where the formatting is also better._
- Fixed `type_ridge()` fill errors for themes that set a qualitative palette,
e.g. `"clean2"`. (#564 @grantmcdermott)

- Fixed plot clipping when using ephemeral `theme = "default"` with a legend
and `tinyplot_add()`. Thanks to @katrinabrock for the report in #557.
(#565 @grantmcdermott)

### Internals

- We now encourage type-specific legend customizations within the individual
Expand Down
16 changes: 11 additions & 5 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,19 @@ tinyplot.default = function(
} else {
warning('Argument `theme` must be a character of length 1 (e.g. "clean"), or a list. Ignoring.')
}
dtheme = theme_default
otheme = opar[names(dtheme)]

on.exit(do.call(tinytheme, otheme), add = TRUE)
if (is.character(theme) && theme == "default") {
# Reset mar to pre-theme value so legend margin adjustment isn't
# clobbered. Only needed for "default" theme which uses hook = FALSE
# and thus sets par(mar) immediately. (#557)
par(mar = opar$mar)
on.exit(init_tpar(rm_hook = TRUE), add = TRUE)
} else {
dtheme = theme_default
otheme = opar[names(dtheme)]
on.exit(do.call(tinytheme, otheme), add = TRUE)
}
}


#
## settings container -----
#
Expand Down
80 changes: 80 additions & 0 deletions inst/tinytest/_tinysnapshot/ephemeral_default_theme_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion inst/tinytest/test-tinytheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,11 @@ f = function() {
plt_add(type = "lm")
par(opar)
}
expect_snapshot_plot(f, label = "tinytheme_ephemeral")
expect_snapshot_plot(f, label = "tinytheme_ephemeral")

# Ephemeral "default" theme with by + plt_add should not clip (#557)
f = function() {
plt(1:3, c(1, 1, 1), by = c("a", "a", "a"), theme = "default", type = "n")
plt_add(type = "b")
}
expect_snapshot_plot(f, label = "ephemeral_default_theme_add")
Loading