|
7 | 7 |
|
8 | 8 | from e3sm_compareview.comparison import ( |
9 | 9 | COMPARISON_TYPES, |
10 | | - COMPARISON_TYPE_LABELS, |
11 | 10 | MULTI_SIM_COMPARISON_LABELS, |
12 | 11 | TWO_SIM_COLUMN_LABELS, |
13 | 12 | ) |
|
18 | 17 | DENSITY = { |
19 | 18 | "adjust-layout": "compact", |
20 | 19 | "simulation-controls": "compact", |
21 | | - "comparison-controls": "compact", |
22 | 20 | "adjust-databounds": "default", |
23 | 21 | "select-slice-time": "default", |
24 | 22 | "animation-controls": "compact", |
|
29 | 27 | "classes": "border-b-thin", |
30 | 28 | } |
31 | 29 |
|
32 | | -COMPARISON_TYPE_TOOLTIPS = { |
33 | | - "source": "Source values (no comparison)", |
34 | | - "diff": "Difference: comparison - control", |
35 | | - "comp1": "Relative difference w.r.t. control: (comparison - control) / control", |
36 | | - "comp2": ( |
37 | | - "Relative difference w.r.t. mean: " |
38 | | - "2 * (comparison - control) / (comparison + control)" |
39 | | - ), |
40 | | -} |
41 | | - |
42 | | -COLUMN_TOOLTIPS = { |
43 | | - "ctrl": "Control simulation values", |
44 | | - "test": "Test simulation values", |
45 | | - "diff": "Difference: test - control", |
46 | | - "comp1": "Relative difference w.r.t. control: (test - control) / control", |
47 | | - "comp2": "Relative difference w.r.t. mean: 2 * (test - control) / (test + control)", |
48 | | -} |
49 | | - |
50 | | - |
51 | 30 | def to_kwargs(value): |
52 | 31 | return { |
53 | 32 | "v_show": js.is_active(value), |
@@ -202,91 +181,6 @@ def _sync_crop_lat_inputs(self, crop_latitude, **_): |
202 | 181 | self.state.crop_latitude_max = crop_latitude[1] |
203 | 182 |
|
204 | 183 |
|
205 | | -class ComparisonMode(v3.VToolbar): |
206 | | - def __init__(self): |
207 | | - super().__init__(**to_kwargs("comparison-controls")) |
208 | | - |
209 | | - with self: |
210 | | - v3.VIcon("mdi-compare-horizontal", classes="pl-6 opacity-50") |
211 | | - with v3.Template(v_if="comparison_mode === 'multi-sim'"): |
212 | | - v3.VLabel("Comparison", classes="text-subtitle-2 px-4") |
213 | | - for comparison_type in COMPARISON_TYPES: |
214 | | - with v3.VTooltip( |
215 | | - text=COMPARISON_TYPE_TOOLTIPS.get( |
216 | | - comparison_type, |
217 | | - MULTI_SIM_COMPARISON_LABELS.get( |
218 | | - comparison_type, comparison_type.upper() |
219 | | - ), |
220 | | - ), |
221 | | - ): |
222 | | - with v3.Template(v_slot_activator="{ props }"): |
223 | | - v3.VBtn( |
224 | | - MULTI_SIM_COMPARISON_LABELS.get( |
225 | | - comparison_type, comparison_type.upper() |
226 | | - ), |
227 | | - v_bind="props", |
228 | | - size="small", |
229 | | - variant="outlined", |
230 | | - color=( |
231 | | - f"comparison_type === '{comparison_type}' ? 'primary' : 'default'", |
232 | | - ), |
233 | | - classes=( |
234 | | - f"`mx-1 text-none ${{comparison_type === '{comparison_type}' ? '' : 'text-medium-emphasis'}}`", |
235 | | - ), |
236 | | - click=f"comparison_type = '{comparison_type}'", |
237 | | - ) |
238 | | - v3.VSpacer() |
239 | | - with v3.VTooltip(): |
240 | | - with v3.Template(v_slot_activator="{ props }"): |
241 | | - v3.VLabel( |
242 | | - "{{ Math.max(0, simulation_configs.filter(sim => sim.path !== control_simulation_file && sim.include).length) }} comparisons", |
243 | | - v_bind="props", |
244 | | - classes="text-caption mr-4", |
245 | | - ) |
246 | | - html.Div( |
247 | | - "{{ (() => { const included = simulation_configs.filter(sim => sim.path === control_simulation_file || sim.include); if (!included.length) return 'Included simulations:\\nnone'; return `Included simulations:\\n${included.map(sim => `${sim.label || sim.path.split('/').pop()}${sim.path === control_simulation_file ? ' (ctrl)' : ''}`).join('\\n')}`; })() }}", |
248 | | - style="white-space: pre-line;", |
249 | | - ) |
250 | | - |
251 | | - with v3.Template(v_else=True): |
252 | | - v3.VLabel("Columns", classes="text-subtitle-2 px-4") |
253 | | - for comp_type in ["ctrl", "test", "diff", "comp1", "comp2"]: |
254 | | - with v3.VTooltip( |
255 | | - text=COLUMN_TOOLTIPS.get( |
256 | | - comp_type, |
257 | | - COMPARISON_TYPE_LABELS.get(comp_type, comp_type.upper()), |
258 | | - ), |
259 | | - ): |
260 | | - with v3.Template(v_slot_activator="{ props }"): |
261 | | - v3.VBtn( |
262 | | - TWO_SIM_COLUMN_LABELS[comp_type], |
263 | | - v_bind="props", |
264 | | - size="small", |
265 | | - variant="outlined", |
266 | | - color=( |
267 | | - "selected_columns.includes('{0}') ? 'primary' : 'default'".format( |
268 | | - comp_type |
269 | | - ), |
270 | | - ), |
271 | | - classes=( |
272 | | - f"`mx-1 text-none ${{selected_columns.includes('{comp_type}') ? '' : 'text-medium-emphasis'}}`", |
273 | | - ), |
274 | | - click=( |
275 | | - f"selected_columns.includes('{comp_type}') ? " |
276 | | - f"selected_columns = selected_columns.filter(c => c !== '{comp_type}') : " |
277 | | - f"selected_columns = [...selected_columns, '{comp_type}']" |
278 | | - ), |
279 | | - ) |
280 | | - v3.VSpacer() |
281 | | - v3.VBtn( |
282 | | - "Show all", |
283 | | - size="small", |
284 | | - variant="text", |
285 | | - classes="mr-2 text-none", |
286 | | - click="selected_columns = ['ctrl', 'test', 'diff', 'comp1', 'comp2']", |
287 | | - ) |
288 | | - |
289 | | - |
290 | 184 | class SimulationControls(v3.VToolbar): |
291 | 185 | def __init__(self): |
292 | 186 | super().__init__(**to_kwargs("simulation-controls")) |
@@ -330,6 +224,71 @@ def __init__(self): |
330 | 224 | ) |
331 | 225 |
|
332 | 226 | v3.VDivider(vertical=True, classes="mx-2") |
| 227 | + with v3.VSelect( |
| 228 | + v_if="comparison_mode === 'multi-sim'", |
| 229 | + v_model=("comparison_type", "diff"), |
| 230 | + items=( |
| 231 | + [ |
| 232 | + { |
| 233 | + "title": MULTI_SIM_COMPARISON_LABELS[comparison_type], |
| 234 | + "value": comparison_type, |
| 235 | + } |
| 236 | + for comparison_type in COMPARISON_TYPES |
| 237 | + ], |
| 238 | + ), |
| 239 | + item_title="title", |
| 240 | + item_value="value", |
| 241 | + label="Comparison type", |
| 242 | + chips=True, |
| 243 | + density="compact", |
| 244 | + variant="solo", |
| 245 | + hide_details=True, |
| 246 | + classes="mx-1", |
| 247 | + style="min-width: 14rem; max-width: 18rem;", |
| 248 | + ): |
| 249 | + with v3.Template(v_slot_selection="{ item }"): |
| 250 | + with html.Div(classes="d-flex align-center py-1"): |
| 251 | + v3.VChip( |
| 252 | + "{{ item.raw.title }}", |
| 253 | + size="small", |
| 254 | + color="primary", |
| 255 | + variant="outlined", |
| 256 | + ) |
| 257 | + with v3.VSelect( |
| 258 | + v_else=True, |
| 259 | + v_model=("selected_columns", ["ctrl", "test", "diff", "comp1", "comp2"]), |
| 260 | + items=( |
| 261 | + [ |
| 262 | + { |
| 263 | + "title": TWO_SIM_COLUMN_LABELS[column], |
| 264 | + "value": column, |
| 265 | + } |
| 266 | + for column in ["ctrl", "test", "diff", "comp1", "comp2"] |
| 267 | + ], |
| 268 | + ), |
| 269 | + item_title="title", |
| 270 | + item_value="value", |
| 271 | + label="Comparison columns", |
| 272 | + multiple=True, |
| 273 | + density="compact", |
| 274 | + variant="solo", |
| 275 | + hide_details=True, |
| 276 | + classes="mx-1", |
| 277 | + style="min-width: 0; max-width: 19rem;", |
| 278 | + ): |
| 279 | + with v3.Template(v_slot_selection="{ item, index }"): |
| 280 | + with html.Div( |
| 281 | + v_if="index === 0", |
| 282 | + classes="d-flex align-center flex-nowrap w-100 overflow-hidden pt-1", |
| 283 | + style="max-width: 100%;", |
| 284 | + ): |
| 285 | + html.Div( |
| 286 | + "{{ selected_columns.length === 1 ? item.raw.title : `${selected_columns.length} selected` }}", |
| 287 | + classes="text-body-2 text-truncate", |
| 288 | + ) |
| 289 | + |
| 290 | + v3.VSpacer() |
| 291 | + |
333 | 292 | with v3.VSelect( |
334 | 293 | v_model=("control_simulation_file", ""), |
335 | 294 | items=("simulation_configs", []), |
@@ -380,8 +339,6 @@ def __init__(self): |
380 | 339 | variant="outlined", |
381 | 340 | ) |
382 | 341 |
|
383 | | - v3.VSpacer() |
384 | | - |
385 | 342 | v3.VBtn( |
386 | 343 | "Organize simulation collection", |
387 | 344 | v_if="comparison_mode === 'multi-sim'", |
|
0 commit comments