2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
6 import Dygraph from
'../../src/dygraph';
7 import Util from
'./Util';
9 describe("visibility", function() {
14 * Does a bunch of the shared busywork of setting up a graph and changing its visibility.
15 * @param {boolean} startingVisibility The starting visibility of all series on the graph
16 * @param {*[]} setVisibilityArgs An array of arguments to be passed directly to setVisibility()
17 * @returns {string} The output of Util.getLegend() called after the visibility is set
19 var getVisibleSeries
= function(startingVisibility
, setVisibilityArgs
) {
23 labels
: ['x', 'A', 'B', 'C', 'D', 'E'],
28 // set the starting visibility
29 var numSeries
= opts
.labels
.length
- 1;
30 for(var i
= 0; i
< numSeries
; i
++) {
31 opts
.visibility
[i
] = startingVisibility
;
35 for (var j
= 0; j
< 10; j
++) {
36 data
.push([j
, 1, 2, 3, 4, 5]);
39 var graph
= document
.getElementById("graph");
40 var g
= new Dygraph(graph
, data
, opts
);
42 g
.setVisibility
.apply(g
, setVisibilityArgs
);
44 return Util
.getLegend();
47 it('testDefaultCases', function() {
48 assert
.equal(' A B C D E', getVisibleSeries(true, [[], true]));
49 assert
.equal('', getVisibleSeries(false, [[], true]));
52 it('testSingleSeriesHide', function() {
53 assert
.equal(' A C D E', getVisibleSeries(true, [1, false]));
56 it('testSingleSeriesShow', function() {
57 assert
.equal(' E', getVisibleSeries(false, [4, true]));
60 it('testMultiSeriesHide', function() {
61 assert
.equal(' A E', getVisibleSeries(true, [[1,2,3], false]));
64 it('testMultiSeriesShow', function() {
65 assert
.equal(' B D', getVisibleSeries(false, [[1,3], true]));
68 it('testObjectSeriesShowAndHide', function() {
69 assert
.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
72 it('testBooleanArraySeriesShowAndHide', function() {
73 assert
.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null]));