From: Dan Vanderkam Date: Wed, 23 Dec 2009 22:51:07 +0000 (-0500) Subject: interface to control series visibility X-Git-Tag: v1.0.0~760 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1cf11047ed006208ed70bfbe5666254264137a6a;p=dygraphs.git interface to control series visibility --- diff --git a/dygraph.js b/dygraph.js index 10f3b4e..ff70bcb 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1231,6 +1231,8 @@ Dygraph.prototype.drawGraph_ = function(data) { // Loop over all fields in the dataset for (var i = 1; i < data[0].length; i++) { + if (!this.visibility()[i - 1]) continue; + var series = []; for (var j = 0; j < data.length; j++) { var date = data[j][0]; @@ -1876,6 +1878,34 @@ Dygraph.prototype.adjustRoll = function(length) { }; /** + * Returns a boolean array of visibility statuses. + */ +Dygraph.prototype.visibility = function() { + // Do lazy-initialization, so that this happens after we know the number of + // data series. + if (!this.attr_("visibility")) { + this.attr_["visibility"] = []; + } + while (this.attr_("visibility").length < this.rawData_[0].length - 1) { + this.attr_("visibility").push(false); + } + return this.attr_("visibility"); +}; + +/** + * Changes the visiblity of a series. + */ +Dygraph.prototype.setVisibility = function(num, value) { + var x = this.visibility(); + if (num < 0 && num >= x.length) { + this.warn("invalid series number in setVisibility: " + num); + } else { + x[num] = value; + this.drawGraph_(this.rawData_); + } +}; + +/** * Create a new canvas element. This is more complex than a simple * document.createElement("canvas") because of IE and excanvas. */