Skip to content

Commit 0e47d11

Browse files
committed
Add docstring examples of installing hover/unhover/click callbacks
1 parent e9edc39 commit 0e47d11

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

plotly/basedatatypes.py

+49-5
Original file line numberDiff line numberDiff line change
@@ -3647,14 +3647,13 @@ def uid(self, val):
36473647
def on_hover(self,
36483648
callback,
36493649
append=False):
3650-
# typ.Callable[['BaseTraceType', Points, InputDeviceState], None]
36513650
"""
36523651
Register function to be called when the user hovers over one or more
36533652
points in this trace
36543653
36553654
Note: Callbacks will only be triggered when the trace belongs to a
36563655
instance of plotly.graph_objs.FigureWidget and it is displayed in an
3657-
ipywidget context. Callbacks will not be triggered when on figures
3656+
ipywidget context. Callbacks will not be triggered on figures
36583657
that are displayed using plot/iplot.
36593658
36603659
Parameters
@@ -3675,6 +3674,21 @@ def on_hover(self,
36753674
Returns
36763675
-------
36773676
None
3677+
3678+
Examples
3679+
--------
3680+
>>> from plotly.callbacks import Points, InputDeviceState
3681+
>>> points, state = Points(), InputDeviceState()
3682+
3683+
>>> def hover_fn(trace, points, state):
3684+
... inds = points.point_inds
3685+
... # Do something
3686+
3687+
>>> trace.on_hover(hover_fn)
3688+
3689+
Note: The creation of the `points` and `state` objects is optional,
3690+
it's simply a convenience to help the text editor perform completion
3691+
on the arguments inside `hover_fn`
36783692
"""
36793693
if not append:
36803694
del self._hover_callbacks[:]
@@ -3700,7 +3714,7 @@ def on_unhover(self,
37003714
37013715
Note: Callbacks will only be triggered when the trace belongs to a
37023716
instance of plotly.graph_objs.FigureWidget and it is displayed in an
3703-
ipywidget context. Callbacks will not be triggered when on figures
3717+
ipywidget context. Callbacks will not be triggered on figures
37043718
that are displayed using plot/iplot.
37053719
37063720
Parameters
@@ -3721,6 +3735,21 @@ def on_unhover(self,
37213735
Returns
37223736
-------
37233737
None
3738+
3739+
Examples
3740+
--------
3741+
>>> from plotly.callbacks import Points, InputDeviceState
3742+
>>> points, state = Points(), InputDeviceState()
3743+
3744+
>>> def unhover_fn(trace, points, state):
3745+
... inds = points.point_inds
3746+
... # Do something
3747+
3748+
>>> trace.on_unhover(unhover_fn)
3749+
3750+
Note: The creation of the `points` and `state` objects is optional,
3751+
it's simply a convenience to help the text editor perform completion
3752+
on the arguments inside `unhover_fn`
37243753
"""
37253754
if not append:
37263755
del self._unhover_callbacks[:]
@@ -3746,7 +3775,7 @@ def on_click(self,
37463775
37473776
Note: Callbacks will only be triggered when the trace belongs to a
37483777
instance of plotly.graph_objs.FigureWidget and it is displayed in an
3749-
ipywidget context. Callbacks will not be triggered when on figures
3778+
ipywidget context. Callbacks will not be triggered on figures
37503779
that are displayed using plot/iplot.
37513780
37523781
Parameters
@@ -3767,6 +3796,21 @@ def on_click(self,
37673796
Returns
37683797
-------
37693798
None
3799+
3800+
Examples
3801+
--------
3802+
>>> from plotly.callbacks import Points, InputDeviceState
3803+
>>> points, state = Points(), InputDeviceState()
3804+
3805+
>>> def click_fn(trace, points, state):
3806+
... inds = points.point_inds
3807+
... # Do something
3808+
3809+
>>> trace.on_click(click_fn)
3810+
3811+
Note: The creation of the `points` and `state` objects is optional,
3812+
it's simply a convenience to help the text editor perform completion
3813+
on the arguments inside `click_fn`
37703814
"""
37713815
if not append:
37723816
del self._click_callbacks[:]
@@ -3792,7 +3836,7 @@ def on_selection(
37923836
37933837
Note: Callbacks will only be triggered when the trace belongs to a
37943838
instance of plotly.graph_objs.FigureWidget and it is displayed in an
3795-
ipywidget context. Callbacks will not be triggered when on figures
3839+
ipywidget context. Callbacks will not be triggered on figures
37963840
that are displayed using plot/iplot.
37973841
37983842
Parameters

0 commit comments

Comments
 (0)