@@ -146,6 +146,12 @@ function drawTimeline(id, data, minX, maxX, minY, maxY, unitY, batchInterval) {
146146 . attr ( "class" , "line" )
147147 . attr ( "d" , line ) ;
148148
149+ // If the user click one point in the graphs, jump to the batch row and highlight it. And
150+ // recovery the batch row after 3 seconds if necessary.
151+ // We need to remember the last clicked batch so that we can recovery it.
152+ var lastClickedBatch = null ;
153+ var lastTimeout = null ;
154+
149155 // Add points to the line. However, we make it invisible at first. But when the user moves mouse
150156 // over a point, it will be displayed with its detail.
151157 svg . selectAll ( ".point" )
@@ -154,6 +160,7 @@ function drawTimeline(id, data, minX, maxX, minY, maxY, unitY, batchInterval) {
154160 . attr ( "stroke" , "white" ) // white and opacity = 0 make it invisible
155161 . attr ( "fill" , "white" )
156162 . attr ( "opacity" , "0" )
163+ . style ( "cursor" , "pointer" )
157164 . attr ( "cx" , function ( d ) { return x ( d . x ) ; } )
158165 . attr ( "cy" , function ( d ) { return y ( d . y ) ; } )
159166 . attr ( "r" , function ( d ) { return 3 ; } )
@@ -175,7 +182,29 @@ function drawTimeline(id, data, minX, maxX, minY, maxY, unitY, batchInterval) {
175182 . attr ( "opacity" , "0" ) ;
176183 } )
177184 . on ( "click" , function ( d ) {
178- window . location . href = "batch/?id=" + d . x ;
185+ if ( lastTimeout != null ) {
186+ window . clearTimeout ( lastTimeout ) ;
187+ }
188+ if ( lastClickedBatch != null ) {
189+ clearBatchRow ( lastClickedBatch ) ;
190+ lastClickedBatch = null ;
191+ }
192+ lastClickedBatch = d . x ;
193+ highlightBatchRow ( lastClickedBatch )
194+ lastTimeout = window . setTimeout ( function ( ) {
195+ lastTimeout = null ;
196+ if ( lastClickedBatch != null ) {
197+ clearBatchRow ( lastClickedBatch ) ;
198+ lastClickedBatch = null ;
199+ }
200+ } , 3000 ) ; // Clean up after 3 seconds
201+
202+ var batchSelector = $ ( "#batch-" + d . x ) ;
203+ var topOffset = batchSelector . offset ( ) . top - 15 ;
204+ if ( topOffset < 0 ) {
205+ topOffset = 0 ;
206+ }
207+ $ ( 'html,body' ) . animate ( { scrollTop : topOffset } , 200 ) ;
179208 } ) ;
180209}
181210
@@ -218,6 +247,9 @@ function drawHistogram(id, values, minY, maxY, unitY, batchInterval) {
218247 svg . append ( "g" )
219248 . attr ( "class" , "x axis" )
220249 . call ( xAxis )
250+ . append ( "text" )
251+ . attr ( "transform" , "translate(" + ( margin . left + width - 40 ) + ", 15)" )
252+ . text ( "#batches" ) ;
221253
222254 svg . append ( "g" )
223255 . attr ( "class" , "y axis" )
@@ -279,3 +311,11 @@ $(function() {
279311 $ ( this ) . find ( '.expand-input-rate-arrow' ) . toggleClass ( 'arrow-open' ) . toggleClass ( 'arrow-closed' ) ;
280312 }
281313} ) ;
314+
315+ function highlightBatchRow ( batch ) {
316+ $ ( "#batch-" + batch ) . parent ( ) . addClass ( "batch-table-cell-highlight" ) ;
317+ }
318+
319+ function clearBatchRow ( batch ) {
320+ $ ( "#batch-" + batch ) . parent ( ) . removeClass ( "batch-table-cell-highlight" ) ;
321+ }
0 commit comments