Skip to content

Commit 5cda159

Browse files
kushalkolarclewis7
andauthored
Tooltips, add overlay render pass (#830)
* add overlay render pass * Graphic accessible in graphics * tooltip prototype * basic tooltips work * custom tooltip example * auto tooltips * black * update iris example, add to __init__ * update docs * type * comments * docstring * add tools dir to api root toctree * forgot to regenerate * Apply suggestions from code review Co-authored-by: Caitlin Lewis <69729525+clewis7@users.noreply.github.com> --------- Co-authored-by: Caitlin Lewis <69729525+clewis7@users.noreply.github.com>
1 parent 220527e commit 5cda159

File tree

19 files changed

+678
-10
lines changed

19 files changed

+678
-10
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. _api.Graphic:
2+
3+
Graphic
4+
*******
5+
6+
=======
7+
Graphic
8+
=======
9+
.. currentmodule:: fastplotlib
10+
11+
Constructor
12+
~~~~~~~~~~~
13+
.. autosummary::
14+
:toctree: Graphic_api
15+
16+
Graphic
17+
18+
Properties
19+
~~~~~~~~~~
20+
.. autosummary::
21+
:toctree: Graphic_api
22+
23+
Graphic.axes
24+
Graphic.block_events
25+
Graphic.deleted
26+
Graphic.event_handlers
27+
Graphic.name
28+
Graphic.offset
29+
Graphic.right_click_menu
30+
Graphic.rotation
31+
Graphic.supported_events
32+
Graphic.visible
33+
Graphic.world_object
34+
35+
Methods
36+
~~~~~~~
37+
.. autosummary::
38+
:toctree: Graphic_api
39+
40+
Graphic.add_axes
41+
Graphic.add_event_handler
42+
Graphic.clear_event_handlers
43+
Graphic.remove_event_handler
44+
Graphic.rotate
45+
Graphic.share_property
46+
Graphic.unshare_property
47+

docs/source/api/graphics/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Graphics
44
.. toctree::
55
:maxdepth: 1
66

7+
Graphic
78
LineGraphic
89
ScatterGraphic
910
ImageGraphic

docs/source/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ API Reference
99
graphics/index
1010
graphic_features/index
1111
selectors/index
12+
tools/index
1213
ui/index
1314
widgets/index
1415
fastplotlib

docs/source/api/layouts/figure.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Properties
2727
Figure.names
2828
Figure.renderer
2929
Figure.shape
30+
Figure.show_tooltips
31+
Figure.tooltip_manager
3032

3133
Methods
3234
~~~~~~~

docs/source/api/layouts/imgui_figure.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Properties
2929
ImguiFigure.names
3030
ImguiFigure.renderer
3131
ImguiFigure.shape
32+
ImguiFigure.show_tooltips
33+
ImguiFigure.tooltip_manager
3234

3335
Methods
3436
~~~~~~~
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.. _api.HistogramLUTTool:
2+
3+
HistogramLUTTool
4+
****************
5+
6+
================
7+
HistogramLUTTool
8+
================
9+
.. currentmodule:: fastplotlib
10+
11+
Constructor
12+
~~~~~~~~~~~
13+
.. autosummary::
14+
:toctree: HistogramLUTTool_api
15+
16+
HistogramLUTTool
17+
18+
Properties
19+
~~~~~~~~~~
20+
.. autosummary::
21+
:toctree: HistogramLUTTool_api
22+
23+
HistogramLUTTool.axes
24+
HistogramLUTTool.block_events
25+
HistogramLUTTool.cmap
26+
HistogramLUTTool.deleted
27+
HistogramLUTTool.event_handlers
28+
HistogramLUTTool.image_graphic
29+
HistogramLUTTool.name
30+
HistogramLUTTool.offset
31+
HistogramLUTTool.right_click_menu
32+
HistogramLUTTool.rotation
33+
HistogramLUTTool.supported_events
34+
HistogramLUTTool.visible
35+
HistogramLUTTool.vmax
36+
HistogramLUTTool.vmin
37+
HistogramLUTTool.world_object
38+
39+
Methods
40+
~~~~~~~
41+
.. autosummary::
42+
:toctree: HistogramLUTTool_api
43+
44+
HistogramLUTTool.add_axes
45+
HistogramLUTTool.add_event_handler
46+
HistogramLUTTool.clear_event_handlers
47+
HistogramLUTTool.disconnect_image_graphic
48+
HistogramLUTTool.remove_event_handler
49+
HistogramLUTTool.rotate
50+
HistogramLUTTool.set_data
51+
HistogramLUTTool.share_property
52+
HistogramLUTTool.unshare_property
53+

docs/source/api/tools/Tooltip.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _api.Tooltip:
2+
3+
Tooltip
4+
*******
5+
6+
=======
7+
Tooltip
8+
=======
9+
.. currentmodule:: fastplotlib
10+
11+
Constructor
12+
~~~~~~~~~~~
13+
.. autosummary::
14+
:toctree: Tooltip_api
15+
16+
Tooltip
17+
18+
Properties
19+
~~~~~~~~~~
20+
.. autosummary::
21+
:toctree: Tooltip_api
22+
23+
Tooltip.background_color
24+
Tooltip.font_size
25+
Tooltip.outline_color
26+
Tooltip.padding
27+
Tooltip.text_color
28+
Tooltip.world_object
29+
30+
Methods
31+
~~~~~~~
32+
.. autosummary::
33+
:toctree: Tooltip_api
34+
35+
Tooltip.register
36+
Tooltip.unregister
37+
Tooltip.unregister_all
38+

docs/source/api/tools/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Tools
2+
*****
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
HistogramLUTTool
8+
Tooltip

docs/source/generate_api.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from fastplotlib.layouts import Subplot
1010
from fastplotlib import graphics
1111
from fastplotlib.graphics import features, selectors
12+
from fastplotlib import tools
1213
from fastplotlib import widgets
1314
from fastplotlib import utils
1415
from fastplotlib import ui
@@ -21,6 +22,7 @@
2122
GRAPHICS_DIR = API_DIR.joinpath("graphics")
2223
GRAPHIC_FEATURES_DIR = API_DIR.joinpath("graphic_features")
2324
SELECTORS_DIR = API_DIR.joinpath("selectors")
25+
TOOLS_DIR = API_DIR.joinpath("tools")
2426
WIDGETS_DIR = API_DIR.joinpath("widgets")
2527
UI_DIR = API_DIR.joinpath("ui")
2628
GUIDE_DIR = current_dir.joinpath("user_guide")
@@ -31,6 +33,7 @@
3133
GRAPHICS_DIR,
3234
GRAPHIC_FEATURES_DIR,
3335
SELECTORS_DIR,
36+
TOOLS_DIR,
3437
WIDGETS_DIR,
3538
UI_DIR,
3639
]
@@ -264,7 +267,8 @@ def main():
264267
)
265268

