8000 Simplify drag_zoom; clarify draw_rubberband. · matplotlib/matplotlib@b138a67 · GitHub
[go: up one dir, main page]

Skip to content

Commit b138a67

Browse files
committed
Simplify drag_zoom; clarify draw_rubberband.
1 parent 5b1f777 commit b138a67

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,10 @@ def dynamic_update(self):
28202820
pass
28212821

28222822
def draw_rubberband(self, event, x0, y0, x1, y1):
2823-
"""Draw a rectangle rubberband to indicate zoom limits"""
2823+
"""Draw a rectangle rubberband to indicate zoom limits.
2824+
2825+
Note that it is not guaranteed that `x0 <= x1` and `y0 <= y1`.
2826+
"""
28242827
pass
28252828

28262829
def remove_rubberband(self):
@@ -3075,20 +3078,13 @@ def drag_zoom(self, event):
30753078
if self._xypress:
30763079
x, y = event.x, event.y
30773080
lastx, lasty, a, ind, view = self._xypress[0]
3078-
3079-
# adjust x, last, y, last
3080-
x1, y1, x2, y2 = a.bbox.extents
3081-
x, lastx = max(min(x, lastx), x1), min(max(x, lastx), x2)
3082-
y, lasty = max(min(y, lasty), y1), min(max(y, lasty), y2)
3083-
3081+
(x1, y1), (x2, y2) = np.clip(
3082+
[[lastx, lasty], [x, y]], a.bbox.min, a.bbox.max)
30843083
if self._zoom_mode == "x":
3085-
x1, y1, x2, y2 = a.bbox.extents
3086-
y, lasty = y1, y2
3084+
y1, y2 = a.bbox.intervaly
30873085
elif self._zoom_mode == "y":
3088-
x1, y1, x2, y2 = a.bbox.extents
3089-
x, lastx = x1, x2
3090-
3091-
self.draw_rubberband(event, x, y, lastx, lasty)
3086+
x1, x2 = a.bbox.intervalx
3087+
self.draw_rubberband(event, x1, y1, x2, y2)
30923088

30933089
def release_zoom(self, event):
30943090
"""the release mouse button callback in zoom to rect mode"""

lib/matplotlib/backend_tools.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -895,23 +895,15 @@ def _mouse_move(self, event):
895895

896896
if self._xypress:
897897
x, y = event.x, event.y
898-
lastx, lasty, a, _ind, _view = self._xypress[0]
899-
900-
# adjust x, last, y, last
901-
x1, y1, x2, y2 = a.bbox.extents
902-
x, lastx = max(min(x, lastx), x1), min(max(x, lastx), x2)
903-
y, lasty = max(min(y, lasty), y1), min(max(y, lasty), y2)
904-
898+
lastx, lasty, a, ind, view = self._xypress[0]
899+
(x1, y1), (x2, y2) = np.clip(
900+
[[lastx, lasty], [x, y]], a.bbox.min, a.bbox.max)
905901
if self._zoom_mode == "x":
906-
x1, y1, x2, y2 = a.bbox.extents
907-
y, lasty = y1, y2
902+
y1, y2 = a.bbox.intervaly
908903
elif self._zoom_mode == "y":
909-
x1, y1, x2, y2 = a.bbox.extents
910-
x, lastx = x1, x2
911- D49B
912-
self.toolmanager.trigger_tool('rubberband',
913-
self,
914-
data=(x, y, lastx, lasty))
904+
x1, x2 = a.bbox.intervalx
905+
self.toolmanager.trigger_tool(
906+
'rubberband', self, data=(x1, y1, x2, y2))
915907

916908
def _release(self, event):
917909
"""the release mouse button callback in zoom to rect mode"""

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
708708
height = self.canvas.figure.bbox.height
709709
y1 = height - y1
710710
y0 = height - y0
711-
712-
w = abs(x1 - x0)
713-
h = abs(y1 - y0)
714-
715-
rect = [int(val)for val in (min(x0, x1), min(y0, y1), w, h)]
711+
rect = [int(val) for val in (x0, y0, x1 - x0, y1 - y0)]
716712
self.canvas.drawRectangle(rect)
717713

718714
def remove_rubberband(self):

0 commit comments

Comments
 (0)
0