From d955e223be111db06e403e9e40cc5007270c0950 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sat, 29 Aug 2009 19:59:32 +0000 Subject: [PATCH] add support for numeric axes in gviz. fixes issue 27 --- dygraph.js | 16 ++++++++----- tests/numeric-axis.html | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 tests/numeric-axis.html diff --git a/dygraph.js b/dygraph.js index be0dca1..f5b5d72 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1136,7 +1136,7 @@ DateGraph.prototype.parseDataTable_ = function(data) { for (var i = 0; i < cols; i++) { labels.push(data.getColumnLabel(i)); } - labels.shift(); // a "date" parameter is assumed. + labels.shift(); // the x-axis parameter is assumed and unnamed. this.labels_ = labels; // regenerate automatic colors. this.setColors_(this.attrs_); @@ -1144,16 +1144,22 @@ DateGraph.prototype.parseDataTable_ = function(data) { MochiKit.Base.update(this.plotter_.options, this.renderOptions_); MochiKit.Base.update(this.layoutOptions_, this.attrs_); - // Assume column 1 is a date type for now. - if (data.getColumnType(0) != 'date') { - alert("only date type is support for column 1 of DataTable input."); + var indepType = data.getColumnType(0); + if (indepType != 'date' && indepType != 'number') { + // TODO(danvk): standardize error reporting. + alert("only 'date' and 'number' types are supported for column 1" + + "of DataTable input (Got '" + indepType + "')"); return null; } var ret = []; for (var i = 0; i < rows; i++) { var row = []; - row.push(data.getValue(i, 0).getTime()); + if (indepType == 'date') { + row.push(data.getValue(i, 0).getTime()); + } else { + row.push(data.getValue(i, 0)); + } for (var j = 1; j < cols; j++) { row.push(data.getValue(i, j)); } diff --git a/tests/numeric-axis.html b/tests/numeric-axis.html new file mode 100644 index 0000000..ad8d9e6 --- /dev/null +++ b/tests/numeric-axis.html @@ -0,0 +1,60 @@ + + + numeric axis + + + + + + +

CSV data source:

+
+ +

GViz data source:

+
+ + + + -- 2.7.4