X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fper_series.js;h=a09f912c367e220e2c4c8ec10210b0cbe4de1215;hb=51fc2820e9e5423394175f481d7003e196718554;hp=a198a95474106bbb8316dcf6d69ace72af3d8c06;hpb=ed8df44ec5bb0b1445474652d4de8f9cd52ca2cb;p=dygraphs.git diff --git a/auto_tests/tests/per_series.js b/auto_tests/tests/per_series.js index a198a95..a09f912 100644 --- a/auto_tests/tests/per_series.js +++ b/auto_tests/tests/per_series.js @@ -3,25 +3,32 @@ * * @author danvk@google.com (Dan Vanderkam) */ -var perSeriesTestCase = TestCase("per-series"); +describe("per-series", function() { -perSeriesTestCase.prototype.setUp = function() { +beforeEach(function() { document.body.innerHTML = "
"; -}; +}); -perSeriesTestCase.prototype.tearDown = function() { -}; +afterEach(function() { +}); - -perSeriesTestCase.prototype.testPerSeriesFill = function() { +it('testPerSeriesFill', function() { var opts = { width: 480, height: 320, - drawXGrid: false, - drawYGrid: false, - drawXAxis: false, - drawYAxis: false, - Y: { fillGraph: true }, + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: false, + } + }, + series: { + Y: { fillGraph: true }, + }, colors: [ '#FF0000', '#0000FF' ], fillAlpha: 0.15 }; @@ -37,67 +44,106 @@ perSeriesTestCase.prototype.testPerSeriesFill = function() { ; var graph = document.getElementById("graph"); - g = new Dygraph(graph, data, opts); + var g = new Dygraph(graph, data, opts); var sampler = new PixelSampler(g); // Inside of the "Z" bump -- no fill. - assertEquals([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5)); + assert.deepEqual([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5)); // Inside of the "Y" bump -- filled in. - assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); -}; + assert.deepEqual([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); +}); -perSeriesTestCase.prototype.testOldStyleSeries = function() { +it('testNewStyleSeries', function() { var opts = { pointSize : 5, - Y: { pointSize : 4 }, + series : { + Y: { pointSize : 4 } + }, }; var graph = document.getElementById("graph"); var data = "X,Y,Z\n1,0,0\n"; - g = new Dygraph(graph, data, opts); + var g = new Dygraph(graph, data, opts); - assertEquals(5, g.getOption("pointSize")); - assertEquals(4, g.getOption("pointSize", "Y")); - assertEquals(5, g.getOption("pointSize", "Z")); -}; + assert.equal(5, g.getOption("pointSize")); + assert.equal(4, g.getOption("pointSize", "Y")); + assert.equal(5, g.getOption("pointSize", "Z")); +}); -perSeriesTestCase.prototype.testNewStyleSeries = function() { +// TODO(konigsberg): move to multiple_axes.js +it('testAxisInNewSeries', function() { var opts = { - pointSize : 5, series : { - Y: { pointSize : 4 } - }, + D : { axis : 'y2' }, + C : { axis : 1 }, + B : { axis : 0 }, + E : { axis : 'y' } + } }; var graph = document.getElementById("graph"); - var data = "X,Y,Z\n1,0,0\n"; - g = new Dygraph(graph, data, opts); + var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; + var g = new Dygraph(graph, data, opts); - assertEquals(5, g.getOption("pointSize")); - assertEquals(4, g.getOption("pointSize", "Y")); - assertEquals(5, g.getOption("pointSize", "Z")); -}; + assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1)); +}); -perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() { +// TODO(konigsberg): move to multiple_axes.js +it('testAxisInNewSeries_withAxes', function() { var opts = { - pointSize : 5, - Z : { pointSize : 6 }, series : { - Y: { pointSize : 4 } + 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,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")); -}; - + var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; + var g = new Dygraph(graph, data, opts); + + assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1)); + + assert.equal(1.5, g.getOption("pointSize")); + assert.equal(7, g.getOption("pointSize", "A")); + assert.equal(7, g.getOption("pointSize", "B")); + assert.equal(6, g.getOption("pointSize", "C")); + assert.equal(6, g.getOption("pointSize", "D")); + assert.equal(7, g.getOption("pointSize", "E")); +}); + +// TODO(konigsberg): move to multiple_axes.js +it('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; + } + + assert.isTrue(threw); +}); + +it('testColorOption', function() { + var graph = document.getElementById("graph"); + var data = "X,A,B,C\n0,1,2,3\n"; + var g = new Dygraph(graph, data, {}); + assert.deepEqual(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors()); + g.updateOptions({series : { B : { color : 'purple' }}}); + assert.deepEqual(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors()); +}); + +});