2 * @fileoverview Regression test for a bug involving data update while panning.
4 * See http://stackoverflow.com/questions/9528173
6 * @author dan@dygraphs.com (Dan Vanderkam)
8 var updateWhilePanningTestCase
= TestCase("update-while-panning");
10 updateWhilePanningTestCase
.prototype.setUp
= function() {
11 document
.body
.innerHTML
= "<div id='graph'></div>";
14 updateWhilePanningTestCase
.prototype.tearDown
= function() {
17 // This tests the following sequence:
18 // 1. Begin dragging a chart (x-panning)
19 // 2. Do a data update (updateOptions({file: ...}))
20 // 3. Verify that the y-axis is still well-defined.
21 updateWhilePanningTestCase
.prototype.testUpdateWhilePanning
= function() {
22 var sinewave
= function(start
, limit
, step
) {
24 for (var x
= start
; x
< limit
; x
+= step
) {
25 data
.push([x
, Math
.sin(x
)]);
36 var graph
= document
.getElementById("graph");
38 var g
= new Dygraph(graph
, sinewave(0, 6, 0.1), opts
);
39 assertEquals([-2, 2], g
.yAxisRange());
41 // Start a pan, but don't finish it yet.
42 DygraphOps
.dispatchMouseDown_Point(g
, 200, 100, {shiftKey
: true});
43 DygraphOps
.dispatchMouseMove_Point(g
, 100, 100, {shiftKey
: true});
44 assertEquals([-2, 2], g
.yAxisRange());
46 // Now do a data update. y-axis should remain the same.
47 g
.updateOptions({file
: sinewave(0, 7, 0.1)});
48 assertEquals([-2, 2], g
.yAxisRange());
50 // Keep the pan going.
51 DygraphOps
.dispatchMouseMove_Point(g
, 50, 100, {shiftKey
: true});
52 assertEquals([-2, 2], g
.yAxisRange());
54 // Now finish the pan.
55 DygraphOps
.dispatchMouseUp_Point(g
, 100, 100, {shiftKey
: true});
56 assertEquals([-2, 2], g
.yAxisRange());