10000 override toImage modebar button opts via config · dsias/plotly.js@e4c6c5c · GitHub
[go: up one dir, main page]

Skip to content

Commit e4c6c5c

Browse files
override toImage modebar button opts via config
1 parent 398eeb3 commit e4c6c5c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/modebar/buttons.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,29 @@ var modeBarButtons = module.exports = {};
4747

4848
modeBarButtons.toImage = {
4949
name: 'toImage',
50-
title: function(gd) { return _(gd, 'Download plot as a png'); },
50+
title: function(gd) { return _(gd, 'Download plot'); },
5151
icon: Icons.camera,
5252
click: function(gd) {
53-
var format = 'png';
53+
var toImageButtonDefaults = gd._context.toImageButtonDefaults;
54+
var opts = {format: toImageButtonDefaults.format || 'png'};
5455

5556
Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');
5657

5758
if(Lib.isIE()) {
5859
Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long');
59-
format = 'svg';
60+
opts.format = 'svg';
6061
}
6162

62-
Registry.call('downloadImage', gd, {'format': format})
63+
if(toImageButtonDefaults.width) {
64+
opts.width = toImageButtonDefaults.width;
65+
}
66+
if(toImageButtonDefaults.height) {
67+
opts.height = toImageButtonDefaults.height;
68+
}
69+
if(toImageButtonDefaults.filename) {
70+
opts.filename = toImageButtonDefaults.filename;
71+
}
72+
Registry.call('downloadImage', gd, opts)
6373
.then(function(filename) {
6474
Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');
6575
})

src/plot_api/plot_config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ module.exports = {
115115
*/
116116
modeBarButtons: false,
117117

118+
// statically override options for toImage modebar button
119+
// allowed keys are format, filename, width, height
120+
toImageButtonDefaults: {},
121+
118122
// add the plotly logo on the end of the mode bar
119123
displaylogo: true,
120124

0 commit comments

Comments
 (0)
0