Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/plots/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ module.exports = {
},
editType: 'plot'
},
computed: {
valType: 'any',
role: 'info',
editType: 'none',
description: [
'Placeholder for exporting automargin-impacting values namely',
'`margin.t`, `margin.b`, `margin.l` and `margin.r` in *full-json* mode.',
].join(' ')
},
paper_bgcolor: {
valType: 'color',
role: 'style',
Expand Down
15 changes: 14 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,20 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults, includeConfi
return d;
})
};
if(!dataonly) { obj.layout = stripObj(layout); }
if(!dataonly) {
obj.layout = stripObj(layout);
if(useDefaults) {
var gs = layout._size;
obj.layout.computed = {
margin: {
b: gs.b,
l: gs.l,
r: gs.r,
t: gs.t
}
};
}
}

if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig();

Expand Down
17 changes: 17 additions & 0 deletions test/jasmine/tests/toimage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var subplotMock = require('@mocks/multiple_subplots.json');
var pieAutoMargin = require('@mocks/pie_automargin');

var FORMATS = ['png', 'jpeg', 'webp', 'svg'];

Expand Down Expand Up @@ -301,5 +302,21 @@ describe('Plotly.toImage', function() {
.catch(failTest)
.then(done);
});

it('export computed margins', function(done) {
Plotly.toImage(pieAutoMargin, imgOpts)
.then(function(fig) {
fig = JSON.parse(fig);
var computed = fig.layout.computed;
expect(computed).toBeDefined('no computed');
expect(computed.margin).toBeDefined('no computed margin');
expect(computed.margin.t).toBeDefined('no top');
expect(computed.margin.l).toBeDefined('no left');
expect(computed.margin.r).toBeDefined('no right');
expect(computed.margin.b).toBeDefined('no bottom');
})
.catch(failTest)
.then(done);
});
});
});