Skip to content

Add way for toImage to export images with current graph width/height - #3746

Merged
etpinard merged 2 commits into
masterfrom
toimage-current-graph-width-height
Apr 9, 2019
Merged

Add way for toImage to export images with current graph width/height#3746
etpinard merged 2 commits into
masterfrom
toimage-current-graph-width-height

Conversation

@etpinard

@etpinard etpinard commented Apr 8, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

chriddyp commented Apr 8, 2019

Copy link
Copy Markdown
Member

lgtm!

@antoinerg

Copy link
Copy Markdown
Contributor

Beautiful feature @etpinard !

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

@etpinard

etpinard commented Apr 8, 2019

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

etpinard commented Apr 8, 2019

Copy link
Copy Markdown
Contributor Author

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