From 890e2a375555ef65c4b8eec3cea265578116deae Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 20 Jul 2012 14:42:37 -0400 Subject: [PATCH] failing stacked test --- auto_tests/misc/local.html | 1 + auto_tests/tests/stacked.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ dygraph-options-reference.js | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 auto_tests/tests/stacked.js diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index 961a9d5..877d272 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -42,6 +42,7 @@ --> + diff --git a/auto_tests/tests/stacked.js b/auto_tests/tests/stacked.js new file mode 100644 index 0000000..a269cab --- /dev/null +++ b/auto_tests/tests/stacked.js @@ -0,0 +1,63 @@ +/** + * @fileoverview Tests using the "stackedGraph" option. + * + * @author dan@dygraphs.com (Dan Vanderkam) + */ +var stackedTestCase = TestCase("stacked"); + +stackedTestCase.prototype.setUp = function() { + document.body.innerHTML = "
"; +}; + +stackedTestCase.prototype.tearDown = function() { +}; + +stackedTestCase.prototype.testCorrectColors = function() { + var opts = { + width: 400, + height: 300, + stackedGraph: true, + drawXGrid: false, + drawYGrid: false, + drawXAxis: false, + drawYAxis: false, + valueRange: [0, 3], + colors: ['#00ff00', '#0000ff'], + fillAlpha: 0.15 + }; + var data = "X,Y1,Y2\n" + + "0,1,1\n" + + "1,1,1\n" + + "2,1,1\n" + + "3,1,1\n" + ; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, opts); + + // y pixels 299-201 = y2 = transparent blue + // y pixel 200 = y2 line (blue) + // y pixels 199-101 = y1 = transparent green + // y pixel 100 = y1 line (green) + // y pixels 0-99 = nothing (white) + + var canvas = g.hidden_ctx_; + var imageData = canvas.getImageData(0, 0, 400, 300); + + assertEquals(400, imageData.width); + assertEquals(300, imageData.height); + + // returns an (r, g, b, alpha) tuple for the pixel. + // values are in [0, 255]. + var getPixel = function(imageData, x, y) { + var i = 4 * (x + imageData.width * y); + var d = imageData.data; + return [d[i], d[i+1], d[i+2], d[i+3]]; + }; + + // 38 = round(0.15 * 255) + assertEquals([0, 0, 255, 38], getPixel(imageData, 200, 250)); + assertEquals([0, 255, 0, 38], getPixel(imageData, 200, 150)); + assertEquals([255, 255, 255, 255], getPixel(imageData, 200, 50)); +}; + diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 69bed8a..04f13d7 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -23,7 +23,7 @@ Dygraph.OPTIONS_REFERENCE = // "default": "false", "labels": ["Data Line display"], "type": "boolean", - "description": "If set, stack series on top of one another rather than drawing them independently." + "description": "If set, stack series on top of one another rather than drawing them independently. The first series specified in the input data will wind up on top of the chart and the last will be on bottom." }, "pointSize": { "default": "1", -- 2.7.4