X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=c0f4ded21384c0c6410e0339aecfea34758f5b49;hb=28713785e7ddd023e8003c5e1479760fe6a890cc;hp=6bf8e7c42fa1da4e0523103862a180550fb2969e;hpb=3230c66289eda13a89722f2abb259b7deab5b103;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 6bf8e7c..c0f4ded 100644 --- a/dygraph.js +++ b/dygraph.js @@ -303,12 +303,13 @@ Dygraph.prototype.toDomCoords = function(x, y) { if (y !== null) { var yRange = this.yAxisRange(); - ret[1] = area.y + (yRange[0] - y) / (yRange[1] - yRange[0]) * area.h; + ret[1] = area.y + (yRange[1] - y) / (yRange[1] - yRange[0]) * area.h; } 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_);