tests/testthat/test-renderer1-segment-size.R

acontext("Segment size")

df <- data.frame(x=c(0, 0),
                 y=c(0, 1),
                 xend=c(1, 1),
                 yend=c(1, 0),
                 size=c(5, 10))

test_that("segment size translates to stroke-width", {
  viz <- list(segs=ggplot()+
              geom_segment(aes(x, y, xend=xend, yend=yend),
                           data=df, size=1))
  info <- animint2HTML(viz)
  ## Need the ^$ so that we do not match e.g. 210.
  expect_styles(info$html, list("stroke-width"="^1[a-z]*$"))
})
              
test_that("segment size range translates to stroke-width", {
  viz <- list(segs=ggplot()+
              geom_segment(aes(x, y, xend=xend, yend=yend, size=size),
                           data=df)+
              scale_size_identity())
  info <- animint2HTML(viz)
  expect_styles(info$html, list("stroke-width"=c("^5[a-z]*$", "^10[a-z]*$")))
})

Try the animint2 package in your browser

Any scripts or data that you put into this service are public.

animint2 documentation built on Nov. 22, 2023, 1:07 a.m.