(function(Q){function Tc(){function n(c,e){c.attr("transform",function(c){return"translate("+(e(c)+ba)+", 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 fc(a){return qa&&a===qa||Y&&id(Y,a)}function jd(a){return!fc(a)}function fb(a){var b=Ka[a.id];a.name=n(b)?b:a.id;return a}function gc(a){var b=a[0],d={},f=[],t,c;for(t=1;tu[d].indexOf(c.id)))for(f=0;f b?a-b:0};return function(a){var c=b?T(a.id):F(a.id);return d(c(a.value))}}function Oa(a,b){var d=s(a)?gb():a;"string"===typeof d&&(d=[d]);for(var f=0;f=e;e+=r)h+=f(a[c-1],a[c],e,l)}return h}function Eb(a){var b,d;ib=c.select(wa);if(ib.empty())Q.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{ib.html("");h.data.x={};h.data.targets=La(a);Hc&&Oa(gb().filter(function(a){return!(a in P)}),Hc);ua();Nb();m.domain(c.extent(Wa()));v.domain(ka("y"));V.domain(ka("y2"));ea.domain(m.domain());$a.domain(v.domain());ab.domain(V.domain()); B.ticks(10>a.length?a.length:10);na.ticks(vd).outerTickSize(0).tickFormat(wd);bb.ticks(xd).outerTickSize(0).tickFormat(yd);W=m.domain();H.x(ea);ra&&D.x(m);Qa=c.select(wa).append("svg").attr("width",q+A+da).attr("height",p+r+G).on("mouseenter",zd).on("mouseleave",Ad);jb=Qa.append("defs");jb.append("clipPath").attr("id",Fb).append("rect").attr("y",r).attr("width",q).attr("height",p-r);jb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-A).attr("y",-20).attr("width",S).attr("height", R);jb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-A+1).attr("y",r-1).attr("width",ja).attr("height",ob);k=Qa.append("g").attr("transform",K.main);w=za?Qa.append("g").attr("transform",K.context):null;Aa=Ba?Qa.append("g").attr("transform",K.legend):null;O=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", K.x).call(g?na:B).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(Bd);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(Cd);Ub&&k.append("g").attr("class","y2 axis").attr("transform",K.y2).call(bb);b=k.append("g").attr("clip-path",Ra).attr("class","grid");Ic&&b.append("g").attr("class", "xgrids");Gb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Gb).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}));Dd&&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);Jc&&b.append("g").attr("class","ygrids");Hb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Hb).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);Y?Ed(b):Fd(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",Gd?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",p).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom",null);null!==kb&&H.extent("function"!==typeof kb?kb:kb(oa,ya));za&&(w.append("g").attr("clip-path",Ra).attr("class","chart"),w.select(".chart").append("g").attr("class","chart-bars"),w.select(".chart").append("g").attr("class", "chart-lines"),w.append("g").attr("clip-path",Ra).attr("class","x brush").call(H).selectAll("rect").attr("height",ma),w.append("g").attr("class","x axis").attr("transform",K.subx).call(Fa));Ba&&lb(h.data.targets);Kc(h.data.targets);z({withTransition:!1,withUpdateXDomain:!0});if(Hd){if(C&&"string"===typeof Ca){Ca=pa(Ca);for(a=0;axb(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=pc(h.data.targets,a);100>xb(d,a)&&k.select(".-circles-"+d.id).select(".-circle-"+d.index).each(function(){Mc(this,d,d.index)})}).call(c.behavior.drag().origin(Object).on("drag",function(){Nc(c.mouse(this))}).on("dragstart",function(){Oc(c.mouse(this))}).on("dragend",function(){Pc()})).call(D).on("dblclick.zoom",null)}function Mc(a,b,d){var f=c.select(a),e=f.classed(ia),g=!1,h;"circle"===a.nodeName?(g=yc(a,1.5*Pa),h=Bc):"rect"===a.nodeName&&(g=zc(a),h=Dc);if(sa||g)ha&& ta(b)&&(f.classed(ia,!e),h(!e,f,b,d)),Jd(b,f)}function Nc(a){if(ha&&(!ra||D.altDomain)){var b=Lb[0],d=Lb[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(ia),k=d.classed(Mb),l,n,p,q;l=!1;"circle"===this.nodeName?(l=1*d.attr("cx"),n=1*d.attr("cy"), q=Bc,l=e", d,c,e;for(d=0;d"+e+""+c+"";return b+""}),Hd=e(["tooltip","init","show"],!1),Ca=e(["tooltip","init","x"],0),Lc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Fb=wa.replace("#","")+"-clip",Ra="url(#"+Fb+")",C="timeseries"===Sc,X="categorized"=== Sc,ub=!C&&(qa||Y),Lb=null,Sa=!1,Kb=!1,la=Ba?40:0,Z=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]}}(Pd,Qd),ad=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)}}(),Qb,Xb,Sb,Za,Wb,Yb,q,p,ma,pb,va,$b,ac,sb,tb,m,v,V,ea,$a,ab,B,na,bb,Fa,Wc=g?"left":"bottom",Xc=g?rb?"top":"bottom":rb?"right":"left", Yc=g?qb?"bottom":"top":qb?"left":"right",Zc="bottom",K={main:function(){return"translate("+A+","+r+")"},context:function(){return"translate("+l+","+Da+")"},legend:function(){return"translate("+Pb+","+Ob+")"},y2:function(){return"translate("+(g?0:q)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+ma+")"}},Ld=function(){var a=c.svg.line().x(g?function(a){return F(a.id)(a.value)}:hb).y(g?hb:function(a){return F(a.id)(a.value)});return function(b){var c= Ec(b.values),e;if(yb(b))return"spline"===P["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),Rc[b.id]?ud(c,m,F(b.id),Rc[b.id]):a(c);e=m(c[0].x);b=F(b.id)(c[0].value);return g?"M "+b+" "+e:"M "+e+" "+b}}(),Md=function(){var a=c.svg.line().x(function(a){return ea(a.x)}).y(function(a){return T(a.id)(a.value)});return function(b){var c=Ec(b.values);return yb(b)?a(c):"M "+ea(c[0].x)+" "+T(b.id)(c[0].value)}}(),H=c.svg.brush().on("brush",function(){z({withTransition:!1,withY:!1, withSubchart:!1,withUpdateXDomain:!0})}),D=c.behavior.zoom().on("zoomstart",function(){D.altDomain=c.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ra?Nd:null);H.update=function(){w&&w.select(".x.brush").call(this);return this};D.orgScaleExtent=function(){var a=Qc?Qc:[1,10];return[a[0],Math.max(Ma()/a[1],a[1])]};D.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,jb,k,w,Aa,O,ib,oa=null, ya=null,W;h.focus=function(a){h.defocus();c.selectAll(Va(a)).filter(function(a){return vb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){c.selectAll(Va(a)).filter(function(a){return vb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){c.selectAll(Va(a)).filter(function(a){return vb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){c.selectAll(Va(a)).transition().style("opacity", 1)};h.hide=function(a){c.selectAll(Va(a)).transition().style("opacity",0)};h.unzoom=function(){H.clear().update();z({withUpdateXDomain:!0})};h.load=function(a){s(a.done)&&(a.done=function(){});"categories"in a&&X&&(Ga=a.categories,B.categories(Ga));if("cacheIds"in a&&Xa(a.cacheIds))Ta(nb(a.cacheIds),a.done);else if("data"in a)Ta(La(a.data),a.done);else if("url"in a)c.csv(a.url,function(b,c){Ta(La(c),a.done)});else if("rows"in a)Ta(La(gc(a.rows)),a.done);else if("columns"in a)Ta(La(hc(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();Ba&&(c.selectAll(".legend-item-"+a).remove(),lb(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=db(function(b){return b.id===a});return 0