Skip to content

Commit 56c5cca

Browse files
PR feedback
1 parent e4c6c5c commit 56c5cca

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/components/modebar/buttons.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,12 @@ modeBarButtons.toImage = {
6060
opts.format = 'svg';
6161
}
6262

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-
}
63+
['filename', 'width', 'height', 'scale'].forEach(function(key) {
64+
if(toImageButtonDefaults[key]) {
65+
opts[key] = toImageButtonDefaults[key];
66+
}
67+
});
68+
7269
Registry.call('downloadImage', gd, opts)
7370
.then(function(filename) {
7471
Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');

src/plot_api/plot_config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ module.exports = {
116116
modeBarButtons: false,
117117

118118
// statically override options for toImage modebar button
119-
// allowed keys are format, filename, width, height
119+
// allowed keys are format, filename, width, height, scale
120+
// see ./components/modebar/buttons.js
120121
toImageButtonDefaults: {},
121122

122123
// add the plotly logo on the end of the mode bar

test/jasmine/tests/modebar_test.js

+37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var manageModeBar = require('@src/components/modebar/manage');
55

66
var Plotly = require('@lib/index');
77
var Plots = require('@src/plots/plots');
8+
var Registry = require('@src/registry');
89
var createGraphDiv = require('../assets/create_graph_div');
910
var destroyGraphDiv = require('../assets/destroy_graph_div');
1011
var selectButton = require('../assets/modebar_button');
@@ -767,6 +768,42 @@ describe('ModeBar', function() {
767768
}
768769
}
769770

771+
describe('toImage handlers', function() {
772+
beforeEach(function() {
773+
spyOn(Registry, 'call').and.callFake(function() {
774+
return Promise.resolve();
775+
});
776+
gd = createGraphDiv();
777+
});
778+
779+
it('should use defaults', function(done) {
780+
Plotly.plot(gd, {data: [], layout: {}})
781+
.then(function() {
782+
selectButton(gd._fullLayout._modeBar, 'toImage').click();
783+
expect(Registry.call).toHaveBeenCalledWith('downloadImage', gd,
784+
{format: 'png'});
785+
done();
786+
});
787+
});
788+
789+
it('should accept overriding defaults', function(done) {
790+
Plotly.plot(gd, {data: [], layout: {}, config: {
791+
toImageButtonDefaults: {
792+
format: 'svg',
793+
filename: 'x',
794+
unsupported: 'should not pass'
795+
}
796+
} })
797+
.then(function() {
798+
selectButton(gd._fullLayout._modeBar, 'toImage').click();
799+
expect(Registry.call).toHaveBeenCalledWith('downloadImage', gd,
800+
{format: 'svg', filename: 'x'});
801+
done();
802+
});
803+
});
804+
805+
});
806+
770807
describe('cartesian handlers', function() {
771808

772809
beforeEach(function(done) {

0 commit comments

Comments
 (0)