add "use strict" to plugins -- was causing errors in dygraph-combined.js
[dygraphs.git] / plugins / axes.js
index 0c81759..88d2fc8 100644 (file)
@@ -6,6 +6,8 @@
 
 Dygraph.Plugins.Axes = (function() {
 
+"use strict";
+
 /*
 
 Bits of jankiness:
@@ -33,7 +35,7 @@ axes.prototype.activate = function(g) {
   return {
     layout: this.layout,
     clearChart: this.clearChart,
-    drawChart: this.drawChart
+    willDrawChart: this.willDrawChart
   };
 };
 
@@ -84,7 +86,7 @@ axes.prototype.clearChart = function(e) {
   this.detachLabels();
 }
 
-axes.prototype.drawChart = function(e) {
+axes.prototype.willDrawChart = function(e) {
   var g = e.dygraph;
   if (!g.getOption('drawXAxis') && !g.getOption('drawYAxis')) return;
   
@@ -94,6 +96,8 @@ axes.prototype.drawChart = function(e) {
 
   var context = e.drawingContext;
   var containerDiv = e.canvas.parentNode;
+  var canvasWidth = e.canvas.width;
+  var canvasHeight = e.canvas.height;
 
   var label, x, y, tick, i;
 
@@ -159,7 +163,7 @@ axes.prototype.drawChart = function(e) {
         var top = (y - g.getOption('axisLabelFontSize') / 2);
         if (top < 0) top = 0;
 
-        if (top + g.getOption('axisLabelFontSize') + 3 > this.height) {
+        if (top + g.getOption('axisLabelFontSize') + 3 > canvasHeight) {
           label.style.bottom = "0px";
         } else {
           label.style.top = top + "px";
@@ -183,7 +187,7 @@ axes.prototype.drawChart = function(e) {
       var bottomTick = this.ylabels_[0];
       var fontSize = g.getOption('axisLabelFontSize');
       var bottom = parseInt(bottomTick.style.top, 10) + fontSize;
-      if (bottom > this.height - fontSize) {
+      if (bottom > canvasHeight - fontSize) {
         bottomTick.style.top = (parseInt(bottomTick.style.top, 10) -
             fontSize / 2) + "px";
       }
@@ -192,7 +196,7 @@ axes.prototype.drawChart = function(e) {
     // draw a vertical line on the left to separate the chart from the labels.
     var axisX;
     if (g.getOption('drawAxesAtZero')) {
-      var r = this.dygraph_.toPercentXCoord(0);
+      var r = g.toPercentXCoord(0);
       if (r > 1 || r < 0) r = 0;
       axisX = halfUp(area.x + r * area.w);
     } else {
@@ -234,8 +238,8 @@ axes.prototype.drawChart = function(e) {
         label.style.top = (y + g.getOption('axisTickSize')) + 'px';
 
         var left = (x - g.getOption('axisLabelWidth')/2);
-        if (left + g.getOption('axisLabelWidth') > this.width) {
-          left = this.width - g.getOption('xAxisLabelWidth');
+        if (left + g.getOption('axisLabelWidth') > canvasWidth) {
+          left = canvasWidth - g.getOption('xAxisLabelWidth');
           label.style.textAlign = "right";
         }
         if (left < 0) {