@@ -218,6 +218,8 @@ class PlotlyGraph extends Component {
218
218
const clearState = props . clearState ;
219
219
const dataArray = props [ dataKey ] ;
220
220
221
+ let p = Promise . resolve ( ) ;
222
+
221
223
dataArray . forEach ( data => {
222
224
let updateData , traceIndices , maxPoints ;
223
225
if ( Array . isArray ( data ) && typeof data [ 0 ] === 'object' ) {
@@ -237,11 +239,16 @@ class PlotlyGraph extends Component {
237
239
traceIndices = generateIndices ( updateData ) ;
238
240
}
239
241
240
- const gd = this . gd . current ;
241
- return Plotly [ plotlyFnKey ] ( gd , updateData , traceIndices , maxPoints ) ;
242
+ p = p . then ( ( ) => {
243
+ const gd = this . gd . current ;
244
+ return (
245
+ gd &&
246
+ Plotly [ plotlyFnKey ] ( gd , updateData , traceIndices , maxPoints )
247
+ ) ;
248
+ } ) ;
242
249
} ) ;
243
250
244
- clearState ( dataKey ) ;
251
+ p . then ( ( ) => clearState ( dataKey ) ) ;
245
252
}
246
253
247
254
getConfig ( config , responsive ) {
@@ -393,16 +400,22 @@ class PlotlyGraph extends Component {
393
400
}
394
401
395
402
componentDidMount ( ) {
396
- this . plot ( this . props ) ;
403
+ let p = this . plot ( this . props ) ;
397
404
if ( this . props . prependData ) {
398
- this . mergeTraces ( this . props , 'prependData' , 'prependTraces' ) ;
405
+ p = p . then ( ( ) =>
406
+ this . mergeTraces ( this . props , 'prependData' , 'prependTraces' )
407
+ ) ;
399
408
}
400
409
if ( this . props . extendData ) {
401
- this . mergeTraces ( this . props , 'extendData' , 'extendTraces' ) ;
410
+ p = p . then ( ( ) =>
411
+ this . mergeTraces ( this . props , 'extendData' , 'extendTraces' )
412
+ ) ;
402
413
}
403
414
404
415
if ( this . props . prependData ?. length || this . props . extendData ?. length ) {
405
- this . props . _dashprivate_onFigureModified ( this . props . figure ) ;
416
+ p . then ( ( ) =>
417
+ this . props . _dashprivate_onFigureModified ( this . props . figure )
418
+ ) ;
406
419
}
407
420
}
408
421
@@ -435,6 +448,8 @@ class PlotlyGraph extends Component {
435
448
*/
436
449
return ;
437
450
}
451
+
452
+ let p = Promise . resolve ( ) ;
438
453
if (
439
454
this . props . mathjax !== nextProps . mathjax ||
440
455
this . props . figure !== nextProps . figure ||
@@ -443,19 +458,25 @@ class PlotlyGraph extends Component {
443
458
this . props . _dashprivate_transformFigure !==
444
459
nextProps . _dashprivate_transformFigure
445
460
) {
446
- this . plot ( nextProps ) ;
461
+ p = this . plot ( nextProps ) ;
447
462
}
448
463
449
464
if ( this . props . prependData !== nextProps . prependData ) {
450
- this . mergeTraces ( nextProps , 'prependData' , 'prependTraces' ) ;
465
+ p = p . then ( ( ) =>
466
+ this . mergeTraces ( nextProps , 'prependData' , 'prependTraces' )
467
+ ) ;
451
468
}
452
469
453
470
if ( this . props . extendData !== nextProps . extendData ) {
454
- this . mergeTraces ( nextProps , 'extendData' , 'extendTraces' ) ;
471
+ p = p . then ( ( ) =>
472
+ this . mergeTraces ( nextProps , 'extendData' , 'extendTraces' )
473
+ ) ;
455
474
}
456
475
457
476
if ( this . props . prependData ?. length || this . props . extendData ?. length ) {
458
- this . props . _dashprivate_onFigureModified ( this . props . figure ) ;
477
+ p . then ( ( ) =>
478
+ this . props . _dashprivate_onFigureModified ( this . props . figure )
479
+ ) ;
459
480
}
460
481
}
461
482
0 commit comments