diff --git a/jquery.flot.js b/jquery.flot.js index e75907c..22573aa 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -175,22 +175,14 @@ }; plot.getAxes = function () { var res = {}, i; - for (i = 0; i < xaxes.length; ++i) - res["x" + (i ? (i + 1) : "") + "axis"] = xaxes[i] || {}; - for (i = 0; i < yaxes.length; ++i) - res["y" + (i ? (i + 1) : "") + "axis"] = yaxes[i] || {}; - - // backwards compatibility - to be removed - if (!res.x2axis) - res.x2axis = { n: 2 }; - if (!res.y2axis) - res.y2axis = { n: 2 }; - + $.each(xaxes.concat(yaxes), function (_, axis) { + if (axis) + res[axis.direction + (axis.n != 1 ? axis.n : "") + "axis"] = axis; + }); return res; }; plot.getXAxes = function () { return xaxes; }; plot.getYAxes = function () { return yaxes; }; - plot.getUsedAxes = getUsedAxes; // return flat array with x and y axes that are in use plot.c2p = canvasToAxisCoords; plot.p2c = axisToCanvasCoords; plot.getOptions = function () { return options; }; @@ -398,21 +390,6 @@ return res; } - function getUsedAxes() { - var res = [], i, axis; - for (i = 0; i < xaxes.length; ++i) { - axis = xaxes[i]; - if (axis && axis.used) - res.push(axis); - } - for (i = 0; i < yaxes.length; ++i) { - axis = yaxes[i]; - if (axis && axis.used) - res.push(axis); - } - return res; - } - function getOrCreateAxis(axes, number) { if (!axes[number - 1]) axes[number - 1] = { @@ -1383,9 +1360,8 @@ } function extractRange(ranges, coord) { - var axis, from, to, axes, key; + var axis, from, to, key, axes = allAxes(); - axes = getUsedAxes(); for (i = 0; i < axes.length; ++i) { axis = axes[i]; if (axis.direction == coord) { diff --git a/jquery.flot.navigate.js b/jquery.flot.navigate.js index e156280..fcb34e5 100644 --- a/jquery.flot.navigate.js +++ b/jquery.flot.navigate.js @@ -221,7 +221,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L } }; - $.each(plot.getUsedAxes(), function(i, axis) { + $.each(plot.getAxes(), function(_, axis) { var opts = axis.options, min = minmax[axis.direction].min, max = minmax[axis.direction].max, @@ -267,7 +267,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L if (isNaN(delta.y)) delta.y = 0; - $.each(plot.getUsedAxes(), function (i, axis) { + $.each(plot.getAxes(), function (_, axis) { var opts = axis.options, min, max, d = delta[axis.direction]; diff --git a/jquery.flot.selection.js b/jquery.flot.selection.js index 44f292d..8bfbbab 100644 --- a/jquery.flot.selection.js +++ b/jquery.flot.selection.js @@ -199,13 +199,12 @@ The plugin allso adds the following methods to the plot object: } } - // taken from markings support + // function taken from markings support in Flot function extractRange(ranges, coord) { - var axis, from, to, axes, key; + var axis, from, to, key, axes = plot.getAxes(); - axes = plot.getUsedAxes(); - for (i = 0; i < axes.length; ++i) { - axis = axes[i]; + for (var k in axes) { + axis = axes[k]; if (axis.direction == coord) { key = coord + axis.n + "axis"; if (!ranges[key] && axis.n == 1) @@ -235,7 +234,6 @@ The plugin allso adds the following methods to the plot object: return { from: from, to: to, axis: axis }; } - function setSelection(ranges, preventEvent) { var axis, range, o = plot.getOptions();