Skip to content

add Plotly.deleteActiveShape command - #6679

Merged
archmoj merged 3 commits into
masterfrom
eraseActiveShape-command
Jul 24, 2023
Merged

add Plotly.deleteActiveShape command#6679
archmoj merged 3 commits into
masterfrom
eraseActiveShape-command

Conversation

@archmoj

@archmoj archmoj commented Jul 21, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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

@alexcjohnson alexcjohnson left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown

That's great, thank you all so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature something new

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