2 * @fileoverview Tests the way that dygraphs parses data.
4 * @author danvk@google.com (Dan Vanderkam)
7 import Dygraph from
'../../src/dygraph';
8 import * as utils from
'../../src/dygraph-utils';
10 describe("parser", function() {
14 it('testDetectLineDelimiter', function() {
21 assert
.equal("\r", utils
.detectLineDelimiter(data
));
29 assert
.equal("\n", utils
.detectLineDelimiter(data
));
37 assert
.equal("\n\r", utils
.detectLineDelimiter(data
));
40 it('testParseDosNewlines', function() {
52 var g
= new Dygraph('graph', data
, opts
);
53 assert
.equal(0, g
.getValue(0, 0));
54 assert
.equal(-1, g
.getValue(0, 1));
55 assert
.equal(1, g
.getValue(1, 0));
56 assert
.equal(0, g
.getValue(1, 1));
57 assert
.deepEqual(['X', 'Y'], g
.getLabels());
60 it('should parse tab-delimited data', function() {
67 var g
= new Dygraph('graph', data
);
68 assert
.equal(0, g
.getValue(0, 0));
69 assert
.equal(-1, g
.getValue(0, 1));
70 assert
.equal(1, g
.getValue(1, 0));
71 assert
.equal(0, g
.getValue(1, 1));
72 assert
.deepEqual(['X', 'Y'], g
.getLabels());
75 it('should parse fractions', function() {
81 var g
= new Dygraph('graph', data
, {fractions
:true});
83 assert
.equal(0, g
.getValue(0, 0));
84 assert
.deepEqual([1, 4], g
.getValue(0, 1));
85 assert
.equal(1, g
.getValue(1, 0));
86 assert
.deepEqual([2, 4], g
.getValue(1, 1));
87 assert
.deepEqual(['X', 'Y'], g
.getLabels());
90 it('should parse error bars', function() {
96 var g
= new Dygraph('graph', data
, {errorBars
:true});
98 assert
.equal(0, g
.getValue(0, 0));
99 assert
.deepEqual([1, 4], g
.getValue(0, 1));
100 assert
.equal(1, g
.getValue(1, 0));
101 assert
.deepEqual([2, 4], g
.getValue(1, 1));
102 assert
.deepEqual(['X', 'Y'], g
.getLabels());
105 it('should parse custom bars', function() {
106 var data
= "X,Y1,Y2\n" +
107 "1,10;20;30,20;5;25\n" +
108 "2,10;25;35,20;10;25\n";
109 var g
= new Dygraph('graph', data
, {customBars
:true});
111 assert
.equal(1, g
.getValue(0, 0));
112 assert
.deepEqual([10, 20, 30], g
.getValue(0, 1));
113 assert
.deepEqual([20, 5, 25], g
.getValue(0, 2));
114 assert
.equal(2, g
.getValue(1, 0));
115 assert
.deepEqual([10, 25, 35], g
.getValue(1, 1));
116 assert
.deepEqual([20, 10, 25], g
.getValue(1, 2));
117 assert
.deepEqual(['X', 'Y1', 'Y2'], g
.getLabels());
121 it('should warn on unsorted input', function() {
124 it('should warn on different length columns', function() {
127 it('should detect double-labeled data', function() {