2 * @fileoverview Tests for data access methods.
4 * @author danvdk@gmail.com (Dan Vanderkam)
6 var dataApiTestCase
= TestCase("data-api");
8 dataApiTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
15 this.graphDiv
= document
.getElementById("graph");
18 dataApiTestCase
.prototype.tearDown
= function() {
21 dataApiTestCase
.prototype.testBasicAccessors
= function() {
22 var g
= new Dygraph(this.graphDiv
, temperature_data
, this.opts
);
24 assertEquals(365, g
.numRows());
25 assertEquals(3, g
.numColumns());
28 assertEquals(62, g
.getValue(0, 1));
29 assertEquals(39, g
.getValue(0, 2));
32 assertEquals(57, g
.getValue(364, 1));
33 assertEquals(42, g
.getValue(364, 2));
37 dataApiTestCase
.prototype.testAccessorsCustomBars
= function() {
38 var g
= new Dygraph(this.graphDiv
, data_temp_high_low
, {
42 assertEquals(1070, g
.numRows());
43 assertEquals(3, g
.numColumns());
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));
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));
55 // Regression test for #554.
56 dataApiTestCase
.prototype.testGetRowForX
= function() {
57 var g
= new Dygraph(this.graphDiv
, [
64 ].join('\n'), this.opts
);
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));
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
, [
94 ].join('\n'), this.opts
);
96 assertEquals(0, g
.getRowForX(1));
97 assertEquals(null, g
.getRowForX(2));
98 assertEquals(5, g
.getRowForX(9));