Skip to content

Commit 679f990

Browse files
committed
set hovermode to closest for non-line scatter traces
1 parent 4aa3ff6 commit 679f990

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

R/plotly.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ plotly_build <- function(l = last_plot()) {
387387
x <- c(x, kwargs)
388388
# traces shouldn't have any names
389389
x$data <- setNames(x$data, NULL)
390+
# if this is a non-line scatter trace and no hovermode exists,
391+
# set hovermode to closest
392+
if (is.null(x$data[[1]]$type) || isTRUE(x$data[[1]]$type == "scatter")) {
393+
if (!grepl("lines", x$data[[1]]$mode %||% "lines"))
394+
x$layout$hovermode <- x$layout$hovermode %||% "closest"
395+
}
390396
# add plotly class mainly for printing method
391397
structure(x, class = unique("plotly", class(x)))
392398
}

0 commit comments

Comments
 (0)