Skip to content

Scale image in Plotly.toImage - #1979

Merged
etpinard merged 3 commits into
masterfrom
to-image-scale
Sep 11, 2017
Merged

etpinard merged 3 commits into
masterfrom
to-image-scale

Conversation

@etpinard

@etpinard etpinard commented Sep 1, 2017 •

Copy link
Copy Markdown
Contributor

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
Comment thread src/plot_api/to_image.js
// extend config for static plot
var configImage = Lib.extendFlat({}, config, {
staticPlot: true,
plotGlPixelRatio: config.plotGlPixelRatio || 2,

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

Comment thread src/snapshot/svgtoimg.js Outdated
var canvas = opts.canvas;
var scale = opts.scale || 1;
var w0 = opts.width || 150;
var h0 = opts.height || 300;

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

Brilliant. 💃 after #1979 (comment)

@etpinard

etpinard commented Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

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