tweak custom circle demo to add per-series highlighting
[dygraphs.git] / auto_tests / tests / callback.js
index 6281b92..fe7f7fd 100644 (file)
@@ -1,4 +1,4 @@
-/** 
+/**
  * @fileoverview Test cases for the callbacks.
  *
  * @author uemit.seren@gmail.com (Ümit Seren)
@@ -54,6 +54,99 @@ CallbackTestCase.prototype.testHighlightCallbackIsCalled = function() {
   assertEquals(2, h_pts.length);
 };
 
+
+/**
+ * Test that drawPointCallback isn't called when drawPoints is false
+ */
+CallbackTestCase.prototype.testDrawPointCallback_disabled = function() {
+  var called = false;
+
+  var callback = function() {
+    called = true;
+  };
+
+  var graph = document.getElementById("graph");
+  var g = new Dygraph(graph, data, {
+      drawPointCallback : callback,
+    });
+
+  assertFalse(called);
+};
+
+/**
+ * Test that drawPointCallback is called when drawPoints is true
+ */
+CallbackTestCase.prototype.testDrawPointCallback_enabled = function() {
+  var called = false;
+
+  var callback = function() {
+    called = true;
+  };
+
+  var graph = document.getElementById("graph");
+  var g = new Dygraph(graph, data, {
+      drawPoints : true,
+      drawPointCallback : callback
+    });
+
+  assertTrue(called);
+};
+
+/**
+ * Test that drawPointCallback is called when drawPoints is true
+ */
+CallbackTestCase.prototype.testDrawPointCallback_pointSize = function() {
+  var pointSize = 0;
+  var count = 0;
+
+  var callback = function(g, seriesName, canvasContext, cx, cy, color, pointSizeParam) {
+    pointSize = pointSizeParam;
+    count++;
+  };
+
+  var graph = document.getElementById("graph");
+  var g = new Dygraph(graph, data, {
+      drawPoints : true,
+      drawPointCallback : callback
+    });
+
+  assertEquals(1.5, pointSize);
+  assertEquals(12, count); // one call per data point.
+
+  var g = new Dygraph(graph, data, {
+      drawPoints : true,
+      drawPointCallback : callback,
+      pointSize : 8
+    });
+
+  assertEquals(8, pointSize);
+};
+
+/**
+ * This tests that when the function idxToRow_ returns the proper row and the onHiglightCallback
+ * is properly called when the first series is hidden (setVisibility = false)
+ *
+ */
+CallbackTestCase.prototype.testDrawHighlightPointCallbackIsCalled = function() {
+  var called = false;
+
+  var drawHighlightPointCallback  = function() {
+    called = true;
+  };
+
+  var graph = document.getElementById("graph");
+  var g = new Dygraph(graph, data,
+      {
+        width: 100,
+        height : 100,
+        drawHighlightPointCallback : drawHighlightPointCallback
+      });
+
+  assertFalse(called);
+  DygraphOps.dispatchMouseMove(g, 13, 10);
+  assertTrue(called);
+};
+
 /**
  * Test the closest-series highlighting methods for normal and stacked modes.
  * Also pass in line widths for plain and highlighted lines for easier visual
@@ -74,8 +167,7 @@ var runClosestTest = function(isStacked, widthNormal, widthHighlighted) {
         strokeWidth: widthNormal,
         strokeBorderWidth: 2,
         highlightCircleSize: widthNormal * 2,
-        highlightSeriesBackgroundFade: 0.7,
-        highlightSeriesAnimate: true,
+        highlightSeriesBackgroundAlpha: 0.3,
 
         highlightSeriesOpts: {
           strokeWidth: widthHighlighted,