Skip to content

Commit f089e93

Browse files
committed
refactor: combine comparison toolbar into simulation toolbar
1 parent dfddf42 commit f089e93

3 files changed

Lines changed: 76 additions & 118 deletions

File tree

src/e3sm_compareview/app.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ def _build_ui(self, **_):
276276
reset_camera=self.view_manager.reset_camera,
277277
)
278278
toolbars.SimulationControls()
279-
toolbars.ComparisonMode()
280279
toolbars.Cropping()
281280
toolbars.DataSelection()
282281
toolbars.Animation()
@@ -614,7 +613,11 @@ async def _import_state(self, state_content):
614613
# Update layout
615614
self.state.aspect_ratio = state_content["layout"]["aspect-ratio"]
616615
self.state.active_layout = state_content["layout"]["active"]
617-
self.state.active_tools = state_content["layout"]["tools"]
616+
self.state.active_tools = [
617+
tool
618+
for tool in state_content["layout"]["tools"]
619+
if tool != "comparison-controls"
620+
]
618621
self.state.compact_drawer = not state_content["layout"]["help"]
619622

620623
# Update filebrowser state
@@ -664,7 +667,12 @@ async def data_loading_open(self, simulation_files, connectivity):
664667
*(
665668
tool
666669
for tool in s.active_tools
667-
if tool not in {"load-data", "select-simulations"}
670+
if tool
671+
not in {
672+
"load-data",
673+
"select-simulations",
674+
"comparison-controls",
675+
}
668676
),
669677
]
670678
s.active_tools = list(dict.fromkeys(next_tools))

src/e3sm_compareview/components/toolbars.py

Lines changed: 65 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from e3sm_compareview.comparison import (
99
COMPARISON_TYPES,
10-
COMPARISON_TYPE_LABELS,
1110
MULTI_SIM_COMPARISON_LABELS,
1211
TWO_SIM_COLUMN_LABELS,
1312
)
@@ -18,7 +17,6 @@
1817
DENSITY = {
1918
"adjust-layout": "compact",
2019
"simulation-controls": "compact",
21-
"comparison-controls": "compact",
2220
"adjust-databounds": "default",
2321
"select-slice-time": "default",
2422
"animation-controls": "compact",
@@ -29,25 +27,6 @@
2927
"classes": "border-b-thin",
3028
}
3129

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-
5130
def to_kwargs(value):
5231
return {
5332
"v_show": js.is_active(value),
@@ -202,91 +181,6 @@ def _sync_crop_lat_inputs(self, crop_latitude, **_):
202181
self.state.crop_latitude_max = crop_latitude[1]
203182

204183

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-
290184
class SimulationControls(v3.VToolbar):
291185
def __init__(self):
292186
super().__init__(**to_kwargs("simulation-controls"))
@@ -330,6 +224,71 @@ def __init__(self):
330224
)
331225

332226
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+
333292
with v3.VSelect(
334293
v_model=("control_simulation_file", ""),
335294
items=("simulation_configs", []),
@@ -380,8 +339,6 @@ def __init__(self):
380339
variant="outlined",
381340
)
382341

383-
v3.VSpacer()
384-
385342
v3.VBtn(
386343
"Organize simulation collection",
387344
v_if="comparison_mode === 'multi-sim'",

src/e3sm_compareview/components/tools.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def __init__(self, reset_camera=None, toggle_toolbar=None):
114114
"adjust-layout",
115115
"select-slice-time",
116116
"simulation-controls",
117-
"comparison-controls",
118117
],
119118
),
120119
):
@@ -137,12 +136,6 @@ def __init__(self, reset_camera=None, toggle_toolbar=None):
137136
icon="mdi-database-cog-outline",
138137
value="simulation-controls",
139138
)
140-
qv_tools.ToggleButton(
141-
compact="compact_drawer",
142-
title="Comparison mode",
143-
icon="mdi-compare-horizontal",
144-
value="comparison-controls",
145-
)
146139

147140
v3.VDivider(classes="my-1")
148141

0 commit comments

Comments
 (0)