X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fper_series.js;h=1a044966ff7e3a9b036efdcd2e59951cddb609a2;hb=c1c42651dd140ecb0460cfcff736aceb117f9cc6;hp=4831ded5994b62d0ca4358a22f4fe78ea3a31842;hpb=9f636500f08868182ecd88288636e7f8718e28de;p=dygraphs.git diff --git a/auto_tests/tests/per_series.js b/auto_tests/tests/per_series.js index 4831ded..1a04496 100644 --- a/auto_tests/tests/per_series.js +++ b/auto_tests/tests/per_series.js @@ -1,5 +1,5 @@ /** - * @fileoverview FILL THIS IN + * @fileoverview Tests for per-series options. * * @author danvk@google.com (Dan Vanderkam) */ @@ -12,7 +12,6 @@ perSeriesTestCase.prototype.setUp = function() { perSeriesTestCase.prototype.tearDown = function() { }; - perSeriesTestCase.prototype.testPerSeriesFill = function() { var opts = { width: 480, @@ -48,3 +47,121 @@ perSeriesTestCase.prototype.testPerSeriesFill = function() { assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); }; +perSeriesTestCase.prototype.testOldStyleSeries = function() { + var opts = { + pointSize : 5, + Y: { pointSize : 4 }, + }; + var graph = document.getElementById("graph"); + var data = "X,Y,Z\n1,0,0\n"; + g = new Dygraph(graph, data, opts); + + assertEquals(5, g.getOption("pointSize")); + assertEquals(4, g.getOption("pointSize", "Y")); + assertEquals(5, g.getOption("pointSize", "Z")); +}; + +perSeriesTestCase.prototype.testNewStyleSeries = function() { + var opts = { + pointSize : 5, + series : { + Y: { pointSize : 4 } + }, + }; + var graph = document.getElementById("graph"); + var data = "X,Y,Z\n1,0,0\n"; + g = new Dygraph(graph, data, opts); + + assertEquals(5, g.getOption("pointSize")); + assertEquals(4, g.getOption("pointSize", "Y")); + assertEquals(5, g.getOption("pointSize", "Z")); +}; + +perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() { + var opts = { + pointSize : 5, + Z : { pointSize : 6 }, + series : { + Y: { pointSize : 4 } + }, + }; + var graph = document.getElementById("graph"); + var data = "X,Y,Z\n1,0,0\n"; + g = new Dygraph(graph, data, opts); + + assertEquals(5, g.getOption("pointSize")); + assertEquals(4, g.getOption("pointSize", "Y")); + assertEquals(5, g.getOption("pointSize", "Z")); + + // Erase the series object, and Z will become visible again. + g.updateOptions({ series : undefined }); + assertEquals(5, g.getOption("pointSize")); + assertEquals(6, g.getOption("pointSize", "Z")); + assertEquals(5, g.getOption("pointSize", "Y")); +}; + +// TODO(konigsberg): move to multiple_axes.js +perSeriesTestCase.prototype.testAxisInNewSeries = function() { + var opts = { + series : { + D : { axis : 'y2' }, + C : { axis : 1 }, + B : { axis : 0 }, + E : { axis : 'y' } + } + }; + var graph = document.getElementById("graph"); + var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; + g = new Dygraph(graph, data, opts); + + assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); +}; + +// TODO(konigsberg): move to multiple_axes.js +perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() { + var opts = { + series : { + D : { axis : 'y2' }, + C : { axis : 1 }, + B : { axis : 0 }, + E : { axis : 'y' } + }, + axes : { + y : { pointSize : 7 }, + y2 : { pointSize : 6 } + } + }; + var graph = document.getElementById("graph"); + var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; + g = new Dygraph(graph, data, opts); + + assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); + + assertEquals(1.5, g.getOption("pointSize")); + assertEquals(7, g.getOption("pointSize", "A")); + assertEquals(7, g.getOption("pointSize", "B")); + assertEquals(6, g.getOption("pointSize", "C")); + assertEquals(6, g.getOption("pointSize", "D")); + assertEquals(7, g.getOption("pointSize", "E")); +}; + +// TODO(konigsberg): move to multiple_axes.js +perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() { + var opts = { + series : { + D : { axis : {} }, + }, + }; + var graph = document.getElementById("graph"); + var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; + var threw = false; + try { + new Dygraph(graph, data, opts); + } catch(e) { + threw = true; + } + + assertTrue(threw); +}