Skip to content

plotly_click not working after version 1.31.2 #2272

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

Closed
step42 opened this issue Jan 19, 2018 · 8 comments
Closed

plotly_click not working after version 1.31.2 #2272

step42 opened this issue Jan 19, 2018 · 8 comments

Comments

@step42
Copy link

step42 commented Jan 19, 2018

Hi,
the code below used to work with version <= 1.31.2. Now with the version 1.32 the plotly_click is no longer called. Any ideas why?

Thanks
Step

plot(props) {
    const plotlyChart = document.getElementById(this.handle)

    // remove all previous listeners from the div plotlyChart element
    if (plotlyChart.removeAllListeners) {
      plotlyChart.removeAllListeners()
    }

    Plotly.purge(plotlyChart)
    Plotly.newPlot(this.handle, data, layout, config)

    // before events it is needed to update the plot
    Plotly.update(this.handle, data, layout)

    plotlyChart
      .on('plotly_click', function (clickEvent) {
        this.props.onDateClick(clickEvent.points[0].x)
      })
....
}
@alexcjohnson
Copy link
Collaborator

@step42 What's on your plot? I'm aware of #2265 if you've got fixed range axes. There's also a new version 1.33 out yesterday, can you check with the latest release?

@step42
Copy link
Author

step42 commented Jan 20, 2018

Yes, this still happens with 1.33.0. The graph is a bar chart.

@alexcjohnson
Copy link
Collaborator

OK, I'm going to need a bit more information than that - generally as far as I can tell bar charts do still support plotly_click. Please see if you can demonstrate the issue in a codepen or some other platform where I can see it in action.

@step42
Copy link
Author

step42 commented Jan 22, 2018

Alex, taking the code out and put it into codepen will require some significant time. It has dependencies to react and specific data and currently it is not so easy to isolate the code (I agree this is not ideal). Is there something quick I can investigate on my end to get to the root cause quicker?

@alexcjohnson
Copy link
Collaborator

If it's purely a plotly.js issue, it should be possible to recreate it from the plot's data, layout, and if necessary config. You can pull these out in the console and insert them in a codepen:

// get the graph DOM element (if you only have one Plotly plot on the page)
var gd = document.querySelector('.js-plotly-plot')

// get the data and layout - this is basically equivalent to:
// JSON.stringify({data: gd.data, layout: gd.layout})
console.log(Plotly.Plots.graphJson(gd))

// if you gave the plot a custom config parameter, we may need that too
console.log(JSON.stringify(gd._context))

// you can copy both of those into a codepen and remake the identical plot
var fig = {"data": [...], "layout": {...}}
var config = {"staticPlot": false, ...}
Plotly.newPlot(gd, fig.data, fig.layout, config)
gd.on('plotly_click', function(e) { console.log('click', e) });

If the problem still shows up, then great! I can take a look at it. If not, this is also useful, it shows that there's something interfering at the application level.

@step42
Copy link
Author

step42 commented Jan 22, 2018

Ok, this codepen shows the issue
https://codepen.io/step42/pen/goEZWo?editors=1111

I don't see the console log when I click a bar.
Btw, how do you select an older version in the codePen?

@alexcjohnson
Copy link
Collaborator

Thanks @step42 - this is indeed #2265 (fixedrange) as I mentioned in my first comment - click is emitted if you remove xaxis.fixedrange (yaxis.fixedrange is set true by default since you have a rangeslider)

You can load old versions from the CDN like:
<script src="https://cdn.plot.ly/plotly-1.31.0.min.js"></script>

@step42
Copy link
Author

step42 commented Jan 22, 2018

Thanks. That fixed it!

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

No branches or pull requests

2 participants