File: test-plotly-size.R

package info (click to toggle)
r-cran-plotly 4.9.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 26,616 kB
  • sloc: javascript: 137,775; sh: 20; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
context("size")

test_that("sizemode is always respected", {
  
  # https://github.com/ropensci/plotly/issues/1133
  p <- plot_ly(mtcars, x = ~wt, y = ~wt, size = ~wt, color = ~as.factor(carb)) 
  d <- expect_doppelganger_built(p, "sizemode")$data
  expect_length(d, length(unique(mtcars$carb)))
  
  for (i in seq_along(d)) {
    expect_true(d[[i]]$type == "scatter")
    expect_true(d[[i]]$mode == "markers")
    expect_true(d[[i]]$marker$sizemode == "area")
    # Make sure size is always translated as an array in this case, because plotly.js
    # https://github.com/plotly/plotly.js/issues/2735
    s <- d[[i]]$marker$size
    if (length(s) == 1) expect_is(s, "AsIs")
  }
})


test_that("size maps correctly to marker.size", {
  p <- plot_ly(x = 1:10, y = 1:10, size = I(30))
  d <- expect_doppelganger_built(p, "marker.size")$data
  expect_length(d[[1]]$marker$size, 10)
  expect_true(all(d[[1]]$marker$size == 30))
})