(function(P){function Sc(){function n(c,e){c.attr("transform",function(c){return"translate("+(e(c)+aa)+", 0)"})}function t(c,e){c.attr("transform",function(c){return"translate(0,"+e(c)+")"})}function P(c){var e=c[0];c=c[c.length-1];return ea?0:a}function ec(a){return qa&&a===qa||X&&hd(X,a)}function id(a){return!ec(a)}function eb(a){var b=Ja[a.id];a.name=n(b)?b:a.id;return a}function fc(a){var b=a[0],d={},f=[],u,c;for(u=1;u v[d].indexOf(c.id)))for(f=0;fb?a-b:0};return function(a){var c=b?S(a.id):E(a.id);return d(c(a.value))}}function Na(a,b){var d=t(a)?fb():a;"string"===typeof d&&(d=[d]);for(var f=0;f=e;e+=s)h+=f(a[c-1],a[c],e,l)}return h}function Db(a){var b,d;hb=c.select(wa);if(hb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{hb.html("");h.data.x={};h.data.targets=Ka(a);Gc&&Na(fb().filter(function(a){return!(a in O)}),Gc);ua();Mb();m.domain(c.extent(Va()));w.domain(ka("y"));U.domain(ka("y2"));da.domain(m.domain()); Za.domain(w.domain());$a.domain(U.domain());B.ticks(10>a.length?a.length:10);na.ticks(ud).outerTickSize(0).tickFormat(vd);ab.ticks(wd).outerTickSize(0).tickFormat(xd);V=m.domain();G.x(da);ra&&C.x(m);Pa=c.select(wa).append("svg").attr("width",q+A+ca).attr("height",p+s+F).on("mouseenter",yd).on("mouseleave",zd);ib=Pa.append("defs");ib.append("clipPath").attr("id",Eb).append("rect").attr("y",s).attr("width",q).attr("height",p-s);ib.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1- A).attr("y",-20).attr("width",R).attr("height",Q);ib.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-A+1).attr("y",s-1).attr("width",ja).attr("height",nb);k=Pa.append("g").attr("transform",J.main);x=ya?Pa.append("g").attr("transform",J.context):null;za=Aa?Pa.append("g").attr("transform",J.legend):null;N=c.select(wa).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");k.append("g").attr("class","x axis").attr("clip-path", g?"":"url(#xaxis-clip)").attr("transform",J.x).call(g?na:B).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(Ad);k.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?B:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Bd);Tb&&k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(ab);b=k.append("g").attr("clip-path",Qa).attr("class", "grid");Hc&&b.append("g").attr("class","xgrids");Fb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Fb).enter().append("g").attr("class","xgrid-line"),d.append("line").attr("class",function(a){return""+a["class"]}),d.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-s).attr("dy",-6).text(function(a){return a.text}));Cd&&b.append("g").attr("class","xgrid-focus").append("line").attr("class", "xgrid-focus").attr("x1",g?0:-10).attr("x2",g?q:-10).attr("y1",g?-10:s).attr("y2",g?-10:p);Ic&&b.append("g").attr("class","ygrids");Gb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Gb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Qa).attr("class","regions");k.append("g").attr("clip-path",Qa).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor", ra?"ew-resize":null);X?Dd(b):Ed(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");if(ra)k.insert("rect",Fd?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",p).style("opacity",0).style("cursor","ew-resize").call(C).on("dblclick.zoom",null);null!==jb&&G.extent("function"!==typeof jb?jb:jb(ea,oa));ya&&(x.append("g").attr("clip-path",Qa).attr("class","chart"),x.select(".chart").append("g").attr("class","chart-bars"), x.select(".chart").append("g").attr("class","chart-lines"),x.append("g").attr("clip-path",Qa).attr("class","x brush").call(G).selectAll("rect").attr("height",ma),x.append("g").attr("class","x axis").attr("transform",J.subx).call(Ea));Aa&&kb(h.data.targets);Jc(h.data.targets);z({withTransition:!1,withUpdateXDomain:!0});if(Gd){if(r&&"string"===typeof Ba){Ba=pa(Ba);for(a=0;awb(d,a)?c.select(".event-rect").style("cursor","pointer"):c.select(".event-rect").style("cursor", null))}).on("click",function(){var a=c.mouse(this),d=oc(h.data.targets,a);100>wb(d,a)&&k.select(".-circles-"+d.id).select(".-circle-"+d.index).each(function(){Lc(this,d,d.index)})}).call(c.behavior.drag().origin(Object).on("drag",function(){Mc(c.mouse(this))}).on("dragstart",function(){Nc(c.mouse(this))}).on("dragend",function(){Oc()})).call(C).on("dblclick.zoom",null)}function Lc(a,b,d){var f=c.select(a),e=f.classed(ia),g=!1,h;"circle"===a.nodeName?(g=xc(a,1.5*Oa),h=Ac):"rect"===a.nodeName&&(g=yc(a), h=Cc);if(sa||g)ha&&ta(b)&&(f.classed(ia,!e),h(!e,f,b,d)),Id(b,f)}function Mc(a){if(ha&&(!ra||C.altDomain)){var b=Kb[0],d=Kb[1],f=a[0];a=a[1];var e=Math.min(b,f),g=Math.max(b,f),h=sa?s:Math.min(d,a),m=sa?p:Math.max(d,a);k.select(".dragarea").attr("x",e).attr("y",h).attr("width",g-e).attr("height",m-h);k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ta(a)}).each(function(a,b){var d=c.select(this),f=d.classed(ia),k=d.classed(Lb),l,n,p,q;l=!1;"circle"===this.nodeName?(l=1*d.attr("cx"), n=1*d.attr("cy"),q=Ac,l=e", d,c,e;for(d=0;d"+e+""+c+"";return b+""}),Gd=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Kc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Eb=wa.replace("#","")+"-clip",Qa="url(#"+Eb+")",r="timeseries"===Rc,W="categorized"=== Rc,tb=!r&&(qa||X),Kb=null,Ra=!1,Jb=!1,la=Aa?40:0,Y=function(a,b){var d=[],c=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===d.indexOf(b)&&d.push(b);return c[d.indexOf(b)%c.length]}}(Od,Pd),$c=function(){var a=[[c.time.format("%Y/%-m/%-d"),function(){return!0}],[c.time.format("%-m/%-d"),function(a){return a.getMonth()}],[c.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[c.time.format("%-m/%-d"), function(a){return a.getDay()&&1!==a.getDate()}],[c.time.format("%I %p"),function(a){return a.getHours()}],[c.time.format("%I:%M"),function(a){return a.getMinutes()}],[c.time.format(":%S"),function(a){return a.getSeconds()}],[c.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,e=a[c];!e[1](b);)e=a[--c];return e[0](b)}}(),Pb,Wb,Rb,Ya,Vb,Xb,q,p,ma,ob,va,Zb,$b,rb,sb,m,w,U,da,Za,$a,B,na,ab,Ea,Vc=g?"left":"bottom",Wc=g?qb?"top":"bottom":qb?"right":"left", Xc=g?pb?"bottom":"top":pb?"left":"right",Yc="bottom",J={main:function(){return"translate("+A+","+s+")"},context:function(){return"translate("+l+","+Ca+")"},legend:function(){return"translate("+Ob+","+Nb+")"},y2:function(){return"translate("+(g?0:q)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+ma+")"}},Kd=function(){var a=c.svg.line().x(g?function(a){return E(a.id)(a.value)}:gb).y(g?gb:function(a){return E(a.id)(a.value)});return function(b){var c= Dc(b.values),e;if(xb(b))return"spline"===O["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),Qc[b.id]?td(c,m,E(b.id),Qc[b.id]):a(c);e=m(c[0].x);b=E(b.id)(c[0].value);return g?"M "+b+" "+e:"M "+e+" "+b}}(),Ld=function(){var a=c.svg.line().x(function(a){return da(a.x)}).y(function(a){return S(a.id)(a.value)});return function(b){var c=Dc(b.values);return xb(b)?a(c):"M "+da(c[0].x)+" "+S(b.id)(c[0].value)}}(),G=c.svg.brush().on("brush",function(){z({withTransition:!1,withY:!1, withSubchart:!1,withUpdateXDomain:!0})}),C=c.behavior.zoom().on("zoomstart",function(){C.altDomain=c.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ra?Md:null);G.update=function(){x&&x.select(".x.brush").call(this);return this};C.orgScaleExtent=function(){var a=Pc?Pc:[1,10];return[a[0],Math.max(La()/a[1],a[1])]};C.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(V[1]-V[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var Pa,ib,k,x,za,N,hb,ea=null, oa=null,V;h.focus=function(a){h.defocus();c.selectAll(Ua(a)).filter(function(a){return ub(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){c.selectAll(Ua(a)).filter(function(a){return ub(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){c.selectAll(Ua(a)).filter(function(a){return ub(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){c.selectAll(Ua(a)).transition().style("opacity", 1)};h.hide=function(a){c.selectAll(Ua(a)).transition().style("opacity",0)};h.unzoom=function(){G.clear().update();z({withUpdateXDomain:!0})};h.load=function(a){t(a.done)&&(a.done=function(){});"categories"in a&&W&&(Fa=a.categories,B.categories(Fa));if("cacheIds"in a&&Wa(a.cacheIds))Sa(mb(a.cacheIds),a.done);else if("data"in a)Sa(Ka(a.data),a.done);else if("url"in a)c.csv(a.url,function(b,c){Sa(Ka(c),a.done)});else if("rows"in a)Sa(Ka(fc(a.rows)),a.done);else if("columns"in a)Sa(Ka(gc(a.columns)), a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});c.selectAll(".target-"+a).transition().style("opacity",0).remove();Aa&&(c.selectAll(".legend-item-"+a).remove(),kb(h.data.targets));0b.classes.indexOf(a)})});return K};h.data.get=function(a){a=h.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=cb(function(b){return b.id===a});return 0