@@ -8,8 +8,6 @@ var markers_url = "img/markers/";
88var vehicle_names = [ ] ;
99var vehicles = [ ] ;
1010
11- var graph_url = "http://chart.googleapis.com/chart?chf=bg,s,67676700&chxr=0,0,46|1,0,0|2,0,45&chxs=0,676767,0,0,_,000000|1,676767,0,0,t,676767|2,676767,0,0,_,676767&chxt=r,y,x&chs=300x80&cht=lc&chco=33B5E5&chds=0,{AA}&chls=2&chm=B,33B5E533,0,0,0,-1&chd=" ;
12-
1311var receiver_names = [ ] ;
1412var receivers = [ ] ;
1513
@@ -435,7 +433,7 @@ function updateVehicleInfo(index, newPosition) {
435433 // start
436434 var a = '<div class="header">'
437435 + '<span>' + vehicle_names [ index ] + ' <i class="icon-target"></i></span>'
438- + '<img class="graph" src="img/blank.png" >'
436+ + '<canvas class="graph"></canvas >'
439437 + '<i class="arrow"></i></div>'
440438 + '<div class="data">'
441439 + '<img class="' + ( ( vehicle . vehicle_type == "car" ) ?'car' :'' ) + '" src="' + image + '" />'
@@ -473,10 +471,14 @@ function updateVehicleInfo(index, newPosition) {
473471 + c // receivers if any
474472 + '' ;
475473
476-
474+ // update html
477475 $ ( '.portrait .vehicle' + index ) . html ( a + p + b ) ;
478476 $ ( '.landscape .vehicle' + index ) . html ( a + l + b ) ;
479477
478+ // redraw canvas
479+ var c = $ ( '.vehicle' + index + ' .graph' ) ;
480+ drawAltitudeProfile ( c . get ( 0 ) , c . get ( 1 ) , vehicles [ index ] . alt_list , vehicles [ index ] . alt_max ) ;
481+
480482 return true ;
481483}
482484
@@ -582,19 +584,60 @@ function convert_time(text) {
582584 return stringToDateUTC ( text ) . getTime ( ) ;
583585}
584586
585- var GChartString = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
586- function GChartEncodeData ( valueArray , maxValue ) {
587- var chartData = [ 's:' ] ;
588- for ( var i = 0 ; i < valueArray . length ; i ++ ) {
589- var currentValue = valueArray [ i ] ;
590-
591- if ( ! isNaN ( currentValue ) && currentValue >= 0 ) {
592- chartData . push ( GChartString . charAt ( Math . round ( ( GChartString . length - 1 ) * currentValue / maxValue ) ) ) ;
593- } else {
594- chartData . push ( '_' ) ;
595- }
587+ function drawAltitudeProfile ( c1 , c2 , alt_list , alt_max ) {
588+ var ctx1 = c1 . getContext ( "2d" ) ;
589+ var ctx2 = c2 . getContext ( "2d" ) ;
590+
591+ c1 = $ ( c1 ) ;
592+ c2 = $ ( c2 ) ;
593+
594+ var ratio = window . devicePixelRatio ;
595+ var cw1 = 150 * ratio ;
596+ var ch1 = 40 * ratio ;
597+ var cw2 = 60 * ratio ;
598+ var ch2 = 40 * ratio ;
599+
600+ c1 . attr ( 'width' , cw1 ) . attr ( 'height' , ch1 ) ;
601+ c2 . attr ( 'width' , cw2 ) . attr ( 'height' , ch2 ) ;
602+
603+ ctx1 . fillStyle = "#d6f0f9" ;
604+ ctx1 . lineWidth = 2 ;
605+ ctx1 . strokeStyle = "#33B5F5" ;
606+ ctx2 . fillStyle = "#d6f0f9" ;
607+ ctx2 . lineWidth = 2 ;
608+ ctx2 . strokeStyle = "#33B5F5" ;
609+
610+ var xt1 = ( cw1 - 2 ) / alt_list . length ;
611+ var yt1 = ( ch1 - 6 ) / alt_max ;
612+ var xt2 = ( cw2 - 2 ) / alt_list . length ;
613+ var yt2 = ( ch2 - 6 ) / alt_max ;
614+
615+ //xt1 = (xt1 > 1) ? 1 : xt1;
616+ //yt1 = (yt1 > 1) ? 1 : yt1;
617+ //xt2 = (xt2 > 1) ? 1 : xt2;
618+ //yt2 = (yt2 > 1) ? 1 : yt2;
619+
620+ ctx1 . beginPath ( ) ;
621+ ctx1 . moveTo ( 0 , c1 . height ) ;
622+ ctx2 . beginPath ( ) ;
623+ ctx2 . moveTo ( 0 , c2 . height ) ;
624+
625+ var i ;
626+ for ( i = 0 ; i < alt_list . length ; i ++ ) {
627+ ctx1 . lineTo ( 1 + ( ( i + 1 ) * xt1 ) , ch1 - ( alt_list [ i ] * yt1 ) ) ;
628+ ctx2 . lineTo ( 1 + ( ( i + 1 ) * xt2 ) , ch2 - ( alt_list [ i ] * yt2 ) ) ;
596629 }
597- return chartData . join ( '' ) ;
630+
631+ ctx1 . stroke ( ) ;
632+ ctx2 . stroke ( ) ;
633+
634+ ctx1 . lineTo ( cw1 - 1 , ch1 ) ;
635+ ctx2 . lineTo ( cw2 - 1 , ch2 ) ;
636+
637+ ctx1 . closePath ( ) ;
638+ ctx2 . closePath ( ) ;
639+ ctx1 . fill ( ) ;
640+ ctx2 . fill ( ) ;
598641}
599642
600643function addPosition ( position ) {
@@ -1237,11 +1280,8 @@ function update(response) {
12371280
12381281 // update the altitude profile, only if its a balloon
12391282 if ( vehicles [ idx ] . vehicle_type != "car" ) {
1240- var graph_src = graph_url . replace ( "{AA}" , vehicles [ idx ] . alt_max ) ; // top range, buttom is always 0
1241- graph_src += GChartEncodeData ( vehicles [ idx ] . alt_list , vehicles [ idx ] . alt_max ) ; // encode datapoint to preserve bandwith
1242-
1243- // update img element
1244- $ ( '.vehicle' + idx + ' .graph' ) . attr ( 'src' , graph_src ) ;
1283+ var c = $ ( '.vehicle' + idx + ' .graph' ) ;
1284+ drawAltitudeProfile ( c . get ( 0 ) , c . get ( 1 ) , vehicles [ idx ] . alt_list , vehicles [ idx ] . alt_max ) ;
12451285 }
12461286 } , 400 * i ) ;
12471287 } else {
@@ -1250,11 +1290,8 @@ function update(response) {
12501290
12511291 // update the altitude profile, only if its a balloon
12521292 if ( vehicles [ i ] . vehicle_type != "car" ) {
1253- var graph_src = graph_url . replace ( "{AA}" , vehicles [ i ] . alt_max ) ; // top range, buttom is always 0
1254- graph_src += GChartEncodeData ( vehicles [ i ] . alt_list , vehicles [ i ] . alt_max ) ; // encode datapoint to preserve bandwith
1255-
1256- // update img element
1257- $ ( '.vehicle' + i + ' .graph' ) . attr ( 'src' , graph_src ) ;
1293+ var c = $ ( '.vehicle' + idx + ' .graph' ) ;
1294+ drawAltitudeProfile ( c . get ( 0 ) , c . get ( 1 ) , vehicles [ idx ] . alt_list , vehicles [ idx ] . alt_max ) ;
12581295 }
12591296
12601297 // remember last position for each vehicle
0 commit comments