-// Copyright 2011 Robert Konigsberg (konigsberg@google.com)
-// All Rights Reserved.
+/**
+ * @license
+ * Copyright 2011 Robert Konigsberg (konigsberg@google.com)
+ * MIT-licensed (http://opensource.org/licenses/MIT)
+ */
-/**
+/**
* @fileoverview The default interaction model for Dygraphs. This is kept out
* of dygraph.js for better navigability.
* @author Robert Konigsberg (konigsberg@google.com)
*/
+/*jshint globalstrict: true */
+/*global Dygraph:false */
+"use strict";
/**
* A collection of functions to facilitate build custom interaction models.
* dragStartX/dragStartY/etc. properties). This function modifies the context.
*/
Dygraph.Interaction.startPan = function(event, g, context) {
+ var i, axis;
context.isPanning = true;
var xRange = g.xAxisRange();
context.dateRange = xRange[1] - xRange[0];
var boundedValues = [];
var maxYPixelsToDraw = g.height_ * g.attr_("panEdgeFraction");
- for (var i = 0; i < g.axes_.length; i++) {
- var axis = g.axes_[i];
+ for (i = 0; i < g.axes_.length; i++) {
+ axis = g.axes_[i];
var yExtremes = axis.extremeRange;
var boundedTopY = g.toDomYCoord(yExtremes[0], i) + maxYPixelsToDraw;
// 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];
+ for (i = 0; i < g.axes_.length; i++) {
+ axis = g.axes_[i];
var yRange = g.yAxisRange(i);
// TODO(konigsberg): These values should be in |context|.
// In log scale, initialTopValue, dragValueRange and unitsPerPixel are log scale.
var pixelsDragged = context.dragEndY - context.dragStartY;
var unitsDragged = pixelsDragged * axis.unitsPerPixel;
-
+
var boundedValue = context.boundedValues ? context.boundedValues[i] : null;
// In log scale, maxValue and minValue are the logs of those values.
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
if (regionWidth < 2 && regionHeight < 2 &&
- g.lastx_ != undefined && g.lastx_ != -1) {
+ g.lastx_ !== undefined && g.lastx_ != -1) {
Dygraph.Interaction.treatMouseOpAsClick(g, event, context);
}
var p = g.selPoints_[i];
var distance = Math.pow(p.canvasx - context.dragEndX, 2) +
Math.pow(p.canvasy - context.dragEndY, 2);
- if (closestIdx == -1 || distance < closestDistance) {
+ if (!isNaN(distance) &&
+ (closestIdx == -1 || distance < closestDistance)) {
closestDistance = distance;
closestIdx = i;
}
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
if (regionWidth < 2 && regionHeight < 2 &&
- g.lastx_ != undefined && g.lastx_ != -1) {
+ g.lastx_ !== undefined && g.lastx_ != -1) {
Dygraph.Interaction.treatMouseOpAsClick(g, event, context);
}
g.doZoomY_(Math.min(context.dragStartY, context.dragEndY),
Math.max(context.dragStartY, context.dragEndY));
} else {
- g.canvas_ctx_.clearRect(0, 0, g.canvas_.width, g.canvas_.height);
+ g.clearZoomRect_();
}
context.dragStartX = null;
context.dragStartY = null;
Dygraph.movePan = Dygraph.Interaction.movePan;
Dygraph.startPan = Dygraph.Interaction.startPan;
+Dygraph.Interaction.nonInteractiveModel_ = {
+ mousedown: function(event, g, context) {
+ context.initializeMouseDown(event, g, context);
+ },
+ 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);
+ var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
+ var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
+
+ if (regionWidth < 2 && regionHeight < 2 &&
+ g.lastx_ !== undefined && g.lastx_ != -1) {
+ Dygraph.Interaction.treatMouseOpAsClick(g, event, context);
+ }
+ }
+};