Add configurable site code labels to geographic map with toggle control and max labels limit based on anomaly score ranking
Browse files
panel_app/kpi_health_check_panel.py
CHANGED
|
@@ -469,6 +469,9 @@ delta_table = pn.widgets.Tabulator(
|
|
| 469 |
height=320, sizing_mode="stretch_width", layout="fit_data_table"
|
| 470 |
)
|
| 471 |
|
|
|
|
|
|
|
|
|
|
| 472 |
site_select = pn.widgets.AutocompleteInput(
|
| 473 |
name="Select a site (Type to search)",
|
| 474 |
options={},
|
|
@@ -707,6 +710,31 @@ def _build_map_fig(df_map: pd.DataFrame) -> go.Figure | None:
|
|
| 707 |
hover_data=hover_cols,
|
| 708 |
custom_data=["site_code"],
|
| 709 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 710 |
fig.update_layout(
|
| 711 |
mapbox_style="open-street-map",
|
| 712 |
margin=dict(l=10, r=10, t=10, b=10),
|
|
@@ -3042,6 +3070,9 @@ kpi_compare_select.param.watch(_on_drilldown_change, "value")
|
|
| 3042 |
kpi_compare_norm.param.watch(_on_drilldown_change, "value")
|
| 3043 |
corr_window_select.param.watch(_on_drilldown_change, "value")
|
| 3044 |
|
|
|
|
|
|
|
|
|
|
| 3045 |
analysis_range.param.watch(_on_drilldown_params_change, "value")
|
| 3046 |
baseline_days.param.watch(_on_drilldown_params_change, "value")
|
| 3047 |
recent_days.param.watch(_on_drilldown_params_change, "value")
|
|
@@ -3349,6 +3380,7 @@ _tab_delta = pn.Column(
|
|
| 3349 |
_tab_map = pn.Column(
|
| 3350 |
pn.pane.Markdown("## Map"),
|
| 3351 |
map_message,
|
|
|
|
| 3352 |
pn.Column(map_pane, sizing_mode="stretch_both", min_height=700),
|
| 3353 |
sizing_mode="stretch_both",
|
| 3354 |
)
|
|
|
|
| 469 |
height=320, sizing_mode="stretch_width", layout="fit_data_table"
|
| 470 |
)
|
| 471 |
|
| 472 |
+
map_show_site_codes = pn.widgets.Checkbox(name="Show site codes", value=True)
|
| 473 |
+
map_max_labels = pn.widgets.IntInput(name="Max labels", value=200, step=50)
|
| 474 |
+
|
| 475 |
site_select = pn.widgets.AutocompleteInput(
|
| 476 |
name="Select a site (Type to search)",
|
| 477 |
options={},
|
|
|
|
| 710 |
hover_data=hover_cols,
|
| 711 |
custom_data=["site_code"],
|
| 712 |
)
|
| 713 |
+
|
| 714 |
+
try:
|
| 715 |
+
if bool(map_show_site_codes.value):
|
| 716 |
+
max_labels = int(_coerce_int(map_max_labels.value) or 0)
|
| 717 |
+
if max_labels <= 0:
|
| 718 |
+
tmp["_label"] = ""
|
| 719 |
+
elif len(tmp) <= max_labels:
|
| 720 |
+
tmp["_label"] = tmp["site_code"].astype(str)
|
| 721 |
+
else:
|
| 722 |
+
top_idx = (
|
| 723 |
+
tmp.sort_values(by=["_score"], ascending=False)
|
| 724 |
+
.head(max_labels)
|
| 725 |
+
.index
|
| 726 |
+
)
|
| 727 |
+
tmp["_label"] = ""
|
| 728 |
+
tmp.loc[top_idx, "_label"] = tmp.loc[top_idx, "site_code"].astype(str)
|
| 729 |
+
|
| 730 |
+
fig.update_traces(
|
| 731 |
+
mode="markers+text",
|
| 732 |
+
text=tmp["_label"],
|
| 733 |
+
textposition="middle center",
|
| 734 |
+
textfont=dict(color="white", size=10),
|
| 735 |
+
)
|
| 736 |
+
except Exception: # noqa: BLE001
|
| 737 |
+
pass
|
| 738 |
fig.update_layout(
|
| 739 |
mapbox_style="open-street-map",
|
| 740 |
margin=dict(l=10, r=10, t=10, b=10),
|
|
|
|
| 3070 |
kpi_compare_norm.param.watch(_on_drilldown_change, "value")
|
| 3071 |
corr_window_select.param.watch(_on_drilldown_change, "value")
|
| 3072 |
|
| 3073 |
+
map_show_site_codes.param.watch(lambda e: _refresh_map_view(), "value")
|
| 3074 |
+
map_max_labels.param.watch(lambda e: _refresh_map_view(), "value")
|
| 3075 |
+
|
| 3076 |
analysis_range.param.watch(_on_drilldown_params_change, "value")
|
| 3077 |
baseline_days.param.watch(_on_drilldown_params_change, "value")
|
| 3078 |
recent_days.param.watch(_on_drilldown_params_change, "value")
|
|
|
|
| 3380 |
_tab_map = pn.Column(
|
| 3381 |
pn.pane.Markdown("## Map"),
|
| 3382 |
map_message,
|
| 3383 |
+
pn.Row(map_show_site_codes, map_max_labels),
|
| 3384 |
pn.Column(map_pane, sizing_mode="stretch_both", min_height=700),
|
| 3385 |
sizing_mode="stretch_both",
|
| 3386 |
)
|