Browse files

speedtest graphs: fixes

  • Loading branch information...
1 parent 9cdc890 commit 0f133a3105f0a0b0bfd40b6ceafd8ef40c9dbb23 @astro committed Sep 29, 2010
Showing with 8 additions and 4 deletions.
  1. +3 −0 speedtest/client.js
  2. +5 −4 speedtest/graph.js
View
3 speedtest/client.js
@@ -222,6 +222,9 @@ if (!WebSocket) {
}
$('#run').click(function() {
+ // clear previous graphs:
+ $('canvas').remove();
+
$('#run').attr('disabled', 'disabled');
runTest(Ping, function() {
runTest(Download, function() {
View
9 speedtest/graph.js
@@ -20,10 +20,8 @@ Graph.prototype.addData = function(t, y) {
} else
this.data.push({ t: t, y: y });
- if (y > this.maxY) {
+ if (y > this.maxY)
this.maxY = y;
- this.yTop = this.maxY * 5 / 4;
- }
this.scheduleDraw();
};
@@ -43,6 +41,7 @@ Graph.prototype.draw = function() {
if (this.data.length > 0) {
+ this.yTop = this.maxY * 5 / 4;
this.drawGrid(ctx);
this.drawData(ctx);
@@ -64,7 +63,7 @@ Graph.prototype.getX = function(t) {
Graph.prototype.getY = function(y) {
var h = this.canvas.height;
- return Math.ceil(h * (1 - y / this.yTop));
+ return Math.floor(h * (1 - y / this.yTop));
};
Graph.prototype.drawData = function(ctx) {
@@ -77,6 +76,8 @@ Graph.prototype.drawData = function(ctx) {
var draw = function() {
if (current) {
ctx.lineTo(current.x, that.getY(current.y));
+ if (current.y > that.maxY)
+ that.maxY = current.y;
current = null;
}
};

0 comments on commit 0f133a3

Please sign in to comment.