Fix ghosting issues when viewing graphs with browser zoomed out. Closes #440.
authorGregory Jordan <gjordan@google.com>
Tue, 21 Oct 2014 17:24:41 +0000 (13:24 -0400)
committerGregory Jordan <gjordan@google.com>
Tue, 21 Oct 2014 17:31:07 +0000 (13:31 -0400)
dygraph-utils.js

index 63fc1e0..dc93023 100644 (file)
@@ -787,13 +787,20 @@ Dygraph.createCanvas = function() {
  */
 Dygraph.getContextPixelRatio = function(context) {
   try {
-    var devicePixelRatio = window.devicePixelRatio || 1,
-        backingStoreRatio = context.webkitBackingStorePixelRatio ||
+    var devicePixelRatio = window.devicePixelRatio;
+    var backingStoreRatio = context.webkitBackingStorePixelRatio ||
                             context.mozBackingStorePixelRatio ||
                             context.msBackingStorePixelRatio ||
                             context.oBackingStorePixelRatio ||
-                            context.backingStorePixelRatio || 1;
-    return devicePixelRatio / backingStoreRatio;
+                            context.backingStorePixelRatio;
+    if (devicePixelRatio !== undefined &&
+        backingStorePixelRatio !== undefined) {
+      return devicePixelRatio / backingStoreRatio;
+    } else {
+      // If either value is undefined, the ratio is meaningless so we want to
+      // return 1.
+      return 1;
+    }
   } catch (e) {
     return 1;
   }