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

enable updating the config of a plot without changing other parameters #6394

Open
josephernest opened this issue Dec 13, 2022 · 3 comments · May be fixed by #6395
Open

enable updating the config of a plot without changing other parameters #6394

josephernest opened this issue Dec 13, 2022 · 3 comments · May be fixed by #6395
Assignees
Labels
feature something new P3 backlog

Comments

@josephernest
Copy link

josephernest commented Dec 13, 2022

We can change the layout of an existing plot with Plotly.relayout, change the data with Plotly.react, but how to change the config of a plot without changing the other parameters?

Example:

// happens when clicking on a button
var config = element.config;    // problem: this doesn't exist!   <-- how to get the current config state of the plot?
config["staticPlot"] = true;  // let's add a configuration parameter
Plotly.react(element.id, element.data, element.layout, config)

How to get element.config in the same way element.layout and element.data exist?

@alexcjohnson
Copy link
Collaborator

Haha how timely, @archmoj and I were just discussing this exact question yesterday in the context of #6393

Sometimes it works to change config via Plotly.react, sometimes it doesn't. I think the right thing to do is, if config changes, we should completely empty and recreate the graph. That means using the newPlot pathway instead of the _doPlot pathway it uses today.

How to get element.config in the same way element.layout and element.data exist?

Right, we should save that but currently we do not. At the moment we have only element._context which is the "filled in version" akin to element._fullData rather than element.data.

@josephernest
Copy link
Author

Haha funny timing indeed @alexcjohnson!
Yes what I wanted to achieve is:

Plotly.react(element.id, element.data, element.layout, { ...element.config, staticPlot: true } );   // merge current config with { staticplot: true }

I needed this because

Plotly.react(element.id, element.data, element.layout, { staticPlot: true } );

does not work (it erases the previous config and returns to default modebar buttons...).

What would you use in the meantime ? :)

@alexcjohnson
Copy link
Collaborator

You can try { ...element._context, staticPlot: true } as the new config. But I think you may need to switch to Plotly.newPlot instead of Plotly.react since we're aware of some cases that config changes are not properly adopted by Plotly.react today. Also I'll note if you have the DOM element you can use that instead of its ID as the first arg. So with the caveat that I haven't tried it myself:

Plotly.newPlot(element, element.data, element.layout, { ...element._context, staticPlot: true });

@archmoj archmoj added the bug something broken label Dec 14, 2022
@archmoj archmoj linked a pull request Dec 14, 2022 that will close this issue
@gvwilson gvwilson self-assigned this Jul 4, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson changed the title Update the config of a plot enable updating the config of a plot without changing other parameters Aug 9, 2024
@gvwilson gvwilson added feature something new P3 backlog and removed bug something broken labels Aug 9, 2024
@gvwilson gvwilson self-assigned this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants