2 * @fileoverview Tests relating to annotations
4 * @author danvk@google.com (Dan Vanderkam)
6 var AnnotationsTestCase
= TestCase("annotations");
8 AnnotationsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 AnnotationsTestCase
.prototype.tearDown
= function() {
15 AnnotationsTestCase
.prototype.testAnnotationsDrawn
= function() {
27 var graph
= document
.getElementById("graph");
28 var g
= new Dygraph(graph
, data
, opts
);
46 assertEquals(2, g
.annotations().length
);
47 var a1
= document
.getElementsByClassName('ann1');
48 assertEquals(1, a1
.length
);
50 assertEquals('A', a1
.textContent
);
52 var a2
= document
.getElementsByClassName('ann2');
53 assertEquals(1, a2
.length
);
55 assertEquals('B', a2
.textContent
);
58 // Some errors that should be flagged:
59 // 1. Invalid series name (e.g. 'X' or 'non-existent')
60 // 2. Passing a string as 'x' instead of a number (e.g. x: '1')
62 AnnotationsTestCase
.prototype.testAnnotationsDontDisappearOnResize
= function() {
72 var graph
= document
.getElementById("graph");
73 var g
= new Dygraph(graph
, data
, opts
);
84 // Check that it displays at all
85 assertEquals(1, g
.annotations().length
);
86 var a1
= document
.getElementsByClassName('ann1');
87 assertEquals(1, a1
.length
);
89 assertEquals('A', a1
.textContent
);
91 // ... and that resizing doesn't kill it.
93 assertEquals(1, g
.annotations().length
);
94 var a1
= document
.getElementsByClassName('ann1');
95 assertEquals(1, a1
.length
);
97 assertEquals('A', a1
.textContent
);
100 // Verify that annotations outside of the visible x-range are not shown.
101 AnnotationsTestCase
.prototype.testAnnotationsOutOfRangeX
= function() {
111 var graph
= document
.getElementById("graph");
112 var g
= new Dygraph(graph
, data
, opts
);
123 // Check that it displays at all
124 assertEquals(1, g
.annotations().length
);
125 var a1
= document
.getElementsByClassName('ann1');
126 assertEquals(1, a1
.length
);
128 assertEquals('A', a1
.textContent
);
130 // ... and that panning right removes the annotation.
131 g
.updateOptions({dateWindow
: [2, 6]});
132 assertEquals(1, g
.annotations().length
);
133 a1
= document
.getElementsByClassName('ann1');
134 assertEquals(0, a1
.length
);
136 // ... and that panning left brings it back.
137 g
.updateOptions({dateWindow
: [0, 4]});
138 assertEquals(1, g
.annotations().length
);
139 a1
= document
.getElementsByClassName('ann1');
140 assertEquals(1, a1
.length
);
143 // Verify that annotations outside of the visible y-range are not shown.
144 AnnotationsTestCase
.prototype.testAnnotationsOutOfRangeY
= function() {
154 var graph
= document
.getElementById("graph");
155 var g
= new Dygraph(graph
, data
, opts
);
166 // ... check that panning up removes the annotation.
167 g
.updateOptions({valueRange
: [0.5, 2.5]});
168 assertEquals(1, g
.annotations().length
);
169 a1
= document
.getElementsByClassName('ann1');
170 assertEquals(0, a1
.length
);
172 // ... and that panning down brings it back.
173 g
.updateOptions({valueRange
: [-1, 1]});
174 assertEquals(1, g
.annotations().length
);
175 a1
= document
.getElementsByClassName('ann1');
176 assertEquals(1, a1
.length
);
179 AnnotationsTestCase
.prototype.testAnnotationsDrawnInDrawCallback
= function() {
185 var graph
= document
.getElementById("graph");
188 var g
= new Dygraph(graph
, data
, {
191 drawCallback
: function(g
, initial
) {
206 assertEquals([true, false], calls
);