(function(P){function kd(){function r(d,f){d.attr("transform",function(d){return"translate("+(f(d)+ca)+", 0)"})}function x(d,f){d.attr("transform",function(d){return"translate(0,"+f(d)+")"})}function P(d){var f=d[0];d=d[d.length-1];return fa?a:0}),c=1;c+a||(b[e][c]+=+a)});return d.max(Object.keys(b).map(function(a){return d.max(b[a])}))}function mb(a){var b=nb(function(b){return y(b.id)===a}),c="y2"===a?wd:xd,e="y2"===a?yd:zd,c=c?c:td(b),e=e?e:ud(b),k=0.1*Math.abs(e-c),d=k,f=k,g="y2"===a?Ad:Bd;g&&(c=Math.max(Math.abs(c),Math.abs(e)),e=c-g,c=g-c);"y"===a&&Ga&&(d=Ga.top?Ga.top:k,f=Ga.bottom?Ga.bottom:k);"y2"===a&&Ha&&(d=Ha.top?Ha.top:k,f=Ha.bottom?Ha.bottom:k);Ia(b,"bar")&&!qc(b)&&(f=c);return[c-f,e+d]}function Cd(a){return d.min(a, function(a){return d.min(a.values,function(a){return a.x})})}function Dd(a){return d.max(a,function(a){return d.max(a.values,function(a){return a.x})})}function ob(a){var b=[Cd(a),Dd(a)];a=b[0];var b=b[1],c=ea?0:0.01*Math.abs(a-b);a=B?new Date(a.getTime()-c):a-c;b=B?new Date(b.getTime()+c):b+c;return[a,b]}function ta(a){return a[1]-a[0]}function Ed(a){for(var b=0;ba?0:a}function tc(a){return na&&a===na||$&&Gd($,a)}function Hd(a){return!tc(a)}function Id(a){Object.keys(a).forEach(function(b){$[b]=a[b]})}function qb(a){var b;a&&(b=Ja[a.id],a.name=b?b:a.id);return a}function uc(a){var b=a[0],c={},e=[],k,d;for(k=1;kb&&(c=a,b=a.values.length)}):c=a?h.data.targets[0]:null;return c}function rb(a){a=x(a)?h.data.targets:a;return a.map(function(a){return a.id})}function xc(a){var b=rb(),c;for(c=0;ca})}function vd(a){return yc(a,function(a){return 0k&&(d-=c+30)),c=b[1]+15+et[c].indexOf(k.id)))for(e=0;e=f;f+=s)h+=e(a[d-1],a[d],f,ya)}return h}function Vb(a){var b;tb=d.select(sa);if(tb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); else{tb.html("");h.data.x={};h.data.targets=Ka(a);qa();R();m.domain(d.extent(ob(h.data.targets)));z.domain(mb("y"));Z.domain(mb("y2"));V.domain(m.domain());hb.domain(z.domain());ib.domain(Z.domain());J.ticks(10>a.length?a.length:10);ua.ticks(ae).outerTickSize(0).tickFormat(be);jb.ticks(ce).outerTickSize(0).tickFormat(de);U=m.domain();L.scale(V);oa&&D.scale(m);n=d.select(sa).append("svg").attr("width",q+A+Y).attr("height",s+u+O).on("mouseenter",ee).on("mouseleave",fe);ub=n.append("defs");ub.append("clipPath").attr("id", Wb).append("rect").attr("y",u).attr("width",q).attr("height",s-u);ub.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-A).attr("y",-20).attr("width",N).attr("height",da);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-A+1).attr("y",u-1).attr("width",ia).attr("height",yb);l=n.append("g").attr("transform",M.main);E=za?n.append("g").attr("transform",M.context):null;Aa=Ba?n.append("g").attr("transform",M.legend):null;W=d.select(sa).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",g?"":"url(#xaxis-clip)").attr("transform",M.x).call(g?ua:J).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(ge);l.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?J:ua).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(he);Bb&& l.append("g").attr("class","y2 axis").attr("transform",M.y2).call(jb);a=l.append("g").attr("clip-path",Qa).attr("class","grid");Xc&&a.append("g").attr("class","xgrids");Xb&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Xb).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",g?"":"rotate(-90)").attr("dx",g? 0:-u).attr("dy",-5).text(function(a){return a.text}));ie&&a.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:u).attr("y2",g?-10:s);Yc&&a.append("g").attr("class","ygrids");Yb&&(a=a.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Yb).enter().append("g").attr("class","ygrid-line"),a.append("line").attr("class",function(a){return""+a["class"]}),a.append("text").attr("class",function(a){return""+ a["class"]}).attr("text-anchor","end").attr("transform",g?"rotate(-90)":"").attr("dx",g?0:-u).attr("dy",-5).text(function(a){return a.text}));l.append("g").attr("clip-path",Qa).attr("class","regions");l.append("g").attr("clip-path",Qa).attr("class","chart");l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",oa?"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",M.arc);if(oa)l.insert("rect",je?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom",null);null!==vb&&L.extent("function"!==typeof vb?vb:vb(ob()));za&&(E.append("g").attr("clip-path",Qa).attr("class","chart"),E.select(".chart").append("g").attr("class","chart-bars"),E.select(".chart").append("g").attr("class","chart-lines"),E.append("g").attr("clip-path",Qa).attr("class","x brush").call(L).selectAll("rect").attr(g? "width":"height",g?Cb:db),E.append("g").attr("class","x axis").attr("transform",M.subx).call(gb));Ba&&wb(h.data.targets);Zc(h.data.targets);I({withTransition:!1,withUpdateXDomain:!0});if(ke){if(B&&"string"===typeof Ca){Ca=ma(Ca);for(a=0;aNb(c,a)?n.select(".event-rect").style("cursor","pointer"):n.select(".event-rect").style("cursor",null))}).on("click", function(){var a,c;C(h.data.targets)||(a=d.mouse(this),c=Ic(h.data.targets,a),100>Nb(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){ad(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){bd(d.mouse(this))}).on("dragstart",function(){cd(d.mouse(this))}).on("dragend",function(){dd()})).call(D).on("dblclick.zoom",null)}function ad(a,b,c){var e=d.select(a),f=e.classed(ha),g=!1,h;"circle"===a.nodeName?(g=Qc(a,1.5*Pa),h=Tc):"rect"===a.nodeName&& (g=Rc(a),h=Vc);if(pa||g)fa&&ga(b)&&(e.classed(ha,!f),h(!f,e,b,c)),pe(b,e)}function bd(a){var b,c,e,f,g,m,n;C(h.data.targets)||!fa||oa&&!D.altDomain||(b=bc[0],c=bc[1],e=a[0],a=a[1],f=Math.min(b,e),g=Math.max(b,e),m=pa?u:Math.min(c,a),n=pa?s:Math.max(c,a),l.select(".dragarea").attr("x",f).attr("y",m).attr("width",g-f).attr("height",n-m),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ga(a)}).each(function(a,b){var c=d.select(this),e=c.classed(ha),h=c.classed(cc),l,p,q,r;l=!1; "circle"===this.nodeName?(l=1*c.attr("cx"),p=1*c.attr("cy"),r=Tc,l=f",c,d,f;for(c=0;c"+f+""+d+"");return b+ ""}),ke=f(["tooltip","init","show"],!1),Ca=f(["tooltip","init","x"],0),$c=f(["tooltip","init","position"],{top:"0px",left:"50px"}),Wb=sa.replace("#","")+"-clip",Qa="url(#"+Wb+")",B="timeseries"===jd,ea="categorized"===jd,Mb=!B&&(na||$),bc=null,Ra=!1,ac=!1,la=Ba?40:0,K=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]}}(we, xe),rd=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)}}(),q,Cb,s,db,zb,ra,eb,Db,kb,mc,nc,Kb,Eb,Fb,Gb,Hb,Ib,Jb,m,z,Z,V,hb,ib,J,ua,jb,gb,md=g?"left":"bottom",nd=g?ab?"top":"bottom":ab?"right":"left",od=g?cb?"bottom":"top":cb?"left":"right",pd=g?"left":"bottom",M={main:function(){return"translate("+A+","+u+")"},context:function(){return"translate("+Ea+","+Da+")"},legend:function(){return"translate("+gc+","+fc+")"},y2:function(){return"translate("+(g?0:q)+","+(g?10:0)+")"}, x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+(g?0:db)+")"},arc:function(){return"translate("+q/2+","+s/2+")"}},kc=40,jc=20;Kb=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var re=function(){var a=d.svg.line().x(g?function(a){return w(a.id)(a.value)}:va).y(g?va:function(a){return w(a.id)(a.value)});return function(b){var c=Rb(b.values),d;if(Ob(b))return Nc(b)?a.interpolate("cardinal"):a.interpolate("linear"),id[b.id]?$d(c, m,w(b.id),id[b.id]):a(c);d=m(c[0].x);b=w(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),se=function(){var a;a=g?d.svg.area().x0(function(a){return w(a.id)(0)}).x1(function(a){return w(a.id)(a.value)}).y(va):d.svg.area().x(va).y0(function(a){return w(a.id)(0)}).y1(function(a){return w(a.id)(a.value)});return function(b){var c=Rb(b.values),d;if(Ia([b],"area")||Ia([b],"area-spline"))return Nc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=m(c[0].x);b=w(b.id)(c[0].value);return g? "M "+b+" "+d:"M "+d+" "+b}}(),te=function(){var a=d.svg.line().x(g?function(a){return F(a.id)(a.value)}:Ec).y(g?Ec:function(a){return F(a.id)(a.value)});return function(b){var c=Rb(b.values);return Ob(b)?a(c):"M "+V(c[0].x)+" "+F(b.id)(c[0].value)}}(),L=d.svg.brush().on("brush",function(){I({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",oa?ue:null);L.update=function(){E&& E.select(".x.brush").call(this);return this};L.scale=function(a){return g?this.y(a):this.x(a)};D.scale=function(a){return g?this.y(a):this.x(a)};D.orgScaleExtent=function(){var a=hd?hd:[1,10];return[a[0],Math.max(fb()/a[1],a[1])]};D.updateScaleExtent=function(){var a=ta(m.orgDomain())/ta(U),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var n,ub,l,E,Aa,W,tb,U;h.focus=function(a){var b=n.selectAll(Ua(a)),c=b.filter(dc),b=b.filter(ec);h.defocus();c.classed("focused",!0).transition().duration(100).style("opacity", 1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&&Ya(a,!0)};h.defocus=function(a){var b=n.selectAll(Ua(a)),c=b.filter(dc),b=b.filter(ec);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);C(h.data.targets)&&xb(a)};h.revert=function(a){var b=n.selectAll(Ua(a)),c=b.filter(dc),b=b.filter(ec);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&& xb(a)};h.show=function(a){n.selectAll(Ua(a)).transition().style("opacity",1)};h.hide=function(a){n.selectAll(Ua(a)).transition().style("opacity",0)};h.unzoom=function(){L.clear().update();I({withUpdateXDomain:!0})};h.load=function(a){"function"!==typeof a.done&&(a.done=function(){});a.xs&&Id(a.xs);"categories"in a&&ea&&(Fa=a.categories,J.categories(Fa));if("cacheIds"in a&&Ed(a.cacheIds))Sa(Fd(a.cacheIds),a.done);else if("data"in a)Sa(Ka(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Sa(Ka(c), a.done)});else if("rows"in a)Sa(Ka(uc(a.rows)),a.done);else if("columns"in a)Sa(Ka(vc(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});n.selectAll(".target-"+a).transition().style("opacity",0).remove();Ba&&(n.selectAll(".legend-item-"+a).remove(),wb(h.data.targets));0b.classes.indexOf(a)})});return Q};h.data.get=function(a){a=h.data.getAsTarget(a);return r(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=nb(function(b){return b.id===a});return 0