2 * @fileoverview Tests for data access methods.
4 * @author danvdk@gmail.com (Dan Vanderkam)
6 import Dygraph from
'../../src/dygraph';
7 describe("data-api", function() {
13 beforeEach(function() {
19 graphDiv
= document
.getElementById("graph");
22 it('testBasicAccessors', function() {
23 var g
= new Dygraph(graphDiv
, temperature_data
, opts
);
25 assert
.equal(365, g
.numRows());
26 assert
.equal(3, g
.numColumns());
29 assert
.equal(62, g
.getValue(0, 1));
30 assert
.equal(39, g
.getValue(0, 2));
33 assert
.equal(57, g
.getValue(364, 1));
34 assert
.equal(42, g
.getValue(364, 2));
38 it('testAccessorsCustomBars', function() {
39 var g
= new Dygraph(graphDiv
, data_temp_high_low
, {
43 assert
.equal(1070, g
.numRows());
44 assert
.equal(3, g
.numColumns());
46 // 2007-01-01,46;51;56,43;45;48
47 assert
.deepEqual([46, 51, 56], g
.getValue(0, 1));
48 assert
.deepEqual([43, 45, 48], g
.getValue(0, 2));
50 // 2009-12-05,37;42;47 (i.e. missing second column)
51 assert
.deepEqual([37, 42, 47], g
.getValue(1069, 1));
52 assert
.deepEqual([null, null, null], g
.getValue(1069, 2));
56 // Regression test for #554.
57 it('testGetRowForX', function() {
58 var g
= new Dygraph(graphDiv
, [
67 assert
.equal(null, g
.getRowForX(0));
68 assert
.equal(0, g
.getRowForX(1));
69 assert
.equal(null, g
.getRowForX(2));
70 assert
.equal(1, g
.getRowForX(3));
71 assert
.equal(null, g
.getRowForX(4));
72 assert
.equal(2, g
.getRowForX(5));
73 assert
.equal(null, g
.getRowForX(6));
74 assert
.equal(3, g
.getRowForX(7));
75 assert
.equal(null, g
.getRowForX(8));
76 assert
.equal(4, g
.getRowForX(9));
77 assert
.equal(null, g
.getRowForX(10));
80 // If there are rows with identical x-values, getRowForX promises that it will
81 // return the first one.
82 it('testGetRowForXDuplicates', function() {
83 var g
= new Dygraph(graphDiv
, [
97 assert
.equal(0, g
.getRowForX(1));
98 assert
.equal(null, g
.getRowForX(2));
99 assert
.equal(5, g
.getRowForX(9));