Add a "highlightSeriesBackgroundColor" option
[dygraphs.git] / auto_tests / tests / highlight_series_background.js
CommitLineData
1715eee9
SS
1/**
2 * @fileoverview Tests for the highlightSeriesBackgroundAlpha and highlightSeriesBackgroundColor options.
3 * @author sergeyslepian@gmail.com
4 */
5
6describe("highlight-series-background", function() {
7
8 beforeEach(function () {
9 document.body.innerHTML = "<div id='graph'></div>";
10 });
11
12 afterEach(function () {
13 });
14
15 function setupGraph(highlightSeriesBackgroundAlpha, highlightSeriesBackgroundColor) {
16 var opts = {
17 width: 480,
18 height: 320,
19 labels: ['x', 'y'],
20 legend: 'always',
21 highlightSeriesOpts: {
22 strokeWidth: 1,
23 strokeBorderWidth: 1,
24 highlightCircleSize: 1
25 }
26 };
27
28 if(highlightSeriesBackgroundAlpha !== undefined) opts.highlightSeriesBackgroundAlpha = highlightSeriesBackgroundAlpha;
29 if(highlightSeriesBackgroundColor !== undefined) opts.highlightSeriesBackgroundColor = highlightSeriesBackgroundColor;
30
31 var data = [];
32 for (var j = 0; j < 10; j++) {
33 data.push([j, 0]);
34 }
35
36 var graph = document.getElementById("graph");
37 return new Dygraph(graph, data, opts);
38 }
39
40 it('testDefaultHighlight', function(done) {
41 var graph = setupGraph();
42
43 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
44
45 graph.setSelection(0, 'y', true);
46
47 // handle background color fade-in time
48 setTimeout(function() {
49 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,255,255,127]);
50 done();
51 }, 1000);
52 });
53
54 it('testNoHighlight', function(done) {
55 var graph = setupGraph(1);
56
57 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
58
59 graph.setSelection(0, 'y', true);
60
61 // handle background color fade-in time
62 setTimeout(function() {
63 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
64 done();
65 }, 1000);
66 });
67
68 it('testCustomHighlightColor', function(done) {
69 var graph = setupGraph(undefined, 'rgb(0,255,255)');
70
71 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
72
73 graph.setSelection(0, 'y', true);
74
75 // handle background color fade-in time
76 setTimeout(function() {
77 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,255,255,127]);
78 done();
79 }, 1000);
80 });
81
82 it('testCustomHighlightAlpha', function(done) {
83 var graph = setupGraph(0.3);
84
85 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
86
87 graph.setSelection(0, 'y', true);
88
89 // handle background color fade-in time
90 setTimeout(function() {
91 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,255,255,179]);
92 done();
93 }, 1000);
94 });
95
96 it('testCustomHighlightColorAndAlpha', function(done) {
97 var graph = setupGraph(0.7,'rgb(255,0,0)');
98
99 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
100
101 graph.setSelection(0, 'y', true);
102
103 // handle background color fade-in time
104 setTimeout(function() {
105 assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,0,0,76]);
106 done();
107 }, 1000);
108 });
109});