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 var pathologicalCasesTestCase
= TestCase("pathological-cases");
9 pathologicalCasesTestCase
.prototype.setUp
= function() {
10 document
.body
.innerHTML
= "<div id='graph'></div>";
13 pathologicalCasesTestCase
.prototype.tearDown
= function() {
16 pathologicalCasesTestCase
.prototype.testZeroPoint
= function() {
23 var graph
= document
.getElementById("graph");
24 var g
= new Dygraph(graph
, data
, opts
);
27 pathologicalCasesTestCase
.prototype.testOnePoint
= function() {
35 var graph
= document
.getElementById("graph");
36 var g
= new Dygraph(graph
, data
, opts
);
39 pathologicalCasesTestCase
.prototype.testCombinations
= function() {
43 nanPoint
: [[10, NaN
]],
44 nanPoints
: [[10, NaN
], [20, NaN
]],
45 multiNan1
: [[10, NaN
, 2], [20, 3, NaN
]],
46 multiNan2
: [[10, NaN
, 2], [20, NaN
, 4]],
47 multiNan3
: [[10, NaN
, NaN
], [20, 3, 4], [30, NaN
, NaN
]],
50 negative
: [[-10, -1]],
51 acrossZero
: [[-10, 1], [10, 2]],
52 normal
: [[0,1,9], [10,3,5], [20,2,7], [30,4,3]]
76 for (var baseName
in baseOpts
) {
77 var base
= baseOpts
[baseName
];
78 for (var variantName
in variantOpts
) {
79 var variant
= variantOpts
[variantName
];
87 for (var key
in base
) {
88 if (base
.hasOwnProperty(key
)) opts
[key
] = base
[key
];
90 for (var key
in variant
) {
91 if (variant
.hasOwnProperty(key
)) opts
[key
] = variant
[key
];
94 var h
= document
.createElement('h3');
95 h
.appendChild(document
.createTextNode(baseName
+ ' ' + variantName
));
96 document
.body
.appendChild(h
);
97 for (var dataName
in dataSets
) {
98 var data
= dataSets
[dataName
];
100 var box
= document
.createElement('fieldset');
101 box
.style
.display
= 'inline-block';
102 var legend
= document
.createElement('legend');
103 legend
.appendChild(document
.createTextNode(dataName
));
104 box
.appendChild(legend
);
105 var gdiv
= document
.createElement('div');
106 gdiv
.style
.display
= 'inline-block';
107 box
.appendChild(gdiv
);
108 document
.body
.appendChild(box
);
110 var cols
= data
&& data
[0] ? data
[0].length
: 0;
111 opts
.labels
= ['X', 'A', 'B', 'C'].slice(0, cols
);
113 var g
= new Dygraph(gdiv
, data
, opts
);
119 pathologicalCasesTestCase
.prototype.testNullLegend
= function() {
128 var graph
= document
.getElementById("graph");
129 var g
= new Dygraph(graph
, data
, opts
);
132 pathologicalCasesTestCase
.prototype.testDivAsString
= function() {
136 var g
= new Dygraph('graph', data
, {});
140 pathologicalCasesTestCase
.prototype.testConstantSeriesNegative
= function() {
145 g
= new Dygraph('graph', data
, {});
146 // This check could be loosened to
147 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
148 assertEquals([-1.1, -0.9], g
.yAxisRange());
152 pathologicalCasesTestCase
.prototype.testConstantSeriesNegativeIncludeZero
= function() {
157 g
= new Dygraph('graph', data
, {includeZero
: true});
158 // This check could be loosened to
159 // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future.
160 assertEquals([-1.1, 0], g
.yAxisRange());