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

fix: check if update_data contains update before batch_update #316

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
31 changes: 16 additions & 15 deletions plotly_resampler/figure_resampler/figurewidget_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,23 @@ def _update_spike_ranges(self, layout, *showspikes, force_update=False):
self._relayout_hist.append(["showspikes-update", len(update_data) - 1])
self._relayout_hist.append("-" * 30)

with self.batch_update():
# First update the layout (first item of update_data)
if not force_update:
self.layout.update(self._parse_relayout(update_data[0]))

# Also: Remove the showspikes from the layout, otherwise the autorange
# will not work as intended (it will not be triggered again)
# Note: this removal causes a second trigger of this method
# which will go in the "else" part below.
for xaxis_str in self._xaxis_list:
self.layout[xaxis_str].pop("showspikes")
if not self._is_no_update(update_data):
with self.batch_update():
# First update the layout (first item of update_data)
if not force_update:
self.layout.update(self._parse_relayout(update_data[0]))

# Also: Remove the showspikes from the layout, otherwise the autorange
# will not work as intended (it will not be triggered again)
# Note: this removal causes a second trigger of this method
# which will go in the "else" part below.
for xaxis_str in self._xaxis_list:
self.layout[xaxis_str].pop("showspikes")
Comment on lines +270 to +275
Copy link
Member Author

Choose a reason for hiding this comment

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

Not 100% sure whether this is necessary when update_data is NoUpdate
(In the previous logic, this would be executed)

Copy link
Member Author

Choose a reason for hiding this comment

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

Quite sure it is correct to only execute this code if update_data is a proper update.


# Then, update the data
for updated_trace in update_data[1:]:
trace_idx = updated_trace.pop("index")
self.data[trace_idx].update(updated_trace)
# Then, update the data
for updated_trace in update_data[1:]:
trace_idx = updated_trace.pop("index")
self.data[trace_idx].update(updated_trace)
elif self._print_verbose:
self._relayout_hist.append(["showspikes", "initial call or showspikes"])
self._relayout_hist.append("-" * 40)
Expand Down
Loading