@@ -331,7 +331,12 @@ function clean_refresh(text, force) {
331331 if ( ajax_inprogress ) return false ;
332332
333333 stopAjax ( ) ;
334+
335+ // reset mode if, invalid mode is specified
336+ if ( modeList . indexOf ( text ) == - 1 ) text = ( is_mobile ) ? modeDefaultMobile : modeDefault ;
337+
334338 wvar . mode = text ;
339+ tmpC . select ( text ) ;
335340
336341 position_id = 0 ;
337342
@@ -1916,20 +1921,22 @@ function updateGraph(vcallsign, reset_selection) {
19161921 updateTimebox ( new Date ( ) ) ;
19171922 }
19181923
1919- if ( vcallsign === null ) return ;
1924+ if ( vcallsign === null || ! vehicles . hasOwnProperty ( vcallsign ) ) return ;
19201925
19211926 var series = vehicles [ vcallsign ] . graph_data ;
19221927
19231928 // if we are drawing the plot for the fisrt time
19241929 // and the dataset is too large, we set an initial selection of the last 7 days
19251930 if ( ! plot_options . hasOwnProperty ( 'xaxis' ) ) {
19261931 if ( series . length && series [ 0 ] . data . length > 4001 ) {
1927- var end = series [ 0 ] . data . length - 1 ;
1932+ var last = series [ 0 ] . data . length - 1 ;
1933+ var end_a = series [ 0 ] . data [ last ] [ 0 ] ;
1934+ var end_b = ( series [ 1 ] . data . length ) ? series [ 1 ] . data [ series [ 1 ] . data . length - 1 ] [ 0 ] : 0 ;
19281935
19291936 plot_options . xaxis = {
19301937 superzoom : 1 ,
1931- min : series [ 0 ] . data [ end - 4000 ] [ 0 ] ,
1932- max : series [ 0 ] . data [ end ] [ 0 ] ,
1938+ min : series [ 0 ] . data [ last - 4000 ] [ 0 ] ,
1939+ max : Math . max ( end_a , end_b ) ,
19331940 } ;
19341941
19351942 }
@@ -2638,7 +2645,9 @@ function update(response) {
26382645 end : function ( ctx ) {
26392646
26402647 // update graph is current vehicles is followed
2641- if ( follow_vehicle !== null && vehicles [ follow_vehicle ] . graph_data_updated ) updateGraph ( follow_vehicle , false ) ;
2648+ if ( follow_vehicle !== null &&
2649+ vehicles . hasOwnProperty ( follow_vehicle ) &&
2650+ vehicles [ follow_vehicle ] . graph_data_updated ) updateGraph ( follow_vehicle , false ) ;
26422651
26432652 // store in localStorage
26442653 offline . set ( 'positions' , ctx . lastPositions ) ;
0 commit comments