}
/**
+ * This tests that clickCallback is still called with the nonInteractiveModel.
+ */
+InteractionModelTestCase.prototype.testClickCallbackIsCalledWithNonInteractiveModel = function() {
+ var clicked;
+
+ // TODO(danvk): also test pointClickCallback here.
+ var clickCallback = function(event, x) {
+ clicked = x;
+ };
+
+ var opts = {
+ width: 100,
+ height : 100,
+ clickCallback : clickCallback,
+ interactionModel : {}
+ };
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data1, opts);
+
+ DygraphOps.dispatchMouseDown_Point(g, 10, 10);
+ DygraphOps.dispatchMouseMove_Point(g, 10, 10);
+ DygraphOps.dispatchMouseUp_Point(g, 10, 10);
+
+ assertEquals(20, clicked);
+};
+
+/**
* A sanity test to ensure pointClickCallback is called.
*/
InteractionModelTestCase.prototype.testPointClickCallback = function() {
Dygraph.movePan = Dygraph.Interaction.movePan;
Dygraph.startPan = Dygraph.Interaction.startPan;
+Dygraph.Interaction.nonInteractiveModel = {
+ mousedown: function(event, g, context) {
+ context.initializeMouseDown(event, g, context);
+ },
+ mouseup: function(event, g, context) {
+ // TODO(danvk): this logic is repeated in Dygraph.Interaction.endZoom
+ context.dragEndX = g.dragGetX_(event, context);
+ context.dragEndY = g.dragGetY_(event, context);
+ var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
+ var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
+
+ if (regionWidth < 2 && regionHeight < 2 &&
+ g.lastx_ != undefined && g.lastx_ != -1) {
+ Dygraph.Interaction.treatMouseOpAsClick(g, event, context);
+ }
+ }
+};
<tr><td>
<b>No interaction model</b>
<div id="div_g2" style="width:600px; height:300px;"></div>
- </td><td>Click and drag all you like, it won't do anything!</td></tr>
+ </td><td>Click and drag all you like, it won't do anything!
+ <div id="g2_console"></div>
+ </td></tr>
<tr><td>
<b>Custom interaction model</b>
Dygraph.addEvent(document, "click", function() { lastClickedGraph = null; });
var g = new Dygraph(document.getElementById("div_g"),
NoisyData, { errorBars : true });
+ var s = document.getElementById("g2_console");
var g2 = new Dygraph(document.getElementById("div_g2"),
- NoisyData, { errorBars : true, interactionModel : {} });
+ NoisyData,
+ {
+ errorBars : true,
+ interactionModel: Dygraph.Interaction.nonInteractiveModel,
+ clickCallback: function(e, x, pts) {
+ s.innerHTML += "<b>Click</b> " + pts[0].name + ": " + pts[0].x + "<br/>";
+ },
+ pointClickCallback: function(e, p) {
+ s.innerHTML += "<b>Point Click</b> " + p.name + ": " + p.x + "<br/>";
+ },
+ });
var g3 = new Dygraph(document.getElementById("div_g3"),
NoisyData, { errorBars : true, interactionModel : {
'mousedown' : downV3,