Fix two inconsistencies in dygraph-externs.js (#859)
[dygraphs.git] / auto_tests / tests / visibility.js
CommitLineData
1f0f434a
SS
1/**
2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
4 */
5
e8c70e4e
DV
6import Dygraph from '../../src/dygraph';
7import Util from './Util';
1f0f434a 8
e8c70e4e 9describe("visibility", function() {
1f0f434a 10
e8c70e4e 11cleanupAfterEach();
1f0f434a
SS
12
13/**
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
18 */
319d0361 19var getVisibleSeries = function(startingVisibility, setVisibilityArgs) {
1f0f434a
SS
20 var opts = {
21 width: 480,
22 height: 320,
23 labels: ['x', 'A', 'B', 'C', 'D', 'E'],
24 legend: 'always',
25 visibility: []
26 };
27
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;
32 }
33
34 var data = [];
35 for (var j = 0; j < 10; j++) {
36 data.push([j, 1, 2, 3, 4, 5]);
37 }
38
39 var graph = document.getElementById("graph");
40 var g = new Dygraph(graph, data, opts);
41
42 g.setVisibility.apply(g, setVisibilityArgs);
43
44 return Util.getLegend();
45};
46
89fdcedb
DV
47it('testDefaultCases', function() {
48 assert.equal(' A B C D E', getVisibleSeries(true, [[], true]));
49 assert.equal('', getVisibleSeries(false, [[], true]));
50});
1f0f434a 51
89fdcedb
DV
52it('testSingleSeriesHide', function() {
53 assert.equal(' A C D E', getVisibleSeries(true, [1, false]));
54});
1f0f434a 55
89fdcedb
DV
56it('testSingleSeriesShow', function() {
57 assert.equal(' E', getVisibleSeries(false, [4, true]));
58});
1f0f434a 59
89fdcedb
DV
60it('testMultiSeriesHide', function() {
61 assert.equal(' A E', getVisibleSeries(true, [[1,2,3], false]));
62});
1f0f434a 63
89fdcedb
DV
64it('testMultiSeriesShow', function() {
65 assert.equal(' B D', getVisibleSeries(false, [[1,3], true]));
66});
67
e5cc0a4c
DR
68it('testObjectSeriesShowAndHide', function() {
69 assert.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
94fff6f2
DR
70});
71
20aaadda
DR
72it('testBooleanArraySeriesShowAndHide', function() {
73 assert.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null]));
74});
75
89fdcedb 76});