X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=plugins%2Faxes.js;h=1f9c256ca2d6c94ac5835644c78b2b69fe9df646;hb=6814f34bd42b51019b3adb525ca3ce71f1f9fb63;hp=0c81759d51b4d8ab8a658e8457d37540dd8cbeaf;hpb=f8540c66c5b87d5e88d31a800dc7af237bf01213;p=dygraphs.git diff --git a/plugins/axes.js b/plugins/axes.js index 0c81759..1f9c256 100644 --- a/plugins/axes.js +++ b/plugins/axes.js @@ -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 }; }; @@ -82,9 +84,9 @@ axes.prototype.detachLabels = function() { axes.prototype.clearChart = function(e) { var g = e.dygraph; 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) { @@ -266,7 +270,7 @@ axes.prototype.drawChart = function(e) { } context.restore(); -} +}; return axes; })();