Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: Add tooltips #843

Merged
merged 6 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions src/python/impactx/dashboard/Input/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

from .. import setup_server, vuetify
from .. import html, setup_server, vuetify
from .defaults import TooltipDefaults
from .generalFunctions import generalFunctions

server, state, ctrl = setup_server()
Expand Down Expand Up @@ -91,13 +92,18 @@ def select(
generalFunctions.get_default(f"{v_model_name}_list", "default_values"),
)

return vuetify.VSelect(
label=label,
v_model=(v_model_name,),
items=items,
dense=True,
**kwargs,
)
with vuetify.VTooltip(**TooltipDefaults.TOOLTIP_STYLE):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VSelect(
label=label,
v_model=(v_model_name,),
items=items,
dense=True,
**kwargs,
v_on="on",
v_bind="attrs",
)
html.Span(TooltipDefaults.TOOLTIP.get(v_model_name))

@staticmethod
def text_field(
Expand All @@ -121,17 +127,22 @@ def text_field(
if v_model_name is None:
v_model_name = label.lower().replace(" ", "_")

return vuetify.VTextField(
label=label,
v_model=(v_model_name,),
error_messages=(f"{v_model_name}_error_message", []),
type="number",
step=generalFunctions.get_default(f"{v_model_name}", "steps"),
suffix=generalFunctions.get_default(f"{v_model_name}", "units"),
__properties=["step"],
dense=True,
**kwargs,
)
with vuetify.VTooltip(**TooltipDefaults.TOOLTIP_STYLE):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
label=label,
v_model=(v_model_name,),
error_messages=(f"{v_model_name}_error_message", []),
type="number",
step=generalFunctions.get_default(f"{v_model_name}", "steps"),
suffix=generalFunctions.get_default(f"{v_model_name}", "units"),
__properties=["step"],
dense=True,
v_on="on",
v_bind="attrs",
**kwargs,
)
html.Span(TooltipDefaults.TOOLTIP.get(v_model_name))


class NavigationComponents:
Expand Down
20 changes: 20 additions & 0 deletions src/python/impactx/dashboard/Input/defaults.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from impactx.impactx_pybind import ImpactX, RefPart

from .defaults_helper import InputDefaultsHelper


class DashboardDefaults:
"""
Defaults for input parameters in the ImpactX dashboard.
Expand Down Expand Up @@ -113,3 +118,18 @@ class DashboardDefaults:
"beta": "m",
"emitt": "m",
}


class TooltipDefaults:
"""
Defaults for input toolips in the ImpactX dashboard.
"""

TOOLTIP_STYLE = {
"bottom": True,
"nudge_top": "20",
}

TOOLTIP = InputDefaultsHelper.get_docstrings(
[RefPart, ImpactX], DashboardDefaults.DEFAULT_VALUES
)
37 changes: 37 additions & 0 deletions src/python/impactx/dashboard/Input/defaults_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import inspect
from typing import Dict, List, Type


class InputDefaultsHelper:
"""
Methods in this class are used to dynamically parse
core ImpactX data (default values, docstrings, etc.)
"""

@staticmethod
def get_docstrings(
class_names: List[Type], default_list: Dict[str, any]
) -> Dict[str, str]:
"""
Retrieves docstrings for each method and property
in the provided clases.

:param classes: The class names to parse docstrings with.
:param defaults_list: The dictionary of defaults value.
"""

docstrings = {}

for each_class in class_names:
for name, attribute in inspect.getmembers(each_class):
if name not in default_list:
continue

is_method = inspect.isfunction(attribute)
is_property = inspect.isdatadescriptor(attribute)

if is_method or is_property:
docstring = inspect.getdoc(attribute) or ""
docstrings[name] = docstring

return docstrings
2 changes: 2 additions & 0 deletions src/python/impactx/dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from trame.widgets import html
from trame.widgets import vuetify as vuetify

# isort: off
Expand All @@ -18,6 +19,7 @@


__all__ = [
"html",
"JupyterApp",
"setup_server",
"vuetify",
Expand Down
Loading