Skip to content

Commit

Permalink
Merge pull request #2516 from platinops/plotly-react
Browse files Browse the repository at this point in the history
Use Plotly.react instead of Plotly.newPlot
  • Loading branch information
falkoschindler authored Feb 5, 2024
2 parents b82aca4 + 85c7f8a commit e4fe519
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions nicegui/elements/plotly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
async mounted() {
await this.$nextTick();
this.update();
this.set_handlers();
},
updated() {
this.update();
Expand All @@ -18,13 +19,9 @@ export default {
if (options.config === undefined) options.config = { responsive: true };
if (options.config.responsive === undefined) options.config.responsive = true;
// re-use plotly instance if config is the same
if (JSON.stringify(options.config) == JSON.stringify(this.last_options.config)) {
Plotly.react(this.$el.id, this.options.data, this.options.layout);
} else {
Plotly.newPlot(this.$el.id, this.options.data, this.options.layout, options.config);
this.set_handlers();
}
// Plotly.react can be used to create a new plot and to update it efficiently
// https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact
Plotly.react(this.$el.id, this.options.data, this.options.layout, options.config);
// store last options
this.last_options = options;
Expand Down

0 comments on commit e4fe519

Please sign in to comment.