-
-
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
Override toImage modebar button opts via config #2607
Conversation
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.
Looks good!
The only thing missing is a test. Our modebar suite is a bit of a mess unforunately and testing image downloads in jasmine isn't great. But we should still try!
So I'm thinking adding a new describe
block in modebar_test.js
that sets spyOn(Registry, 'call')
and look up its arguments after click (using toHaveBeenCalledWith
I think) for different config
options.
src/components/modebar/buttons.js
Outdated
} | ||
|
||
Registry.call('downloadImage', gd, {'format': format}) | ||
if(toImageButtonDefaults.width) { |
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.
Nice. No need for isNumeric()
here toImage handles it already:
plotly.js/src/plot_api/to_image.js
Lines 120 to 125 in 398eeb3
var format = coerce('format'); | |
var width = coerce('width'); | |
var height = coerce('height'); | |
var scale = coerce('scale'); | |
var setBackground = coerce('setBackground'); | |
var imageDataOnly = coerce('imageDataOnly'); |
src/components/modebar/buttons.js
Outdated
} | ||
if(toImageButtonDefaults.filename) { | ||
opts.filename = toImageButtonDefaults.filename; | ||
} |
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.
@nicolaskruchten we might as well add scale
plotly.js/src/plot_api/to_image.js
Lines 41 to 51 in 398eeb3
scale: { | |
valType: 'number', | |
min: 0, | |
dflt: 1, | |
description: [ | |
'Sets a scaling for the generated image.', | |
'If set, all features of a graphs (e.g. text, line width)', | |
'are scaled, unlike simply setting', | |
'a bigger *width* and *height*.' | |
].join(' ') | |
}, |
Nicely done. 💃 |
(unless someone would prefer another name for that config key instead of |
src/components/modebar/buttons.js
Outdated
|
||
Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long'); | ||
|
||
if(Lib.isIE()) { | ||
Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long'); | ||
format = 'svg'; | ||
opts.format = 'svg'; |
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.
also we should change the conditional to if(Lib.isIE() && opts.format !== 'svg')
src/components/modebar/buttons.js
Outdated
@@ -47,19 +47,26 @@ var modeBarButtons = module.exports = {}; | |||
|
|||
modeBarButtons.toImage = { | |||
name: 'toImage', | |||
title: function(gd) { return _(gd, 'Download plot as a png'); }, | |||
title: function(gd) { return _(gd, 'Download plot'); }, |
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.
We can't make dynamic strings here, so _(gd, 'Download plot as a ' + format)
won't work, but perhaps we can keep 'Download plot as a png'
as the default string and only degrade to 'Download plot'
if it's not a png? Two reasons:
- I don't want to unnecessarily break all our existing translations, for folks who are not using this new option.
- I do find "as a png" helpful, to clarify that it's not the data or json for example, though I guess the icon mitigates that substantially.
They're not really defaults at that point, since there's no way to override them further, right? So I might vote |
Thanks @alexcjohnson ! I've implemented your suggestions |
Thanks! 💃 |
This PR allows for selective overriding of default behaviour of the
toImage
modebar button. Specifying nothing falls through to the current defaults. Note sure about the implications of renaming the button, wrt to locale files.