Skip to content

Commit 7e00673

Browse files
committed
add a test
1 parent 3b321db commit 7e00673

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/testthat/test-plotly-subplot.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,56 @@ test_that("shape paper repositioning", {
208208
expect_equal(y1, rep(0.75, 2))
209209
expect_equal(xref, rep("paper", 2))
210210
expect_equal(yref, rep("paper", 2))
211+
212+
# now with a fixed height/width
213+
p1 <- plot_ly(mtcars) %>%
214+
layout(
215+
shapes = ~list(
216+
type = "rect",
217+
x0 = 0.25,
218+
x1 = 0.75,
219+
xref = "paper",
220+
y0 = 0,
221+
y1 = 30,
222+
yanchor = 0.5,
223+
ysizemode = "pixel",
224+
yref = "paper",
225+
fillcolor = "red"
226+
)
227+
)
228+
p2 <- plot_ly(mtcars) %>%
229+
layout(
230+
shapes = ~list(
231+
type = "rect",
232+
y0 = 0.25,
233+
y1 = 0.75,
234+
yref = "paper",
235+
x0 = 0,
236+
x1 = 30,
237+
xanchor = 0.5,
238+
xsizemode = "pixel",
239+
xref = "paper",
240+
line = list(color = "blue")
241+
)
242+
)
243+
244+
s <- subplot(p1, p2)
245+
shapes <- expect_doppelganger_built(s, "subplot-reposition-shape-fixed")$layout$shapes
246+
expect_length(shapes, 2)
247+
248+
xanchor <- lapply(shapes, "[[", "xanchor")[[2]]
249+
yanchor <- lapply(shapes, "[[", "yanchor")[[1]]
250+
x0 <- sapply(shapes, "[[", "x0")
251+
x1 <- sapply(shapes, "[[", "x1")
252+
y0 <- sapply(shapes, "[[", "y0")
253+
y1 <- sapply(shapes, "[[", "y1")
254+
255+
expect_equal(xanchor, 0.76)
256+
expect_equal(yanchor, 0.5)
257+
expect_equal(x0, c(0.12, 0))
258+
expect_equal(x1, c(0.36, 30))
259+
expect_equal(y0, c(0, 0.25))
260+
expect_equal(y1, c(30, 0.75))
211261
})
212262

213263

0 commit comments

Comments
 (0)