From b04888ccae2e78f4b1113e3904e2828d8dcaed08 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 18 Feb 2013 15:32:21 -0500 Subject: [PATCH] Clean up some zooming oddities; fixes issues 434 and 280 --- dygraph-interaction-model.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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_(); } }, -- 2.7.4