(function(Q){function Kc(){function n(c,e){c.attr("transform",function(c){return"translate("+(e(c)+aa)+", 0)"})}function s(c,e){c.attr("transform",function(c){return"translate(0,"+e(c)+")"})}function Q(c){var e=c[0];c=c[c.length-1];return ea?0:a}function ac(a){return qa&&a===qa||X&&ad(X,a)}function bd(a){return!ac(a)}function eb(a){var b=Ka[a.id];a.name=n(b)?b:a.id;return a}function bc(a){var b=a[0],d={},f=[],c,e;for(c=1;ct[d].indexOf(c.id)))for(f=0;f=e;e+=r)h+=f(a[c-1],a[c],e,l)}return h}function Ab(a){var b,d;gb=c.select(wa);if(gb.empty())Q.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); else{gb.html("");h.data.x={};h.data.targets=La(a);ua();Jb();m.domain(c.extent([xa,Ma]));u.domain(la("y"));V.domain(la("y2"));da.domain(m.domain());Za.domain(u.domain());$a.domain(V.domain());z.ticks(10>a.length?a.length:10);oa.ticks(nd).outerTickSize(0).tickFormat(od);ab.ticks(pd).outerTickSize(0).tickFormat(qd);W=m.domain();G.x(da);ra&&B.x(m);Qa=c.select(wa).append("svg").attr("width",q+y+ca).attr("height",p+r+F).on("mouseenter",rd).on("mouseleave",sd);hb=Qa.append("defs");hb.append("clipPath").attr("id", Bb).append("rect").attr("y",r).attr("width",q).attr("height",p-r);hb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-y).attr("y",-20).attr("width",S).attr("height",R);hb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-y+1).attr("y",r-1).attr("width",ka).attr("height",mb);k=Qa.append("g").attr("transform",J.main);v=ya?Qa.append("g").attr("transform",J.context):null;za=Aa?Qa.append("g").attr("transform",J.legend):null;Y=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?oa:z).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(td);k.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?z:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(ud);Rb&& k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(ab);b=k.append("g").attr("clip-path",Ra).attr("class","grid");zc&&b.append("g").attr("class","xgrids");Cb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Cb).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:-r).attr("dy",-6).text(function(a){return a.text}));vd&&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:r).attr("y2",g?-10:p);Ac&&b.append("g").attr("class","ygrids");Db&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Db).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Ra).attr("class","regions");k.append("g").attr("clip-path", Ra).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ra?"ew-resize":null);X?wd(b):xd(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",yd?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",p).style("opacity",0).style("cursor","ew-resize").call(B).on("dblclick.zoom",null);null!==ib&&G.extent("function"!==typeof ib? ib:ib(xa,Ma));ya&&(v.append("g").attr("clip-path",Ra).attr("class","chart"),v.select(".chart").append("g").attr("class","chart-bars"),v.select(".chart").append("g").attr("class","chart-lines"),v.append("g").attr("clip-path",Ra).attr("class","x brush").call(G).selectAll("rect").attr("height",na),v.append("g").attr("class","x axis").attr("transform",J.subx).call(Fa));Aa&&jb(h.data.targets);Bc(h.data.targets);C({withTransition:!1,withUpdateXDomain:!0});if(zd){if(A&&"string"===typeof Ba){Ba=pa(Ba);for(a= 0;asc(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=ic(h.data.targets,a);100>sc(d, a)&&k.select(".-circles-"+d.id).select(".-circle-"+d.index).each(function(){Dc(this,d,d.index)})}).call(c.behavior.drag().origin(Object).on("drag",function(){Ec(c.mouse(this))}).on("dragstart",function(){Fc(c.mouse(this))}).on("dragend",function(){Gc()})).call(B).on("dblclick.zoom",null)}function Dc(a,b,d){var f=c.select(a),e=f.classed(ja),g=!1,h;"circle"===a.nodeName?(g=qc(a,1.5*Pa),h=uc):"rect"===a.nodeName&&(g=rc(a),h=wc);if(sa||g)ia&&ta(b)&&(f.classed(ja,!e),h(!e,f,b,d)),Bd(b,f)}function Ec(a){if(ia&& (!ra||B.altDomain)){var b=Hb[0],d=Hb[1],f=a[0];a=a[1];var e=Math.min(b,f),g=Math.max(b,f),h=sa?r: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(ja),k=d.classed(Ib),l,n,p,q;l=!1;"circle"===this.nodeName?(l=1*d.attr("cx"),n=1*d.attr("cy"),q=uc,l=e",c,e,g;for(c=0;c"+g+""+e+"";return b+""}),zd=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Cc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Bb=wa.replace("#","")+"-clip",Ra="url(#"+Bb+")",A="timeseries"===Jc,ea="categorized"===Jc,sb=!A&&(qa||X),Hb=null,kb=!1,Gb=!1,ma=Aa?40:0,Z=function(a,b){var c=[],e=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===c.indexOf(b)&&c.push(b);return e[c.indexOf(b)%e.length]}}(Hd,Id),Sc=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)}}(),Nb,Ub,Pb,Ya,Tb,Vb,q,p,na,nb,va,Xb,Yb,qb,rb,m,u,V,da,Za,$a,z,oa,ab,Fa,Nc=g?"left":"bottom",Oc=g?pb?"top":"bottom":pb?"right":"left",Pc=g?ob?"bottom":"top":ob?"left":"right",Qc="bottom",J={main:function(){return"translate("+y+","+r+")"},context:function(){return"translate("+l+","+Ca+")"},legend:function(){return"translate("+Lb+","+Kb+")"},y2:function(){return"translate("+ (g?0:q)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+na+")"}},Dd=function(){var a=c.svg.line().x(g?function(a){return E(a.id)(a.value)}:fb).y(g?fb:function(a){return E(a.id)(a.value)});return function(b){var c=xc(b.values),e;if(xb(b))return"spline"===ha["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),Ic[b.id]?md(c,m,E(b.id),Ic[b.id]):a(c);e=m(c[0].x);b=E(b.id)(c[0].value);return g?"M "+b+" "+e:"M "+e+" "+b}}(),Ed=function(){var a= c.svg.line().x(function(a){return da(a.x)}).y(function(a){return T(a.id)(a.value)});return function(b){var c=xc(b.values);return xb(b)?a(c):"M "+da(c[0].x)+" "+T(b.id)(c[0].value)}}(),G=c.svg.brush().on("brush",function(){C({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),B=c.behavior.zoom().on("zoomstart",function(){B.altDomain=c.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ra?Fd:null);G.update=function(){v&&v.select(".x.brush").call(this);return this};B.orgScaleExtent= function(){var a=Hc?Hc:[1,10];return[a[0],Math.max(Na()/a[1],a[1])]};B.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(W[1]-W[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var Qa,hb,k,v,za,Y,gb,xa=null,Ma=null,W;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();C({withUpdateXDomain:!0})};h.load=function(a){s(a.done)&&(a.done=function(){});"categories"in a&&ea&&(Ga=a.categories,z.categories(Ga)); if("cacheIds"in a&&Va(a.cacheIds))Sa(Wa(a.cacheIds),a.done);else if("data"in a)Sa(La(a.data),a.done);else if("url"in a)c.csv(a.url,function(b,c){Sa(La(c),a.done)});else if("rows"in a)Sa(La(bc(a.rows)),a.done);else if("columns"in a)Sa(La(cc(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(),jb(h.data.targets));0b.classes.indexOf(a)})});return L};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