@@ -36,14 +36,19 @@ describe('Test gl plot interactions', function() {
3636
3737 sceneIds = Plots . getSubplotIds ( fullLayout , 'gl3d' ) ;
3838 sceneIds . forEach ( function ( id ) {
39- fullLayout [ id ] . _scene . destroy ( ) ;
39+ var scene = fullLayout [ id ] . _scene ;
40+
41+ if ( scene . glplot ) scene . destroy ( ) ;
4042 } ) ;
4143
4244 sceneIds = Plots . getSubplotIds ( fullLayout , 'gl2d' ) ;
4345 sceneIds . forEach ( function ( id ) {
4446 var scene2d = fullLayout . _plots [ id ] . _scene2d ;
45- scene2d . stopped = true ;
46- scene2d . destroy ( ) ;
47+
48+ if ( scene2d . glplot ) {
49+ scene2d . stopped = true ;
50+ scene2d . destroy ( ) ;
51+ }
4752 } ) ;
4853
4954 destroyGraphDiv ( ) ;
@@ -369,4 +374,43 @@ describe('Test gl plot interactions', function() {
369374 } ) ;
370375
371376 } ) ;
377+
378+ describe ( 'Plots.cleanPlot' , function ( ) {
379+
380+ it ( 'should remove gl context from the graph div of a gl3d plot' , function ( done ) {
381+ gd = createGraphDiv ( ) ;
382+
383+ var mockData = [ {
384+ type : 'scatter3d'
385+ } ] ;
386+
387+ Plotly . plot ( gd , mockData ) . then ( function ( ) {
388+ expect ( gd . _fullLayout . scene . _scene . glplot ) . toBeDefined ( ) ;
389+
390+ Plots . cleanPlot ( [ ] , { } , gd . _fullData , gd . _fullLayout ) ;
391+ expect ( gd . _fullLayout . scene . _scene . glplot ) . toBe ( null ) ;
392+
393+ done ( ) ;
394+ } ) ;
395+ } ) ;
396+
397+ it ( 'should remove gl context from the graph div of a gl2d plot' , function ( done ) {
398+ gd = createGraphDiv ( ) ;
399+
400+ var mockData = [ {
401+ type : 'scattergl' ,
402+ x : [ 1 , 2 , 3 ] ,
403+ y : [ 1 , 2 , 3 ]
404+ } ] ;
405+
406+ Plotly . plot ( gd , mockData ) . then ( function ( ) {
407+ expect ( gd . _fullLayout . _plots . xy . _scene2d . glplot ) . toBeDefined ( ) ;
408+
409+ Plots . cleanPlot ( [ ] , { } , gd . _fullData , gd . _fullLayout ) ;
410+ expect ( gd . _fullLayout . _plots . xy . _scene2d . glplot ) . toBe ( null ) ;
411+
412+ done ( ) ;
413+ } ) ;
414+ } ) ;
415+ } ) ;
372416} ) ;
0 commit comments