Override toImage modebar button opts via config#2607
Conversation
etpinard
left a comment
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| Registry.call('downloadImage', gd, {'format': format}) | ||
| if(toImageButtonDefaults.width) { |
There was a problem hiding this comment.
Nice. No need for isNumeric() here toImage handles it already:
plotly.js/src/plot_api/to_image.js
Lines 120 to 125 in 398eeb3
| } | ||
| if(toImageButtonDefaults.filename) { | ||
| opts.filename = toImageButtonDefaults.filename; | ||
| } |
There was a problem hiding this comment.
@nicolaskruchten we might as well add scale
plotly.js/src/plot_api/to_image.js
Lines 41 to 51 in 398eeb3
|
Nicely done. 💃 |
|
(unless someone would prefer another name for that config key instead of |
| 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.
also we should change the conditional to if(Lib.isIE() && opts.format !== 'svg')
| 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.
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
toImagemodebar button. Specifying nothing falls through to the current defaults. Note sure about the implications of renaming the button, wrt to locale files.