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