Skip to content

Commit d6ac0f6

Browse files
committed
Merge branch 'figresampler_display_improvements' into os_matrix
2 parents 6886a61 + c884c48 commit d6ac0f6

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def __init__(
4343
verbose: bool = False,
4444
show_dash_kwargs: dict | None = None,
4545
):
46-
# `pr_props`` is a variable to store properties of a plotly-resampler figure
47-
# This variable will only be set when loading a pickled plotly-resampler figure
48-
pr_props = None
49-
5046
# Parse the figure input before calling `super`
5147
if is_figure(figure) and not is_fr(figure):
5248
# A go.Figure
@@ -78,8 +74,12 @@ def __init__(
7874
f._grid_str = figure.get("_grid_str")
7975
f._grid_ref = figure.get("_grid_ref")
8076
f.add_traces(figure.get("data"))
81-
# `pr_props`will be not None when loading a pickled plotly-resampler figure
82-
pr_props = figure.get("pr_props")
77+
# `pr_props` is not None when loading a pickled plotly-resampler figure
78+
f._pr_props = figure.get("pr_props")
79+
# `f._pr_props`` is an attribute to store properties of a
80+
# plotly-resampler figure. This attribute is only used to pass
81+
# information to the super() constructor. Once the super constructor is
82+
# called, the attribute is removed.
8383

8484
# f.add_frames(figure.get("frames")) TODO
8585
elif isinstance(figure, (dict, list)):
@@ -97,7 +97,6 @@ def __init__(
9797
show_mean_aggregation_size,
9898
convert_traces_kwargs,
9999
verbose,
100-
pr_props=pr_props,
101100
)
102101

103102
if isinstance(figure, AbstractFigureAggregator):

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ def __init__(
9292
``convert_existing_traces`` is set to True.
9393
verbose: bool, optional
9494
Whether some verbose messages will be printed or not, by default False.
95-
pr_props: dict, optional
96-
A dict of properties that will be overwrite the above arguments.
97-
This is useful when the figure is created from a pickled object, allowing
98-
the PR figure to be created with the same properties as the pickled object.
99-
.. note::
100-
Users should not use this argument, as it is used internally by the
101-
subclasses of this abstract class.
10295
10396
"""
10497
self._hf_data: Dict[str, dict] = {}
@@ -111,18 +104,22 @@ def __init__(
111104

112105
self._global_downsampler = default_downsampler
113106

114-
# Overwrite the passed properties with the property dict values
115-
# (this is the case when the PR figure is created from a pickled object)
116-
if pr_props is not None:
117-
for k, v in pr_props.items():
118-
setattr(self, k, v)
119-
120107
# Given figure should always be a BaseFigure that is not wrapped by
121108
# a plotly-resampler class
122109
assert isinstance(figure, BaseFigure)
123110
assert not issubclass(type(figure), AbstractFigureAggregator)
124111
self._figure_class = figure.__class__
125112

113+
# Overwrite the passed arguments with the property dict values
114+
# (this is the case when the PR figure is created from a pickled object)
115+
if hasattr(figure, "_pr_props"):
116+
pr_props = figure._pr_props # a dict of PR properties
117+
if pr_props is not None:
118+
# Overwrite the default arguments with the serialized properties
119+
for k, v in pr_props.items():
120+
setattr(self, k, v)
121+
delattr(figure, "_pr_props") # should not be stored anymore
122+
126123
if convert_existing_traces:
127124
# call __init__ with the correct layout and set the `_grid_ref` of the
128125
# to-be-converted figure

plotly_resampler/figure_resampler/figurewidget_resampler.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ def __init__(
5656
f = self._get_figure_class(go.FigureWidget)()
5757
f._data_validator.set_uid = False
5858

59-
# `pr_props`` is a variable to store properties of a plotly-resampler figure
60-
# This variable will only be set when loading a pickled plotly-resampler figure
61-
pr_props = None
62-
6359
if isinstance(figure, BaseFigure):
6460
# A base figure object, can be;
6561
# - a base plotly figure: go.Figure or go.FigureWidget
@@ -79,8 +75,12 @@ def __init__(
7975
f._grid_str = figure.get("_grid_str")
8076
f._grid_ref = figure.get("_grid_ref")
8177
f.add_traces(figure.get("data"))
82-
# `pr_props`will be not None when loading a pickled plotly-resampler figure
83-
pr_props = figure.get("pr_props")
78+
# `pr_props` is not None when loading a pickled plotly-resampler figure
79+
f._pr_props = figure.get("pr_props")
80+
# `f._pr_props`` is an attribute to store properties of a plotly-resampler
81+
# figure. This attribute is only used to pass information to the super()
82+
# constructor. Once the super constructor is called, the attribute is
83+
# removed.
8484

8585
# f.add_frames(figure.get("frames")) TODO
8686
elif isinstance(figure, (dict, list)):
@@ -96,7 +96,6 @@ def __init__(
9696
show_mean_aggregation_size,
9797
convert_traces_kwargs,
9898
verbose,
99-
pr_props=pr_props,
10099
)
101100

102101
if isinstance(figure, AbstractFigureAggregator):

0 commit comments

Comments
 (0)