Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38e8cbb

Browse files
committed
Class definition, method implementations, and API doc changes
1 parent 3ebfc4e commit 38e8cbb

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

doc/api/next_api_changes/development/00001-ABC.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- The signature and implementation of the `set_hover()` and `get_hover()` methods of the `Artist` class, as well as the `HoverEvent(Event)` Class, have been added:
2+
3+
.. versionchanged:: 3.7.2
4+
The `set_hover()` method takes two arguments, `self` and `hover`. `hover` is the hover status that the object is then set to.
5+
The `get_hover()` methods take a single argument `self` and returns the hover status of the object.
6+
The `HoverEvent(Event)` Class takes a single argument `Event` and fires when the mouse hovers over a canvas.

lib/matplotlib/artist.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def __init__(self):
193193
self._clipon = True
194194
self._label = ''
195195
self._picker = None
196+
self._hover = None
196197
self._rasterized = False
197198
self._agg_filter = None
198199
# Normally, artist classes need to be queried for mouseover info if and
@@ -594,6 +595,49 @@ def get_picker(self):
594595
set_picker, pickable, pick
595596
"""
596597
return self._picker
598+
599+
def set_hover(self, hover):
600+
"""
601+
Define the hover status of the artist.
602+
603+
Parameters
604+
----------
605+
hover : None or bool or float or callable
606+
This can be one of the following:
607+
608+
- *None*: Hover is disabled for this artist (default).
609+
610+
- A boolean: If *True* then hover will be enabled and the
611+
artist will fire a hover event if the mouse event is hovering over
612+
the artist.
613+
614+
- A float: If hover is a number it is interpreted as an
615+
epsilon tolerance in points and the artist will fire
616+
off an event if its data is within epsilon of the mouse
617+
event. For some artists like lines and patch collections,
618+
the artist may provide additional data to the hover event
619+
that is generated, e.g., the indices of the data within
620+
epsilon of the hover event
621+
622+
- A function: If hover is callable, it is a user supplied
623+
function which determines whether the artist is hit by the
624+
mouse event to determine the hit test. if the mouse event
625+
is over the artist, return *hit=True* and props is a dictionary of
626+
properties you want added to the HoverEvent attributes.
627+
"""
628+
self._hover = hover
629+
630+
def get_hover(self):
631+
"""
632+
Return the hover status of the artist.
633+
634+
The possible values are described in `.set_hover`.
635+
636+
See Also
637+
--------
638+
set_hover
639+
"""
640+
return self._hover
597641

598642
def get_url(self):
599643
"""Return the url."""

lib/matplotlib/backend_bases.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,7 @@ class _Backend:
495495

496496
class ShowBase(_Backend):
497497
def __call__(self, block: bool | None = ...): ...
498+
499+
class HoverEvent:
500+
def __init__(self, canvas, x, y, guiEvent=None):
501+
pass

0 commit comments

Comments
 (0)