Commit | Line | Data |
---|---|---|
1715eee9 | 1 | /** |
6833c463 DV |
2 | * @fileoverview Tests for the highlightSeriesBackgroundAlpha and |
3 | * highlightSeriesBackgroundColor options. | |
1715eee9 SS |
4 | * @author sergeyslepian@gmail.com |
5 | */ | |
6 | ||
6833c463 DV |
7 | import Dygraph from '../../src/dygraph'; |
8 | import * as utils from '../../src/dygraph-utils'; | |
9 | import Util from './Util'; | |
1715eee9 | 10 | |
6833c463 | 11 | describe("highlight-series-background", function() { |
1715eee9 | 12 | |
6833c463 | 13 | cleanupAfterEach(); |
1715eee9 | 14 | |
6833c463 DV |
15 | function setupGraph(highlightSeriesBackgroundAlpha, |
16 | highlightSeriesBackgroundColor) { | |
1715eee9 SS |
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 | ||
6833c463 DV |
29 | if (highlightSeriesBackgroundAlpha) utils.update(opts, {highlightSeriesBackgroundAlpha}); |
30 | if (highlightSeriesBackgroundColor) utils.update(opts, {highlightSeriesBackgroundColor}); | |
1715eee9 SS |
31 | |
32 | var data = []; | |
33 | for (var j = 0; j < 10; j++) { | |
34 | data.push([j, 0]); | |
35 | } | |
36 | ||
6833c463 | 37 | return new Dygraph('graph', data, opts); |
1715eee9 SS |
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) { | |
6833c463 | 69 | var graph = setupGraph(null, 'rgb(0,255,255)'); |
1715eee9 SS |
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 | }); | |
6833c463 | 109 | }); |