@@ -136,6 +136,8 @@ proto.prepareOptions = function() {
136136 return opts ;
137137} ;
138138
139+ var firstInit = true ;
140+
139141proto . tryCreatePlot = function ( ) {
140142 var scene = this ;
141143
@@ -146,7 +148,7 @@ proto.tryCreatePlot = function() {
146148 try {
147149 scene . glplot = createPlot ( opts ) ;
148150 } catch ( e ) {
149- if ( scene . staticMode ) {
151+ if ( scene . staticMode || ! firstInit ) {
150152 success = false ;
151153 } else { // try second time
152154 try {
@@ -158,15 +160,22 @@ proto.tryCreatePlot = function() {
158160 'The device may not be supported by is-mobile module!' ,
159161 'Inverting preserveDrawingBuffer option in second attempt to create webgl scene.'
160162 ] . join ( ' ' ) ) ;
163+
164+ // invert is-mobile
161165 isMobile = opts . glOptions . preserveDrawingBuffer = ! opts . glOptions . preserveDrawingBuffer ;
162166
163167 scene . glplot = createPlot ( opts ) ;
164168 } catch ( e ) {
169+ // revert changes to is-mobile
170+ isMobile = opts . glOptions . preserveDrawingBuffer = ! opts . glOptions . preserveDrawingBuffer ;
171+
165172 success = false ;
166173 }
167174 }
168175 }
169176
177+ firstInit = false ;
178+
170179 return success ;
171180} ;
172181
@@ -238,43 +247,45 @@ proto.initializeGLPlot = function() {
238247 scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
239248 } ;
240249
241- scene . glplot . canvas . addEventListener ( 'mouseup' , function ( ) {
242- relayoutCallback ( scene ) ;
243- } ) ;
250+ if ( scene . glplot . canvas ) {
251+ scene . glplot . canvas . addEventListener ( 'mouseup' , function ( ) {
252+ relayoutCallback ( scene ) ;
253+ } ) ;
244254
245- scene . glplot . canvas . addEventListener ( 'wheel' , function ( e ) {
246- if ( gd . _context . _scrollZoom . gl3d ) {
247- if ( scene . camera . _ortho ) {
248- var s = ( e . deltaX > e . deltaY ) ? 1.1 : 1.0 / 1.1 ;
249- var o = scene . glplot . getAspectratio ( ) ;
250- scene . glplot . setAspectratio ( {
251- x : s * o . x ,
252- y : s * o . y ,
253- z : s * o . z
254- } ) ;
255- }
255+ scene . glplot . canvas . addEventListener ( 'wheel' , function ( e ) {
256+ if ( gd . _context . _scrollZoom . gl3d ) {
257+ if ( scene . camera . _ortho ) {
258+ var s = ( e . deltaX > e . deltaY ) ? 1.1 : 1.0 / 1.1 ;
259+ var o = scene . glplot . getAspectratio ( ) ;
260+ scene . glplot . setAspectratio ( {
261+ x : s * o . x ,
262+ y : s * o . y ,
263+ z : s * o . z
264+ } ) ;
265+ }
256266
257- relayoutCallback ( scene ) ;
258- }
259- } , passiveSupported ? { passive : false } : false ) ;
267+ relayoutCallback ( scene ) ;
268+ }
269+ } , passiveSupported ? { passive : false } : false ) ;
260270
261- scene . glplot . canvas . addEventListener ( 'mousemove' , function ( ) {
262- if ( scene . fullSceneLayout . dragmode === false ) return ;
263- if ( scene . camera . mouseListener . buttons === 0 ) return ;
271+ scene . glplot . canvas . addEventListener ( 'mousemove' , function ( ) {
272+ if ( scene . fullSceneLayout . dragmode === false ) return ;
273+ if ( scene . camera . mouseListener . buttons === 0 ) return ;
264274
265- var update = makeUpdate ( ) ;
266- scene . graphDiv . emit ( 'plotly_relayouting' , update ) ;
267- } ) ;
275+ var update = makeUpdate ( ) ;
276+ scene . graphDiv . emit ( 'plotly_relayouting' , update ) ;
277+ } ) ;
268278
269- if ( ! scene . staticMode ) {
270- scene . glplot . canvas . addEventListener ( 'webglcontextlost' , function ( event ) {
271- if ( gd && gd . emit ) {
272- gd . emit ( 'plotly_webglcontextlost' , {
273- event : event ,
274- layer : scene . id
275- } ) ;
276- }
277- } , false ) ;
279+ if ( ! scene . staticMode ) {
280+ scene . glplot . canvas . addEventListener ( 'webglcontextlost' , function ( event ) {
281+ if ( gd && gd . emit ) {
282+ gd . emit ( 'plotly_webglcontextlost' , {
283+ event : event ,
284+ layer : scene . id
285+ } ) ;
286+ }
287+ } , false ) ;
288+ }
278289 }
279290
280291 scene . glplot . oncontextloss = function ( ) {
0 commit comments