X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=dygraph.js;h=f82285b73f56fd65f93d25e490545ab6be8b4b71;hb=0755e27d80c9d4c7dffbeaded74b545d71c11466;hp=4502bd41f72f101111316f5f52c82a146f404888;hpb=cdcb628b3219ffc94666f424256df33d4401286c;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 4502bd4..f82285b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -3602,19 +3602,25 @@ Dygraph.prototype.visibility = function() { }; /** - * Changes the visiblity of a series. + * Changes the visibility of one or more series. * - * @param {number} num the series index + * @param {number|number[]} num the series index or an array of series indices * @param {boolean} value true or false, identifying the visibility. */ Dygraph.prototype.setVisibility = function(num, value) { var x = this.visibility(); - if (num < 0 || num >= x.length) { - console.warn("invalid series number in setVisibility: " + num); - } else { - x[num] = value; - this.predraw_(); + + 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]); + } else { + x[num[i]] = value; + } } + + this.predraw_(); }; /** @@ -3677,6 +3683,35 @@ Dygraph.prototype.indexFromSetName = function(name) { }; /** + * Find the row number corresponding to the given x-value. + * Returns null if there is no such x-value in the data. + * If there are multiple rows with the same x-value, this will return the + * first one. + * @param {number} xVal The x-value to look for (e.g. millis since epoch). + * @return {?number} The row number, which you can pass to getValue(), or null. + */ +Dygraph.prototype.getRowForX = function(xVal) { + var low = 0, + high = this.numRows() - 1; + + while (low <= high) { + var idx = (high + low) >> 1; + var x = this.getValue(idx, 0); + if (x < xVal) { + low = idx + 1; + } else if (x > xVal) { + high = idx - 1; + } else if (low != idx) { // equal, but there may be an earlier match. + high = idx; + } else { + return idx; + } + } + + return null; +}; + +/** * Trigger a callback when the dygraph has drawn itself and is ready to be * manipulated. This is primarily useful when dygraphs has to do an XHR for the * data (i.e. a URL is passed as the data source) and the chart is drawn