diff --git a/API.txt b/API.txt index 2809799..d744532 100644 --- a/API.txt +++ b/API.txt @@ -621,6 +621,9 @@ making the selection. A "plotselecting" event is fired during the process with the same parameters as the "plotselected" event, in case you want to know what's happening while it's happening, +A "plotunselected" event with no arguments is emitted when the user +clicks the mouse to remove the selection. + Customizing the crosshair ========================= @@ -676,9 +679,10 @@ can call: "plotselected" handler, pass true as the second parameter. - - clearSelection() + - clearSelection(preventEvent) - Clear the selection rectangle. + Clear the selection rectangle. Pass in true to avoid getting a + "plotunselected" event. - setCrosshair(pos) diff --git a/NEWS.txt b/NEWS.txt index 0085cc8..23f3bd5 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -25,12 +25,16 @@ Changes: $.plot.formatDate(...) (suggestion by Matt Manela) and even replaced. -- Added "borderColor" option to the grid (patch from Amaury Chamayoau +- Added "borderColor" option to the grid (patch from Amaury Chamayou and patch from Mike R. Williamson). - Added support for gradient background for the grid, take a look at the "setting options" example (based on patch from Amaury Chamayou, issue 90). + +- Added a "plotunselected" event which is triggered when the selection + is removed, see "selection" example (suggestion by Meda Ugo); + Bug fixes: diff --git a/examples/selection.html b/examples/selection.html index 4a745d7..944dc49 100644 --- a/examples/selection.html +++ b/examples/selection.html @@ -90,6 +90,10 @@ $(function () { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to } })); }); + + placeholder.bind("plotunselected", function (event) { + $("#selection").text(""); + }); var plot = $.plot(placeholder, data, options); diff --git a/jquery.flot.js b/jquery.flot.js index d628cab..3880821 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -1934,9 +1934,11 @@ triggerSelectedEvent(); clickIsMouseUp = true; } - else + else { // this counts as a clear + target.trigger("plotunselected", [ ]); target.trigger("plotselecting", [ null ]); + } return false; } @@ -1969,13 +1971,15 @@ triggerRedrawOverlay(); } else - clearSelection(); + clearSelection(true); } - function clearSelection() { + function clearSelection(preventEvent) { if (selection.show) { selection.show = false; triggerRedrawOverlay(); + if (!preventEvent) + target.trigger("plotunselected", [ ]); } }