--- /dev/null
+/**
+ * @fileoverview Tests zero and one-point charts.
+ * These don't have to render nicely, they just have to not crash.
+ *
+ * @author dan@dygraphs.com (Dan Vanderkam)
+ */
+var pathologicalCasesTestCase = TestCase("pathological-cases");
+
+pathologicalCasesTestCase.prototype.setUp = function() {
+ document.body.innerHTML = "<div id='graph'></div>";
+};
+
+pathologicalCasesTestCase.prototype.tearDown = function() {
+};
+
+pathologicalCasesTestCase.prototype.testZeroPoint = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "X,Y\n";
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+};
+
+pathologicalCasesTestCase.prototype.testOnePoint = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "X,Y\n" +
+ "1,2\n";
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+};
this.fractions_ = attrs.fractions || false;
this.dateWindow_ = attrs.dateWindow || null;
- this.wilsonInterval_ = attrs.wilsonInterval || true;
this.is_initial_draw_ = true;
this.annotations_ = [];
* @return { Integer } The number of columns.
*/
Dygraph.prototype.numColumns = function() {
- return this.rawData_[0].length;
+ return this.rawData_[0] ? this.rawData_[0].length : this.attr_("labels").length;
};
/**
};
/**
+ * Returns the full range of the x-axis, as determined by the most extreme
+ * values in the data set. Not affected by zooming, visibility, etc.
+ * @return { Array<Number> } A [low, high] pair
+ * @private
+ */
+Dygraph.prototype.fullXRange_ = function() {
+ if (this.numRows() > 0) {
+ return [this.rawData_[0][0], this.rawData_[this.numRows() - 1][0]];
+ } else {
+ return [0, 1];
+ }
+}
+
+/**
* Returns the value in the given row and column. If the row and column exceed
* the bounds on the data, returns null. Also returns null if the value is
* missing.
if (this.dateWindow_) {
range = [this.dateWindow_[0], this.dateWindow_[1]];
} else {
- range = [this.rawData_[0][0], this.rawData_[this.rawData_.length - 1][0]];
+ range = this.fullXRange_();
}
var xAxisOptionsView = this.optionsViewForAxis_('x');
// Convert the raw data (a 2D array) into the internal format and compute
// rolling averages.
this.rolledSeries_ = [null]; // x-axis is the first series and it's special
- for (var i = 1; i < this.rawData_[0].length; i++) {
+ for (var i = 1; i < this.numColumns(); i++) {
var connectSeparatedPoints = this.attr_('connectSeparatedPoints', i);
var logScale = this.attr_('logscale', i);
var series = this.extractSeries_(this.rawData_, i, logScale, connectSeparatedPoints);
var date = originalData[i][0];
var value = den ? num / den : 0.0;
if (this.attr_("errorBars")) {
- if (this.wilsonInterval_) {
+ if (this.attr_("wilsonInterval")) {
// For more details on this confidence interval, see:
// http://en.wikipedia.org/wiki/Binomial_confidence_interval
if (den) {
if (!this.attr_("visibility")) {
this.attrs_["visibility"] = [];
}
- while (this.attr_("visibility").length < this.rawData_[0].length - 1) {
+ while (this.attr_("visibility").length < this.numColumns() - 1) {
this.attr_("visibility").push(true);
}
return this.attr_("visibility");