2 * @fileoverview Tests using the "stackedGraph" option.
4 * @author dan@dygraphs.com (Dan Vanderkam)
6 var stackedTestCase
= TestCase("stacked");
8 stackedTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 stackedTestCase
.prototype.tearDown
= function() {
15 stackedTestCase
.prototype.testCorrectColors
= function() {
25 colors
: ['#00ff00', '#0000ff'],
28 var data
= "X,Y1,Y2\n" +
35 var graph
= document
.getElementById("graph");
36 var g
= new Dygraph(graph
, data
, opts
);
38 // y pixels 299-201 = y2 = transparent blue
39 // y pixel 200 = y2 line (blue)
40 // y pixels 199-101 = y1 = transparent green
41 // y pixel 100 = y1 line (green)
42 // y pixels 0-99 = nothing (white)
44 // TODO(danvk): factor this and getPixel() into a utility usable by all tests.
45 var ctx
= g
.hidden_ctx_
;
46 var imageData
= ctx
.getImageData(0, 0, 400, 300);
48 assertEquals(400, imageData
.width
);
49 assertEquals(300, imageData
.height
);
51 // returns an (r, g, b, alpha) tuple for the pixel.
52 // values are in [0, 255].
53 var getPixel
= function(imageData
, x
, y
) {
54 var i
= 4 * (x
+ imageData
.width
* y
);
55 var d
= imageData
.data
;
56 return [d
[i
], d
[i
+1], d
[i
+2], d
[i
+3]];
59 // 38 = round(0.15 * 255)
60 assertEquals([0, 0, 255, 38], getPixel(imageData
, 200, 250));
61 assertEquals([0, 255, 0, 38], getPixel(imageData
, 200, 150));
64 // Regression test for http://code.google.com/p/dygraphs/issues/detail
?id
=358
65 stackedTestCase
.prototype.testSelectionValues
= function() {
69 var data
= "X,Y1,Y2\n" +
76 var graph
= document
.getElementById("graph");
77 g
= new Dygraph(graph
, data
, opts
);
81 assertEquals("0: Y1: 1 Y2: 1", Util
.getLegend());
83 // Verify that the behavior is correct with highlightSeriesOpts as well.
85 highlightSeriesOpts
: {
90 assertEquals("0: Y1: 1 Y2: 1", Util
.getLegend());
93 assertEquals("1: Y1: 1 Y2: 1", Util
.getLegend());
95 g
.setSelection(0, 'Y2');
96 assertEquals("0: Y1: 1 Y2: 1", Util
.getLegend());
99 // Regression test for http://code.google.com/p/dygraphs/issues/detail
?id
=176
100 stackedTestCase
.prototype.testDuplicatedXValue
= function() {
108 var data
= "X,Y1\n" +
112 "2,1\n" + // duplicate x-value!
116 var graph
= document
.getElementById("graph");
117 g
= new Dygraph(graph
, data
, opts
);
119 assert(g
.yAxisRange()[1] < 2);
121 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 250));
122 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 317, 250));