Skip to content

Different results with plotly_click vs plotly_selected #1471

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
destradafilm opened this issue Mar 13, 2017 · 1 comment
Closed

Different results with plotly_click vs plotly_selected #1471

destradafilm opened this issue Mar 13, 2017 · 1 comment

Comments

@destradafilm
Copy link

destradafilm commented Mar 13, 2017

I'm working on a SCATTERPLOT and adding some user interactions.

'plotly_click' is only called when a user clicks a point

'plotly_selected' is also called when a user clicks either a blank area of the plot OR when a user clicks a point (but returns an empty data obj)

I feel like it makes more sense to call 'plotly_click' no matter where you click on the chart, return data if a point is clicked, but return empty data if no points are clicked.

I'm asking for this feature for some interactions on my scatterplot.

For example:
If a user clicks a point, color the point 'red'

  • easy, since I can use the data.points[0] to find which marker to color

If a user clicks an empty part of the chart, reset the 'selected' points and color it back to original color.

  • I can use 'if data == undefined' then color all points back to original color', but problem is data == undefined if I click a point, or click an empty place in chart...'plotly_click' is never called here
@etpinard
Copy link
Contributor

@destradafilm thanks for sharing your thoughts with us.

There's definitively room for improvement in our event namespace. That said, we're currently freezing the event behavior as is in v1 so I pasted your comment in the v2 event issue #145 (comment).

To workaround this problem in the meantime, I'd recommend adding a (plain) click handler to the graph div:

var gd = document.getElementById('graph')

Plotly.plot(gd, /* */)

// plotly.click stuff triggered within hover distance of pts
gd.on('plotly_click', () => {}) 

// plain click triggered on any click on graph div
gd.addEventListeners('click', () => {})

I'd also recommend digging up old posts on https://community.plot.ly/ for more examples.

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