Skip to content

User-facing tinytheme_get() function + restore plot region after theme - #738

Merged
grantmcdermott merged 13 commits into
mainfrom
issue629
Sep 21, 2026
Merged

grantmcdermott merged 13 commits into
mainfrom
issue629

Conversation

@grantmcdermott

@grantmcdermott grantmcdermott commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Closes #629

Follow-up on two good points made by @bastistician in this comment, after I'd already closed the issue.

  1. Users can now invoke the tinytheme_get() convenience function to grab the name of the current theme.
pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot
tinytheme("classic")
tinytheme_get()
#> [1] "classic"
tinytheme()
tinytheme_get()
#> [1] "default"
  1. type_v/hline and co. correctly reach the axis after a text() call. This ended up being slightly trickier to catch/and plug. The underlying issue is that a theme's margins are applied through a before.plot.new hook, so rolling the theme back on exit left par describing a different plot region than the one that was drawn into. Meanwhile, base R only recomputes the device clipping rectangle when xpd changes, so anything drawn after an intervening xpd toggle (e.g. text()-based, but also box(), etc.) was clipped short.
pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot
plt(0, 0, theme = "classic")
plt_add(par("usr")[1], y = 0.3, type = type_text(labels = "foo", xpd = NA, pos = 2))
plt_add(type = type_hline(0.3))

- An ephemeral theme's margins live only in the `before.plot.new` hook, so rolling it back left `par(plt)` describing a different region than was drawn into.
- Base R recomputes the device clip rect from `par()` whenever `xpd` changes, silently truncating anything added afterwards.

This comment was marked as resolved.

@grantmcdermott
grantmcdermott merged commit f5a97f3 into main Sep 21, 2026
3 checks passed
@grantmcdermott
grantmcdermott deleted the issue629 branch September 21, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mtext truncates plot region in classic theme

2 participants