context.isPanning = true;
var xRange = g.xAxisRange();
context.dateRange = xRange[1] - xRange[0];
+ context.initialLeftmostDate = xRange[0];
+ context.xUnitsPerPixel = context.dateRange / (g.plotter_.area.w - 1);
// 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.
for (var i = 0; i < g.axes_.length; i++) {
var axis = g.axes_[i];
var yRange = g.yAxisRange(i);
+ // TODO(konigsberg): These values should be in |context|.
axis.dragValueRange = yRange[1] - yRange[0];
- var r = g.toDataCoords(null, context.dragStartY, i);
- axis.draggingValue = r[1];
+ axis.initialTopValue = yRange[1];
+ axis.unitsPerPixel = axis.dragValueRange / (g.plotter_.area.h - 1);
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
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 minDate = context.initialLeftmostDate -
+ (context.dragEndX - context.dragStartX) * context.xUnitsPerPixel;
var maxDate = minDate + context.dateRange;
g.dateWindow_ = [minDate, maxDate];
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 maxValue = axis.initialTopValue +
+ (context.dragEndY - context.dragStartY) * axis.unitsPerPixel;
var minValue = maxValue - axis.dragValueRange;
axis.valueWindow = [ minValue, maxValue ];
}
// panning behavior.
//
Dygraph.endPan = function(event, g, context) {
+ // TODO(konigsberg): Clear the context data from the axis.
+ // TODO(konigsberg): mouseup should just delete the
+ // context object, and mousedown should create a new one.
context.isPanning = false;
context.is2DPan = false;
- context.draggingDate = null;
+ context.initialLeftmostDate = null;
context.dateRange = null;
context.valueRange = null;
}
prevEndY: null,
prevDragDirection: null,
- // TODO(danvk): update this comment
- // draggingDate and draggingValue represent the [date,value] point on the
- // graph at which the mouse was pressed. As the mouse moves while panning,
- // the viewport must pan so that the mouse position points to
- // [draggingDate, draggingValue]
- draggingDate: null,
+ // The value on the left side of the graph when a pan operation starts.
+ initialLeftmostDate: null,
+
+ // The number of units each pixel spans. (This won't be valid for log
+ // scales)
+ xUnitsPerPixel: null,
// TODO(danvk): update this comment
// The range in second/value units that the viewport encompasses during a