Fork off Karma file for in-browser debug
[dygraphs.git] / auto_tests / tests / selection.js
1 // Copyright 2011 Google Inc. All Rights Reserved.
2
3 /**
4 * @fileoverview Regression test based on an optimization w/
5 * unforeseen consequences.
6 * @author danvk@google.com (Dan Vanderkam)
7 */
8
9 describe("selection", function() {
10
11 beforeEach(function() {
12 document.body.innerHTML = "<div id='graph'></div>";
13 });
14
15 it('testSetGetSelection', function() {
16 var graph = document.getElementById("graph");
17 var g = new Dygraph(graph,
18 "X,Y\n" +
19 "1,1\n" +
20 "50,50\n" +
21 "100,100\n"
22 );
23
24 g.setSelection(0);
25 assert.equal(0, g.getSelection());
26 g.setSelection(1);
27 assert.equal(1, g.getSelection());
28 g.setSelection(2);
29 assert.equal(2, g.getSelection());
30 });
31
32 it('testSetGetSelectionDense', function() {
33 var graph = document.getElementById("graph");
34 var g = new Dygraph(graph,
35 "X,Y\n" +
36 "1,1\n" +
37 "50,50\n" +
38 "50.0001,50.0001\n" +
39 "100,100\n"
40 );
41
42 g.setSelection(0);
43 assert.equal(0, g.getSelection());
44 g.setSelection(1);
45 assert.equal(1, g.getSelection());
46 g.setSelection(2);
47 assert.equal(2, g.getSelection());
48 g.setSelection(3);
49 assert.equal(3, g.getSelection());
50 });
51
52 it('testSetGetSelectionMissingPoints', function() {
53 var dataHandler = function() {};
54 dataHandler.prototype = new Dygraph.DataHandlers.DefaultHandler();
55 dataHandler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) {
56 var val = null;
57 if (setName == 'A') {
58 val = 1;
59 } else if (setName == 'B') {
60 val = 2;
61 } else if (setName == 'C') {
62 val = 3;
63 }
64 return [{
65 x: NaN,
66 y: NaN,
67 xval: val,
68 yval: val,
69 name: setName,
70 idx: val - 1
71 }];
72 };
73 var graph = document.getElementById("graph");
74 var g = new Dygraph(graph,
75 "X,A,B,C\n" +
76 "1,1,,\n" +
77 "2,,2,\n" +
78 "3,,,3\n",
79 {
80 dataHandler: dataHandler
81 }
82 );
83
84 g.setSelection(0);
85 assert.equal(0, g.getSelection());
86 g.setSelection(1);
87 assert.equal(1, g.getSelection());
88 g.setSelection(2);
89 assert.equal(2, g.getSelection());
90 });
91
92 });