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;
count++;
if (point.name == setName) {
if (!isOK(point.y)) {
- prevX = -1;
+ prevX = NaN;
continue;
}
// TODO(danvk): here
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]);
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;
count++;
if (point.name == setName) {
if (!isOK(point.y)) {
- prevX = -1;
+ prevX = NaN;
continue;
}
var pX = 1.0 + this.layout.minyval * this.layout.yscale;
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]);
return ret;
};
+// TODO(danvk): use these functions throughout dygraphs.
/**
* Convert from canvas/div coords to data coordinates.
* Returns a two-element array: [X, Y]
*/
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_);