diff --git a/callbacks/control_bar.py b/callbacks/control_bar.py index 11e02315..a06e319e 100644 --- a/callbacks/control_bar.py +++ b/callbacks/control_bar.py @@ -2,37 +2,6 @@ import dash_mantine_components as dmc import json from utils.data_utils import convert_hex_to_rgba, data -from tifffile import imread -import numpy as np - - -@callback( - Output("colormap-scale", "min"), - Output("colormap-scale", "max"), - Output("colormap-scale", "value"), - Input("image-selection-slider", "value"), - Input("project-name-src", "value"), -) -def set_color_range(image_idx, project_name): - if image_idx: - image_idx -= 1 # slider starts at 1, so subtract 1 to get the correct index - tf = data[project_name][image_idx] - min_color = np.min(tf) - max_color = np.max(tf) - return min_color, max_color, [min_color, max_color] - else: - return 0, 255, [0, 255] - - -@callback( - Output("image-viewer", "figure", allow_duplicate=True), - Input("annotation-opacity", "value"), - prevent_initial_call=True, -) -def annotation_opacity(opacity_value): - patched_figure = Patch() - patched_figure["layout"]["newshape"]["opacity"] = opacity_value - return patched_figure @callback( @@ -118,14 +87,10 @@ def annotation_visibility(checked, store, figure, image_idx): @callback( Output("figure-brightness", "value", allow_duplicate=True), Output("figure-contrast", "value", allow_duplicate=True), - Output("colormap-scale", "value", allow_duplicate=True), Input("filters-reset", "n_clicks"), - State("colormap-scale", "min"), - State("colormap-scale", "max"), prevent_initial_call=True, ) -def reset_filters(n_clicks, min_color, max_color): +def reset_filters(n_clicks): default_brightness = 100 default_contrast = 100 - default_colormap_scale = [min_color, max_color] - return default_brightness, default_contrast, default_colormap_scale + return default_brightness, default_contrast diff --git a/callbacks/image_viewer.py b/callbacks/image_viewer.py index 1048af49..779cb089 100644 --- a/callbacks/image_viewer.py +++ b/callbacks/image_viewer.py @@ -11,17 +11,13 @@ Output("image-viewer", "figure"), Input("image-selection-slider", "value"), State("project-name-src", "value"), - Input("colormap-scale", "value"), State("paintbrush-width", "value"), - State("annotation-opacity", "value"), State("annotation-class-selection", "className"), ) def render_image( image_idx, project_name, - zrange, annotation_width, - annotation_opacity, annotation_color, ): if image_idx: @@ -29,7 +25,7 @@ def render_image( tf = data[project_name][image_idx] else: tf = np.zeros((500, 500)) - fig = px.imshow(tf, binary_string=True, zmin=zrange[0], zmax=zrange[1]) + fig = px.imshow(tf, binary_string=True) fig.update_layout( margin=dict(l=0, r=0, t=0, b=0), xaxis=dict(visible=False), @@ -37,7 +33,10 @@ def render_image( dragmode="pan", height=620, width=620, + paper_bgcolor="rgba(0,0,0,0)", + plot_bgcolor="rgba(0,0,0,0)", ) + fig.update_traces(hovertemplate=None, hoverinfo="skip") # set the default annotation style hex_color = dmc.theme.DEFAULT_COLORS[annotation_color][7] @@ -45,7 +44,6 @@ def render_image( newshape=dict( line=dict(color=annotation_color, width=annotation_width), fillcolor=convert_hex_to_rgba(hex_color, 0.3), - opacity=annotation_opacity, ) ) return fig diff --git a/components/control_bar.py b/components/control_bar.py index 59d47f69..03511219 100644 --- a/components/control_bar.py +++ b/components/control_bar.py @@ -62,35 +62,6 @@ def layout(): "image-transformations", children=html.Div( [ - dmc.ActionIcon( - dmc.Tooltip( - label="Reset filters", - children=[ - DashIconify( - icon="fluent:arrow-reset-32-regular", - width=20, - ), - ], - ), - size="lg", - variant="filled", - id="filters-reset", - n_clicks=0, - mb=10, - ml="auto", - ), - dmc.Text("Colormap scalar range", size="sm"), - dmc.RangeSlider( - id="colormap-scale", - value=[0, 255], - min=0, - max=255, - minRange=0.00001, - step=0.00001, - color="gray", - size="sm", - ), - dmc.Space(h=5), dmc.Text("Brightness", size="sm"), dmc.Slider( id=f"figure-brightness", @@ -112,6 +83,25 @@ def layout(): color="gray", size="sm", ), + dmc.Space(h=10), + dmc.ActionIcon( + dmc.Tooltip( + label="Reset filters", + children=[ + DashIconify( + icon="fluent:arrow-reset-32-regular", + width=20, + ), + ], + ), + size="lg", + variant="filled", + id="filters-reset", + n_clicks=0, + mb=10, + ml="auto", + style={"margin": "auto"}, + ), ] ), ), @@ -142,17 +132,6 @@ def layout(): color="gray", size="sm", ), - dmc.Space(h=5), - dmc.Text("Annotation opacity", size="sm"), - dmc.Slider( - id="annotation-opacity", - value=1, - min=0.1, - max=1, - step=0.1, - color="gray", - size="sm", - ), dmc.Space(h=20), dmc.Text("Annotation class", size="sm"), dmc.Group( diff --git a/components/image_viewer.py b/components/image_viewer.py index d6fbb596..1cf7bab4 100644 --- a/components/image_viewer.py +++ b/components/image_viewer.py @@ -1,6 +1,7 @@ from dash import html, dcc import dash_mantine_components as dmc from dash_iconify import DashIconify +from utils.plot_utils import blank_fig COMPONENT_STYLE = { "width": "640px", @@ -85,7 +86,9 @@ def layout(): color=dmc.theme.DEFAULT_COLORS["blue"][6], variant="bars" ), children=[ - dcc.Graph(id="image-viewer", config=FIGURE_CONFIG), + dcc.Graph( + id="image-viewer", config=FIGURE_CONFIG, figure=blank_fig() + ), ], ), ], diff --git a/utils/plot_utils.py b/utils/plot_utils.py new file mode 100644 index 00000000..88cf9401 --- /dev/null +++ b/utils/plot_utils.py @@ -0,0 +1,10 @@ +import plotly.graph_objects as go + + +def blank_fig(): + fig = go.Figure(go.Scatter(x=[], y=[])) + fig.update_layout(template=None) + fig.update_xaxes(showgrid=False, showticklabels=False, zeroline=False) + fig.update_yaxes(showgrid=False, showticklabels=False, zeroline=False) + + return fig