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

Allow drag zoom of arbitrary aspect ratio with dcc.Graph and image as data #4861

Open
matt-sd-watson opened this issue Nov 12, 2024 · 3 comments
Labels
feature something new P3 backlog

Comments

@matt-sd-watson
Copy link

Our application uses dcc.Graph to render images. Currently, the zoom feature maintains the aspect ratio of the full-resolution image. Is it possible to configure the graph component to permit drag zooming of arbitrary aspect ratios? One consideration is that the behaviour would be separate from scollZoom as scrolling would have to maintain the current aspect ratio

@alexcjohnson
Copy link
Collaborator

Arbitrary aspect zoom normally is possible, unless your graph locks its aspect ratio, for example with yaxis.scaleanchor = “x”. Where this gets confusing is with image traces, that make this the default behavior. In that case you have to explicitly unlock it, for example:
fig.update_layout(yaxis_scaleanchor=None)

@gvwilson gvwilson added feature something new P3 backlog labels Nov 12, 2024
@matt-sd-watson
Copy link
Author

matt-sd-watson commented Nov 12, 2024

fig.update_layout(yaxis_scaleanchor=None) doesn't appear to work when the underlying data comes from px.imshow:

canvas = px.imshow(Image.fromarray(image.astype(np.uint8))
fig = go.Figure(canvas)
fig.update_layout(yaxis_scaleanchor=None)

the fig is then passed to the component:

dcc.Graph(config={"modeBarButtonsToAdd": [
        "drawclosedpath",
        "drawrect",
        "eraseshape"],
        'toImageButtonOptions': {'format': 'png', 'filename': filename, 'scale': 1},
        'edits': {'shapePosition': False}, 'scrollZoom': fullscreen_mode, 'displaylogo': False},
        relayoutData={'autosize': True},
        id=input_id,
        style=style_canvas,
        figure={'layout': dict(yaxis_scaleanchor=None, xaxis_showgrid=False, yaxis_showgrid=False,
                               newshape=dict(line=dict(color="white")),
                               xaxis=go.XAxis(showticklabels=False),
                               yaxis=go.YAxis(showticklabels=False),
                               margin=default_canvas_margins()
                               )})

using dash 2.10.2

@matt-sd-watson matt-sd-watson changed the title Allow drag zoom of arbitrary aspect ratio with dcc.Graph Allow drag zoom of arbitrary aspect ratio with dcc.Graph and image as data Nov 12, 2024
@alexcjohnson
Copy link
Collaborator

Ah so it's False, not None... and it seems like in different situations the scaleanchor can get set on either x or y, so the most reliable way to do this I think is:

fig.update_layout(xaxis_scaleanchor=False, yaxis_scaleanchor=False)

or if you have multiple subplots:

fig.update_xaxes(scaleanchor=False).update_yaxes(scaleanchor=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants