-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PRF: only check some artists on mousemove #4878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0def4c5
1133214
01c4b90
090b6d6
ded655a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ def __init__(self): | |
self._contains = None | ||
self._rasterized = None | ||
self._agg_filter = None | ||
|
||
self._mouseover = False | ||
self.eventson = False # fire events only if eventson | ||
self._oid = 0 # an observer id | ||
self._propobservers = {} # a dict from oids to funcs | ||
|
@@ -147,6 +147,23 @@ def remove(self): | |
# callback has one parameter, which is the child to be removed. | ||
if self._remove_method is not None: | ||
self._remove_method(self) | ||
# clear stale callback | ||
self.stale_callback = None | ||
_ax_flag = False | ||
if hasattr(self, 'axes') and self.axes: | ||
# remove from the mouse hit list | ||
self.axes.mouseover_set.discard(self) | ||
# mark the axes as stale | ||
self.axes.stale = True | ||
# decouple the artist from the axes | ||
self.axes = None | ||
_ax_flag = True | ||
|
||
if self.figure: | ||
self.figure = None | ||
if not _ax_flag: | ||
self.figure = True | ||
|
||
else: | ||
raise NotImplementedError('cannot remove artist') | ||
# TODO: the fix for the collections relim problem is to move the | ||
|
@@ -214,7 +231,9 @@ def axes(self): | |
|
||
@axes.setter | ||
def axes(self, new_axes): | ||
if self._axes is not None and new_axes != self._axes: | ||
|
||
if (new_axes is not None and | ||
(self._axes is not None and new_axes != self._axes)): | ||
raise ValueError("Can not reset the axes. You are " | ||
"probably trying to re-use an artist " | ||
"in more than one Axes which is not " | ||
|
@@ -961,6 +980,21 @@ def format_cursor_data(self, data): | |
data = [data] | ||
return ', '.join('{:0.3g}'.format(item) for item in data) | ||
|
||
@property | ||
def mouseover(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, have you ever measured the performance of descriptor access vs attribute lookup. You might be quite shocked 😱 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not, but I made this a property for the setter functionality. |
||
return self._mouseover | ||
|
||
@mouseover.setter | ||
def mouseover(self, val): | ||
val = bool(val) | ||
self._mouseover = val | ||
ax = self.axes | ||
if ax: | ||
if val: | ||
ax.mouseover_set.add(self) | ||
else: | ||
ax.mouseover_set.discard(self) | ||
|
||
|
||
class ArtistInspector(object): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,6 +786,8 @@ def _set_artist_props(self, a): | |
a.set_transform(self.transData) | ||
|
||
a.axes = self | ||
if a.mouseover: | ||
self.mouseover_set.add(a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alarm bells... 🔔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The remove method takes care of this. |
||
|
||
def _gen_axes_patch(self): | ||
""" | ||
|
@@ -916,6 +918,7 @@ def cla(self): | |
self.tables = [] | ||
self.artists = [] | ||
self.images = [] | ||
self.mouseover_set = set() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a huge fan of the name. Is this really "artists who have mouseover enabled"? Can we come up with a better name? |
||
self._current_image = None # strictly for pyplot via _sci, _gci | ||
self.legend_ = None | ||
self.collections = [] # collection.Collection instances | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely the logic for removing from the axes should live in the remove method itself. Is there a reason we can't do that?