From: Neal Nelson Date: Thu, 18 Nov 2010 10:12:40 +0000 (+0100) Subject: Changed zoom flags to isZoomed function. X-Git-Tag: v1.0.0~536^2~1^2~14 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=57baab0329f90475370bce7b76a6720a7f73e4f1;p=dygraphs.git Changed zoom flags to isZoomed function. --- diff --git a/dygraph.js b/dygraph.js index 4b52555..f63fbc7 100644 --- a/dygraph.js +++ b/dygraph.js @@ -193,9 +193,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.annotations_ = []; // Zoomed indicators - These indicate when the graph has been zoomed and on what axis. - this.zoomed = false; - this.zoomedX = false; - this.zoomedY = false; + this.zoomed_x_ = false; + this.zoomed_y_ = false; // Clear the div. This ensure that, if multiple dygraphs are passed the same // div, then only one will be drawn. @@ -259,6 +258,14 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.start_(); }; +// axis is an optional parameter. Can be set to 'x' or 'y'. +Dygraph.prototype.isZoomed = function(axis) { + if (axis == null) return this.zoomed_x_ || this.zoomed_y_; + if (axis == 'x') return this.zoomed_x_; + if (axis == 'y') return this.zoomed_y_; + throw "axis parameter to Dygraph.isZoomed must be missing, 'x' or 'y'."; +}; + Dygraph.prototype.attr_ = function(name, seriesName) { if (seriesName && typeof(this.user_attrs_[seriesName]) != 'undefined' && @@ -1089,8 +1096,7 @@ Dygraph.prototype.doZoomX_ = function(lowX, highX) { */ Dygraph.prototype.doZoomXDates_ = function(minDate, maxDate) { this.dateWindow_ = [minDate, maxDate]; - this.zoomed = true; - this.zoomedX = true; + this.zoomed_x_ = true; this.drawGraph_(); if (this.attr_("zoomCallback")) { var yRange = this.yAxisRange(); @@ -1119,8 +1125,7 @@ Dygraph.prototype.doZoomY_ = function(lowY, highY) { valueRanges.push([low[1], hi[1]]); } - this.zoomed = true; - this.zoomedY = true; + this.zoomed_y_ = true; this.drawGraph_(); if (this.attr_("zoomCallback")) { var xRange = this.xAxisRange(); @@ -1152,9 +1157,8 @@ Dygraph.prototype.doUnzoom_ = function() { if (dirty) { // Putting the drawing operation before the callback because it resets // yAxisRange. - this.zoomed = false; - this.zoomedX = false; - this.zoomedY = false; + this.zoomed_x_ = false; + this.zoomed_y_ = false; this.drawGraph_(); if (this.attr_("zoomCallback")) { var minDate = this.rawData_[0][0]; diff --git a/tests/zoom.html b/tests/zoom.html index 43ea545..d428d19 100644 --- a/tests/zoom.html +++ b/tests/zoom.html @@ -50,9 +50,9 @@ showDimensions(a,b,c,d); }, drawCallback: function(me, initial) { - document.getElementById("zoomed").innerHTML = me.zoomed ? "True" : "False"; - document.getElementById("zoomedX").innerHTML = me.zoomedX ? "True" : "False"; - document.getElementById("zoomedY").innerHTML = me.zoomedY ? "True" : "False"; + document.getElementById("zoomed").innerHTML = "" + me.isZoomed(); + document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x"); + document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y"); } } );