Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4c6c5c

Browse filesBrowse files
override toImage modebar button opts via config
1 parent 398eeb3 commit e4c6c5c
Copy full SHA for e4c6c5c

File tree

Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed

‎src/components/modebar/buttons.js

Copy file name to clipboardExpand all lines: src/components/modebar/buttons.js
+14-4Lines 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

Copy file name to clipboardExpand all lines: src/plot_api/plot_config.js
+4Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.