2 * @fileoverview Tests involving multiple y-axes.
4 * @author danvdk@gmail.com (Dan Vanderkam)
7 var MultipleAxesOldTestCase
= TestCase("multiple-axes-old-tests");
9 MultipleAxesOldTestCase
.prototype.setUp
= function() {
10 document
.body
.innerHTML
= "<div id='graph'></div>";
13 MultipleAxesOldTestCase
.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 MultipleAxesOldTestCase
.prototype.testOldBasicMultipleAxes
= function() {
32 var data
= MultipleAxesTestCase
.getData();
35 document
.getElementById("graph"),
38 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
43 // set axis-related properties here
48 axis
: 'Y3' // use the same y-axis as series Y3
53 assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], Util
.getYLabels("1"));
54 assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], Util
.getYLabels("2"));
57 MultipleAxesOldTestCase
.prototype.testOldNewStylePerAxisOptions
= function() {
58 var data
= MultipleAxesTestCase
.getData();
61 document
.getElementById("graph"),
64 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
71 axis
: 'Y3' // use the same y-axis as series Y3
81 assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], Util
.getYLabels("1"));
82 assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], Util
.getYLabels("2"));
85 MultipleAxesOldTestCase
.prototype.testOldMultiAxisLayout
= function() {
86 var data
= MultipleAxesTestCase
.getData();
88 var el
= document
.getElementById("graph");
94 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
101 axis
: 'Y3' // use the same y-axis as series Y3
111 // Test that all elements are inside the bounds of the graph, set above
112 var innerDiv
= el
.firstChild
;
113 for (var child
= innerDiv
.firstChild
; child
!= null; child
= child
.nextSibling
) {
114 assertTrue(child
.offsetLeft
>= 0);
115 assertTrue((child
.offsetLeft
+ child
.offsetWidth
) <= 640);
116 assertTrue(child
.offsetTop
>= 0);
117 // TODO(flooey@google.com): Text sometimes linebreaks,
118 // causing the labels to appear outside the allocated area.
119 // assertTrue((child.offsetTop + child.offsetHeight) <= 350);
123 MultipleAxesOldTestCase
.prototype.testOldTwoAxisVisibility
= function() {
126 data
.push([1,2,2000]);
127 data
.push([2,4,1000]);
130 document
.getElementById("graph"),
133 labels
: [ 'X', 'bar', 'zot' ],
142 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
143 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
145 g
.setVisibility(0, false);
147 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
148 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
150 g
.setVisibility(0, true);
151 g
.setVisibility(1, false);
153 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y").length
> 0);
154 assertTrue(document
.getElementsByClassName("dygraph-axis-label-y2").length
> 0);
157 // verifies that all four chart labels (title, x-, y-, y2-axis label) can be
158 // used simultaneously.
159 MultipleAxesOldTestCase
.prototype.testOldMultiChartLabels
= function() {
160 var data
= MultipleAxesTestCase
.getData();
162 var el
= document
.getElementById("graph");
163 el
.style
.border
= '1px solid black';
164 el
.style
.marginLeft
= '200px';
165 el
.style
.marginTop
= '200px';
171 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
178 axis
: 'Y3' // use the same y-axis as series Y3
187 assertEquals(["Chart title", "x-axis", "y-axis", "y2-axis"],
188 Util
.getClassTexts("dygraph-label"));
189 assertEquals(["Chart title"], Util
.getClassTexts("dygraph-title"));
190 assertEquals(["x-axis"], Util
.getClassTexts("dygraph-xlabel"));
191 assertEquals(["y-axis"], Util
.getClassTexts("dygraph-ylabel"));
192 assertEquals(["y2-axis"], Util
.getClassTexts("dygraph-y2label"));
194 // TODO(danvk): check relative positioning here: title on top, y left of y2.
197 // Check that a chart w/o a secondary y
-axis will not get a y2label
, even
if one
199 MultipleAxesOldTestCase
.prototype.testOldNoY2LabelWithoutSecondaryAxis
= function() {
201 document
.getElementById("graph"),
202 MultipleAxesTestCase
.getData(),
204 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
214 assertEquals(["Chart title", "x-axis", "y-axis"],
215 Util
.getClassTexts("dygraph-label"));
216 assertEquals(["Chart title"], Util
.getClassTexts("dygraph-title"));
217 assertEquals(["x-axis"], Util
.getClassTexts("dygraph-xlabel"));
218 assertEquals(["y-axis"], Util
.getClassTexts("dygraph-ylabel"));
219 assertEquals([], Util
.getClassTexts("dygraph-y2label"));
222 MultipleAxesOldTestCase
.prototype.testOldValueRangePerAxisOptions
= function() {
223 var data
= MultipleAxesTestCase
.getData();
226 document
.getElementById("graph"),
229 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
235 axis
: 'Y3' // use the same y-axis as series Y3
242 // set axis-related properties here
246 ylabel
: 'Primary y-axis',
247 y2label
: 'Secondary y-axis',
251 assertEquals(["40", "45", "50", "55", "60", "65"], Util
.getYLabels("1"));
252 assertEquals(["900K","1.1M","1.3M","1.5M","1.7M","1.9M"], Util
.getYLabels("2"));
261 valueRange
: [1e6
, 1.2e6
]
266 assertEquals(["40", "45", "50", "55", "60", "65", "70", "75"], Util
.getYLabels("1"));
267 assertEquals(["1M", "1.02M", "1.05M", "1.08M", "1.1M", "1.13M", "1.15M", "1.18M"], Util
.getYLabels("2"));
270 MultipleAxesOldTestCase
.prototype.testOldDrawPointCallback
= function() {
271 var data
= MultipleAxesTestCase
.getData();
273 var results
= { y
: {}, y2
: {}};
274 var firstCallback
= function(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
) {
275 results
.y
[seriesName
] = 1;
276 Dygraph
.Circles
.DEFAULT(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
);
279 var secondCallback
= function(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
) {
280 results
.y2
[seriesName
] = 1;
281 Dygraph
.Circles
.DEFAULT(g
, seriesName
, ctx
, canvasx
, canvasy
, color
, radius
);
285 document
.getElementById("graph"),
288 labels
: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
296 axis
: 'Y3' // use the same y-axis as series Y3
300 drawPointCallback
: secondCallback
303 drawPointCallback
: firstCallback
307 assertEquals(1, results
.y
["Y1"]);
308 assertEquals(1, results
.y
["Y2"]);
309 assertEquals(1, results
.y2
["Y3"]);
310 assertEquals(1, results
.y2
["Y4"]);