Speed up filled charts by down-sampling.
[dygraphs.git] / auto_tests / tests / selection.js
... / ...
CommitLineData
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
9var SelectionTestCase = TestCase("selection");
10
11SelectionTestCase.prototype.setUp = function() {
12 document.body.innerHTML = "<div id='graph'></div>";
13};
14
15SelectionTestCase.prototype.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 assertEquals(0, g.getSelection());
26 g.setSelection(1);
27 assertEquals(1, g.getSelection());
28 g.setSelection(2);
29 assertEquals(2, g.getSelection());
30};
31
32SelectionTestCase.prototype.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 assertEquals(0, g.getSelection());
44 g.setSelection(1);
45 assertEquals(1, g.getSelection());
46 g.setSelection(2);
47 assertEquals(2, g.getSelection());
48 g.setSelection(3);
49 assertEquals(3, g.getSelection());
50};
51
52SelectionTestCase.prototype.testSetGetSelectionMissingPoints = function() {
53 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,null,null\n" +
77 "2,null,2,null\n" +
78 "3,null,null,3\n",
79 {
80 dataHandler: dataHandler
81 }
82 );
83
84 g.setSelection(0);
85 assertEquals(0, g.getSelection());
86 g.setSelection(1);
87 assertEquals(1, g.getSelection());
88 g.setSelection(2);
89 assertEquals(2, g.getSelection());
90};