From: Dan Vanderkam Date: Tue, 1 Dec 2009 17:25:09 +0000 (-0800) Subject: add "delimiter" attribute, support for tabbed input X-Git-Tag: v1.0.0~826 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=3d67f03bae2df09cb81a49ad8212bbc855b30b25;p=dygraphs.git add "delimiter" attribute, support for tabbed input --- diff --git a/dygraph.js b/dygraph.js index 1cb4b62..c695c9d 100644 --- a/dygraph.js +++ b/dygraph.js @@ -105,6 +105,8 @@ Dygraph.DEFAULT_ATTRS = { xValueParser: Dygraph.dateParser, xTicker: Dygraph.dateTicker, + delimiter: ',', + sigma: 2.0, errorBars: false, fractions: false, @@ -1402,10 +1404,17 @@ Dygraph.prototype.detectTypeFromString_ = function(str) { Dygraph.prototype.parseCSV_ = function(data) { var ret = []; var lines = data.split("\n"); + + // Use the default delimiter or fall back to a tab if that makes sense. + var delim = this.attr_('delimiter'); + if (lines[0].indexOf(delim) == -1 && lines[0].indexOf('\t') >= 0) { + delim = '\t'; + } + var start = 0; if (this.labelsFromCSV_) { start = 1; - this.attrs_.labels = lines[0].split(","); + this.attrs_.labels = lines[0].split(delim); } var xParser; @@ -1414,7 +1423,8 @@ Dygraph.prototype.parseCSV_ = function(data) { for (var i = start; i < lines.length; i++) { var line = lines[i]; if (line.length == 0) continue; // skip blank lines - var inFields = line.split(','); + if (line[0] == '#') continue; // skip comment lines + var inFields = line.split(delim); if (inFields.length < 2) continue; var fields = []; diff --git a/tests/noise.html b/tests/noise.html index b6fcc25..a589fb3 100644 --- a/tests/noise.html +++ b/tests/noise.html @@ -25,7 +25,7 @@ ); g30 = new Dygraph( document.getElementById("g30"), - NoisyData, { + NoisyData().replace(/,/g, "\t"), { rollPeriod: 14, errorBars: true }