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)
8 import Dygraph from
'../../src/dygraph';
9 import Util from
'./Util';
11 describe("pathological-cases", function() {
17 beforeEach(function() {
18 restoreConsole
= Util
.captureConsole(logs
);
21 afterEach(function() {
25 var graph
= document
.getElementById("graph");
27 it('testZeroPoint', function() {
34 var g
= new Dygraph(graph
, data
, opts
);
37 it('testOnePoint', function() {
45 var g
= new Dygraph(graph
, data
, opts
);
48 it('testCombinations', function() {
52 nanPoint
: [[10, NaN
]],
53 nanPoints
: [[10, NaN
], [20, NaN
]],
54 multiNan1
: [[10, NaN
, 2], [20, 3, NaN
]],
55 multiNan2
: [[10, NaN
, 2], [20, NaN
, 4]],
56 multiNan3
: [[10, NaN
, NaN
], [20, 3, 4], [30, NaN
, NaN
]],
59 negative
: [[-10, -1]],
60 acrossZero
: [[-10, 1], [10, 2]],
61 normal
: [[0,1,9], [10,3,5], [20,2,7], [30,4,3]]
85 for (var baseName
in baseOpts
) {
86 var base
= baseOpts
[baseName
];
87 for (var variantName
in variantOpts
) {
88 var variant
= variantOpts
[variantName
];
96 for (var key
in base
) {
97 if (base
.hasOwnProperty(key
)) opts
[key
] = base
[key
];
99 for (var key
in variant
) {
100 if (variant
.hasOwnProperty(key
)) opts
[key
] = variant
[key
];
103 var h
= document
.createElement('h3');
104 h
.appendChild(document
.createTextNode(baseName
+ ' ' + variantName
));
105 graph
.appendChild(h
);
106 for (var dataName
in dataSets
) {
107 var data
= dataSets
[dataName
];
109 var box
= document
.createElement('fieldset');
110 box
.style
.display
= 'inline-block';
111 var legend
= document
.createElement('legend');
112 legend
.appendChild(document
.createTextNode(dataName
));
113 box
.appendChild(legend
);
114 var gdiv
= document
.createElement('div');
115 gdiv
.style
.display
= 'inline-block';
116 box
.appendChild(gdiv
);
117 graph
.appendChild(box
);
119 var cols
= data
&& data
[0] ? data
[0].length
: 0;
120 opts
.labels
= ['X', 'A', 'B', 'C'].slice(0, cols
);
122 var g
= new Dygraph(gdiv
, data
, opts
);
124 if (dataName
== 'empty') {
125 assert
.deepEqual(logs
, {
127 error
: ["Can't plot empty data set"]
129 logs
.error
= []; // reset
131 assert
.deepEqual(logs
, {log
: [], warn
: [], error
: []});
138 it('testNullLegend', function() {
147 var g
= new Dygraph(graph
, data
, opts
);
150 it('testDivAsString', function() {
154 var g
= new Dygraph('graph', data
, {});
158 it('testConstantSeriesNegative', function() {
163 var g
= new Dygraph('graph', data
, {});
164 // This check could be loosened to
165 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
166 assert
.deepEqual([-1.1, -0.9], g
.yAxisRange());
170 it('testConstantSeriesNegativeIncludeZero', function() {
175 var g
= new Dygraph('graph', data
, {includeZero
: true});
176 // This check could be loosened to
177 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
178 assert
.deepEqual([-1.1, 0], g
.yAxisRange());
181 it('should throw with non-existent divs', function() {
186 assert
.throws(function() {
187 new Dygraph(null, data
);
188 }, /non-existent div/);
190 assert
.throws(function() {
191 new Dygraph('non-existent-div-id', data
);
192 }, /non-existent div/);