Skip to content

Commit 78e4612

Browse files
committed
Merge pull request #519 from ropensci/feature/zoom
Feature/zoom
2 parents 997afea + 2646cf6 commit 78e4612

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
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.js'
3-
Version: 3.4.5
3+
Version: 3.4.6
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "cpsievert1@gmail.com"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
3.4.6 -- 17 Mar 2016
2+
3+
NEW FEATURES:
4+
5+
The 'plotly_relayout' event is now accessible via the event_data() function.
6+
7+
Fixed #514.
8+
19
3.4.5 -- 17 Mar 2016
210

311
BUGFIX:

R/shiny.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
3636
#' This function must be called within a reactive shiny context.
3737
#'
3838
#' @param event The type of plotly event. Currently 'plotly_hover',
39-
#' 'plotly_click', and 'plotly_selected' are supported.
39+
#' 'plotly_click', 'plotly_selected', and 'plotly_relayout' are supported.
4040
#' @param source Which plot should the listener be tied to? This
4141
#' (character string) should match the value of \code{source} in \link{plot_ly}.
4242
#' @export
@@ -45,8 +45,8 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
4545
#' shiny::runApp(system.file("examples", "events", package = "plotly"))
4646
#' }
4747

48-
event_data <- function(event = c("plotly_hover", "plotly_click", "plotly_selected"),
49-
source = "A") {
48+
event_data <- function(event = c("plotly_hover", "plotly_click", "plotly_selected",
49+
"plotly_relayout"), source = "A") {
5050
session <- shiny::getDefaultReactiveDomain()
5151
if (is.null(session)) {
5252
stop("No reactive domain detected. This function can only be called \n",

inst/examples/plotlyEvents/app.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ ui <- fluidPage(
66
plotlyOutput("plot"),
77
verbatimTextOutput("hover"),
88
verbatimTextOutput("click"),
9-
verbatimTextOutput("brush")
9+
verbatimTextOutput("brush"),
10+
verbatimTextOutput("zoom")
1011
)
1112

1213
server <- function(input, output, session) {
@@ -39,6 +40,11 @@ server <- function(input, output, session) {
3940
if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
4041
})
4142

43+
output$zoom <- renderPrint({
44+
d <- event_data("plotly_relayout")
45+
if (is.null(d)) "Relayout (i.e., zoom) events appear here" else d
46+
})
47+
4248
}
4349

4450
shinyApp(ui, server, options = list(display.mode = "showcase"))

inst/htmlwidgets/plotly.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ HTMLWidgets.widget({
7171

7272
// send user input event data to shiny
7373
if (shinyMode) {
74+
// https://plot.ly/javascript/zoom-events/
75+
graphDiv.on('plotly_relayout', function(d) {
76+
Shiny.onInputChange(
77+
".clientValue-" + "plotly_relayout" + "-" + x.source,
78+
JSON.stringify(d)
79+
);
80+
});
7481
graphDiv.on('plotly_hover', sendEventData('plotly_hover'));
7582
graphDiv.on('plotly_click', sendEventData('plotly_click'));
7683
graphDiv.on('plotly_selected', sendEventData('plotly_selected'));

man/event_data.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-ggplot-point.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ test_that("tickvals/ticktext are appropriately boxed", {
4949
d <- data.frame(x = factor(75), y = 10)
5050
p <- qplot(x, y, data = d)
5151
info <- save_outputs(p, "point-box")
52-
expect_true(plotly::to_JSON(info$layout$xaxis$tickvals) == '[1]')
53-
expect_true(plotly::to_JSON(info$layout$xaxis$ticktext) == '["75"]')
52+
expect_true(plotly:::to_JSON(info$layout$xaxis$tickvals) == '[1]')
53+
expect_true(plotly:::to_JSON(info$layout$xaxis$ticktext) == '["75"]')
5454
})

0 commit comments

Comments
 (0)