From dcd421975372a3cf5ca95ef2f72bdf9c1656d495 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 8 Oct 2019 16:26:12 -0500 Subject: [PATCH 1/2] verify_webgl() shouldn't warn about types that are already gl, closes #1569 --- R/utils.R | 9 +++++---- tests/testthat/test-plotly.R | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/R/utils.R b/R/utils.R index cc3395d4ac..5175bdc941 100644 --- a/R/utils.R +++ b/R/utils.R @@ -823,14 +823,15 @@ verify_webgl <- function(p) { return(p) } types <- sapply(p$x$data, function(x) x[["type"]][1] %||% "scatter") - idx <- paste0(types, "gl") %in% names(Schema$traces) - if (any(!idx)) { + can_gl <- paste0(types, "gl") %in% names(Schema$traces) + already_gl <- grepl("gl$", types) + if (any(!can_gl & !already_gl)) { warning( "The following traces don't have a WebGL equivalent: ", - paste(which(!idx), collapse = ", ") + paste(which(!can_gl & !already_gl), collapse = ", ") ) } - for (i in which(idx)) { + for (i in which(can_gl)) { p$x$data[[i]]$type <- paste0(p$x$data[[i]]$type, "gl") } p diff --git a/tests/testthat/test-plotly.R b/tests/testthat/test-plotly.R index 0e84bd8232..a0d2694e25 100644 --- a/tests/testthat/test-plotly.R +++ b/tests/testthat/test-plotly.R @@ -310,3 +310,10 @@ test_that("Informative deprecation message for titlefont", { p <- layout(plot_ly(), title = "A title", titlefont = list(size = 30)) expect_warning(plotly_build(p), "titlefont") }) + +test_that("toWebGL() shouldn't complain if it's already webgl", { + p <- plot_ly(x = 1, y = 1) %>% + add_markers() %>% + toWebGL() + expect_silent(plotly_build(p)) +}) From 6d9050930d69e2ec290aa61e12aec00c2d076fe2 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 8 Oct 2019 16:52:15 -0500 Subject: [PATCH 2/2] fix test --- tests/testthat/test-plotly.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-plotly.R b/tests/testthat/test-plotly.R index a0d2694e25..8dd43a405a 100644 --- a/tests/testthat/test-plotly.R +++ b/tests/testthat/test-plotly.R @@ -313,7 +313,7 @@ test_that("Informative deprecation message for titlefont", { test_that("toWebGL() shouldn't complain if it's already webgl", { p <- plot_ly(x = 1, y = 1) %>% - add_markers() %>% + add_trace(type = "scattergl", mode = "markers") %>% toWebGL() expect_silent(plotly_build(p)) })