2 * @fileoverview Utility functions for Dygraphs.
4 * @author konigsberg@google.com (Robert Konigsberg)
9 * Get the y-labels for a given axis.
11 * You can specify a parent if more than one graph is in the document.
13 Util
.getYLabels
= function(axis_num
, parent
) {
14 axis_num
= axis_num
|| "";
15 parent
= parent
|| document
;
16 var y_labels
= parent
.getElementsByClassName("dygraph-axis-label-y" + axis_num
);
18 for (var i
= 0; i
< y_labels
.length
; i
++) {
19 ary
.push(y_labels
[i
].innerHTML
);
25 * Get the x-labels for a given axis.
27 * You can specify a parent if more than one graph is in the document.
29 Util
.getXLabels
= function(parent
) {
30 parent
= parent
|| document
;
31 var x_labels
= parent
.getElementsByClassName("dygraph-axis-label-x");
33 for (var i
= 0; i
< x_labels
.length
; i
++) {
34 ary
.push(x_labels
[i
].innerHTML
);
40 * Returns all text in tags w/ a given css class, sorted.
41 * You can specify a parent if more than one graph is on the document.
43 Util
.getClassTexts
= function(css_class
, parent
) {
44 parent
= parent
|| document
;
46 var els
= parent
.getElementsByClassName(css_class
);
47 for (var i
= 0; i
< els
.length
; i
++) {
48 texts
[i
] = els
[i
].textContent
;
54 Util
.getLegend
= function(parent
) {
55 parent
= parent
|| document
;
56 var legend
= parent
.getElementsByClassName("dygraph-legend")[0];
57 return legend
.textContent
;
61 * Assert that all elements have a certain style property.
63 Util
.assertStyleOfChildren
= function(selector
, property
, expectedValue
) {
64 assertTrue(selector
.length
> 0);
65 $.each(selector
, function(idx
, child
) {
66 assertEquals(expectedValue
, $(child
).css(property
));
72 * Takes in an array of strings and returns an array of floats.
74 Util
.makeNumbers
= function(ary
) {
76 for (var i
= 0; i
< ary
.length
; i
++) {
77 ret
.push(parseFloat(ary
[i
]));