Skip to content
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

add Plotly.deleteActiveShape command #6679

Merged
merged 3 commits into from Jul 24, 2023
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jul 21, 2023

Resolves #6678.
@tamidodo Using this dist/plotly.min.js, you could call Plotly.deleteActiveShape(gd) to erase the active shape on the gd.

cc: @plotly/plotly_js

From dash:

clientside_callback(
    """
    function eraseShape(_, graph_id) {
        Plotly.deleteActiveShape(graph_id)
        return dash_clientside.no_update
    }
    """
    Output('my-graph', 'id'),
    Input('erase-button', 'n_clicks'),
    State('my-graph', 'id'),
    prevent_initial_call=True
)

@alexcjohnson
Copy link
Contributor

If we do this we should add lib.getgraphDiv to the function (or make the exported function a wrapper that adds this), so in Dash you'd do something like:

clientside_callback(
    """
    function eraseShape(_, graph_id) {
        Plotly.eraseActiveShape(graph_id)
        return dash_clientside.no_update
    }
    """
    Output('my-graph', 'id'),
    Input('erase-button', 'n_clicks'),
    State('my-graph', 'id'),
    prevent_initial_call=True
)

rather than needing Plotly.eraseActiveShape(document.getElementById(graph_id))
(note this code won't work with pattern-matching IDs but that's a broader issue...)

@archmoj archmoj changed the title add Plotly.eraseActiveShape command add Plotly.deleteActiveShape command Jul 24, 2023
Copy link
Contributor

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 LGTM, @tamidodo does this work for your purposes?

@tamidodo
Copy link

That's great, thank you all so much!

@archmoj archmoj merged commit e0e79b4 into master Jul 24, 2023
1 check passed
@archmoj archmoj deleted the eraseActiveShape-command branch July 24, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to erase the active shape via a dash callback
3 participants