From aed23610badc44695e1171c694648bdb74f3f300 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Fri, 9 Jul 2021 13:48:23 +0800 Subject: [PATCH 01/11] Fix RectangleSelector so that mouse button press and release are reported correctly --- lib/matplotlib/widgets.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index a199e45d4018..bac515f7ed99 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2701,8 +2701,6 @@ def _press(self, event): if self._active_handle is None: x = event.xdata y = event.ydata - self.visible = False - self.extents = x, x, y, y self.visible = True else: self.set_visible(True) @@ -2714,18 +2712,6 @@ def _release(self, event): if not self._interactive: self._to_draw.set_visible(False) - # update the eventpress and eventrelease with the resulting extents - x0, x1, y0, y1 = self.extents - self._eventpress.xdata = x0 - self._eventpress.ydata = y0 - xy0 = self.ax.transData.transform([x0, y0]) - self._eventpress.x, self._eventpress.y = xy0 - - self._eventrelease.xdata = x1 - self._eventrelease.ydata = y1 - 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) From eba1886a89b024c49d19a18699903255ba267252 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Fri, 9 Jul 2021 14:03:22 +0800 Subject: [PATCH 02/11] removed redundant variables --- lib/matplotlib/widgets.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index bac515f7ed99..ba088d2849af 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2698,12 +2698,7 @@ def _press(self, event): # Clear previous rectangle before drawing new rectangle. self.update() - if self._active_handle is None: - x = event.xdata - y = event.ydata - self.visible = True - else: - self.set_visible(True) + self.set_visible(True) return False From f85c07644a3c2f13905e042a692160094c4c23b1 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Fri, 9 Jul 2021 17:20:38 +0800 Subject: [PATCH 03/11] Revert "removed redundant variables" This reverts commit eba1886a89b024c49d19a18699903255ba267252. --- lib/matplotlib/widgets.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index ba088d2849af..bac515f7ed99 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2698,7 +2698,12 @@ def _press(self, event): # Clear previous rectangle before drawing new rectangle. self.update() - self.set_visible(True) + if self._active_handle is None: + x = event.xdata + y = event.ydata + self.visible = True + else: + self.set_visible(True) return False From 94d7bfcc3de1dd461ef8fe77c0e8dd9c7f7caba0 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Fri, 9 Jul 2021 17:22:33 +0800 Subject: [PATCH 04/11] removed redundant variables --- lib/matplotlib/widgets.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index bac515f7ed99..eb70e53f358d 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2699,8 +2699,6 @@ def _press(self, event): self.update() if self._active_handle is None: - x = event.xdata - y = event.ydata self.visible = True else: self.set_visible(True) From e1d1193ac5c34b10c7448d5fd05367b520fc4027 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Fri, 9 Jul 2021 22:24:16 +0800 Subject: [PATCH 05/11] Correct the test assertions to reflect actual mouse release events Mouse release is now taken as the coordinates of the actual mouse button release. Previously, the onmove set the extent of rectangle, and the extent was used as the mouse press and release coordinates. Now they are decoupled, and the test must be updated. --- lib/matplotlib/tests/test_widgets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index 71ebd176f0b9..473fece3a796 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -17,8 +17,8 @@ def onselect(epress, erelease): ax._got_onselect = True assert epress.xdata == 100 assert epress.ydata == 100 - assert erelease.xdata == 199 - assert erelease.ydata == 199 + assert erelease.xdata == 200 + assert erelease.ydata == 200 tool = widgets.RectangleSelector(ax, onselect, **kwargs) do_event(tool, 'press', xdata=100, ydata=100, button=1) From 3acd7298fca8408b879edb62f8b03d868e4815f7 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Sat, 10 Jul 2021 10:34:03 +0800 Subject: [PATCH 06/11] fix RectangleSelector onselect output --- doc/api/next_api_changes/behavior/20611-MRR.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/api/next_api_changes/behavior/20611-MRR.rst diff --git a/doc/api/next_api_changes/behavior/20611-MRR.rst b/doc/api/next_api_changes/behavior/20611-MRR.rst new file mode 100644 index 000000000000..982880babf7b --- /dev/null +++ b/doc/api/next_api_changes/behavior/20611-MRR.rst @@ -0,0 +1,6 @@ +``RectangleSelector`` ``onselect`` now reports actual mouse press and release coordinates +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The current docstrings in ``RectangleSelector`` explain ``onselect`` as a function with the +the signature ``def onselect(eclick: MouseEvent, erelease: MouseEvent)``. The old +behaviour is to actually report the ``extent`` of the rectangle, not the mouse event +coordinates. The new behaviour reports the actual mouse event coordinates. From f9cb27981825be4b04d35b8477f6cf83dcf8d5a8 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Sat, 10 Jul 2021 16:37:20 +0800 Subject: [PATCH 07/11] Update doc/api/next_api_changes/behavior/20611-MRR.rst Co-authored-by: Elliott Sales de Andrade --- doc/api/next_api_changes/behavior/20611-MRR.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/next_api_changes/behavior/20611-MRR.rst b/doc/api/next_api_changes/behavior/20611-MRR.rst index 982880babf7b..9ed4ede480e6 100644 --- a/doc/api/next_api_changes/behavior/20611-MRR.rst +++ b/doc/api/next_api_changes/behavior/20611-MRR.rst @@ -1,6 +1,6 @@ ``RectangleSelector`` ``onselect`` now reports actual mouse press and release coordinates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The current docstrings in ``RectangleSelector`` explain ``onselect`` as a function with the +The current docstrings in `.RectangleSelector` describe ``onselect`` as a function with the the signature ``def onselect(eclick: MouseEvent, erelease: MouseEvent)``. The old behaviour is to actually report the ``extent`` of the rectangle, not the mouse event coordinates. The new behaviour reports the actual mouse event coordinates. From 18874074177b8c21e76ae36a932dce513b7a0891 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Sat, 10 Jul 2021 16:37:34 +0800 Subject: [PATCH 08/11] Update doc/api/next_api_changes/behavior/20611-MRR.rst Co-authored-by: Elliott Sales de Andrade --- doc/api/next_api_changes/behavior/20611-MRR.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/next_api_changes/behavior/20611-MRR.rst b/doc/api/next_api_changes/behavior/20611-MRR.rst index 9ed4ede480e6..62288874dc6b 100644 --- a/doc/api/next_api_changes/behavior/20611-MRR.rst +++ b/doc/api/next_api_changes/behavior/20611-MRR.rst @@ -1,6 +1,6 @@ ``RectangleSelector`` ``onselect`` now reports actual mouse press and release coordinates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The current docstrings in `.RectangleSelector` describe ``onselect`` as a function with the -the signature ``def onselect(eclick: MouseEvent, erelease: MouseEvent)``. The old -behaviour is to actually report the ``extent`` of the rectangle, not the mouse event +the signature ``def onselect(eclick: MouseEvent, erelease: MouseEvent)``. The +previous behaviour reported the ``extent`` of the rectangle, not the mouse event coordinates. The new behaviour reports the actual mouse event coordinates. From 4e159913dca9515eda13d7c6e8c7e855176784c0 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Sat, 10 Jul 2021 21:23:00 +0800 Subject: [PATCH 09/11] restore initialisation of extents on button press --- lib/matplotlib/widgets.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index eb70e53f358d..03ae2eb11a60 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2699,6 +2699,9 @@ def _press(self, event): self.update() if self._active_handle is None: + x = self._eventpress.xdata + y = self._eventpress.ydata + self.extents = x,x,y,y self.visible = True else: self.set_visible(True) From 72c1452974e6e5ad8212aab3bd87149a23fb6c99 Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Sun, 11 Jul 2021 14:35:54 +0800 Subject: [PATCH 10/11] update RectagleSelector for lint compliance --- lib/matplotlib/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 03ae2eb11a60..abcb975794da 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2701,7 +2701,7 @@ def _press(self, event): if self._active_handle is None: x = self._eventpress.xdata y = self._eventpress.ydata - self.extents = x,x,y,y + self.extents = x, x, y, y self.visible = True else: self.set_visible(True) From 4601451bad8905a2a5fe9235d42fe5dcc55e056b Mon Sep 17 00:00:00 2001 From: rowlesmr Date: Tue, 20 Jul 2021 17:49:04 +0800 Subject: [PATCH 11/11] update references to _eventpress and _eventrelease event == self._eventpress in _press and event == self._eventrelease in _release, so this makes sure the _release and _press functions refer to the event that is passed to them. --- lib/matplotlib/widgets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index abcb975794da..c7dbc1b80b15 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2699,8 +2699,8 @@ def _press(self, event): self.update() if self._active_handle is None: - x = self._eventpress.xdata - y = self._eventpress.ydata + x = event.xdata + y = event.ydata self.extents = x, x, y, y self.visible = True else: @@ -2715,11 +2715,11 @@ def _release(self, event): # 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) + spanx = abs(self._eventpress.xdata - event.xdata) + spany = abs(self._eventpress.ydata - event.ydata) elif self.spancoords == 'pixels': - spanx = abs(self._eventpress.x - self._eventrelease.x) - spany = abs(self._eventpress.y - self._eventrelease.y) + spanx = abs(self._eventpress.x - event.x) + spany = abs(self._eventpress.y - event.y) else: _api.check_in_list(['data', 'pixels'], spancoords=self.spancoords) @@ -2734,7 +2734,7 @@ def _release(self, event): return # call desired function - self.onselect(self._eventpress, self._eventrelease) + self.onselect(self._eventpress, event) self.update() return False