@@ -268,8 +268,10 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
268268 // camera updates
269269 update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera ) ;
270270
271- // scene updates
272- update [ scene . id + '.aspectratio' ] = scene . glplot . getAspectratio ( ) ;
271+ if ( scene . camera . _ortho === true ) {
272+ // scene updates
273+ update [ scene . id + '.aspectratio' ] = scene . glplot . getAspectratio ( ) ;
274+ }
273275
274276 return update ;
275277 } ;
@@ -290,15 +292,12 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
290292 if ( gd . _context . _scrollZoom . gl3d ) {
291293 if ( scene . glplot . camera . _ortho ) {
292294 var s = ( e . deltaX > e . deltaY ) ? 1.1 : 1.0 / 1.1 ;
293-
294- var aspectratio = scene . fullSceneLayout . aspectratio ;
295-
296- aspectratio . x = scene . glplot . aspect [ 0 ] *= s ;
297- aspectratio . y = scene . glplot . aspect [ 1 ] *= s ;
298- aspectratio . z = scene . glplot . aspect [ 2 ] *= s ;
299-
300- scene . glplot . setAspectratio ( aspectratio ) ;
301- scene . glplot . redraw ( ) ;
295+ var o = scene . glplot . getAspectratio ( ) ;
296+ scene . glplot . setAspectratio ( {
297+ x : s * o . x ,
298+ y : s * o . y ,
299+ z : s * o . z
300+ } ) ;
302301 }
303302
304303 relayoutCallback ( scene ) ;
@@ -747,6 +746,15 @@ proto.plot = function(sceneData, fullLayout, layout) {
747746 */
748747 this . glplot . setAspectratio ( fullSceneLayout . aspectratio ) ;
749748
749+ // save 'initial' camera view settings for modebar button
750+ if ( ! this . viewInitial . aspectratio ) {
751+ this . viewInitial . aspectratio = {
752+ x : fullSceneLayout . aspectratio . x ,
753+ y : fullSceneLayout . aspectratio . y ,
754+ z : fullSceneLayout . aspectratio . z
755+ } ;
756+ }
757+
750758 // Update frame position for multi plots
751759 var domain = fullSceneLayout . domain || null ;
752760 var size = fullLayout . _size || null ;
@@ -841,25 +849,25 @@ proto.saveLayout = function saveLayout(layout) {
841849 var cameraNestedProp = Lib . nestedProperty ( layout , this . id + '.camera' ) ;
842850 var cameraDataLastSave = cameraNestedProp . get ( ) ;
843851
852+
844853 var aspectData = this . glplot . getAspectratio ( ) ;
845- var aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.camera ' ) ;
854+ var aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.aspectratio ' ) ;
846855 var aspectDataLastSave = aspectNestedProp . get ( ) ;
847856
848- var hasChanged = false ;
849-
850857 function same ( x , y , i , j ) {
851858 var vectors = [ 'up' , 'center' , 'eye' ] ;
852859 var components = [ 'x' , 'y' , 'z' ] ;
853860 return y [ vectors [ i ] ] && ( x [ vectors [ i ] ] [ components [ j ] ] === y [ vectors [ i ] ] [ components [ j ] ] ) ;
854861 }
855862
863+ var cameraChanged = false ;
856864 if ( cameraDataLastSave === undefined ) {
857- hasChanged = true ;
865+ cameraChanged = true ;
858866 } else {
859867 for ( var i = 0 ; i < 3 ; i ++ ) {
860868 for ( var j = 0 ; j < 3 ; j ++ ) {
861869 if ( ! same ( cameraData , cameraDataLastSave , i , j ) ) {
862- hasChanged = true ;
870+ cameraChanged = true ;
863871 break ;
864872 }
865873 }
@@ -868,37 +876,39 @@ proto.saveLayout = function saveLayout(layout) {
868876 if ( ! cameraDataLastSave . projection || (
869877 cameraData . projection &&
870878 cameraData . projection . type !== cameraDataLastSave . projection . type ) ) {
871- hasChanged = true ;
879+ cameraChanged = true ;
872880 }
873881 }
874882
875- if ( ! hasChanged ) {
876- if ( aspectDataLastSave === undefined ) {
877- hasChanged = true ;
878- } else {
879- if (
880- aspectDataLastSave . x !== aspectData . x ||
881- aspectDataLastSave . y !== aspectData . y ||
882- aspectDataLastSave . z !== aspectData . z
883- ) {
884- hasChanged = true ;
885- }
886- }
887- }
883+ var aspectChanged = (
884+ aspectDataLastSave === undefined || (
885+ aspectDataLastSave . x !== aspectData . x ||
886+ aspectDataLastSave . y !== aspectData . y ||
887+ aspectDataLastSave . z !== aspectData . z
888+ ) ) ;
888889
890+ var hasChanged = cameraChanged || aspectChanged ;
889891 if ( hasChanged ) {
890892 var preGUI = { } ;
891- preGUI [ this . id + '.camera' ] = cameraDataLastSave ;
892- preGUI [ this . id + '.aspectratio' ] = aspectDataLastSave ;
893+ if ( cameraChanged ) preGUI [ this . id + '.camera' ] = cameraDataLastSave ;
894+ if ( aspectChanged ) preGUI [ this . id + '.aspectratio' ] = aspectDataLastSave ;
893895 Registry . call ( '_storeDirectGUIEdit' , layout , fullLayout . _preGUI , preGUI ) ;
894896
895- cameraNestedProp . set ( cameraData ) ;
897+ if ( cameraChanged ) {
898+ cameraNestedProp . set ( cameraData ) ;
896899
897- var cameraFullNP = Lib . nestedProperty ( fullLayout , this . id + '.camera' ) ;
898- cameraFullNP . set ( cameraData ) ;
900+ var cameraFullNP = Lib . nestedProperty ( fullLayout , this . id + '.camera' ) ;
901+ cameraFullNP . set ( cameraData ) ;
902+ }
903+
904+ if ( aspectChanged ) {
905+ aspectNestedProp . set ( aspectData ) ;
899906
900- var aspectFullNP = Lib . nestedProperty ( fullLayout , this . id + '.aspectratio' ) ;
901- aspectFullNP . set ( aspectData ) ;
907+ var aspectFullNP = Lib . nestedProperty ( fullLayout , this . id + '.aspectratio' ) ;
908+ aspectFullNP . set ( aspectData ) ;
909+
910+ this . glplot . redraw ( ) ;
911+ }
902912 }
903913
904914 return hasChanged ;
0 commit comments