Make dashboard usable on mobile
Move inline styles into assets/style.css with wrapping KPI and chart rows, a horizontally scrolling tab bar, and phone breakpoints. Shared components put chart titles in HTML headings, legends above plots, and disable drag-to-zoom so swiping scrolls the page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X9jG4CUFcH6n4vFvgtwndY
This commit is contained in:
parent
8916d10b63
commit
eb489a782d
9 changed files with 319 additions and 196 deletions
|
|
@ -6,6 +6,16 @@ from dash import html, dcc, Input, Output, dash_table
|
|||
import plotly.express as px
|
||||
import plotly.graph_objects as go
|
||||
|
||||
from admin_analytics.dashboard.components import (
|
||||
GRAPH_CONFIG,
|
||||
graph,
|
||||
graph_style,
|
||||
kpi_card,
|
||||
kpi_row,
|
||||
chart_row,
|
||||
no_data,
|
||||
style_figure,
|
||||
)
|
||||
from admin_analytics.dashboard.queries import (
|
||||
query_top_earners,
|
||||
query_comp_by_role,
|
||||
|
|
@ -15,33 +25,12 @@ from admin_analytics.dashboard.queries import (
|
|||
query_aggregate_comp_cagr,
|
||||
)
|
||||
|
||||
_NO_DATA = html.Div(
|
||||
"No IRS 990 data loaded. Run: admin-analytics ingest irs990",
|
||||
style={"textAlign": "center", "padding": "40px", "color": "#888"},
|
||||
)
|
||||
_NO_DATA = no_data("No IRS 990 data loaded. Run: admin-analytics ingest irs990")
|
||||
|
||||
# Roles to highlight in trend chart
|
||||
_KEY_ROLES = ["PRESIDENT", "PROVOST", "VP_FINANCE", "VP_RESEARCH", "VP_ADVANCEMENT", "CFO"]
|
||||
|
||||
|
||||
def _kpi_card(title: str, value: str, subtitle: str = "") -> html.Div:
|
||||
return html.Div(
|
||||
[
|
||||
html.H4(title, style={"margin": "0", "color": "#666", "fontSize": "14px"}),
|
||||
html.H2(value, style={"margin": "5px 0", "color": "#00539F"}),
|
||||
html.P(subtitle, style={"margin": "0", "color": "#999", "fontSize": "12px"}),
|
||||
],
|
||||
style={
|
||||
"flex": "1",
|
||||
"padding": "20px",
|
||||
"backgroundColor": "#f8f9fa",
|
||||
"borderRadius": "8px",
|
||||
"textAlign": "center",
|
||||
"margin": "0 8px",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def layout(conn: duckdb.DuckDBPyConnection):
|
||||
all_earners = query_top_earners(conn)
|
||||
if all_earners.height == 0:
|
||||
|
|
@ -57,28 +46,28 @@ def layout(conn: duckdb.DuckDBPyConnection):
|
|||
agg_cagr = query_aggregate_comp_cagr(conn)
|
||||
kpi_cards = []
|
||||
if cagr:
|
||||
kpi_cards.append(_kpi_card(
|
||||
kpi_cards.append(kpi_card(
|
||||
"President Compensation",
|
||||
f"${cagr['end_comp']:,}",
|
||||
f"Tax year {cagr['end_year']}",
|
||||
))
|
||||
kpi_cards.append(_kpi_card(
|
||||
kpi_cards.append(kpi_card(
|
||||
"President CAGR",
|
||||
f"{cagr['cagr_pct']}%",
|
||||
f"Annualized growth, {cagr['start_year']}-{cagr['end_year']}",
|
||||
))
|
||||
if agg_cagr:
|
||||
kpi_cards.append(_kpi_card(
|
||||
kpi_cards.append(kpi_card(
|
||||
"Top-10 Total Compensation",
|
||||
f"${agg_cagr['end_comp']:,}",
|
||||
f"Tax year {agg_cagr['end_year']}",
|
||||
))
|
||||
kpi_cards.append(_kpi_card(
|
||||
kpi_cards.append(kpi_card(
|
||||
"Top-10 CAGR",
|
||||
f"{agg_cagr['cagr_pct']}%",
|
||||
f"Annualized growth, {agg_cagr['start_year']}-{agg_cagr['end_year']}",
|
||||
))
|
||||
kpi_row = html.Div(kpi_cards, style={"display": "flex", "marginBottom": "24px"}) if kpi_cards else html.Div()
|
||||
kpis = kpi_row(kpi_cards) if kpi_cards else html.Div()
|
||||
|
||||
# Compensation by role trend
|
||||
role_df = query_comp_by_role(conn)
|
||||
|
|
@ -127,7 +116,7 @@ def layout(conn: duckdb.DuckDBPyConnection):
|
|||
)
|
||||
|
||||
return html.Div([
|
||||
kpi_row,
|
||||
kpis,
|
||||
html.Div(
|
||||
[
|
||||
html.Label("Filter by Tax Year: ", style={"fontWeight": "bold"}),
|
||||
|
|
@ -135,10 +124,10 @@ def layout(conn: duckdb.DuckDBPyConnection):
|
|||
id="comp-year-dropdown",
|
||||
options=year_options,
|
||||
value="all",
|
||||
style={"width": "200px", "display": "inline-block"},
|
||||
clearable=False,
|
||||
),
|
||||
],
|
||||
style={"marginBottom": "16px"},
|
||||
className="filter-bar",
|
||||
),
|
||||
dash_table.DataTable(
|
||||
id="comp-table",
|
||||
|
|
@ -162,14 +151,17 @@ def layout(conn: duckdb.DuckDBPyConnection):
|
|||
style_cell={"textAlign": "left", "padding": "8px", "fontSize": "13px"},
|
||||
style_header={"fontWeight": "bold", "backgroundColor": "#f0f0f0"},
|
||||
),
|
||||
html.Div(
|
||||
[
|
||||
html.Div(dcc.Graph(id="comp-breakdown-chart", config={"displaylogo": False}), style={"flex": "1"}),
|
||||
html.Div(dcc.Graph(figure=cpi_fig, config={"displaylogo": False}), style={"flex": "1"}),
|
||||
],
|
||||
style={"display": "flex", "gap": "16px", "marginTop": "16px"},
|
||||
chart_row(
|
||||
html.Div(
|
||||
[
|
||||
html.H3(id="comp-breakdown-title", className="chart-title"),
|
||||
dcc.Graph(id="comp-breakdown-chart", config=GRAPH_CONFIG, style=graph_style(380)),
|
||||
],
|
||||
className="chart",
|
||||
),
|
||||
graph(cpi_fig),
|
||||
),
|
||||
dcc.Graph(figure=role_fig, config={"displaylogo": False}),
|
||||
graph(role_fig),
|
||||
])
|
||||
|
||||
|
||||
|
|
@ -177,7 +169,11 @@ def register_callbacks(app: dash.Dash, conn: duckdb.DuckDBPyConnection) -> None:
|
|||
"""Register interactive callbacks for the compensation page."""
|
||||
|
||||
@app.callback(
|
||||
[Output("comp-table", "data"), Output("comp-breakdown-chart", "figure")],
|
||||
[
|
||||
Output("comp-table", "data"),
|
||||
Output("comp-breakdown-chart", "figure"),
|
||||
Output("comp-breakdown-title", "children"),
|
||||
],
|
||||
Input("comp-year-dropdown", "value"),
|
||||
)
|
||||
def update_compensation(year_value):
|
||||
|
|
@ -218,9 +214,9 @@ def register_callbacks(app: dash.Dash, conn: duckdb.DuckDBPyConnection) -> None:
|
|||
|
||||
title_suffix = f" ({year})" if year else " (All Years)"
|
||||
breakdown_fig.update_layout(
|
||||
title=f"Compensation Breakdown — Top 10{title_suffix}",
|
||||
xaxis_title="", yaxis_title="$",
|
||||
template="plotly_white", height=380,
|
||||
)
|
||||
style_figure(breakdown_fig)
|
||||
|
||||
return table_data, breakdown_fig
|
||||
return table_data, breakdown_fig, f"Compensation Breakdown — Top 10{title_suffix}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue