diff --git a/ml_peg/app/utils/build_components.py b/ml_peg/app/utils/build_components.py index a35dc17e7..1e1f22d45 100644 --- a/ml_peg/app/utils/build_components.py +++ b/ml_peg/app/utils/build_components.py @@ -27,6 +27,7 @@ calculate_column_widths, get_framework_config, get_threshold_colours, + weight_input_style, ) @@ -119,14 +120,7 @@ def build_weight_input( value=default_value, step=0.01, debounce=True, - style={ - "width": "60px", - "fontSize": "12px", - "padding": "2px 4px", - "border": "1px solid #6c757d", - "borderRadius": "3px", - "textAlign": "center", - }, + style=weight_input_style(default_value), ) ) diff --git a/ml_peg/app/utils/register_callbacks.py b/ml_peg/app/utils/register_callbacks.py index 168acc5fd..8c4cc15e4 100644 --- a/ml_peg/app/utils/register_callbacks.py +++ b/ml_peg/app/utils/register_callbacks.py @@ -40,6 +40,7 @@ format_tooltip_headers, get_scores, get_threshold_colours, + weight_input_style, ) THRESHOLD_INPUT_STEP = 0.0001 @@ -879,11 +880,12 @@ def store_input_value( @callback( Output(f"{input_id}-input", "value"), + Output(f"{input_id}-input", "style"), Input(f"{table_id}-weight-store", "data"), prevent_initial_call="initial_duplicate", optional=True, ) - def sync_inputs(stored_weights: dict[str, float]) -> float: + def sync_inputs(stored_weights: dict[str, float]) -> tuple[float, dict[str, str]]: """ Sync weight values between the text input and Store. @@ -894,10 +896,11 @@ def sync_inputs(stored_weights: dict[str, float]) -> float: Returns ------- - float - Weight to set text input value. + tuple[float, dict[str, str]] + Weight to set text input value, and its style (greyed when zero). """ - return stored_weights[column] + weight = stored_weights[column] + return weight, weight_input_style(weight) def register_normalization_callbacks( diff --git a/ml_peg/app/utils/utils.py b/ml_peg/app/utils/utils.py index 98e9d19f8..9cd167515 100644 --- a/ml_peg/app/utils/utils.py +++ b/ml_peg/app/utils/utils.py @@ -105,6 +105,37 @@ def build_threshold_input_style(border_colour: str) -> dict[str, str]: } +def weight_input_style(value: float | None) -> dict[str, str]: + """ + Build the inline style for a metric weight input. + + A weight of ``0`` excludes the metric from the score. The input stays white + with dark text (it is still editable); only its border switches to a muted + dashed style to signal the column is switched off. + + Parameters + ---------- + value + Current weight value for the input. + + Returns + ------- + dict[str, str] + Inline Dash style dictionary. + """ + style = { + "width": "60px", + "fontSize": "12px", + "padding": "2px 4px", + "border": "1px solid #6c757d", + "borderRadius": "3px", + "textAlign": "center", + } + if value == 0: + style |= {"border": "1px dashed #adb5bd"} + return style + + class FrameworkEntry(TypedDict): """Style and link metadata for benchmark framework attribution badges."""