Skip to content

Commit 264889a

Browse files
committed
Fix: Add xaxis.range[0]/[1] If Not Exist predict-idlab#335
1 parent bb30c91 commit 264889a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,23 @@ def _construct_update_data(
13361336
# 1. Base case - there is an x-range specified in the front-end
13371337
start_matches = self._re_matches(re.compile(r"xaxis\d*.range\[0]"), cl_k)
13381338
stop_matches = self._re_matches(re.compile(r"xaxis\d*.range\[1]"), cl_k)
1339+
1340+
# When the user sets x range via update_xaxes and the number of points in
1341+
# data exceeds the default_n_shown_samples, then after resetting the axes
1342+
# the relayout may only have "xaxis.range", instead of "xaxis.range[0]" and
1343+
# "xaxis.range[1]". If this happens, we need to manually add "xaxis.range[0]"
1344+
# and "xaxis.range[1]", otherwise resetting axes wouldn't work.
1345+
if not (start_matches and stop_matches):
1346+
range_matches = self._re_matches(re.compile(r"xaxis\d*.range"), cl_k)
1347+
for range_match in range_matches:
1348+
x_range = relayout_data[range_match]
1349+
start, stop = x_range
1350+
start_match = range_match + "[0]"
1351+
stop_match = range_match + "[1]"
1352+
relayout_data[start_match] = start
1353+
relayout_data[stop_match] = stop
1354+
start_matches.append(start_match)
1355+
stop_matches.append(stop_match)
13391356
if start_matches and stop_matches: # when both are not empty
13401357
for t_start_key, t_stop_key in zip(start_matches, stop_matches):
13411358
# Check if the xaxis<NUMB> part of xaxis<NUMB>.[0-1] matches

0 commit comments

Comments
 (0)