Commit 82eebf64 by Torkel Ödegaard

fix(graph): Fix so that zoom works even when no data exists, fixes #5570

parent cc5c4511
...@@ -94,11 +94,11 @@ The plugin allso adds the following methods to the plot object: ...@@ -94,11 +94,11 @@ The plugin allso adds the following methods to the plot object:
var savedhandlers = {}; var savedhandlers = {};
var mouseUpHandler = null; var mouseUpHandler = null;
function onMouseMove(e) { function onMouseMove(e) {
if (selection.active) { if (selection.active) {
updateSelection(e); updateSelection(e);
plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]); plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]);
} }
} }
...@@ -106,7 +106,7 @@ The plugin allso adds the following methods to the plot object: ...@@ -106,7 +106,7 @@ The plugin allso adds the following methods to the plot object:
function onMouseDown(e) { function onMouseDown(e) {
if (e.which != 1) // only accept left-click if (e.which != 1) // only accept left-click
return; return;
// cancel out any text selections // cancel out any text selections
document.body.focus(); document.body.focus();
...@@ -127,13 +127,13 @@ The plugin allso adds the following methods to the plot object: ...@@ -127,13 +127,13 @@ The plugin allso adds the following methods to the plot object:
// this is a bit silly, but we have to use a closure to be // this is a bit silly, but we have to use a closure to be
// able to whack the same handler again // able to whack the same handler again
mouseUpHandler = function (e) { onMouseUp(e); }; mouseUpHandler = function (e) { onMouseUp(e); };
$(document).one("mouseup", mouseUpHandler); $(document).one("mouseup", mouseUpHandler);
} }
function onMouseUp(e) { function onMouseUp(e) {
mouseUpHandler = null; mouseUpHandler = null;
// revert drag stuff for old-school browsers // revert drag stuff for old-school browsers
if (document.onselectstart !== undefined) if (document.onselectstart !== undefined)
document.onselectstart = savedhandlers.onselectstart; document.onselectstart = savedhandlers.onselectstart;
...@@ -158,13 +158,22 @@ The plugin allso adds the following methods to the plot object: ...@@ -158,13 +158,22 @@ The plugin allso adds the following methods to the plot object:
function getSelection() { function getSelection() {
if (!selectionIsSane()) if (!selectionIsSane())
return null; return null;
if (!selection.show) return null; if (!selection.show) return null;
var r = {}, c1 = selection.first, c2 = selection.second; var r = {}, c1 = selection.first, c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) { var axes = plot.getAxes();
if (axis.used) { // look if no axis is used
var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]); var noAxisInUse = true;
$.each(axes, function (name, axis) {
if (axis.used) {
anyUsed = false;
}
})
$.each(axes, function (name, axis) {
if (axis.used || noAxisInUse) {
var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]);
r[name] = { from: Math.min(p1, p2), to: Math.max(p1, p2) }; r[name] = { from: Math.min(p1, p2), to: Math.max(p1, p2) };
} }
}); });
...@@ -252,10 +261,10 @@ The plugin allso adds the following methods to the plot object: ...@@ -252,10 +261,10 @@ The plugin allso adds the following methods to the plot object:
from = to; from = to;
to = tmp; to = tmp;
} }
return { from: from, to: to, axis: axis }; return { from: from, to: to, axis: axis };
} }
function setSelection(ranges, preventEvent) { function setSelection(ranges, preventEvent) {
var axis, range, o = plot.getOptions(); var axis, range, o = plot.getOptions();
...@@ -333,11 +342,11 @@ The plugin allso adds the following methods to the plot object: ...@@ -333,11 +342,11 @@ The plugin allso adds the following methods to the plot object:
ctx.restore(); ctx.restore();
} }
}); });
plot.hooks.shutdown.push(function (plot, eventHolder) { plot.hooks.shutdown.push(function (plot, eventHolder) {
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown); eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler) if (mouseUpHandler)
$(document).unbind("mouseup", mouseUpHandler); $(document).unbind("mouseup", mouseUpHandler);
}); });
......
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