Skip to content

Override toImage modebar button opts via config#2607

Merged
nicolaskruchten merged 3 commits into
masterfrom
download_config
May 3, 2018
Merged

Override toImage modebar button opts via config#2607
nicolaskruchten merged 3 commits into
masterfrom
download_config

Conversation

@nicolaskruchten

Copy link
Copy Markdown
Contributor

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.

@etpinard etpinard left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/components/modebar/buttons.js Outdated
}

Registry.call('downloadImage', gd, {'format': format})
if(toImageButtonDefaults.width) {

Copy link
Copy Markdown
Contributor

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:

var format = coerce('format');
var width = coerce('width');
var height = coerce('height');
var scale = coerce('scale');
var setBackground = coerce('setBackground');
var imageDataOnly = coerce('imageDataOnly');

Comment thread src/components/modebar/buttons.js Outdated
}
if(toImageButtonDefaults.filename) {
opts.filename = toImageButtonDefaults.filename;
}

Copy link
Copy Markdown
Contributor

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

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(' ')
},

@etpinard etpinard added this to the v1.38.0 milestone May 3, 2018
@nicolaskruchten nicolaskruchten changed the title WIP override toImage modebar button opts via config verride toImage modebar button opts via config May 3, 2018
@nicolaskruchten nicolaskruchten changed the title verride toImage modebar button opts via config Override toImage modebar button opts via config May 3, 2018
@etpinard

etpinard commented May 3, 2018

Copy link
Copy Markdown
Contributor

Nicely done. 💃

@etpinard

etpinard commented May 3, 2018

Copy link
Copy Markdown
Contributor

(unless someone would prefer another name for that config key instead of toImageButtonDefaults)

if(Lib.isIE()) {
Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long');
format = 'svg';
opts.format = 'svg';

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.

also we should change the conditional to if(Lib.isIE() && opts.format !== 'svg')

Comment thread src/components/modebar/buttons.js Outdated
modeBarButtons.toImage = {
name: 'toImage',
title: function(gd) { return _(gd, 'Download plot as a png'); },
title: function(gd) { return _(gd, 'Download plot'); },

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.

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.

@alexcjohnson

Copy link
Copy Markdown
Collaborator

(unless someone would prefer another name for that config key instead of toImageButtonDefaults)

They're not really defaults at that point, since there's no way to override them further, right? So I might vote toImageButtonOptions or something.

@nicolaskruchten

Copy link
Copy Markdown
Contributor Author

Thanks @alexcjohnson ! I've implemented your suggestions

@alexcjohnson

Copy link
Copy Markdown
Collaborator

Thanks! 💃

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.

3 participants