--- a/src/main/resources/scripts/graph.js Thu Aug 25 14:18:48 2011 -0400
+++ b/src/main/resources/scripts/graph.js Thu Aug 25 15:15:27 2011 -0400
@@ -8,7 +8,8 @@
'bottom':20,
'left':20
};
- this.AxisTextMergin = 10;
+ this.axisTextMergin = 10;
+ this.normarizeSec = 30;
this.init = function(){
this.SN = "http://www.w3.org/2000/svg";
@@ -38,7 +39,7 @@
//Axis Text
var xAxisText = document.createElementNS(this.SN,'text');
xAxisText.setAttribute('x',this.mergin.left);
- xAxisText.setAttribute('y',this.mergin.top - this.AxisTextMergin);
+ xAxisText.setAttribute('y',this.mergin.top - this.axisTextMergin);
xAxisText.setAttribute("text-anchor","middle");
var xAxisTextNode = document.createTextNode("km/h");
xAxisText.appendChild(xAxisTextNode);
@@ -46,7 +47,7 @@
var yAxisText = document.createElementNS(this.SN,'text');
- yAxisText.setAttribute('x',this.graphWidth - this.mergin.right + this.AxisTextMergin);
+ yAxisText.setAttribute('x',this.graphWidth - this.mergin.right + this.axisTextMergin);
yAxisText.setAttribute('y',this.graphHeight-this.mergin.bottom);
yAxisText.setAttribute("alignment-baseline","central");
var yAxisTextNode = document.createTextNode("Time");
@@ -62,11 +63,14 @@
//Calculate speed
var speedData = [];
var topSpeed = 0;
+ var counter = 0;
var duration = (jsonData.events[jsonData.events.length-1].t - jsonData.events[0].t)/1000;
- for ( var int = 1; int < jsonData.events.length; int++) {
- var distance = Util.geo.calculateDistance(jsonData.events[int-1].c[0], jsonData.events[int-1].c[1], jsonData.events[int].c[0], jsonData.events[int].c[1]);
- var timeSec = (jsonData.events[int].t - jsonData.events[int-1].t)/1000;
- var elapsedTime = (jsonData.events[int].t - jsonData.events[0].t)/1000;
+ for ( var i = 0; i < jsonData.events.length; i++) {
+ if ((jsonData.events[i].t - jsonData.events[counter].t) < 1000 * this.normarizeSec) continue;
+ var distance = Util.geo.calculateDistance(jsonData.events[counter].c[0], jsonData.events[counter].c[1], jsonData.events[i].c[0], jsonData.events[i].c[1]);
+ var timeSec = (jsonData.events[i].t - jsonData.events[counter].t)/1000;
+ var elapsedTime = (jsonData.events[i].t - jsonData.events[0].t)/1000;
+ console.log(distance);
var speed = distance / timeSec * 3600;
if (topSpeed < speed) {
topSpeed = speed;
@@ -75,12 +79,13 @@
'speed':speed,
'elapsedTime':elapsedTime,
});
+ counter = i;
};
console.log(speedData);
//Plot data
- for ( var i = 0; i < speedData.length; i++) {
- var x = speedData[i].elapsedTime / duration * (this.graphWidth-this.mergin.left - this.mergin.right);
- var y = speedData[i].speed / topSpeed * (this.graphHeight - this.mergin.top - this.mergin.bottom);
+ for ( var j = 0; j < speedData.length; j++) {
+ var x = speedData[j].elapsedTime / duration * (this.graphWidth-this.mergin.left - this.mergin.right);
+ var y = speedData[j].speed / topSpeed * (this.graphHeight - this.mergin.top - this.mergin.bottom);
this.drawPoint(this.svg, x, y, 1);
}
};