Skip to content

Commit

Permalink
Split settings groups in RftPlotter (#1180)
Browse files Browse the repository at this point in the history
* Split selections into plot_type and ensembles

* Renames Selections to Ensembles

* removed print

* Removed len > 0 to check if lists are not empty

Co-authored-by: Øyvind Lind-Johansen <[email protected]>
  • Loading branch information
lindjoha and Øyvind Lind-Johansen authored Dec 5, 2022
1 parent 0ce2456 commit 0bc4814
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, datamodel: RftPlotterDataModel) -> None:
self._well_names = datamodel.well_names

def layout(self) -> List[Component]:
ensemble = self._ensembles[0] if len(self._ensembles) > 0 else None
well = self._well_names[0] if len(self._well_names) > 0 else None
ensemble = self._ensembles[0] if self._ensembles else None
well = self._well_names[0] if self._well_names else None
dates_in_well = self._datamodel.date_in_well(well) if well is not None else []
return [
wcc.Dropdown(
Expand All @@ -49,7 +49,7 @@ def layout(self) -> List[Component]:
id=self.register_component_unique_id(self.Ids.DATE),
options=[{"label": date, "value": date} for date in dates_in_well],
clearable=False,
value=dates_in_well[0] if len(dates_in_well) > 0 else None,
value=dates_in_well[0] if dates_in_well else None,
),
wcc.RadioItems(
label="Plot simulations as",
Expand Down Expand Up @@ -154,7 +154,7 @@ def _update_date(
well: str, current_date: str
) -> Tuple[List[Dict[str, str]], Optional[str]]:
dates = self._datamodel.date_in_well(well)
first_date = dates[0] if len(dates) > 0 else None
first_date = dates[0] if dates else None
available_dates = [{"label": date, "value": date} for date in dates]
date = current_date if current_date in dates else first_date
return available_dates, date
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def layout(self) -> List[Component]:
label="Ensembles",
id=self.register_component_unique_id(self.Ids.ENSEMBLES),
options=[{"label": ens, "value": ens} for ens in self._ensembles],
value=[self._ensembles[0] if len(self._ensembles) > 0 else None],
value=[self._ensembles[0] if self._ensembles else None],
clearable=False,
multi=True,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def _update_selections_from_clickdata(

clickdata = corr_vector_clickdata.get("points", [{}])[0].get("y")
ls_clickdata = clickdata.split()
print("click dat ais: ", ls_clickdata)
return ls_clickdata[0]

@callback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from ._selections import PlotType, Selections
from ._ensembles import Ensembles
from ._plot_type import PlotType, PlotTypeSettings
from ._size_color_settings import SizeColorSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List

import webviz_core_components as wcc
from dash.development.base_component import Component
from webviz_config.utils import StrEnum
from webviz_config.webviz_plugin_subclasses import SettingsGroupABC


class Ensembles(SettingsGroupABC):
class Ids(StrEnum):
ENSEMBLES = "ensembles"

def __init__(self, ensembles: List[str]) -> None:
super().__init__("Ensembles")
self._ensembles = ensembles

def layout(self) -> List[Component]:
return [
wcc.Dropdown(
id=self.register_component_unique_id(self.Ids.ENSEMBLES),
options=[{"label": ens, "value": ens} for ens in self._ensembles],
value=[self._ensembles[0] if self._ensembles else None],
clearable=False,
multi=True,
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ class PlotType(StrEnum):
ERROR_BOXPLOT = "error-boxplot"


class Selections(SettingsGroupABC):
class PlotTypeSettings(SettingsGroupABC):
class Ids(StrEnum):
PLOT_TYPE = "plot-type"
ENSEMBLES = "ensembles"

def __init__(self, ensembles: List[str]) -> None:
super().__init__("Selections")
self._ensembles = ensembles
def __init__(self) -> None:
super().__init__("Plot Type")

def layout(self) -> List[Component]:
return [
wcc.RadioItems(
label="Plot Type",
id=self.register_component_unique_id(self.Ids.PLOT_TYPE),
options=[
{
Expand All @@ -37,12 +34,4 @@ def layout(self) -> List[Component]:
],
value=PlotType.CROSSPLOT,
),
wcc.Dropdown(
label="Ensembles",
id=self.register_component_unique_id(self.Ids.ENSEMBLES),
options=[{"label": ens, "value": ens} for ens in self._ensembles],
value=[self._ensembles[0] if len(self._ensembles) > 0 else None],
clearable=False,
multi=True,
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from ..._reusable_view_element import GeneralViewElement
from ..._types import ColorAndSizeByType
from ..._utils import RftPlotterDataModel, filter_frame
from ._settings import PlotType, Selections, SizeColorSettings
from ._settings import Ensembles, PlotType, PlotTypeSettings, SizeColorSettings
from ._utils import update_crossplot, update_errorplot


class SimVsObsView(ViewABC):
class Ids(StrEnum):
SELECTIONS = "selections"
PLOT_TYPE = "plot-type"
ENSEMBLES = "ensembles"
FILTERS = "filters"
SIZE_COLOR_SETTINGS = "size-color-settings"
VIEW_ELEMENT = "view-element"
Expand All @@ -26,7 +27,8 @@ def __init__(self, datamodel: RftPlotterDataModel) -> None:

self.add_settings_groups(
{
self.Ids.SELECTIONS: Selections(self._datamodel.ensembles),
self.Ids.PLOT_TYPE: PlotTypeSettings(),
self.Ids.ENSEMBLES: Ensembles(self._datamodel.ensembles),
self.Ids.FILTERS: FilterLayout(
wells=self._datamodel.well_names,
zones=self._datamodel.zone_names,
Expand All @@ -47,14 +49,14 @@ def set_callbacks(self) -> None:
"children",
),
Input(
self.settings_group(self.Ids.SELECTIONS)
.component_unique_id(Selections.Ids.PLOT_TYPE)
self.settings_group(self.Ids.PLOT_TYPE)
.component_unique_id(PlotTypeSettings.Ids.PLOT_TYPE)
.to_string(),
"value",
),
Input(
self.settings_group(self.Ids.SELECTIONS)
.component_unique_id(Selections.Ids.ENSEMBLES)
self.settings_group(self.Ids.ENSEMBLES)
.component_unique_id(Ensembles.Ids.ENSEMBLES)
.to_string(),
"value",
),
Expand Down

0 comments on commit 0bc4814

Please sign in to comment.