Skip to content

Commit ae0be9b

Browse files
authored
Merge pull request #37 from thomasp85/patch-2
Add `print_plot()` method for grob
2 parents faf6159 + e56c6dc commit ae0be9b

File tree

7 files changed

+46
-84
lines changed

7 files changed

+46
-84
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
S3method(print_plot,"function")
44
S3method(print_plot,default)
55
S3method(print_plot,ggplot)
6+
S3method(print_plot,grob)
67
S3method(print_plot,recordedplot)
78
export(expect_doppelganger)
89
export(write_svg)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ There are two steps to update your snapshots to vdiffr 1.0.
2525
run `devtools::test()`, and then `testthat::snapshot_review()`.
2626

2727

28+
## Other changes
29+
30+
* `expect_doppelganger()` now supports grid objects such as `gtable`
31+
and `grob` (#36).
32+
33+
2834
# vdiffr 0.4.0
2935

3036
This is a github-only release that is meant to help you migrate from

R/svg.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ print_plot.ggplot <- function(p, title = "") {
4343
print(p)
4444
}
4545

46+
#' @export
47+
print_plot.grob <- function(p, title) {
48+
grid::grid.draw(p)
49+
}
50+
4651
#' @export
4752
print_plot.recordedplot <- function(p, title) {
4853
grDevices::replayPlot(p)
Lines changed: 23 additions & 0 deletions
Loading

tests/testthat/_snaps/expect-doppelganger/page-error1.svg

Lines changed: 0 additions & 41 deletions
Loading

tests/testthat/_snaps/expect-doppelganger/page-error2.svg

Lines changed: 0 additions & 41 deletions
Loading

tests/testthat/test-expect-doppelganger.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ test_that("no 'svglite supports one page' error (#85)", {
7272
widths = unit(c(0.05, 0.9, 0.05), "npc"),
7373
heights = unit(c(0.05, 0.9, 0.05), "npc")
7474
)
75-
gt <- gtable_add_grob(gt, list(axes_grob), 2, 2, clip = "off")
76-
plot(gt)
75+
gtable_add_grob(gt, list(axes_grob), 2, 2, clip = "off")
7776
}
7877
environment(test_draw_axis) <- env(ns_env("ggplot2"))
7978

8079
expect_doppelganger("page-error1", test_draw_axis(FALSE))
8180
expect_doppelganger("page-error2", test_draw_axis(TRUE))
8281
})
82+
83+
test_that("supports `grob` objects (#36)", {
84+
circle <- grid::circleGrob(
85+
x = 0.5,
86+
y = 0.5,
87+
r = 0.5,
88+
gp = grid::gpar(col = "gray", lty = 3)
89+
)
90+
expect_doppelganger("grob", circle)
91+
})

0 commit comments

Comments
 (0)