Skip to content

Commit 90f4aa0

Browse files
committed
add some basic subplot tests
1 parent d86969c commit 90f4aa0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/testthat/test-plotly-subplot.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
context("subplot")
2+
3+
expect_traces <- function(p, n.traces, name){
4+
stopifnot(is.numeric(n.traces))
5+
L <- save_outputs(p, paste0("plotly-subplot", name))
6+
expect_equal(length(L$data), n.traces)
7+
L
8+
}
9+
10+
test_that("simple subplot works", {
11+
p1 <- plot_ly(x = c(1, 2))
12+
p2 <- plot_ly(x = c(1, 2))
13+
s <- expect_traces(subplot(p1, p2), 2, "simple")
14+
expect_identical(s$data[[2]]$xaxis, s$layout[["yaxis2"]][["anchor"]])
15+
expect_identical(s$data[[2]]$yaxis, s$layout[["xaxis2"]][["anchor"]])
16+
doms <- lapply(s$layout, "[[", "domain")
17+
expect_true(doms$xaxis[2] < doms$xaxis2[1])
18+
})
19+
20+
test_that("nrows argument works", {
21+
p1 <- plot_ly(x = c(1, 2))
22+
p2 <- plot_ly(x = c(1, 2))
23+
s <- expect_traces(subplot(p1, p2, nrows = 2), 2, "simple")
24+
expect_identical(s$data[[2]]$xaxis, s$layout[["yaxis2"]][["anchor"]])
25+
expect_identical(s$data[[2]]$yaxis, s$layout[["xaxis2"]][["anchor"]])
26+
doms <- lapply(s$layout, "[[", "domain")
27+
expect_true(doms$yaxis[1] > doms$yaxis2[2])
28+
})
29+
30+
31+
32+

0 commit comments

Comments
 (0)