@@ -50,7 +50,7 @@ function render(scene) {
50
50
var lastPicked = null ;
51
51
var selection = scene . glplot . selection ;
52
52
for ( var i = 0 ; i < keys . length ; ++ i ) {
53
- var trace = scene . traces [ keys [ i ] ] ;
53
+ trace = scene . traces [ keys [ i ] ] ;
54
54
if ( trace . handlePick ( selection ) ) {
55
55
lastPicked = trace ;
56
56
}
@@ -172,6 +172,15 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) {
172
172
showNoWebGlMsg ( scene ) ;
173
173
}
174
174
175
+ var relayoutCallback = function ( scene , domEvent ) {
176
+ var update = { } ;
177
+ update [ scene . id ] = getLayoutCamera ( scene . camera ) ;
178
+ scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
179
+ } ;
180
+
181
+ scene . glplot . canvas . addEventListener ( 'mouseup' , relayoutCallback . bind ( null , scene ) ) ;
182
+ scene . glplot . canvas . addEventListener ( 'wheel' , relayoutCallback . bind ( null , scene ) ) ;
183
+
175
184
if ( ! scene . staticMode ) {
176
185
scene . glplot . canvas . addEventListener ( 'webglcontextlost' , function ( ev ) {
177
186
console . log ( 'lost context' ) ;
@@ -255,7 +264,7 @@ function Scene(options, fullLayout) {
255
264
256
265
this . contourLevels = [ [ ] , [ ] , [ ] ] ;
257
266
258
- if ( ! initializeGLPlot ( this , fullLayout ) ) return ;
267
+ if ( ! initializeGLPlot ( this , fullLayout ) ) return ; // todo check the necessity for this line
259
268
}
260
269
261
270
var proto = Scene . prototype ;
@@ -286,7 +295,7 @@ function coordinateBound(axis, coord, d, bounds) {
286
295
for ( var i = 0 ; i < coord . length ; ++ i ) {
287
296
if ( Array . isArray ( coord [ i ] ) ) {
288
297
for ( var j = 0 ; j < coord [ i ] . length ; ++ j ) {
289
- var x = axis . d2l ( coord [ i ] [ j ] ) ;
298
+ x = axis . d2l ( coord [ i ] [ j ] ) ;
290
299
if ( ! isNaN ( x ) && isFinite ( x ) ) {
291
300
bounds [ 0 ] [ d ] = Math . min ( bounds [ 0 ] [ d ] , x ) ;
292
301
bounds [ 1 ] [ d ] = Math . max ( bounds [ 1 ] [ d ] , x ) ;
@@ -354,14 +363,14 @@ proto.plot = function(sceneData, fullLayout, layout) {
354
363
[ Infinity , Infinity , Infinity ] ,
355
364
[ - Infinity , - Infinity , - Infinity ]
356
365
] ;
357
- for ( var i = 0 ; i < sceneData . length ; ++ i ) {
358
- var data = sceneData [ i ] ;
366
+ for ( i = 0 ; i < sceneData . length ; ++ i ) {
367
+ data = sceneData [ i ] ;
359
368
if ( data . visible !== true ) continue ;
360
369
361
370
computeTraceBounds ( this , data , dataBounds ) ;
362
371
}
363
372
var dataScale = [ 1 , 1 , 1 ] ;
364
- for ( var j = 0 ; j < 3 ; ++ j ) {
373
+ for ( j = 0 ; j < 3 ; ++ j ) {
365
374
if ( dataBounds [ 0 ] [ j ] > dataBounds [ 1 ] [ j ] ) {
366
375
dataScale [ j ] = 1.0 ;
367
376
}
@@ -379,7 +388,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
379
388
this . dataScale = dataScale ;
380
389
381
390
//Update traces
382
- for ( var i = 0 ; i < sceneData . length ; ++ i ) {
391
+ for ( i = 0 ; i < sceneData . length ; ++ i ) {
383
392
data = sceneData [ i ] ;
384
393
if ( data . visible !== true ) {
385
394
continue ;
@@ -416,7 +425,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
416
425
axisTypeRatios = { } ;
417
426
418
427
for ( i = 0 ; i < 3 ; ++ i ) {
419
- var axis = fullSceneLayout [ axisProperties [ i ] ] ;
428
+ axis = fullSceneLayout [ axisProperties [ i ] ] ;
420
429
var axisType = axis . type ;
421
430
422
431
if ( axisType in axisTypeRatios ) {
@@ -471,9 +480,9 @@ proto.plot = function(sceneData, fullLayout, layout) {
471
480
var axesScaleRatio = [ 1 , 1 , 1 ] ;
472
481
473
482
//Compute axis scale per category
474
- for ( var i = 0 ; i < 3 ; ++ i ) {
475
- var axis = fullSceneLayout [ axisProperties [ i ] ] ;
476
- var axisType = axis . type ;
483
+ for ( i = 0 ; i < 3 ; ++ i ) {
484
+ axis = fullSceneLayout [ axisProperties [ i ] ] ;
485
+ axisType = axis . type ;
477
486
var axisRatio = axisTypeRatios [ axisType ] ;
478
487
axesScaleRatio [ i ] = Math . pow ( axisRatio . acc , 1.0 / axisRatio . count ) / dataScale [ i ] ;
479
488
}
@@ -567,33 +576,35 @@ proto.setCameraToDefault = function setCameraToDefault() {
567
576
} ) ;
568
577
} ;
569
578
570
- // get camera position in plotly coords from 'orbit-camera' coords
571
- proto . getCamera = function getCamera ( ) {
572
- this . glplot . camera . view . recalcMatrix ( this . camera . view . lastT ( ) ) ;
573
-
574
- var up = this . glplot . camera . up ;
575
- var center = this . glplot . camera . center ;
576
- var eye = this . glplot . camera . eye ;
579
+ // getOrbitCamera :: plotly_coords -> orbit_camera_coords
580
+ // inverse of getLayoutCamera
581
+ function getOrbitCamera ( camera ) {
582
+ return [
583
+ [ camera . eye . x , camera . eye . y , camera . eye . z ] ,
584
+ [ camera . center . x , camera . center . y , camera . center . z ] ,
585
+ [ camera . up . x , camera . up . y , camera . up . z ]
586
+ ] ;
587
+ }
577
588
589
+ // getLayoutCamera :: orbit_camera_coords -> plotly_coords
590
+ // inverse of getOrbitCamera
591
+ function getLayoutCamera ( camera ) {
578
592
return {
579
- up : { x : up [ 0 ] , y : up [ 1 ] , z : up [ 2 ] } ,
580
- center : { x : center [ 0 ] , y : center [ 1 ] , z : center [ 2 ] } ,
581
- eye : { x : eye [ 0 ] , y : eye [ 1 ] , z : eye [ 2 ] }
593
+ up : { x : camera . up [ 0 ] , y : camera . up [ 1 ] , z : camera . up [ 2 ] } ,
594
+ center : { x : camera . center [ 0 ] , y : camera . center [ 1 ] , z : camera . center [ 2 ] } ,
595
+ eye : { x : camera . eye [ 0 ] , y : camera . eye [ 1 ] , z : camera . eye [ 2 ] }
582
596
} ;
597
+ }
598
+
599
+ // get camera position in plotly coords from 'orbit-camera' coords
600
+ proto . getCamera = function getCamera ( ) {
601
+ this . glplot . camera . view . recalcMatrix ( this . camera . view . lastT ( ) ) ;
602
+ return getLayoutCamera ( this . glplot . camera ) ;
583
603
} ;
584
604
585
605
// set camera position with a set of plotly coords
586
606
proto . setCamera = function setCamera ( cameraData ) {
587
607
588
- // getOrbitCamera :: plotly_coords -> orbit_camera_coords
589
- function getOrbitCamera ( camera ) {
590
- return [
591
- [ camera . eye . x , camera . eye . y , camera . eye . z ] ,
592
- [ camera . center . x , camera . center . y , camera . center . z ] ,
593
- [ camera . up . x , camera . up . y , camera . up . z ]
594
- ] ;
595
- }
596
-
597
608
var update = { } ;
598
609
599
610
update [ this . id ] = cameraData ;
0 commit comments