X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FDygraphOps.js;h=52f594385cbfb68c4b5b02d2ab4aa16194b85d14;hb=c36a62c2638dd9a4ce0c91146b9bcb2557168aff;hp=4dae18e2ec781d19d6394ee7183249e694d0334f;hpb=21c079e5c7761be8a0fb1e2d6a4d6ada57fae3a1;p=dygraphs.git diff --git a/auto_tests/tests/DygraphOps.js b/auto_tests/tests/DygraphOps.js index 4dae18e..52f5943 100644 --- a/auto_tests/tests/DygraphOps.js +++ b/auto_tests/tests/DygraphOps.js @@ -51,7 +51,7 @@ DygraphOps.defaultEvent_ = { * @param command the command to create. * @param custom an associative array of event attributes and their new values. */ -DygraphOps.createEvent_ = function(command, custom) { +DygraphOps.createEvent = function(command, custom) { var copy = function(from, to) { if (from != null) { @@ -86,70 +86,70 @@ DygraphOps.createEvent_ = function(command, custom) { e.button, e.relatedTarget); return event; -} +}; /** * Dispatch an event onto the graph's canvas. */ -DygraphOps.dispatchCanvasEvent(g, event) { +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); + var event = DygraphOps.createEvent(opts, custom); DygraphOps.dispatchCanvasEvent(g, event); }; -DygraphOps.dispatchMouseDown_Point = function(g, x, y, custom) { - var pageX = Dygraph.findPosX(g.canvas_) + x; - var pageY = Dygraph.findPosY(g.canvas_) + y; +/* + * Create an 'opts' argument which can be passed to createEvent that contains + * type, screenX, screenY, clientX, clientY. + */ +DygraphOps.createOptsForPoint_ = function(g, type, x, y) { + var pos = Dygraph.findPos(g.canvas_); + var pageX = pos.x + x; + var pageY = pos.y + y; - var opts = { - type : 'mousedown', - detail : 1, + return { + type : type, screenX : pageX, screenY : pageY, clientX : pageX, clientY : pageY, }; +}; - var event = DygraphOps.createEvent_(opts, custom); +DygraphOps.dispatchMouseDown_Point = function(g, x, y, custom) { + var opts = DygraphOps.createOptsForPoint_(g, 'mousedown', x, y); + opts.detail = 1; + var event = DygraphOps.createEvent(opts, custom); DygraphOps.dispatchCanvasEvent(g, event); -} +}; 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', - screenX : pageX, - screenY : pageY, - clientX : pageX, - clientY : pageY, - }; - - var event = DygraphOps.createEvent_(opts, custom); + var opts = DygraphOps.createOptsForPoint_(g, 'mousemove', x, y); + var event = DygraphOps.createEvent(opts, custom); DygraphOps.dispatchCanvasEvent(g, event); }; DygraphOps.dispatchMouseUp_Point = function(g, x, y, custom) { - var pageX = Dygraph.findPosX(g.canvas_) + x; - var pageY = Dygraph.findPosY(g.canvas_) + y; + var opts = DygraphOps.createOptsForPoint_(g, 'mouseup', x, y); + var event = DygraphOps.createEvent(opts, custom); + DygraphOps.dispatchCanvasEvent(g, event); +}; - var opts = { - type : 'mouseup', - screenX : pageX, - screenY : pageY, - clientX : pageX, - clientY : pageY, - }; +DygraphOps.dispatchMouseOver_Point = function(g, x, y, custom) { + var opts = DygraphOps.createOptsForPoint_(g, 'mouseover', x, y); + var event = DygraphOps.createEvent(opts, custom); + DygraphOps.dispatchCanvasEvent(g, event); +}; - var event = DygraphOps.createEvent_(opts, custom); +DygraphOps.dispatchMouseOut_Point = function(g, x, y, custom) { + var opts = DygraphOps.createOptsForPoint_(g, 'mouseout', x, y); + var event = DygraphOps.createEvent(opts, custom); DygraphOps.dispatchCanvasEvent(g, event); }; @@ -189,3 +189,27 @@ DygraphOps.dispatchMouseUp = function(g, x, y, custom) { custom); }; +/** + * Dispatches a mouse over using the graph's data coordinate system. + * (The y value mapped to the first axis.) + */ +DygraphOps.dispatchMouseOver = function(g, x, y, custom) { + DygraphOps.dispatchMouseOver_Point( + g, + g.toDomXCoord(x), + g.toDomYCoord(y), + custom); +}; + +/** + * Dispatches a mouse out using the graph's data coordinate system. + * (The y value mapped to the first axis.) + */ +DygraphOps.dispatchMouseOut = function(g, x, y, custom) { + DygraphOps.dispatchMouseOut_Point( + g, + g.toDomXCoord(x), + g.toDomYCoord(y), + custom); +}; +