Skip to content

Commit 8128c88

Browse files
authored
Merge pull request #5203 from plotly/export-computed-lauout
Provide computed margins in full-json export
2 parents d4e449e + 586f2cc commit 8128c88

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/plots/layout_attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ module.exports = {
265265
},
266266
editType: 'plot'
267267
},
268+
computed: {
269+
valType: 'any',
270+
role: 'info',
271+
editType: 'none',
272+
description: [
273+
'Placeholder for exporting automargin-impacting values namely',
274+
'`margin.t`, `margin.b`, `margin.l` and `margin.r` in *full-json* mode.',
275+
].join(' ')
276+
},
268277
paper_bgcolor: {
269278
valType: 'color',
270279
role: 'style',

src/plots/plots.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,20 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults, includeConfi
21602160
return d;
21612161
})
21622162
};
2163-
if(!dataonly) { obj.layout = stripObj(layout); }
2163+
if(!dataonly) {
2164+
obj.layout = stripObj(layout);
2165+
if(useDefaults) {
2166+
var gs = layout._size;
2167+
obj.layout.computed = {
2168+
margin: {
2169+
b: gs.b,
2170+
l: gs.l,
2171+
r: gs.r,
2172+
t: gs.t
2173+
}
2174+
};
2175+
}
2176+
}
21642177

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

test/jasmine/tests/toimage_test.js

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var createGraphDiv = require('../assets/create_graph_div');
66
var destroyGraphDiv = require('../assets/destroy_graph_div');
77
var failTest = require('../assets/fail_test');
88
var subplotMock = require('@mocks/multiple_subplots.json');
9+
var pieAutoMargin = require('@mocks/pie_automargin');
910

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

@@ -301,5 +302,21 @@ describe('Plotly.toImage', function() {
301302
.catch(failTest)
302303
.then(done);
303304
});
305+
306+
it('export computed margins', function(done) {
307+
Plotly.toImage(pieAutoMargin, imgOpts)
308+
.then(function(fig) {
309+
fig = JSON.parse(fig);
310+
var computed = fig.layout.computed;
311+
expect(computed).toBeDefined('no computed');
312+
expect(computed.margin).toBeDefined('no computed margin');
313+
expect(computed.margin.t).toBeDefined('no top');
314+
expect(computed.margin.l).toBeDefined('no left');
315+
expect(computed.margin.r).toBeDefined('no right');
316+
expect(computed.margin.b).toBeDefined('no bottom');
317+
})
318+
.catch(failTest)
319+
.then(done);
320+
});
304321
});
305322
});

0 commit comments

Comments
 (0)