@@ -49,29 +49,28 @@ function MiddlewareStack() {
4949
5050} ;
5151
52- function Animation ( paper ) {
52+ function Animation ( paper , name ) {
5353 var that = this ; // Create a handle to the current animation
5454 this . paper = paper ;
5555 this . requestBall = this . paper . circle ( 0 , HORIZON , 5 ) . attr ( { fill : 'red' } ) ;
56+ this . name = name ;
5657
5758 this . steps = [ ] ;
5859
5960 this . addStep = function ( node ) {
6061 this . steps . push ( node ) ;
6162 } ;
6263
63- this . run = function ( ) {
64- for ( var i = 0 ; i < this . steps . length ; i += 1 ) {
65- console . log ( 'in run for node ' + i ) ;
66- this . animateRequestBall ( this . steps [ i ] ) ;
67- } ;
64+ this . run = function ( step ) {
65+ this . animateRequestBall ( this . steps [ step ] ) ;
6866 } ;
6967
7068 this . animateRequestBall = function ( destination ) {
7169 console . log ( 'in animate destination is ' + destination ) ;
7270 var centerOfNode = destination . startX + ARM_LEN + NODE_RADIUS ;
7371 var anim = Raphael . animation ( { cx : centerOfNode , cy : HORIZON } , SPEED , destination . highlightNode ) ;
7472 this . requestBall . animate ( anim ) ;
73+ destination = this . steps [ step ++ ] ;
7574 } ;
7675} ;
7776
@@ -85,7 +84,8 @@ function displayRailsMiddlewareStack() {
8584
8685 var p = new Raphael ( document . getElementById ( 'canvas_container' ) , 1000 , 500 ) ;
8786 var middlewares = new MiddlewareStack ( ) ;
88- var animation2 ;
87+ // global because it is initalized here but incremented in the animation.
88+ step = 0 ;
8989
9090 // Eventually this will be specific for each set of animations.
9191 // We will add nodes representing each of the middlewares in the stack we are displaying.
@@ -99,8 +99,9 @@ function displayRailsMiddlewareStack() {
9999 return middlewares ;
100100 }
101101
102+ // For each middleware stack, we will provide sets of animations
102103 animation1 = function ( ) {
103- var anim = new Animation ( p ) ;
104+ var anim = new Animation ( p , 'First Animation' ) ;
104105 anim . addStep ( middlewares . nodes [ 0 ] ) ;
105106 anim . addStep ( middlewares . nodes [ 1 ] ) ;
106107 anim . addStep ( middlewares . nodes [ 2 ] ) ;
@@ -110,7 +111,7 @@ function displayRailsMiddlewareStack() {
110111 } ;
111112
112113 var runAnimation = function ( ) {
113- animation1 ( ) . run ( ) ;
114+ animation1 ( ) . run ( step ) ;
114115 }
115116
116117 // OK now actually do stuff
0 commit comments