File: test-style.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65


p1 <- plot_ly(x = 1:10, y = 1:10, symbol = I(15))
marker1 <- plotly_build(p1)$x$data[[1]]$marker

test_that("Whole update works as expected", {
  p2 <- style(p1, marker = list(color = "red"))
  marker2 <- plotly_build(p2)$x$data[[1]]$marker
  expect_equal(marker2, list(color = "red"))
  
  p3 <- style(p1, marker = list(line = list(color = "red", width = 10)))
  marker3 <- plotly_build(p3)$x$data[[1]]$marker
  expect_equal(marker3, list(line = list(color = "red", width = 10)))
})


test_that("Partial update works as expected", {
  p4 <- style(p1, marker.color = "red")
  marker4 <- plotly_build(p4)$x$data[[1]]$marker
  expect_equal(marker4, modifyList(marker4, list(color = "red")))
  
  p5 <- style(p1, marker.line.color = "red")
  marker5 <- plotly_build(p5)$x$data[[1]]$marker
  expect_equal(marker5, modifyList(marker5, list(line = list(color = "red"))))
})

test_that("Partial update works as expected", {
  p4 <- style(p1, marker.color = "red")
  marker4 <- plotly_build(p4)$x$data[[1]]$marker
  expect_equal(marker4, modifyList(marker4, list(color = "red")))
  
  p5 <- style(p1, marker.line.color = "red")
  marker5 <- plotly_build(p5)$x$data[[1]]$marker
  expect_equal(marker5, modifyList(marker5, list(line = list(color = "red"))))
})


test_that("Partial update works as expected", {
  trace <- list(
    x = 1:5,
    y = 6:10,
    marker = list(line = list(color = "red", width = 20))
  )
  
  trace_new <- trace_replace(trace, c("marker", "line"), list(width = 10))
  trace$marker$line <- list(width = 10)
  expect_equal(trace_new, trace)
  
  trace <- list(
    x = 1:5,
    y = 6:10,
    marker = list(line = list(color = "red", width = 20))
  )
  trace_new <- trace_replace(trace, c("marker", "line", "width"), 10)
  trace$marker$line$width <- 10
  expect_equal(trace_new, trace)
  
  trace <- list(
    x = 1:5,
    y = 6:10
  )
  trace_new <- trace_replace(trace, c("marker", "line", "width"), 10)
  trace$marker$line$width <- 10
  expect_equal(trace_new, trace)
})