Skip to content

Commit 63c7639

Browse files
Mark JessopMark Jessop
authored andcommitted
Hopeful fix for the small altitude plots
1 parent 9f68f08 commit 63c7639

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

js/tracker.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,9 +1768,9 @@ function updateVehicleInfo(vcallsign, newPosition) {
17681768
if(wvar.mode != "Position" && vehicle.graph_data.length) {
17691769
var can = $('.vehicle'+vehicle.uuid+' .graph');
17701770
if (vehicle.vehicle_type!="car") {
1771-
drawAltitudeProfile(can.get(0), can.get(1), vehicle.graph_data[0], vehicle.max_alt, true);
1771+
drawAltitudeProfile(can.get(0), can.get(1), vehicle.graph_data[0], vehicle.max_alt, vehicle.max_alt_time, true, vehicle.callsign);
17721772
} else {
1773-
drawAltitudeProfile(can.get(0), can.get(1), vehicle.graph_data[0], vehicle.max_alt, true);
1773+
drawAltitudeProfile(can.get(0), can.get(1), vehicle.graph_data[0], vehicle.max_alt, vehicle.max_alt_time, true, vehicle.callsign);
17741774
}
17751775
}
17761776

@@ -2213,11 +2213,21 @@ function updatePolyline(vcallsign) {
22132213
}
22142214
}
22152215

2216-
function drawAltitudeProfile(c1, c2, series, alt_max, chase) {
2216+
function drawAltitudeProfile(c1, c2, series, alt_max, alt_max_time, chase, name) {
2217+
// Updated 2023-04-10 to make use of position time data to set
2218+
// the x-coordinate. This helps resolve issues with backlog vs live data.
22172219
alt_max = (alt_max < 2000) ? 2000 : alt_max;
22182220
var alt_list = series.data;
2221+
var first_time = alt_list[0][0];
22192222
var len = alt_list.length;
22202223
var real_len = len - series.nulls;
2224+
var last_time = alt_list[len-1][0];
2225+
var time_range = last_time - first_time;
2226+
2227+
// Only attempt to draw if we have more than 1 data point.
2228+
if(len == 1){
2229+
return;
2230+
}
22212231

22222232
var ctx1 = c1.getContext("2d");
22232233
var ctx2 = c2.getContext("2d");
@@ -2250,16 +2260,19 @@ function drawAltitudeProfile(c1, c2, series, alt_max, chase) {
22502260
ctx2.strokeStyle= "#f53333";
22512261
}
22522262

2253-
var xt1 = (cw1 - (2 * ratio)) / real_len;
2263+
//var xt1 = (cw1 - (2 * ratio)) / real_len;
2264+
var xt1 = (cw1 - (2 * ratio)) / time_range;
22542265
var yt1 = (ch1 - (6 * ratio)) / alt_max;
2255-
var xt2 = (cw2 - (2 * ratio)) / real_len;
2266+
//var xt2 = (cw2 - (2 * ratio)) / real_len;
2267+
var xt2 = (cw2 - (2 * ratio)) / time_range;
22562268
var yt2 = (ch2 - (6 * ratio)) / alt_max;
22572269

22582270
xt1 = (xt1 > 1) ? 1 : xt1;
22592271
yt1 = (yt1 > 1) ? 1 : yt1;
22602272
xt2 = (xt2 > 1) ? 1 : xt2;
22612273
yt2 = (yt2 > 1) ? 1 : yt2;
22622274

2275+
22632276
ctx1.beginPath();
22642277
ctx2.beginPath();
22652278

@@ -2275,26 +2288,33 @@ function drawAltitudeProfile(c1, c2, series, alt_max, chase) {
22752288
if(cw1*2 > real_len) {
22762289
for(i = 0; i < real_len; i++) {
22772290
alt = alt_list[i][1];
2291+
alt_time = last_time - alt_list[i][0];
22782292

2279-
ctx1.lineTo(1+((i+1)*xt1), ch1 - (alt * yt1));
2280-
ctx2.lineTo(1+((i+1)*xt2), ch2 - (alt * yt2));
2293+
//
2294+
//ctx1.lineTo(1+((i+1)*xt1), ch1 - (alt * yt1));
2295+
//ctx2.lineTo(1+((i+1)*xt2), ch2 - (alt * yt2));
2296+
ctx1.lineTo(cw1-(alt_time*xt1), ch1 - (alt * yt1));
2297+
ctx2.lineTo(cw2-(alt_time*xt2), ch2 - (alt * yt2));
22812298

22822299
if(i+2 < len && alt_list[i+2][1] === null) i += 2;
22832300
}
22842301
}
22852302
// if they are too many, downsample to keep the loop short
22862303
else {
2287-
xt1 = 0.5;
2288-
xt2 = 0.16;
2304+
//xt1 = 0.5;
2305+
//xt2 = 0.16;
22892306
var max = cw1 * 2;
22902307
var step = (1.0*len) / max;
22912308

22922309
for(i = 0; i < max; i++) {
22932310
alt = alt_list[Math.floor(i*step)][1];
2311+
alt_time = last_time - alt_list[Math.floor(i*step)][0];
22942312
if(alt === null) continue;
22952313

2296-
ctx1.lineTo(1+((i+1)*xt1), ch1 - (alt * yt1));
2297-
ctx2.lineTo(1+((i+1)*xt2), ch2 - (alt * yt2));
2314+
//ctx1.lineTo(1+((i+1)*xt1), ch1 - (alt * yt1));
2315+
//ctx2.lineTo(1+((i+1)*xt2), ch2 - (alt * yt2));
2316+
ctx1.lineTo(cw1-(alt_time*xt1), ch1 - (alt * yt1));
2317+
ctx2.lineTo(cw2-(alt_time*xt2), ch2 - (alt * yt2));
22982318
}
22992319

23002320
// fix index for fill
@@ -2305,8 +2325,13 @@ function drawAltitudeProfile(c1, c2, series, alt_max, chase) {
23052325
ctx2.stroke();
23062326

23072327
// close the path, so it can be filled
2308-
ctx1.lineTo(1+((i+1)*xt1), ch1);
2309-
ctx2.lineTo(1+((i+1)*xt2), ch2);
2328+
//ctx1.lineTo(1+((i+1)*xt1), ch1);
2329+
//ctx2.lineTo(1+((i+1)*xt2), ch2);
2330+
end_x1 = cw1 - (last_time - alt_list[len-1][0])*xt1;
2331+
end_x2 = cw2 - (last_time - alt_list[len-1][0])*xt2;
2332+
2333+
ctx1.lineTo(end_x1, ch1);
2334+
ctx2.lineTo(end_x2, ch2);
23102335
ctx1.lineTo(0,ch1);
23112336
ctx2.lineTo(0,ch2);
23122337

@@ -3039,6 +3064,7 @@ function addPosition(position) {
30393064
ascent_rate: 0.0,
30403065
horizontal_rate: 0.0,
30413066
max_alt: parseFloat(position.gps_alt),
3067+
max_alt_time: convert_time(position.gps_time),
30423068
follow: false,
30433069
color_index: color_index,
30443070
graph_data_updated: false,
@@ -3287,6 +3313,7 @@ function addPosition(position) {
32873313
// record the highest altitude
32883314
if(parseFloat(position.gps_alt) > vehicle.max_alt) {
32893315
vehicle.max_alt = parseFloat(position.gps_alt);
3316+
vehicle.max_alt_time = new_ts;
32903317
}
32913318

32923319
return;

0 commit comments

Comments
 (0)