From d15c344aae80504cbe4d32b9becb4b237160de45 Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Thu, 28 Jun 2018 19:32:53 +0300 Subject: [PATCH 1/7] Ensuring both x and y attrs of LocationEvent are int --- lib/matplotlib/backend_bases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 54728fe05d6b..29bebe7131d9 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1365,8 +1365,8 @@ def __init__(self, name, canvas, x, y, guiEvent=None): *x*, *y* in figure coords, 0,0 = bottom, left """ Event.__init__(self, name, canvas, guiEvent=guiEvent) - self.x = x # x position - pixels from left of canvas - self.y = y # y position - pixels from right of canvas + self.x = int(x) # x position - pixels from left of canvas + self.y = int(y) # y position - pixels from right of canvas self.inaxes = None # the Axes instance if mouse us over axes self.xdata = None # x coord of mouse in data coords self.ydata = None # y coord of mouse in data coords From a20f6e1b51fa781cc3503c83f9692607683f411f Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Fri, 29 Jun 2018 09:48:54 +0300 Subject: [PATCH 2/7] taking into account possible None values of x and y --- lib/matplotlib/backend_bases.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 29bebe7131d9..05b94fe4bb3f 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1342,10 +1342,10 @@ class LocationEvent(Event): Attributes ---------- - x : scalar + x : int x position - pixels from left of canvas - y : scalar + y : int y position - pixels from bottom of canvas inaxes : bool @@ -1365,8 +1365,8 @@ def __init__(self, name, canvas, x, y, guiEvent=None): *x*, *y* in figure coords, 0,0 = bottom, left """ Event.__init__(self, name, canvas, guiEvent=guiEvent) - self.x = int(x) # x position - pixels from left of canvas - self.y = int(y) # y position - pixels from right of canvas + self.x = int(x) if x is not None else 0 # x position - pixels from left of canvas + self.y = int(y) if y is not None else 0 # y position - pixels from right of canvas self.inaxes = None # the Axes instance if mouse us over axes self.xdata = None # x coord of mouse in data coords self.ydata = None # y coord of mouse in data coords From b3be888cc658e69419d92a7312ff9caaf4e08dd5 Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Fri, 29 Jun 2018 10:40:20 +0300 Subject: [PATCH 3/7] E501 check --- lib/matplotlib/backend_bases.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 05b94fe4bb3f..f9094107d347 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1365,8 +1365,10 @@ def __init__(self, name, canvas, x, y, guiEvent=None): *x*, *y* in figure coords, 0,0 = bottom, left """ Event.__init__(self, name, canvas, guiEvent=guiEvent) - self.x = int(x) if x is not None else 0 # x position - pixels from left of canvas - self.y = int(y) if y is not None else 0 # y position - pixels from right of canvas + # x position - pixels from left of canvas + self.x = int(x) if x is not None else 0 + # y position - pixels from right of canvas + self.y = int(y) if y is not None else 0 self.inaxes = None # the Axes instance if mouse us over axes self.xdata = None # x coord of mouse in data coords self.ydata = None # y coord of mouse in data coords From bda50d0f607a64dbef07b5ed6672259aedc58345 Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Fri, 29 Jun 2018 20:30:01 +0300 Subject: [PATCH 4/7] passing through None --- lib/matplotlib/backend_bases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index f9094107d347..c1ab1620c111 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1366,9 +1366,9 @@ def __init__(self, name, canvas, x, y, guiEvent=None): """ Event.__init__(self, name, canvas, guiEvent=guiEvent) # x position - pixels from left of canvas - self.x = int(x) if x is not None else 0 + self.x = int(x) if x is not None else x # y position - pixels from right of canvas - self.y = int(y) if y is not None else 0 + self.y = int(y) if y is not None else y self.inaxes = None # the Axes instance if mouse us over axes self.xdata = None # x coord of mouse in data coords self.ydata = None # y coord of mouse in data coords From 8853a3f8fa0de8c45677a699cf495bb2a951f9ed Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Fri, 29 Jun 2018 20:30:11 +0300 Subject: [PATCH 5/7] passing through None --- lib/matplotlib/backend_bases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index c1ab1620c111..e0ea6cea5de5 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1342,10 +1342,10 @@ class LocationEvent(Event): Attributes ---------- - x : int + x : scalar x position - pixels from left of canvas - y : int + y : scalar y position - pixels from bottom of canvas inaxes : bool From fff96784e92ea3d4aba41b6ac3025b84c83dce4d Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Sun, 1 Jul 2018 00:31:30 +0300 Subject: [PATCH 6/7] added a test case for x and y args of LocationEvent --- lib/matplotlib/tests/test_backend_bases.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py index cd8db6bc08ef..e9ee4cccfb99 100644 --- a/lib/matplotlib/tests/test_backend_bases.py +++ b/lib/matplotlib/tests/test_backend_bases.py @@ -1,5 +1,6 @@ from matplotlib.backend_bases import FigureCanvasBase from matplotlib.backend_bases import RendererBase +from matplotlib.backend_bases import LocationEvent import matplotlib.pyplot as plt import matplotlib.transforms as transforms @@ -77,3 +78,25 @@ def test_non_gui_warning(): assert len(rec) == 1 assert ('Matplotlib is currently using pdf, which is a non-GUI backend' in str(rec[0].message)) + + +def test_location_event_position(): + # LocationEvent should cast its x and y arguments + # to int unless it is None + fig = plt.figure() + canvas = FigureCanvasBase(fig) + test_positions = [(42, 24), (None, 42), (None, None), + (200, 100.01), (205.75, 2.0)] + for x, y in test_positions: + event = LocationEvent("test_event", canvas, x, y) + if x is None: + assert event.x is None + else: + assert event.x == int(x) + assert isinstance(event.x, int) + if y is None: + assert event.y is None + else: + assert event.y == int(y) + assert isinstance(event.y, int) + From eae165d9175572c0734a5e5daa0c8591186e9240 Mon Sep 17 00:00:00 2001 From: Taras Kuzyo Date: Sun, 1 Jul 2018 01:07:04 +0300 Subject: [PATCH 7/7] PEP8-check fixes --- lib/matplotlib/tests/test_backend_bases.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py index e9ee4cccfb99..048da404c81f 100644 --- a/lib/matplotlib/tests/test_backend_bases.py +++ b/lib/matplotlib/tests/test_backend_bases.py @@ -78,14 +78,14 @@ def test_non_gui_warning(): assert len(rec) == 1 assert ('Matplotlib is currently using pdf, which is a non-GUI backend' in str(rec[0].message)) - - + + def test_location_event_position(): # LocationEvent should cast its x and y arguments # to int unless it is None fig = plt.figure() canvas = FigureCanvasBase(fig) - test_positions = [(42, 24), (None, 42), (None, None), + test_positions = [(42, 24), (None, 42), (None, None), (200, 100.01), (205.75, 2.0)] for x, y in test_positions: event = LocationEvent("test_event", canvas, x, y) @@ -99,4 +99,3 @@ def test_location_event_position(): else: assert event.y == int(y) assert isinstance(event.y, int) -