Add multiple_axes.js which focuses only on new style series API.
[dygraphs.git] / auto_tests / tests / multiple_axes.js
index 05e93c7..39ec8b1 100644 (file)
@@ -63,40 +63,17 @@ MultipleAxesTestCase.prototype.testBasicMultipleAxes = function() {
       labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
       width: 640,
       height: 350,
-      'Y3': {
-        axis: {
-          // set axis-related properties here
-          labelsKMB: true
+      series : {
+        'Y3': {
+          axis: 'y2'
+        },
+        'Y4': {
+          axis: 'y2'
         }
       },
-      'Y4': {
-        axis: 'Y3'  // use the same y-axis as series Y3
-      }
-    }
-  );
-
-  assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], getYLabelsForAxis("1"));
-  assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], getYLabelsForAxis("2"));
-};
-
-MultipleAxesTestCase.prototype.testNewStylePerAxisOptions = function() {
-  var data = MultipleAxesTestCase.getData();
-
-  var g = new Dygraph(
-    document.getElementById("graph"),
-    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: {
+      axes : {
+        y2 : {
+          // set axis-related properties here
           labelsKMB: true
         }
       }
@@ -107,44 +84,6 @@ MultipleAxesTestCase.prototype.testNewStylePerAxisOptions = function() {
   assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], getYLabelsForAxis("2"));
 };
 
-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]);
@@ -156,8 +95,13 @@ MultipleAxesTestCase.prototype.testTwoAxisVisibility = function() {
     data,
     {
       labels: [ 'X', 'bar', 'zot' ],
-      'zot': {
-        axis: {
+      series : {
+        zot : {
+          axis : 'y2'
+        }
+      },
+      axes : {
+        y2: {
           labelsKMB: true
         }
       }
@@ -196,11 +140,13 @@ MultipleAxesTestCase.prototype.testMultiChartLabels = function() {
       labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
       width: 640,
       height: 350,
-      'Y3': {
-        axis: { }
-      },
-      'Y4': {
-        axis: 'Y3'  // use the same y-axis as series Y3
+      series : {
+        'Y3': {
+          axis: 'y2'
+        },
+        'Y4': {
+          axis: 'y2'
+        }
       },
       xlabel: 'x-axis',
       ylabel: 'y-axis',
@@ -252,13 +198,14 @@ MultipleAxesTestCase.prototype.testValueRangePerAxisOptions = function() {
     data,
     {
       labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
-      'Y3': {
-        axis: {
+      series : {
+        'Y3': {
+          axis: 'y2'
+        },
+        'Y4': {
+          axis: 'y2'
         }
       },
-      'Y4': {
-        axis: 'Y3'  // use the same y-axis as series Y3
-      },
       axes: {
         y: {
           valueRange: [40, 70]
@@ -290,4 +237,48 @@ MultipleAxesTestCase.prototype.testValueRangePerAxisOptions = function() {
   );
   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
+};
+
+MultipleAxesTestCase.prototype.testDrawPointCallback = function() {
+  var data = MultipleAxesTestCase.getData();
+
+  var results = { y : {}, y2 : {}};
+  var firstCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) {
+    results.y[seriesName] = 1; 
+    Dygraph.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius);
+
+  };
+  var secondCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) {
+    results.y2[seriesName] = 1; 
+    Dygraph.Circles.TRIANGLE(g, seriesName, ctx, canvasx, canvasy, color, radius);
+  };
+
+  g = new Dygraph(
+    document.getElementById("graph"),
+    data,
+    {
+      labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
+      drawPoints : true,
+      pointSize : 3,
+      series : {
+        'Y3': {
+          axis: 'y2'
+        },
+        'Y4': {
+          axis: 'y2'
+        }
+      },
+      axes: {
+        y2: {
+          drawPointCallback: secondCallback
+        }
+      },
+      drawPointCallback: firstCallback
+    }
+  );
+
+  assertEquals(1, results.y["Y1"]);
+  assertEquals(1, results.y["Y2"]);
+  assertEquals(1, results.y2["Y3"]);
+  assertEquals(1, results.y2["Y4"]);
+};