60f4f8d1722452520def2e7875a340101466f3fb
[dygraphs.git] / auto_tests / tests / highlight_series_background.js
1 /**
2 * @fileoverview Tests for the highlightSeriesBackgroundAlpha and
3 * highlightSeriesBackgroundColor options.
4 * @author sergeyslepian@gmail.com
5 */
6
7 import Dygraph from '../../src/dygraph';
8 import * as utils from '../../src/dygraph-utils';
9 import Util from './Util';
10
11 describe("highlight-series-background", function() {
12
13 cleanupAfterEach();
14
15 function setupGraph(highlightSeriesBackgroundAlpha,
16 highlightSeriesBackgroundColor) {
17 var opts = {
18 width: 480,
19 height: 320,
20 labels: ['x', 'y'],
21 legend: 'always',
22 highlightSeriesOpts: {
23 strokeWidth: 1,
24 strokeBorderWidth: 1,
25 highlightCircleSize: 1
26 }
27 };
28
29 if (highlightSeriesBackgroundAlpha) utils.update(opts, {highlightSeriesBackgroundAlpha});
30 if (highlightSeriesBackgroundColor) utils.update(opts, {highlightSeriesBackgroundColor});
31
32 var data = [];
33 for (var j = 0; j < 10; j++) {
34 data.push([j, 0]);
35 }
36
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(null, '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 });