!function(e){e.plot.plugins.push({init:function(t){function o(e){f.active&&(l(e),t.getPlaceholder().trigger("plotselecting",[i()]))}function n(o){1==o.which&&(document.body.focus(),void 0!==document.onselectstart&&null==g.onselectstart&&(g.onselectstart=document.onselectstart,document.onselectstart=function(){return!1}),void 0!==document.ondrag&&null==g.ondrag&&(g.ondrag=document.ondrag,document.ondrag=function(){return!1}),c(f.first,o),f.active=!0,h=function(e){!function(e){h=null,void 0!==document.onselectstart&&(document.onselectstart=g.onselectstart),void 0!==document.ondrag&&(document.ondrag=g.ondrag),f.active=!1,l(e),u()?s():(t.getPlaceholder().trigger("plotunselected",[]),t.getPlaceholder().trigger("plotselecting",[null]))}(e)},e(document).one("mouseup",h))}function i(){if(!u())return null;var o={},n=f.first,i=f.second;return e.each(t.getAxes(),function(e,t){if(t.used){var s=t.c2p(n[t.direction]),r=t.c2p(i[t.direction]);o[e]={from:Math.min(s,r),to:Math.max(s,r)}}}),o}function s(){var e=i();t.getPlaceholder().trigger("plotselected",[e]),e.xaxis&&e.yaxis&&t.getPlaceholder().trigger("selected",[{x1:e.xaxis.from,y1:e.yaxis.from,x2:e.xaxis.to,y2:e.yaxis.to}])}function r(e,t,o){return t<e?e:t>o?o:t}function c(e,o){var n=t.getOptions(),i=t.getPlaceholder().offset(),s=t.getPlotOffset();e.x=r(0,o.pageX-i.left-s.left,t.width()),e.y=r(0,o.pageY-i.top-s.top,t.height()),"y"==n.selection.mode&&(e.x=e==f.first?0:t.width()),"x"==n.selection.mode&&(e.y=e==f.first?0:t.height())}function l(e){null!=e.pageX&&(c(f.second,e),u()?(f.show=!0,t.triggerRedrawOverlay()):a(!0))}function a(e){f.show&&(f.show=!1,t.triggerRedrawOverlay(),e||t.getPlaceholder().trigger("plotunselected",[]))}function d(e,o){var n,i,s,r,c=t.getAxes();for(var l in c)if((n=c[l]).direction==o&&(r=o+n.n+"axis",e[r]||1!=n.n||(r=o+"axis"),e[r])){i=e[r].from,s=e[r].to;break}if(e[r]||(n="x"==o?t.getXAxes()[0]:t.getYAxes()[0],i=e[o+"1"],s=e[o+"2"]),null!=i&&null!=s&&i>s){var a=i;i=s,s=a}return{from:i,to:s,axis:n}}function u(){return Math.abs(f.second.x-f.first.x)>=5&&Math.abs(f.second.y-f.first.y)>=5}var f={first:{x:-1,y:-1},second:{x:-1,y:-1},show:!1,active:!1},g={},h=null;t.clearSelection=a,t.setSelection=function(e,o){var n,i=t.getOptions();"y"==i.selection.mode?(f.first.x=0,f.second.x=t.width()):(n=d(e,"x"),f.first.x=n.axis.p2c(n.from),f.second.x=n.axis.p2c(n.to)),"x"==i.selection.mode?(f.first.y=0,f.second.y=t.height()):(n=d(e,"y"),f.first.y=n.axis.p2c(n.from),f.second.y=n.axis.p2c(n.to)),f.show=!0,t.triggerRedrawOverlay(),!o&&u()&&s()},t.getSelection=i,t.hooks.bindEvents.push(function(e,t){null!=e.getOptions().selection.mode&&(t.mousemove(o),t.mousedown(n))}),t.hooks.drawOverlay.push(function(t,o){if(f.show&&u()){var n=t.getPlotOffset(),i=t.getOptions();o.save(),o.translate(n.left,n.top);var s=e.color.parse(i.selection.color);o.strokeStyle=s.scale("a",.8).toString(),o.lineWidth=1,o.lineJoin="round",o.fillStyle=s.scale("a",.4).toString();var r=Math.min(f.first.x,f.second.x),c=Math.min(f.first.y,f.second.y),l=Math.abs(f.second.x-f.first.x),a=Math.abs(f.second.y-f.first.y);o.fillRect(r,c,l,a),o.strokeRect(r,c,l,a),o.restore()}}),t.hooks.shutdown.push(function(t,i){i.unbind("mousemove",o),i.unbind("mousedown",n),h&&e(document).unbind("mouseup",h)})},options:{selection:{mode:null,color:"#e8cfac"}},name:"selection",version:"1.1"})}(jQuery);