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