Repository navigation
Expand file tree
/
Copy pathstyle.py
More file actions
388 lines (350 loc) · 12.7 KB
/
Copy pathstyle.py
File metadata and controls
388 lines (350 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
"""
style.py — Design tokens and HTML builders
Light theme matching the AP Hub Google Sheets mockup:
- White page background
- Navy (#001E62) section banner bars
- Sky blue (#56C0E9) sidebar accents and expand links
- #DAEeF6 alternating row tint
- Light gray sidebar (#F4F6FB)
"""
import streamlit as st
# ---------------------------------------------------------------------------
# Color tokens
# ---------------------------------------------------------------------------
COLORS = {
"navy": "#001E62", # primary brand / section banners
"navy_2": "#002d8a", # heatmap rank 1
"sky": "#56C0E9", # sidebar pills, expand links, hover
"orange": "#F9A21A", # accent / mock data badge
"white": "#FFFFFF",
"g0": "#F4F6FB", # sidebar background
"g1": "#F8F9FB", # subtle off-white
"g2": "#EDEEF2", # card borders / dividers
"g4": "#8A8FA2", # secondary text / sub-labels
"g5": "#3D4259", # primary body text
"row_alt": "#EAEAEA", # alternating row tint (light grey)
"green": "#1A9E5B",
"red": "#D63B3B",
}
# ---------------------------------------------------------------------------
# Heatmap coloring (rank-based, light-theme aware)
# ---------------------------------------------------------------------------
def heatmap_color(rank: int, n: int) -> str:
"""
Linear interpolation from #B3C4ED (rank 1, best) → #EAEAEA (rank N, worst).
All fills are light enough that dark text is always readable.
"""
t = (rank - 1) / max(n - 1, 1)
r = int(0xB3 + t * (0xEA - 0xB3))
g = int(0xC4 + t * (0xEA - 0xC4))
b = int(0xED + t * (0xEA - 0xED))
return f"#{r:02X}{g:02X}{b:02X}"
def text_color(rank: int) -> str:
# All fills are light — always use dark text
return "#3D4259"
# ---------------------------------------------------------------------------
# Global CSS
# ---------------------------------------------------------------------------
def inject_global_css() -> None:
st.markdown("""
<style>
@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700&family=DM+Sans:wght@400;500;600&family=JetBrains+Mono:wght@500&display=swap');
/* ── Force light theme — override system dark mode ────────── */
:root {
color-scheme: light only !important;
}
@media (prefers-color-scheme: dark) {
html, body, [data-testid="stAppViewContainer"],
[data-testid="stHeader"], [data-testid="stSidebar"],
.main, [class*="css"] {
background-color: #FFFFFF !important;
color: #3D4259 !important;
}
}
/* ── Base ─────────────────────────────────────────────────── */
html, body, [class*="css"] {
font-family: 'DM Sans', sans-serif;
color: #3D4259;
background-color: #FFFFFF;
}
.main .block-container {
background: #FFFFFF;
padding-top: 1.25rem;
padding-bottom: 3rem;
max-width: 1100px !important;
padding-left: 2rem !important;
padding-right: 2rem !important;
}
h1, h2, h3 {
font-family: 'Barlow Condensed', sans-serif;
font-weight: 700;
color: #001E62;
letter-spacing: 0.01em;
}
/* ── Sidebar — light ──────────────────────────────────────── */
section[data-testid="stSidebar"] {
background: #F4F6FB;
border-right: 1.5px solid #EDEEF2;
}
section[data-testid="stSidebar"] .stSelectbox label {
color: #001E62 !important;
font-family: 'Barlow Condensed', sans-serif;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
/* ── Domain section banners ───────────────────────────────── */
.domain-banner {
background: #001E62;
color: #ffffff;
font-family: 'Barlow Condensed', sans-serif;
font-size: 17px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
padding: 9px 14px;
margin-bottom: 10px;
border-radius: 4px;
}
/* ── Subheader labels ─────────────────────────────────────── */
.sub-label {
font-family: 'Barlow Condensed', sans-serif;
font-size: 13px;
font-weight: 700;
color: #8A8FA2;
letter-spacing: 0.07em;
text-transform: uppercase;
margin-bottom: 6px;
margin-top: 14px;
}
/* ── Heatmap table ────────────────────────────────────────── */
table.heatmap {
width: 100%;
border-collapse: collapse;
font-family: 'DM Sans', sans-serif;
font-size: 13px;
}
table.heatmap th {
background: #001E62;
color: #ffffff;
font-family: 'Barlow Condensed', sans-serif;
font-weight: 600;
font-size: 12px;
letter-spacing: 0.05em;
text-transform: uppercase;
padding: 7px 10px;
text-align: left;
}
table.heatmap td {
padding: 6px 10px;
border-bottom: 1px solid #EDEEF2;
background: #FFFFFF;
}
table.heatmap tr:nth-child(even) td {
background: #F4F6FB;
}
table.heatmap tr:last-child td {
border-bottom: none;
}
table.heatmap tr:hover td {
font-weight: 700 !important;
}
/* ── Hotlist (student) table ──────────────────────────────── */
table.hotlist {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
table.hotlist th {
background: #F4F6FB;
color: #8A8FA2;
font-family: 'JetBrains Mono', monospace;
font-size: 11px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.06em;
padding: 6px 8px;
border-bottom: 1.5px solid #EDEEF2;
text-align: left;
}
table.hotlist td {
padding: 6px 8px;
border-bottom: 1px solid #EDEEF2;
font-family: 'DM Sans', sans-serif;
background: #FFFFFF;
}
table.hotlist tr:nth-child(even) td {
background: #EAEAEA;
}
table.hotlist td.mono {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
}
/* ── Expander — styled as blue expand links ───────────────── */
[data-testid="stExpander"] {
border: none !important;
border-top: 1px solid #EDEEF2 !important;
background: transparent !important;
box-shadow: none !important;
}
[data-testid="stExpander"] summary {
color: #56C0E9 !important;
font-style: italic;
font-family: 'DM Sans', sans-serif;
font-size: 13px;
padding: 6px 2px;
}
[data-testid="stExpander"] summary:hover {
color: #002d8a !important;
}
[data-testid="stExpander"] summary svg {
fill: #56C0E9 !important;
}
/* ── Metric value display ─────────────────────────────────── */
.metric-value {
font-family: 'Barlow Condensed', sans-serif;
font-weight: 700;
font-size: 28px;
color: #001E62;
line-height: 1.1;
}
.metric-label {
font-family: 'DM Sans', sans-serif;
font-size: 11px;
font-weight: 500;
color: #8A8FA2;
text-transform: uppercase;
letter-spacing: 0.07em;
}
/* ── Alert badges ─────────────────────────────────────────── */
.badge-alert {
display: inline-block;
background: #FFF0F0;
color: #D63B3B;
font-family: 'JetBrains Mono', monospace;
font-size: 11px;
font-weight: 500;
border-radius: 4px;
padding: 3px 8px;
}
.badge-ok {
display: inline-block;
background: #F0FFF6;
color: #1A9E5B;
font-family: 'JetBrains Mono', monospace;
font-size: 11px;
font-weight: 500;
border-radius: 4px;
padding: 3px 8px;
}
/* ── Sidebar jump-to link pills ───────────────────────────── */
.jump-link {
display: block;
color: #001E62;
font-family: 'DM Sans', sans-serif;
font-size: 13px;
font-weight: 500;
padding: 5px 10px;
border-radius: 4px;
text-decoration: none;
margin-bottom: 2px;
transition: background 0.15s;
}
.jump-link:hover {
background: #DAEeF6;
color: #001E62;
text-decoration: none;
}
/* ── Hide Streamlit chrome ────────────────────────────────── */
#MainMenu { visibility: hidden; }
footer { visibility: hidden; }
header { visibility: hidden; }
</style>
""", unsafe_allow_html=True)
# ---------------------------------------------------------------------------
# HTML builders
# ---------------------------------------------------------------------------
def domain_banner(title: str, anchor_id: str) -> str:
"""Full-width navy section header with anchor target."""
return (
f'<div id="{anchor_id}"></div>'
f'<div class="domain-banner">{title}</div>'
)
def sub_label(text: str) -> str:
return f'<div class="sub-label">{text}</div>'
def jump_to_sidebar(sections: list[tuple[str, str]]) -> str:
"""
Render a Jump To nav block for the sidebar.
sections: list of (label, anchor_id)
"""
links = "".join(
f'<a class="jump-link" href="#{anchor}">{label}</a>'
for label, anchor in sections
)
return (
'<div style="margin-bottom:6px;font-family:Barlow Condensed,sans-serif;'
'font-size:11px;font-weight:700;letter-spacing:0.1em;text-transform:uppercase;'
'color:#56C0E9;background:#001E62;padding:4px 10px;border-radius:4px;">'
'Jump To</div>'
+ links
)
def heatmap_table(rows: list[dict], cols: list[dict], rank_col: str = None, n: int = None) -> str:
"""
Generic heatmap HTML table.
cols: list of {"key": str, "label": str, "align": "left"|"right", "mono": bool}
rank_col: key whose int value drives background color
n: total row count for rank color scale
"""
header_cells = "".join(
f'<th style="text-align:{c.get("align","left")}">{c["label"]}</th>'
for c in cols
)
body_rows = []
for i, row in enumerate(rows):
rank = int(row.get(rank_col, 999)) if rank_col else None
row_bg = COLORS["row_alt"] if i % 2 == 1 else COLORS["white"]
cells = []
for c in cols:
val = row.get(c["key"], "")
align = c.get("align", "left")
mono_cls = ' class="mono"' if c.get("mono") else ""
if rank_col and c["key"] != cols[0]["key"] and rank is not None and n is not None:
bg = heatmap_color(rank, n)
fg = text_color(rank)
cells.append(
f'<td{mono_cls} style="text-align:{align};background:{bg};'
f'color:{fg};font-weight:600">{val}</td>'
)
else:
cells.append(
f'<td{mono_cls} style="text-align:{align};background:{row_bg}">{val}</td>'
)
body_rows.append(f'<tr>{"".join(cells)}</tr>')
return (
'<table class="heatmap">'
f'<thead><tr>{header_cells}</tr></thead>'
f'<tbody>{"".join(body_rows)}</tbody>'
'</table>'
)
def hotlist_table(rows: list[dict], cols: list[dict]) -> str:
"""Generic student-level hotlist table."""
header_cells = "".join(
f'<th style="text-align:{c.get("align","left")}">{c["label"]}</th>'
for c in cols
)
body_rows = []
for row in rows:
cells = []
for c in cols:
val = row.get(c["key"], "")
align = c.get("align", "left")
mono_cls = ' class="mono"' if c.get("mono") else ""
cells.append(f'<td{mono_cls} style="text-align:{align}">{val}</td>')
body_rows.append(f'<tr>{"".join(cells)}</tr>')
return (
'<table class="hotlist">'
f'<thead><tr>{header_cells}</tr></thead>'
f'<tbody>{"".join(body_rows)}</tbody>'
'</table>'
)