X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fper_series.js;h=f3ff16d099c551f8ee3f6bc45a4cdf45a16906ac;hb=91bd611cb031bf1f3d39650e3109135fd0e78791;hp=1a044966ff7e3a9b036efdcd2e59951cddb609a2;hpb=b839102723a21830b8896413f9c3fa9b7c643238;p=dygraphs.git diff --git a/auto_tests/tests/per_series.js b/auto_tests/tests/per_series.js index 1a04496..f3ff16d 100644 --- a/auto_tests/tests/per_series.js +++ b/auto_tests/tests/per_series.js @@ -3,24 +3,32 @@ * * @author danvk@google.com (Dan Vanderkam) */ -var perSeriesTestCase = TestCase("per-series"); -perSeriesTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; -}; +import Dygraph from '../../src/dygraph'; -perSeriesTestCase.prototype.tearDown = function() { -}; +import PixelSampler from './PixelSampler'; -perSeriesTestCase.prototype.testPerSeriesFill = function() { +describe("per-series", function() { + +cleanupAfterEach(); + +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 }; @@ -36,72 +44,78 @@ 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('testPerSeriesAlpha', function() { var opts = { - pointSize : 5, - Y: { pointSize : 4 }, + width: 480, + height: 320, + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: false, + } + }, + series: { + Y: { fillGraph: true, fillAlpha: 0.25 }, + Z: { fillGraph: true, fillAlpha: 0.75 } + }, + colors: [ '#FF0000', '#0000FF' ] }; + var data = "X,Y,Z\n" + + "1,0,0\n" + + "2,0,1\n" + + "3,0,1\n" + + "4,0,0\n" + + "5,0,0\n" + + "6,1,0\n" + + "7,1,0\n" + + "8,0,0\n" + ; + 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")); -}; + var sampler = new PixelSampler(g); -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); + // Inside of the "Y" bump -- 5% alpha. + assert.deepEqual([255,0,0,63], sampler.colorAtCoordinate(6.5, 0.5)); - assertEquals(5, g.getOption("pointSize")); - assertEquals(4, g.getOption("pointSize", "Y")); - assertEquals(5, g.getOption("pointSize", "Z")); -}; + // Inside of the "Z" bump -- 95% alpha. + assert.deepEqual([0,0,255,191], sampler.colorAtCoordinate(2.5, 0.5)); +}); -perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() { +it('testNewStyleSeries', 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")); + var g = new Dygraph(graph, data, opts); - // 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")); -}; + assert.equal(5, g.getOption("pointSize")); + assert.equal(4, g.getOption("pointSize", "Y")); + assert.equal(5, g.getOption("pointSize", "Z")); +}); // TODO(konigsberg): move to multiple_axes.js -perSeriesTestCase.prototype.testAxisInNewSeries = function() { +it('testAxisInNewSeries', function() { var opts = { series : { D : { axis : 'y2' }, @@ -112,14 +126,14 @@ perSeriesTestCase.prototype.testAxisInNewSeries = function() { }; 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); + var g = new Dygraph(graph, data, opts); - assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); - assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); -}; + assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1)); +}); // TODO(konigsberg): move to multiple_axes.js -perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() { +it('testAxisInNewSeries_withAxes', function() { var opts = { series : { D : { axis : 'y2' }, @@ -134,21 +148,21 @@ perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() { }; 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); + var g = new Dygraph(graph, data, opts); - assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); - assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); + assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); + assert.deepEqual(["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")); -}; + 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 -perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() { +it('testOldAxisSpecInNewSeriesThrows', function() { var opts = { series : { D : { axis : {} }, @@ -163,5 +177,16 @@ perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() { threw = true; } - assertTrue(threw); -} + 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()); +}); + +});