Commit 7331dc2f authored by olau@iola.dk's avatar olau@iola.dk

Base zoom out on current mouse position rather than a one-level undo


git-svn-id: https://flot.googlecode.com/svn/trunk@192 1e0a6537-2640-0410-bfb7-f154510ff394
parent 689daa1f
...@@ -15,7 +15,7 @@ Example usage: ...@@ -15,7 +15,7 @@ Example usage:
plot.zoom({ center: { left: 10, top: 20 } }); plot.zoom({ center: { left: 10, top: 20 } });
// zoom out again // zoom out again
plot.zoomOut(); plot.zoomOut({ center: { left: 10, top: 20 } });
// pan 100 pixels to the left and 20 down // pan 100 pixels to the left and 20 down
plot.pan({ left: -100, top: 20 }) plot.pan({ left: -100, top: 20 })
...@@ -97,25 +97,23 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -97,25 +97,23 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
}; };
function init(plot) { function init(plot) {
var prevPoint = null;
function bindEvents(plot, eventHolder) { function bindEvents(plot, eventHolder) {
var o = plot.getOptions(); var o = plot.getOptions();
if (o.zoom.interactive) { if (o.zoom.interactive) {
function clickHandler(e) { function clickHandler(e, zoomOut) {
prevPoint = plot.offset(); var c = plot.offset();
prevPoint.left = e.pageX - prevPoint.left; c.left = e.pageX - c.left;
prevPoint.top = e.pageY - prevPoint.top; c.top = e.pageY - c.top;
plot.zoom({ center: prevPoint }); if (zoomOut)
plot.zoomOut({ center: c });
else
plot.zoom({ center: c });
} }
eventHolder[o.zoom.trigger](clickHandler); eventHolder[o.zoom.trigger](clickHandler);
eventHolder.mousewheel(function (e, delta) { eventHolder.mousewheel(function (e, delta) {
if (delta > 0) clickHandler(e, delta < 0);
clickHandler(e);
else
plot.zoomOut();
}); });
} }
if (o.pan.interactive) { if (o.pan.interactive) {
...@@ -141,15 +139,18 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -141,15 +139,18 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
} }
} }
plot.zoomOut = function () { plot.zoomOut = function (args) {
plot.zoom({ amount: 1 / plot.getOptions().zoom.amount }); if (!args.amount)
prevPoint = null; args.amount = plot.getOptions().zoom.amount
args.amount = 1 / args.amount;
plot.zoom(args);
} }
plot.zoom = function (args) { plot.zoom = function (args) {
var axes = plot.getAxes(), var axes = plot.getAxes(),
options = plot.getOptions(), options = plot.getOptions(),
c = args.center ? args.center : prevPoint, c = args.center,
amount = args.amount ? args.amount : options.zoom.amount, amount = args.amount ? args.amount : options.zoom.amount,
w = plot.width(), h = plot.height(); w = plot.width(), h = plot.height();
...@@ -259,6 +260,6 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -259,6 +260,6 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
init: init, init: init,
options: options, options: options,
name: 'navigate', name: 'navigate',
version: '1.0' version: '1.1'
}); });
})(jQuery); })(jQuery);
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