X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-interaction-model.js;h=38e63d941daaabbc277e4909aeef56bf4ee9427b;hb=5ee26cc16754904d3e81c5786c35109ecdfb2687;hp=f29a52ba299b3e2c00af6bee1ba8d841c8c25c30;hpb=c7ad69891a81c463fde1d9765bf9c8ae2780811e;p=dygraphs.git diff --git a/dygraph-interaction-model.js b/dygraph-interaction-model.js index f29a52b..38e63d9 100644 --- a/dygraph-interaction-model.js +++ b/dygraph-interaction-model.js @@ -342,13 +342,27 @@ Dygraph.Interaction.endZoom = function(event, g, context) { Dygraph.Interaction.treatMouseOpAsClick(g, event, context); } + // The zoom rectangle is visibly clipped to the plot area, so its behavior + // should be as well. + // See http://code.google.com/p/dygraphs/issues/detail?id=280 + var plotArea = g.getArea(); if (regionWidth >= 10 && context.dragDirection == Dygraph.HORIZONTAL) { - g.doZoomX_(Math.min(context.dragStartX, context.dragEndX), - Math.max(context.dragStartX, context.dragEndX)); + var left = Math.min(context.dragStartX, context.dragEndX), + right = Math.max(context.dragStartX, context.dragEndX); + left = Math.max(left, plotArea.x); + right = Math.min(right, plotArea.x + plotArea.w); + if (left < right) { + g.doZoomX_(left, right); + } 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)); + var top = Math.min(context.dragStartY, context.dragEndY), + bottom = Math.max(context.dragStartY, context.dragEndY); + top = Math.max(top, plotArea.y); + bottom = Math.min(bottom, plotArea.y + plotArea.h); + if (top < bottom) { + g.doZoomY_(top, bottom); + } context.cancelNextDblclick = true; } else { if (context.zoomMoved) g.clearZoomRect_(); @@ -385,8 +399,9 @@ Dygraph.Interaction.startTouch = function(event, g, context) { // This is just a swipe. context.initialPinchCenter = touches[0]; context.touchDirections = { x: true, y: true }; - } else if (touches.length == 2) { + } else if (touches.length >= 2) { // It's become a pinch! + // In case there are 3+ touches, we ignore all but the "first" two. // only screen coordinates can be averaged (data coords could be log scale). context.initialPinchCenter = { @@ -467,7 +482,7 @@ Dygraph.Interaction.moveTouch = function(event, g, context) { if (touches.length == 1) { xScale = 1.0; yScale = 1.0; - } else if (touches.length == 2) { + } else if (touches.length >= 2) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); xScale = (touches[1].pageX - c_now.pageX) / initHalfWidth; @@ -595,6 +610,7 @@ Dygraph.Interaction.defaultModel = { if (context.isZooming) { context.dragEndX = null; context.dragEndY = null; + g.clearZoomRect_(); } },