|
17 | 17 | from dashboard.components import create_controls |
18 | 18 | from dashboard.constants import DEFAULT_LAST_N, DEFAULT_LOAD_N_CHARTS |
19 | 19 | from dashboard.data import get_data |
| 20 | +from monsterui.all import Modal, ModalTitle |
20 | 21 |
|
21 | 22 |
|
22 | 23 | def get_batch_data(batch_name: str) -> pd.DataFrame: |
@@ -123,27 +124,137 @@ def get(batch_name: str, chart_index: int): |
123 | 124 | fig = ChartManager.create_chart(df_metric, chart_index) |
124 | 125 | app.state.chart_cache[batch_name][chart_index] = fig |
125 | 126 |
|
126 | | - return Card( |
127 | | - Style( |
| 127 | + modal_id = f"modal-{batch_name}-{chart_index}" |
| 128 | + |
| 129 | + return Div( |
| 130 | + Card( |
| 131 | + Style( |
| 132 | + """ |
| 133 | + .uk-card-header { padding: 1rem; } |
| 134 | + .uk-card-body { padding: 1rem; } |
| 135 | + .chart-card-container { position: relative; } |
| 136 | + .chart-expand-btn { |
| 137 | + position: absolute; |
| 138 | + top: 0.75rem; |
| 139 | + right: 0.75rem; |
| 140 | + z-index: 20; |
| 141 | + background: rgba(255, 255, 255, 0.95); |
| 142 | + border: 1px solid #e5e7eb; |
| 143 | + border-radius: 0.375rem; |
| 144 | + padding: 0.375rem; |
| 145 | + cursor: pointer; |
| 146 | + transition: all 0.2s; |
| 147 | + display: flex; |
| 148 | + align-items: center; |
| 149 | + justify-content: center; |
| 150 | + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); |
| 151 | + min-width: 44px; |
| 152 | + min-height: 44px; |
| 153 | + } |
| 154 | + .chart-expand-btn:hover { |
| 155 | + background: rgba(255, 255, 255, 1); |
| 156 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); |
| 157 | + transform: scale(1.05); |
| 158 | + } |
| 159 | + /* Mobile optimizations */ |
| 160 | + @media (max-width: 768px) { |
| 161 | + .chart-expand-btn { |
| 162 | + top: 0.5rem; |
| 163 | + right: 0.5rem; |
| 164 | + min-width: 48px; |
| 165 | + min-height: 48px; |
| 166 | + padding: 0.5rem; |
| 167 | + } |
| 168 | + } |
| 169 | + .dark .chart-expand-btn { |
| 170 | + background: rgba(17, 24, 39, 0.95); |
| 171 | + border-color: #374151; |
| 172 | + color: #e5e7eb; |
| 173 | + } |
| 174 | + .dark .chart-expand-btn:hover { |
| 175 | + background: rgba(17, 24, 39, 1); |
| 176 | + } |
128 | 177 | """ |
129 | | - .uk-card-header { padding: 1rem; } |
130 | | - .uk-card-body { padding: 1rem; } |
131 | | - """ |
132 | | - ), |
133 | | - Safe(app.state.chart_cache[batch_name][chart_index]), |
134 | | - header=Div( |
135 | | - H4(metric_name, cls="mb-1"), |
136 | | - DivLAligned( |
137 | | - P( |
138 | | - f"Anomaly Rate: {anomaly_rate:.1%}", |
139 | | - cls="text-sm text-muted-foreground", |
| 178 | + ), |
| 179 | + Safe(app.state.chart_cache[batch_name][chart_index]), |
| 180 | + # Expand button overlay positioned on entire card |
| 181 | + Button( |
| 182 | + UkIcon("expand", height=16, width=16), |
| 183 | + cls="chart-expand-btn", |
| 184 | + uk_toggle=f"target: #{modal_id}", |
| 185 | + title="Click to expand chart", |
| 186 | + type="button" |
| 187 | + ), |
| 188 | + header=Div( |
| 189 | + H4(metric_name, cls="mb-1"), |
| 190 | + DivLAligned( |
| 191 | + P( |
| 192 | + f"Anomaly Rate: {anomaly_rate:.1%}", |
| 193 | + cls="text-sm text-muted-foreground", |
| 194 | + ), |
| 195 | + P(f"Avg Score: {avg_score:.1%}", cls="text-sm text-muted-foreground"), |
| 196 | + style="gap: 1rem;", |
140 | 197 | ), |
141 | | - P(f"Avg Score: {avg_score:.1%}", cls="text-sm text-muted-foreground"), |
142 | | - style="gap: 1rem;", |
143 | 198 | ), |
| 199 | + id=f"chart-{chart_index}", |
| 200 | + cls="mb-1 chart-card-container", |
144 | 201 | ), |
145 | | - id=f"chart-{chart_index}", |
146 | | - cls="mb-1", |
| 202 | + # Modal for expanded chart view |
| 203 | + Modal( |
| 204 | + ModalTitle(f"{metric_name} - Expanded View"), |
| 205 | + Div( |
| 206 | + # Expanded chart will be loaded here |
| 207 | + Div( |
| 208 | + id=f"expanded-chart-{chart_index}", |
| 209 | + hx_get=f"/batch/{batch_name}/chart/{chart_index}/expanded", |
| 210 | + hx_trigger="load", |
| 211 | + cls="min-h-96" |
| 212 | + ), |
| 213 | + # Chart statistics |
| 214 | + Div( |
| 215 | + DivLAligned( |
| 216 | + P( |
| 217 | + f"Anomaly Rate: {anomaly_rate:.1%}", |
| 218 | + cls="text-sm text-muted-foreground", |
| 219 | + ), |
| 220 | + P(f"Avg Score: {avg_score:.1%}", cls="text-sm text-muted-foreground"), |
| 221 | + style="gap: 1rem;", |
| 222 | + ), |
| 223 | + cls="mt-4 p-4 bg-muted rounded-lg" |
| 224 | + ), |
| 225 | + cls="space-y-4" |
| 226 | + ), |
| 227 | + id=modal_id, |
| 228 | + cls="uk-modal-full" |
| 229 | + ) |
| 230 | + ) |
| 231 | + |
| 232 | + |
| 233 | +@rt("/batch/{batch_name}/chart/{chart_index}/expanded") |
| 234 | +def get_expanded_chart(batch_name: str, chart_index: int): |
| 235 | + """Get expanded chart for modal display. |
| 236 | +
|
| 237 | + Args: |
| 238 | + batch_name (str): The name of the batch. |
| 239 | + chart_index (int): The index of the chart. |
| 240 | +
|
| 241 | + Returns: |
| 242 | + Div: The expanded chart. |
| 243 | + """ |
| 244 | + df = app.state.df_cache[batch_name] |
| 245 | + metric_stats = app.state.stats_cache[batch_name] |
| 246 | + metric_name = metric_stats[chart_index]["metric_name"] |
| 247 | + |
| 248 | + # Generate expanded chart (larger and with more interactive features) |
| 249 | + df_metric = df[df["metric_name"] == metric_name] |
| 250 | + df_metric = extract_metadata(df_metric, "anomaly_explanation") |
| 251 | + |
| 252 | + # Create expanded chart with enhanced configuration |
| 253 | + expanded_fig = ChartManager.create_expanded_chart(df_metric, chart_index) |
| 254 | + |
| 255 | + return Div( |
| 256 | + Safe(expanded_fig), |
| 257 | + cls="w-full" |
147 | 258 | ) |
148 | 259 |
|
149 | 260 |
|
|
0 commit comments