Skip to content

Commit 8987372

Browse files
committed
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
1 parent 22d715d commit 8987372

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

R/helpers.R

+13
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,24 @@ hide_legend <- function(p) {
162162
toWebGL <- function(p) {
163163
if (ggplot2::is.ggplot(p)) {
164164
p <- plotly_build(p)
165+
p <- remove_hoveron_from_gl_traces(p)
165166
}
166167
p$x$.plotlyWebGl <- TRUE
167168
p
168169
}
169170

171+
# ggplotly automatically assigns hoveron mappings that are incompatible with
172+
# webGL based traces, we remove those mappings during toWebGL() conversion
173+
# (See #1582)
174+
remove_hoveron_from_gl_traces <- function(p) {
175+
traces_without_hoveron <- glTypes()
176+
trace_idx <- vapply(
177+
p$x$data,
178+
function(trace) trace$type %in% traces_without_hoveron,
179+
logical(1)
180+
)
181+
p <- style(p, hoveron = NULL, traces = which(trace_idx))
182+
}
170183

171184
#' Create a complete empty plotly graph.
172185
#'

0 commit comments

Comments
 (0)