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

[WIP] Tooltips for user-inputs in dashboard #759

Draft
wants to merge 6 commits into
base: development
Choose a base branch
from
Draft
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
28 changes: 18 additions & 10 deletions src/python/impactx/dashboard/Input/csrConfiguration/csrMain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame.widgets import vuetify
from trame.widgets import html, vuetify

from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions
Expand Down Expand Up @@ -47,20 +47,28 @@ def card():
)
vuetify.VDivider()
with vuetify.VCardText():
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(classes="py-0"):
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VSelect(
label="Particle Shape",
v_model=("particle_shape",),
items=([1, 2, 3],),
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.particle_shape }}")
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(classes="py-0"):
vuetify.VTextField(
label="CSR Bins",
v_model=("csr_bins",),
error_messages=("csr_bins_error_message",),
type="number",
dense=True,
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
label="CSR Bins",
v_model=("csr_bins",),
error_messages=("csr_bins_error_message",),
type="number",
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.csr_bins }}")
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import inspect

from distribution_input_helpers import twiss
from trame.widgets import vuetify
from trame.widgets import html, vuetify

from impactx import distribution

Expand Down Expand Up @@ -39,6 +39,7 @@
state.selectedDistributionParameters = []
state.distributionTypeDisabled = False


# -----------------------------------------------------------------------------
# Main Functions
# -----------------------------------------------------------------------------
Expand All @@ -50,7 +51,6 @@ def populate_distribution_parameters(selectedDistribution):
:param selectedDistribution (str): The name of the selected distribution
whose parameters need to be populated.
"""

if state.selectedDistributionType == "Twiss":
sig = inspect.signature(twiss)
state.selectedDistributionParameters = [
Expand All @@ -63,6 +63,9 @@ def populate_distribution_parameters(selectedDistribution):
"parameter_error_message": generalFunctions.validate_against(
param.default if param.default != param.empty else None, "float"
),
"parameter_tooltip": generalFunctions.parameter_tooltips.get(
param.name, "N/A"
),
"parameter_units": "m"
if "beta" in param.name or "emitt" in param.name
else "",
Expand All @@ -85,6 +88,9 @@ def populate_distribution_parameters(selectedDistribution):
"parameter_error_message": generalFunctions.validate_against(
parameter[1], parameter[2]
),
"parameter_tooltip": generalFunctions.parameter_tooltips.get(
parameter[0], "N/A"
),
"parameter_units": "m"
if "beta" in parameter[0] or "emitt" in parameter[0]
else "",
Expand Down Expand Up @@ -219,17 +225,26 @@ def card():
with vuetify.VCol(
v_if=f"index % 3 == {i}", classes="py-1"
):
vuetify.VTextField(
label=("parameter.parameter_name",),
v_model=("parameter.parameter_default_value",),
suffix=("parameter.parameter_units",),
change=(
ctrl.updateDistributionParameters,
"[parameter.parameter_name, $event, parameter.parameter_type]",
),
error_messages=(
"parameter.parameter_error_message",
),
type="number",
dense=True,
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(
v_slot_activator="{ on, attrs }"
):
vuetify.VTextField(
label=("parameter.parameter_name",),
v_model=(
"parameter.parameter_default_value",
),
suffix=("parameter.parameter_units",),
change=(
ctrl.updateDistributionParameters,
"[parameter.parameter_name, $event, parameter.parameter_type]",
),
error_messages=(
"parameter.parameter_error_message",
),
type="number",
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter.parameter_tooltip }}")
26 changes: 26 additions & 0 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,29 @@ def convert_to_correct_type(value, desired_type):
return str(value)
else:
raise ValueError("Unknown type")

# -----------------------------------------------------------------------------
# Tooltip Comments
# -----------------------------------------------------------------------------

parameter_tooltips = {
# Input Parameters
"particle_shape": "Whether to calculate space charge effects.",
"kin_energy": "Get reference particle energy (MeV).",
"charge_qe": "Get reference particle charge (positive elementary charge).",
"npart": "Number of particles to simulate.",
"mass_MeV": "Get reference particle rest mass (MeV/c^2).",
"bunch_charge_C": "Total charge of the particle bunch (Coulombs).",
# Distribution Parameters
"beta_x": "Beta function value (unit: meter) in the x dimension, must be a non-zero positive value.",
"beta_y": "Beta function value (unit: meter) in the y dimension, must be a non-zero positive value.",
"beta_t": "Beta function value (unit: meter) in the t dimension (arrival time differences multiplied by light speed), must be a non-zero positive value.",
"emitt_x": "Emittance value (unit: meter times radian) in the x dimension, must be a non-zero positive value.",
"emitt_y": "Emittance value (unit: meter times radian) in the y dimension, must be a non-zero positive value.",
"emitt_t": "Emittance value (unit: meter times radian) in the t dimension (arrival time differences multiplied by light speed), must be a non-zero positive value.",
"alpha_x": "Alpha function value () in the x dimension, default is 0.0.",
"alpha_y": "Alpha function value in the y dimension, default is 0.0.",
"alpha_t": "Alpha function value in the t dimension, default is 0.0.",
# Lattice Parameters
"nslice": "testing",
}
143 changes: 84 additions & 59 deletions src/python/impactx/dashboard/Input/inputParameters/inputMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
License: BSD-3-Clause-LBNL
"""

