(function(U){function id(){function p(d,e){d.attr("transform",function(d){return"translate("+(e(d)+da)+", 0)"})}function t(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function U(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return pa&&a===pa||aa&&Dd(aa,a)}function Ed(a){return!qc(a)}function nb(a){var b= Na[a.id];a.name=p(b)?b:a.id;return a}function rc(a){var b=a[0],c={},k=[],f,d;for(f=1;fx[c].indexOf(f.id)))for(d=0;db?a-b:0};return function(a){var d=b?X(a.id):u(a.id);return c(d(a.value))}}function Sa(a,b){var c=t(a)?ob():a;"string"===typeof c&&(c=[c]);for(var d=0;d=e;e+=s)g+=d(a[f-1],a[f],e,n)}return g}function Mb(a){var b,c;pb=d.select(va);if(pb.empty())U.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); g.data.x={};g.data.targets=Oa(a);ta();Xb();m.domain(d.extent(lb(g.data.targets)));y.domain(jb("y"));Z.domain(jb("y2"));R.domain(m.domain());eb.domain(y.domain());fb.domain(Z.domain());G.ticks(10>a.length?a.length:10);na.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);S=m.domain();H.x(R);qa&&D.x(m);Ua=d.select(va).append("svg").attr("width",r+F+ea).attr("height",q+s+K).on("mouseenter",Wd).on("mouseleave",Xd);qb=Ua.append("defs");qb.append("clipPath").attr("id", Nb).append("rect").attr("y",s).attr("width",r).attr("height",q-s);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-F).attr("y",-20).attr("width",W).attr("height",V);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-F+1).attr("y",s-1).attr("width",ka).attr("height",tb);l=Ua.append("g").attr("transform",I.main);z=ya?Ua.append("g").attr("transform",I.context):null;za=Aa?Ua.append("g").attr("transform",I.legend):null;T=d.select(va).style("position","relative").append("div").style("position", "absolute").style("z-index","10").style("display","none");l.append("g").attr("class","x axis").attr("clip-path",h?"":"url(#xaxis-clip)").attr("transform",I.x).call(h?na:G).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(Yd);l.append("g").attr("class","y axis").attr("clip-path",h?"url(#yaxis-clip)":"").call(h?G:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Zd);dc&& l.append("g").attr("class","y2 axis").attr("transform",I.y2).call(gb);b=l.append("g").attr("clip-path",Va).attr("class","grid");Vc&&b.append("g").attr("class","xgrids");Ob&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Ob).enter().append("g").attr("class","xgrid-line"),c.append("line").attr("class",function(a){return""+a["class"]}),c.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"":"rotate(-90)").attr("dx",h? 0:-s).attr("dy",-6).text(function(a){return a.text}));$d&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",h?0:-10).attr("x2",h?r:-10).attr("y1",h?-10:s).attr("y2",h?-10:q);Wc&&b.append("g").attr("class","ygrids");Pb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});l.append("g").attr("clip-path",Va).attr("class","regions");l.append("g").attr("clip-path", Va).attr("class","chart");b=l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",qa?"ew-resize":null);aa?ae(b):be(b,a);l.select(".chart").append("g").attr("class","chart-bars");l.select(".chart").append("g").attr("class","chart-lines");l.select(".chart").append("g").attr("class","chart-arcs").attr("transform",I.arc);if(qa)l.insert("rect",ce?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",q).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom", null);null!==rb&&H.extent("function"!==typeof rb?rb:rb(lb()));ya&&(z.append("g").attr("clip-path",Va).attr("class","chart"),z.select(".chart").append("g").attr("class","chart-bars"),z.select(".chart").append("g").attr("class","chart-lines"),z.append("g").attr("clip-path",Va).attr("class","x brush").call(H).selectAll("rect").attr("height",ma),z.append("g").attr("class","x axis").attr("transform",I.subx).call(Ha));Aa&&sb(g.data.targets);Xc(g.data.targets);E({withTransition:!1,withUpdateXDomain:!0}); if(de){if(A&&"string"===typeof Ba){Ba=oa(Ba);for(a=0;aEb(c,a)?d.select(".event-rect").style("cursor","pointer"):d.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;B(g.data.targets)||(a=d.mouse(this),c=Cc(g.data.targets,a),100>Eb(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this, c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(D).on("dblclick.zoom",null)}function Zc(a,b,c){var e=d.select(a),f=e.classed(ja),g=!1,h;"circle"===a.nodeName?(g=Nc(a,1.5*Ta),h=Qc):"rect"===a.nodeName&&(g=Oc(a),h=Sc);if(ra||g)ha&&ia(b)&&(e.classed(ja,!f),h(!f,e,b,c)),fe(b,e)}function $c(a){var b,c,e,f,h,m,n;B(g.data.targets)||!ha||qa&&!D.altDomain||(b=Tb[0],c=Tb[1],e=a[0], a=a[1],f=Math.min(b,e),h=Math.max(b,e),m=ra?s:Math.min(c,a),n=ra?q:Math.max(c,a),l.select(".dragarea").attr("x",f).attr("y",m).attr("width",h-f).attr("height",n-m),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ia(a)}).each(function(a,b){var c=d.select(this),e=c.classed(ja),k=c.classed(Ub),g,l,p,q;g=!1;"circle"===this.nodeName?(g=1*c.attr("cx"),l=1*c.attr("cy"),q=Qc,g=f",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Yc=e(["tooltip","init", "position"],{top:"0px",left:"50px"}),Nb=va.replace("#","")+"-clip",Va="url(#"+Nb+")",A="timeseries"===hd,$="categorized"===hd,Db=!A&&(pa||aa),Tb=null,Wa=!1,Sb=!1,la=Aa?40:0,N=function(a,b){var c=[],d=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 d[c.indexOf(b)%d.length]}}(me,ne),qd=function(){var a=[[d.time.format("%Y/%-m/%-d"),function(){return!0}],[d.time.format("%-m/%-d"), function(a){return a.getMonth()}],[d.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[d.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[d.time.format("%I %p"),function(a){return a.getHours()}],[d.time.format("%I:%M"),function(a){return a.getMinutes()}],[d.time.format(":%S"),function(a){return a.getSeconds()}],[d.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),$b,gc, bc,cb,fc,hc,r,q,ma,ub,ua,db,xb,hb,lc,mc,Ab,jc,kc,yb,zb,m,y,Z,R,eb,fb,G,na,gb,Ha,ld=h?"left":"bottom",md=h?wb?"top":"bottom":wb?"right":"left",nd=h?vb?"bottom":"top":vb?"left":"right",od="bottom",I={main:function(){return"translate("+F+","+s+")"},context:function(){return"translate("+n+","+Ca+")"},legend:function(){return"translate("+Zb+","+Yb+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"},x:function(){return"translate(0,"+q+")"},subx:function(){return"translate(0,"+ma+")"},arc:function(){return"translate("+ r/2+","+q/2+")"}};Ab=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var he=function(){var a=d.svg.line().x(h?function(a){return u(a.id)(a.value)}:xa).y(h?xa:function(a){return u(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Fb(b))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),gd[b.id]?Rd(c,m,u(b.id),gd[b.id]):a(c);d=m(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),ie=function(){var a;a=h?d.svg.area().x0(function(a){return u(a.id)(0)}).x1(function(a){return u(a.id)(a.value)}).y(xa): d.svg.area().x(xa).y0(function(a){return u(a.id)(0)}).y1(function(a){return u(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Ma([b],"area")||Ma([b],"area-spline"))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=m(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),je=function(){var a=d.svg.line().x(function(a){return R(a.x)}).y(function(a){return X(a.id)(a.value)});return function(b){var c=Ib(b.values);return Fb(b)?a(c):"M "+R(c[0].x)+" "+X(b.id)(c[0].value)}}(), H=d.svg.brush().on("brush",function(){E({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),D=d.behavior.zoom().on("zoomstart",function(){D.altDomain=d.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",qa?ke:null);H.update=function(){z&&z.select(".x.brush").call(this);return this};D.orgScaleExtent=function(){var a=fd?fd:[1,10];return[a[0],Math.max(Pa()/a[1],a[1])]};D.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(S[1]-S[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]* a,b[1]*a]);return this};var Ua,qb,l,z,za,T,pb,S;g.focus=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);g.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(g.data.targets)&&Fa(a,!0)};g.defocus=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);B(g.data.targets)&&Ga(a)}; g.revert=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(g.data.targets)&&Ga(a)};g.show=function(a){d.selectAll(Za(a)).transition().style("opacity",1)};g.hide=function(a){d.selectAll(Za(a)).transition().style("opacity",0)};g.unzoom=function(){H.clear().update();E({withUpdateXDomain:!0})};g.load=function(a){t(a.done)&&(a.done=function(){});"categories"in a&&$&& (Ia=a.categories,G.categories(Ia));if("cacheIds"in a&&Bd(a.cacheIds))Xa(Cd(a.cacheIds),a.done);else if("data"in a)Xa(Oa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Xa(Oa(c),a.done)});else if("rows"in a)Xa(Oa(rc(a.rows)),a.done);else if("columns"in a)Xa(Oa(sc(a.columns)),a.done);else throw Error("url or rows or columns is required.");};g.unload=function(a){g.data.targets=g.data.targets.filter(function(b){return b.id!==a});d.selectAll(".target-"+a).transition().style("opacity",0).remove(); Aa&&(d.selectAll(".legend-item-"+a).remove(),sb(g.data.targets));0b.classes.indexOf(a)})});return O}; g.data.get=function(a){a=g.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};g.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0