Commit | Line | Data |
---|---|---|
97583b90 DV |
1 | /** |
2 | * @fileoverview Regression test for a bug involving data update while panning. | |
3 | * | |
4 | * See http://stackoverflow.com/questions/9528173 | |
5 | * | |
6 | * @author dan@dygraphs.com (Dan Vanderkam) | |
7 | */ | |
97583b90 | 8 | |
e8c70e4e DV |
9 | import Dygraph from '../../src/dygraph'; |
10 | import DygraphOps from './DygraphOps'; | |
11 | ||
12 | describe("update-while-panning", function() { | |
97583b90 | 13 | |
e8c70e4e | 14 | cleanupAfterEach(); |
97583b90 DV |
15 | |
16 | // This tests the following sequence: | |
17 | // 1. Begin dragging a chart (x-panning) | |
18 | // 2. Do a data update (updateOptions({file: ...})) | |
19 | // 3. Verify that the y-axis is still well-defined. | |
89fdcedb | 20 | it('testUpdateWhilePanning', function() { |
97583b90 DV |
21 | var sinewave = function(start, limit, step) { |
22 | var data = []; | |
23 | for (var x = start; x < limit; x += step) { | |
24 | data.push([x, Math.sin(x)]); | |
25 | } | |
26 | return data; | |
27 | }; | |
28 | ||
29 | var opts = { | |
30 | width: 480, | |
31 | height: 320, | |
1b7afc93 DV |
32 | valueRange: [-2, 2], |
33 | labels: ['X', 'Y'] | |
97583b90 DV |
34 | }; |
35 | ||
36 | var graph = document.getElementById("graph"); | |
37 | ||
38 | var g = new Dygraph(graph, sinewave(0, 6, 0.1), opts); | |
89fdcedb | 39 | assert.deepEqual([-2, 2], g.yAxisRange()); |
97583b90 DV |
40 | |
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}); | |
89fdcedb | 44 | assert.deepEqual([-2, 2], g.yAxisRange()); |
97583b90 DV |
45 | |
46 | // Now do a data update. y-axis should remain the same. | |
47 | g.updateOptions({file: sinewave(0, 7, 0.1)}); | |
89fdcedb | 48 | assert.deepEqual([-2, 2], g.yAxisRange()); |
97583b90 DV |
49 | |
50 | // Keep the pan going. | |
51 | DygraphOps.dispatchMouseMove_Point(g, 50, 100, {shiftKey: true}); | |
89fdcedb | 52 | assert.deepEqual([-2, 2], g.yAxisRange()); |
97583b90 DV |
53 | |
54 | // Now finish the pan. | |
55 | DygraphOps.dispatchMouseUp_Point(g, 100, 100, {shiftKey: true}); | |
89fdcedb DV |
56 | assert.deepEqual([-2, 2], g.yAxisRange()); |
57 | }); | |
97583b90 | 58 | |
89fdcedb DV |
59 | |
60 | }); |