@@ -10,9 +10,9 @@ expect_traces <- function(p, n.traces, name){
10
10
11
11
test_that(" Can set colorbar attributes" , {
12
12
p <- plot_ly(mtcars , x = ~ wt , y = ~ cyl , color = ~ cyl )
13
- p <- colorbar(p , len = 0.5 )
13
+ p <- colorbar(p , len = 0.3 )
14
14
l <- expect_traces(p , 2 , " colorbar" )
15
- expect_equivalent(l $ data [[2 ]]$ marker $ colorbar $ len , 0.5 )
15
+ expect_equivalent(l $ data [[2 ]]$ marker $ colorbar $ len , 0.3 )
16
16
})
17
17
18
18
@@ -43,6 +43,8 @@ test_that("Can expand z limits", {
43
43
expect_equivalent(l $ data [[1 ]]$ zmax , 300 )
44
44
})
45
45
46
+
47
+ # TODO: values outside the scale limits should probably be non-transparent (e.g. gray)
46
48
test_that(" Can restrict z limits" , {
47
49
p <- plot_ly(z = ~ volcano )
48
50
p <- colorbar(p , limits = c(140 , 160 ))
@@ -54,3 +56,40 @@ test_that("Can restrict z limits", {
54
56
dim(v ) <- dim(volcano )
55
57
expect_equivalent(l $ data [[1 ]][[" z" ]], v )
56
58
})
59
+
60
+
61
+ test_that(" colorbar does not affect mode of other traces" , {
62
+ # https://github.com/ropensci/plotly/issues/1196
63
+ p <- plot_ly() %> %
64
+ add_markers(data = mtcars , x = ~ hp , y = ~ mpg , color = ~ wt ) %> %
65
+ add_lines(x = seq(100 , 300 , length.out = 20 ), y = seq(10 , 30 , length.out = 20 ),
66
+ color = I(" black" ))
67
+
68
+ expect_true(hide_colorbar(p )$ x $ data [[1 ]]$ mode == " markers" )
69
+ expect_true(hide_colorbar(p )$ x $ data [[2 ]]$ mode == " lines" )
70
+ expect_true(colorbar(p , limits = c(1 ,10 ))$ x $ data [[1 ]]$ mode == " markers" )
71
+ expect_true(colorbar(p , limits = c(1 ,10 ))$ x $ data [[2 ]]$ mode == " lines" )
72
+
73
+ })
74
+
75
+
76
+ test_that(" can control both fill and stroke colorbars" , {
77
+
78
+ p <- plot_ly(mtcars , x = ~ wt , y = ~ cyl , color = ~ cyl , stroke = ~ wt ) %> %
79
+ colorbar(title = " fill color" , len = 0.4 ) %> %
80
+ colorbar(title = " stroke color" , len = 0.6 , y = 0.55 , which = 2 )
81
+
82
+ d <- p $ x $ data
83
+ expect_length(d , 3 )
84
+
85
+ bar_fill <- d [[2 ]]$ marker $ colorbar
86
+ expect_true(bar_fill $ len == 0.4 )
87
+ expect_true(bar_fill $ y == 1 )
88
+ expect_true(bar_fill $ title == " fill color" )
89
+
90
+ bar_stroke <- d [[3 ]]$ marker $ colorbar
91
+ expect_true(bar_stroke $ len == 0.6 )
92
+ expect_true(bar_stroke $ y == 0.55 )
93
+ expect_true(bar_stroke $ title == " stroke color" )
94
+
95
+ })
0 commit comments