X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-interaction-model.js;h=b1981d77ce9ed2460f063f73e660e4115a97371a;hb=b04888ccae2e78f4b1113e3904e2828d8dcaed08;hp=9afc3c19bc8c3d6065a481e14122dd2ce5b4430e;hpb=6108122b89102ea5eab6ae02f9175acc6dfbd353;p=dygraphs.git diff --git a/dygraph-interaction-model.js b/dygraph-interaction-model.js index 9afc3c1..b1981d7 100644 --- a/dygraph-interaction-model.js +++ b/dygraph-interaction-model.js @@ -342,13 +342,21 @@ 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); + g.doZoomX_(Math.max(left, plotArea.x), + Math.min(right, plotArea.x + plotArea.w)); 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); + g.doZoomY_(Math.max(top, plotArea.y), + Math.min(bottom, plotArea.y + plotArea.h)); context.cancelNextDblclick = true; } else { if (context.zoomMoved) g.clearZoomRect_(); @@ -596,6 +604,7 @@ Dygraph.Interaction.defaultModel = { if (context.isZooming) { context.dragEndX = null; context.dragEndY = null; + g.clearZoomRect_(); } },