Skip to content

Commit d246de8

Browse files
committed
Move general plot options to sidebar
1 parent 2a34262 commit d246de8

9 files changed

Lines changed: 238 additions & 178 deletions

File tree

src/ert/gui/plotting/customization_dialog/default_customization_view.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import TYPE_CHECKING, override
22

3-
from ert.gui.utils import is_everest_application
4-
53
from .customization_view import CustomizationView, WidgetProperty
64

75
if TYPE_CHECKING:
@@ -24,10 +22,6 @@ class DefaultCustomizationView(CustomizationView):
2422
title = WidgetProperty()
2523
x_label = WidgetProperty()
2624
y_label = WidgetProperty()
27-
legend = WidgetProperty()
28-
grid = WidgetProperty()
29-
history = WidgetProperty()
30-
observations = WidgetProperty()
3125

3226
def __init__(self) -> None:
3327
CustomizationView.__init__(self)
@@ -51,30 +45,13 @@ def __init__(self) -> None:
5145
f"The label of the y-axis. {_label_msg('label')}",
5246
placeholder="y-label",
5347
)
54-
self.add_spacing()
55-
self.add_check_box("legend", "Legend", "Toggle legend visibility.")
56-
self.add_check_box("grid", "Grid", "Toggle grid visibility.")
57-
58-
self.is_everest = is_everest_application()
59-
if not self.is_everest:
60-
self.add_check_box("history", "History", "Toggle history visibility.")
61-
self.add_check_box(
62-
"observations", "Observations", "Toggle observations visibility."
63-
)
6448

6549
@override
6650
def apply_customization(self, plot_config: "PlotConfig") -> None:
6751
plot_config.set_title(self.title)
68-
6952
plot_config.set_x_label(self.x_label)
7053
plot_config.set_y_label(self.y_label)
7154

72-
plot_config.set_legend_enabled(self.legend)
73-
plot_config.set_grid_enabled(self.grid)
74-
if not self.is_everest:
75-
plot_config.set_history_enabled(self.history)
76-
plot_config.set_observations_enabled(self.observations)
77-
7855
@override
7956
def revert_customization(self, plot_config: "PlotConfig") -> None:
8057
if not plot_config.is_unnamed():
@@ -84,9 +61,3 @@ def revert_customization(self, plot_config: "PlotConfig") -> None:
8461

8562
self.x_label = plot_config.x_label()
8663
self.y_label = plot_config.y_label()
87-
88-
self.legend = plot_config.is_legend_enabled()
89-
self.grid = plot_config.is_grid_enabled()
90-
if not self.is_everest:
91-
self.history = plot_config.is_history_enabled()
92-
self.observations = plot_config.is_observations_enabled()

src/ert/gui/plotting/plot_window.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
)
2727

