Merge branch 'master' of git://github.com/danvk/dygraphs
[dygraphs.git] / auto_tests / tests / DygraphOps.js
index 072d992..d792259 100644 (file)
@@ -44,7 +44,14 @@ DygraphOps.defaultEvent_ = {
   relatedTarget : null
 };
 
-DygraphOps.createEvent_ = function(command, custom) {
+/**
+ * Create an event. Sets default event values except for special ones
+ * overridden by the 'custom' parameter.
+ *
+ * @param command the command to create.
+ * @param custom an associative array of event attributes and their new values.
+ */
+DygraphOps.createEvent = function(command, custom) {
 
   var copy = function(from, to) {
     if (from != null) {
@@ -81,21 +88,25 @@ DygraphOps.createEvent_ = function(command, custom) {
   return event;
 }
 
+/**
+ * Dispatch an event onto the graph's canvas.
+ */
+DygraphOps.dispatchCanvasEvent = function(g, event) {
+  g.canvas_.dispatchEvent(event);
+}
+
 DygraphOps.dispatchDoubleClick = function(g, custom) {
   var opts = {
     type : 'dblclick',
     detail : 2
   };
-  var event = DygraphOps.createEvent_(opts, custom);
-  g.canvas_.dispatchEvent(event);
+  var event = DygraphOps.createEvent(opts, custom);
+  DygraphOps.dispatchCanvasEvent(g, event);
 };
 
-DygraphOps.dispatchMouseDown = function(g, x, y, custom) {
-  var px = Dygraph.findPosX(g.canvas_);
-  var py = Dygraph.findPosY(g.canvas_);
-
-  var pageX = px + g.toDomXCoord(x);
-  var pageY = py + g.toDomYCoord(y);
+DygraphOps.dispatchMouseDown_Point = function(g, x, y, custom) {
+  var pageX = Dygraph.findPosX(g.canvas_) + x;
+  var pageY = Dygraph.findPosY(g.canvas_) + y;
 
   var opts = {
     type : 'mousedown',
@@ -106,16 +117,13 @@ DygraphOps.dispatchMouseDown = function(g, x, y, custom) {
     clientY : pageY,
   };
 
-  var event = DygraphOps.createEvent_(opts, custom);
-  g.canvas_.dispatchEvent(event);
-};
-
-DygraphOps.dispatchMouseMove = function(g, x, y, custom) {
-  var px = Dygraph.findPosX(g.canvas_);
-  var py = Dygraph.findPosY(g.canvas_);
+  var event = DygraphOps.createEvent(opts, custom);
+  DygraphOps.dispatchCanvasEvent(g, event);
+}
 
-  var pageX = px + g.toDomXCoord(x);
-  var pageY = py + g.toDomYCoord(y);
+DygraphOps.dispatchMouseMove_Point = function(g, x, y, custom) {
+  var pageX = Dygraph.findPosX(g.canvas_) + x;
+  var pageY = Dygraph.findPosY(g.canvas_) + y;
 
   var opts = {
     type : 'mousemove',
@@ -125,16 +133,13 @@ DygraphOps.dispatchMouseMove = function(g, x, y, custom) {
     clientY : pageY,
   };
 
-  var event = DygraphOps.createEvent_(opts, custom);
-  g.canvas_.dispatchEvent(event);
+  var event = DygraphOps.createEvent(opts, custom);
+  DygraphOps.dispatchCanvasEvent(g, event);
 };
 
-DygraphOps.dispatchMouseUp = function(g, x, y, custom) {
-  var px = Dygraph.findPosX(g.canvas_);
-  var py = Dygraph.findPosY(g.canvas_);
-
-  var pageX = px + g.toDomXCoord(x);
-  var pageY = py + g.toDomYCoord(y);
+DygraphOps.dispatchMouseUp_Point = function(g, x, y, custom) {
+  var pageX = Dygraph.findPosX(g.canvas_) + x;
+  var pageY = Dygraph.findPosY(g.canvas_) + y;
 
   var opts = {
     type : 'mouseup',
@@ -144,6 +149,43 @@ DygraphOps.dispatchMouseUp = function(g, x, y, custom) {
     clientY : pageY,
   };
 
-  var event = DygraphOps.createEvent_(opts, custom);
-  g.canvas_.dispatchEvent(event);
+  var event = DygraphOps.createEvent(opts, custom);
+  DygraphOps.dispatchCanvasEvent(g, event);
+};
+
+/**
+ * Dispatches a mouse down using the graph's data coordinate system.
+ * (The y value mapped to the first axis.)
+ */
+DygraphOps.dispatchMouseDown = function(g, x, y, custom) {
+  DygraphOps.dispatchMouseDown_Point(
+      g,
+      g.toDomXCoord(x),
+      g.toDomYCoord(y),
+      custom);
 };
+
+/**
+ * Dispatches a mouse move using the graph's data coordinate system.
+ * (The y value mapped to the first axis.)
+ */
+DygraphOps.dispatchMouseMove = function(g, x, y, custom) {
+  DygraphOps.dispatchMouseMove_Point(
+      g,
+      g.toDomXCoord(x),
+      g.toDomYCoord(y),
+      custom);
+};
+
+/**
+ * Dispatches a mouse up using the graph's data coordinate system.
+ * (The y value mapped to the first axis.)
+ */
+DygraphOps.dispatchMouseUp = function(g, x, y, custom) {
+  DygraphOps.dispatchMouseUp_Point(
+      g,
+      g.toDomXCoord(x),
+      g.toDomYCoord(y),
+      custom);
+};
+