Skip to content

Commit

Permalink
Merge pull request #6642 from blink1073/fix-rectangle-selector
Browse files Browse the repository at this point in the history
FIX: rectangle selector release bug

Close #6623.
  • Loading branch information
tacaswell committed Jun 28, 2016
2 parents 989aa06 + 27da912 commit a8ad349
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,18 @@ def _release(self, event):
if not self.interactive:
self.to_draw.set_visible(False)

# update the eventpress and eventrelease with the resulting extents
x1, x2, y1, y2 = self.extents
self.eventpress.xdata = x1
self.eventpress.ydata = y1
xy1 = self.ax.transData.transform_point([x1, y1])
self.eventpress.x, self.eventpress.y = xy1

self.eventrelease.xdata = x2
self.eventrelease.ydata = y2
xy2 = self.ax.transData.transform_point([x2, y2])
self.eventrelease.x, self.eventrelease.y = xy2

if self.spancoords == 'data':
xmin, ymin = self.eventpress.xdata, self.eventpress.ydata
xmax, ymax = self.eventrelease.xdata, self.eventrelease.ydata
Expand All @@ -1854,27 +1866,16 @@ def _release(self, event):
xproblems = self.minspanx is not None and spanx < self.minspanx
yproblems = self.minspany is not None and spany < self.minspany

if (((self.drawtype == 'box') or (self.drawtype == 'line')) and
(xproblems or yproblems)):
# check if drawn distance (if it exists) is not too small in
# neither x nor y-direction
self.extents = [0, 0, 0, 0]
# check if drawn distance (if it exists) is not too small in
# either x or y-direction
if self.drawtype != 'none' and (xproblems or yproblems):
for artist in self.artists:
artist.set_visible(False)
self.update()
return

# update the eventpress and eventrelease with the resulting extents
x1, x2, y1, y2 = self.extents
self.eventpress.xdata = x1
self.eventpress.ydata = y1
xy1 = self.ax.transData.transform_point([x1, y1])
self.eventpress.x, self.eventpress.y = xy1

self.eventrelease.xdata = x2
self.eventrelease.ydata = y2
xy2 = self.ax.transData.transform_point([x2, y2])
self.eventrelease.x, self.eventrelease.y = xy2

# call desired function
self.onselect(self.eventpress, self.eventrelease)
# call desired function
self.update()

return False
Expand Down

0 comments on commit a8ad349

Please sign in to comment.