From 56623f3b4aa7ba86b08c3710be9b219de9e99f9d Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 19 Feb 2010 19:37:12 -0800 Subject: [PATCH] overdrawing with error bars --- dygraph-canvas.js | 12 ++++++------ dygraph.js | 18 +++++------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index fc47be5..979688d 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -488,7 +488,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { ctx.save(); ctx.strokeStyle = color; ctx.lineWidth = this.options.strokeWidth; - var prevX = -1; + var prevX = NaN; var prevYs = [-1, -1]; var count = 0; var yscale = this.layout.yscale; @@ -503,7 +503,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { count++; if (point.name == setName) { if (!isOK(point.y)) { - prevX = -1; + prevX = NaN; continue; } // TODO(danvk): here @@ -511,7 +511,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { point.y + point.errorMinus * yscale ]; newYs[0] = this.area.h * newYs[0] + this.area.y; newYs[1] = this.area.h * newYs[1] + this.area.y; - if (prevX >= 0) { + if (!isNaN(prevX)) { ctx.moveTo(prevX, prevYs[0]); ctx.lineTo(point.canvasx, newYs[0]); ctx.lineTo(point.canvasx, newYs[1]); @@ -537,7 +537,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { ctx.save(); ctx.strokeStyle = color; ctx.lineWidth = this.options.strokeWidth; - var prevX = -1; + var prevX = NaN; var prevYs = [-1, -1]; var count = 0; var yscale = this.layout.yscale; @@ -552,7 +552,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { count++; if (point.name == setName) { if (!isOK(point.y)) { - prevX = -1; + prevX = NaN; continue; } var pX = 1.0 + this.layout.minyval * this.layout.yscale; @@ -561,7 +561,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var newYs = [ point.y, pX ]; newYs[0] = this.area.h * newYs[0] + this.area.y; newYs[1] = this.area.h * newYs[1] + this.area.y; - if (prevX >= 0) { + if (!isNaN(prevX)) { ctx.moveTo(prevX, prevYs[0]); ctx.lineTo(point.canvasx, newYs[0]); ctx.lineTo(point.canvasx, newYs[1]); diff --git a/dygraph.js b/dygraph.js index 6bacea2..c0f4ded 100644 --- a/dygraph.js +++ b/dygraph.js @@ -309,6 +309,7 @@ Dygraph.prototype.toDomCoords = function(x, y) { return ret; }; +// TODO(danvk): use these functions throughout dygraphs. /** * Convert from canvas/div coords to data coordinates. * Returns a two-element array: [X, Y] @@ -850,19 +851,10 @@ Dygraph.prototype.drawZoomRect_ = function(startX, endX, prevEndX) { */ Dygraph.prototype.doZoom_ = function(lowX, highX) { // Find the earliest and latest dates contained in this canvasx range. - var points = this.layout_.points; - var minDate = null; - var maxDate = null; - // Find the nearest [minDate, maxDate] that contains [lowX, highX] - for (var i = 0; i < points.length; i++) { - var cx = points[i].canvasx; - var x = points[i].xval; - if (cx < lowX && (minDate == null || x > minDate)) minDate = x; - if (cx > highX && (maxDate == null || x < maxDate)) maxDate = x; - } - // Use the extremes if either is missing - if (minDate == null) minDate = points[0].xval; - if (maxDate == null) maxDate = points[points.length-1].xval; + var r = this.toDataCoords(lowX, null); + var minDate = r[0]; + r = this.toDataCoords(highX, null); + var maxDate = r[0]; this.dateWindow_ = [minDate, maxDate]; this.drawGraph_(this.rawData_); -- 2.7.4