Skip to content

Commit 887222c

Browse files
committed
Add tests for patterns and gradients
Thanks again @trevorld 082641a#commitcomment-143136554
1 parent 082641a commit 887222c

File tree

8 files changed

+533
-5
lines changed

8 files changed

+533
-5
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: treemapify
22
Title: Draw Treemaps in 'ggplot2'
3-
Version: 2.5.6.9003
3+
Version: 2.5.6.9004
44
Authors@R: c(
55
person("David", "Wilkins", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-3385-8981")),
@@ -15,7 +15,8 @@ Imports:
1515
ggplot2 (>= 3.5),
1616
ggfittext (>= 0.5.0),
1717
grid (>= 3.1),
18-
cli (>= 3.6.1)
18+
cli (>= 3.6.1),
19+
svglite
1920
Suggests:
2021
knitr,
2122
rmarkdown,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ import(grid)
1818
importFrom(ggplot2,alpha)
1919
importFrom(ggplot2,layer)
2020
importFrom(grid,roundrectGrob)
21+
importFrom(svglite,svglite)

R/treemapify-package.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#' @keywords internal
2+
"_PACKAGE"
3+
4+
## usethis namespace: start
5+
#' @importFrom svglite svglite
6+
## usethis namespace: end
7+
NULL

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GeomTreemap
55
GeomTreemapText
66
HDI
77
Huizing
8+
ORCID
89
Squarified
910
Subgrouping
1011
TCVG

man/treemapify-package.Rd

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/plots/chequer-pattern-fill.svg

Lines changed: 336 additions & 0 deletions
Loading
Lines changed: 134 additions & 0 deletions
Loading

tests/testthat/test_plots.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,19 @@ test_that("plots look the way they should", {
105105
list(color = c("red", "black"))))
106106
})
107107

108-
# vdiffr does not support patterns
109-
expect_no_error({
108+
})
109+
110+
test_that("pattern fills work", {
111+
112+
skip_if_not_installed("svglite", "2.1.3")
113+
114+
svglite_writer <- function(plot, file, ...) {
115+
svglite::svglite(file)
116+
print(plot)
117+
dev.off()
118+
}
119+
120+
vdiffr::expect_doppelganger("linearGradient fills", {
110121
patterns <- list(
111122
linearGradient(c("red", "blue"), group = FALSE),
112123
linearGradient(c("yellow", "orange"), group = FALSE),
@@ -117,6 +128,16 @@ test_that("plots look the way they should", {
117128
ggplot2::ggplot(G4, ggplot2::aes(area = gdp_mil_usd, fill = country)) +
118129
geom_treemap() +
119130
ggplot2::scale_fill_manual(values = patterns)
120-
})
131+
}, writer = svglite_writer)
132+
133+
vdiffr::expect_doppelganger("chequer pattern fill", {
134+
chequer_pattern <- pattern(
135+
rectGrob(x = c(0.25, 0.75), y = c(0.25, 0.75), width = 0.5, height = 0.5),
136+
width = unit(5, "mm"), height = unit(5, "mm"), extend = "repeat",
137+
gp = gpar(fill = "limegreen")
138+
)
139+
ggplot2::ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = country)) +
140+
geom_treemap(fill = chequer_pattern)
141+
}, writer = svglite_writer)
121142

122143
})

0 commit comments

Comments
 (0)