Skip to content

Commit

Permalink
Merge pull request #44 from mlexchange/fix-loading-overlay
Browse files Browse the repository at this point in the history
🚸 improve fig loading overlay to only show on img change
  • Loading branch information
hannahker authored Jul 14, 2023
2 parents 609714d + 61ea283 commit 0f71cea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions callbacks/image_viewer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dash import Input, Output, State, callback, ctx
from dash import Input, Output, State, callback, ctx, clientside_callback
import dash_mantine_components as dmc
from tifffile import imread
import plotly.express as px
Expand All @@ -8,11 +8,13 @@

@callback(
Output("image-viewer", "figure"),
Output("image-viewer-loading", "zIndex", allow_duplicate=True),
Input("image-selection-slider", "value"),
State("project-name-src", "value"),
State("paintbrush-width", "value"),
State("annotation-class-selection", "className"),
State("annotation-store", "data"),
prevent_initial_call=True,
)
def render_image(
image_idx,
Expand Down Expand Up @@ -60,7 +62,19 @@ def render_image(
if str(image_idx) in annotation_store["annotations"]:
fig["layout"]["shapes"] = annotation_store["annotations"][str(image_idx)]

return fig
fig_loading_overlay = -1
return fig, fig_loading_overlay


clientside_callback(
"""
function EnableImageLoadingOverlay(zIndex) {
return 9999;
}
""",
Output("image-viewer-loading", "zIndex"),
Input("image-selection-slider", "value"),
)


@callback(
Expand Down
1 change: 1 addition & 0 deletions components/image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def layout():
),
dmc.Space(h=20),
dmc.LoadingOverlay(
id="image-viewer-loading",
overlayOpacity=0.15,
loaderProps=dict(
color=dmc.theme.DEFAULT_COLORS["blue"][6], variant="bars"
Expand Down

0 comments on commit 0f71cea

Please sign in to comment.