X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=plugins%2Faxes.js;h=cacda86e8d414e100144729a3ba4b1283f4622d7;hb=87f2fcd1862a6142c3535612a4679e6fc865baf4;hp=3c0b015383464b082fcc9033b6603df3ba71c695;hpb=b67b868cd8cab33adef1cc2967a3ad7566bbed18;p=dygraphs.git diff --git a/plugins/axes.js b/plugins/axes.js index 3c0b015..cacda86 100644 --- a/plugins/axes.js +++ b/plugins/axes.js @@ -4,6 +4,8 @@ * MIT-licensed (http://opensource.org/licenses/MIT) */ +/*global Dygraph:false */ + Dygraph.Plugins.Axes = (function() { "use strict"; @@ -52,23 +54,29 @@ axes.prototype.layout = function(e) { if (g.getOption('drawYAxis')) { var w = g.getOption('yAxisLabelWidth') + 2 * g.getOption('axisTickSize'); - var y_axis_rect = e.reserveSpaceLeft(w); + e.reserveSpaceLeft(w); } if (g.getOption('drawXAxis')) { var h; + // NOTE: I think this is probably broken now, since g.getOption() now + // hits the dictionary. (That is, g.getOption('xAxisHeight') now always + // has a value.) if (g.getOption('xAxisHeight')) { h = g.getOption('xAxisHeight'); } else { h = g.getOptionForAxis('axisLabelFontSize', 'x') + 2 * g.getOption('axisTickSize'); } - var x_axis_rect = e.reserveSpaceBottom(h); + e.reserveSpaceBottom(h); } if (g.numAxes() == 2) { - // TODO(danvk): per-axis setting. - var w = g.getOption('yAxisLabelWidth') + 2 * g.getOption('axisTickSize'); - var y2_axis_rect = e.reserveSpaceRight(w); + // TODO(danvk): introduce a 'drawAxis' per-axis property. + if (g.getOption('drawYAxis')) { + // TODO(danvk): per-axis setting. + var w = g.getOption('yAxisLabelWidth') + 2 * g.getOption('axisTickSize'); + e.reserveSpaceRight(w); + } } else if (g.numAxes() > 2) { g.error("Only two y-axes are supported at this time. (Trying " + "to use " + g.numAxes() + ")"); @@ -90,7 +98,6 @@ axes.prototype.detachLabels = function() { }; axes.prototype.clearChart = function(e) { - var g = e.dygraph; this.detachLabels(); }; @@ -120,17 +127,17 @@ axes.prototype.willDrawChart = function(e) { lineHeight: "normal", // Something other than "normal" line-height screws up label positioning. overflow: "hidden" }; - } + }; var labelStyles = { x : makeLabelStyle('x'), y : makeLabelStyle('y'), - y2 : makeLabelStyle('y2'), + y2 : makeLabelStyle('y2') }; var makeDiv = function(txt, axis, prec_axis) { /* - * This seems to be called with the following three sets of axis/perc_axis: + * This seems to be called with the following three sets of axis/prec_axis: * x: undefined * y: y1 * y: y2 @@ -221,7 +228,7 @@ axes.prototype.willDrawChart = function(e) { var axisX; if (g.getOption('drawAxesAtZero')) { var r = g.toPercentXCoord(0); - if (r > 1 || r < 0) r = 0; + if (r > 1 || r < 0 || isNaN(r)) r = 0; axisX = halfUp(area.x + r * area.w); } else { axisX = halfUp(area.x);