from trame.widgets import vuetify
from trame.widgets import html, vuetify

from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions
Expand Down Expand Up @@ -80,6 +80,7 @@ def __init__(self):
state.bunch_charge_C_validation = []
state.mass_MeV_validation = []
state.charge_qe_validation = []
state.parameter_tooltips = generalFunctions.parameter_tooltips

def card(self):
"""
Expand Down Expand Up @@ -111,58 +112,77 @@ def card(self):
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VTextField(
label="Ref. Particle Charge",
v_model=("charge_qe",),
suffix="qe",
type="number",
dense=True,
error_messages=("charge_qe_validation",),
change=(
ctrl.on_input_change,
"[$event, 'int','charge_qe','charge_qe_validation', ['non_zero']]",
),
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
label="Ref. Particle Charge",
v_model=("charge_qe",),
suffix="qe",
type="number",
dense=True,
error_messages=("charge_qe_validation",),
change=(
ctrl.on_input_change,
"[$event, 'int','charge_qe','charge_qe_validation', ['non_zero']]",
),
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.charge_qe }}")
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VTextField(
label="Ref. Particle Mass",
v_model=("mass_MeV",),
suffix="MeV",
type="number",
dense=True,
error_messages=("mass_MeV_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','mass_MeV','mass_MeV_validation', ['positive']]",
),
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
label="Ref. Particle Mass",
v_model=("mass_MeV",),
suffix="MeV",
type="number",
dense=True,
error_messages=("mass_MeV_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','mass_MeV','mass_MeV_validation', ['positive']]",
),
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.mass_MeV }}")
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(cols=12, classes="py-0"):
vuetify.VTextField(
v_model=("npart",),
label="Number of Particles",
error_messages=("npart_validation",),
change=(
ctrl.on_input_change,
"[$event, 'int','npart','npart_validation']",
),
type="number",
dense=True,
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
v_model=("npart",),
label="Number of Particles",
error_messages=("npart_validation",),
change=(
ctrl.on_input_change,
"[$event, 'int','npart','npart_validation']",
),
type="number",
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.npart }}")
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=8, classes="py-0"):
vuetify.VTextField(
v_model=("kin_energy",),
label="Kinetic Energy",
error_messages=("kin_energy_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','kin_energy','kin_energy_validation']",
),
type="number",
dense=True,
classes="mr-2",
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
v_model=("kin_energy",),
label="Kinetic Energy",
error_messages=("kin_energy_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','kin_energy','kin_energy_validation']",
),
type="number",
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.kin_energy }}")
with vuetify.VCol(cols=4, classes="py-0"):
vuetify.VSelect(
v_model=("kin_energy_unit",),
Expand All @@ -173,17 +193,22 @@ def card(self):
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=8, classes="py-0"):
vuetify.VTextField(
label="Bunch Charge",
v_model=("bunch_charge_C",),
error_messages=("bunch_charge_C_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','bunch_charge_C','bunch_charge_C_validation']",
),
type="number",
dense=True,
)
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
vuetify.VTextField(
label="Bunch Charge",
v_model=("bunch_charge_C",),
error_messages=("bunch_charge_C_validation",),
change=(
ctrl.on_input_change,
"[$event, 'float','bunch_charge_C','bunch_charge_C_validation']",
),
type="number",
dense=True,
v_on="on",
v_bind="attrs",
)
html.Span("{{ parameter_tooltips.bunch_charge_C }}")
with vuetify.VCol(cols=4, classes="py-0"):
vuetify.VTextField(
label="Unit",
Expand Down
Loading