Skip to content

Conversation

@etpinard
Copy link
Contributor

@etpinard etpinard commented Apr 8, 2019

resolves #3743 ... in a slightly more general way than proposed in that issue.

This PR adds special logic to Plotly.toImage (which is called by Plotly.downloadImage, which is itself called when clicking on the toImage modebar button) for options width:null and height:null.

In brief, Plotly.toImage(gd, {width:null, height:null}) will use the width/height values found in gd._fullLayout to generate its output image. Equivalently,

Plotly.react(gd, data, layout, {
  toImageButtonOptions: {width: null, height: null}
})

and clicking on the toImage modebar button will generate an image using the current gd._fullLayout.width and gd._fullLayout.height values - which (should at least) always store the current graph width/height values.

@plotly/plotly_js @nicolaskruchten - let me know what you think!

etpinard added 2 commits April 8, 2019 16:40
... where in that case, we use graph's current width/height
    (as found in gd._fullLayout) for the exported dimensions.
@etpinard etpinard added this to the v1.47.0 milestone Apr 8, 2019
@nicolaskruchten
Copy link
Contributor

Hah that’s actually what I had initially tried and thought might work so I’m totally down with that approach. /cc @chriddyp

@chriddyp
Copy link
Member

chriddyp commented Apr 8, 2019

lgtm!

@antoinerg
Copy link
Contributor

Beautiful feature @etpinard !

Could config options toImageButtonOptions: {width: null, height: null} be the default when responsive: true?

@etpinard
Copy link
Contributor Author

etpinard commented Apr 8, 2019

Could config options toImageButtonOptions: {width: null, height: null} be the default when responsive: true?

I'd call that a breaking change. For sure in v2 though.

@antoinerg
Copy link
Contributor

I'd call that a breaking change. For sure in v2 though.

Ok, then the only request I have is to add it to the v2 wishlist!

💃

@etpinard
Copy link
Contributor Author

etpinard commented Apr 8, 2019

Ok, then the only request I have is to add it to the v2 wishlist!

✏️ in #1576 (comment) - for better context info.

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

Labels

feature something new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toImageButtonOptions arg to download current size

4 participants