Skip to content

Commit

Permalink
Avoid hoveron warning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zeehio committed Oct 23, 2023
1 parent ee22264 commit ed7a8a9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down

0 comments on commit ed7a8a9

Please sign in to comment.