From ed7a8a954f3e101bf18cf9985d947a462af5bd21 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Fri, 6 Oct 2023 04:13:18 +0200 Subject: [PATCH] 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. #'