Commit 69a23e4d authored by olau@iola.dk's avatar olau@iola.dk

Support restricting navigate plugin to not pan/zoom an axis (based on patch by kkaefer)

git-svn-id: https://flot.googlecode.com/svn/trunk@297 1e0a6537-2640-0410-bfb7-f154510ff394
parent 4c0a2a49
...@@ -80,6 +80,8 @@ Changes: ...@@ -80,6 +80,8 @@ Changes:
changes size, e.g. on window resizes (sponsored by Novus Partners). changes size, e.g. on window resizes (sponsored by Novus Partners).
- Support Infinity/-Infinity for plotting asymptotes by hacking it - Support Infinity/-Infinity for plotting asymptotes by hacking it
into +/-Number.MAX_VALUE (reported by rabaea.mircea). into +/-Number.MAX_VALUE (reported by rabaea.mircea).
- Support restricting navigate plugin to not pan/zoom an axis (based
on patch by kkaefer).
- New hooks: drawSeries - New hooks: drawSeries
......
...@@ -21,8 +21,8 @@ Options: ...@@ -21,8 +21,8 @@ Options:
} }
xaxis, yaxis, x2axis, y2axis: { xaxis, yaxis, x2axis, y2axis: {
zoomRange: null // or [number, number] (min range, max range) zoomRange: null // or [number, number] (min range, max range) or false
panRange: null // or [number, number] (min, max) panRange: null // or [number, number] (min, max) or false
} }
"interactive" enables the built-in drag/click behaviour. If you enable "interactive" enables the built-in drag/click behaviour. If you enable
...@@ -40,11 +40,13 @@ mouse button is released). ...@@ -40,11 +40,13 @@ mouse button is released).
"zoomRange" is the interval in which zooming can happen, e.g. with "zoomRange" is the interval in which zooming can happen, e.g. with
zoomRange: [1, 100] the zoom will never scale the axis so that the zoomRange: [1, 100] the zoom will never scale the axis so that the
difference between min and max is smaller than 1 or larger than 100. difference between min and max is smaller than 1 or larger than 100.
You can set either end to null to ignore, e.g. [1, null]. You can set either end to null to ignore, e.g. [1, null]. If you set
zoomRange to false, zooming on that axis will be disabled.
"panRange" confines the panning to stay within a range, e.g. with "panRange" confines the panning to stay within a range, e.g. with
panRange: [-10, 20] panning stops at -10 in one end and at 20 in the panRange: [-10, 20] panning stops at -10 in one end and at 20 in the
other. Either can be null, e.g. [-10, null]. other. Either can be null, e.g. [-10, null]. If you set
panRange to false, panning on that axis will be disabled.
Example API usage: Example API usage:
...@@ -215,7 +217,11 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -215,7 +217,11 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
$.each(plot.getUsedAxes(), function(i, axis) { $.each(plot.getUsedAxes(), function(i, axis) {
var opts = axis.options, var opts = axis.options,
min = minmax[axis.direction].min, min = minmax[axis.direction].min,
max = minmax[axis.direction].max max = minmax[axis.direction].max,
zr = opts.zoomRange;
if (zr === false) // no zooming on this axis
return;
min = axis.c2p(min); min = axis.c2p(min);
max = axis.c2p(max); max = axis.c2p(max);
...@@ -226,7 +232,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -226,7 +232,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
max = tmp; max = tmp;
} }
var range = max - min, zr = opts.zoomRange; var range = max - min;
if (zr && if (zr &&
((zr[0] != null && range < zr[0]) || ((zr[0] != null && range < zr[0]) ||
(zr[1] != null && range > zr[1]))) (zr[1] != null && range > zr[1])))
...@@ -262,6 +268,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -262,6 +268,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
max = axis.c2p(axis.p2c(axis.max) + d); max = axis.c2p(axis.p2c(axis.max) + d);
var pr = opts.panRange; var pr = opts.panRange;
if (pr === false) // no panning on this axis
return;
if (pr) { if (pr) {
// check whether we hit the wall // check whether we hit the wall
if (pr[0] != null && pr[0] > min) { if (pr[0] != null && pr[0] > min) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment