X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdygraph.js;h=a28e231426b4b38b09872429088c54baf3fcbc3b;hb=bf50de0db3094fc5155efc8aee14112df2545e42;hp=4f3ce77a93cbf1502f0b68fae7fd760042164d60;hpb=b617ba25a4500750fd4ffdc7ac12758c7e1b3823;p=dygraphs.git diff --git a/src/dygraph.js b/src/dygraph.js index 4f3ce77..a28e231 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -1656,10 +1656,11 @@ Dygraph.prototype.resetZoom = function() { this.zoomed_x_ = false; this.zoomed_y_ = false; - var minDate = this.rawData_[0][0]; - var maxDate = this.rawData_[this.rawData_.length - 1][0]; + //calculate extremes to avoid lack of padding on reset. + var extremes = this.xAxisExtremes(); + var minDate = extremes[0], + maxDate = extremes[1]; - // With only one frame, don't bother calculating extreme ranges. // TODO(danvk): merge this block w/ the code below. if (!this.getBooleanOption("animatedZooms")) { this.dateWindow_ = null; @@ -3578,19 +3579,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; + } + } } }