8000 Minor RectangleSelector refactors by dstansby · Pull Request #22146 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Minor RectangleSelector refactors #22146

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,19 @@ def _press(self, event):

return False

def _selector_too_small(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a property?

# Return True if selector is smaller than minimum allowed size
if self.spancoords == 'data':
spanx = self._eventpress.xdata - self._eventrelease.xdata
spany = self._eventpress.ydata - self._eventrelease.ydata
elif self.spancoords == 'pixels':
spanx = self._eventpress.x - self._eventrelease.x
spany = self._eventpress.y - self._eventrelease.y
else:
_api.check_in_list(['data', 'pixels'],
spancoords=self.spancoords)
return abs(spanx) <= self.minspanx or abs(spany) <= self.minspany

def _release(self, event):
"""Button release event handler."""
if not self._interactive:
Expand All @@ -3026,26 +3039,11 @@ def _release(self, event):
xy1 = self.ax.transData.transform([x1, y1])
self._eventrelease.x, self._eventrelease.y = xy1

# calculate dimensions of box or line
if self.spancoords == 'data':
spanx = abs(self._eventpress.xdata - self._eventrelease.xdata)
spany = abs(self._eventpress.ydata - self._eventrelease.ydata)
elif self.spancoords == 'pixels':
spanx = abs(self._eventpress.x - self._eventrelease.x)
spany = abs(self._eventpress.y - self._eventrelease.y)
else:
_api.check_in_list(['data', 'pixels'],
spancoords=self.spancoords)
# check if drawn distance (if it exists) is not too small in
# either x or y-direction
minspanxy = (spanx <= self.minspanx or spany <= self.minspany)
if (self._drawtype != 'none' and minspanxy):
< 8000 span class='blob-code-inner blob-code-marker js-skip-tagsearch' data-code-marker="-"> for artist in self.artists:
artist.set_visible(False)
if self._drawtype != 'none' and self._selector_too_small():
if self._selection_completed:
# Call onselect, only when the selection is already existing
self.onselect(self._eventpress, self._eventrelease)
self._selection_completed = False
self.clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intended here? It's not a refactoring but changes code, e.g. clear() calls update() and then we call update again below in 3501.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what is the purpose of the visible attribute but another consequence of using clear is that it changes the value of the visible attribute from True to False and I am not sure if this desirable - this would need to be checked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: it seems that the visibl 58DD e attribute is only used by the selector itself (and should be private) and it is reset in _press, so the point I made here is not an issue!

else:
self.onselect(self._eventpress, self._eventrelease)
self._selection_completed = True
Expand Down
0