Skip to content

Commit 2c6deff

Browse files
authored
Merge pull request #316 from predict-idlab/fw_resampler_no_update
fix: check if update_data contains update before batch_update
2 parents 0223450 + ebf6aa6 commit 2c6deff

File tree

6 files changed

+61
-35
lines changed

6 files changed

+61
-35
lines changed

.github/workflows/test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ jobs:
2626
matrix:
2727
os: ['windows-latest', 'macOS-latest', 'ubuntu-latest']
2828
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
29+
exclude: # Python < 3.8 is not supported on Apple Silicon ARM64
30+
- os: macOS-latest
31+
python-version: '3.7'
32+
include: # So run on older version on Intel CPU
33+
- os: macOS-13
34+
python-version: '3.7'
2935
defaults:
3036
run:
3137
shell: bash

plotly_resampler/figure_resampler/figure_resampler_interface.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -980,21 +980,21 @@ def add_trace(
980980
uuid_str = str(uuid4()) if trace.uid is None else trace.uid
981981
trace.uid = uuid_str
982982

983-
# construct the hf_data_container
984-
# TODO in future version -> maybe regex on kwargs which start with `hf_`
985-
dc = self._parse_get_trace_props(
986-
trace,
987-
hf_x,
988-
hf_y,
989-
hf_text,
990-
hf_hovertext,
991-
hf_marker_size,
992-
hf_marker_color,
993-
)
994-
995983
# These traces will determine the autoscale its RANGE!
996984
# -> so also store when `limit_to_view` is set.
997985
if trace["type"].lower() in self._high_frequency_traces:
986+
# construct the hf_data_container
987+
# TODO in future version -> maybe regex on kwargs which start with `hf_`
988+
dc = self._parse_get_trace_props(
989+
trace,
990+
hf_x,
991+
hf_y,
992+
hf_text,
993+
hf_hovertext,
994+
hf_marker_size,
995+
hf_marker_color,
996+
)
997+
998998
n_samples = len(dc.x)
999999
if n_samples > max_out_s or limit_to_view:
10001000
self._print(

plotly_resampler/figure_resampler/figurewidget_resampler.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,30 @@ def _update_spike_ranges(self, layout, *showspikes, force_update=False):
254254

255255
# Construct the update data
256256
update_data = self._construct_update_data(relayout_dict)
257-
if self._print_verbose:
258-
self._relayout_hist.append(layout)
259-
self._relayout_hist.append(["showspikes-update", len(update_data) - 1])
260-
self._relayout_hist.append("-" * 30)
261-
262-
with self.batch_update():
263-
# First update the layout (first item of update_data)
264-
if not force_update:
265-
self.layout.update(self._parse_relayout(update_data[0]))
266-
267-
# Also: Remove the showspikes from the layout, otherwise the autorange
268-
# will not work as intended (it will not be triggered again)
269-
# Note: this removal causes a second trigger of this method
270-
# which will go in the "else" part below.
271-
for xaxis_str in self._xaxis_list:
272-
self.layout[xaxis_str].pop("showspikes")
257+
if not self._is_no_update(update_data):
258+
if self._print_verbose:
259+
self._relayout_hist.append(layout)
260+
self._relayout_hist.append(
261+
["showspikes-update", len(update_data) - 1]
262+
)
263+
self._relayout_hist.append("-" * 30)
264+
265+
with self.batch_update():
266+
# First update the layout (first item of update_data)
267+
if not force_update:
268+
self.layout.update(self._parse_relayout(update_data[0]))
269+
270+
# Also: Remove the showspikes from the layout, otherwise the autorange
271+
# will not work as intended (it will not be triggered again)
272+
# Note: this removal causes a second trigger of this method
273+
# which will go in the "else" part below.
274+
for xaxis_str in self._xaxis_list:
275+
self.layout[xaxis_str].pop("showspikes")
273276

274-
# Then, update the data
275-
for updated_trace in update_data[1:]:
276-
trace_idx = updated_trace.pop("index")
277-
self.data[trace_idx].update(updated_trace)
277+
# Then, update the data
278+
for updated_trace in update_data[1:]:
279+
trace_idx = updated_trace.pop("index")
280+
self.data[trace_idx].update(updated_trace)
278281
elif self._print_verbose:
279282
self._relayout_hist.append(["showspikes", "initial call or showspikes"])
280283
self._relayout_hist.append("-" * 40)

tests/fr_selenium.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def browser_independent_single_callback_request_assert(
136136
# There are 2 requests which are send
137137
# 1. first: changed-layout to server -> new data to back-end request
138138
# 2. the front-end relayout request
139-
assert len(requests) >= 1
139+
assert len(requests) >= 1, f"len(requests) = {len(requests)}"
140140
if len(requests) == 2:
141141
fetch_data_request, relayout_request = requests
142142
# RequestParser.assert_front_end_relayout_request(relayout_request)
@@ -146,7 +146,7 @@ def browser_independent_single_callback_request_assert(
146146
elif "chrome" in browser_name:
147147
# for some, yet unknown reason, chrome does not seem to capture the
148148
# second front-end request.
149-
assert len(requests) == 1
149+
assert len(requests) == 1, f"len(requests) = {len(requests)}"
150150
fetch_data_request = requests[0]
151151
else:
152152
raise ValueError(f"invalid browser name {browser_name}")

tests/test_figure_resampler_selenium.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def test_multi_trace_go_figure(driver, multi_trace_go_figure):
625625
n_updated_traces=30,
626626
)
627627

628-
fr.drag_and_zoom("xy", x0=0.1, x1=0.3, y0=0.6, y1=0.9)
628+
fr.drag_and_zoom("xy", x0=0.1, x1=0.3, y0=0.3, y1=0.5)
629629
fr.clear_requests(sleep_time_s=3)
630630

631631
# First, apply some horizontal based zooms

tests/test_figurewidget_resampler.py

+17
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ def test_add_not_a_hf_trace(float_series):
142142
)
143143

144144

145+
def test_add_not_scatter():
146+
fw_fig = FigureWidgetResampler(
147+
go.Figure(go.Bar(x=[1, 2, 3, 4], y=[1, 2, 3, 4])), verbose=True
148+
)
149+
150+
# we do not want to have an relayout update
151+
assert len(fw_fig._relayout_hist) == 0
152+
153+
# zoom in on both traces
154+
fw_fig.layout.update(
155+
{"xaxis": {"range": [0, 1]}},
156+
overwrite=False,
157+
)
158+
# reset axes
159+
fw_fig.reset_axes()
160+
161+
145162
def test_box_histogram(float_series):
146163
base_fig = make_subplots(
147164
rows=2,

0 commit comments

Comments
 (0)