consolidating scripts
[dygraphs.git] / auto_tests / tests / selection.js
CommitLineData
87bbdb4d
DV
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
e8c70e4e
DV
9import Dygraph from '../../src/dygraph';
10import DefaultHandler from '../../src/datahandler/default';
11
89fdcedb 12describe("selection", function() {
87bbdb4d 13
e8c70e4e 14cleanupAfterEach();
87bbdb4d 15
89fdcedb 16it('testSetGetSelection', function() {
87bbdb4d
DV
17 var graph = document.getElementById("graph");
18 var g = new Dygraph(graph,
19 "X,Y\n" +
20 "1,1\n" +
21 "50,50\n" +
22 "100,100\n"
23 );
24
25 g.setSelection(0);
89fdcedb 26 assert.equal(0, g.getSelection());
87bbdb4d 27 g.setSelection(1);
89fdcedb 28 assert.equal(1, g.getSelection());
87bbdb4d 29 g.setSelection(2);
89fdcedb
DV
30 assert.equal(2, g.getSelection());
31});
87bbdb4d 32
89fdcedb 33it('testSetGetSelectionDense', function() {
87bbdb4d
DV
34 var graph = document.getElementById("graph");
35 var g = new Dygraph(graph,
36 "X,Y\n" +
37 "1,1\n" +
38 "50,50\n" +
39 "50.0001,50.0001\n" +
40 "100,100\n"
41 );
42
43 g.setSelection(0);
89fdcedb 44 assert.equal(0, g.getSelection());
87bbdb4d 45 g.setSelection(1);
89fdcedb 46 assert.equal(1, g.getSelection());
87bbdb4d 47 g.setSelection(2);
89fdcedb 48 assert.equal(2, g.getSelection());
87bbdb4d 49 g.setSelection(3);
89fdcedb
DV
50 assert.equal(3, g.getSelection());
51});
8b7f7651 52
89fdcedb
DV
53it('testSetGetSelectionMissingPoints', function() {
54 var dataHandler = function() {};
e8c70e4e 55 dataHandler.prototype = new DefaultHandler();
8b7f7651
AV
56 dataHandler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) {
57 var val = null;
58 if (setName == 'A') {
59 val = 1;
60 } else if (setName == 'B') {
61 val = 2;
62 } else if (setName == 'C') {
63 val = 3;
64 }
65 return [{
66 x: NaN,
67 y: NaN,
68 xval: val,
69 yval: val,
70 name: setName,
71 idx: val - 1
72 }];
73 };
74 var graph = document.getElementById("graph");
75 var g = new Dygraph(graph,
76 "X,A,B,C\n" +
1b7afc93
DV
77 "1,1,,\n" +
78 "2,,2,\n" +
79 "3,,,3\n",
8b7f7651
AV
80 {
81 dataHandler: dataHandler
82 }
83 );
84
85 g.setSelection(0);
89fdcedb 86 assert.equal(0, g.getSelection());
8b7f7651 87 g.setSelection(1);
89fdcedb 88 assert.equal(1, g.getSelection());
8b7f7651 89 g.setSelection(2);
89fdcedb
DV
90 assert.equal(2, g.getSelection());
91});
92
93});