2 * @fileoverview Tests involving multiple y-axes.
4 * @author danvdk@gmail.com (Dan Vanderkam)
7 describe("multiple-axes-tests", function() {
9 beforeEach(function() {
10 document
.body
.innerHTML
= "<div id='graph'></div>";
13 var getData
= function() {
15 for (var i
= 1; i
<= 100; i
++) {
17 if (d
> 31) { m
= "02"; d
-= 31; }
18 if (m
== "02" && d
> 28) { m
= "03"; d
-= 28; }
19 if (m
== "03" && d
> 31) { m
= "04"; d
-= 31; }
20 if (d
< 10) d
= "0" + d
;
21 // two series, one with range 1-100, one with range 1-2M
22 data
.push([new Date("2010/" + m + "/" + d
),
25 1e6
* (1 + i
* (100 - i
) / (50 * 50)),
26 1e6
* (2 - i
* (100 - i
) / (50 * 50))]);
31 it('testBasicMultipleAxes', function() {
35 document
.getElementById("graph"),
38 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
51 // set axis-related properties here
58 assert
.deepEqual(["0","20","40","60","80","100"], Util
.getYLabels("1"));
59 assert
.deepEqual(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util
.getYLabels("2"));
62 it('testTwoAxisVisibility', function() {
65 data
.push([1,2,2000]);
66 data
.push([2,4,1000]);
69 document
.getElementById("graph"),
72 labels
: [ 'X', 'bar', 'zot' ],
86 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
87 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
89 g
.setVisibility(0, false);
91 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
92 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
94 g
.setVisibility(0, true);
95 g
.setVisibility(1, false);
97 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
98 assert
.isTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
101 // verifies that all four chart labels (title, x-, y-, y2-axis label) can be
102 // used simultaneously.
103 it('testMultiChartLabels', function() {
104 var data
= getData();
106 var el
= document
.getElementById("graph");
107 el
.style
.border
= '1px solid black';
108 el
.style
.marginLeft
= '200px';
109 el
.style
.marginTop
= '200px';
115 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
133 assert
.deepEqual(["Chart title", "x-axis", "y-axis", "y2-axis"],
134 Util
.getClassTexts("dygraph-label"));
135 assert
.deepEqual(["Chart title"], Util
.getClassTexts("dygraph-title"));
136 assert
.deepEqual(["x-axis"], Util
.getClassTexts("dygraph-xlabel"));
137 assert
.deepEqual(["y-axis"], Util
.getClassTexts("dygraph-ylabel"));
138 assert
.deepEqual(["y2-axis"], Util
.getClassTexts("dygraph-y2label"));
140 // TODO(danvk): check relative positioning here: title on top, y left of y2.
143 // Check that a chart w/o a secondary y
-axis will not get a y2label
, even
if one
145 it('testNoY2LabelWithoutSecondaryAxis', function() {
147 document
.getElementById("graph"),
150 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
160 assert
.deepEqual(["Chart title", "x-axis", "y-axis"],
161 Util
.getClassTexts("dygraph-label"));
162 assert
.deepEqual(["Chart title"], Util
.getClassTexts("dygraph-title"));
163 assert
.deepEqual(["x-axis"], Util
.getClassTexts("dygraph-xlabel"));
164 assert
.deepEqual(["y-axis"], Util
.getClassTexts("dygraph-ylabel"));
165 assert
.deepEqual([], Util
.getClassTexts("dygraph-y2label"));
168 it('testValueRangePerAxisOptions', function() {
169 var data
= getData();
172 document
.getElementById("graph"),
175 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
190 // set axis-related properties here
194 ylabel
: 'Primary y-axis',
195 y2label
: 'Secondary y-axis',
198 assert
.deepEqual(["40", "45", "50", "55", "60", "65"], Util
.getYLabels("1"));
199 assert
.deepEqual(["900K","1.1M","1.3M","1.5M","1.7M","1.9M"], Util
.getYLabels("2"));
208 valueRange
: [1e6
, 1.2e6
]
213 assert
.deepEqual(["40", "45", "50", "55", "60", "65", "70", "75"], Util
.getYLabels("1"));
214 assert
.deepEqual(["1M", "1.02M", "1.05M", "1.08M", "1.1M", "1.13M", "1.15M", "1.18M"], Util
.getYLabels("2"));
217 it('testDrawPointCallback', function() {
218 var data
= getData();
220 var results
= { y
: {}, y2
: {}};
221 var firstCallback
= function(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
) {
222 results
.y
[seriesName
] = 1;
223 Dygraph
.Circles
.DEFAULT(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
);
226 var secondCallback
= function(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
) {
227 results
.y2
[seriesName
] = 1;
228 Dygraph
.Circles
.DEFAULT(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
);
232 document
.getElementById("graph"),
235 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
248 drawPointCallback
: secondCallback
251 drawPointCallback
: firstCallback
255 assert
.equal(1, results
.y
["Y1"]);
256 assert
.equal(1, results
.y
["Y2"]);
257 assert
.equal(1, results
.y2
["Y3"]);
258 assert
.equal(1, results
.y2
["Y4"]);
261 // Test for http://code.google.com/p/dygraphs/issues/detail
?id
=436
262 it('testRemovingSecondAxis', function() {
263 var data
= getData();
265 var results
= { y
: {}, y2
: {}};
268 document
.getElementById("graph"),
271 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
282 g
.updateOptions({ series
: { Y4
: { axis
: 'y' } } });