2828
from ert.config import BreakthroughConfig
29+
from ert.config.distribution import ConstSettings
2930
from ert.config.field import Field
31+
from ert.config.gen_kw_config import GenKwConfig
3032
from ert.dark_storage.common import get_storage_api_version
3133
from ert.gui.ertwidgets import CopyButton, showWaitCursorWhileWaiting
3234
from ert.gui.plotting.ert_plots import (
@@ -58,7 +60,11 @@
5860
from .utils.qt_creator import create_group_box, create_group_layout, create_side_panel
5961
from .widgets.data_type_keys_widget import DataTypeKeysWidget
6062
from .widgets.everest_control_selection_widget import EverestControlSelectionWidget
61-
from .widgets.plot_controls import EverestControlsPlotOptions, MisfitsOptions
63+
from .widgets.plot_controls import (
64+
EverestControlsPlotOptions,
65+
GeneralOptions,
66+
MisfitsOptions,
67+
)
6268
from .widgets.plot_ensemble_selection_widget import EnsembleSelectionWidget
6369
from .widgets.plot_widget import Plotter, PlotWidget
6470

@@ -324,12 +330,17 @@ def __init__(
324330
self.updatePlot
325331
)
326332

333+
self._general_options = GeneralOptions(
334+
self.updatePlot,
335+
is_everest=self.is_everest,
336+
)
327337
self._misfits_options = MisfitsOptions(self.updatePlot)
328338

329339
right_container = QWidget()
330340
right_layout = create_group_layout(
331341
[
332342
self._ensemble_group,
343+
self._general_options.get_widget(),
333344
self._everest_controls_plot_options.get_widget(),
334345
self._everest_controls_group,
335346
self._misfits_options.get_widget(),
@@ -355,6 +366,32 @@ def __init__(
355366
if self.getSelectedKey() is None:
356367
self._show_no_data_message()
357368

369+
def _sync_log_scale_option(
370+
self,
371+
selected_tab: str,
372+
log_scale_valid_values: bool,
373+
key_def: PlotApiKeyDefinition | None = None,
374+
) -> None:
375+
if (
376+
selected_tab
377+
in {
378+
HISTOGRAM,
379+
DISTRIBUTION,
380+
GAUSSIAN_KDE,
381+
}
382+
and log_scale_valid_values
383+
):
384+
if key_def is not None:
385+
a = key_def.parameter
386+
if isinstance(a, GenKwConfig) and isinstance(
387+
a.distribution, ConstSettings
388+
):
389+
self._general_options.set_log_visible(False)
390+
return
391+
self._general_options.set_log_visible(True)
392+
else:
393+
self._general_options.set_log_visible(False)
394+
358395
def _show_no_data_message(self) -> None:
359396
current_widget = self._central_tab.currentWidget()
360397
if not isinstance(current_widget, PlotWidget):
@@ -549,6 +586,16 @@ def fetch_data(
549586
plot_config = PlotConfig.create_copy(
550587
self._plot_customizer.get_plot_config()
551588
)
589+
plot_config.set_legend_enabled(self._general_options.legend_checkbox_state)
590+
plot_config.set_grid_enabled(self._general_options.grid_checkbox_state)
591+
if not self.is_everest:
592+
plot_config.set_history_enabled(
593+
self._general_options.history_checkbox_state
594+
)
595+
plot_config.set_observations_enabled(
596+
self._general_options.observations_checkbox_state
597+
)
598+
552599
plot_context = PlotContext(
553600
plot_config,
554601
selected_ensembles,
@@ -563,6 +610,14 @@ def fetch_data(
563610
plot_context.scatter_plot = self._misfits_options.scatter_checkbox_state
564611
plot_context.box_plot = self._misfits_options.box_checkbox_state
565612
plot_context.mean = self._misfits_options.mean_checkbox_state
613+
self._sync_log_scale_option(selected_tab, log_scale_valid_values, key_def)
614+
615+
plot_context.log_scale = (
616+
self._general_options.is_log_visible()
617+
and self._general_options.log_checkbox_state
618+
and log_scale_valid_values
619+
)
620+
566621
plot_context.outliers = self._misfits_options.outliers_checkbox_state
567622

568623
# Check if key is a history key.
@@ -650,7 +705,6 @@ def addPlotWidget(
650705
plot_widget = PlotWidget(name, plotter)
651706
plot_widget.customizationTriggered.connect(self.toggleCustomizeDialog)
652707
plot_widget.layerIndexChanged.connect(self.layerIndexChanged)
653-
plot_widget.plotUpdateRequested.connect(self.updatePlot)
654708

655709
index = self._central_tab.addTab(plot_widget, name)
656710
self._plot_widgets.append(plot_widget)

src/ert/gui/plotting/utils/plot_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def legend_items(self) -> list[Any]:
179179
def legend_labels(self) -> list[str]:
180180
return self._legend_labels
181181

182-
def set_x_label(self, label: str) -> None:
182+
def set_x_label(self, label: str | None) -> None:
183183
self._x_label = label
184184

185-
def set_y_label(self, label: str) -> None:
185+
def set_y_label(self, label: str | None) -> None:
186186
self._y_label = label
187187

188188
def set_observations_enabled(self, enabled: bool) -> None:

src/ert/gui/plotting/utils/plot_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ def plot_type(self) -> PlotType | None:
134134
def plot_type(self, value: PlotType) -> None:
135135
self._plot_type = value
136136

137-
def setXLabel(self, value: str) -> None:
137+
def setXLabel(self, value: str | None) -> None:
138138
self._plot_config.set_x_label(value)
139139

140-
def setYLabel(self, value: str) -> None:
140+
def setYLabel(self, value: str | None) -> None:
141141
self._plot_config.set_y_label(value)
142142

143143
@property
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from .everest_controls_plot_options import EverestControlsPlotOptions
2+
from .general_options import GeneralOptions
23
from .misfits_options import MisfitsOptions
34

45
__all__ = [
56
"EverestControlsPlotOptions",
7+
"GeneralOptions",
68
"MisfitsOptions",
79
]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import logging
2+
from collections.abc import Callable
3+
4+
from PyQt6.QtWidgets import (
5+
QCheckBox,
6+
QGroupBox,
7+
QWidget,
8+
)
9+
10+
from ert.gui.plotting.utils.qt_creator import create_group_box, create_group_layout
11+
12+
logger = logging.getLogger(__name__)
13+
14+
15+
class GeneralOptions:
16+
def __init__(
17+
self, connection_point: Callable[..., object], *, is_everest: bool
18+
) -> None:
19+
def refresh_plot(_state: int) -> None:
20+
connection_point()
21+
22+
self._toggle_legend = QCheckBox("Legend")
23+
self._toggle_legend.setChecked(True)
24+
self._toggle_legend.stateChanged.connect(refresh_plot)
25+
26+
self._toggle_grid = QCheckBox("Grid")
27+
self._toggle_grid.setChecked(True)
28+
self._toggle_grid.stateChanged.connect(refresh_plot)
29+
30+
self._toggle_history = QCheckBox("History")
31+
self._toggle_history.setChecked(True)
32+
self._toggle_history.stateChanged.connect(refresh_plot)
33+
34+
self._toggle_observations = QCheckBox("Observations")
35+
self._toggle_observations.setChecked(True)
36+
self._toggle_observations.stateChanged.connect(refresh_plot)
37+
38+
self._toggle_log_scale = QCheckBox("Log scale")
39+
self._toggle_log_scale.setObjectName("log_scale_checkbox")
40+
self._toggle_log_scale.setChecked(False)
41+
self._toggle_log_scale.setVisible(False)
42+
43+
def _on_log_scale_toggled(_state: int) -> None:
44+
logger.info("Plot sidebar option used: 'Log scale'")
45+
self._toggle_log_scale.stateChanged.disconnect(_on_log_scale_toggled)
46+
self._toggle_log_scale.stateChanged.connect(refresh_plot)
47+
connection_point()
48+
49+
self._toggle_log_scale.stateChanged.connect(_on_log_scale_toggled)
50+
51+
widgets: list[QWidget] = [
52+
self._toggle_legend,
53+
self._toggle_grid,
54+
self._toggle_log_scale,
55+
]
56+
if not is_everest:
57+
widgets.extend(
58+
[
59+
self._toggle_history,
60+
self._toggle_observations,
61+
]
62+
)
63+
64+
self._general_options = create_group_box(
65+
"General options",
66+
create_group_layout(widgets),
67+
)
68+
69+
def get_widget(self) -> QGroupBox:
70+
return self._general_options
71+
72+
@property
73+
def legend_checkbox_state(self) -> bool:
74+
return self._toggle_legend.isChecked()
75+
76+
@property
77+
def grid_checkbox_state(self) -> bool:
78+
return self._toggle_grid.isChecked()
79+
80+
@property
81+
def history_checkbox_state(self) -> bool:
82+
return self._toggle_history.isChecked()
83+
84+
@property
85+
def observations_checkbox_state(self) -> bool:
86+
return self._toggle_observations.isChecked()
87+
88+
@property
89+
def log_checkbox_state(self) -> bool:
90+
return self._toggle_log_scale.isChecked()
91+
92+
def set_log_visible(self, visible: bool) -> None:
93+
self._toggle_log_scale.setVisible(visible)
94+
95+
def is_log_visible(self) -> bool:
96+
return self._toggle_log_scale.isVisible()

0 commit comments

Comments
 (0)