Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 877356b

Browse files
committed
apply sizes in plot and image test
1 parent ebab12b commit 877356b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/plot_api/to_image.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ function toImage(gd, opts) {
121121

122122
var fullOpts = {};
123123

124+
var template = layout.template;
125+
if(Lib.isPlainObject(template)) {
126+
fullOpts.template = template;
127+
fullOpts._template = template.layout;
128+
fullOpts._dataTemplate = template.data;
129+
}
130+
124131
function coerce(attr, dflt) {
125132
return Lib.coerce(opts, fullOpts, attrs, attr, dflt);
126133
}
@@ -169,8 +176,8 @@ function toImage(gd, opts) {
169176
function convert() {
170177
return new Promise(function(resolve, reject) {
171178
var svg = toSVG(clonedGd, format, scale);
172-
var width = clonedGd._fullLayout.width;
173-
var height = clonedGd._fullLayout.height;
179+
var _width = clonedGd._fullLayout.width;
180+
var _height = clonedGd._fullLayout.height;
174181

175182
function cleanup() {
176183
plotApi.purge(clonedGd);
@@ -204,8 +211,8 @@ function toImage(gd, opts) {
204211

205212
svgToImg({
206213
format: format,
207-
width: width,
208-
height: height,
214+
width: _width,
215+
height: _height,
209216
scale: scale,
210217
canvas: canvas,
211218
svg: svg,

src/plots/plots.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,9 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
14901490
// to pass through the autosize routine
14911491
//
14921492
// This behavior is subject to change in v2.
1493-
coerce('autosize', !(layoutIn.width && layoutIn.height));
1493+
var hasWidth = !!(layoutIn.width || (layoutOut._template || {}).width);
1494+
var hasHeight = !!(layoutIn.height || (layoutOut._template || {}).height);
1495+
coerce('autosize', !(hasWidth && hasHeight));
14941496

14951497
coerce('width');
14961498
coerce('height');
@@ -1501,7 +1503,7 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
15011503
coerce('margin.pad');
15021504
coerce('margin.autoexpand');
15031505

1504-
if(layoutIn.width && layoutIn.height) plots.sanitizeMargins(layoutOut);
1506+
if(hasWidth && hasHeight) plots.sanitizeMargins(layoutOut);
15051507

15061508
Registry.getComponentMethod('grid', 'sizeDefaults')(layoutIn, layoutOut);
15071509

test/image/assets/get_image_request_options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ module.exports = function getRequestOpts(specs) {
2323
scale: specs.scale || DEFAULT_SCALE
2424
};
2525

26+
var layout = figure.layout || {};
27+
var tempLayout = (layout.template || {}).layout || {};
28+
var autosize = layout.autosize || tempLayout.autosize;
29+
if(autosize !== true) {
30+
body.width = layout.width || tempLayout.width;
31+
body.height = layout.height || tempLayout.height;
32+
}
33+
2634
if(specs.width) body.width = specs.width;
2735
if(specs.height) body.height = specs.height;
2836

0 commit comments

Comments
 (0)