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

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

Merged
merged 2 commits into from Apr 9, 2019

Conversation

@etpinard
Copy link
Member

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 Apr 8, 2019
... where in that case, we use graph's current width/height
    (as found in gd._fullLayout) for the exported dimensions.
@nicolaskruchten

This comment has been minimized.

Copy link
Member

nicolaskruchten commented Apr 8, 2019

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

@chriddyp

This comment has been minimized.

Copy link
Member

chriddyp commented Apr 8, 2019

lgtm!

@antoinerg

This comment has been minimized.

Copy link
Collaborator

antoinerg commented Apr 8, 2019

Beautiful feature @etpinard !

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

@etpinard

This comment has been minimized.

Copy link
Member 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

This comment has been minimized.

Copy link
Collaborator

antoinerg commented Apr 8, 2019

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

This comment has been minimized.

Copy link
Member 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.

@etpinard etpinard merged commit 636a356 into master Apr 9, 2019
10 checks passed
10 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: publish Your tests passed on CircleCI!
Details
ci/circleci: test-bundle Your tests passed on CircleCI!
Details
ci/circleci: test-image Your tests passed on CircleCI!
Details
ci/circleci: test-image2 Your tests passed on CircleCI!
Details
ci/circleci: test-jasmine Your tests passed on CircleCI!
Details
ci/circleci: test-jasmine2 Your tests passed on CircleCI!
Details
ci/circleci: test-jasmine3 Your tests passed on CircleCI!
Details
ci/circleci: test-syntax Your tests passed on CircleCI!
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
@etpinard etpinard deleted the toimage-current-graph-width-height branch Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.