test-gtables.R 4.23 KB
Newer Older
1 2
test_that("gtable text row no padding", {
  theme <- ttheme_awesome(padding=unit(c(0,0), "mm"))
Pradat Yoann's avatar
Pradat Yoann committed
3
  d <- t(DBS$colData$description)
4 5
  widths <- rep(theme$core$size, ncol(d))
  heights <- unit(4, "mm")
Pradat Yoann's avatar
Pradat Yoann committed
6

Pradat Yoann's avatar
Pradat Yoann committed
7
  gc <- gtable_table(d, name="colhead",
8 9 10 11 12 13
                     widths=widths,
                     heights=heights,
                     fg_fun=theme$colhead$fg_fun, 
                     bg_fun=theme$colhead$bg_fun, 
                     fg_params=theme$colhead$fg_params, 
                     bg_params=theme$colhead$bg_params, 
Pradat Yoann's avatar
Pradat Yoann committed
14
                     padding=theme$colhead$padding)
Pradat Yoann's avatar
Pradat Yoann committed
15

16 17 18 19 20 21 22
  out <- plot_grob(gc, name="gtable_text_row_no_padding.pdf", width=8, height=1)
  expect_true(out$plot_success)

})

test_that("gtable text row with padding", {
  theme <- ttheme_awesome(padding=unit(c(2,0), "mm"))
Pradat Yoann's avatar
Pradat Yoann committed
23
  d <- t(DBS$colData$description)
24 25 26 27 28 29 30 31 32 33 34 35 36 37
  widths <- rep(theme$core$size, ncol(d))
  heights <- unit(4, "mm")

  gc <- gtable_table(d, name="colhead",
                     widths=widths,
                     heights=heights,
                     fg_fun=theme$colhead$fg_fun, 
                     bg_fun=theme$colhead$bg_fun, 
                     fg_params=theme$colhead$fg_params, 
                     bg_params=theme$colhead$bg_params, 
                     padding=theme$colhead$padding)

  out <- plot_grob(gc, name="gtable_text_row_with_padding.pdf", width=8, height=1)
  expect_true(out$plot_success)
Pradat Yoann's avatar
Pradat Yoann committed
38 39 40
})

test_that("gtable text col", {
41
  theme <- ttheme_awesome(padding=unit(c(0,0), "mm"))
Pradat Yoann's avatar
Pradat Yoann committed
42 43
  d <- DBS$rowData$name
  heights <- rep(theme$core$size, length(d))
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

  gr <- gtable_table(d, name="rowhead",
                     heights=heights,
                     fg_fun=theme$rowhead$fg_fun, 
                     bg_fun=theme$rowhead$bg_fun, 
                     fg_params=theme$rowhead$fg_params, 
                     bg_params=theme$rowhead$bg_params, 
                     padding=theme$rowhead$padding)

  out <- plot_grob(gr, name="gtable_text_col.pdf", width=1, height=4.5)
  expect_true(out$plot_success)
})

test_that("gtable text mat no padding", {
  theme <- ttheme_awesome(padding=unit(c(0,0), "mm"))
Pradat Yoann's avatar
Pradat Yoann committed
59
  d <- DBS$rowData$name
60 61 62
  d <- matrix(rep(d, 5), nrow=5, byrow=T)
  widths <- rep(theme$core$size, ncol(d))
  heights <- rep(theme$core$size, nrow(d))
Pradat Yoann's avatar
Pradat Yoann committed
63

Pradat Yoann's avatar
Pradat Yoann committed
64
  gr <- gtable_table(d, name="rowhead",
65 66 67 68 69 70
                     widths=widths,
                     heights=heights,
                     fg_fun=theme$rowhead$fg_fun, 
                     bg_fun=theme$rowhead$bg_fun, 
                     fg_params=theme$rowhead$fg_params, 
                     bg_params=theme$rowhead$bg_params, 
Pradat Yoann's avatar
Pradat Yoann committed
71
                     padding=theme$rowhead$padding)
Pradat Yoann's avatar
Pradat Yoann committed
72

73 74
  out <- plot_grob(gr, name="gtable_text_mat_no_padding.pdf")
  expect_true(out$plot_success)
Pradat Yoann's avatar
Pradat Yoann committed
75 76
})

77 78
test_that("gtable text mat with padding", {
  theme <- ttheme_awesome(padding=unit(c(1,1), "mm"))
Pradat Yoann's avatar
Pradat Yoann committed
79
  d <- DBS$rowData$name
Pradat Yoann's avatar
Pradat Yoann committed
80
  d <- matrix(rep(d, 5), nrow=5, byrow=T)
81 82
  widths <- rep(theme$core$size, ncol(d))
  heights <- rep(theme$core$size, nrow(d))
Pradat Yoann's avatar
Pradat Yoann committed
83

Pradat Yoann's avatar
Pradat Yoann committed
84
  gr <- gtable_table(d, name="rowhead",
85 86 87 88 89 90
                     widths=widths,
                     heights=heights,
                     fg_fun=theme$rowhead$fg_fun, 
                     bg_fun=theme$rowhead$bg_fun, 
                     fg_params=theme$rowhead$fg_params, 
                     bg_params=theme$rowhead$bg_params, 
Pradat Yoann's avatar
Pradat Yoann committed
91
                     padding=theme$rowhead$padding)
Pradat Yoann's avatar
Pradat Yoann committed
92

93 94
  out <- plot_grob(gr, name="gtable_text_mat_with_padding.pdf")
  expect_true(out$plot_success)
Pradat Yoann's avatar
Pradat Yoann committed
95 96
})

97 98 99

test_that("gtable circle", {
  theme <- ttheme_awesome()
Pradat Yoann's avatar
Pradat Yoann committed
100
  d <- DBS$assays$proportion
101 102 103 104 105 106 107 108 109 110 111
  widths <- rep(theme$core$size, ncol(d))
  heights <- rep(theme$core$size, nrow(d))

  g <- gtable_table(d, name="circle",
                     widths=widths,
                     heights=heights,
                     fg_fun=theme$core$fg_fun, 
                     bg_fun=theme$core$bg_fun, 
                     fg_params=theme$core$fg_params, 
                     bg_params=theme$core$bg_params, 
                     padding=theme$core$padding,
112 113 114
                     scale_breaks=theme$core$scale_breaks,
                     dscale_min=NULL,
                     dscale_max=NULL,
Pradat Yoann's avatar
Pradat Yoann committed
115
                     r_min=0.1*theme$core$size,
116
                     r_max=0.5*theme$core$size)
117 118 119 120

  out <- plot_grob(g, name="gtable_circle.pdf")
  expect_true(out$plot_success)
})