Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 718eee7

Browse filesBrowse files
committed
lineslider events works
1 parent e11ab3f commit 718eee7
Copy full SHA for 718eee7

File tree

Expand file treeCollapse file tree

1 file changed

+18
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-10
lines changed

‎fastplotlib/graphics/line_slider.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/line_slider.py
+18-10Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ class SliderValueFeature(GraphicFeature):
2222
2323
**pick info**
2424
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+
+------------------+----------------------------------------------------------------+
3233
3334
"""
3435
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):
5960
"collection-index": self._collection_index,
6061
"world_object": self._parent.world_object,
6162
"new_data": new_data,
62-
"graphic_index": g_ix
63+
"selected_index": g_ix,
64+
"graphic": self._parent
6365
}
6466

6567
event_data = FeatureEvent(type="slider", pick_info=pick_info)
@@ -189,6 +191,7 @@ def _setup_ipywidget_slider(self, widget):
189191
widget.value = int(self.value())
190192
widget.observe(self._ipywidget_callback, "value")
191193
self.value.add_event_handler(self._update_ipywidget)
194+
self._plot_area.renderer.add_event_handler(self._set_slider_layout, "resize")
192195

193196
def _update_ipywidget(self, ev):
194197
# update the ipywidget slider value when LineSlider value changes
@@ -203,6 +206,11 @@ def _ipywidget_callback(self, change):
203206

204207
self.value = change["new"]
205208

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+
206214
def make_ipywidget_slider(self, kind: str = "IntSlider", **kwargs):
207215
"""
208216
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:
271279
idx = np.searchsorted(to_search, find_value, side="left")
272280

273281
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)
275283
else:
276-
return idx
284+
return int(idx)
277285

278286
def _get_source(self, graphic):
279287
if self.parent is None and graphic is None:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.