2 * @fileoverview Tests zero and one-point charts.
3 * These don't have to render nicely, they just have to not crash.
5 * @author dan@dygraphs.com (Dan Vanderkam)
7 describe("pathological-cases", function() {
11 beforeEach(function() {
12 document
.body
.innerHTML
= "<div id='graph'></div>";
13 restoreConsole
= Util
.captureConsole(logs
);
16 afterEach(function() {
20 it('testZeroPoint', function() {
27 var graph
= document
.getElementById("graph");
28 var g
= new Dygraph(graph
, data
, opts
);
31 it('testOnePoint', function() {
39 var graph
= document
.getElementById("graph");
40 var g
= new Dygraph(graph
, data
, opts
);
43 it('testCombinations', function() {
47 nanPoint
: [[10, NaN
]],
48 nanPoints
: [[10, NaN
], [20, NaN
]],
49 multiNan1
: [[10, NaN
, 2], [20, 3, NaN
]],
50 multiNan2
: [[10, NaN
, 2], [20, NaN
, 4]],
51 multiNan3
: [[10, NaN
, NaN
], [20, 3, 4], [30, NaN
, NaN
]],
54 negative
: [[-10, -1]],
55 acrossZero
: [[-10, 1], [10, 2]],
56 normal
: [[0,1,9], [10,3,5], [20,2,7], [30,4,3]]
80 for (var baseName
in baseOpts
) {
81 var base
= baseOpts
[baseName
];
82 for (var variantName
in variantOpts
) {
83 var variant
= variantOpts
[variantName
];
91 for (var key
in base
) {
92 if (base
.hasOwnProperty(key
)) opts
[key
] = base
[key
];
94 for (var key
in variant
) {
95 if (variant
.hasOwnProperty(key
)) opts
[key
] = variant
[key
];
98 var h
= document
.createElement('h3');
99 h
.appendChild(document
.createTextNode(baseName
+ ' ' + variantName
));
100 document
.body
.appendChild(h
);
101 for (var dataName
in dataSets
) {
102 var data
= dataSets
[dataName
];
104 var box
= document
.createElement('fieldset');
105 box
.style
.display
= 'inline-block';
106 var legend
= document
.createElement('legend');
107 legend
.appendChild(document
.createTextNode(dataName
));
108 box
.appendChild(legend
);
109 var gdiv
= document
.createElement('div');
110 gdiv
.style
.display
= 'inline-block';
111 box
.appendChild(gdiv
);
112 document
.body
.appendChild(box
);
114 var cols
= data
&& data
[0] ? data
[0].length
: 0;
115 opts
.labels
= ['X', 'A', 'B', 'C'].slice(0, cols
);
117 var g
= new Dygraph(gdiv
, data
, opts
);
119 if (dataName
== 'empty') {
120 assert
.deepEqual(logs
, {
122 error
: ["Can't plot empty data set"]
124 logs
.error
= []; // reset
126 assert
.deepEqual(logs
, {log
: [], warn
: [], error
: []});
133 it('testNullLegend', function() {
142 var graph
= document
.getElementById("graph");
143 var g
= new Dygraph(graph
, data
, opts
);
146 it('testDivAsString', function() {
150 var g
= new Dygraph('graph', data
, {});
154 it('testConstantSeriesNegative', function() {
159 var g
= new Dygraph('graph', data
, {});
160 // This check could be loosened to
161 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
162 assert
.deepEqual([-1.1, -0.9], g
.yAxisRange());
166 it('testConstantSeriesNegativeIncludeZero', function() {
171 var g
= new Dygraph('graph', data
, {includeZero
: true});
172 // This check could be loosened to
173 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
174 assert
.deepEqual([-1.1, 0], g
.yAxisRange());
177 it('should throw with non-existent divs', function() {
182 assert
.throws(function() {
183 new Dygraph(null, data
);
184 }, /non-existent div/);
186 assert
.throws(function() {
187 new Dygraph('non-existent-div-id', data
);
188 }, /non-existent div/);