266269
# the rest of this is a mess and can be refactored later
267-
270+
##############################################################################
271+
# ** Graphic classes ** #
268272
graphic_classes = [getattr(graphics, g) for g in graphics.__all__]
269273

270274
graphic_class_names = [g.__name__ for g in graphic_classes]
@@ -290,7 +294,7 @@ def main():
290294
source_path=GRAPHICS_DIR.joinpath(f"{graphic_cls.__name__}.rst"),
291295
)
292296
##############################################################################
293-
297+
# ** GraphicFeature classes ** #
294298
feature_classes = [getattr(features, f) for f in features.__all__]
295299

296300
feature_class_names = [f.__name__ for f in feature_classes]
@@ -315,7 +319,7 @@ def main():
315319
source_path=GRAPHIC_FEATURES_DIR.joinpath(f"{feature_cls.__name__}.rst"),
316320
)
317321
##############################################################################
318-
322+
# ** Selector classes ** #
319323
selector_classes = [getattr(selectors, s) for s in selectors.__all__]
320324

321325
selector_class_names = [s.__name__ for s in selector_classes]
@@ -339,8 +343,35 @@ def main():
339343
modules=["fastplotlib"],
340344
source_path=SELECTORS_DIR.joinpath(f"{selector_cls.__name__}.rst"),
341345
)
346+
342347
##############################################################################
348+
# ** Tools classes ** #
349+
tools_classes = [getattr(tools, t) for t in tools.__all__]
343350

