Skip to content

Commit 09955b2

Browse files
Merge branch 'beta', prediction altitude in graph
2 parents 43690f6 + d3210a6 commit 09955b2

File tree

2 files changed

+77
-35
lines changed

2 files changed

+77
-35
lines changed

js/plot_config.js

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function updateLegend(pos) {
1212
});
1313

1414

15-
var i, j, ij, dataset = plot.getData();
15+
var i, j, ij, pij, dataset = plot.getData();
16+
var outside = false;
1617
//var axes = plot.getAxes();
1718

1819
if(dataset.length === 0) return;
@@ -22,33 +23,46 @@ function updateLegend(pos) {
2223
//
2324
// here we don't snap to existing data point
2425
for (i = 0; i < dataset.length; ++i) {
25-
2626
var series = dataset[i];
27+
var y;
28+
y = null;
2729

2830
// Find the nearest points, x-wise
2931

30-
for (j = 0; j < series.data.length; ++j) {
31-
if (series.data[j][0] > pos.x) {
32-
break;
33-
}
32+
if(series.data.length < 2 ||
33+
(i===1 && series.data[0][0] > pos.x)) {
34+
y = null;
35+
}
36+
else if (i !== 1 && pos.x > series.data[series.data.length-1][0]) {
37+
outside = true;
3438
}
35-
if(i === 0) ij = j;
36-
37-
var y;
38-
if(series.noInterpolate > 0) { y = series.data[((j===0)?j:j-1)][1]; }
3939
else {
40-
var p1 = (j===0) ? null : series.data[j-1];
41-
p2 = series.data[j];
40+
for (j = 0; j < series.data.length; ++j) {
41+
if (series.data[j][0] > pos.x) {
42+
break;
43+
}
44+
}
4245

43-
if (p1 === null) {
44-
y = p2[1];
45-
} else if (p2 === null) {
46-
y = p1[1];
47-
} else {
48-
y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
46+
if(i === 0) ij = j;
47+
if(i === 1) {
48+
pij = (j >= series.data.length) ? j-1 : j;
4949
}
5050

51-
y = ((p1 && p1[1] === null) || (p2 && p2[1] === null)) ? null : y.toFixed(2);
51+
if(series.noInterpolate === true) { y = series.data[((j===0)?j:j-1)][1]; }
52+
else {
53+
var p1 = (j===0) ? null : series.data[j-1];
54+
p2 = series.data[j];
55+
56+
if (p1 === null) {
57+
y = p2[1];
58+
} else if (p2 === null || p2 === undefined) {
59+
y = p1[1];
60+
} else {
61+
y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
62+
}
63+
64+
y = ((p1 && p1[1] === null) || (p2 && p2[1] === null)) ? null : y.toFixed(2);
65+
}
5266
}
5367
legend.eq(i).text(series.label.replace(/=.*/, "= " + y));
5468
}
@@ -72,21 +86,27 @@ function updateLegend(pos) {
7286
if(follow_vehicle !== null && vehicles[follow_vehicle].positions.length) {
7387
// adjust index for null data points
7488
var null_count = 0;
75-
var data_ref = vehicles[follow_vehicle].graph_data[0];
76-
77-
if(ij > data_ref.data.length / 2) {
78-
for(i = data_ref.data.length - 1; i > ij; i--) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
79-
null_count = data_ref.nulls - null_count * 2;
80-
} else {
81-
for(i = 0; i < ij; i++) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
82-
null_count *= 2;
89+
90+
if(outside && pij !== undefined) {
91+
polyMarker.setPosition(vehicles[follow_vehicle].prediction_polyline.getPath().getArray()[pij]);
8392
}
93+
else {
94+
var data_ref = vehicles[follow_vehicle].graph_data[0];
8495

85-
// update position
86-
ij -= null_count + ((null_count===0||null_count===data_ref.nulls) ? 0 : 1);
87-
if(ij < 0) ij = 0;
96+
if(ij > data_ref.data.length / 2) {
97+
for(i = data_ref.data.length - 1; i > ij; i--) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
98+
null_count = data_ref.nulls - null_count * 2;
99+
} else {
100+
for(i = 0; i < ij; i++) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
101+
null_count *= 2;
102+
}
88103

89-
polyMarker.setPosition(vehicles[follow_vehicle].positions[ij]);
104+
// update position
105+
ij -= null_count + ((null_count===0||null_count===data_ref.nulls) ? 0 : 1);
106+
if(ij < 0) ij = 0;
107+
108+
polyMarker.setPosition(vehicles[follow_vehicle].positions[ij]);
109+
}
90110

91111
// adjust nite overlay
92112
var date = new Date(pos.x1);

js/tracker.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ function redrawPrediction(vcallsign) {
983983
if(data.warnings || data.errors) return;
984984

985985
var line = [];
986+
var graph_data = [];
986987
var latlng = null;
987988
var max_alt = -99999;
988989
var latlng_burst = null;
@@ -992,6 +993,7 @@ function redrawPrediction(vcallsign) {
992993
for(var i = 0, ii = data.length; i < ii; i++) {
993994
latlng = new google.maps.LatLng(data[i].lat, data[i].lon);
994995
line.push(latlng);
996+
graph_data.push([parseInt(data[i].time)*1000, parseInt(data[i].alt)]);
995997

996998
if(parseFloat(data[i].alt) > max_alt) {
997999
max_alt = parseFloat(data[i].alt);
@@ -1001,7 +1003,11 @@ function redrawPrediction(vcallsign) {
10011003
if(i > 1) path_length += google.maps.geometry.spherical.computeDistanceBetween(line[i-1], line[i]);
10021004
}
10031005

1004-
if(typeof vehicle.prediction_polyline !== 'undefined') {
1006+
vehicle.graph_data[1].data = graph_data;
1007+
updateGraph(vcallsign, true);
1008+
vehicle.prediction_path = line;
1009+
1010+
if(vehicle.prediction_polyline !== null) {
10051011
vehicle.prediction_polyline.setPath(line);
10061012
} else {
10071013
vehicle.prediction_polyline = new google.maps.Polyline({
@@ -1710,13 +1716,14 @@ function addPosition(position) {
17101716
}),
17111717
],
17121718
prediction: null,
1719+
prediction_polyline: null,
1720+
prediction_traget: null,
1721+
prediction_burst: null,
17131722
ascent_rate: 0.0,
17141723
horizontal_rate: 0.0,
17151724
max_alt: parseFloat(position.gps_alt),
17161725
follow: false,
17171726
color_index: color_index,
1718-
prediction_traget: null,
1719-
prediction_burst: null,
17201727
graph_data_updated: false,
17211728
graph_data_map: {},
17221729
graph_data: [],
@@ -1990,6 +1997,8 @@ function graphAddPosition(vcallsign, new_data) {
19901997
else if (xref[i][1] !== null && xref[i][0] + gap_size < ts) {
19911998
// pad with previous datum
19921999
$.each(data, function(k,v) {
2000+
if(k==1) return; // skip prediction series
2001+
19932002
v.data.splice(i+1, 0, [xref[i][0]+pad_size, v.data[i][1]], [xref[i][0]+pad_size+1, null]);
19942003
v.nulls += 2;
19952004
});
@@ -2009,6 +2018,8 @@ function graphAddPosition(vcallsign, new_data) {
20092018
//insert gap when there are 3mins, or more, without telemetry
20102019
if(ts_last + gap_size < ts) {
20112020
$.each(data, function(k,v) {
2021+
if(k==1) return; // skip prediction series
2022+
20122023
v.data.push([ts_last+pad_size, v.data[ts_last_idx][1]]);
20132024
v.data.push([ts_last+pad_size+1, null]);
20142025
v.nulls += 2;
@@ -2031,6 +2042,17 @@ function graphAddPosition(vcallsign, new_data) {
20312042
data: []
20322043
};
20332044

2045+
i += 1;
2046+
2047+
data[i] = {
2048+
label: "pred.alt. = 0",
2049+
color: '#999999',
2050+
yaxis: i+1,
2051+
lines: { show:true, fill: false, },
2052+
nulls: 0,
2053+
data: []
2054+
};
2055+
20342056
}
20352057

20362058
if(parseInt(new_data.gps_alt) < 0) delete vehicle.graph_yaxes[i].min;
@@ -2052,7 +2074,7 @@ function graphAddPosition(vcallsign, new_data) {
20522074

20532075
i = (k in vehicle.graph_data_map) ? vehicle.graph_data_map[k] : data.length;
20542076

2055-
if(i >= 8) return; // up to 8 seperate data plots only
2077+
if(i >= 8) return; // up to 7 seperate data plots only, 1 taken by alt, 1 by prediction
20562078

20572079
if(data[i] === undefined) {
20582080
// configure series

0 commit comments

Comments
 (0)