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