@@ -52,22 +52,23 @@ def __init__(
52
52
origin = (hist_scaled .max () / 2 , 0 )
53
53
54
54
self ._linear_region_selector = LinearRegionSelector (
55
- bounds = bounds ,
55
+ selection = bounds ,
56
56
limits = limits ,
57
57
size = size ,
58
- origin = origin ,
58
+ center = origin [ 0 ] ,
59
59
axis = "y" ,
60
60
edge_thickness = 8 ,
61
+ parent = self ._histogram_line
61
62
)
62
63
63
- # there will be a small difference with the histogram edges so this makes them both line up exactly
64
+ #there will be a small difference with the histogram edges so this makes them both line up exactly
64
65
self ._linear_region_selector .selection = (
65
- image_graphic . cmap .vmin ,
66
- image_graphic . cmap .vmax ,
66
+ self . _image_graphic .vmin ,
67
+ self . _image_graphic .vmax ,
67
68
)
68
69
69
- self ._vmin = self .image_graphic .cmap . vmin
70
- self ._vmax = self .image_graphic .cmap . vmax
70
+ self ._vmin = self .image_graphic .vmin
71
+ self ._vmax = self .image_graphic .vmax
71
72
72
73
vmin_str , vmax_str = self ._get_vmin_vmax_str ()
73
74
@@ -105,17 +106,15 @@ def __init__(
105
106
106
107
self .world_object .local .scale_x *= - 1
107
108
108
- self ._text_vmin .position_x = - 120
109
- self ._text_vmin .position_y = self ._linear_region_selector .selection ()[0 ]
109
+ self ._text_vmin .offset = (- 120 , self ._linear_region_selector .selection [0 ], 0 )
110
110
111
- self ._text_vmax .position_x = - 120
112
- self ._text_vmax .position_y = self ._linear_region_selector .selection ()[1 ]
111
+ self ._text_vmax .offset = (- 120 , self ._linear_region_selector .selection [1 ], 0 )
113
112
114
- self ._linear_region_selector .selection . add_event_handler (
115
- self ._linear_region_handler
113
+ self ._linear_region_selector .add_event_handler (
114
+ self ._linear_region_handler , "selection"
116
115
)
117
116
118
- self .image_graphic .cmap . add_event_handler (self ._image_cmap_handler )
117
+ self .image_graphic .add_event_handler (self ._image_cmap_handler , "vmin" , "vmax" )
119
118
120
119
def _get_vmin_vmax_str (self ) -> tuple [str , str ]:
121
120
if self .vmin < 0.001 or self .vmin > 99_999 :
@@ -198,39 +197,38 @@ def _calculate_histogram(self, data):
198
197
def _linear_region_handler (self , ev ):
199
198
# must use world coordinate values directly from selection()
200
199
# otherwise the linear region bounds jump to the closest bin edges
201
- vmin , vmax = self ._linear_region_selector .selection ()
200
+ selected_ixs = self ._linear_region_selector .selection
201
+ vmin , vmax = selected_ixs [0 ], selected_ixs [1 ]
202
202
vmin , vmax = vmin / self ._scale_factor , vmax / self ._scale_factor
203
203
self .vmin , self .vmax = vmin , vmax
204
204
205
205
def _image_cmap_handler (self , ev ):
206
- self .vmin , self .vmax = ev .pick_info ["vmin" ], ev .pick_info ["vmax" ]
207
-
208
- def _block_events (self , b : bool ):
209
- self .image_graphic .cmap .block_events (b )
210
- self ._linear_region_selector .selection .block_events (b )
206
+ setattr (self , ev .type , ev .info ["value" ])
211
207
212
208
@property
213
209
def vmin (self ) -> float :
214
210
return self ._vmin
215
211
216
212
@vmin .setter
217
213
def vmin (self , value : float ):
218
- self ._block_events (True )
214
+ self .image_graphic .block_events = True
215
+ self ._linear_region_selector .block_events = True
219
216
220
217
# must use world coordinate values directly from selection()
221
218
# otherwise the linear region bounds jump to the closest bin edges
222
219
self ._linear_region_selector .selection = (
223
220
value * self ._scale_factor ,
224
- self ._linear_region_selector .selection () [1 ],
221
+ self ._linear_region_selector .selection [1 ],
225
222
)
226
- self .image_graphic .cmap . vmin = value
223
+ self .image_graphic .vmin = value
227
224
228
- self ._block_events (False )
225
+ self .image_graphic .block_events = False
226
+ self ._linear_region_selector .block_events = False
229
227
230
228
self ._vmin = value
231
229
232
230
vmin_str , vmax_str = self ._get_vmin_vmax_str ()
233
- self ._text_vmin .position_y = self ._linear_region_selector .selection () [0 ]
231
+ self ._text_vmin .offset = ( - 120 , self ._linear_region_selector .selection [0 ], 0 )
234
232
self ._text_vmin .text = vmin_str
235
233
236
234
@property
@@ -239,22 +237,25 @@ def vmax(self) -> float:
239
237
240
238
@vmax .setter
241
239
def vmax (self , value : float ):
242
- self ._block_events (True )
240
+ self .image_graphic .block_events = True
241
+ self ._linear_region_selector .block_events = True
243
242
244
243
# must use world coordinate values directly from selection()
245
244
# otherwise the linear region bounds jump to the closest bin edges
246
245
self ._linear_region_selector .selection = (
247
- self ._linear_region_selector .selection () [0 ],
246
+ self ._linear_region_selector .selection [0 ],
248
247
value * self ._scale_factor ,
249
248
)
250
- self .image_graphic .cmap .vmax = value
251
249
252
- self ._block_events (False )
250
+ self .image_graphic .vmax = value
251
+
252
+ self .image_graphic .block_events = False
253
+ self ._linear_region_selector .block_events = False
253
254
254
255
self ._vmax = value
255
256
256
257
vmin_str , vmax_str = self ._get_vmin_vmax_str ()
257
- self ._text_vmax .position_y = self ._linear_region_selector .selection () [1 ]
258
+ self ._text_vmax .offset = ( - 120 , self ._linear_region_selector .selection [1 ], 0 )
258
259
self ._text_vmax .text = vmax_str
259
260
260
261
def set_data (self , data , reset_vmin_vmax : bool = True ):
@@ -275,9 +276,11 @@ def set_data(self, data, reset_vmin_vmax: bool = True):
275
276
self ._linear_region_selector .selection = bounds
276
277
else :
277
278
# don't change the current selection
278
- self ._block_events (True )
279
+ self .image_graphic .block_events = True
280
+ self ._linear_region_selector .block_events = True
279
281
self ._linear_region_selector .limits = limits
280
- self ._block_events (False )
282
+ self .image_graphic .block_events = False
283
+ self ._linear_region_selector .block_events = False
281
284
282
285
self ._data = weakref .proxy (data )
283
286
@@ -297,14 +300,14 @@ def image_graphic(self, graphic):
297
300
298
301
if self ._image_graphic is not None :
299
302
# cleanup events from current image graphic
300
- self ._image_graphic .cmap . remove_event_handler (self ._image_cmap_handler )
303
+ self ._image_graphic .remove_event_handler (self ._image_cmap_handler )
301
304
302
305
self ._image_graphic = graphic
303
306
304
- self .image_graphic .cmap . add_event_handler (self ._image_cmap_handler )
307
+ self .image_graphic .add_event_handler (self ._image_cmap_handler )
305
308
306
309
def disconnect_image_graphic (self ):
307
- self ._image_graphic .cmap . remove_event_handler (self ._image_cmap_handler )
310
+ self ._image_graphic .remove_event_handler (self ._image_cmap_handler )
308
311
del self ._image_graphic
309
312
# self._image_graphic = None
310
313
0 commit comments