+
+MultipleAxesTestCase.prototype.testMultiAxisLayout = function() {
+ var data = MultipleAxesTestCase.getData();
+
+ var el = document.getElementById("graph");
+
+ var g = new Dygraph(
+ el,
+ data,
+ {
+ labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
+ width: 640,
+ height: 350,
+ 'Y3': {
+ axis: { }
+ },
+ 'Y4': {
+ axis: 'Y3' // use the same y-axis as series Y3
+ },
+ axes: {
+ y2: {
+ labelsKMB: true
+ }
+ }
+ }
+ );
+
+ // Test that all elements are inside the bounds of the graph, set above
+ var innerDiv = el.firstChild;
+ for (var child = innerDiv.firstChild; child != null; child = child.nextSibling) {
+ assertTrue(child.offsetLeft >= 0);
+ assertTrue((child.offsetLeft + child.offsetWidth) <= 640);
+ assertTrue(child.offsetTop >= 0);
+ // TODO(flooey@google.com): Text sometimes linebreaks,
+ // causing the labels to appear outside the allocated area.
+ // assertTrue((child.offsetTop + child.offsetHeight) <= 350);
+ }
+};
+
+MultipleAxesTestCase.prototype.testTwoAxisVisibility = function() {
+ var data = [];
+ data.push([0,0,0]);
+ data.push([1,2,2000]);
+ data.push([2,4,1000]);
+
+ var g = new Dygraph(
+ document.getElementById("graph"),
+ data,
+ {
+ labels: [ 'X', 'bar', 'zot' ],
+ 'zot': {
+ axis: {
+ labelsKMB: true
+ }
+ }
+ }
+ );
+
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0);
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0);
+
+ g.setVisibility(0, false);
+
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0);
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0);
+
+ g.setVisibility(0, true);
+ g.setVisibility(1, false);
+
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0);
+ assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0);
+};
+
+// verifies that all four chart labels (title, x-, y-, y2-axis label) can be
+// used simultaneously.
+MultipleAxesTestCase.prototype.testMultiChartLabels = function() {
+ var data = MultipleAxesTestCase.getData();
+
+ var el = document.getElementById("graph");
+ el.style.border = '1px solid black';
+ el.style.marginLeft = '200px';
+ el.style.marginTop = '200px';
+
+ var g = new Dygraph(
+ el,
+ data,
+ {
+ labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
+ width: 640,
+ height: 350,
+ 'Y3': {
+ axis: { }
+ },
+ 'Y4': {
+ axis: 'Y3' // use the same y-axis as series Y3
+ },
+ xlabel: 'x-axis',
+ ylabel: 'y-axis',
+ y2label: 'y2-axis',
+ title: 'Chart title'
+ }
+ );
+
+ assertEquals(["Chart title", "x-axis", "y-axis", "y2-axis"],
+ getClassTexts("dygraph-label"));
+ assertEquals(["Chart title"], getClassTexts("dygraph-title"));
+ assertEquals(["x-axis"], getClassTexts("dygraph-xlabel"));
+ assertEquals(["y-axis"], getClassTexts("dygraph-ylabel"));
+ assertEquals(["y2-axis"], getClassTexts("dygraph-y2label"));
+
+ // TODO(danvk): check relative positioning here: title on top, y left of y2.
+};
+
+// Check that a chart w/o a secondary y-axis will not get a y2label, even if one
+// is specified.
+MultipleAxesTestCase.prototype.testNoY2LabelWithoutSecondaryAxis = function() {
+ var g = new Dygraph(
+ document.getElementById("graph"),
+ MultipleAxesTestCase.getData(),
+ {
+ labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
+ width: 640,
+ height: 350,
+ xlabel: 'x-axis',
+ ylabel: 'y-axis',
+ y2label: 'y2-axis',
+ title: 'Chart title'
+ }
+ );
+
+ assertEquals(["Chart title", "x-axis", "y-axis"],
+ getClassTexts("dygraph-label"));
+ assertEquals(["Chart title"], getClassTexts("dygraph-title"));
+ assertEquals(["x-axis"], getClassTexts("dygraph-xlabel"));
+ assertEquals(["y-axis"], getClassTexts("dygraph-ylabel"));
+ assertEquals([], getClassTexts("dygraph-y2label"));
+};
+
+MultipleAxesTestCase.prototype.testValueRangePerAxisOptions = function() {
+ var data = MultipleAxesTestCase.getData();
+
+ g = new Dygraph(
+ document.getElementById("graph"),
+ data,
+ {
+ labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
+ 'Y3': {
+ axis: {
+ }
+ },
+ 'Y4': {
+ axis: 'Y3' // use the same y-axis as series Y3
+ },
+ axes: {
+ y: {
+ valueRange: [40, 70]
+ },
+ y2: {
+ // set axis-related properties here
+ labelsKMB: true
+ }
+ },
+ ylabel: 'Primary y-axis',
+ y2label: 'Secondary y-axis',
+ yAxisLabelWidth: 60
+ }
+ );
+ assertEquals(["40", "45", "50", "55", "60", "65"], getYLabelsForAxis("1"));
+ assertEquals(["900K","1.1M","1.3M","1.5M","1.7M","1.9M"], getYLabelsForAxis("2"));
+
+ g.updateOptions(
+ {
+ axes: {
+ y: {
+ valueRange: [40, 80]
+ },
+ y2: {
+ valueRange: [1e6, 1.2e6]
+ }
+ }
+ }
+ );
+ assertEquals(["40", "45", "50", "55", "60", "65", "70", "75"], getYLabelsForAxis("1"));
+ assertEquals(["1M", "1.02M", "1.05M", "1.08M", "1.1M", "1.13M", "1.15M", "1.18M"], getYLabelsForAxis("2"));
+};
\ No newline at end of file