Skip to content

Commit

Permalink
Format on plot page by #323
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosak01 committed Mar 16, 2024
1 parent cf32ef7 commit a34da51
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 11 deletions.
21 changes: 21 additions & 0 deletions R/plot_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ create_plot_pages_text <- function(rs, cntnt, lpg_rows, tmp_dir) {
# print(pgby$var)
# print(dat)
pgval <- dat[1, c(pgby$var)]

if (!is.null(pgby$format)) {
pgval <- fapply(pgval, pgby$format)
}
}

# Save plot to temp file
Expand Down Expand Up @@ -515,6 +519,10 @@ create_plot_pages_rtf <- function(rs, cntnt, lpg_rows, tmp_dir) {
# print(pgby$var)
# print(dat)
pgval <- dat[1, c(pgby$var)]

if (!is.null(pgby$format)) {
pgval <- fapply(pgval, pgby$format)
}
}

# Save plot to temp file
Expand Down Expand Up @@ -754,6 +762,10 @@ create_plot_pages_html <- function(rs, cntnt, lpg_rows, tmp_dir) {
# print(pgby$var)
# print(dat)
pgval <- dat[1, c(pgby$var)]

if (!is.null(pgby$format)) {
pgval <- fapply(pgval, pgby$format)
}
}

# Save plot to temp file
Expand Down Expand Up @@ -980,7 +992,12 @@ create_plot_pages_pdf <- function(rs, cntnt, lpg_rows, tmp_dir) {
if (!is.null(pgby)) {
# print(pgby$var)
# print(dat)

pgval <- dat[1, c(pgby$var)]

if (!is.null(pgby$format)) {
pgval <- fapply(pgval, pgby$format)
}
}

# Save plot to temp file
Expand Down Expand Up @@ -1277,6 +1294,10 @@ create_plot_pages_docx<- function(rs, cntnt, lpg_rows, tmp_dir, imgCnt) {
# print(pgby$var)
# print(dat)
pgval <- dat[1, c(pgby$var)]

if (!is.null(pgby$format)) {
pgval <- fapply(pgval, pgby$format)
}
}

# Save plot to temp file
Expand Down
Binary file removed tests/testthat/html/images/test11-DUG5.jpg
Binary file not shown.
Binary file removed tests/testthat/html/images/test14-B279.jpg
Binary file not shown.
Binary file removed tests/testthat/html/images/test14-UGDC.jpg
Binary file not shown.
Binary file removed tests/testthat/html/images/test14-XS6Y.jpg
Binary file not shown.
Binary file removed tests/testthat/html/images/test20-QFL6.jpg
Binary file not shown.
Binary file removed tests/testthat/pdf/test30.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test31.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test32.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test35.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test36.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test37.pdf
Binary file not shown.
Binary file removed tests/testthat/pdf/test38.pdf
Binary file not shown.
6 changes: 5 additions & 1 deletion tests/testthat/test-docx.R
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ test_that("docx14: Plot with page by on plot works as expected.", {

fp <- file.path(base_path, "docx/test14.docx")

fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

dat <- mtcars[order(mtcars$cyl), ]

Expand All @@ -518,7 +521,8 @@ test_that("docx14: Plot with page by on plot works as expected.", {
titles("Figure 1.0", "MTCARS Miles per Cylinder Plot",
borders = "all",
blank_row = "both") %>%
page_by(cyl, "Cylinders: ", borders = "all", blank_row = "both") %>%
page_by(cyl, "Cylinders: ", borders = "all", blank_row = "both",
format = fmt) %>%
footnotes("* Motor Trend, 1974", borders = "all", valign = "top",
blank_row = "both")

Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ test_that("html8: Page by works as expected.", {

dat <- iris


tbl <- create_table(dat, borders = "all") %>%
titles("Table 1.0", "My Nice Irises", "Another Title",
borders = "outside") %>%
page_by(Species, label = "Species: ", borders = "outside", align = "center") %>%
page_by(Species, label = "Species: ", borders = "outside",
align = "center") %>%
define(Sepal.Length, label = "Sepal Length", width = 1.5, align = "center") %>%
define(Sepal.Width, label = "Sepal Width", width = 1.25, align = "centre") %>%
define(Species, visible = FALSE) %>%
Expand Down Expand Up @@ -481,6 +481,10 @@ test_that("html14: Plot with page by on plot works as expected.", {
fp <- file.path(base_path, "html/test14.html")


fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

dat <- mtcars[order(mtcars$cyl), ]

p <- ggplot(dat, aes(x=disp, y=mpg)) + geom_point()
Expand All @@ -494,7 +498,7 @@ test_that("html14: Plot with page by on plot works as expected.", {
titles("Figure 1.0", "MTCARS Miles per Cylinder Plot",
borders = brdrs,
blank_row = "none") %>%
page_by(cyl, "Cylinders: ", borders = brdrs) %>%
page_by(cyl, "Cylinders: ", borders = brdrs, format = fmt) %>%
footnotes("* Motor Trend, 1974", borders = brdrs)

rpt <- create_report(fp, output_type = "HTML", font = fnt, font_size = fsz) %>%
Expand Down Expand Up @@ -592,7 +596,7 @@ test_that("html17: 9 pt font cm works as expected.", {

})

test_that("html8: 11 pt font inches works as expected.", {
test_that("html18: 11 pt font inches works as expected.", {


fp <- file.path(base_path, "html/test18.html")
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-pdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ test_that("pdf19: Plot with page by on plot works as expected.", {

fp <- file.path(base_path, "pdf/test19.pdf")


fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

dat <- mtcars[order(mtcars$cyl), ]

p <- ggplot(dat, aes(x=disp, y=mpg)) + geom_point()
Expand All @@ -650,7 +653,8 @@ test_that("pdf19: Plot with page by on plot works as expected.", {

plt <- create_plot(p, height = 4, width = 8) %>%
titles("Figure 1.0", "MTCARS Mileage By Displacement", blank_row = "none") %>%
page_by(cyl, "Cylinders: ", align = "left", blank_row = "none") %>%
page_by(cyl, "Cylinders: ", align = "left",
blank_row = "none", format = fmt) %>%
footnotes("* Motor Trend, 1974")

rpt <- create_report(fp, output_type = "PDF") %>%
Expand Down
17 changes: 15 additions & 2 deletions tests/testthat/test-pdf2.R
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,19 @@ test_that("pdf2-22: Page by works as expected.", {
fp <- file.path(base_path, "pdf2/test22.pdf")

dat <- iris
dat$Species <- as.character(dat$Species)

library(fmtr)

fmt <- value(condition(x == "setosa", "Setosa"),
condition(x == "versicolor", "Versicolor"),
condition(x == "virginica", "Virginica"))

tbl <- create_table(dat, borders = "all") %>%
titles("Table 1.0", "My Nice Report with a Page By", borders = "outside",
blank_row = "none") %>%
page_by(Species, label = "Species", align = "center", borders = "all",
blank_row = "none") %>%
blank_row = "none", format = fmt) %>%
footnotes("My footnote 1", "Page [pg] of [tpg]", borders = "none", align = "right")

rpt <- create_report(fp, output_type = "PDF", font = fnt,
Expand Down Expand Up @@ -1097,6 +1104,11 @@ test_that("pdf2-27: Plot with page by on plot works as expected.", {

if (dev) {
library(ggplot2)
library(fmtr)

fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

fp <- file.path(base_path, "pdf2/test27.pdf")

Expand All @@ -1112,7 +1124,8 @@ test_that("pdf2-27: Plot with page by on plot works as expected.", {
plt <- create_plot(p, height = 4, width = 8, borders = "all") %>%
titles("Figure 1.0", "MTCARS Miles per Cylinder Plot", blank_row = "none",
borders = "all") %>%
page_by(cyl, "Cylinders2: ", blank_row = "below", borders = "all") %>%
page_by(cyl, "Cylinders2: ", blank_row = "below",
borders = "all", format = fmt) %>%
footnotes("* Motor Trend, 1974", borders = "all")

rpt <- create_report(fp, output_type = "PDF", font = fnt, font_size = fsz) %>%
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-rtf.R
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ test_that("rtf19: Plot with page by on plot works as expected.", {

dat <- mtcars[order(mtcars$cyl), ]


fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

p <- ggplot(dat, aes(x=disp, y=mpg)) + geom_point()


Expand All @@ -628,7 +633,7 @@ test_that("rtf19: Plot with page by on plot works as expected.", {

plt <- create_plot(p, height = 4, width = 8) %>%
titles("Figure 1.0", "MTCARS Miles per Cylinder Plot", blank_row = "none") %>%
page_by(cyl, "Cylinders: ") %>%
page_by(cyl, "Cylinders: ", format = fmt) %>%
footnotes("* Motor Trend, 1974")

rpt <- create_report(fp, output_type = "RTF") %>%
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-rtf2.R
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,9 @@ test_that("rtf2-27: Plot with page by on plot works as expected.", {

fp <- file.path(base_path, "rtf2/test27.rtf")

fmt <- value(condition(x == 4, "4 Cylinder"),
condition(x == 6, "6 Cylinder"),
condition(x == 8, "8 Cylinder"))

dat <- mtcars[order(mtcars$cyl), ]

Expand All @@ -989,7 +992,7 @@ test_that("rtf2-27: Plot with page by on plot works as expected.", {

plt <- create_plot(p, height = 4, width = 8) %>%
titles("Figure 1.0", "MTCARS Miles per Cylinder Plot", blank_row = "none") %>%
page_by(cyl, "Cylinders: ") %>%
page_by(cyl, "Cylinders: ", format = fmt) %>%
footnotes("* Motor Trend, 1974")

rpt <- create_report(fp, output_type = "RTF", font = fnt, font_size = fsz) %>%
Expand Down

0 comments on commit a34da51

Please sign in to comment.