(function(P){function ld(){function u(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?xd:yd,e="y2"===a?zd:Ad,c=c?c:ud(b),e=e?e:vd(b),k=0.1*Math.abs(e-c),d=k,f=k,g="y2"===a?Bd:Cd;g&&(c=Math.max(Math.abs(c),Math.abs(e)),e=c-g,c=g-c);"y"===a&&Ia&&(d=Ia.top?Ia.top:k,f=Ia.bottom?Ia.bottom:k);"y2"===a&&Ja&&(d=Ja.top?Ja.top:k,f=Ja.bottom? Ja.bottom:k);ma(b,"bar")&&!tc(b)&&(f=c);return[c-f,e+d]}function Dd(a){return d.min(a,function(a){return d.min(a.values,function(a){return a.x})})}function Ed(a){return d.max(a,function(a){return d.max(a.values,function(a){return a.x})})}function ob(a){var b=[Dd(a),Ed(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 ua(a){return a[1]-a[0]}function Fd(a){for(var b=0;ba?0:a}function wc(a){return oa&&a===oa||$&&Hd($,a)}function Id(a){return!wc(a)}function Jd(a){Object.keys(a).forEach(function(b){$[b]=a[b]})}function qb(a){var b;a&&(b=Ka[a.id],a.name=b?b:a.id);return a}function xc(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 Bc(a){var b=rb(),c;for(c=0;ca})} function wd(a){return Cc(a,function(a){return 0k&&(d-=c+30)),c=b[1]+15+et[c].indexOf(k.id)))for(e=0;e=f;f+=r)h+=e(a[d-1],a[d],f,za)}return h}function Wb(a){var b;tb=d.select(ta);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=La(a);ra();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);va.ticks(be).outerTickSize(0).tickFormat(ce); jb.ticks(de).outerTickSize(0).tickFormat(ee);U=m.domain();L.scale(V);pa&&E.scale(m);p=d.select(ta).append("svg").attr("width",r+A+Y).attr("height",s+n+O).on("mouseenter",fe).on("mouseleave",ge);ub=p.append("defs");ub.append("clipPath").attr("id",Xb).append("rect").attr("y",n).attr("width",r).attr("height",s-n);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",n-1).attr("width",ia).attr("height",yb);l=p.append("g").attr("transform",M.main);F=Aa?p.append("g").attr("transform",M.context):null;Ba=Ca?p.append("g").attr("transform",M.legend):null;W=d.select(ta).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?va:J).append("text").attr("class","-axis-x-label").attr("x", r).attr("dy","-.5em").style("text-anchor","end").text(he);l.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?J:va).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(ie);Bb&&l.append("g").attr("class","y2 axis").attr("transform",M.y2).call(jb);a=l.append("g").attr("clip-path",Ra).attr("class","grid");ad&&a.append("g").attr("class","xgrids");Yb&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Yb).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:-n).attr("dy",-5).text(function(a){return a.text}));je&&a.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:n).attr("y2",g?-10:s);bd&&a.append("g").attr("class","ygrids");Zb&&(a=a.append("g").attr("class", "ygrid-lines").selectAll("ygrid-line").data(Zb).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:-n).attr("dy",-5).text(function(a){return a.text}));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",pa?"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(pa)l.insert("rect",ke?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(E).on("dblclick.zoom",null);null!==vb&&L.extent("function"!==typeof vb?vb:vb(ob())); Aa&&(F.append("g").attr("clip-path",Ra).attr("class","chart"),F.select(".chart").append("g").attr("class","chart-bars"),F.select(".chart").append("g").attr("class","chart-lines"),F.append("g").attr("clip-path",Ra).attr("class","x brush").call(L).selectAll("rect").attr(g?"width":"height",g?Cb:eb),F.append("g").attr("class","x axis").attr("transform",M.subx).attr("clip-path",g?"url(#yaxis-clip)":"").call(gb));Ca&&wb(h.data.targets);cd(h.data.targets);I({withTransition:!1,withUpdateXDomain:!0});if(le){if(B&& "string"===typeof Da){Da=na(Da);for(a=0;aOb(c,a)?p.select(".event-rect").style("cursor","pointer"):p.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;D(h.data.targets)||(a=d.mouse(this),c=Mc(h.data.targets,a),100>Ob(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){ed(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){fd(d.mouse(this))}).on("dragstart", function(){gd(d.mouse(this))}).on("dragend",function(){hd()})).call(E).on("dblclick.zoom",null)}function ed(a,b,c){var e=d.select(a),f=e.classed(ha),g=!1,h;"circle"===a.nodeName?(g=Uc(a,1.5*Qa),h=Xc):"rect"===a.nodeName&&(g=Vc(a),h=Zc);if(qa||g)fa&&ga(b)&&(e.classed(ha,!f),h(!f,e,b,c)),qe(b,e)}function fd(a){var b,c,e,f,g,m,p;D(h.data.targets)||!fa||pa&&!E.altDomain||(b=cc[0],c=cc[1],e=a[0],a=a[1],f=Math.min(b,e),g=Math.max(b,e),m=qa?n:Math.min(c,a),p=qa?s:Math.max(c,a),l.select(".dragarea").attr("x", f).attr("y",m).attr("width",g-f).attr("height",p-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(dc),l,n,q,r;l=!1;"circle"===this.nodeName?(l=1*c.attr("cx"),n=1*c.attr("cy"),r=Xc,l=f",c,d,f;for(c=0;c"+f+""+d+"");return b+""}), le=f(["tooltip","init","show"],!1),Da=f(["tooltip","init","x"],0),dd=f(["tooltip","init","position"],{top:"0px",left:"50px"}),Xb=ta.replace("#","")+"-clip",Ra="url(#"+Xb+")",B="timeseries"===kd,ea="categorized"===kd,Nb=!B&&(oa||$),cc=null,Sa=!1,bc=!1,la=Ca?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]}}(ye,ze), sd=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)}}(),r,Cb,s,eb,zb,sa,Ga,Db,Eb,kb,pc,qc,Lb,Fb,Gb,Hb,Ib,Jb,Kb,m,z,Z,V,hb,ib,J,va,jb,gb,nd=g?"left":"bottom",od=g?bb?"top":"bottom":bb?"right":"left",pd=g?db?"bottom":"top":db?"left":"right",qd=g?"left":"bottom",M={main:function(){return"translate("+A+","+n+")"},context:function(){return"translate("+Fa+","+Ea+")"},legend:function(){return"translate("+jc+","+ic+")"},y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"}, x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+(g?0:eb)+")"},arc:function(){return"translate("+r/2+","+s/2+")"}},nc=40,mc=20;Lb=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var se=function(){var a=d.svg.line().x(g?function(a){return w(a.id)(a.value)}:wa).y(g?wa:function(a){return w(a.id)(a.value)});return function(b){var c=Sb(b.values),d;if(Pb(b))return Rc(b)?a.interpolate("cardinal"):a.interpolate("linear"),jd[b.id]?ae(c, m,w(b.id),jd[b.id]):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;a=g?d.svg.area().x0(function(a){return w(a.id)(0)}).x1(function(a){return w(a.id)(a.value)}).y(wa):d.svg.area().x(wa).y0(function(a){return w(a.id)(0)}).y1(function(a){return w(a.id)(a.value)});return function(b){var c=Sb(b.values),d;if(ma([b],"area")||ma([b],"area-spline"))return Rc(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}}(),ue=function(){var a=d.svg.line().x(g?function(a){return G(a.id)(a.value)}:Ic).y(g?Ic:function(a){return G(a.id)(a.value)});return function(b){var c=Sb(b.values);return Pb(b)?a(c):"M "+V(c[0].x)+" "+G(b.id)(c[0].value)}}(),L=d.svg.brush().on("brush",function(){I({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),E=d.behavior.zoom().on("zoomstart",function(){E.altDomain=d.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",pa?ve:null);L.update=function(){F&& F.select(".x.brush").call(this);return this};L.scale=function(a){return g?this.y(a):this.x(a)};E.scale=function(a){return g?this.y(a):this.x(a)};E.orgScaleExtent=function(){var a=id?id:[1,10];return[a[0],Math.max(fb()/a[1],a[1])]};E.updateScaleExtent=function(){var a=ua(m.orgDomain())/ua(U),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var p,ub,l,F,Ba,W,tb,U;h.focus=function(a){var b=p.selectAll(Va(a)),c=b.filter(gc),b=b.filter(hc);h.revert();h.defocus();c.classed("focused", !0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);D(h.data.targets)&&Za(a,!0);ec(a)};h.defocus=function(a){var b=p.selectAll(Va(a)),c=b.filter(gc),b=b.filter(hc);h.revert();c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);D(h.data.targets)&&xb(a);we(a)};h.revert=function(a){var b=p.selectAll(Va(a)),c=b.filter(gc),b=b.filter(hc);c.classed("focused",!1).transition().duration(100).style("opacity", 1);b.transition().duration(100).style("opacity",1);D(h.data.targets)&&xb(a);fc()};h.show=function(a){p.selectAll(Va(a)).transition().style("opacity",1)};h.hide=function(a){p.selectAll(Va(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&&Jd(a.xs);"categories"in a&&ea&&(Ha=a.categories,J.categories(Ha));if("cacheIds"in a&&Fd(a.cacheIds))Ta(Gd(a.cacheIds),a.done);else if("data"in a)Ta(La(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Ta(La(c),a.done)});else if("rows"in a)Ta(La(xc(a.rows)),a.done);else if("columns"in a)Ta(La(yc(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});p.selectAll(".target-"+a).transition().style("opacity",0).remove();Ca&&(p.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 u(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