Tests for when the graph is embedded in a scrolling div.
[dygraphs.git] / auto_tests / tests / scrolling_div.js
CommitLineData
bf06e350
RK
1/**
2 * @fileoverview Test cases for a graph contained in a scrolling div
3 *
4 * @author konigsberg@google.com (Robert Konigsbrg)
5 */
6var ScrollingDivTestCase = TestCase("scrolling-div");
7
8ScrollingDivTestCase.prototype.setUp = function() {
9
10var LOREM_IPSUM =
11 "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\n" +
12 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\n" +
13 "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\n" +
14 "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\n" +
15 "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n" +
16 "non proident, sunt in culpa qui officia deserunt mollit anim id est\n" +
17 "laborum.</p>";
18
19 document.body.innerHTML =
20 "<div style='overflow: scroll; height: 450px; width: 800px;'>" +
21 "<a name='TOP'></a><div id='graph'></div>" +
22 "<div style='height:100px; background-color:green;'>" + LOREM_IPSUM + " </div>" +
23 "<div style='height:100px; background-color:red;'>" + LOREM_IPSUM + "</div>" +
24 "<a name='BOTTOM'></a>" +
25 "</div>";
26
27 var data = [
28 [ 10, 1 ],
29 [ 20, 3 ],
30 [ 30, 2 ],
31 [ 40, 4 ],
32 [ 50, 3 ],
33 [ 60, 5 ],
34 [ 70, 4 ],
35 [ 80, 6 ] ];
36
37 var graph = document.getElementById("graph");
38
39 this.point = null;
40 var self = this;
41 this.g = new Dygraph(graph, data,
42 {
43 labels : ['a', 'b'],
44 drawPoints : true,
45 highlightCircleSize : 6,
46 pointClickCallback : function(evt, point) {
47 self.point = point;
48 }
49 }
50 );
51
52};
53
54ScrollingDivTestCase.prototype.tearDown = function() {
55};
56
57/**
58 * This tests that when the nested div is unscrolled, things work normally.
59 */
60ScrollingDivTestCase.prototype.testUnscrolledDiv = function() {
61
62 window.location.href="#TOP";
63
64 var clickOn4_40 = {
65 clientX: 244,
66 clientY: 131,
67 screenX: 416,
68 screenY: 320
69 };
70
71 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
72 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
73 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
74
75 assertEquals(40, this.point.xval);
76 assertEquals(4, this.point.yval);
77};
78
79/**
80 * This tests that when the nested div is scrolled, things work normally.
81 */
82ScrollingDivTestCase.prototype.testScrolledDiv = function() {
83 window.location.href="#BOTTOM";
84
85 var clickOn4_40 = {
86 clientX: 244,
87 clientY: 20,
88 screenX: 416,
89 screenY: 160
90 };
91
92 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
93 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
94 DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
95
96 assertEquals(40, this.point.xval);
97 assertEquals(4, this.point.yval);
98};
99
100/*
101NORMAL
102
103mousedown
104MouseEvent
105
106defaultPrevented?
107detail?
108returnValue?
109
110srcElement
111target
112toElement
113
114type: "mousedown"
115
116pageX: 244
117pageY: 131
118layerX: 233
119layerY: 281
120offsetX: 236
121offsetY: 235
122which: 1
123x: 244
124y: 131
125
126mouseup
127MouseEvent
128
129clientX: 244
130clientY: 131
131screenX: 416
132screenY: 320
133type: "mouseup"
134
135pageX: 244
136pageY: 131
137layerX: 233
138layerY: 281
139offsetX: 236
140offsetY: 235
141which: 1
142x: 244
143y: 131
144
145
146SCROLLED
147
148mousedown
149MouseEvent
150
151clientX: 244
152clientY: 20
153pageX: 244
154pageY: 20
155screenX: 417
156screenY: 160
157type: "mousedown"
158
159layerX: 233
160layerY: 170
161offsetX: 236
162offsetY: 124
163which: 1
164x: 244
165y: 20
166
167mouseup
168MouseEvent
169
170clientX: 244
171clientY: 20
172layerX: 233
173layerY: 170
174offsetX: 236
175offsetY: 124
176pageX: 244
177pageY: 20
178screenX: 417
179screenY: 160
180type: "mouseup"
181which: 1
182x: 244
183y: 20
184*/