Skip to content

Commit 80ca55a

Browse files
fixed graph data not being spliced well
There is still the matter of making the null work when spilcing.
1 parent 1000ce2 commit 80ca55a

File tree

2 files changed

+60
-41
lines changed

2 files changed

+60
-41
lines changed

js/plot_config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ function updateLegend() {
131131
polyMarker.setPosition(vehicles[follow_vehicle].positions[j - null_count]);
132132

133133
// adjust nite overlay
134-
var date = new Date(data_ref.data[j][0])
134+
try {
135+
var date = new Date(data_ref.data[j][0])
136+
} catch(e) {
137+
return;
138+
}
139+
135140
nite.setDate(date);
136141
nite.refresh();
137142
// set timebox

js/tracker.js

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ function addPosition(position) {
11061106
time_last_alt: 0,
11071107
alt_max: 100,
11081108
graph_data_updated: false,
1109+
graph_data_map: {},
11091110
graph_data: [],
11101111
graph_yaxes: [],
11111112
updated: false,
@@ -1223,7 +1224,7 @@ function addPosition(position) {
12231224
if(poslen > 1) vehicle.path_length += google.maps.geometry.spherical.computeDistanceBetween(vehicle.positions[poslen-2], vehicle.positions[poslen-1]);
12241225

12251226
vehicle.curr_position = position;
1226-
graphAddPosition(vehicle_index, vehicle.curr_position);
1227+
graphAddPosition(vehicle_index, position);
12271228

12281229
}
12291230
else if(vehicle.positions_ts.indexOf(new_ts) == -1) { // backlog packets, need to splice them into the array
@@ -1302,46 +1303,48 @@ function updateGraph(idx, reset_selection) {
13021303
function graphAddPosition(idx, new_data) {
13031304
if(!plot) return;
13041305

1305-
vehicles[idx].graph_data_updated = true;
1306+
var vehicle = vehicles[idx];
1307+
vehicle.graph_data_updated = true;
13061308

13071309
var data = vehicles[idx].graph_data;
13081310
var ts = convert_time(new_data.gps_time);
13091311
var splice_idx = 0;
13101312
var splice = false;
13111313

1312-
if(data.length && data[0].data.length) {
1313-
if(data[0].data[data[0].data.length - 1][0] > ts) splice = true;
1314-
}
1315-
1316-
if(splice) {
1317-
// adjust splice_idx to account for null entries
1318-
var xref = data[0].data;
1319-
var i = xref.length - 1;
1320-
for(; i >= 0; i--) {
1321-
if(ts > xref[i][0]) break;
1322-
}
1323-
splice_idx = i+1;
1324-
1325-
//TODO: correct/adjust null entries
1326-
}
1327-
else if(vehicles[idx].graph_data.length) {
1314+
if(data.length) {
13281315
var ts_last_idx = data[0].data.length - 1;
13291316
var ts_last = data[0].data[ts_last_idx][0];
13301317

1331-
//insert gap when there are 3mins, or more, without telemetry
1332-
var gap_size = 180000; // 3 mins in milis
1333-
var pad_size = 120000; // 2 min
1334-
1335-
if(ts_last + gap_size < ts) {
1336-
$.each(data, function(k,v) {
1337-
v.data.push([ts_last+pad_size, v.data[v.data.length - 1][1]]);
1338-
v.data.push([ts_last+pad_size+1, null]);
1339-
v.nulls += 2;
1340-
})
1318+
if(data[0].data.length) {
1319+
if(data[0].data[ts_last_idx][0] >= ts) splice = true;
13411320
}
13421321

1322+
if(splice) {
1323+
// adjust splice_idx to account for null entries
1324+
var xref = data[0].data;
1325+
var i = xref.length - 1;
1326+
for(; i >= 0; i--) {
1327+
if(ts > xref[i][0]) break;
1328+
}
1329+
splice_idx = i+1;
1330+
1331+
//TODO: correct/adjust null entries
1332+
}
1333+
else {
1334+
//insert gap when there are 3mins, or more, without telemetry
1335+
var gap_size = 180000; // 3 mins in milis
1336+
var pad_size = 120000; // 2 min
1337+
1338+
if(ts_last + gap_size < ts) {
1339+
$.each(data, function(k,v) {
1340+
v.data.push([ts_last+pad_size, v.data[v.data.length - 1][1]]);
1341+
v.data.push([ts_last+pad_size+1, null]);
1342+
v.nulls += 2;
1343+
})
1344+
}
1345+
}
13431346
// update the selection upper limit to the latest timestamp, only if the upper limit is equal to the last timestamp
1344-
if(plot_options.xaxis && follow_vehicle == idx && ts_last == plot_options.xaxis.max) plot_options.xaxis.max = ts;
1347+
if(plot_options.xaxis && follow_vehicle == idx && ts_last == plot_options.xaxis.max && ts > ts_last) plot_options.xaxis.max = ts;
13451348
}
13461349

13471350
var i = 0;
@@ -1355,6 +1358,7 @@ function graphAddPosition(idx, new_data) {
13551358
nulls: 0,
13561359
data: []
13571360
};
1361+
13581362
}
13591363

13601364
// push latest altitude
@@ -1364,16 +1368,22 @@ function graphAddPosition(idx, new_data) {
13641368
data[0].data.push([ts, parseInt(new_data.gps_alt)]);
13651369
}
13661370

1367-
if(parseInt(new_data.gps_alt) < 0) delete vehicles[idx].graph_yaxes[i].min;
1368-
i++;
1371+
if(parseInt(new_data.gps_alt) < 0) delete vehicle.graph_yaxes[i].min;
13691372

13701373
// the rest of the series is from the data field
13711374
var json = $.parseJSON(new_data.data);
13721375
if(!json) return;
13731376

1377+
// init empty data matrix
1378+
var data_matrix = [];
1379+
for(var k in vehicle.graph_data_map) data_matrix[vehicle.graph_data_map[k]] = [ts, null];
1380+
13741381
$.each(json, function(k, v) {
13751382
if(isNaN(v) || v=="") return; // only take data that is numerical
1376-
if(i >= 8) return; // up to 8 seperate data plots
1383+
1384+
i = (k in vehicle.graph_data_map) ? vehicle.graph_data_map[k] : data.length;
1385+
1386+
if(i >= 8) return; // up to 8 seperate data plots only
13771387

13781388
if(data[i] === undefined) {
13791389
data[i] = {
@@ -1384,20 +1394,24 @@ function graphAddPosition(idx, new_data) {
13841394
data: []
13851395
};
13861396

1387-
if(isInt(v)) $.extend(true, data[i], { noInterpolate: true, lines: { steps: true }});
1397+
vehicle.graph_data_map[k] = i;
1398+
data_matrix[i] = [ts, null];
1399+
1400+
if(isInt(v)) $.extend(true, data[i], { noInterpolate: true, lines: { steps: true }});
13881401
}
13891402

1390-
if(k != data[i].key) return;
1403+
if(parseFloat(v) < 0) delete vehicle.graph_yaxes[i].min;
1404+
1405+
data_matrix[i][1] = parseFloat(v);
1406+
});
13911407

1408+
for(var k in data_matrix) {
13921409
if(splice) {
1393-
data[i].data.splice(splice_idx,0, [ts, parseFloat(v)]);
1410+
data[k].data.splice(splice_idx, 0, data_matrix[k]);
13941411
} else {
1395-
data[i].data.push([ts, parseFloat(v)]);
1412+
data[k].data.push(data_matrix[k]);
13961413
}
1397-
if(parseFloat(v) < 0) delete vehicles[idx].graph_yaxes[i].min;
1398-
1399-
i++;
1400-
});
1414+
}
14011415
}
14021416

14031417
function refresh() {

0 commit comments

Comments
 (0)