consolidating scripts
[dygraphs.git] / auto_tests / tests / data_api.js
CommitLineData
fcf37b29
DV
1/**
2 * @fileoverview Tests for data access methods.
3 *
4 * @author danvdk@gmail.com (Dan Vanderkam)
5 */
e8c70e4e 6import Dygraph from '../../src/dygraph';
89fdcedb 7describe("data-api", function() {
fcf37b29 8
e8c70e4e
DV
9cleanupAfterEach();
10
319d0361
DV
11var opts, graphDiv;
12
89fdcedb 13beforeEach(function() {
319d0361 14 opts = {
fcf37b29
DV
15 width: 480,
16 height: 320
17 };
18
319d0361 19 graphDiv = document.getElementById("graph");
89fdcedb 20});
fcf37b29 21
89fdcedb 22it('testBasicAccessors', function() {
319d0361 23 var g = new Dygraph(graphDiv, temperature_data, opts);
fcf37b29 24
89fdcedb
DV
25 assert.equal(365, g.numRows());
26 assert.equal(3, g.numColumns());
fcf37b29
DV
27
28 // 2007-01-01,62,39
89fdcedb
DV
29 assert.equal(62, g.getValue(0, 1));
30 assert.equal(39, g.getValue(0, 2));
fcf37b29
DV
31
32 // 2007-12-31,57,42
89fdcedb
DV
33 assert.equal(57, g.getValue(364, 1));
34 assert.equal(42, g.getValue(364, 2));
35});
fcf37b29
DV
36
37
89fdcedb 38it('testAccessorsCustomBars', function() {
319d0361 39 var g = new Dygraph(graphDiv, data_temp_high_low, {
fcf37b29
DV
40 customBars: true
41 });
42
89fdcedb
DV
43 assert.equal(1070, g.numRows());
44 assert.equal(3, g.numColumns());
fcf37b29
DV
45
46 // 2007-01-01,46;51;56,43;45;48
89fdcedb
DV
47 assert.deepEqual([46, 51, 56], g.getValue(0, 1));
48 assert.deepEqual([43, 45, 48], g.getValue(0, 2));
fcf37b29
DV
49
50 // 2009-12-05,37;42;47 (i.e. missing second column)
89fdcedb
DV
51 assert.deepEqual([37, 42, 47], g.getValue(1069, 1));
52 assert.deepEqual([null, null, null], g.getValue(1069, 2));
53});
fcf37b29
DV
54
55
56// Regression test for #554.
89fdcedb 57it('testGetRowForX', function() {
319d0361 58 var g = new Dygraph(graphDiv, [
fcf37b29
DV
59 "x,y",
60 "1,2",
61 "3,4",
62 "5,6",
63 "7,8",
64 "9,10"
319d0361 65 ].join('\n'), opts);
fcf37b29 66
89fdcedb
DV
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));
78});
fcf37b29
DV
79
80// If there are rows with identical x-values, getRowForX promises that it will
81// return the first one.
89fdcedb 82it('testGetRowForXDuplicates', function() {
319d0361 83 var g = new Dygraph(graphDiv, [
fcf37b29
DV
84 "x,y",
85 "1,2", // 0
86 "1,4", // 1
87 "1,6", // 2
88 "1,8", // 3
89 "1,6", // 4
90 "9,2", // 5
91 "9,4",
92 "9,6",
93 "9,8",
94 "9,10"
319d0361 95 ].join('\n'), opts);
fcf37b29 96
89fdcedb
DV
97 assert.equal(0, g.getRowForX(1));
98 assert.equal(null, g.getRowForX(2));
99 assert.equal(5, g.getRowForX(9));
100});
101
102});