Skip to content

Commit 949b445

Browse files
committed
🖊️ review code
1 parent 7878da0 commit 949b445

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def show_dash(
388388
if x_range: # when not None
389389
relayout_dict[f"{xaxis_str}.range[0]"] = x_range[0]
390390
relayout_dict[f"{xaxis_str}.range[1]"] = x_range[1]
391-
if relayout_dict:
391+
if relayout_dict: # when not empty
392392
update_data = self.construct_update_data(relayout_dict)
393393

394394
if not self._is_no_update(update_data): # when there is an update

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ def construct_update_data(
12601260
# 1. Base case - there is an x-range specified in the front-end
12611261
start_matches = self._re_matches(re.compile(r"xaxis\d*.range\[0]"), cl_k)
12621262
stop_matches = self._re_matches(re.compile(r"xaxis\d*.range\[1]"), cl_k)
1263-
if start_matches and stop_matches:
1263+
if start_matches and stop_matches: # when both are not empty
12641264
for t_start_key, t_stop_key in zip(start_matches, stop_matches):
12651265
# Check if the xaxis<NUMB> part of xaxis<NUMB>.[0-1] matches
12661266
xaxis = t_start_key.split(".")[0]
@@ -1280,7 +1280,7 @@ def construct_update_data(
12801280
)
12811281
spike_matches = self._re_matches(re.compile(r"xaxis\d*.showspikes"), cl_k)
12821282
# 2.1 Reset-axes -> autorange & reset to the global data view
1283-
if autorange_matches and spike_matches:
1283+
if autorange_matches and spike_matches: # when both are not empty
12841284
for autorange_key in autorange_matches:
12851285
if relayout_data[autorange_key]:
12861286
xaxis = autorange_key.split(".")[0]
@@ -1291,14 +1291,16 @@ def construct_update_data(
12911291
)
12921292
# 2.1. Autorange -> do nothing, the autorange will be applied on the
12931293
# current front-end view
1294-
elif autorange_matches and not spike_matches:
1294+
elif (
1295+
autorange_matches and not spike_matches
1296+
): # when only autorange is not empty
12951297
# PreventUpdate returns a 204 status code response on the
12961298
# relayout post request
12971299
return dash.no_update
12981300

12991301
# If we do not have any traces to be updated, we will return an empty
13001302
# request response
1301-
if not updated_trace_indices:
1303+
if not updated_trace_indices: # when updated_trace_indices is empty
13021304
# PreventUpdate returns a 204 status-code response on the relayout post
13031305
# request
13041306
return dash.no_update
@@ -1336,7 +1338,7 @@ def _parse_dtype_orjson(series: np.ndarray) -> np.ndarray:
13361338
# * float16 and float128 aren't supported with latest orjson versions (3.8.1)
13371339
# * this method assumes that the it will not get a float128 series
13381340
# -> this method can be removed if orjson supports float16
1339-
if series.dtype in (np.float16):
1341+
if series.dtype == np.float16:
13401342
return series.astype(np.float32)
13411343
return series
13421344

plotly_resampler/figure_resampler/figurewidget_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _update_x_ranges(self, layout, *x_ranges, force_update: bool = False):
168168
# -> save current xaxis range to _prev_layout
169169
self._prev_layout[xaxis_str]["range"] = x_range
170170

171-
if relayout_dict:
171+
if relayout_dict: # when not empty
172172
# Construct the update data
173173
update_data = self.construct_update_data(relayout_dict)
174174

plotly_resampler/figure_resampler/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def timedelta_to_str(td: pd.Timedelta) -> str:
128128
if c.days > 0:
129129
out_str += f"{c.days}D"
130130
if c.hours > 0 or c.minutes > 0 or c.seconds > 0 or c.milliseconds > 0:
131-
out_str += "_" if out_str else ""
131+
out_str += "_" if out_str else "" # add seperator if non-empty
132132

133133
if c.hours > 0:
134134
out_str += f"{c.hours}h"

0 commit comments

Comments
 (0)