From cd872296479aecce62b74c787dc778732070c498 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Sat, 30 Mar 2013 07:07:34 -0400 Subject: [PATCH] Add test suite for DygraphOptions object. Fix broken method in it. --- auto_tests/misc/local.html | 1 + auto_tests/tests/dygraph-options-tests.js | 32 +++++++++++++++++++++++++++++++ dygraph-options.js | 14 +++++++------- 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 auto_tests/tests/dygraph-options-tests.js diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index 74f57e6..3841372 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -26,6 +26,7 @@ + diff --git a/auto_tests/tests/dygraph-options-tests.js b/auto_tests/tests/dygraph-options-tests.js new file mode 100644 index 0000000..691b24a --- /dev/null +++ b/auto_tests/tests/dygraph-options-tests.js @@ -0,0 +1,32 @@ +/** + * @fileoverview Test cases for DygraphOptions. + */ +var DygraphOptionsTestCase = TestCase("dygraph-options-tests"); + +DygraphOptionsTestCase.prototype.setUp = function() { + document.body.innerHTML = "
"; +}; + +DygraphOptionsTestCase.prototype.tearDown = function() { +}; + +/* + * Pathalogical test to ensure getSeriesNames works + */ +DygraphOptionsTestCase.prototype.testGetSeriesNames = function() { + var opts = { + width: 480, + height: 320 + }; + var data = "X,Y,Y2,Y3\n" + + "0,-1,0,0"; + + // Kind of annoying that you need a DOM to test the object. + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, opts); + + // We don't need to get at g's attributes_ object just + // to test DygraphOptions. + var o = new DygraphOptions(g); + assertEquals(["Y", "Y2", "Y3"], o.seriesNames()); +}; diff --git a/dygraph-options.js b/dygraph-options.js index 55bfe1a..6889a09 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -100,7 +100,7 @@ DygraphOptions.prototype.reparseSeries = function() { return; // -- can't do more for now, will parse after getting the labels. } - this.labels = labels.slice(1); + this.labels_ = labels.slice(1); this.yAxes_ = [ { series : [], options : {}} ]; // Always one axis at least. this.xAxis_ = { options : {} }; @@ -133,8 +133,8 @@ DygraphOptions.prototype.reparseSeries = function() { if (oldStyleSeries) { var axisId = 0; // 0-offset; there's always one. // Go through once, add all the series, and for those with {} axis options, add a new axis. - for (var idx = 0; idx < this.labels.length; idx++) { - var seriesName = this.labels[idx]; + for (var idx = 0; idx < this.labels_.length; idx++) { + var seriesName = this.labels_[idx]; var optionsForSeries = this.user_[seriesName] || {}; @@ -155,8 +155,8 @@ DygraphOptions.prototype.reparseSeries = function() { // Go through one more time and assign series to an axis defined by another // series, e.g. { 'Y1: { axis: {} }, 'Y2': { axis: 'Y1' } } - for (var idx = 0; idx < this.labels.length; idx++) { - var seriesName = this.labels[idx]; + for (var idx = 0; idx < this.labels_.length; idx++) { + var seriesName = this.labels_[idx]; var optionsForSeries = this.series_[seriesName]["options"]; var axis = optionsForSeries["axis"]; @@ -172,8 +172,8 @@ DygraphOptions.prototype.reparseSeries = function() { } } } else { - for (var idx = 0; idx < this.labels.length; idx++) { - var seriesName = this.labels[idx]; + for (var idx = 0; idx < this.labels_.length; idx++) { + var seriesName = this.labels_[idx]; var optionsForSeries = this.user_.series[seriesName] || {}; var yAxis = DygraphOptions.axisToIndex_(optionsForSeries["axis"]); -- 2.7.4