Various fixes/workarounds for IE7/IE8 and some fixes/tweaks of range selector
[dygraphs.git] / dygraph-interaction-model.js
index 42f0eaf..06655f1 100644 (file)
@@ -1,7 +1,10 @@
-// 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)
@@ -126,7 +129,7 @@ Dygraph.Interaction.movePan = function(event, g, context) {
 
       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.
@@ -319,7 +322,7 @@ Dygraph.Interaction.endZoom = function(event, g, 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;
@@ -393,3 +396,20 @@ Dygraph.endPan = Dygraph.Interaction.endPan;
 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);
+    }
+  }
+};