update reference to drawGrid option
[dygraphs.git] / auto_tests / tests / data_api.js
1 /**
2 * @fileoverview Tests for data access methods.
3 *
4 * @author danvdk@gmail.com (Dan Vanderkam)
5 */
6 var dataApiTestCase = TestCase("data-api");
7
8 dataApiTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10 this.opts = {
11 width: 480,
12 height: 320
13 };
14
15 this.graphDiv = document.getElementById("graph");
16 };
17
18 dataApiTestCase.prototype.tearDown = function() {
19 };
20
21 dataApiTestCase.prototype.testBasicAccessors = function() {
22 var g = new Dygraph(this.graphDiv, temperature_data, this.opts);
23
24 assertEquals(365, g.numRows());
25 assertEquals(3, g.numColumns());
26
27 // 2007-01-01,62,39
28 assertEquals(62, g.getValue(0, 1));
29 assertEquals(39, g.getValue(0, 2));
30
31 // 2007-12-31,57,42
32 assertEquals(57, g.getValue(364, 1));
33 assertEquals(42, g.getValue(364, 2));
34 };
35
36
37 dataApiTestCase.prototype.testAccessorsCustomBars = function() {
38 var g = new Dygraph(this.graphDiv, data_temp_high_low, {
39 customBars: true
40 });
41
42 assertEquals(1070, g.numRows());
43 assertEquals(3, g.numColumns());
44
45 // 2007-01-01,46;51;56,43;45;48
46 assertEquals([46, 51, 56], g.getValue(0, 1));
47 assertEquals([43, 45, 48], g.getValue(0, 2));
48
49 // 2009-12-05,37;42;47 (i.e. missing second column)
50 assertEquals([37, 42, 47], g.getValue(1069, 1));
51 assertEquals([null, null, null], g.getValue(1069, 2));
52 };
53
54
55 // Regression test for #554.
56 dataApiTestCase.prototype.testGetRowForX = function() {
57 var g = new Dygraph(this.graphDiv, [
58 "x,y",
59 "1,2",
60 "3,4",
61 "5,6",
62 "7,8",
63 "9,10"
64 ].join('\n'), this.opts);
65
66 assertEquals(null, g.getRowForX(0));
67 assertEquals(0, g.getRowForX(1));
68 assertEquals(null, g.getRowForX(2));
69 assertEquals(1, g.getRowForX(3));
70 assertEquals(null, g.getRowForX(4));
71 assertEquals(2, g.getRowForX(5));
72 assertEquals(null, g.getRowForX(6));
73 assertEquals(3, g.getRowForX(7));
74 assertEquals(null, g.getRowForX(8));
75 assertEquals(4, g.getRowForX(9));
76 assertEquals(null, g.getRowForX(10));
77 };
78
79 // If there are rows with identical x-values, getRowForX promises that it will
80 // return the first one.
81 dataApiTestCase.prototype.testGetRowForXDuplicates = function() {
82 var g = new Dygraph(this.graphDiv, [
83 "x,y",
84 "1,2", // 0
85 "1,4", // 1
86 "1,6", // 2
87 "1,8", // 3
88 "1,6", // 4
89 "9,2", // 5
90 "9,4",
91 "9,6",
92 "9,8",
93 "9,10"
94 ].join('\n'), this.opts);
95
96 assertEquals(0, g.getRowForX(1));
97 assertEquals(null, g.getRowForX(2));
98 assertEquals(5, g.getRowForX(9));
99 };