@@ -64,6 +64,47 @@ def test_rectangle_selector():
64
64
check_rectangle (props = dict (fill = True ))
65
65
66
66
67
+ @pytest .mark .parametrize ('spancoords' , ['data' , 'pixels' ])
68
+ @pytest .mark .parametrize ('minspanx, x1' , [[0 , 10 ], [1 , 10.5 ], [1 , 11 ]])
69
+ @pytest .mark .parametrize ('minspany, y1' , [[0 , 10 ], [1 , 10.5 ], [1 , 11 ]])
70
+ def test_rectangle_minspan (spancoords , minspanx , x1 , minspany , y1 ):
71
+ ax = get_ax ()
72
+ # attribute to track number of onselect calls
73
+ ax ._n_onselect = 0
74
+
75
+ def onselect (epress , erelease ):
76
+ ax ._n_onselect += 1
77
+ ax ._epress = epress
78
+ ax ._erelease = erelease
79
+
80
+ x0 , y0 = (10 , 10 )
81
+ if spancoords == 'pixels' :
82
+ minspanx , minspany = (ax .transData .transform ((x1 , y1 )) -
83
+ ax .transData .transform ((x0 , y0 )))
84
+
85
+ tool = widgets .RectangleSelector (ax , onselect , interactive = True ,
86
+ spancoords = spancoords ,
87
+ minspanx = minspanx , minspany = minspany )
88
+ # Too small to create a selector
89
+ click_and_drag (tool , start = (x0 , x1 ), end = (y0 , y1 ))
90
+ assert not tool ._selection_completed
91
+ assert ax ._n_onselect == 0
92
+
93
+ click_and_drag (tool , start = (20 , 20 ), end = (30 , 30 ))
94
+ assert tool ._selection_completed
95
+ assert ax ._n_onselect == 1
96
+
97
+ # Too small to create a selector. Should clear exising selector, and
98
+ # trigger onselect because there was a pre-exisiting selector
99
+ click_and_drag (tool , start = (x0 , y0 ), end = (x1 , y1 ))
100
+ assert not tool ._selection_completed
101
+ assert ax ._n_onselect == 2
102
+ assert ax ._epress .xdata == x0
103
+ assert ax ._epress .ydata == y0
104
+ assert ax ._erelease .xdata == x1
105
+ assert ax ._erelease .ydata == y1
106
+
107
+
67
108
@pytest .mark .parametrize ('drag_from_anywhere, new_center' ,
68
109
[[True , (60 , 75 )],
69
110
[False , (30 , 20 )]])
0 commit comments