✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Unselect points when click empty area

If I’m using the selection tool for my scatterplot and I click a selection then the selected points stay current opacity. Then if I click outside of that selection say at an empty area, I want the selection box to disappear and all the points to go back to having the opacity they had before being selected.

Currently, if I double click, it will do what I want it to do.

// this is written in Coffeescript

plotlyDiv.on('plotly_selected', (data) ->
    if data == null
       //  make points go back to normal opacity and remove selection box

Based on this case
How can I remove plotly select box after the selection is done

I came up with a solution:

The solutions above don’t work for me. Here is my solution:


The trick is setting the traces selectedpoints attribute to null:

Plotly.restyle(graphDiv, {selectedpoints: [null]});