351+
tools_class_names = [t.__name__ for t in tools_classes]
352+
353+
tools_class_names_str = "\n ".join([""] + tools_class_names)
354+
355+
with open(TOOLS_DIR.joinpath("index.rst"), "w") as f:
356+
f.write(
357+
f"Tools\n"
358+
f"*****\n"
359+
f"\n"
360+
f".. toctree::\n"
361+
f" :maxdepth: 1\n"
362+
f"{tools_class_names_str}\n"
363+
)
364+
365+
for tool_cls in tools_classes:
366+
generate_page(
367+
page_name=tool_cls.__name__,
368+
classes=[tool_cls],
369+
modules=["fastplotlib"],
370+
source_path=TOOLS_DIR.joinpath(f"{tool_cls.__name__}.rst"),
371+
)
372+
373+
##############################################################################
374+
# ** Widget classes ** #
344375
widget_classes = [getattr(widgets, w) for w in widgets.__all__]
345376

346377
widget_class_names = [w.__name__ for w in widget_classes]
@@ -365,7 +396,7 @@ def main():
365396
source_path=WIDGETS_DIR.joinpath(f"{widget_cls.__name__}.rst"),
366397
)
367398
##############################################################################
368-
399+
# ** UI classes ** #
369400
ui_classes = [ui.BaseGUI, ui.Window, ui.EdgeWindow, ui.Popup]
370401

371402
ui_class_names = [cls.__name__ for cls in ui_classes]
@@ -410,6 +441,7 @@ def main():
410441
" graphics/index\n"
411442
" graphic_features/index\n"
412443
" selectors/index\n"
444+
" tools/index\n"
413445
" ui/index\n"
414446
" widgets/index\n"
415447
" fastplotlib\n"
@@ -438,6 +470,9 @@ def write_table(name, feature_cls):
438470
f.write("============\n\n")
439471

440472
for graphic_cls in [*graphic_classes, *selector_classes]:
473+
if graphic_cls is graphics.Graphic:
474+
# skip Graphic base class
475+
continue
441476
f.write(f"{graphic_cls.__name__}\n")
442477
f.write("-" * len(graphic_cls.__name__) + "\n\n")
443478
for name, type_ in graphic_cls._features.items():

examples/line_collection/line_stack.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
data = np.column_stack([xs, ys])
2020
multi_data = np.stack([data] * 10)
2121

22-
figure = fpl.Figure(size=(700, 560))
22+
figure = fpl.Figure(
23+
size=(700, 560),
24+
show_tooltips=True
25+
)
2326

2427
line_stack = figure[0, 0].add_line_stack(
2528
multi_data, # shape: (10, 100, 2), i.e. [n_lines, n_points, xy]
@@ -28,6 +31,26 @@
2831
separation=1, # spacing between lines along the separation axis, default separation along "y" axis
2932
)
3033

34+
35+
def tooltip_info(ev):
36+
"""A custom function to display the index of the graphic within the collection."""
37+
index = ev.pick_info["vertex_index"] # index of the line datapoint being hovered
38+
39+
# get index of the hovered line within the line stack
40+
line_index = np.where(line_stack.graphics == ev.graphic)[0].item()
41+
info = f"line index: {line_index}\n"
42+
43+
# append data value info
44+
info += "\n".join(f"{dim}: {val}" for dim, val in zip("xyz", ev.graphic.data[index]))
45+
46+
# return str to display in tooltip
47+
return info
48+
49+
# register the line stack with the custom tooltip function
50+
figure.tooltip_manager.register(
51+
line_stack, custom_info=tooltip_info
52+
)
53+
3154
figure.show(maintain_aspect=False)
3255

3356

0 commit comments

Comments
 (0)