X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-interaction-model.js;h=d335f15a3e7b7986184009dac6edbca30f31da41;hb=21ebe38bb1eeae3a7fd73335a411bfd81c66d985;hp=27906332670ee08b3f6da58fa0933ac92323ba8f;hpb=6125fedf574a2916c5c48bc711da86984ed13a6f;p=dygraphs.git diff --git a/dygraph-interaction-model.js b/dygraph-interaction-model.js index 2790633..d335f15 100644 --- a/dygraph-interaction-model.js +++ b/dygraph-interaction-model.js @@ -28,10 +28,11 @@ Dygraph.Interaction = {}; * Custom interaction model builders can use it to provide the default * panning behavior. * - * @param { Event } event the event object which led to the startPan call. - * @param { Dygraph} g The dygraph on which to act. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the startPan call. + * @param {Dygraph} g The dygraph on which to act. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.startPan = function(event, g, context) { var i, axis; @@ -106,10 +107,11 @@ Dygraph.Interaction.startPan = function(event, g, context) { * Custom interaction model builders can use it to provide the default * panning behavior. * - * @param { Event } event the event object which led to the movePan call. - * @param { Dygraph} g The dygraph on which to act. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the movePan call. + * @param {Dygraph} g The dygraph on which to act. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.movePan = function(event, g, context) { context.dragEndX = g.dragGetX_(event, context); @@ -176,10 +178,11 @@ Dygraph.Interaction.movePan = function(event, g, context) { * Custom interaction model builders can use it to provide the default * panning behavior. * - * @param { Event } event the event object which led to the endPan call. - * @param { Dygraph} g The dygraph on which to act. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the endPan call. + * @param {Dygraph} g The dygraph on which to act. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.endPan = function(event, g, context) { context.dragEndX = g.dragGetX_(event, context); @@ -213,13 +216,15 @@ Dygraph.Interaction.endPan = function(event, g, context) { * Custom interaction model builders can use it to provide the default * zooming behavior. * - * @param { Event } event the event object which led to the startZoom call. - * @param { Dygraph} g The dygraph on which to act. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the startZoom call. + * @param {Dygraph} g The dygraph on which to act. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.startZoom = function(event, g, context) { context.isZooming = true; + context.zoomMoved = false; }; /** @@ -230,12 +235,14 @@ Dygraph.Interaction.startZoom = function(event, g, context) { * Custom interaction model builders can use it to provide the default * zooming behavior. * - * @param { Event } event the event object which led to the moveZoom call. - * @param { Dygraph} g The dygraph on which to act. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the moveZoom call. + * @param {Dygraph} g The dygraph on which to act. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.moveZoom = function(event, g, context) { + context.zoomMoved = true; context.dragEndX = g.dragGetX_(event, context); context.dragEndY = g.dragGetY_(event, context); @@ -260,13 +267,19 @@ Dygraph.Interaction.moveZoom = function(event, g, context) { context.prevDragDirection = context.dragDirection; }; +/** + * @param {Dygraph} g + * @param {Event} event + * @param {Object} context + */ Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) { var clickCallback = g.attr_('clickCallback'); var pointClickCallback = g.attr_('pointClickCallback'); var selectedPoint = null; - // Find out if the click occurs on a point. This only matters if there's a pointClickCallback. + // Find out if the click occurs on a point. This only matters if there's a + // pointClickCallback. if (pointClickCallback) { var closestIdx = -1; var closestDistance = Number.MAX_VALUE; @@ -309,10 +322,11 @@ Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) { * Custom interaction model builders can use it to provide the default * zooming behavior. * - * @param { Event } event the event object which led to the endZoom call. - * @param { Dygraph} g The dygraph on which to end the zoom. - * @param { Object} context The dragging context object (with - * dragStartX/dragStartY/etc. properties). This function modifies the context. + * @param {Event} event the event object which led to the endZoom call. + * @param {Dygraph} g The dygraph on which to end the zoom. + * @param {Object} context The dragging context object (with + * dragStartX/dragStartY/etc. properties). This function modifies the + * context. */ Dygraph.Interaction.endZoom = function(event, g, context) { context.isZooming = false; @@ -329,11 +343,13 @@ Dygraph.Interaction.endZoom = function(event, g, context) { if (regionWidth >= 10 && context.dragDirection == Dygraph.HORIZONTAL) { g.doZoomX_(Math.min(context.dragStartX, context.dragEndX), Math.max(context.dragStartX, context.dragEndX)); + context.cancelNextDblclick = true; } else if (regionHeight >= 10 && context.dragDirection == Dygraph.VERTICAL) { g.doZoomY_(Math.min(context.dragStartY, context.dragEndY), Math.max(context.dragStartY, context.dragEndY)); + context.cancelNextDblclick = true; } else { - g.clearZoomRect_(); + if (context.zoomMoved) g.clearZoomRect_(); } context.dragStartX = null; context.dragStartY = null; @@ -372,7 +388,7 @@ Dygraph.Interaction.startTouch = function(event, g, context) { // TODO(danvk): remove dataX: 0.5 * (touches[0].dataX + touches[1].dataX), - dataY: 0.5 * (touches[0].dataY + touches[1].dataY), + dataY: 0.5 * (touches[0].dataY + touches[1].dataY) }; // Make pinches in a 45-degree swath around either axis 1-dimensional zooms. @@ -401,12 +417,12 @@ Dygraph.Interaction.startTouch = function(event, g, context) { * @private */ Dygraph.Interaction.moveTouch = function(event, g, context) { - var touches = []; - for (var i = 0; i < event.touches.length; i++) { + var i, touches = []; + for (i = 0; i < event.touches.length; i++) { var t = event.touches[i]; touches.push({ pageX: t.pageX, - pageY: t.pageY, + pageY: t.pageY }); } var initialTouches = context.initialTouches; @@ -428,7 +444,7 @@ Dygraph.Interaction.moveTouch = function(event, g, context) { // we toss it out for now, but could use it in the future. var swipe = { pageX: c_now.pageX - c_init.pageX, - pageY: c_now.pageY - c_init.pageY, + pageY: c_now.pageY - c_init.pageY }; var dataWidth = context.initialRange.x[1] - context.initialRange.x[0]; var dataHeight = context.initialRange.y[0] - context.initialRange.y[1]; @@ -456,19 +472,19 @@ Dygraph.Interaction.moveTouch = function(event, g, context) { if (context.touchDirections.x) { g.dateWindow_ = [ c_init.dataX - swipe.dataX + (context.initialRange.x[0] - c_init.dataX) / xScale, - c_init.dataX - swipe.dataX + (context.initialRange.x[1] - c_init.dataX) / xScale, + c_init.dataX - swipe.dataX + (context.initialRange.x[1] - c_init.dataX) / xScale ]; } if (context.touchDirections.y) { - for (var i = 0; i < 1 /*g.axes_.length*/; i++) { + for (i = 0; i < 1 /*g.axes_.length*/; i++) { var axis = g.axes_[i]; if (axis.logscale) { // TODO(danvk): implement } else { axis.valueWindow = [ c_init.dataY - swipe.dataY + (context.initialRange.y[0] - c_init.dataY) / yScale, - c_init.dataY - swipe.dataY + (context.initialRange.y[1] - c_init.dataY) / yScale, + c_init.dataY - swipe.dataY + (context.initialRange.y[1] - c_init.dataY) / yScale ]; } } @@ -481,7 +497,7 @@ Dygraph.Interaction.moveTouch = function(event, g, context) { * @private */ Dygraph.Interaction.endTouch = function(event, g, context) { - if (event.touches.length != 0) { + if (event.touches.length !== 0) { // this is effectively a "reset" Dygraph.Interaction.startTouch(event, g, context); } @@ -499,6 +515,9 @@ Dygraph.Interaction.endTouch = function(event, g, context) { Dygraph.Interaction.defaultModel = { // Track the beginning of drag events mousedown: function(event, g, context) { + // Right-click should not initiate a zoom. + if (event.button && event.button == 2) return; + context.initializeMouseDown(event, g, context); if (event.altKey || event.shiftKey) { @@ -545,6 +564,10 @@ Dygraph.Interaction.defaultModel = { // Disable zooming out if panning. dblclick: function(event, g, context) { + if (context.cancelNextDblclick) { + context.cancelNextDblclick = false; + return; + } if (event.altKey || event.shiftKey) { return; }