Skip to content

Remove the scaleanchor constrain on axes having an image trace #6709

Closed
@josephernest

Description

@josephernest

In Keep square pixels + ability to have any rectangular shape zoom with Plotly.js, with a plot with 2 layers's answer by @lvlte, we see that it is sometimes useful to be able to remove the scaleanchor constrain applied by default on axes having an image trace.

But this doesn't work: setting scaleanchor: false on either or both axes has no effect.

The easiest solution is to patch, in https://github.com/plotly/plotly.js/blob/v2.25.2/src/plots/cartesian/constraints.js#L34,

hasImage: axHasImage[axName]

by

hasImage: false

but this is not a solution in the long-term.

Do you think it could be useful to add a setting to avoid this manual patching?

Activity

changed the title [-]Remove the scaleanchor constrain applied by default on axes having an image trace[/-] [+]Remove the scaleanchor constrain on axes having an image trace[/+] on Aug 17, 2023
alexcjohnson

alexcjohnson commented on Aug 17, 2023

@alexcjohnson
Collaborator

Good point! I don't see any way currently to turn this behavior off. Seems like the options are:

  • add something like false to the acceptable options for scaleanchor so you can explicitly override a default set by having an image
  • add an attribute to image traces to disable automatic scaleanchor - ie giving the image trace an attribute like squarepixels which would default to true but you can set it to false in which case that image would not contribute to axHasImage.

The second might be more discoverable in the documentation, but it's less direct and if you have multiple images you'd need to set this on all of them. The first requires you to figure out that the constraint is specified on the Y axis and that an explicit false will remove it, but you only have to do this once (per Y axis) and would generalize if we ever add any other conditions that automatically set a constraint.

So I'd lean toward the first, plus a note somewhere in the docs for image trace about this setting in the Y axis.

josephernest

josephernest commented on Aug 18, 2023

@josephernest
Author

This would be great @alexcjohnson! What do you think @lvlte?

lvlte

lvlte commented on Aug 18, 2023

@lvlte
Contributor

Yes I would go for the first option too. I think I will make a PR this weekend or next week.

josephernest

josephernest commented on Aug 22, 2023

@josephernest
Author

Thanks for the pull request @lvlte and for the merge!
Do you think it will be included for v2.25.3 @archmoj?

archmoj

archmoj commented on Aug 22, 2023

@archmoj
Contributor

Thanks for the pull request @lvlte and for the merge! Do you think it will be included for v2.25.3 @archmoj?
@josephernest New features would be included in the next minor.
We would possibly release 2.26.0 this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcjohnson@josephernest@archmoj@lvlte

      Issue actions

        Remove the scaleanchor constrain on axes having an image trace · Issue #6709 · plotly/plotly.js