context.initialLeftmostDate = xRange[0];
context.xUnitsPerPixel = context.dateRange / (g.plotter_.area.w - 1);
- if (g.attr_("panEdgeFraction")) {
- var maxXPixelsToDraw = g.width_ * g.attr_("panEdgeFraction");
+ if (g.getNumericOption("panEdgeFraction")) {
+ var maxXPixelsToDraw = g.width_ * g.getNumericOption("panEdgeFraction");
var xExtremes = g.xAxisExtremes(); // I REALLY WANT TO CALL THIS xTremes!
var boundedLeftX = g.toDomXCoord(xExtremes[0]) - maxXPixelsToDraw;
context.boundedDates = [boundedLeftDate, boundedRightDate];
var boundedValues = [];
- var maxYPixelsToDraw = g.height_ * g.attr_("panEdgeFraction");
+ var maxYPixelsToDraw = g.height_ * g.getNumericOption("panEdgeFraction");
for (i = 0; i < g.axes_.length; i++) {
axis = g.axes_[i];
var boundedTopY = g.toDomYCoord(yExtremes[0], i) + maxYPixelsToDraw;
var boundedBottomY = g.toDomYCoord(yExtremes[1], i) - maxYPixelsToDraw;
- var boundedTopValue = g.toDataYCoord(boundedTopY);
- var boundedBottomValue = g.toDataYCoord(boundedBottomY);
+ var boundedTopValue = g.toDataYCoord(boundedTopY, i);
+ var boundedBottomValue = g.toDataYCoord(boundedBottomY, i);
boundedValues[i] = [boundedTopValue, boundedBottomValue];
}
* context.
*/
Dygraph.Interaction.movePan = function(event, g, context) {
- context.dragEndX = g.dragGetX_(event, context);
- context.dragEndY = g.dragGetY_(event, context);
+ context.dragEndX = Dygraph.dragGetX_(event, context);
+ context.dragEndY = Dygraph.dragGetY_(event, context);
var minDate = context.initialLeftmostDate -
(context.dragEndX - context.dragStartX) * context.xUnitsPerPixel;
// y-axis scaling is automatic unless this is a full 2D pan.
if (context.is2DPan) {
+
+ var pixelsDragged = context.dragEndY - context.dragStartY;
+
// Adjust each axis appropriately.
for (var i = 0; i < g.axes_.length; i++) {
var axis = g.axes_[i];
var axis_data = context.axes[i];
-
- var pixelsDragged = context.dragEndY - context.dragStartY;
var unitsDragged = pixelsDragged * axis_data.unitsPerPixel;
var boundedValue = context.boundedValues ? context.boundedValues[i] : null;
* context.
*/
Dygraph.Interaction.endPan = function(event, g, context) {
- context.dragEndX = g.dragGetX_(event, context);
- context.dragEndY = g.dragGetY_(event, context);
+ context.dragEndX = Dygraph.dragGetX_(event, context);
+ context.dragEndY = Dygraph.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
*/
Dygraph.Interaction.moveZoom = function(event, g, context) {
context.zoomMoved = true;
- context.dragEndX = g.dragGetX_(event, context);
- context.dragEndY = g.dragGetY_(event, context);
+ context.dragEndX = Dygraph.dragGetX_(event, context);
+ context.dragEndY = Dygraph.dragGetY_(event, context);
var xDelta = Math.abs(context.dragStartX - context.dragEndX);
var yDelta = Math.abs(context.dragStartY - context.dragEndY);
* @param {Object} context
*/
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
- var clickCallback = g.attr_('clickCallback');
- var pointClickCallback = g.attr_('pointClickCallback');
+ var clickCallback = g.getFunctionOption('clickCallback');
+ var pointClickCallback = g.getFunctionOption('pointClickCallback');
var selectedPoint = null;
}
// Allow any click within two pixels of the dot.
- var radius = g.attr_('highlightCircleSize') + 2;
+ var radius = g.getNumericOption('highlightCircleSize') + 2;
if (closestDistance <= radius * radius) {
selectedPoint = g.selPoints_[closestIdx];
}
*/
Dygraph.Interaction.endZoom = function(event, g, context) {
context.isZooming = false;
- context.dragEndX = g.dragGetX_(event, context);
- context.dragEndY = g.dragGetY_(event, context);
+ context.dragEndX = Dygraph.dragGetX_(event, context);
+ context.dragEndY = Dygraph.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
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_();
// 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 = {
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;
g.drawGraph_(false);
// We only call zoomCallback on zooms, not pans, to mirror desktop behavior.
- if (didZoom && touches.length > 1 && g.attr_('zoomCallback')) {
+ if (didZoom && touches.length > 1 && g.getFunctionOption('zoomCallback')) {
var viewWindow = g.xAxisRange();
- g.attr_("zoomCallback")(viewWindow[0], viewWindow[1], g.yAxisRanges());
+ g.getFunctionOption("zoomCallback")(viewWindow[0], viewWindow[1], g.yAxisRanges());
}
};
if (context.isZooming) {
context.dragEndX = null;
context.dragEndY = null;
+ g.clearZoomRect_();
}
},
},
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);
+ context.dragEndX = Dygraph.dragGetX_(event, context);
+ context.dragEndY = Dygraph.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);