Skip to content

Commit 6ab5701

Browse files
committed
📝 review
1 parent 22f32ac commit 6ab5701

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

plotly_resampler/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"EfficientLTTB",
1616
"LTTB",
1717
"EveryNthPoint",
18-
"FuncAggregator",
1918
"register_plotly_resampler",
2019
"unregister_plotly_resampler",
2120
]

plotly_resampler/registering.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Register plotly-resampler to (un)wrap plotly-graph-objects."""
2+
13
__author__ = "Jeroen Van Der Donckt, Jonas Van Der Donckt, Emiel Deprost"
24

35
from plotly_resampler import FigureResampler, FigureWidgetResampler
@@ -23,7 +25,21 @@ def _already_wrapped(constr):
2325
return constr.__name__.startswith(WRAPPED_PREFIX)
2426

2527

26-
def get_plotly_constr(constr):
28+
def _get_plotly_constr(constr):
29+
"""Return the constructor of the underlying plotly graph object and thus omit the
30+
possibly wrapped :class:`AbstractFigureAggregator <plotly_resampler.figure_resampler.figure_resampler_interface.AbstractFigureAggregator>`
31+
instance.
32+
33+
Parameters
34+
----------
35+
constr : callable
36+
The constructor of a instantiatedplotly-object.
37+
38+
Returns
39+
-------
40+
callable
41+
The constructor of a ``go.FigureWidget`` or a ``go.Figure``.
42+
"""
2743
if _already_wrapped(constr):
2844
return constr.__wrapped__ # get the original constructor
2945
return constr
@@ -49,7 +65,7 @@ def _register_wrapper(
4965
**aggregator_kwargs,
5066
):
5167
constr = getattr(module, constr_name)
52-
constr = get_plotly_constr(constr) # get the original plotly constructor
68+
constr = _get_plotly_constr(constr) # get the original plotly constructor
5369

5470
# print(f"Wrapping {constr_name} with {pr_class}")
5571

@@ -62,13 +78,19 @@ def wrapped_constr(*args, **kwargs):
6278
setattr(module, constr_name, wrapped_constr)
6379

6480

65-
def register_plotly_resampler(mode="auto", **aggregator_kwargs): # TODO: show kwargs (e.g., port)?
81+
def register_plotly_resampler(mode="auto", **aggregator_kwargs):
6682
"""Register plotly-resampler to plotly.graph_objects.
6783
6884
This function results in the use of plotly-resampler under the hood.
6985
7086
.. Note::
71-
We advise to
87+
We advise to use mode= ``widget`` when working in an IPython based environment
88+
as this will just behave as a ``go.FigureWidget``, but with dynamic aggregation.
89+
When using mode= ``auto`` or ``figure``; most figures will be wrapped as
90+
:class:`FigureResampler <plotly_resampler.figure_resampler.FigureResampler>`,
91+
on which
92+
:func:`show_dash <plotly_resampler.figure_resampler.FigureResampler.show_dash>`
93+
needs to be called.
7294
7395
Parameters
7496
----------
@@ -78,14 +100,14 @@ def register_plotly_resampler(mode="auto", **aggregator_kwargs): # TODO: show k
78100
If 'auto' is used, the mode is determined based on the environment; if it is in
79101
an ipython environment, the mode is 'widget', otherwise it is 'figure'.
80102
If 'figure' is used, all plotly figures are wrapped as FigureResampler objects.
81-
If 'widget' is used, all plotly figure widgets are wrapped as
103+
If 'widget' is used, all plotly figure widgets are wrapped as
82104
FigureWidgetResampler objects (we advise to use this mode in ipython environment
83105
with a kernel).
84106
If None is used, wrapping is done as expected (go.Figure -> FigureResampler,
85107
go.FigureWidget -> FigureWidgetResampler).
86108
aggregator_kwargs : dict, optional
87109
The keyword arguments to pass to the plotly-resampler decorator its constructor.
88-
See more details in :class:`FigureResampler <FigureResampler>` and
110+
See more details in :class:`FigureResampler <FigureResampler>` and
89111
:class:`FigureWidgetResampler <FigureWidgetResampler>`.
90112
91113
"""

tests/test_registering.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from plotly_resampler.registering import (
1010
register_plotly_resampler,
1111
unregister_plotly_resampler,
12-
get_plotly_constr,
12+
_get_plotly_constr,
1313
)
1414

1515
from .conftest import registering_cleanup
@@ -25,24 +25,24 @@ def test_get_plotly_const(registering_cleanup):
2525
assert not (isfunction(go.Figure) or isfunction(go.FigureWidget))
2626
assert not issubclass(go.Figure, AbstractFigureAggregator)
2727
assert not issubclass(go.FigureWidget, AbstractFigureAggregator)
28-
assert not issubclass(get_plotly_constr(go.Figure), AbstractFigureAggregator)
29-
assert not issubclass(get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
28+
assert not issubclass(_get_plotly_constr(go.Figure), AbstractFigureAggregator)
29+
assert not issubclass(_get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
3030

3131
register_plotly_resampler()
3232
assert isfunction(go.Figure) and isfunction(go.FigureWidget)
3333
assert isinstance(go.Figure(), AbstractFigureAggregator)
3434
assert isinstance(go.FigureWidget(), AbstractFigureAggregator)
3535
assert issubclass(FigureResampler, AbstractFigureAggregator)
3636
assert issubclass(FigureWidgetResampler, AbstractFigureAggregator)
37-
assert not issubclass(get_plotly_constr(go.Figure), AbstractFigureAggregator)
38-
assert not issubclass(get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
37+
assert not issubclass(_get_plotly_constr(go.Figure), AbstractFigureAggregator)
38+
assert not issubclass(_get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
3939

4040
unregister_plotly_resampler()
4141
assert not (isfunction(go.Figure) or isfunction(go.FigureWidget))
4242
assert not issubclass(go.Figure, AbstractFigureAggregator)
4343
assert not issubclass(go.FigureWidget, AbstractFigureAggregator)
44-
assert not issubclass(get_plotly_constr(go.Figure), AbstractFigureAggregator)
45-
assert not issubclass(get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
44+
assert not issubclass(_get_plotly_constr(go.Figure), AbstractFigureAggregator)
45+
assert not issubclass(_get_plotly_constr(go.FigureWidget), AbstractFigureAggregator)
4646

4747

4848
def test_register_and_unregister_graph_objects(registering_cleanup):

0 commit comments

Comments
 (0)