@@ -505,12 +505,12 @@ var BirdWatch = BirdWatch || {};
505
505
return { ratioHist : [ ] , posHist : [ ] , lastUpdate : now ( ) , posArrDir : "RIGHT" , ratioArrDir : "RIGHT-UP" }
506
506
} ,
507
507
componentWillReceiveProps : function ( props ) {
508
- this . setState ( { ratioHist : _ . last ( this . state . ratioHist . concat ( props . val / props . count ) , 100 ) } ) ;
508
+ this . setState ( { ratioHist : _ . last ( this . state . ratioHist . concat ( props . val / props . count ) , this . props . ratioChangeTweets ) } ) ;
509
509
this . setState ( { posHist : _ . last ( this . state . posHist . concat ( props . idx + 1 ) , 2 ) } ) ;
510
510
511
511
// slope of the fitted position change function
512
512
var posSlope = regression ( 'linear' , regressionData ( this . state . posHist ) ) . equation [ 0 ] ;
513
- if ( posSlope === 0 && now ( ) - this . state . lastUpdate > 60000 ) { this . setState ( { posArrDir : "RIGHT" } ) ; }
513
+ if ( posSlope === 0 && now ( ) - this . state . lastUpdate > this . props . posChangeDur ) { this . setState ( { posArrDir : "RIGHT" } ) ; }
514
514
if ( posSlope > 0 ) { this . setState ( { posArrDir : "UP" , lastUpdate : now ( ) } ) ; }
515
515
if ( posSlope < 0 ) { this . setState ( { posArrDir : "DOWN" , lastUpdate : now ( ) } ) ; }
516
516
@@ -539,14 +539,17 @@ var BirdWatch = BirdWatch || {};
539
539
}
540
540
} ) ;
541
541
542
- /** BarChart component, renders all bar items */
542
+ /** BarChart component, renders all bar items.
543
+ * Also renders interactive legend where the trend indicator durations can be configured */
543
544
var BarChart = React . createClass ( { displayName : 'BarChart' ,
544
545
render : function ( ) {
545
546
var bars = this . props . words . map ( function ( bar , i , arr ) {
546
547
if ( ! bar ) return "" ;
547
548
var y = i * 15 ;
548
549
var w = bar . value / arr [ 0 ] . value * ( barChartElem . width ( ) - 190 ) ;
549
- return Bar ( { t :bar . key , y :y , w :w , key :bar . key , idx :i , val :bar . value , count :this . props . count } ) ;
550
+ return Bar ( { t :bar . key , y :y , w :w , key :bar . key , idx :i , val :bar . value , count :this . props . count ,
551
+ posChangeDur :this . refs . posChangeDur . getDOMNode ( ) . value ,
552
+ ratioChangeTweets :this . refs . ratioChangeTweets . getDOMNode ( ) . value } ) ;
550
553
} . bind ( this ) ) ;
551
554
return React . DOM . div ( null ,
552
555
React . DOM . svg ( { width :"750" , height :"380" } ,
@@ -555,8 +558,24 @@ var BirdWatch = BirdWatch || {};
555
558
React . DOM . line ( { transform :"translate(168, 0)" , y :"0" , y2 :"375" , stroke :"#000000" } )
556
559
)
557
560
) ,
558
- React . DOM . p ( { className :"legend" } , React . DOM . strong ( null , "1st trend indicator:" ) , " position changes in last minute" ) ,
559
- React . DOM . p ( { className :"legend" } , React . DOM . strong ( null , "2nd trend indicator:" ) , " ratio change termCount / totalTermsCounted over last 100 tweets" )
561
+ React . DOM . p ( { className :"legend" } , React . DOM . strong ( null , "1st trend indicator:" ) , " position changes in last " ,
562
+ React . DOM . select ( { defaultValue :"60000" , ref :"posChangeDur" } ,
563
+ React . DOM . option ( { value :"10000" } , "10 seconds" ) ,
564
+ React . DOM . option ( { value :"30000" } , "30 seconds" ) ,
565
+ React . DOM . option ( { value :"60000" } , "minute" ) ,
566
+ React . DOM . option ( { value :"300000" } , "5 minutes" ) ,
567
+ React . DOM . option ( { value :"600000" } , "10 minutes" )
568
+ )
569
+ ) ,
570
+ React . DOM . p ( { className :"legend" } , React . DOM . strong ( null , "2nd trend indicator:" ) ,
571
+ "ratio change termCount / totalTermsCounted over last " ,
572
+ React . DOM . select ( { defaultValue :"100" , ref :"ratioChangeTweets" } ,
573
+ React . DOM . option ( { value :"10" } , "10 tweets" ) ,
574
+ React . DOM . option ( { value :"100" } , "100 tweets" ) ,
575
+ React . DOM . option ( { value :"500" } , "500 tweets" ) ,
576
+ React . DOM . option ( { value :"1000" } , "1000 tweets" )
577
+ )
578
+ )
560
579
)
561
580
}
562
581
} ) ;
0 commit comments