X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FDygraphOps.js;h=460547bb53ee74059c2056a477b27501ab03873b;hb=ac928d203b05de4a8d43ad89667347865e98bb7c;hp=072d99294f9848fafd8d2501ad1bd4683331fd89;hpb=02eb7ae72eb3d5e83c2bf546d1fc2a6a60b91008;p=dygraphs.git diff --git a/auto_tests/tests/DygraphOps.js b/auto_tests/tests/DygraphOps.js index 072d992..460547b 100644 --- a/auto_tests/tests/DygraphOps.js +++ b/auto_tests/tests/DygraphOps.js @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +import * as utils from '../../src/dygraph-utils'; /** * @fileoverview Utility functions for Dygraphs. @@ -44,7 +45,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) { @@ -79,71 +87,132 @@ DygraphOps.createEvent_ = function(command, custom) { e.button, e.relatedTarget); 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); +/* + * 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 = utils.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); - g.canvas_.dispatchEvent(event); +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 = function(g, x, y, custom) { - var px = Dygraph.findPosX(g.canvas_); - var py = Dygraph.findPosY(g.canvas_); +DygraphOps.dispatchMouseMove_Point = function(g, x, y, custom) { + var opts = DygraphOps.createOptsForPoint_(g, 'mousemove', x, y); + var event = DygraphOps.createEvent(opts, custom); + DygraphOps.dispatchCanvasEvent(g, event); +}; - var pageX = px + g.toDomXCoord(x); - var pageY = py + g.toDomYCoord(y); +DygraphOps.dispatchMouseUp_Point = function(g, x, y, custom) { + var opts = DygraphOps.createOptsForPoint_(g, 'mouseup', x, y); + var event = DygraphOps.createEvent(opts, custom); + DygraphOps.dispatchCanvasEvent(g, event); +}; - var opts = { - type : 'mousemove', - 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); - g.canvas_.dispatchEvent(event); +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); }; -DygraphOps.dispatchMouseUp = function(g, x, y, custom) { - var px = Dygraph.findPosX(g.canvas_); - var py = Dygraph.findPosY(g.canvas_); +/** + * 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); +}; - var pageX = px + g.toDomXCoord(x); - var pageY = py + g.toDomYCoord(y); +/** + * 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); +}; - var opts = { - type : 'mouseup', - screenX : pageX, - screenY : pageY, - clientX : pageX, - clientY : pageY, - }; +/** + * 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); +}; - var event = DygraphOps.createEvent_(opts, custom); - g.canvas_.dispatchEvent(event); +/** + * 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); }; + + +export default DygraphOps;