From ed7a8a954f3e101bf18cf9985d947a462af5bd21 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Fri, 6 Oct 2023 04:13:18 +0200 Subject: [PATCH 1/2] Avoid hoveron warning When converting a ggplot object to webgl, invalid 'hoveron' warnings appear. If the toWebGL() function receives the ggplot object then it is possible for us to remove those warnings. Closes: #2296 Closes: #1582 --- R/helpers.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/helpers.R b/R/helpers.R index 8018ce0db9..05c0c03c1b 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -162,11 +162,24 @@ hide_legend <- function(p) { toWebGL <- function(p) { if (ggplot2::is.ggplot(p)) { p <- plotly_build(p) + p <- remove_hoveron_from_gl_traces(p) } p$x$.plotlyWebGl <- TRUE p } +# ggplotly automatically assigns hoveron mappings that are incompatible with +# webGL based traces, we remove those mappings during toWebGL() conversion +# (See #1582) +remove_hoveron_from_gl_traces <- function(p) { + traces_without_hoveron <- glTypes() + trace_idx <- vapply( + p$x$data, + function(trace) trace$type %in% traces_without_hoveron, + logical(1) + ) + p <- style(p, hoveron = NULL, traces = which(trace_idx)) +} #' Create a complete empty plotly graph. #' From 752aa20019f064fd2a8124f3b8d9bf17498116a6 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Mon, 23 Oct 2023 04:51:30 +0200 Subject: [PATCH 2/2] Add news entry --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 11ef7b536f..740ddedb68 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # plotly (development version) +## Bug fixes + +* Closed #1582, #2296: Avoid `hoveron=` related warnings when converting a ggplot object toWebGL(). + # 4.10.3 ## Improvements