Skip to content

Commit 0c2b7bf

Browse files
bug fix, graph better handle empty data field
1 parent 338b881 commit 0c2b7bf

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

cache.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# version 91
2+
# version 104
33

44
# gogole maps files
55
http://maps.google.com/maps/api/js?v=3.10&sensor=false&key=AIzaSyCOqkcNey4CCyG4X0X5qxHAhCgD8g5DwXg

js/plot_config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var polyMarker = null;
4949
// updates legend with extrapolated values under the mouse position
5050
function updateLegend() {
5151
var legend = $(plot_holder + " .legendLabel");
52-
$(plot_holder + " .legend table").css({'background-color':"rgba(255,255,255,0.9)"});
52+
$(plot_holder + " .legend table").css({'background-color':"rgba(255,255,255,0.9)","pointer-events":"none"});
5353
legend.each(function() {
5454
$(this).css({'padding-left':'3px'});
5555
});
@@ -107,6 +107,12 @@ function updateLegend() {
107107
});
108108
}
109109

110+
for (j = 0; j < dataset[0].data.length; ++j) {
111+
if (dataset[0].data[j][0] > pos.x) {
112+
break;
113+
}
114+
}
115+
110116
if(follow_vehicle != -1 && vehicles[follow_vehicle].positions.length) {
111117
// adjust index for null data points
112118
j = j - vehicles[follow_vehicle].graph_data[0].nulls;
@@ -121,7 +127,7 @@ $(plot_holder).bind("plothover", function (event, pos, item) {
121127
plot.lockCrosshair();
122128
plot.setCrosshair(pos);
123129
if (!updateLegendTimeout) {
124-
updateLegendTimeout = setTimeout(updateLegend, 50);
130+
updateLegendTimeout = setTimeout(updateLegend, 100);
125131
}
126132
});
127133

js/tracker.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,6 @@ function graphAddLastPosition(idx) {
811811
var data = vehicles[idx].graph_data;
812812
var new_data = vehicles[idx].curr_position;
813813
var ts = (new Date(new_data.gps_time)).getTime(); // flot needs miliseconds for time
814-
var series_idx = 1;
815814

816815
if(vehicles[idx].graph_data.length) {
817816
var ts_last_idx = data[0].data.length - 1;
@@ -826,12 +825,13 @@ function graphAddLastPosition(idx) {
826825
if(plot_options.xaxis && follow_vehicle == idx && ts_last == plot_options.xaxis.max) plot_options.xaxis.max = ts;
827826
}
828827

828+
var i = 0;
829829
// altitude is always first in the series
830-
if(data[0] === undefined) {
831-
data[0] = {
830+
if(data[i] === undefined) {
831+
data[i] = {
832832
label: "altitude = 0",
833833
color: '#33B5E5',
834-
yaxis: series_idx,
834+
yaxis: i+1,
835835
lines: { show:true, fill: true, fillColor: "rgba(51, 181, 229, 0.1)" },
836836
nulls: 0,
837837
data: []
@@ -840,29 +840,33 @@ function graphAddLastPosition(idx) {
840840

841841
// push latest altitude
842842
data[0].data.push([ts, parseInt(new_data.gps_alt)]);
843-
if(parseInt(new_data.gps_alt) < 0) delete vehicles[idx].graph_yaxes[series_idx-1].min;
843+
if(parseInt(new_data.gps_alt) < 0) delete vehicles[idx].graph_yaxes[i].min;
844+
i++;
844845

845846
// the rest of the series is from the data field
846847
var json = $.parseJSON(new_data.data);
847848

848849
$.each(json, function(k, v) {
849-
if(isNaN(v)) return; // only take data that is numerical
850-
if(series_idx > 7) return; // up to 7 seperate data plots
851-
852-
var i = series_idx++;
850+
if(isNaN(v) || v=="") return; // only take data that is numerical
851+
if(i >= 8) return; // up to 8 seperate data plots
853852

854853
if(data[i] === undefined) {
855854
data[i] = {
856855
label: k + " = 0",
856+
key: k,
857857
yaxis: i + 1,
858858
data: []
859859
};
860860

861861
if(isInt(v)) $.extend(true, data[i], { noInterpolate: true, lines: { steps: true }});
862862
}
863863

864+
if(k != data[i].key) return;
865+
864866
data[i].data.push([ts, parseFloat(v)]);
865867
if(parseFloat(v) < 0) delete vehicles[idx].graph_yaxes[i].min;
868+
869+
i++;
866870
});
867871
}
868872

0 commit comments

Comments
 (0)