+// Called in response to an interaction model operation that
+// should start the default panning behavior.
+//
+// It's used in the default callback for "mousedown" operations.
+// Custom interaction model builders can use it to provide the default
+// panning behavior.
+//
+Dygraph.startPan = function(event, g, context) {
+ context.isPanning = true;
+ var xRange = g.xAxisRange();
+ context.dateRange = xRange[1] - xRange[0];
+
+ // Record the range of each y-axis at the start of the drag.
+ // If any axis has a valueRange or valueWindow, then we want a 2D pan.
+ context.is2DPan = false;
+ for (var i = 0; i < g.axes_.length; i++) {
+ var axis = g.axes_[i];
+ var yRange = g.yAxisRange(i);
+ axis.dragValueRange = yRange[1] - yRange[0];
+ axis.draggingValue = g.toDataYCoord(context.dragStartY, i);
+ if (axis.valueWindow || axis.valueRange) context.is2DPan = true;
+ }
+
+ // TODO(konigsberg): Switch from all this math to toDataCoords?
+ // Seems to work for the dragging value.
+ context.draggingDate = (context.dragStartX / g.width_) * context.dateRange + xRange[0];
+};
+
+// Called in response to an interaction model operation that
+// responds to an event that pans the view.
+//
+// It's used in the default callback for "mousemove" operations.
+// Custom interaction model builders can use it to provide the default
+// panning behavior.
+//
+Dygraph.movePan = function(event, g, context) {
+ context.dragEndX = g.dragGetX_(event, context);
+ context.dragEndY = g.dragGetY_(event, context);
+
+ // TODO(danvk): update this comment
+ // Want to have it so that:
+ // 1. draggingDate appears at dragEndX, draggingValue appears at dragEndY.
+ // 2. daterange = (dateWindow_[1] - dateWindow_[0]) is unaltered.
+ // 3. draggingValue appears at dragEndY.
+ // 4. valueRange is unaltered.
+
+ var minDate = context.draggingDate - (context.dragEndX / g.width_) * context.dateRange;
+ var maxDate = minDate + context.dateRange;
+ g.dateWindow_ = [minDate, maxDate];
+
+ // y-axis scaling is automatic unless this is a full 2D pan.
+ if (context.is2DPan) {
+ // Adjust each axis appropriately.
+ // NOTE(konigsberg): I don't think this computation for y_frac is correct.
+ // I think it doesn't take into account the display of the x axis.
+ // See, when I tested this with console.log(y_frac), and move the mouse
+ // cursor to the botom, the largest y_frac was 0.94, and not 1.0. That
+ // could also explain why panning tends to start with a small jumpy shift.
+ var y_frac = context.dragEndY / g.height_;
+
+ for (var i = 0; i < g.axes_.length; i++) {
+ var axis = g.axes_[i];
+ var maxValue = axis.draggingValue + y_frac * axis.dragValueRange;
+ var minValue = maxValue - axis.dragValueRange;
+ axis.valueWindow = [ minValue, maxValue ];
+ }
+ }
+
+ g.drawGraph_();
+}