@@ -1294,8 +1294,25 @@ function plotAutoSize(gd, aobj) {
1294
1294
var gdBB = gd . layout . _container . node ( ) . getBoundingClientRect ( ) ;
1295
1295
newheight = Math . round ( gdBB . height * 0.9 ) ;
1296
1296
newwidth = Math . round ( gdBB . width * 0.9 ) ;
1297
+
1298
+ // restrict aspect ratio to between 2:1 and 1:2, but only change height to do this
1299
+ newheight = Plotly . Lib . constrain ( newheight , newwidth / 2 , newwidth * 2 ) ;
1300
+ }
1301
+ else if ( gd . shareplot ) {
1302
+ newheight = $ ( window ) . height ( ) - $ ( '#banner' ) . height ( ) ;
1303
+ newwidth = $ ( window ) . width ( ) - parseInt ( $ ( '#embedded-graph' ) . css ( 'padding-left' ) || 0 , 10 ) ;
1304
+ if ( gd . standalone ) {
1305
+ // full-page shareplot - restrict aspect ratio to between 2:1 and 1:2,
1306
+ // but only change height to do this
1307
+ newheight = Plotly . Lib . constrain ( newheight , newwidth / 2 , newwidth * 2 ) ;
1308
+ }
1309
+ // else embedded in an iframe - just take the full iframe size if we get
1310
+ // to this point, with no aspect ratio restrictions
1297
1311
}
1298
1312
else {
1313
+ // plotly.js - let the developers do what they want, either provide height and width
1314
+ // for the container div, specify size in layout, or take the defaults, but don't
1315
+ // enforce any ratio restrictions
1299
1316
newheight = $ ( gd ) . height ( ) || gd . layout . height || defaultLayout ( ) . height ;
1300
1317
newwidth = $ ( gd ) . width ( ) || gd . layout . width || defaultLayout ( ) . width ;
1301
1318
// delete aobj.autosize;
@@ -1305,24 +1322,26 @@ function plotAutoSize(gd, aobj) {
1305
1322
gd . layout . height = newheight ;
1306
1323
gd . layout . width = newwidth ;
1307
1324
}
1308
- // if there's no size change, update layout but only restyle (different
1309
- // element may get margin color)
1325
+ // if there's no size change, update layout but delete the autosize attr so we don't redraw
1326
+ // REMOVED: call restyle (different element may get margin color)
1310
1327
else if ( gd . layout . autosize != 'initial' ) { // can't call layoutStyles for initial autosize
1311
1328
delete ( aobj . autosize ) ;
1312
1329
gd . layout . autosize = true ;
1313
- layoutStyles ( gd ) ;
1330
+ // layoutStyles(gd);
1314
1331
}
1315
1332
return aobj ;
1316
1333
}
1317
1334
1318
1335
// check whether to resize a tab (if it's a plot) to the container
1319
1336
plots . resize = function ( gd ) {
1320
1337
if ( typeof gd == 'string' ) { gd = document . getElementById ( gd ) ; }
1321
- killPopovers ( ) ;
1322
1338
1323
- if ( gd . mainsite ) { setFileAndCommentsHeight ( gd ) ; }
1339
+ if ( gd . mainsite ) {
1340
+ killPopovers ( ) ;
1341
+ setFileAndCommentsHeight ( gd ) ;
1342
+ }
1324
1343
1325
- if ( gd && gd . tabtype == 'plot' && $ ( gd ) . css ( 'display' ) != 'none' ) {
1344
+ if ( gd && ( gd . tabtype == 'plot' || gd . shareplot ) && $ ( gd ) . css ( 'display' ) != 'none' ) {
1326
1345
if ( gd . redrawTimer ) { clearTimeout ( gd . redrawTimer ) ; }
1327
1346
gd . redrawTimer = setTimeout ( function ( ) {
1328
1347
@@ -1336,7 +1355,7 @@ plots.resize = function(gd) {
1336
1355
gd . changed = oldchanged ; // autosizing doesn't count as a change
1337
1356
}
1338
1357
1339
- if ( LIT ) {
1358
+ if ( window . LIT ) {
1340
1359
hidebox ( ) ;
1341
1360
litebox ( ) ;
1342
1361
}
@@ -1363,7 +1382,7 @@ function makePlotFramework(divid, layout) {
1363
1382
// test if this is on the main site or embedded
1364
1383
gd . mainsite = $ ( '#plotlyMainMarker' ) . length > 0 ;
1365
1384
1366
- // hook class for plots main container (in case of plotly.js this won't be #embedded_graph or .js-tab-contents)
1385
+ // hook class for plots main container (in case of plotly.js this won't be #embedded-graph or .js-tab-contents)
1367
1386
// almost nobody actually needs this anymore, but just to be safe...
1368
1387
$gd . addClass ( 'js-plotly-plot' ) ;
1369
1388
0 commit comments