Skip to content

Commit c44ff23

Browse files
committed
export computed margins in full-json
1 parent dadcd06 commit c44ff23

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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)