--- /dev/null
+/**
+ * @fileoverview Test cases for how axis labels are chosen and formatted.
+ *
+ * @author dan@dygraphs.com (Dan Vanderkam)
+ */
+var MultiCsvTestCase = TestCase("axis-labels");
+
+MultiCsvTestCase.prototype.setUp = function() {
+ document.body.innerHTML = "<div id='graph'></div>";
+};
+
+MultiCsvTestCase.prototype.tearDown = function() {
+};
+
+function getXLabels() {
+ var x_labels = document.getElementsByClassName("dygraph-axis-label-x");
+ var ary = [];
+ for (var i = 0; i < x_labels.length; i++) {
+ ary.push(x_labels[i].innerHTML);
+ }
+ return ary;
+}
+
+MultiCsvTestCase.prototype.testOneCSV = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "X,Y\n" +
+ "0,-1\n" +
+ "1,0\n" +
+ "2,1\n" +
+ "3,0\n"
+ ;
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+
+ assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+};
+
+MultiCsvTestCase.prototype.testTwoCSV = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "X,Y\n" +
+ "0,-1\n" +
+ "1,0\n" +
+ "2,1\n" +
+ "3,0\n"
+ ;
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+
+ assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+
+ g.updateOptions({file: data});
+
+ assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+};
this.boundaryIds_ = [];
- // Make a note of whether labels will be pulled from the CSV file.
- this.labelsFromCSV_ = (this.attr_("labels") == null);
-
// Create the containing DIV and other interactive elements
this.createInterface_();
}
var start = 0;
- if (this.labelsFromCSV_) {
+ if (!('labels' in this.user_attrs_)) {
+ // User hasn't explicitly set labels, so they're (presumably) in the CSV.
start = 1;
- this.attrs_.labels = lines[0].split(delim);
+ this.attrs_.labels = lines[0].split(delim); // NOTE: _not_ user_attrs_.
}
var line_no = 0;
Dygraph.update(this.user_attrs_, attrs);
- this.labelsFromCSV_ = (this.attr_("labels") == null);
-
if (attrs['file']) {
this.file_ = attrs['file'];
if (!block_redraw) this.start_();