From 82eebf64b6b8f62a52398c067ef31ec93c28c309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 13 Jul 2016 10:02:53 +0200 Subject: [PATCH] fix(graph): Fix so that zoom works even when no data exists, fixes #5570 --- public/vendor/flot/jquery.flot.selection.js | 35 +++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/public/vendor/flot/jquery.flot.selection.js b/public/vendor/flot/jquery.flot.selection.js index f8fa668ff4f..b7993d92ee3 100644 --- a/public/vendor/flot/jquery.flot.selection.js +++ b/public/vendor/flot/jquery.flot.selection.js @@ -94,11 +94,11 @@ The plugin allso adds the following methods to the plot object: var savedhandlers = {}; var mouseUpHandler = null; - + function onMouseMove(e) { if (selection.active) { updateSelection(e); - + plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]); } } @@ -106,7 +106,7 @@ The plugin allso adds the following methods to the plot object: function onMouseDown(e) { if (e.which != 1) // only accept left-click return; - + // cancel out any text selections document.body.focus(); @@ -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 // able to whack the same handler again mouseUpHandler = function (e) { onMouseUp(e); }; - + $(document).one("mouseup", mouseUpHandler); } function onMouseUp(e) { mouseUpHandler = null; - + // revert drag stuff for old-school browsers if (document.onselectstart !== undefined) document.onselectstart = savedhandlers.onselectstart; @@ -158,13 +158,22 @@ The plugin allso adds the following methods to the plot object: function getSelection() { if (!selectionIsSane()) return null; - + if (!selection.show) return null; var r = {}, c1 = selection.first, c2 = selection.second; - $.each(plot.getAxes(), function (name, axis) { - if (axis.used) { - var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]); + var axes = plot.getAxes(); + // look if no axis is used + 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) }; } }); @@ -252,10 +261,10 @@ The plugin allso adds the following methods to the plot object: from = to; to = tmp; } - + return { from: from, to: to, axis: axis }; } - + function setSelection(ranges, preventEvent) { var axis, range, o = plot.getOptions(); @@ -333,11 +342,11 @@ The plugin allso adds the following methods to the plot object: ctx.restore(); } }); - + plot.hooks.shutdown.push(function (plot, eventHolder) { eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousedown", onMouseDown); - + if (mouseUpHandler) $(document).unbind("mouseup", mouseUpHandler); });