2 * @fileoverview Tests for data formats.
4 * @author konigsberg@google.com (Robert Konigsberg)
7 import Dygraph from
'../../src/dygraph';
9 describe("formats", function() {
25 var BASE_OPTS
= {labels
: ['X', 'Y']};
27 it('testCsv', function() {
28 var data
= dataString
;
29 var graph
= document
.getElementById("graph");
30 var g
= new Dygraph(graph
, data
, {});
34 it('testArray', function() {
36 var graph
= document
.getElementById("graph");
37 var g
= new Dygraph(graph
, data
, BASE_OPTS
);
41 it('testFunctionReturnsCsv', function() {
42 var data
= function() { return dataString
; };
44 var graph
= document
.getElementById("graph");
45 var g
= new Dygraph(graph
, data
, {});
49 it('testFunctionDefinesArray', function() {
50 var array
= dataArray
;
51 var data
= function() { return array
; }
53 var graph
= document
.getElementById("graph");
54 var g
= new Dygraph(graph
, data
, BASE_OPTS
);
58 it('testXValueParser', function() {
66 var graph
= document
.getElementById("graph");
67 var g
= new Dygraph(graph
, data
, {
68 xValueParser
: function(str
) {
69 assert
.equal(1, str
.length
);
70 return str
.charCodeAt(0) - "a".charCodeAt(0);
74 assert
.equal(3, g
.getValue(0, 0));
75 assert
.equal(4, g
.getValue(1, 0));
76 assert
.equal(5, g
.getValue(2, 0));
77 assert
.equal(6, g
.getValue(3, 0));
80 var assertData
= function(g
) {
81 var expected
= dataArray
;
83 assert
.equal(4, g
.numRows());
84 assert
.equal(2, g
.numColumns());
86 for (var i
= 0; i
< 4; i
++) {
87 for (var j
= 0; j
< 2; j
++) {
88 assert
.equal(expected
[i
][j
], g
.getValue(i
, j
));