From: Danilo Reinert Date: Sun, 6 Sep 2015 19:09:05 +0000 (-0300) Subject: Support boolean array in setVisibility X-Git-Tag: v2.0.0~42^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=20aaadda52577cfa97d25b350405726e7f51ffd1;p=dygraphs.git Support boolean array in setVisibility --- diff --git a/auto_tests/tests/visibility.js b/auto_tests/tests/visibility.js index dad65dc..5f54639 100644 --- a/auto_tests/tests/visibility.js +++ b/auto_tests/tests/visibility.js @@ -71,4 +71,8 @@ it('testObjectSeriesShowAndHide', function() { assert.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null])); }); +it('testBooleanArraySeriesShowAndHide', function() { + assert.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null])); +}); + }); diff --git a/src/dygraph.js b/src/dygraph.js index 1de84a6..0b42d86 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -3578,10 +3578,10 @@ Dygraph.prototype.visibility = function() { /** * Changes the visibility of one or more series. * - * @param {number|number[]|object} num the series index or an array of series indices - or an object mapping series numbers, as keys, to - visibility state (boolean values) - * + * @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) { @@ -3608,10 +3608,18 @@ Dygraph.prototype.setVisibility = function(num, value) { } } else { 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 (typeof num[i] === 'boolean') { + if (i >= x.length) { + console.warn("Invalid series number in setVisibility: " + i); + } else { + x[i] = num[i]; + } } else { - x[num[i]] = value; + if (num[i] < 0 || num[i] >= x.length) { + console.warn("Invalid series number in setVisibility: " + num[i]); + } else { + x[num[i]] = value; + } } } }