631990980493ad02ccb031f359c57e6b6ebbb9f3
2 * @fileoverview Tests for data access methods.
4 * @author danvdk@gmail.com (Dan Vanderkam)
6 import Dygraph from
'../../src/dygraph';
7 import * as utils from
'../../src/dygraph-utils';
8 describe("data-api", function() {
14 beforeEach(function() {
20 graphDiv
= document
.getElementById("graph");
23 it('testBasicAccessors', function() {
24 var g
= new Dygraph(graphDiv
, temperature_data
, opts
);
26 assert
.equal(365, g
.numRows());
27 assert
.equal(3, g
.numColumns());
30 assert
.equal(62, g
.getValue(0, 1));
31 assert
.equal(39, g
.getValue(0, 2));
34 assert
.equal(57, g
.getValue(364, 1));
35 assert
.equal(42, g
.getValue(364, 2));
39 it('testAccessorsCustomBars', function() {
40 var g
= new Dygraph(graphDiv
, data_temp_high_low
, {
44 assert
.equal(1070, g
.numRows());
45 assert
.equal(3, g
.numColumns());
47 // 2007-01-01,46;51;56,43;45;48
48 assert
.deepEqual([46, 51, 56], g
.getValue(0, 1));
49 assert
.deepEqual([43, 45, 48], g
.getValue(0, 2));
51 // 2009-12-05,37;42;47 (i.e. missing second column)
52 assert
.deepEqual([37, 42, 47], g
.getValue(1069, 1));
53 assert
.deepEqual([null, null, null], g
.getValue(1069, 2));
57 // Regression test for #554.
58 it('testGetRowForX', function() {
59 var g
= new Dygraph(graphDiv
, [
68 assert
.equal(null, g
.getRowForX(0));
69 assert
.equal(0, g
.getRowForX(1));
70 assert
.equal(null, g
.getRowForX(2));
71 assert
.equal(1, g
.getRowForX(3));
72 assert
.equal(null, g
.getRowForX(4));
73 assert
.equal(2, g
.getRowForX(5));
74 assert
.equal(null, g
.getRowForX(6));
75 assert
.equal(3, g
.getRowForX(7));
76 assert
.equal(null, g
.getRowForX(8));
77 assert
.equal(4, g
.getRowForX(9));
78 assert
.equal(null, g
.getRowForX(10));
81 // If there are rows with identical x-values, getRowForX promises that it will
82 // return the first one.
83 it('testGetRowForXDuplicates', function() {
84 var g
= new Dygraph(graphDiv
, [
98 assert
.equal(0, g
.getRowForX(1));
99 assert
.equal(null, g
.getRowForX(2));
100 assert
.equal(5, g
.getRowForX(9));
103 // indexFromSeriesName should return a value even if the series is invisible
104 // In 1.1.1, if you request the last set and it's invisible, the method returns undefined.
105 it('testIndexFromSetNameOnInvisibleSet', function() {
107 var localOpts
= utils
.clone(opts
);
108 localOpts
.visibility
= [true, false];
110 var g
= new Dygraph(graphDiv
, [
115 ].join('\n'), localOpts
);
117 assert
.equal(2, g
.indexFromSetName("y2"));