@@ -591,32 +591,84 @@ describe('Test animate API', function() {
591591describe ( 'Animate API details' , function ( ) {
592592 'use strict' ;
593593
594- var gd , mockCopy ;
594+ var gd ;
595+ var dur = 30 ;
596+ var mockCopy ;
595597
596598 beforeEach ( function ( done ) {
597599 gd = createGraphDiv ( ) ;
598-
599600 mockCopy = Lib . extendDeep ( { } , mock ) ;
600-
601- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
602- return Plotly . addFrames ( gd , mockCopy . frames ) ;
603- } ) . then ( done ) ;
601+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
604602 } ) ;
605603
606604 afterEach ( function ( ) {
607605 Plotly . purge ( gd ) ;
608606 destroyGraphDiv ( ) ;
609607 } ) ;
610608
611- it ( 'null frames should not break everything' , function ( done ) {
612- gd . _transitionData . _frames . push ( null ) ;
609+ it ( 'redraws after a layout animation' , function ( done ) {
610+ var redraws = 0 ;
611+ gd . on ( 'plotly_redraw' , function ( ) { redraws ++ ; } ) ;
613612
614- Plotly . animate ( gd , null , {
615- frame : { duration : 0 } ,
616- transition : { duration : 0 }
613+ Plotly . animate ( gd ,
614+ { layout : { 'xaxis.range' : [ 0 , 1 ] } } ,
615+ { frame : { redraw : true , duration : dur } , transition : { duration : dur } }
616+ ) . then ( function ( ) {
617+ expect ( redraws ) . toBe ( 1 ) ;
617618 } ) . catch ( fail ) . then ( done ) ;
618619 } ) ;
619620
621+ it ( 'forces a relayout after layout animations' , function ( done ) {
622+ var relayouts = 0 ;
623+ var restyles = 0 ;
624+ var redraws = 0 ;
625+ gd . on ( 'plotly_relayout' , function ( ) { relayouts ++ ; } ) ;
626+ gd . on ( 'plotly_restyle' , function ( ) { restyles ++ ; } ) ;
627+ gd . on ( 'plotly_redraw' , function ( ) { redraws ++ ; } ) ;
628+
629+ Plotly . animate ( gd ,
630+ { layout : { 'xaxis.range' : [ 0 , 1 ] } } ,
631+ { frame : { redraw : false , duration : dur } , transition : { duration : dur } }
632+ ) . then ( function ( ) {
633+ expect ( relayouts ) . toBe ( 1 ) ;
634+ expect ( restyles ) . toBe ( 0 ) ;
635+ expect ( redraws ) . toBe ( 0 ) ;
636+ } ) . catch ( fail ) . then ( done ) ;
637+ } ) ;
638+
639+ it ( 'triggers plotly_animated after a single layout animation' , function ( done ) {
640+ var animateds = 0 ;
641+ gd . on ( 'plotly_animated' , function ( ) { animateds ++ ; } ) ;
642+
643+ Plotly . animate ( gd , [
644+ { layout : { 'xaxis.range' : [ 0 , 1 ] } } ,
645+ ] , { frame : { redraw : false , duration : dur } , transition : { duration : dur } }
646+ ) . then ( function ( ) {
647+ // Wait a bit just to be sure:
648+ setTimeout ( function ( ) {
649+ expect ( animateds ) . toBe ( 1 ) ;
650+ done ( ) ;
651+ } , dur ) ;
652+ } ) ;
653+ } ) ;
654+
655+ it ( 'triggers plotly_animated after a multi-step layout animation' , function ( done ) {
656+ var animateds = 0 ;
657+ gd . on ( 'plotly_animated' , function ( ) { animateds ++ ; } ) ;
658+
659+ Plotly . animate ( gd , [
660+ { layout : { 'xaxis.range' : [ 0 , 1 ] } } ,
661+ { layout : { 'xaxis.range' : [ 2 , 4 ] } } ,
662+ ] , { frame : { redraw : false , duration : dur } , transition : { duration : dur } }
663+ ) . then ( function ( ) {
664+ // Wait a bit just to be sure:
665+ setTimeout ( function ( ) {
666+ expect ( animateds ) . toBe ( 1 ) ;
667+ done ( ) ;
668+ } , dur ) ;
669+ } ) ;
670+ } ) ;
671+
620672 it ( 'does not fail if strings are not used' , function ( done ) {
621673 Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 8 , 7 , 6 ] } ] } ] ) . then ( function ( ) {
622674 // Verify it was added as a string name:
@@ -634,12 +686,23 @@ describe('Animate API details', function() {
634686 var cnt = 0 ;
635687 gd . on ( 'plotly_animatingframe' , function ( ) { cnt ++ ; } ) ;
636688
637- Plotly . animate ( gd , [ 'frame0' , null , undefined ] , { transition : { duration : 0 } , frame : { duration : 0 } } ) . then ( function ( ) {
689+ Plotly . addFrames ( gd , mockCopy . frames ) . then ( function ( ) {
690+ return Plotly . animate ( gd , [ 'frame0' , null , undefined ] , { transition : { duration : 0 } , frame : { duration : 0 } } ) ;
691+ } ) . then ( function ( ) {
638692 // Check only one animating was fired:
639693 expect ( cnt ) . toEqual ( 1 ) ;
640694
641695 // Check unused frames did not affect the current frame:
642696 expect ( gd . _fullLayout . _currentFrame ) . toEqual ( 'frame0' ) ;
643697 } ) . catch ( fail ) . then ( done ) ;
644698 } ) ;
699+
700+ it ( 'null frames should not break everything' , function ( done ) {
701+ gd . _transitionData . _frames . push ( null ) ;
702+
703+ Plotly . animate ( gd , null , {
704+ frame : { duration : 0 } ,
705+ transition : { duration : 0 }
706+ } ) . catch ( fail ) . then ( done ) ;
707+ } ) ;
645708} ) ;
0 commit comments