-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
- 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, |
There was a problem hiding this comment.
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 🔪
src/snapshot/svgtoimg.js
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
150 <-> 300 ?
There was a problem hiding this comment.
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
Brilliant. 💃 after #1979 (comment) |
Thanks for the quick review @alexcjohnson ! I'll leave this one unmerged until |
This PR adds a
scale
option toPlotly.toImage
(andPlotly.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 layoutwidth
/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. Forpng
,jpeg
andwebp
this is accomplished usingcontext.drawImage
's width/height options. Forsvg
, we tweak theviewBox
attribute similar to during scroll/pan interactions.