feat: drug switching network graph tab (Task C.4)
This commit is contained in:
@@ -342,6 +342,31 @@ def _render_scatter(app_state, title):
|
||||
return create_duration_cost_scatter_figure(data, title)
|
||||
|
||||
|
||||
def _render_network(app_state, title):
|
||||
"""Build the drug co-occurrence network graph from current filter state."""
|
||||
from dash_app.data.queries import get_drug_network
|
||||
from visualization.plotly_generator import create_drug_network_figure
|
||||
|
||||
filter_id = (app_state or {}).get("date_filter_id", "all_6mo")
|
||||
chart_type = (app_state or {}).get("chart_type", "directory")
|
||||
|
||||
selected_dirs = (app_state or {}).get("selected_directorates") or []
|
||||
selected_trusts = (app_state or {}).get("selected_trusts") or []
|
||||
directory = selected_dirs[0] if len(selected_dirs) == 1 else None
|
||||
trust = selected_trusts[0] if len(selected_trusts) == 1 else None
|
||||
|
||||
try:
|
||||
data = get_drug_network(filter_id, chart_type, directory, trust)
|
||||
except Exception:
|
||||
log.exception("Failed to load drug network data")
|
||||
return _empty_figure("Failed to load drug network data.")
|
||||
|
||||
if not data.get("nodes"):
|
||||
return _empty_figure("No drug network data available.\nTry adjusting your filters.")
|
||||
|
||||
return create_drug_network_figure(data, title)
|
||||
|
||||
|
||||
def register_chart_callbacks(app):
|
||||
"""Register tab switching, pathway data loading, and chart rendering callbacks."""
|
||||
|
||||
@@ -491,6 +516,9 @@ def register_chart_callbacks(app):
|
||||
elif active_tab == "scatter":
|
||||
fig = _render_scatter(app_state, title)
|
||||
|
||||
elif active_tab == "network":
|
||||
fig = _render_network(app_state, title)
|
||||
|
||||
else:
|
||||
# Placeholder for charts not yet implemented
|
||||
tab_label = dict(TAB_DEFINITIONS).get(active_tab, active_tab)
|
||||
|
||||
@@ -11,6 +11,7 @@ TAB_DEFINITIONS = [
|
||||
("funnel", "Funnel"),
|
||||
("depth", "Depth"),
|
||||
("scatter", "Scatter"),
|
||||
("network", "Network"),
|
||||
]
|
||||
|
||||
# Full set retained for Trust Comparison dashboard (Phase 10.8)
|
||||
|
||||
@@ -27,6 +27,7 @@ from data_processing.pathway_queries import (
|
||||
get_retention_funnel as _get_retention_funnel,
|
||||
get_pathway_depth_distribution as _get_pathway_depth_distribution,
|
||||
get_duration_cost_scatter as _get_duration_cost_scatter,
|
||||
get_drug_network as _get_drug_network,
|
||||
)
|
||||
|
||||
DB_PATH = Path(__file__).resolve().parents[2] / "data" / "pathways.db"
|
||||
@@ -216,3 +217,13 @@ def get_duration_cost_scatter(
|
||||
) -> list[dict]:
|
||||
"""Drug-level avg_days and cost_pp_pa for scatter plot."""
|
||||
return _get_duration_cost_scatter(DB_PATH, date_filter_id, chart_type, directory, trust)
|
||||
|
||||
|
||||
def get_drug_network(
|
||||
date_filter_id: str = "all_6mo",
|
||||
chart_type: str = "directory",
|
||||
directory: Optional[str] = None,
|
||||
trust: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""Undirected drug co-occurrence network for network graph."""
|
||||
return _get_drug_network(DB_PATH, date_filter_id, chart_type, directory, trust)
|
||||
|
||||
Reference in New Issue
Block a user