Skip to content

Commit 4e7c043

Browse files
committed
Add 'plotly_selecting' to acceptable 'on' events
1 parent 4642714 commit 4e7c043

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

Diff for: R/highlight.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ highlight <- function(p, on = "plotly_click", off,
130130
if (missing(off)) {
131131
off_default <- switch(
132132
on %||% "",
133+
plotly_selecting = ,
133134
plotly_selected = "plotly_deselect",
134135
plotly_click = "plotly_doubleclick",
135136
plotly_hover = "plotly_doubleclick"
@@ -148,7 +149,7 @@ highlight <- function(p, on = "plotly_click", off,
148149
# main (non-plotly.js) spec passed along to HTMLwidgets.renderValue()
149150
p$x$highlight <- list(
150151
# NULL may be used to disable on/off events
151-
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected"))),
152+
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected", "selecting"))),
152153
off = if (is.default(off)) off else if (!is.null(off)) match.arg(off, off_options),
153154
persistent = persistent,
154155
dynamic = dynamic,

Diff for: R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ supply_highlight_attrs <- function(p) {
401401
# add HTML dependencies, set a sensible dragmode default, & throw messages
402402
if (hasKeys) {
403403
p$x$layout$dragmode <- p$x$layout$dragmode %|D|%
404-
default(switch(p$x$highlight$on %||% "", plotly_selected = "select") %||% "zoom")
404+
default(switch(p$x$highlight$on %||% "", plotly_selected = "select", plotly_selecting = "select") %||% "zoom")
405405
if (is.default(p$x$highlight$off)) {
406406
message(
407407
sprintf(

Diff for: demo/crosstalk-highlight-intro.R

+1-13
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,12 @@ p <- plot_ly(hd, x = ~visit, y = ~perc, color = I("black"),
1818
group_by(patient) %>%
1919
add_trace(mode = "markers+lines")
2020

21-
# Since the data provided (hd) has a primary key definition of 'patient',
22-
# **plotly** knows to highlight any lines/markers matching the selected patient(s).
23-
# Go ahead and *click* on any marker and watch the entire 'patient' be highlighted
24-
layout(p, title = "Click on a marker to highlight that patient")
25-
26-
# By default, the "on event" is "plotly_click", but we can change that to
27-
# "plotly_selected", which corresponds to click and drag mouse events.
28-
p %>%
29-
layout(title = "Click and drag to select patient") %>%
30-
highlight("plotly_selected")
31-
32-
3321
# Plotly provides two types of drag modes that will trigger a "plotly_selected"
3422
# event: "lasso" and "select". You can change the dragmode interactively via
3523
# the modebar and/or set the default dragmode via `layout()`.
3624
p %>%
3725
layout(title = "Click and drag to select patient", dragmode = "lasso") %>%
38-
highlight("plotly_selected")
26+
highlight("plotly_selecting")
3927

4028
# The first argument of `highlight()`, `on`, sets the interaction type used
4129
# trigger a "highlight selection". The second argument, `off`, sets the

0 commit comments

Comments
 (0)