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() {
15 function getXLabels() {
16 var x_labels
= document
.getElementsByClassName("dygraph-axis-label-x");
18 for (var i
= 0; i
< x_labels
.length
; i
++) {
19 ary
.push(x_labels
[i
].innerHTML
);
24 InteractionModelTestCase
.prototype.pan
= function(g
, xRange
, yRange
) {
25 var originalXRange
= g
.xAxisRange();
26 var originalYRange
= g
.yAxisRange(0);
28 DygraphOps
.dispatchMouseDown(g
, xRange
[0], yRange
[0]);
29 DygraphOps
.dispatchMouseMove(g
, xRange
[1], yRange
[0]); // this is really necessary.
30 DygraphOps
.dispatchMouseUp(g
, xRange
[1], yRange
[0]);
32 assertEqualsDelta(xRange
, g
.xAxisRange(), 0.2);
33 // assertEqualsDelta(originalYRange, g.yAxisRange(0), 0.2); // Not
true, it
's something in the middle.
35 var midX = (xRange[1] - xRange[0]) / 2;
36 DygraphOps.dispatchMouseDown(g, midX, yRange[0]);
37 DygraphOps.dispatchMouseMove(g, midX, yRange[1]); // this is really necessary.
38 DygraphOps.dispatchMouseUp(g, midX, yRange[1]);
40 assertEqualsDelta(xRange, g.xAxisRange(), 0.2);
41 assertEqualsDelta(yRange, g.yAxisRange(0), 0.2);
45 * This tests that when changing the interaction model so pan is used instead
46 * of zoom as the default behavior, a standard click method is still called.
48 InteractionModelTestCase.prototype.testClickCallbackIsCalled = function() {
51 var clickCallback = function(event, x) {
62 var graph = document.getElementById("graph");
63 var g = new Dygraph(graph, data,
67 clickCallback : clickCallback
70 DygraphOps.dispatchMouseDown_Point(g, 10, 10);
71 DygraphOps.dispatchMouseMove_Point(g, 10, 10);
72 DygraphOps.dispatchMouseUp_Point(g, 10, 10);
74 assertEquals(20, clicked);
78 * This tests that when changing the interaction model so pan is used instead
79 * of zoom as the default behavior, a standard click method is still called.
81 InteractionModelTestCase.prototype.testClickCallbackIsCalledOnCustomPan = function() {
84 var clickCallback = function(event, x) {
95 function customDown(event, g, context) {
96 context.initializeMouseDown(event, g, context);
97 Dygraph.startPan(event, g, context);
100 function customMove(event, g, context) {
101 Dygraph.movePan(event, g, context);
104 function customUp(event, g, context) {
105 Dygraph.endPan(event, g, context);
111 clickCallback : clickCallback,
113 'mousedown
' : customDown,
114 'mousemove
' : customMove,
115 'mouseup
' : customUp,
119 var graph = document.getElementById("graph");
120 var g = new Dygraph(graph, data, opts);
122 DygraphOps.dispatchMouseDown_Point(g, 10, 10);
123 DygraphOps.dispatchMouseMove_Point(g, 10, 10);
124 DygraphOps.dispatchMouseUp_Point(g, 10, 10);
126 assertEquals(20, clicked);