From: Neal Nelson Date: Tue, 7 Dec 2010 13:37:49 +0000 (+0100) Subject: Merge branch 'master' of http://github.com/danvk/dygraphs X-Git-Tag: v1.0.0~536^2~1^2~13 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a593879d42f14356ba6ff9c213d9d64f32d1714c;hp=-c;p=dygraphs.git Merge branch 'master' of github.com/danvk/dygraphs Conflicts: tests/zoom.html --- a593879d42f14356ba6ff9c213d9d64f32d1714c diff --combined dygraph.js index f63fbc7,1ed103c..40a43c8 --- a/dygraph.js +++ b/dygraph.js @@@ -37,7 -37,7 +37,7 @@@ And error bars will be calculated automatically using a binomial distribution. - For further documentation and examples, see http://www.danvk.org/dygraphs + For further documentation and examples, see http://dygraphs.com/ */ @@@ -192,10 -192,6 +192,10 @@@ Dygraph.prototype.__init__ = function(d this.is_initial_draw_ = true; this.annotations_ = []; + // Zoomed indicators - These indicate when the graph has been zoomed and on what axis. + 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. div.innerHTML = ""; @@@ -258,14 -254,6 +258,14 @@@ 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' && @@@ -1096,11 -1084,9 +1096,10 @@@ Dygraph.prototype.doZoomX_ = function(l */ Dygraph.prototype.doZoomXDates_ = function(minDate, maxDate) { this.dateWindow_ = [minDate, maxDate]; + this.zoomed_x_ = true; this.drawGraph_(); if (this.attr_("zoomCallback")) { - var yRange = this.yAxisRange(); - this.attr_("zoomCallback")(minDate, maxDate, yRange[0], yRange[1]); + this.attr_("zoomCallback")(minDate, maxDate, this.yAxisRanges()); } }; @@@ -1125,12 -1111,10 +1124,12 @@@ Dygraph.prototype.doZoomY_ = function(l valueRanges.push([low[1], hi[1]]); } + this.zoomed_y_ = true; this.drawGraph_(); if (this.attr_("zoomCallback")) { var xRange = this.xAxisRange(); - this.attr_("zoomCallback")(xRange[0], xRange[1], this.yAxisRanges()); + var yRange = this.yAxisRange(); + this.attr_("zoomCallback")(xRange[0], xRange[1], yRange[0], yRange[1]); } }; @@@ -1157,8 -1141,6 +1156,8 @@@ Dygraph.prototype.doUnzoom_ = function( if (dirty) { // Putting the drawing operation before the callback because it resets // yAxisRange. + this.zoomed_x_ = false; + this.zoomed_y_ = false; this.drawGraph_(); if (this.attr_("zoomCallback")) { var minDate = this.rawData_[0][0]; @@@ -2018,15 -2000,6 +2017,15 @@@ Dygraph.prototype.drawGraph_ = function * indices are into the axes_ array. */ Dygraph.prototype.computeYAxes_ = function() { + var valueWindow; + if (this.axes_ != undefined) { + // Preserve valueWindow settings. + valueWindow = []; + for (var index = 0; index < this.axes_.length; index++) { + valueWindow.push(this.axes_[index].valueWindow); + } + } + this.axes_ = [{}]; // always have at least one y-axis. this.seriesToAxisMap_ = {}; @@@ -2099,13 -2072,6 +2098,13 @@@ if (vis[i - 1]) seriesToAxisFiltered[s] = this.seriesToAxisMap_[s]; } this.seriesToAxisMap_ = seriesToAxisFiltered; + + if (valueWindow != undefined) { + // Restore valueWindow settings. + for (var index = 0; index < valueWindow.length; index++) { + this.axes_[index].valueWindow = valueWindow[index]; + } + } }; /** @@@ -2446,7 -2412,8 +2445,8 @@@ Dygraph.prototype.parseCSV_ = function( // Parse the x as a float or return null if it's not a number. var parseFloatOrNull = function(x) { var val = parseFloat(x); - return isNaN(val) ? null : val; + // isFinite() returns false for NaN and +/-Infinity. + return isFinite(val) ? val : null; }; var xParser; @@@ -2678,6 -2645,11 +2678,11 @@@ Dygraph.prototype.parseDataTable_ = fun if (ret.length > 0 && row[0] < ret[ret.length - 1][0]) { outOfOrder = true; } + + // Strip out infinities, which give dygraphs problems later on. + for (var j = 0; j < row.length; j++) { + if (!isFinite(row[j])) row[j] = null; + } ret.push(row); } diff --combined tests/zoom.html index d428d19,10b0457..d37a26d --- a/tests/zoom.html +++ b/tests/zoom.html @@@ -16,14 -16,8 +16,14 @@@ buttons are useful for testing.

Window coordinates (in dates and values):

+
+

Zoomed: False

+

Zoomed X: False

+

Zoomed Y: False

+

+

Zoom operations:

  @@@ -46,13 -40,8 +46,13 @@@ document.getElementById("div_g"), NoisyData, { errorBars: true, - zoomCallback : function(a,b,c,d) { - showDimensions(a,b,c,d); + zoomCallback : function(minDate, maxDate, yRange) { + showDimensions(minDate, maxDate, yRange); + }, + drawCallback: function(me, initial) { + document.getElementById("zoomed").innerHTML = "" + me.isZoomed(); + document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x"); + document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y"); } } ); @@@ -63,13 -52,12 +63,12 @@@ // Pull an initial value for logging. var minDate = g.xAxisRange()[0]; var maxDate = g.xAxisRange()[1]; - var minValue = g.yAxisRange()[0]; - var maxValue = g.yAxisRange()[1]; - showDimensions(minDate, maxDate, minValue, maxValue); + var minValue = g.yAxisRange(); + showDimensions(minDate, maxDate, yAxisRange); - function showDimensions(minDate, maxDate, minValue, maxValue) { - showXDimensions(minDate, maxDate); - showYDimensions(minValue, maxValue); + function showDimensions(minDate, maxDate, yAxisRange) { + showXDimensions(minDate, maxDate); + showYDimensions(yAxisRange); } function showXDimensions(first, second) { @@@ -77,23 -65,23 +76,23 @@@ elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]"; } - function showYDimensions(first, second) { + function showYDimensions(range) { var elem = document.getElementById("ydimensions"); - elem.innerHTML = "valueRange : [" + first + ", "+ second + "]"; + elem.innerHTML = "valueRange : [" + range + "]"; } function zoomGraphX(minDate, maxDate) { g.updateOptions({ dateWindow: [minDate, maxDate] }); - showXDimensions(minDate, maxDate); + showXDimensions(minDate, maxDate); } function zoomGraphY(minValue, maxValue) { g.updateOptions({ valueRange: [minValue, maxValue] }); - showYDimensions(minValue, maxValue); + showYDimensions(minValue, maxValue); } function unzoomGraph() {