2 * @fileoverview Test cases for a graph contained in a scrolling div
4 * @author konigsberg@google.com (Robert Konigsbrg)
6 describe("scrolling-div", function() {
10 beforeEach(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
, p
) {
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 afterEach(function() {
81 * This tests that when the nested div is unscrolled, things work normally.
83 it('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 assert
.equal(40, point
.xval
);
99 assert
.equal(4, point
.yval
);
103 * This tests that when the nested div is scrolled, things work normally.
105 it('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 assert
.equal(40, point
.xval
);
120 assert
.equal(4, point
.yval
);