def make_range_slider(values: pd.Series, name: str, uuid: str) -> html.Div: return wcc.RangeSlider( label=name, id={ "id": uuid, "type": "range-slider", "name": name }, min=values.min(), max=values.max(), step=calculate_slider_step( min_value=values.min(), max_value=values.max(), steps=len(list(values.unique())) - 1, ), value=[values.min(), values.max()], marks={ str(values.min()): { "label": f"{values.min():.2f}" }, str(values.max()): { "label": f"{values.max():.2f}" }, }, tooltip={"always_visible": False}, )
def make_range_slider(domid, values, col_name): try: values.apply(pd.to_numeric, errors="raise") except ValueError: raise ValueError(f"Cannot calculate filter range for {col_name}. " "Ensure that it is a numerical column.") return dcc.RangeSlider( id=domid, min=values.min(), max=values.max(), step=calculate_slider_step( min_value=values.min(), max_value=values.max(), steps=len(list(values.unique())) - 1, ), value=[values.min(), values.max()], marks={ str(values.min()): { "label": f"{values.min():.2f}" }, str(values.max()): { "label": f"{values.max():.2f}" }, }, )
def _update_color_slider(_clicks, cubepath): cube = load_cube_data(get_path(cubepath)) minv = float(f"{cube.values.min():2f}") maxv = float(f"{cube.values.max():2f}") value = [minv, maxv] step = calculate_slider_step(minv, maxv, steps=100) return minv, maxv, value, step
def _update_color_slider(_clicks, gridparameter): grid = load_grid(get_path(self.gridfile)) gridparameter = load_grid_parameter(grid, get_path(gridparameter)) minv = float(f"{gridparameter.values.min():2f}") maxv = float(f"{gridparameter.values.max():2f}") value = [minv, maxv] step = calculate_slider_step(minv, maxv, steps=100) return minv, maxv, value, step
def _reset_color_range( _btn_clicked: int, state_data_str: Union[str, None] ) -> Tuple[float, float, list, float]: if not state_data_str: raise PreventUpdate state = json.loads(state_data_str) minv = state["min_value"] maxv = state["max_value"] value = [minv, maxv] step = calculate_slider_step(min_value=minv, max_value=maxv, steps=100) return minv, maxv, value, step
def _reset_color_range(btn_clicked, state): if not state: raise PreventUpdate state = json.loads(state) minv = state["min_value"] maxv = state["max_value"] value = [minv, maxv] step = calculate_slider_step(min_value=minv, max_value=maxv, steps=100) return minv, maxv, value, step
def settings_layout(self) -> wcc.FlexBox: """Layout for color and other settings""" return wcc.Frame( style={"width": "40%"}, children=[ html.Div( style={"width": "100%"}, children=wcc.Dropdown( label="Seismic cube", id=self.uuid("cube"), options=[{ "label": Path(cube).stem, "value": cube } for cube in self.segyfiles], value=self.segyfiles[0], 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( label="Color range", id=self.uuid("color-values"), min=self.init_state["min_value"], max=self.init_state["max_value"], value=[ self.init_state["min_value"], self.init_state["max_value"], ], tooltip={"placement": "bottom"}, step=calculate_slider_step( min_value=self.init_state["min_value"], max_value=self.init_state["max_value"], steps=100, ), ), ], ), html.Button(id=self.uuid("color-reset"), children="Reset Range"), html.Button(id=self.uuid("zoom"), children="Reset zoom"), ], )
def settings_layout(self) -> wcc.FlexBox: """Layout for color and other settings""" return wcc.FlexBox( style={"margin": "50px"}, children=[ html.Div( style={"width": "100%"}, children=html.Label( children=[ html.Span("Seismic cube:", style={"font-weight": "bold"}), dcc.Dropdown( id=self.ids("cube"), options=[ {"label": Path(cube).stem, "value": cube} for cube in self.segyfiles ], value=self.segyfiles[0], clearable=False, persistence=True, persistence_type="session", ), ] ), ), html.Div( style={"marginRight": "50px", "width": "50%", "marginLeft": "50px"}, children=[ html.Label( style={"font-weight": "bold", "textAlign": "center"}, children="Set colorscale", ), wcc.ColorScales( id=self.ids("color-scale"), colorscale=self.initial_colors, nSwatches=12, ), ], ), html.Div( style={"marginRight": "50px", "width": "50%", "marginLeft": "50px"}, children=[ html.P( "Color range", style={"textAlign": "center", "font-weight": "bold"}, ), dcc.RangeSlider( id=self.ids("color-values"), min=self.init_state["min_value"], max=self.init_state["max_value"], value=[ self.init_state["min_value"], self.init_state["max_value"], ], tooltip={"always_visible": True}, step=calculate_slider_step( min_value=self.init_state["min_value"], max_value=self.init_state["max_value"], steps=100, ), persistence=True, persistence_type="session", ), ], ), html.Button(id=self.ids("color-reset"), children="Reset Range"), html.Button(id=self.ids("zoom"), children="Reset zoom"), ], )