Skip to content

Commit 10cb22a

Browse files
committed
🖊️
1 parent 525e029 commit 10cb22a

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,28 @@ def stop_server(self, warn: bool = True):
149149
+ "\t- 'show-dash' method was not called, or \n"
150150
+ "\t- the dash-server wasn't started with 'show_dash'"
151151
)
152+
153+
def register_update_graph_callback(
154+
self, app: dash.Dash, graph_id: str, trace_updater_id: str
155+
):
156+
"""Register the :func:`construct_update_data` method as callback function to
157+
the passed dash-app.
158+
159+
Parameters
160+
----------
161+
app: Union[dash.Dash, JupyterDash]
162+
The app in which the callback will be registered.
163+
graph_id:
164+
The id of the ``dcc.Graph``-component which withholds the to-be resampled
165+
Figure.
166+
trace_updater_id
167+
The id of the ``TraceUpdater`` component. This component is leveraged by
168+
``FigureResampler`` to efficiently POST the to-be-updated data to the
169+
front-end.
170+
171+
"""
172+
app.callback(
173+
dash.dependencies.Output(trace_updater_id, "updateData"),
174+
dash.dependencies.Input(graph_id, "relayoutData"),
175+
prevent_initial_call=True,
176+
)(self.construct_update_data)

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -913,31 +913,6 @@ def construct_update_data(self, relayout_data: dict) -> List[dict]:
913913
layout_traces_list.append(trace_reduced)
914914
return layout_traces_list
915915

916-
def register_update_graph_callback(
917-
self, app: dash.Dash, graph_id: str, trace_updater_id: str
918-
):
919-
"""Register the :func:`construct_update_data` method as callback function to
920-
the passed dash-app.
921-
922-
Parameters
923-
----------
924-
app: Union[dash.Dash, JupyterDash]
925-
The app in which the callback will be registered.
926-
graph_id:
927-
The id of the ``dcc.Graph``-component which withholds the to-be resampled
928-
Figure.
929-
trace_updater_id
930-
The id of the ``TraceUpdater`` component. This component is leveraged by
931-
``FigureResampler`` to efficiently POST the to-be-updated data to the
932-
front-end.
933-
934-
"""
935-
app.callback(
936-
dash.dependencies.Output(trace_updater_id, "updateData"),
937-
dash.dependencies.Input(graph_id, "relayoutData"),
938-
prevent_initial_call=True,
939-
)(self.construct_update_data)
940-
941916
@staticmethod
942917
def _re_matches(regex: re.Pattern, strings: Iterable[str]) -> List[str]:
943918
"""Returns all the items in ``strings`` which regex.match(es) ``regex``."""

plotly_resampler/figure_resampler/figurewidget_resampler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
self._xaxis_list = self._re_matches(re.compile("xaxis\d*"), self._layout.keys())
7474
# edge case: an empty `go.Figure()` does not yet contain xaxis keys
7575
if not len(self._xaxis_list):
76-
self._xaxis_list = ['xaxis']
76+
self._xaxis_list = ["xaxis"]
7777

7878
# Assign the the update-methods to the corresponding classes
7979
showspike_keys = [f"{xaxis}.showspikes" for xaxis in self._xaxis_list]
@@ -118,7 +118,7 @@ def _update_x_ranges(self, layout, *x_ranges):
118118

119119
# An update will take place for that trace
120120
# -> save current xaxis range to _prev_layout
121-
self._prev_layout[xaxis_str]['range'] = x_range
121+
self._prev_layout[xaxis_str]["range"] = x_range
122122

123123
if len(relayout_dict):
124124
# Construct the update data
@@ -135,7 +135,7 @@ def _update_x_ranges(self, layout, *x_ranges):
135135
self.layout.update(update_data[0])
136136

137137
for xaxis_str in self._xaxis_list:
138-
if 'showspikes' in layout[xaxis_str]:
138+
if "showspikes" in layout[xaxis_str]:
139139
self.layout[xaxis_str].pop("showspikes")
140140

141141
# Then update the data
@@ -177,8 +177,8 @@ def _update_spike_ranges(self, layout, *showspikes):
177177
relayout_dict[f"{xaxis_str}.autorange"] = True
178178
relayout_dict[f"{xaxis_str}.showspikes"] = showspike
179179
# autorange -> we pop the xaxis range
180-
if 'range' in layout[xaxis_str]:
181-
del layout[xaxis_str]['range']
180+
if "range" in layout[xaxis_str]:
181+
del layout[xaxis_str]["range"]
182182

183183
if len(relayout_dict):
184184
# An update will take place, save current layout to _prev_layout
@@ -209,6 +209,3 @@ def _update_spike_ranges(self, layout, *showspikes):
209209
elif self._print_verbose:
210210
self._relayout_hist.append(["showspikes", "initial call or showspikes"])
211211
self._relayout_hist.append("-" * 40)
212-
213-
# def show(self, *args, **kwargs):
214-
# super(go.FigureWidget, self).show(*args, **kwargs)

tests/test_figure_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_add_trace_not_resampling(float_series):
9090

9191

9292
def test_add_scatter_trace_no_data():
93-
fig = FigureResampler(go.Figure(), default_n_shown_samples=1000)
93+
fig = FigureResampler(default_n_shown_samples=1000)
9494

9595
# no x and y data
9696
fig.add_trace(go.Scatter())

tests/test_figurewidget_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_add_trace_not_resampling(float_series):
9090

9191

9292
def test_add_scatter_trace_no_data():
93-
fig = FigureWidgetResampler(go.Figure(), default_n_shown_samples=1000)
93+
fig = FigureWidgetResampler(default_n_shown_samples=1000)
9494

9595
# no x and y data
9696
fig.add_trace(go.Scatter())

0 commit comments

Comments
 (0)