@@ -136,6 +136,8 @@ proto.prepareOptions = function() {
136
136
return opts ;
137
137
} ;
138
138
139
+ var firstInit = true ;
140
+
139
141
proto . tryCreatePlot = function ( ) {
140
142
var scene = this ;
141
143
@@ -146,7 +148,7 @@ proto.tryCreatePlot = function() {
146
148
try {
147
149
scene . glplot = createPlot ( opts ) ;
148
150
} catch ( e ) {
149
- if ( scene . staticMode ) {
151
+ if ( scene . staticMode || ! firstInit ) {
150
152
success = false ;
151
153
} else { // try second time
152
154
try {
@@ -158,15 +160,22 @@ proto.tryCreatePlot = function() {
158
160
'The device may not be supported by is-mobile module!' ,
159
161
'Inverting preserveDrawingBuffer option in second attempt to create webgl scene.'
160
162
] . join ( ' ' ) ) ;
163
+
164
+ // invert is-mobile
161
165
isMobile = opts . glOptions . preserveDrawingBuffer = ! opts . glOptions . preserveDrawingBuffer ;
162
166
163
167
scene . glplot = createPlot ( opts ) ;
164
168
} catch ( e ) {
169
+ // revert changes to is-mobile
170
+ isMobile = opts . glOptions . preserveDrawingBuffer = ! opts . glOptions . preserveDrawingBuffer ;
171
+
165
172
success = false ;
166
173
}
167
174
}
168
175
}
169
176
177
+ firstInit = false ;
178
+
170
179
return success ;
171
180
} ;
172
181
@@ -238,43 +247,45 @@ proto.initializeGLPlot = function() {
238
247
scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
239
248
} ;
240
249
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
+ } ) ;
244
254
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
+ }
256
266
257
- relayoutCallback ( scene ) ;
258
- }
259
- } , passiveSupported ? { passive : false } : false ) ;
267
+ relayoutCallback ( scene ) ;
268
+ }
269
+ } , passiveSupported ? { passive : false } : false ) ;
260
270
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 ;
264
274
265
- var update = makeUpdate ( ) ;
266
- scene . graphDiv . emit ( 'plotly_relayouting' , update ) ;
267
- } ) ;
275
+ var update = makeUpdate ( ) ;
276
+ scene . graphDiv . emit ( 'plotly_relayouting' , update ) ;
277
+ } ) ;
268
278
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
+ }
278
289
}
279
290
280
291
scene . glplot . oncontextloss = function ( ) {
0 commit comments