(function(N){function jd(){function s(d,e){d.attr("transform",function(d){return"translate("+(e(d)+ba)+", 0)"})}function v(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function N(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return qa&&a===qa||Z&&Ed(Z,a)}function Fd(a){return!qc(a)}function Gd(a){Object.keys(a).forEach(function(b){Z[b]=a[b]})}function pb(a){var b;a&&(b=La[a.id],a.name=b?b:a.id);return a}function rc(a){var b=a[0],c={},f=[],k,d;for(k=1;kb&&(c=a,b=a.values.length)}):c=a?g.data.targets[0]:null;return c}function qb(a){a=v(a)?g.data.targets:a;return a.map(function(a){return a.id})}function uc(a){var b=qb(),c;for(c=0;ck&&(d-=c+30));c=b[1]+ 15+fr[c].indexOf(k.id)))for(f=0;fb?a-b:0};return function(a){var d=b?L(a.id):x(a.id);return c(d(a.value))}}function Pa(a,b){var c=v(a)?qb():a;"string"===typeof c&&(c=[c]);for(var f=0;f=e;e+=t)g+=f(a[d-1],a[d],e,m)}return g}function Ob(a){var b;rb=d.select(va);if(rb.empty())N.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); else{rb.html("");g.data.x={};g.data.targets=Ma(a);ta();Q();n.domain(d.extent(nb(g.data.targets)));y.domain(lb("y"));X.domain(lb("y2"));T.domain(n.domain());gb.domain(y.domain());hb.domain(X.domain());H.ticks(10>a.length?a.length:10);oa.ticks(Vd).outerTickSize(0).tickFormat(Wd);ib.ticks(Xd).outerTickSize(0).tickFormat(Yd);U=n.domain();I.x(T);ra&&E.x(n);q=d.select(va).append("svg").attr("width",p+G+da).attr("height",t+u+M).on("mouseenter",Zd).on("mouseleave",$d);sb=q.append("defs");sb.append("clipPath").attr("id", Pb).append("rect").attr("y",u).attr("width",p).attr("height",t-u);sb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-G).attr("y",-20).attr("width",K).attr("height",ca);sb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y",u-1).attr("width",ja).attr("height",wb);l=q.append("g").attr("transform",J.main);z=ya?q.append("g").attr("transform",J.context):null;za=Aa?q.append("g").attr("transform",J.legend):null;V=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",J.x).call(h?oa:H).append("text").attr("class","-axis-x-label").attr("x",p).attr("dy","-.5em").style("text-anchor","end").text(ae);l.append("g").attr("class","y axis").attr("clip-path",h?"url(#yaxis-clip)":"").call(h?H:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(be);yb&& l.append("g").attr("class","y2 axis").attr("transform",J.y2).call(ib);a=l.append("g").attr("clip-path",Ra).attr("class","grid");Wc&&a.append("g").attr("class","xgrids");Qb&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Qb).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",h?"":"rotate(-90)").attr("dx",h? 0:-u).attr("dy",-6).text(function(a){return a.text}));ce&&a.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",h?0:-10).attr("x2",h?p:-10).attr("y1",h?-10:u).attr("y2",h?-10:t);Xc&&a.append("g").attr("class","ygrids");Rb&&a.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Rb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});l.append("g").attr("clip-path",Ra).attr("class","regions");l.append("g").attr("clip-path", Ra).attr("class","chart");l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ra?"ew-resize":null);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",J.arc);if(ra)l.insert("rect",de?null:"g.grid").attr("class","zoom-rect").attr("width",p).attr("height",t).style("opacity",0).style("cursor","ew-resize").call(E).on("dblclick.zoom", null);null!==tb&&I.extent("function"!==typeof tb?tb:tb(nb()));ya&&(z.append("g").attr("clip-path",Ra).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",Ra).attr("class","x brush").call(I).selectAll("rect").attr("height",na),z.append("g").attr("class","x axis").attr("transform",J.subx).call(Fa));Aa&&ub(g.data.targets);Yc(g.data.targets);F({withTransition:!1,withUpdateXDomain:!0}); if(ee){if(A&&"string"===typeof Ba){Ba=pa(Ba);for(a=0;aGb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;B(g.data.targets)||(a=d.mouse(this),c=Dc(g.data.targets,a),100>Gb(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){$c(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){ad(d.mouse(this))}).on("dragstart", function(){bd(d.mouse(this))}).on("dragend",function(){cd()})).call(E).on("dblclick.zoom",null)}function $c(a,b,c){var f=d.select(a),e=f.classed(ia),g=!1,h;"circle"===a.nodeName?(g=Oc(a,1.5*Qa),h=Rc):"rect"===a.nodeName&&(g=Pc(a),h=Tc);if(sa||g)ga&&ha(b)&&(f.classed(ia,!e),h(!e,f,b,c)),je(b,f)}function ad(a){var b,c,f,e,h,n,m;B(g.data.targets)||!ga||ra&&!E.altDomain||(b=Vb[0],c=Vb[1],f=a[0],a=a[1],e=Math.min(b,f),h=Math.max(b,f),n=sa?u:Math.min(c,a),m=sa?t:Math.max(c,a),l.select(".dragarea").attr("x", e).attr("y",n).attr("width",h-e).attr("height",m-n),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ha(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ia),g=c.classed(Wb),l,p,s,q;l=!1;"circle"===this.nodeName?(l=1*c.attr("cx"),p=1*c.attr("cy"),q=Rc,l=e",c,d,e;for(c=0;c"+e+""+d+"");return b+""}),ee=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Zc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Pb=va.replace("#","")+"-clip",Ra="url(#"+Pb+")",A="timeseries"===id,Y="categorized"===id,Fb=!A&&(qa||Z),Vb=null,Sa=!1,Ub=!1,ma=Aa?40:0,O=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]}}(qe,re),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)}}(),cc,gc,ec,cb,fc,hc,p,t,na,xb,ua,fb,zb,jb,lc,mc,Db,jc,kc,Bb,Cb,n,y,X,T,gb,hb,H,oa,ib,Fa,ld=h?"left":"bottom",md=h?eb?"top":"bottom":eb?"right":"left",nd=h?bb?"bottom":"top":bb?"left":"right",od="bottom",J={main:function(){return"translate("+G+","+u+")"},context:function(){return"translate("+m+","+Ca+")"},legend:function(){return"translate("+ $b+","+Zb+")"},y2:function(){return"translate("+(h?0:p)+","+(h?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+na+")"},arc:function(){return"translate("+p/2+","+t/2+")"}};Db=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var le=function(){var a=d.svg.line().x(h?function(a){return x(a.id)(a.value)}:xa).y(h?xa:function(a){return x(a.id)(a.value)});return function(b){var c=Kb(b.values),d;if(Hb(b))return Lc(b)?a.interpolate("cardinal"): a.interpolate("linear"),hd[b.id]?Ud(c,n,x(b.id),hd[b.id]):a(c);d=n(c[0].x);b=x(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),me=function(){var a;a=h?d.svg.area().x0(function(a){return x(a.id)(0)}).x1(function(a){return x(a.id)(a.value)}).y(xa):d.svg.area().x(xa).y0(function(a){return x(a.id)(0)}).y1(function(a){return x(a.id)(a.value)});return function(b){var c=Kb(b.values),d;if(Ka([b],"area")||Ka([b],"area-spline"))return Lc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d= n(c[0].x);b=x(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),ne=function(){var a=d.svg.line().x(function(a){return T(a.x)}).y(function(a){return L(a.id)(a.value)});return function(b){var c=Kb(b.values);return Hb(b)?a(c):"M "+T(c[0].x)+" "+L(b.id)(c[0].value)}}(),I=d.svg.brush().on("brush",function(){F({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),E=d.behavior.zoom().on("zoomstart",function(){E.altDomain=d.event.sourceEvent.altKey?n.orgDomain():null}).on("zoom",ra? oe:null);I.update=function(){z&&z.select(".x.brush").call(this);return this};E.orgScaleExtent=function(){var a=gd?gd:[1,10];return[a[0],Math.max(Ea()/a[1],a[1])]};E.updateScaleExtent=function(){var a=n.orgDomain(),a=(a[1]-a[0])/(U[1]-U[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var q,sb,l,z,za,V,rb,U;g.focus=function(a){var b=q.selectAll(Va(a)),c=b.filter(Xb),b=b.filter(Yb);g.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity", 1);B(g.data.targets)&&Za(a,!0)};g.defocus=function(a){var b=q.selectAll(Va(a)),c=b.filter(Xb),b=b.filter(Yb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);B(g.data.targets)&&vb(a)};g.revert=function(a){var b=q.selectAll(Va(a)),c=b.filter(Xb),b=b.filter(Yb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(g.data.targets)&&vb(a)};g.show=function(a){q.selectAll(Va(a)).transition().style("opacity", 1)};g.hide=function(a){q.selectAll(Va(a)).transition().style("opacity",0)};g.unzoom=function(){I.clear().update();F({withUpdateXDomain:!0})};g.load=function(a){"function"!==typeof a.done&&(a.done=function(){});a.xs&&Gd(a.xs);"categories"in a&&Y&&(Ga=a.categories,H.categories(Ga));if("cacheIds"in a&&Cd(a.cacheIds))Ta(Dd(a.cacheIds),a.done);else if("data"in a)Ta(Ma(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Ta(Ma(c),a.done)});else if("rows"in a)Ta(Ma(rc(a.rows)),a.done);else if("columns"in a)Ta(Ma(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});q.selectAll(".target-"+a).transition().style("opacity",0).remove();Aa&&(q.selectAll(".legend-item-"+a).remove(),ub(g.data.targets));0b.classes.indexOf(a)})});return P};g.data.get=function(a){a=g.data.getAsTarget(a);return s(a)?a.values.map(function(a){return a.value}):void 0};g.data.getAsTarget=function(a){var b=mb(function(b){return b.id===a});return 0