Skip to content
Open
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
10 changes: 2 additions & 8 deletions ml_peg/app/utils/build_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
calculate_column_widths,
get_framework_config,
get_threshold_colours,
weight_input_style,
)


Expand Down Expand Up @@ -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),
)
)

Expand Down
11 changes: 7 additions & 4 deletions ml_peg/app/utils/register_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
format_tooltip_headers,
get_scores,
get_threshold_colours,
weight_input_style,
)

THRESHOLD_INPUT_STEP = 0.0001
Expand Down Expand Up @@ -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.

Expand All @@ -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(
Expand Down
31 changes: 31 additions & 0 deletions ml_peg/app/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
Loading