@@ -22,13 +22,14 @@ class SliderValueFeature(GraphicFeature):
22
22
23
23
**pick info**
24
24
25
- +-----------------+----------------------------------------------------------------+
26
- | key | value |
27
- +=================+================================================================+
28
- | "new_data" | the new slider position in world coordinates |
29
- | "graphic_index" | the graphic data index that corresponds to the slider position |
30
- | "world_object" | parent world object |
31
- +-----------------+----------------------------------------------------------------+
25
+ +------------------+----------------------------------------------------------------+
26
+ | key | value |
27
+ +==================+================================================================+
28
+ | "new_data" | the new slider position in world coordinates |
29
+ | "selected_index" | the graphic data index that corresponds to the slider position |
30
+ | "world_object" | parent world object |
31
+ | "graphic" | LineSlider instance |
32
+ +------------------+----------------------------------------------------------------+
32
33
33
34
"""
34
35
def __init__ (self , parent , axis : str , value : float ):
@@ -59,7 +60,8 @@ def _feature_changed(self, key: Union[int, slice, Tuple[slice]], new_data: Any):
59
60
"collection-index" : self ._collection_index ,
60
61
"world_object" : self ._parent .world_object ,
61
62
"new_data" : new_data ,
62
- "graphic_index" : g_ix
63
+ "selected_index" : g_ix ,
64
+ "graphic" : self ._parent
63
65
}
64
66
65
67
event_data = FeatureEvent (type = "slider" , pick_info = pick_info )
@@ -189,6 +191,7 @@ def _setup_ipywidget_slider(self, widget):
189
191
widget .value = int (self .value ())
190
192
widget .observe (self ._ipywidget_callback , "value" )
191
193
self .value .add_event_handler (self ._update_ipywidget )
194
+ self ._plot_area .renderer .add_event_handler (self ._set_slider_layout , "resize" )
192
195
193
196
def _update_ipywidget (self , ev ):
194
197
# update the ipywidget slider value when LineSlider value changes
@@ -203,6 +206,11 @@ def _ipywidget_callback(self, change):
203
206
204
207
self .value = change ["new" ]
205
208
209
+ def _set_slider_layout (self , * args ):
210
+ w , h = self ._plot_area .renderer .logical_size
211
+
212
+ self .ipywidget_slider .layout = ipywidgets .Layout (width = f"{ w } px" )
213
+
206
214
def make_ipywidget_slider (self , kind : str = "IntSlider" , ** kwargs ):
207
215
"""
208
216
Makes and returns an ipywidget slider that is associated to this LineSlider
@@ -271,9 +279,9 @@ def get_selected_index(self, graphic: Graphic = None) -> int:
271
279
idx = np .searchsorted (to_search , find_value , side = "left" )
272
280
273
281
if idx > 0 and (idx == len (to_search ) or math .fabs (find_value - to_search [idx - 1 ]) < math .fabs (find_value - to_search [idx ])):
274
- return idx - 1
282
+ return int ( idx - 1 )
275
283
else :
276
- return idx
284
+ return int ( idx )
277
285
278
286
def _get_source (self , graphic ):
279
287
if self .parent is None and graphic is None :
0 commit comments