From: Dan Vanderkam Date: Thu, 3 Mar 2011 05:32:36 +0000 (-0600) Subject: more warnings on CSV parsing X-Git-Tag: v1.0.0~576 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=7219edb31f2695199aaa6fc4ce6d74c7d62be9f0;p=dygraphs.git more warnings on CSV parsing --- diff --git a/dygraph.js b/dygraph.js index 3756702..e343548 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2970,14 +2970,27 @@ Dygraph.prototype.parseCSV_ = function(data) { for (var j = 1; j < inFields.length; j++) { // TODO(danvk): figure out an appropriate way to flag parse errors. var vals = inFields[j].split("/"); - fields[j] = [this.parseFloat_(vals[0], i, line), - this.parseFloat_(vals[1], i, line)]; + if (vals.length != 2) { + this.error('Expected fractional "num/den" values in CSV data ' + + "but found a value '" + inFields[j] + "' on line " + + (1 + i) + " ('" + line + "') which is not of this form."); + fields[j] = [0, 0]; + } else { + fields[j] = [this.parseFloat_(vals[0], i, line), + this.parseFloat_(vals[1], i, line)]; + } } } else if (this.attr_("errorBars")) { // If there are error bars, values are (value, stddev) pairs - for (var j = 1; j < inFields.length; j += 2) + if (inFields.length % 2 != 1) { + this.error('Expected alternating (value, stdev.) pairs in CSV data ' + + 'but line ' + (1 + i) + ' has an odd number of values (' + + (inFields.length - 1) + "): '" + line + "'"); + } + for (var j = 1; j < inFields.length; j += 2) { fields[(j + 1) / 2] = [this.parseFloat_(inFields[j], i, line), this.parseFloat_(inFields[j + 1], i, line)]; + } } else if (this.attr_("customBars")) { // Bars are a low;center;high tuple for (var j = 1; j < inFields.length; j++) { diff --git a/tests/independent-series.html b/tests/independent-series.html index 37cf0e0..543f51f 100644 --- a/tests/independent-series.html +++ b/tests/independent-series.html @@ -27,6 +27,7 @@ +

Independent Series

By using the connectSeparated attribute, it's possible to display a chart of several time series with completely independent x-values.

The trick is to specify values for the series at the union of the x-values of all series. For one series' x values, specify null for each of the other series.