Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 preserve zoom and pan on image change #42

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 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, clientside_callback
from dash import Input, Output, State, callback, ctx, Patch, clientside_callback
import dash_mantine_components as dmc
from tifffile import imread
import plotly.express as px
Expand All @@ -8,6 +8,7 @@

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

view = annotation_store["view"]
if "xaxis_range_0" in view and annotation_store["image_size"] == tf.size:
fig.update_layout(
xaxis=dict(range=[view["xaxis_range_0"], view["xaxis_range_1"]]),
yaxis=dict(range=[view["yaxis_range_0"], view["yaxis_range_1"]]),
)
patched_annotation_store = Patch()
patched_annotation_store["image_size"] = tf.size
fig_loading_overlay = -1
return fig, fig_loading_overlay

return fig, patched_annotation_store, fig_loading_overlay


clientside_callback(
Expand Down Expand Up @@ -92,6 +102,13 @@ def locally_store_annotations(relayout_data, img_idx, annotation_store):
"""
if "shapes" in relayout_data:
annotation_store["annotations"][str(img_idx - 1)] = relayout_data["shapes"]

if "xaxis.range[0]" in relayout_data:
annotation_store["view"]["xaxis_range_0"] = relayout_data["xaxis.range[0]"]
annotation_store["view"]["xaxis_range_1"] = relayout_data["xaxis.range[1]"]
annotation_store["view"]["yaxis_range_0"] = relayout_data["yaxis.range[0]"]
annotation_store["view"]["yaxis_range_1"] = relayout_data["yaxis.range[1]"]

return annotation_store


Expand Down
8 changes: 7 additions & 1 deletion components/control_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ def layout():
),
dcc.Store(
id="annotation-store",
data={"dragmode": "drawopenpath", "visible": True, "annotations": {}},
data={
"dragmode": "drawopenpath",
"visible": True,
"annotations": {},
"view": {},
"image_size": [],
},
),
dcc.Store(id="project-data"),
html.Div(id="dummy-output"),
Expand Down
Loading