From 1cf11047ed006208ed70bfbe5666254264137a6a Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Wed, 23 Dec 2009 17:51:07 -0500 Subject: [PATCH] interface to control series visibility --- dygraph.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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. */ -- 2.7.4