Move common code to Util.js, reducing multiple-axes tests.
[dygraphs.git] / auto_tests / tests / Util.js
1 /**
2 * @fileoverview Utility functions for Dygraphs.
3 *
4 * @author konigsberg@google.com (Robert Konigsberg)
5 */
6 var Util = {};
7
8 /**
9 * Get the y-labels for a given axis. You can specify a parent if more than one
10 * graph is on the document.
11 */
12 Util.getYLabels = function(axis_num, parent) {
13 axis_num = axis_num || "";
14 parent = parent || document;
15 var y_labels = parent.getElementsByClassName("dygraph-axis-label-y" + axis_num);
16 var ary = [];
17 for (var i = 0; i < y_labels.length; i++) {
18 ary.push(y_labels[i].innerHTML);
19 }
20 return ary;
21 }
22
23 /**
24 * Returns all text in tags w/ a given css class, sorted.
25 * You can specify a parent if more than one graph is on the document.
26 */
27 Util.getClassTexts = function(css_class, parent) {
28 parent = parent || document;
29 var texts = [];
30 var els = parent.getElementsByClassName(css_class);
31 for (var i = 0; i < els.length; i++) {
32 texts[i] = els[i].textContent;
33 }
34 texts.sort();
35 return texts;
36 }