2 * @fileoverview Test cases for the interaction model.
4 * @author konigsberg@google.com (Robert Konigsbrg)
6 var InteractionModelTestCase
= TestCase("interaction-model");
8 InteractionModelTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 InteractionModelTestCase
.prototype.tearDown
= function() {
32 function getXLabels() {
33 var x_labels
= document
.getElementsByClassName("dygraph-axis-label-x");
35 for (var i
= 0; i
< x_labels
.length
; i
++) {
36 ary
.push(x_labels
[i
].innerHTML
);
41 InteractionModelTestCase
.prototype.pan
= function(g
, xRange
, yRange
) {
42 var originalXRange
= g
.xAxisRange();
43 var originalYRange
= g
.yAxisRange(0);
45 DygraphOps
.dispatchMouseDown(g
, xRange
[0], yRange
[0]);
46 DygraphOps
.dispatchMouseMove(g
, xRange
[1], yRange
[0]); // this is really necessary.
47 DygraphOps
.dispatchMouseUp(g
, xRange
[1], yRange
[0]);
49 assertEqualsDelta(xRange
, g
.xAxisRange(), 0.2);
50 // assertEqualsDelta(originalYRange, g.yAxisRange(0), 0.2); // Not
true, it
's something in the middle.
52 var midX = (xRange[1] - xRange[0]) / 2;
53 DygraphOps.dispatchMouseDown(g, midX, yRange[0]);
54 DygraphOps.dispatchMouseMove(g, midX, yRange[1]); // this is really necessary.
55 DygraphOps.dispatchMouseUp(g, midX, yRange[1]);
57 assertEqualsDelta(xRange, g.xAxisRange(), 0.2);
58 assertEqualsDelta(yRange, g.yAxisRange(0), 0.2);
62 * This tests that when changing the interaction model so pan is used instead
63 * of zoom as the default behavior, a standard click method is still called.
65 InteractionModelTestCase.prototype.testClickCallbackIsCalled = function() {
68 var clickCallback = function(event, x) {
72 var graph = document.getElementById("graph");
73 var g = new Dygraph(graph, data1,
77 clickCallback : clickCallback
80 DygraphOps.dispatchMouseDown_Point(g, 10, 10);
81 DygraphOps.dispatchMouseMove_Point(g, 10, 10);
82 DygraphOps.dispatchMouseUp_Point(g, 10, 10);
84 assertEquals(20, clicked);
88 * This tests that when changing the interaction model so pan is used instead
89 * of zoom as the default behavior, a standard click method is still called.
91 InteractionModelTestCase.prototype.testClickCallbackIsCalledOnCustomPan = function() {
94 var clickCallback = function(event, x) {
98 function customDown(event, g, context) {
99 context.initializeMouseDown(event, g, context);
100 Dygraph.startPan(event, g, context);
103 function customMove(event, g, context) {
104 Dygraph.movePan(event, g, context);
107 function customUp(event, g, context) {
108 Dygraph.endPan(event, g, context);
114 clickCallback : clickCallback,
116 'mousedown
' : customDown,
117 'mousemove
' : customMove,
118 'mouseup
' : customUp,
122 var graph = document.getElementById("graph");
123 var g = new Dygraph(graph, data1, opts);
125 DygraphOps.dispatchMouseDown_Point(g, 10, 10);
126 DygraphOps.dispatchMouseMove_Point(g, 10, 10);
127 DygraphOps.dispatchMouseUp_Point(g, 10, 10);
129 assertEquals(20, clicked);
132 InteractionModelTestCase.clickAt = function(g, x, y) {
133 DygraphOps.dispatchMouseDown(g, x, y);
134 DygraphOps.dispatchMouseMove(g, x, y);
135 DygraphOps.dispatchMouseUp(g, x, y);
139 * A sanity test to ensure pointClickCallback is called.
141 InteractionModelTestCase.prototype.testPointClickCallback = function() {
143 var g = new Dygraph(document.getElementById("graph"), data2, {
144 pointClickCallback : function(event, point) {
149 InteractionModelTestCase.clickAt(g, 4, 40);
151 assertEquals(4, clicked.xval);
152 assertEquals(40, clicked.yval);
156 * A sanity test to ensure pointClickCallback is not called when out of range.
158 InteractionModelTestCase.prototype.testNoPointClickCallbackWhenOffPoint = function() {
160 var g = new Dygraph(document.getElementById("graph"), data2, {
161 pointClickCallback : function(event, point) {
166 InteractionModelTestCase.clickAt(g, 5, 40);
168 assertUndefined(clicked);
172 * Ensures pointClickCallback circle size is taken into account.
174 InteractionModelTestCase.prototype.testPointClickCallback_circleSize = function() {
175 // TODO(konigsberg): Implement.
179 * Ensures that pointClickCallback is called prior to clickCallback
181 InteractionModelTestCase.prototype.testPointClickCallbackCalledPriorToClickCallback = function() {
185 var g = new Dygraph(document.getElementById("graph"), data2, {
186 pointClickCallback : function(event, point) {
188 pointClicked = counter;
190 clickCallback : function(event, point) {
196 InteractionModelTestCase.clickAt(g, 4, 40);
197 assertEquals(1, pointClicked);
198 assertEquals(2, clicked);
202 * Ensures that when there's no pointClickCallback
, clicking on a point still calls
205 InteractionModelTestCase
.prototype.testClickCallback_clickOnPoint
= function() {
207 var g
= new Dygraph(document
.getElementById("graph"), data2
, {
208 clickCallback
: function(event
, point
) {
213 InteractionModelTestCase
.clickAt(g
, 4, 40);
214 assertEquals(1, clicked
);