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

Scale image in Plotly.toImage #1979

Merged
merged 3 commits into from
Sep 11, 2017
Merged

Scale image in Plotly.toImage #1979

merged 3 commits into from
Sep 11, 2017

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Sep 1, 2017

This PR adds a scale option to Plotly.toImage (and Plotly.downloadImage) which scales the generated image by a given factor. Note that, scaling an image isn't the same as just relayouting it to some factor times the current layout width/height values. Scaling scales every feature of a graph - this should help users that want higher resolution image exports.

The new scale has an effect on all the supported formats. For png, jpeg and webp this is accomplished using context.drawImage's width/height options. For svg, we tweak the viewBox attribute similar to during scroll/pan interactions.

- which draw image data on bigger canvas (for png/jpeg/webp)
- and scales svg using top-level width/height/viewBox attribute
@@ -128,7 +140,6 @@ function toImage(gd, opts) {
// extend config for static plot
var configImage = Lib.extendFlat({}, config, {
staticPlot: true,
plotGlPixelRatio: config.plotGlPixelRatio || 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. This should have been in a separate commit. In brief, this line was useless, so 🔪

@@ -33,6 +33,12 @@ function svgToImg(opts) {
}

var canvas = opts.canvas;
var scale = opts.scale || 1;
var w0 = opts.width || 150;
var h0 = opts.height || 300;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

150 <-> 300 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eyes! Done in 633882b

@alexcjohnson
Copy link
Collaborator

Brilliant. 💃 after #1979 (comment)

@etpinard
Copy link
Contributor Author

etpinard commented Sep 1, 2017

Thanks for the quick review @alexcjohnson !

I'll leave this one unmerged until 1.30.1 is released early next week.

@etpinard etpinard merged commit 00856ad into master Sep 11, 2017
@etpinard etpinard deleted the to-image-scale branch September 11, 2017 14:22
@etpinard etpinard mentioned this pull request Nov 30, 2017
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.

2 participants