File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -76,12 +76,15 @@ plots.redrawText = function(gd) {
7676plots . resize = function ( gd ) {
7777 gd = Lib . getGraphDiv ( gd ) ;
7878
79- return new Promise ( function ( resolve , reject ) {
79+ var resolveLastResize ;
80+ var p = new Promise ( function ( resolve , reject ) {
8081 if ( ! gd || Lib . isHidden ( gd ) ) {
8182 reject ( new Error ( 'Resize must be passed a displayed plot div element.' ) ) ;
8283 }
8384
8485 if ( gd . _redrawTimer ) clearTimeout ( gd . _redrawTimer ) ;
86+ if ( gd . _resolveResize ) resolveLastResize = gd . _resolveResize ;
87+ gd . _resolveResize = resolve ;
8588
8689 gd . _redrawTimer = setTimeout ( function ( ) {
8790 // return if there is nothing to resize or is hidden
@@ -101,10 +104,17 @@ plots.resize = function(gd) {
101104
102105 Registry . call ( 'relayout' , gd , { autosize : true } ) . then ( function ( ) {
103106 gd . changed = oldchanged ;
104- resolve ( gd ) ;
107+ // Only resolve if a new call hasn't been made!
108+ if ( gd . _resolveResize === resolve ) {
109+ delete gd . _resolveResize ;
110+ resolve ( gd ) ;
111+ }
105112 } ) ;
106113 } , 100 ) ;
107114 } ) ;
115+
116+ if ( resolveLastResize ) resolveLastResize ( p ) ;
117+ return p ;
108118} ;
109119
110120
Original file line number Diff line number Diff line change @@ -412,6 +412,31 @@ describe('Test Plots', function() {
412412 . then ( done ) ;
413413 } ) ;
414414 } ) ;
415+
416+ describe ( 'returns Promises' , function ( ) {
417+ afterEach ( destroyGraphDiv ) ;
418+
419+ it ( 'should resolve them all' , function ( done ) {
420+ gd = createGraphDiv ( ) ;
421+ var p = [ ] ;
422+ Plotly . newPlot ( gd , [ { y : [ 5 , 2 , 5 ] } ] )
423+ . then ( function ( ) {
424+ gd . style . width = '500px' ;
425+ gd . style . height = '500px' ;
426+ p . push ( Plotly . Plots . resize ( gd ) ) ;
427+ p . push ( Plotly . Plots . resize ( gd ) ) ;
428+ p . push ( Plotly . Plots . resize ( gd ) ) ;
429+ return Promise . all ( p ) ;
430+ } )
431+ . then ( function ( v ) {
432+ // Make sure they all resolve to the same value
433+ expect ( v [ 0 ] ) . toEqual ( v [ 1 ] ) ;
434+ expect ( v [ 1 ] ) . toEqual ( v [ 2 ] ) ;
435+ } )
436+ . catch ( failTest )
437+ . then ( done ) ;
438+ } ) ;
439+ } ) ;
415440 } ) ;
416441
417442 describe ( 'Plots.purge' , function ( ) {
You can’t perform that action at this time.
0 commit comments