Skip to content

Commit

Permalink
Remove use of wcc.ColorScales (equinor#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv authored Dec 3, 2024
1 parent aa84f0a commit 2af9699
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ def ray_pick(
i_ref = reference(0)
j_ref = reference(0)
k_ref = reference(0)
grid.ComputeCellStructuredCoords(cell_id, i_ref, j_ref, k_ref, True) # type: ignore[arg-type]
grid.ComputeCellStructuredCoords(
cell_id, i_ref, j_ref, k_ref, True # type: ignore[arg-type]
)

cell_property_val: Optional[np.ndarray] = None
if property_spec:
Expand Down
32 changes: 6 additions & 26 deletions webviz_subsurface/plugins/_segy_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(

self.zunit = zunit
self.segyfiles: List[str] = [str(segy) for segy in segyfiles]
self.initial_colors = (
self.colors = (
colors
if colors
else [
Expand All @@ -68,7 +68,6 @@ def __init__(
]
)
self.init_state = self.update_state(self.segyfiles[0])
self.init_state.get("colorscale", self.initial_colors)
self.init_state.get("uirevision", str(uuid4()))

self.plotly_theme = webviz_settings.theme.plotly_theme
Expand All @@ -86,7 +85,6 @@ def update_state(self, cubepath: str, **kwargs: Any) -> Dict[str, Any]:
"color_min_value": float(f"{round(cube.values.min(), 2):2f}"),
"color_max_value": float(f"{round(cube.values.max(), 2):2f}"),
"uirevision": str(uuid4()),
"colorscale": self.initial_colors,
}
if kwargs:
for key, value in kwargs.items():
Expand Down Expand Up @@ -121,10 +119,6 @@ def tour_steps(self) -> List[dict]:
"id": self.uuid("zslice"),
"content": "Selected zslice for the seismic cube.",
},
{
"id": self.uuid("color-scale"),
"content": "Click this button to change colorscale",
},
{
"id": self.uuid("color-values"),
"content": "Drag either node of slider to truncate color ranges.",
Expand Down Expand Up @@ -160,18 +154,6 @@ def settings_layout(self) -> wcc.FlexBox:
clearable=False,
),
),
html.Div(
children=[
wcc.Label(
children="Set colorscale",
),
wcc.ColorScales(
id=self.uuid("color-scale"),
colorscale=self.initial_colors,
nSwatches=12,
),
],
),
html.Div(
children=[
wcc.RangeSlider(
Expand All @@ -183,7 +165,8 @@ def settings_layout(self) -> wcc.FlexBox:
self.init_state["min_value"],
self.init_state["max_value"],
],
tooltip={"placement": "bottom"},
marks=None,
tooltip={"placement": "bottom", "always_visible": True},
step=calculate_slider_step(
min_value=self.init_state["min_value"],
max_value=self.init_state["max_value"],
Expand Down Expand Up @@ -257,7 +240,6 @@ def set_callbacks(self, app: Dash) -> None:
Input(self.uuid("xline"), "clickData"),
Input(self.uuid("zslice"), "clickData"),
Input(self.uuid("color-values"), "value"),
Input(self.uuid("color-scale"), "colorscale"),
Input(self.uuid("zoom"), "n_clicks"),
Input(self.uuid("color-reset"), "n_clicks"),
],
Expand All @@ -272,7 +254,6 @@ def _update_state(
xcd: Union[dict, None],
zcd: Union[dict, None],
color_values: List[float],
colorscale: List[float],
_zoom_btn: Union[int, None],
_reset_range_btn: Union[int, None],
zfig: Union[dict, None],
Expand Down Expand Up @@ -311,7 +292,6 @@ def _update_state(
else:
store["color_min_value"] = color_values[0]
store["color_max_value"] = color_values[1]
store["colorscale"] = colorscale
return json.dumps(store)

@app.callback(
Expand Down Expand Up @@ -358,7 +338,7 @@ def _set_zslice(state_data_str: Union[str, None]) -> dict:
reverse_y=False,
zmin=state["color_min_value"],
zmax=state["color_max_value"],
colorscale=state["colorscale"],
colorscale=self.colors,
uirevision=state["uirevision"],
)
fig["layout"]["shapes"] = shapes
Expand Down Expand Up @@ -406,7 +386,7 @@ def _set_iline(state_data_str: Union[str, None]) -> dict:
yaxis_title=self.zunit,
zmin=state["color_min_value"],
zmax=state["color_max_value"],
colorscale=state["colorscale"],
colorscale=self.colors,
uirevision=state["uirevision"],
)
fig["layout"]["shapes"] = shapes
Expand Down Expand Up @@ -451,7 +431,7 @@ def _set_xline(state_data_str: Union[str, None]) -> dict:
yaxis_title=self.zunit,
zmin=state["color_min_value"],
zmax=state["color_max_value"],
colorscale=state["colorscale"],
colorscale=self.colors,
uirevision=state["uirevision"],
)
fig["layout"]["shapes"] = shapes
Expand Down
19 changes: 3 additions & 16 deletions webviz_subsurface/plugins/_surface_with_grid_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
Path(gridfile).stem for gridfile in gridparameterfiles
]
self.plotly_theme = webviz_settings.theme.plotly_theme
self.initial_colors = (
self.colors = (
colors
if colors is not None
else [
Expand Down Expand Up @@ -154,10 +154,6 @@ def tour_steps(self):
"id": self.ids("gridparameter"),
"content": "The visualized grid parameter.",
},
{
"id": self.ids("color-scale"),
"content": ("Click this button to change colorscale"),
},
{
"id": self.ids("color-values"),
"content": ("Drag either node of slider to truncate color ranges"),
Expand Down Expand Up @@ -224,14 +220,6 @@ def layout(self):
value=self.gridparafiles[0],
clearable=False,
),
wcc.Label(
children="Set colorscale",
),
wcc.ColorScales(
id=self.ids("color-scale"),
colorscale=self.initial_colors,
nSwatches=12,
),
wcc.RangeSlider(
label="Set color range",
id=self.ids("color-values"),
Expand Down Expand Up @@ -335,10 +323,9 @@ def _render_surface(
Input(self.ids("gridparameter"), "value"),
Input(self.ids("surface"), "value"),
Input(self.ids("color-values"), "value"),
Input(self.ids("color-scale"), "colorscale"),
],
)
def _render_fence(coords, gridparameter, surfacepath, color_values, colorscale):
def _render_fence(coords, gridparameter, surfacepath, color_values):
if not coords:
raise PreventUpdate
grid = load_grid(get_path(self.gridfile))
Expand Down Expand Up @@ -369,7 +356,7 @@ def _render_fence(coords, gridparameter, surfacepath, color_values, colorscale):
s_arr=s_arr,
theme=self.plotly_theme,
s_name=self.surfacenames[self.surfacefiles.index(surfacepath)],
colorscale=colorscale,
colorscale=self.colors,
xmin=hmin,
xmax=hmax,
ymin=vmin,
Expand Down
19 changes: 3 additions & 16 deletions webviz_subsurface/plugins/_surface_with_seismic_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
else:
self.segynames = [Path(segyfile).stem for segyfile in segyfiles]
self.plotly_theme = webviz_settings.theme.plotly_theme
self.initial_colors = (
self.colors = (
colors
if colors is not None
else [
Expand Down Expand Up @@ -148,10 +148,6 @@ def tour_steps(self):
"id": self.ids("cube"),
"content": "The visualized cube.",
},
{
"id": self.ids("color-scale"),
"content": ("Click this button to change colorscale"),
},
{
"id": self.ids("color-values"),
"content": ("Drag either node of slider to truncate color ranges"),
Expand Down Expand Up @@ -216,14 +212,6 @@ def layout(self):
value=self.segyfiles[0],
clearable=False,
),
wcc.Label(
children="Set colorscale",
),
wcc.ColorScales(
id=self.ids("color-scale"),
colorscale=self.initial_colors,
nSwatches=12,
),
wcc.RangeSlider(
label="Set color range",
id=self.ids("color-values"),
Expand Down Expand Up @@ -320,10 +308,9 @@ def _render_surface(
Input(self.ids("cube"), "value"),
Input(self.ids("surface"), "value"),
Input(self.ids("color-values"), "value"),
Input(self.ids("color-scale"), "colorscale"),
],
)
def _render_fence(coords, cubepath, surfacepath, color_values, colorscale):
def _render_fence(coords, cubepath, surfacepath, color_values):
if not coords:
raise PreventUpdate
cube = load_cube_data(get_path(cubepath))
Expand All @@ -337,7 +324,7 @@ def _render_fence(coords, cubepath, surfacepath, color_values, colorscale):
s_arr=s_arr,
theme=self.plotly_theme,
s_name=self.surfacenames[self.surfacefiles.index(surfacepath)],
colorscale=colorscale,
colorscale=self.colors,
xmin=hmin,
xmax=hmax,
ymin=vmin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Optional
from typing import Callable, List, Optional

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -32,7 +32,7 @@

# pylint: disable=too-many-statements
def distribution_controllers(
get_uuid: Callable, volumemodel: InplaceVolumesModel
get_uuid: Callable, volumemodel: InplaceVolumesModel, colors: List[str]
) -> None:
@callback(
Output({"id": get_uuid("main-voldist"), "page": "custom"}, "children"),
Expand Down Expand Up @@ -105,18 +105,18 @@ def _update_page_custom(selections: dict, page_selected: str) -> tuple:
nbins=selections["hist_bins"],
facet_col=selections["Subplots"],
color=selections["Color by"],
color_discrete_sequence=selections["Colorscale"],
color_continuous_scale=selections["Colorscale"],
color_discrete_map=FLUID_COLORS
if selections["Color by"] == "FLUID_ZONE"
else None,
color_discrete_sequence=colors,
color_continuous_scale=colors,
color_discrete_map=(
FLUID_COLORS if selections["Color by"] == "FLUID_ZONE" else None
),
barmode=selections["barmode"],
boxmode=selections["barmode"],
text_auto=get_text_format_bar_plot(
selected_data, selections, volumemodel
)
if selections["Plot type"] == "bar"
else False,
text_auto=(
get_text_format_bar_plot(selected_data, selections, volumemodel)
if selections["Plot type"] == "bar"
else False
),
layout={
"title": (
{
Expand Down Expand Up @@ -151,18 +151,22 @@ def _update_page_custom(selections: dict, page_selected: str) -> tuple:

return custom_plotting_layout(
figure=figure,
tables=make_tables(
dframe=dframe,
responses=list({selections["X Response"], selections["Y Response"]}),
groups=groups,
volumemodel=volumemodel,
page_selected=page_selected,
selections=selections,
table_type="Statistics table",
view_height=37,
)
if selections["bottom_viz"] == "table"
else None,
tables=(
make_tables(
dframe=dframe,
responses=list(
{selections["X Response"], selections["Y Response"]}
),
groups=groups,
volumemodel=volumemodel,
page_selected=page_selected,
selections=selections,
table_type="Statistics table",
view_height=37,
)
if selections["bottom_viz"] == "table"
else None
),
)

@callback(
Expand Down Expand Up @@ -233,7 +237,7 @@ def _update_page_per_zr(selections: dict, page_selected: str) -> list:
data_frame=dframe,
values=selections["X Response"],
names=selector,
color_discrete_sequence=selections["Colorscale"],
color_discrete_sequence=colors,
color=selector,
)
.update_traces(marker_line={"color": "#000000", "width": 1})
Expand All @@ -250,7 +254,7 @@ def _update_page_per_zr(selections: dict, page_selected: str) -> list:
title=f"{selections['X Response']} per {selector}",
barmode="overlay" if selector == selections["Color by"] else "group",
layout={"bargap": 0.05},
color_discrete_sequence=selections["Colorscale"],
color_discrete_sequence=colors,
color=selections["Color by"],
xaxis={
"type": "category",
Expand All @@ -263,9 +267,9 @@ def _update_page_per_zr(selections: dict, page_selected: str) -> list:
selections=selections,
volumemodel=volumemodel,
),
color_discrete_map=FLUID_COLORS
if selections["Color by"] == "FLUID_ZONE"
else None,
color_discrete_map=(
FLUID_COLORS if selections["Color by"] == "FLUID_ZONE" else None
),
).update_layout(margin_t=35)

if selections["X Response"] not in volumemodel.hc_responses:
Expand Down
Loading

0 comments on commit 2af9699

Please sign in to comment.