From: Robert Konigsberg Date: Sat, 30 Mar 2013 11:07:34 +0000 (-0400) Subject: Add test suite for DygraphOptions object. Fix broken method in it. X-Git-Tag: v1.0.0~43^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=cd872296479aecce62b74c787dc778732070c498;p=dygraphs.git Add test suite for DygraphOptions object. Fix broken method in it. --- 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"]);