Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vdiffr for visual unit tests #1874

Merged
merged 11 commits into from Feb 1, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,13 @@ language: R
cache: packages
sudo: false

addons:
apt:
sources:
- debian-sid
packages:
- libfreetype6

r_github_packages:
- hadley/staticdocs@old

Expand Down
2 changes: 2 additions & 0 deletions DESCRIPTION
Expand Up @@ -36,6 +36,7 @@ Suggests:
multcomp,
nlme,
testthat (>= 0.11.0),
vdiffr,
quantreg,
knitr,
rpart,
Expand Down Expand Up @@ -217,3 +218,4 @@ Collate:
'zzz.r'
VignetteBuilder: knitr
RoxygenNote: 6.0.0
Remotes: hadley/svglite
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -476,6 +476,7 @@ export(theme_linedraw)
export(theme_minimal)
export(theme_replace)
export(theme_set)
export(theme_test)
export(theme_update)
export(theme_void)
export(transform_position)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# ggplot2 2.2.1.9000

* Automatic visual unit tests with vdiffr.

* Layers no longer warn about unknown aesthetics who's value is set to
`NULL` (overriding a set aesthetic in the plot) (#1909).

Expand Down
111 changes: 111 additions & 0 deletions R/theme-defaults.r
Expand Up @@ -40,6 +40,10 @@
#' \item{\code{theme_void}}{
#' A completely empty theme.}
#'
#' \item{\code{theme_test}}{
#' A theme for visual unit tests. It should ideally never change except
#' for new features.}
#'
#' }
#'
#' @examples
Expand Down Expand Up @@ -341,3 +345,110 @@ theme_void <- function(base_size = 11, base_family = "") {
)
}

#' @export
#' @rdname ggtheme
theme_test <- function(base_size = 11, base_family = "") {
half_line <- base_size / 2

theme(
line = element_line(colour = "black", size = 0.5, linetype = 1,
lineend = "butt"),
rect = element_rect(fill = "white", colour = "black",
size = 0.5, linetype = 1),
text = element_text(
family = base_family, face = "plain",
colour = "black", size = base_size,
lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0,
margin = margin(), debug = FALSE
),

axis.line = element_blank(),
axis.line.x = NULL,
axis.line.y = NULL,
axis.text = element_text(size = rel(0.8), colour = "grey30"),
axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1),
axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0),
axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1),
axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line / 2), hjust = 0),
axis.ticks = element_line(colour = "grey20"),
axis.ticks.length = unit(half_line / 2, "pt"),
axis.title.x = element_text(
margin = margin(t = half_line),
vjust = 1
),
axis.title.x.top = element_text(
margin = margin(b = half_line),
vjust = 0
),
axis.title.y = element_text(
angle = 90,
margin = margin(r = half_line),
vjust = 1
),
axis.title.y.right = element_text(
angle = -90,
margin = margin(l = half_line),
vjust = 0
),

legend.background = element_rect(colour = NA),
legend.spacing = unit(0.4, "cm"),
legend.spacing.x = NULL,
legend.spacing.y = NULL,
legend.margin = margin(0, 0, 0, 0, "cm"),
legend.key = element_rect(fill = "white", colour=NA),
legend.key.size = unit(1.2, "lines"),
legend.key.height = NULL,
legend.key.width = NULL,
legend.text = element_text(size = rel(0.8)),
legend.text.align = NULL,
legend.title = element_text(hjust = 0),
legend.title.align = NULL,
legend.position = "right",
legend.direction = NULL,
legend.justification = "center",
legend.box = NULL,
legend.box.margin = margin(0, 0, 0, 0, "cm"),
legend.box.background = element_blank(),
legend.box.spacing = unit(0.4, "cm"),

panel.background = element_rect(fill = "white", colour = NA),
panel.border = element_rect(fill = NA, colour = "grey20"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.spacing = unit(half_line, "pt"),
panel.spacing.x = NULL,
panel.spacing.y = NULL,
panel.ontop = FALSE,

strip.background = element_rect(fill = "grey85", colour = "grey20"),
strip.text = element_text(colour = "grey10", size = rel(0.8)),
strip.text.x = element_text(margin = margin(t = half_line, b = half_line)),
strip.text.y = element_text(angle = -90, margin = margin(l = half_line, r = half_line)),
strip.placement = "inside",
strip.placement.x = NULL,
strip.placement.y = NULL,
strip.switch.pad.grid = unit(0.1, "cm"),
strip.switch.pad.wrap = unit(0.1, "cm"),

plot.background = element_rect(colour = "white"),
plot.title = element_text(
size = rel(1.2),
hjust = 0, vjust = 1,
margin = margin(b = half_line * 1.2)
),
plot.subtitle = element_text(
size = rel(0.9),
hjust = 0, vjust = 1,
margin = margin(b = half_line * 0.9)
),
plot.caption = element_text(
size = rel(0.9),
hjust = 1, vjust = 1,
margin = margin(t = half_line * 0.9)
),
plot.margin = margin(half_line, half_line, half_line, half_line),

complete = TRUE
)
}
4 changes: 4 additions & 0 deletions appveyor.yml
Expand Up @@ -12,6 +12,10 @@ install:

# Adapt as necessary starting from here

environment:
global:
USE_RTOOLS: true

build_script:
- travis-tool.sh install_deps

Expand Down
7 changes: 7 additions & 0 deletions man/ggtheme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions tests/figs/cartesian-coordinates/contract-range.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.