Support boolean array in setVisibility
[dygraphs.git] / auto_tests / tests / visibility.js
... / ...
CommitLineData
1/**
2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
4 */
5
6describe("visibility", function() {
7
8beforeEach(function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10});
11
12afterEach(function() {
13});
14
15/**
16 * Does a bunch of the shared busywork of setting up a graph and changing its visibility.
17 * @param {boolean} startingVisibility The starting visibility of all series on the graph
18 * @param {*[]} setVisibilityArgs An array of arguments to be passed directly to setVisibility()
19 * @returns {string} The output of Util.getLegend() called after the visibility is set
20 */
21var getVisibleSeries = function(startingVisibility, setVisibilityArgs) {
22 var opts = {
23 width: 480,
24 height: 320,
25 labels: ['x', 'A', 'B', 'C', 'D', 'E'],
26 legend: 'always',
27 visibility: []
28 };
29
30 // set the starting visibility
31 var numSeries = opts.labels.length - 1;
32 for(var i = 0; i < numSeries; i++) {
33 opts.visibility[i] = startingVisibility;
34 }
35
36 var data = [];
37 for (var j = 0; j < 10; j++) {
38 data.push([j, 1, 2, 3, 4, 5]);
39 }
40
41 var graph = document.getElementById("graph");
42 var g = new Dygraph(graph, data, opts);
43
44 g.setVisibility.apply(g, setVisibilityArgs);
45
46 return Util.getLegend();
47};
48
49it('testDefaultCases', function() {
50 assert.equal(' A B C D E', getVisibleSeries(true, [[], true]));
51 assert.equal('', getVisibleSeries(false, [[], true]));
52});
53
54it('testSingleSeriesHide', function() {
55 assert.equal(' A C D E', getVisibleSeries(true, [1, false]));
56});
57
58it('testSingleSeriesShow', function() {
59 assert.equal(' E', getVisibleSeries(false, [4, true]));
60});
61
62it('testMultiSeriesHide', function() {
63 assert.equal(' A E', getVisibleSeries(true, [[1,2,3], false]));
64});
65
66it('testMultiSeriesShow', function() {
67 assert.equal(' B D', getVisibleSeries(false, [[1,3], true]));
68});
69
70it('testObjectSeriesShowAndHide', function() {
71 assert.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
72});
73
74it('testBooleanArraySeriesShowAndHide', function() {
75 assert.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null]));
76});
77
78});