X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=src%2Fdygraph.js;h=0b42d863ef26b534df69fe75384a091c755fd7b5;hb=20aaadda52577cfa97d25b350405726e7f51ffd1;hp=878a747e69355d8c016e91d5ca482363536a7667;hpb=3f5bea727e68f15ae8edbf58e853de5cdf10355f;p=dygraphs.git diff --git a/src/dygraph.js b/src/dygraph.js index 878a747..0b42d86 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -2671,7 +2671,7 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { this.canvas_.getContext('2d').clearRect(0, 0, this.width_, this.height_); if (this.getFunctionOption("drawCallback") !== null) { - this.getFunctionOption("drawCallback")(this, is_initial_draw); + this.getFunctionOption("drawCallback").call(this, this, is_initial_draw); } if (is_initial_draw) { this.readyFired_ = true; @@ -3578,19 +3578,49 @@ Dygraph.prototype.visibility = function() { /** * Changes the visibility of one or more series. * - * @param {number|number[]} num the series index or an array of series indices - * @param {boolean} value true or false, identifying the visibility. + * @param {number|number[]|object} num the series index or an array of series indices + * or a boolean array of visibility states by index + * or an object mapping series numbers, as keys, to + * visibility state (boolean values) + * @param {boolean} value the visibility state expressed as a boolean */ Dygraph.prototype.setVisibility = function(num, value) { var x = this.visibility(); + var numIsObject = false; - if (num.constructor !== Array) num = [num]; - - for (var i = 0; i < num.length; i++) { - if (num[i] < 0 || num[i] >= x.length) { - console.warn("invalid series number in setVisibility: " + num[i]); + if (!Array.isArray(num)) { + if (num !== null && typeof num === 'object') { + numIsObject = true; } else { - x[num[i]] = value; + num = [num]; + } + } + + if (numIsObject) { + for (var i in num) { + if (num.hasOwnProperty(i)) { + if (i < 0 || i >= x.length) { + console.warn("Invalid series number in setVisibility: " + i); + } else { + x[i] = num[i]; + } + } + } + } else { + for (var i = 0; i < num.length; i++) { + if (typeof num[i] === 'boolean') { + if (i >= x.length) { + console.warn("Invalid series number in setVisibility: " + i); + } else { + x[i] = num[i]; + } + } else { + if (num[i] < 0 || num[i] >= x.length) { + console.warn("Invalid series number in setVisibility: " + num[i]); + } else { + x[num[i]] = value; + } + } } }