Skip to content

Commit

Permalink
Improve handling of update button n_clicks (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikNevjenNR authored Dec 22, 2023
1 parent 5091834 commit b866dc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
16 changes: 6 additions & 10 deletions webviz_subsurface/plugins/_co2_leakage/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(
raise

self._summed_co2: Dict[str, Any] = {}
self._visualization_threshold = -1.0
self._visualization_info = {"threshold": -1.0, "n_clicks": 0}
self._color_tables = co2leakage_color_tables()
self.add_shared_settings_group(
ViewSettings(
Expand Down Expand Up @@ -357,10 +357,6 @@ def make_unit_list(
Output(self._view_component(MapViewElement.Ids.DECKGL_MAP), "layers"),
Output(self._view_component(MapViewElement.Ids.DECKGL_MAP), "children"),
Output(self._view_component(MapViewElement.Ids.DECKGL_MAP), "views"),
Output(
self._settings_component(ViewSettings.Ids.VISUALIZATION_UPDATE),
"n_clicks",
),
Input(self._settings_component(ViewSettings.Ids.PROPERTY), "value"),
Input(self._view_component(MapViewElement.Ids.DATE_SLIDER), "value"),
Input(self._settings_component(ViewSettings.Ids.FORMATION), "value"),
Expand Down Expand Up @@ -405,7 +401,7 @@ def update_map_attribute(
selected_wells: List[str],
ensemble: str,
current_views: List[Any],
) -> Tuple[List[Dict[Any, Any]], List[Any], Dict[Any, Any], int]:
) -> Tuple[List[Dict[Any, Any]], List[Any], Dict[Any, Any]]:
attribute = MapAttribute(attribute)
if len(realization) == 0 or ensemble is None:
raise PreventUpdate
Expand All @@ -420,10 +416,10 @@ def update_map_attribute(
}
# Unable to clear cache (when needed) without the protected member
# pylint: disable=protected-access
self._visualization_threshold = process_visualization_info(
self._visualization_info = process_visualization_info(
visualization_update,
visualization_threshold,
self._visualization_threshold,
self._visualization_info,
self._surface_server._image_cache,
)
# Surface
Expand All @@ -447,7 +443,7 @@ def update_map_attribute(
),
color_map_name=color_map_name,
readable_name_=readable_name(attribute),
visualization_threshold=self._visualization_threshold,
visualization_threshold=self._visualization_info["threshold"],
map_attribute_names=self._map_attribute_names,
)
surf_data, self._summed_co2 = process_summed_mass(
Expand Down Expand Up @@ -493,7 +489,7 @@ def update_map_attribute(
attribute=attribute,
)
viewports = no_update if current_views else create_map_viewports()
return layers, annotations, viewports, 0
return layers, annotations, viewports

@callback(
Output(ViewSettings.Ids.OPTIONS_DIALOG, "open"),
Expand Down
12 changes: 6 additions & 6 deletions webviz_subsurface/plugins/_co2_leakage/_utilities/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,21 @@ def _parse_polygon_file(filename: str) -> Dict[str, Any]:
def process_visualization_info(
n_clicks: int,
threshold: Optional[float],
stored_threshold: float,
stored_info: Dict[str, Union[float, int]],
cache: Cache,
) -> float:
) -> Dict[str, Union[float, int]]:
if threshold is None:
print("Visualization threshold must be a number.")
return stored_threshold
if n_clicks > 0 and threshold != stored_threshold:
return stored_info
if n_clicks != stored_info["n_clicks"] and threshold != stored_info["threshold"]:
# Clear surface cache if the threshold for visualization is changed
print(
"Clearing cache because the visualization threshold was changed\n"
"Re-select realization(s) to update the current map"
)
cache.clear()
return threshold
return stored_threshold
return {"threshold": threshold, "n_clicks": n_clicks}
return stored_info


def process_zone_info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def __init__(
dcc.Input(
id=visualization_threshold_id,
type="number",
value=-1,
value=-1.0,
style={"width": "70%"},
),
html.Div(style={"width": "5%"}),
Expand Down

0 comments on commit b866dc6

Please sign in to comment.