763504c2c7120b91c48c452164fa5df731bde7f1
2 * @fileoverview Test cases for a graph contained in a scrolling div
4 * @author konigsberg@google.com (Robert Konigsbrg)
6 var ScrollingDivTestCase
= TestCase("scrolling-div");
10 ScrollingDivTestCase
.prototype.setUp
= function() {
13 "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\n" +
14 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\n" +
15 "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\n" +
16 "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\n" +
17 "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n" +
18 "non proident, sunt in culpa qui officia deserunt mollit anim id est\n" +
21 document
.body
.innerHTML
=
22 "<div id='scroller' style='overflow: scroll; height: 450px; width: 800px;'>" +
23 "<div id='graph'></div>" +
24 "<div style='height:100px; background-color:green;'>" + LOREM_IPSUM
+ " </div>" +
25 "<div style='height:100px; background-color:red;'>" + LOREM_IPSUM
+ "</div>" +
38 var graph
= document
.getElementById("graph");
41 g
= new Dygraph(graph
, data
,
45 highlightCircleSize
: 6,
46 pointClickCallback
: function(evt
, point
) {
54 // This is usually something like 15, but for OS X Lion and its auto-hiding
55 // scrollbars, it's 0. This is a large enough difference that we need to
56 // consider it when synthesizing clicks.
57 // Adapted from http://davidwalsh.name/detect-scrollbar
-width
58 var detectScrollbarWidth
= function() {
59 // Create the measurement node
60 var scrollDiv
= document
.createElement("div");
61 scrollDiv
.style
.width
= "100px";
62 scrollDiv
.style
.height
= "100px";
63 scrollDiv
.style
.overflow
= "scroll";
64 scrollDiv
.style
.position
= "absolute";
65 scrollDiv
.style
.top
= "-9999px";
66 document
.body
.appendChild(scrollDiv
);
68 // Get the scrollbar width
69 var scrollbarWidth
= scrollDiv
.offsetWidth
- scrollDiv
.clientWidth
;
72 document
.body
.removeChild(scrollDiv
);
74 return scrollbarWidth
;
77 ScrollingDivTestCase
.prototype.tearDown
= function() {
81 * This tests that when the nested div is unscrolled, things work normally.
83 ScrollingDivTestCase
.prototype.testUnscrolledDiv
= function() {
85 document
.getElementById('scroller').scrollTop
= 0;
94 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mousemove' }));
95 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mousedown' }));
96 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mouseup' }));
98 assertEquals(40, point
.xval
);
99 assertEquals(4, point
.yval
);
103 * This tests that when the nested div is scrolled, things work normally.
105 ScrollingDivTestCase
.prototype.testScrolledDiv
= function() {
106 document
.getElementById('scroller').scrollTop
= 117;
110 clientY
: 30 - detectScrollbarWidth(),
115 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mousemove' }));
116 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mousedown' }));
117 DygraphOps
.dispatchCanvasEvent(g
, DygraphOps
.createEvent(clickOn4_40
, { type
: 'mouseup' }));
119 assertEquals(40, point
.xval
);
120 assertEquals(4, point
.yval
);