Skip to content

crosstalk should only delete traces that it has added itself #1436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2018

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Dec 13, 2018

Description

Crosstalk highlight events work by adding/deleting traces as needed. Currently, the deleting logic removes all traces added after initial render. This change makes it so only the traces added by crosstalk are removed.

Example

In the example below you would expect that a new marker is added to the everytime a point is clicked. Instead, without this change, only a single marker is added (and moves x position after every click)

library(plotly)
library(htmlwidgets)

mtcars %>%
  highlight_key() %>%
  plot_ly(x = ~wt, y = ~mpg) %>%
  add_markers() %>%
  highlight("plotly_click") %>%
  onRender("
    function(el) {
      window.nclicks = 0;
      el.on('plotly_click', function(d) {
        window.nclicks = window.nclicks + 1;
        var trace = {
          x: [window.nclicks],
          y: [10],
          type: 'scatter',
          mode: 'markers'
        }
        Plotly.addTraces(el.id, trace);
      })
    }
  ")

Testing Notes

Install devtools::install_github("ropensci/plotly#1436") then ensure the example above has the correct behavior

@cpsievert cpsievert changed the title TraceManager should only delete traces that it has added itself crosstalk should only delete traces that it has added itself Dec 13, 2018
@cpsievert cpsievert merged commit 4f2ffde into master Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants