Skip to content

Commit 1b6308a

Browse files
committed
Merge pull request #367 from ropensci/feature/hovermode
set hovermode to closest for non-line scatter traces
2 parents 24d3c5c + 1e0ce5b commit 1b6308a

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
3-
Version: 2.1.3
3+
Version: 2.2.0
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.2.0 -- 13 Jan 2015
2+
3+
The default for layout.hovermode is now 'closest' for non-line scatter traces
4+
15
2.1.3 -- 12 Jan 2015
26

37
Fix size and alpha translation for geom_point. Fixes #386

R/plotly.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ plotly_build <- function(l = last_plot()) {
353353
}
354354
# traces shouldn't have any names
355355
x$data <- setNames(x$data, NULL)
356+
# if this is a non-line scatter trace and no hovermode exists,
357+
# set hovermode to closest
358+
if (is.null(x$data[[1]]$type) || isTRUE(x$data[[1]]$type == "scatter")) {
359+
if (!grepl("lines", x$data[[1]]$mode %||% "lines"))
360+
x$layout$hovermode <- x$layout$hovermode %||% "closest"
361+
}
356362
# add plotly class mainly for printing method
357363
structure(x, class = unique("plotly", class(x)))
358364
}

tests/testthat/test-plotly-subplot.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ test_that("group + [x/y]axis works", {
3434
p <- plot_ly(iris, x = Petal.Length, y = Petal.Width, group = Species,
3535
xaxis = paste0("x", id), mode = "markers")
3636
s <- expect_traces(subplot(p, margin = 0.05), 3, "group")
37-
doms <- lapply(s$layout, "[[", "domain")
37+
ax <- s$layout[grepl("^[x-y]axis", names(s$layout))]
38+
doms <- lapply(ax, "[[", "domain")
3839
# make sure y domain is [0, 1] on every axis
3940
ydom <- doms[grepl("^y", names(doms))]
4041
expect_equal(sort(unique(unlist(ydom))), c(0, 1))

0 commit comments

Comments
 (0)