@@ -356,7 +356,7 @@ Plotly.plot = function(gd, data, layout, config) {
356
356
// even if everything we did was synchronous, return a promise
357
357
// so that the caller doesn't care which route we took
358
358
return ( donePlotting && donePlotting . then ) ?
359
- donePlotting : Promise . resolve ( ) ;
359
+ donePlotting : Promise . resolve ( gd ) ;
360
360
} ;
361
361
362
362
// Get the container div: we store all variables for this plot as
@@ -926,6 +926,7 @@ Plotly.redraw = function(gd) {
926
926
gd . calcdata = undefined ;
927
927
return Plotly . plot ( gd ) . then ( function ( ) {
928
928
gd . emit ( 'plotly_redraw' ) ;
929
+ return gd ;
929
930
} ) ;
930
931
} ;
931
932
@@ -1361,12 +1362,14 @@ Plotly.extendTraces = function extendTraces (gd, update, indices, maxPoints) {
1361
1362
return target . splice ( 0 , target . length - maxPoints ) ;
1362
1363
} ) ;
1363
1364
1364
- Plotly . redraw ( gd ) ;
1365
+ var promise = Plotly . redraw ( gd ) ;
1365
1366
1366
1367
var undoArgs = [ gd , undo . update , indices , undo . maxPoints ] ;
1367
1368
if ( Plotly . Queue ) {
1368
1369
Plotly . Queue . add ( gd , Plotly . prependTraces , undoArgs , extendTraces , arguments ) ;
1369
1370
}
1371
+
1372
+ return promise ;
1370
1373
} ;
1371
1374
1372
1375
Plotly . prependTraces = function prependTraces ( gd , update , indices , maxPoints ) {
@@ -1388,12 +1391,14 @@ Plotly.prependTraces = function prependTraces (gd, update, indices, maxPoints)
1388
1391
return target . splice ( maxPoints , target . length ) ;
1389
1392
} ) ;
1390
1393
1391
- Plotly . redraw ( gd ) ;
1394
+ var promise = Plotly . redraw ( gd ) ;
1392
1395
1393
1396
var undoArgs = [ gd , undo . update , indices , undo . maxPoints ] ;
1394
1397
if ( Plotly . Queue ) {
1395
1398
Plotly . Queue . add ( gd , Plotly . extendTraces , undoArgs , prependTraces , arguments ) ;
1396
1399
}
1400
+
1401
+ return promise ;
1397
1402
} ;
1398
1403
1399
1404
/**
@@ -1436,9 +1441,9 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) {
1436
1441
// if the user didn't define newIndices, they just want the traces appended
1437
1442
// i.e., we can simply redraw and be done
1438
1443
if ( typeof newIndices === 'undefined' ) {
1439
- Plotly . redraw ( gd ) ;
1444
+ var promise = Plotly . redraw ( gd ) ;
1440
1445
if ( Plotly . Queue ) Plotly . Queue . add ( gd , undoFunc , undoArgs , redoFunc , redoArgs ) ;
1441
- return ;
1446
+ return promise ;
1442
1447
}
1443
1448
1444
1449
// make sure indices is property defined
@@ -1462,8 +1467,9 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) {
1462
1467
// this requires some extra work that moveTraces will do
1463
1468
if ( Plotly . Queue ) Plotly . Queue . startSequence ( gd ) ;
1464
1469
if ( Plotly . Queue ) Plotly . Queue . add ( gd , undoFunc , undoArgs , redoFunc , redoArgs ) ;
1465
- Plotly . moveTraces ( gd , currentIndices , newIndices ) ;
1470
+ var promise = Plotly . moveTraces ( gd , currentIndices , newIndices ) ;
1466
1471
if ( Plotly . Queue ) Plotly . Queue . stopSequence ( gd ) ;
1472
+ return promise ;
1467
1473
} ;
1468
1474
1469
1475
/**
@@ -1502,9 +1508,11 @@ Plotly.deleteTraces = function deleteTraces (gd, indices) {
1502
1508
traces . push ( deletedTrace ) ;
1503
1509
}
1504
1510
1505
- Plotly . redraw ( gd ) ;
1511
+ var promise = Plotly . redraw ( gd ) ;
1506
1512
1507
1513
if ( Plotly . Queue ) Plotly . Queue . add ( gd , undoFunc , undoArgs , redoFunc , redoArgs ) ;
1514
+
1515
+ return promise ;
1508
1516
} ;
1509
1517
1510
1518
/**
@@ -1599,9 +1607,11 @@ Plotly.moveTraces = function moveTraces (gd, currentIndices, newIndices) {
1599
1607
1600
1608
gd . data = newData ;
1601
1609
1602
- Plotly . redraw ( gd ) ;
1610
+ var promise = Plotly . redraw ( gd ) ;
1603
1611
1604
1612
if ( Plotly . Queue ) Plotly . Queue . add ( gd , undoFunc , undoArgs , redoFunc , redoArgs ) ;
1613
+
1614
+ return promise ;
1605
1615
} ;
1606
1616
1607
1617
// -----------------------------------------------------
@@ -1640,7 +1650,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
1640
1650
}
1641
1651
else {
1642
1652
console . log ( 'restyle fail' , astr , val , traces ) ;
1643
- return ;
1653
+ return new Promise . reject ( ) ;
1644
1654
}
1645
1655
1646
1656
if ( Object . keys ( aobj ) . length ) gd . changed = true ;
@@ -2115,8 +2125,8 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
2115
2125
if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( ) ;
2116
2126
2117
2127
return plotDone . then ( function ( ) {
2118
- gd . emit ( 'plotly_restyle' ,
2119
- Plotly . Lib . extendDeep ( [ ] , [ redoit , traces ] ) ) ;
2128
+ gd . emit ( 'plotly_restyle' , Plotly . Lib . extendDeep ( [ ] , [ redoit , traces ] ) ) ;
2129
+ return gd ;
2120
2130
} ) ;
2121
2131
} ;
2122
2132
@@ -2161,7 +2171,9 @@ function swapXYData(trace) {
2161
2171
Plotly . relayout = function relayout ( gd , astr , val ) {
2162
2172
gd = getGraphDiv ( gd ) ;
2163
2173
2164
- if ( gd . framework && gd . framework . isPolar ) return ;
2174
+ if ( gd . framework && gd . framework . isPolar ) {
2175
+ return new Promise . resolve ( gd ) ;
2176
+ }
2165
2177
2166
2178
var layout = gd . layout ,
2167
2179
fullLayout = gd . _fullLayout ,
@@ -2178,7 +2190,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
2178
2190
else if ( Plotly . Lib . isPlainObject ( astr ) ) aobj = astr ;
2179
2191
else {
2180
2192
console . log ( 'relayout fail' , astr , val ) ;
2181
- return ;
2193
+ return new Promise . reject ( ) ;
2182
2194
}
2183
2195
2184
2196
if ( Object . keys ( aobj ) . length ) gd . changed = true ;
@@ -2484,11 +2496,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
2484
2496
2485
2497
var plotDone = Plotly . Lib . syncOrAsync ( seq , gd ) ;
2486
2498
2487
- if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( ) ;
2499
+ if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( gd ) ;
2488
2500
2489
2501
return plotDone . then ( function ( ) {
2490
2502
gd . emit ( 'plotly_relayout' ,
2491
2503
Plotly . Lib . extendDeep ( { } , redoit ) ) ;
2504
+ return gd ;
2492
2505
} ) ;
2493
2506
} ;
2494
2507
0 commit comments