Skip to content

Commit

Permalink
Unified code location of tooltip comments
Browse files Browse the repository at this point in the history
Future work includes helper function to parse comments from docstring
  • Loading branch information
proy30 committed Nov 21, 2024
1 parent 1fcae70 commit c81ce87
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@
state.distributionTypeDisabled = False


parameter_tooltips = {
"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.",
}

# -----------------------------------------------------------------------------
# Main Functions
# -----------------------------------------------------------------------------
Expand All @@ -63,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 @@ -76,7 +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": parameter_tooltips.get(param.name, "N/A"),
"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 @@ -99,7 +88,9 @@ def populate_distribution_parameters(selectedDistribution):
"parameter_error_message": generalFunctions.validate_against(
parameter[1], parameter[2]
),
"parameter_tooltip": parameter_tooltips.get(parameter[0], "N/A"),
"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
29 changes: 21 additions & 8 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,24 @@ def convert_to_correct_type(value, desired_type):
# Tooltip Comments
# -----------------------------------------------------------------------------

state.particle_shape_tooltip = "Whether to calculate space charge effects."
state.kin_energy_tooltip = "Get reference particle energy (MeV)"
state.charge_qe_tooltip = (
"Get reference particle charge (positive elementary charge)"
)
state.npart_tooltip = "TBD"
state.mass_MeV_tooltip = "Get reference particle rest mass (MeV/c^2)"
state.bunch_charge_C_tooltip = "TBD"
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",
}
13 changes: 7 additions & 6 deletions src/python/impactx/dashboard/Input/inputParameters/inputMain.py
Original file line number Diff line number Diff line change
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 All @@ -106,7 +107,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ particle_shape_tooltip }}")
html.Span("{{ parameter_tooltips.particle_shape }}")
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=6, classes="py-0"):
with vuetify.VTooltip(bottom=True, nudge_top="10"):
Expand All @@ -125,7 +126,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ charge_qe_tooltip }}")
html.Span("{{ parameter_tooltips.charge_qe }}")
with vuetify.VCol(cols=6, classes="py-0"):
with vuetify.VTooltip(bottom=True, nudge_top="10"):
with vuetify.Template(v_slot_activator="{ on, attrs }"):
Expand All @@ -143,7 +144,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ mass_MeV_tooltip }}")
html.Span("{{ parameter_tooltips.mass_MeV }}")
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(cols=12, classes="py-0"):
with vuetify.VTooltip(bottom=True, nudge_top="10"):
Expand All @@ -161,7 +162,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ npart_tooltip }}")
html.Span("{{ parameter_tooltips.npart }}")
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=8, classes="py-0"):
with vuetify.VTooltip(bottom=True, nudge_top="10"):
Expand All @@ -179,7 +180,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ kin_energy_tooltip }}")
html.Span("{{ parameter_tooltips.kin_energy }}")
with vuetify.VCol(cols=4, classes="py-0"):
vuetify.VSelect(
v_model=("kin_energy_unit",),
Expand All @@ -205,7 +206,7 @@ def card(self):
v_on="on",
v_bind="attrs",
)
html.Span("{{ bunch_charge_C_tooltip }}")
html.Span("{{ parameter_tooltips.bunch_charge_C }}")
with vuetify.VCol(cols=4, classes="py-0"):
vuetify.VTextField(
label="Unit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
state.nsliceDefaultValue = None


parameter_tooltips = {
"nslice": "testing",
}

# -----------------------------------------------------------------------------
# Main Functions
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -68,7 +64,9 @@ def add_lattice_element():
"parameter_error_message": generalFunctions.validate_against(
parameter[1], parameter[2]
),
"parameter_tooltip": parameter_tooltips.get(parameter[0], "N/A"),
"parameter_tooltip": generalFunctions.parameter_tooltips.get(
parameter[0], "N/A"
),
}
for parameter in selectedLatticeParameters
],
Expand Down

0 comments on commit c81ce87

Please sign in to comment.