@@ -135,8 +135,44 @@ test_that("positioning with multiple colorbars and legends", {
135135
136136 expect_true(b $ x $ layout $ legend $ y == 0.5 )
137137 expect_true(b $ x $ layout $ legend $ yanchor == " top" )
138+ })
139+
140+
141+ test_that(" Colorbar limits controls marker.color and line.color" , {
138142
143+ # https://github.com/ropensci/plotly/issues/1236
144+ p <- plot_ly(
145+ mtcars , x = ~ hp , y = ~ cyl , z = ~ mpg , color = ~ mpg ,
146+ type = " scatter3d" , mode = " lines+markers"
147+ )
139148
140-
141-
149+ b <- plotly_build(p )
150+ expect_length(b $ x $ data , 2 )
151+ expect_true(all(b $ x $ data [[1 ]]$ marker $ color == mtcars $ mpg ))
152+ expect_true(all(b $ x $ data [[1 ]]$ line $ color == mtcars $ mpg ))
153+ expect_true(b $ x $ data [[1 ]]$ marker $ cmin == min(mtcars $ mpg ))
154+ expect_true(b $ x $ data [[1 ]]$ marker $ cmax == max(mtcars $ mpg ))
155+ expect_true(b $ x $ data [[1 ]]$ line $ cmin == min(mtcars $ mpg ))
156+ expect_true(b $ x $ data [[1 ]]$ line $ cmax == max(mtcars $ mpg ))
157+
158+ p2 <- colorbar(p , limits = c(0 , 100 ))
159+ b2 <- plotly_build(p2 )
160+ expect_length(b2 $ x $ data , 2 )
161+ expect_true(all(b2 $ x $ data [[1 ]]$ marker $ color == mtcars $ mpg ))
162+ expect_true(all(b2 $ x $ data [[1 ]]$ line $ color == mtcars $ mpg ))
163+ expect_true(b2 $ x $ data [[1 ]]$ marker $ cmin == 0 )
164+ expect_true(b2 $ x $ data [[1 ]]$ marker $ cmax == 100 )
165+ expect_true(b2 $ x $ data [[1 ]]$ line $ cmin == 0 )
166+ expect_true(b2 $ x $ data [[1 ]]$ line $ cmax == 100 )
167+
168+ p3 <- colorbar(p , limits = c(20 , 100 ))
169+ b3 <- plotly_build(p3 )
170+ mpg <- mtcars $ mpg
171+ mpg [mpg < 20 ] <- NA
172+ expect_true(Reduce(`&` , Map(identical , b3 $ x $ data [[1 ]]$ marker $ color , mpg )))
173+ expect_true(Reduce(`&` , Map(identical , b3 $ x $ data [[1 ]]$ line $ color , mpg )))
174+ expect_true(b3 $ x $ data [[1 ]]$ marker $ cmin == 20 )
175+ expect_true(b3 $ x $ data [[1 ]]$ marker $ cmax == 100 )
176+ expect_true(b3 $ x $ data [[1 ]]$ line $ cmin == 20 )
177+ expect_true(b3 $ x $ data [[1 ]]$ line $ cmax == 100 )
142178})
0 commit comments