@@ -1260,19 +1260,19 @@ function plotDo(gd,aobj,traces) {
1260
1260
}
1261
1261
1262
1262
function plotAutoSize ( gd , aobj ) {
1263
- var plotBB = gd . paper . node ( ) . getBoundingClientRect ( ) ;
1263
+ var plotBB = gd . paperdiv . node ( ) . getBoundingClientRect ( ) ;
1264
1264
var gdBB = gd . getBoundingClientRect ( ) ;
1265
- var ftBB = $ ( '#filetab' ) [ 0 ] . getBoundingClientRect ( ) ;
1265
+ var ftBB = $ ( '#filetab' ) . length ? $ ( '#filetab' ) [ 0 ] . getBoundingClientRect ( ) : { width : 0 } ;
1266
1266
var newheight = Math . round ( gdBB . bottom - plotBB . top ) ;
1267
1267
var newwidth = Math . round ( ( ftBB . width ? ftBB . left : gdBB . right ) - plotBB . left ) ;
1268
1268
if ( Math . abs ( gd . layout . width - newwidth ) > 1 || Math . abs ( gd . layout . height - newheight ) > 1 ) {
1269
1269
gd . layout . height = newheight ;
1270
1270
gd . layout . width = newwidth ;
1271
1271
}
1272
- else { // if there's no size change, update layout but don't need to redraw
1272
+ else { // if there's no size change, update layout but only restyle (different element may get margin color)
1273
1273
delete ( aobj . autosize ) ;
1274
1274
gd . layout . autosize = true ;
1275
- newModeBar ( gd ) ;
1275
+ layoutStyles ( gd ) ;
1276
1276
}
1277
1277
return aobj
1278
1278
}
@@ -1281,15 +1281,13 @@ function plotAutoSize(gd,aobj) {
1281
1281
function plotResize ( gd ) {
1282
1282
killPopovers ( ) ;
1283
1283
if ( gd && gd . tabtype == 'plot' && $ ( gd ) . css ( 'display' ) != 'none' ) {
1284
- $ ( gd ) . find ( '.modebar' ) . remove ( ) ;
1285
1284
if ( gd . redrawTimer ) { clearTimeout ( gd . redrawTimer ) }
1286
1285
gd . redrawTimer = setTimeout ( function ( ) {
1287
1286
if ( $ ( gd ) . css ( 'display' ) == 'none' ) { return }
1288
1287
if ( gd . layout && gd . layout . autosize ) {
1289
1288
gd . autoplay = true ; // don't include this relayout in the undo queue
1290
1289
relayout ( gd , { autosize :true } ) ;
1291
1290
}
1292
- else { newModeBar ( gd ) }
1293
1291
1294
1292
if ( LIT ) {
1295
1293
hidebox ( ) ;
@@ -1308,28 +1306,33 @@ function newPlot(divid, layout) {
1308
1306
// (for extension to multiple graphs per page)
1309
1307
// some callers send this in already by dom element
1310
1308
1311
- var gd = ( typeof divid == 'string' ) ? document . getElementById ( divid ) : divid ;
1309
+ var gd = ( typeof divid == 'string' ) ? document . getElementById ( divid ) : divid ,
1310
+ gd3 = d3 . select ( gd ) ;
1312
1311
if ( ! layout ) layout = { } ;
1313
1312
// test if this is on the main site or embedded
1314
1313
gd . mainsite = Boolean ( $ ( '#plotlyMainMarker' ) . length ) ;
1315
1314
1316
1315
// destroy any plot that already exists in this div
1317
1316
// first check if we can save the toolbars
1318
- if ( gd . mainsite ? ( $ ( gd ) . children ( '.graphbar' ) . length == 1 &&
1319
- $ ( gd ) . children ( '.demobar' ) . length == 1 &&
1320
- $ ( gd ) . children ( 'svg' ) . length == 1 &&
1321
- $ ( gd ) . children ( ) . length >= 3 ) : /* 4th child is graph tips alert div, then modebar... */
1322
- ( $ ( gd ) . children ( 'svg' ) . length == 1 )
1323
- ) { $ ( gd ) . children ( 'svg' ) . remove ( ) }
1317
+ if ( ( $ ( gd ) . children ( '.svgcontainer' ) . length == 1 ) && ( ! gd . mainsite ||
1318
+ ( $ ( gd ) . children ( '.graphbar' ) . length == 1 && $ ( gd ) . children ( '.demobar' ) . length == 1 ) ) ) {
1319
+ $ ( gd ) . children ( '.svgcontainer' ) . children ( 'svg' ) . remove ( )
1320
+ }
1324
1321
else { // not the right children (probably none, but in case something goes wrong redraw all)
1322
+ // TODO - remove tooltips here
1323
+ $ ( gd ) . find ( '[rel="tooltip"]' ) . tooltip ( 'destroy' ) ;
1325
1324
gd . innerHTML = '' ;
1326
- if ( gd . mainsite ) graphbar ( gd ) ;
1325
+ if ( gd . mainsite ) { graphbar ( gd ) }
1326
+ // Make the outer graph container
1327
+ gd . paperdiv = gd3 . append ( 'div' )
1328
+ . classed ( 'svgcontainer' , true )
1329
+ . style ( 'position' , 'relative' ) ;
1327
1330
}
1328
1331
1329
1332
// Get the layout info - take the default and update it with layout arg
1330
1333
gd . layout = updateObject ( defaultLayout ( ) , layout ) ;
1331
1334
1332
- var gl = gd . layout , gd3 = d3 . select ( gd ) , xa = gl . xaxis , ya = gl . yaxis ;
1335
+ var gl = gd . layout , xa = gl . xaxis , ya = gl . yaxis ;
1333
1336
Axes . setTypes ( gd ) ;
1334
1337
1335
1338
// initial autosize
@@ -1341,11 +1344,8 @@ function newPlot(divid, layout) {
1341
1344
gd . paper . remove ( ) ;
1342
1345
gl . autosize = true ;
1343
1346
}
1344
-
1345
1347
// Make the graph containers
1346
- gd . paper = gd3 . append ( 'svg' )
1347
- gd . paperbg = gd . paper . append ( 'rect' )
1348
- . style ( 'fill' , 'none' )
1348
+ gd . paper = gd . paperdiv . append ( 'svg' ) ;
1349
1349
gd . plotbg = gd . paper . append ( 'rect' )
1350
1350
. attr ( 'stroke-width' , 0 ) ;
1351
1351
gd . axlines = {
@@ -1399,8 +1399,6 @@ function newPlot(divid, layout) {
1399
1399
dragBox ( gd , x2 , y2 + y1 - y0 , x1 - x0 , y0 - y1 , 'n' , 'e' ) ;
1400
1400
dragBox ( gd , x0 , y1 , x1 - x0 , y0 - y1 , 's' , 'w' ) ;
1401
1401
dragBox ( gd , x2 , y1 , x1 - x0 , y0 - y1 , 's' , 'e' ) ;
1402
-
1403
- newModeBar ( gd ) ;
1404
1402
}
1405
1403
1406
1404
// layoutStyles: styling for plot layout elements
@@ -1423,20 +1421,19 @@ function layoutStyles(gd) {
1423
1421
gd . plotwidth = gl . width - gm . l - gm . r ;
1424
1422
gd . plotheight = gl . height - gm . t - gm . b ;
1425
1423
1426
- gd . paper
1427
- . call ( setSize , gl . width , gl . height ) ;
1428
- gd . paperbg
1429
- . call ( setRect , 0 , 0 , gl . width , gl . height ) ;
1424
+ gd . paperdiv . style ( { width :gl . width + 'px' , height :gl . height + 'px' } ) ;
1425
+ gd . paper . call ( setSize , gl . width , gl . height ) ;
1426
+
1430
1427
// plot background: color the whole div if it's autosized in the main site,
1431
1428
// so we don't always have a weird white strip with the "My Data" tab
1432
- // otherwise color the paperbg rect , so you see the plot the size it's meant to be.
1429
+ // otherwise color the paperdiv , so you see the plot the size it's meant to be.
1433
1430
if ( gl . autosize && gd . mainsite ) {
1434
1431
d3 . select ( gd ) . style ( 'background' , gl . paper_bgcolor ) ;
1435
- gd . paperbg . style ( 'fill ' , 'none ' ) ;
1432
+ gd . paperdiv . style ( 'background ' , 'transparent ' ) ;
1436
1433
}
1437
1434
else {
1438
1435
d3 . select ( gd ) . style ( 'background' , '#fff' ) ;
1439
- gd . paperbg . call ( fillColor , gl . paper_bgcolor ) ;
1436
+ gd . paperdiv . style ( 'background' , gl . paper_bgcolor ) ;
1440
1437
}
1441
1438
gd . plotbg
1442
1439
. call ( setRect , gm . l - gm . p , gm . t - gm . p , gd . plotwidth + 2 * gm . p , gd . plotheight + 2 * gm . p )
@@ -1460,6 +1457,8 @@ function layoutStyles(gd) {
1460
1457
. attr ( 'stroke-width' , ylw )
1461
1458
. call ( strokeColor , ya . linecolor ) ;
1462
1459
makeTitles ( gd , 'gtitle' ) ;
1460
+
1461
+ newModeBar ( gd ) ;
1463
1462
}
1464
1463
1465
1464
// ----------------------------------------------------
@@ -1544,7 +1543,7 @@ function makeTitles(gd,title) {
1544
1543
else { el . remove ( ) }
1545
1544
1546
1545
// move labels out of the way, if possible, when tick labels interfere
1547
- var titlebb = el [ 0 ] [ 0 ] . getBoundingClientRect ( ) , gdbb = gd . paper . node ( ) . getBoundingClientRect ( ) ;
1546
+ var titlebb = el [ 0 ] [ 0 ] . getBoundingClientRect ( ) , gdbb = gd . paperdiv . node ( ) . getBoundingClientRect ( ) ;
1548
1547
if ( k == 'xtitle' ) {
1549
1548
var labels = gd . paper . selectAll ( 'text.xtick' ) [ 0 ] , ticky = 0 ;
1550
1549
for ( var i = 0 ; i < labels . length ; i ++ ) {
@@ -1754,7 +1753,7 @@ function legend(gd) {
1754
1753
if ( Math . abs ( dy ) < MINDRAG ) { dy = 0 }
1755
1754
if ( dx || dy ) { gd . dragged = true }
1756
1755
el3 . call ( setPosition , x0 + dx , y0 + dy ) ;
1757
- var pbb = gd . paper . node ( ) . getBoundingClientRect ( ) ;
1756
+ var pbb = gd . paperdiv . node ( ) . getBoundingClientRect ( ) ;
1758
1757
1759
1758
// drag to within a couple px of edge to take the legend outside the plot
1760
1759
if ( e2 . clientX > pbb . right - 3 * MINDRAG || ( gd . lw > 0 && dx > - MINDRAG ) ) { xf = 100 }
@@ -1857,7 +1856,7 @@ function annotation(gd,index,opt,value) {
1857
1856
1858
1857
// get the paper and plot bounding boxes before adding pieces that go off screen
1859
1858
// firefox will include things that extend outside the original... can we avoid that?
1860
- var paperbb = gd . paper . node ( ) . getBoundingClientRect ( ) ,
1859
+ var paperbb = gd . paperdiv . node ( ) . getBoundingClientRect ( ) ,
1861
1860
plotbb = d3 . select ( gd ) . select ( '.nsewdrag' ) . node ( ) . getBoundingClientRect ( ) ,
1862
1861
x = plotbb . left - paperbb . left ,
1863
1862
y = plotbb . top - paperbb . top ;
0 commit comments