2 * @fileoverview Tests the way that dygraphs parses data.
4 * @author danvk@google.com (Dan Vanderkam)
6 describe("parser", function() {
8 beforeEach(function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 afterEach(function() {
15 it('testDetectLineDelimiter', function() {
22 assert
.equal("\r", Dygraph
.detectLineDelimiter(data
));
30 assert
.equal("\n", Dygraph
.detectLineDelimiter(data
));
38 assert
.equal("\n\r", Dygraph
.detectLineDelimiter(data
));
41 it('testParseDosNewlines', function() {
53 var g
= new Dygraph('graph', data
, opts
);
54 assert
.equal(0, g
.getValue(0, 0));
55 assert
.equal(-1, g
.getValue(0, 1));
56 assert
.equal(1, g
.getValue(1, 0));
57 assert
.equal(0, g
.getValue(1, 1));
58 assert
.deepEqual(['X', 'Y'], g
.getLabels());
61 it('should parse tab-delimited data', function() {
68 var g
= new Dygraph('graph', data
);
69 assert
.equal(0, g
.getValue(0, 0));
70 assert
.equal(-1, g
.getValue(0, 1));
71 assert
.equal(1, g
.getValue(1, 0));
72 assert
.equal(0, g
.getValue(1, 1));
73 assert
.deepEqual(['X', 'Y'], g
.getLabels());
76 it('should parse fractions', function() {
82 var g
= new Dygraph('graph', data
, {fractions
:true});
84 assert
.equal(0, g
.getValue(0, 0));
85 assert
.deepEqual([1, 4], g
.getValue(0, 1));
86 assert
.equal(1, g
.getValue(1, 0));
87 assert
.deepEqual([2, 4], g
.getValue(1, 1));
88 assert
.deepEqual(['X', 'Y'], g
.getLabels());
91 it('should parse error bars', function() {
97 var g
= new Dygraph('graph', data
, {errorBars
:true});
99 assert
.equal(0, g
.getValue(0, 0));
100 assert
.deepEqual([1, 4], g
.getValue(0, 1));
101 assert
.equal(1, g
.getValue(1, 0));
102 assert
.deepEqual([2, 4], g
.getValue(1, 1));
103 assert
.deepEqual(['X', 'Y'], g
.getLabels());
106 it('should parse custom bars', function() {
107 var data
= "X,Y1,Y2\n" +
108 "1,10;20;30,20;5;25\n" +
109 "2,10;25;35,20;10;25\n";
110 var g
= new Dygraph('graph', data
, {customBars
:true});
112 assert
.equal(1, g
.getValue(0, 0));
113 assert
.deepEqual([10, 20, 30], g
.getValue(0, 1));
114 assert
.deepEqual([20, 5, 25], g
.getValue(0, 2));
115 assert
.equal(2, g
.getValue(1, 0));
116 assert
.deepEqual([10, 25, 35], g
.getValue(1, 1));
117 assert
.deepEqual([20, 10, 25], g
.getValue(1, 2));
118 assert
.deepEqual(['X', 'Y1', 'Y2'], g
.getLabels());
122 it('should warn on unsorted input', function() {
125 it('should warn on different length columns', function() {
128 it('should detect double-labeled data', function() {