Commit | Line | Data |
---|---|---|
e5763589 DV |
1 | /** |
2 | * @fileoverview Tests the way that dygraphs parses data. | |
3 | * | |
4 | * @author danvk@google.com (Dan Vanderkam) | |
5 | */ | |
89fdcedb | 6 | describe("parser", function() { |
e5763589 | 7 | |
89fdcedb | 8 | beforeEach(function() { |
e5763589 | 9 | document.body.innerHTML = "<div id='graph'></div>"; |
89fdcedb | 10 | }); |
e5763589 | 11 | |
89fdcedb DV |
12 | afterEach(function() { |
13 | }); | |
e5763589 | 14 | |
89fdcedb | 15 | it('testDetectLineDelimiter', function() { |
e5763589 DV |
16 | var data = "X,Y\r" + |
17 | "0,-1\r" + | |
18 | "1,0\r" + | |
19 | "2,1\r" + | |
20 | "3,0\r" | |
21 | ; | |
89fdcedb | 22 | assert.equal("\r", Dygraph.detectLineDelimiter(data)); |
e5763589 DV |
23 | |
24 | data = "X,Y\n" + | |
25 | "0,-1\n" + | |
26 | "1,0\n" + | |
27 | "2,1\n" + | |
28 | "3,0\n" | |
29 | ; | |
89fdcedb | 30 | assert.equal("\n", Dygraph.detectLineDelimiter(data)); |
e5763589 DV |
31 | |
32 | data = "X,Y\n\r" + | |
33 | "0,-1\n\r" + | |
34 | "1,0\n\r" + | |
35 | "2,1\n\r" + | |
36 | "3,0\n\r" | |
37 | ; | |
89fdcedb DV |
38 | assert.equal("\n\r", Dygraph.detectLineDelimiter(data)); |
39 | }); | |
e5763589 | 40 | |
89fdcedb | 41 | it('testParseDosNewlines', function() { |
e5763589 DV |
42 | var opts = { |
43 | width: 480, | |
44 | height: 320 | |
45 | }; | |
46 | var data = "X,Y\r" + | |
47 | "0,-1\r" + | |
48 | "1,0\r" + | |
49 | "2,1\r" + | |
50 | "3,0\r" | |
51 | ; | |
52 | ||
a907c94d DV |
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()); | |
59 | }); | |
60 | ||
61 | it('should parse tab-delimited data', function() { | |
62 | var data = "X\tY\n" + | |
63 | "0\t-1\n" + | |
64 | "1\t0\n" + | |
65 | "2\t1\n" + | |
66 | "3\t0\n"; | |
e5763589 | 67 | |
a907c94d | 68 | var g = new Dygraph('graph', data); |
89fdcedb DV |
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()); | |
74 | }); | |
e5763589 | 75 | |
a907c94d DV |
76 | it('should parse fractions', function() { |
77 | var data = "X,Y\n" + | |
78 | "0,1/4\n" + | |
79 | "1,2/4\n" + | |
80 | "2,3/4\n" + | |
81 | "3,4/4\n"; | |
82 | var g = new Dygraph('graph', data, {fractions:true}); | |
83 | ||
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()); | |
89 | }); | |
90 | ||
91 | it('should parse error bars', function() { | |
92 | var data = "X,Y\n" + | |
93 | "0,1,4\n" + | |
94 | "1,2,4\n" + | |
95 | "2,3,4\n" + | |
96 | "3,4,4\n"; | |
97 | var g = new Dygraph('graph', data, {errorBars:true}); | |
98 | ||
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()); | |
104 | }); | |
105 | ||
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}); | |
111 | ||
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()); | |
119 | }); | |
120 | ||
121 | /* | |
122 | it('should warn on unsorted input', function() { | |
123 | }); | |
124 | ||
125 | it('should warn on different length columns', function() { | |
126 | }); | |
127 | ||
128 | it('should detect double-labeled data', function() { | |
129 | }); | |
130 | */ | |
89fdcedb DV |
131 | |
132 | }); |