@@ -488,7 +488,109 @@ describe('Test gl plot interactions', function() {
488488 expect ( buttonHover . isActive ( ) ) . toBe ( true ) ;
489489 } ) ;
490490
491+ it ( 'button resetCameraDefault3d should reset camera to default' , function ( done ) {
492+ var buttonDefault = selectButton ( modeBar , 'resetCameraDefault3d' ) ;
493+
494+ expect ( gd . _fullLayout . scene . _scene . cameraInitial . eye ) . toEqual ( { x : 0.1 , y : 0.1 , z : 1 } ) ;
495+ expect ( gd . _fullLayout . scene2 . _scene . cameraInitial . eye ) . toEqual ( { x : 2.5 , y : 2.5 , z : 2.5 } ) ;
496+
497+ gd . once ( 'plotly_relayout' , function ( ) {
498+ assertScenes ( gd . _fullLayout , 'camera.eye.x' , 1.25 ) ;
499+ assertScenes ( gd . _fullLayout , 'camera.eye.y' , 1.25 ) ;
500+ assertScenes ( gd . _fullLayout , 'camera.eye.z' , 1.25 ) ;
501+
502+ expect ( gd . _fullLayout . scene . _scene . getCamera ( ) . eye . z ) . toBeCloseTo ( 1.25 ) ;
503+ expect ( gd . _fullLayout . scene2 . _scene . getCamera ( ) . eye . z ) . toBeCloseTo ( 1.25 ) ;
504+
505+ done ( ) ;
491506 } ) ;
507+
508+ buttonDefault . click ( ) ;
509+ } ) ;
510+
511+ it ( 'button resetCameraLastSave3d should reset camera to default' , function ( done ) {
512+ var buttonDefault = selectButton ( modeBar , 'resetCameraDefault3d' ) ;
513+ var buttonLastSave = selectButton ( modeBar , 'resetCameraLastSave3d' ) ;
514+
515+ function assertCameraEye ( sceneLayout , eyeX , eyeY , eyeZ ) {
516+ expect ( sceneLayout . camera . eye . x ) . toEqual ( eyeX ) ;
517+ expect ( sceneLayout . camera . eye . y ) . toEqual ( eyeY ) ;
518+ expect ( sceneLayout . camera . eye . z ) . toEqual ( eyeZ ) ;
519+
520+ var camera = sceneLayout . _scene . getCamera ( ) ;
521+ expect ( camera . eye . x ) . toBeCloseTo ( eyeX ) ;
522+ expect ( camera . eye . y ) . toBeCloseTo ( eyeY ) ;
523+ expect ( camera . eye . z ) . toBeCloseTo ( eyeZ ) ;
524+ }
525+
526+ Plotly . relayout ( gd , {
527+ 'scene.camera.eye.z' : 4 ,
528+ 'scene2.camera.eye.z' : 5
529+ } )
530+ . then ( function ( ) {
531+ assertCameraEye ( gd . _fullLayout . scene , 0.1 , 0.1 , 4 ) ;
532+ assertCameraEye ( gd . _fullLayout . scene2 , 2.5 , 2.5 , 5 ) ;
533+
534+ return new Promise ( function ( resolve ) {
535+ gd . once ( 'plotly_relayout' , resolve ) ;
536+ buttonLastSave . click ( ) ;
537+ } ) ;
538+ } )
539+ . then ( function ( ) {
540+ assertCameraEye ( gd . _fullLayout . scene , 0.1 , 0.1 , 1 ) ;
541+ assertCameraEye ( gd . _fullLayout . scene2 , 2.5 , 2.5 , 2.5 ) ;
542+
543+ return new Promise ( function ( resolve ) {
544+ gd . once ( 'plotly_relayout' , resolve ) ;
545+ buttonDefault . click ( ) ;
546+ } ) ;
547+ } )
548+ . then ( function ( ) {
549+ assertCameraEye ( gd . _fullLayout . scene , 1.25 , 1.25 , 1.25 ) ;
550+ assertCameraEye ( gd . _fullLayout . scene2 , 1.25 , 1.25 , 1.25 ) ;
551+
552+ return new Promise ( function ( resolve ) {
553+ gd . once ( 'plotly_relayout' , resolve ) ;
554+ buttonLastSave . click ( ) ;
555+ } ) ;
556+ } )
557+ . then ( function ( ) {
558+ assertCameraEye ( gd . _fullLayout . scene , 0.1 , 0.1 , 1 ) ;
559+ assertCameraEye ( gd . _fullLayout . scene2 , 2.5 , 2.5 , 2.5 ) ;
560+
561+ delete gd . _fullLayout . scene . _scene . cameraInitial ;
562+ delete gd . _fullLayout . scene2 . _scene . cameraInitial ;
563+
564+ Plotly . relayout ( gd , {
565+ 'scene.bgcolor' : '#d3d3d3' ,
566+ 'scene.camera.eye.z' : 4 ,
567+ 'scene2.camera.eye.z' : 5
568+ } ) ;
569+ } )
570+ . then ( function ( ) {
571+ assertCameraEye ( gd . _fullLayout . scene , 0.1 , 0.1 , 4 ) ;
572+ assertCameraEye ( gd . _fullLayout . scene2 , 2.5 , 2.5 , 5 ) ;
573+
574+ return new Promise ( function ( resolve ) {
575+ gd . once ( 'plotly_relayout' , resolve ) ;
576+ buttonDefault . click ( ) ;
577+ } ) ;
578+ } )
579+ . then ( function ( ) {
580+ assertCameraEye ( gd . _fullLayout . scene , 1.25 , 1.25 , 1.25 ) ;
581+ assertCameraEye ( gd . _fullLayout . scene2 , 1.25 , 1.25 , 1.25 ) ;
582+
583+ return new Promise ( function ( resolve ) {
584+ gd . once ( 'plotly_relayout' , resolve ) ;
585+ buttonLastSave . click ( ) ;
586+ } ) ;
587+ } )
588+ . then ( function ( ) {
589+ assertCameraEye ( gd . _fullLayout . scene , 0.1 , 0.1 , 4 ) ;
590+ assertCameraEye ( gd . _fullLayout . scene2 , 2.5 , 2.5 , 5 ) ;
591+ } )
592+ . then ( done ) ;
593+
492594 } ) ;
493595 } ) ;
494596
0 commit comments