Quite good looking graph derived from d3.js http://c3js.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
34 KiB

(function(O){function wc(){function n(d,e){d.attr("transform",function(d){return"translate("+(e(d)+Z)+", 0)"})}function t(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function O(d){var e=d[0];d=d[d.length-1];return e<d?[e,d]:[d,e]}function Aa(d){for(var e=[],n=Math.ceil(d[0]);n<d[1];n++)e.push(n);0<e.length&&0<e[0]&&e.unshift(e[0]-(e[1]-e[0]));return e}function Ba(d){d=d<P.length?P[d]:d;return Q?Q(d):d}function m(m){m.each(function(){var m=d.select(this),ja=Aa(q.domain()),H=
m.selectAll(".tick.major").data(ja,String),C=H.enter().insert("g","path").attr("class","tick major").style("opacity",1E-6),D=d.transition(H.exit()).style("opacity",1E-6).remove(),R=d.transition(H).style("opacity",1),M,N=q.rangeExtent?q.rangeExtent():O(q.range()),m=m.selectAll(".domain").data([0]);m.enter().append("path").attr("class","domain");var m=d.transition(m),I=q.copy(),Q=this.__chart__||I;this.__chart__=I;C.append("line");C.append("text");var P=C.select("line"),ka=R.select("line"),$=H.select("text"),
Sa=C.select("text"),Ta=R.select("text");Z=(I(1)-I(0))/2;H=sa?0:Z;switch(aa){case "bottom":M=n;P.attr("y2",E);Sa.attr("y",Math.max(E,0)+e);ka.attr("x1",H).attr("x2",H).attr("y2",E);Ta.attr("x",0).attr("y",Math.max(E,0)+e);$.attr("dy",".71em").style("text-anchor","middle");$.text(function(d){return ja.length<S||0===d%Math.ceil(ja.length/S)?Ba(d):""});m.attr("d","M"+N[0]+","+A+"V0H"+N[1]+"V"+A);break;case "left":M=t,P.attr("x2",-E),Sa.attr("x",-(Math.max(E,0)+e)),ka.attr("x2",-E).attr("y2",0),Ta.attr("x",
-(Math.max(E,0)+e)).attr("y",Z),$.attr("dy",".32em").style("text-anchor","end"),$.text(function(d){return ja.length<S||0===d%Math.ceil(ja.length/S)?Ba(d):""}),m.attr("d","M"+-A+","+N[0]+"H0V"+N[1]+"H"+-A)}if(q.ticks)C.call(M,Q),R.call(M,I),D.call(M,I);else{var Ca=I.rangeBand()/2,D=function(d){return I(d)+Ca};C.call(M,D);R.call(M,D)}})}var q=d.scale.linear(),aa="bottom",E=6,A=6,e=3,sa=!1,S=10,Z=0,Q=null,P=[];m.scale=function(d){if(!arguments.length)return q;q=d;return m};m.orient=function(d){if(!arguments.length)return aa;
aa=d in{top:1,right:1,bottom:1,left:1}?d+"":"bottom";return m};m.categories=function(d){if(!arguments.length)return P;P=d;return m};m.tickCentered=function(d){if(!arguments.length)return sa;sa=d;return m};m.tickTextNum=function(d){if(!arguments.length)return S;S=d;return m};m.tickFormat=function(d){if(!arguments.length)return Q;Q=d;return m};m.tickOffset=function(){return Z};m.ticks=function(){};return m}function t(d){return"undefined"===typeof d}function n(d){return"undefined"!==typeof d}var hb=
O.c3={},d=O.d3;hb.generate=function(Y){var Fb,Gb,Aa,Ba,m,q,aa,E,A;function e(a,b){for(var c=Y,k=0;k<a.length;k++){if(!(a[k]in c))return b;c=c[a[k]]}return c}function sa(){ib=null===Ua?Z():Ua;ta=S();Ib=20+Jb+la;Kb=Lb?Lb:Mb?jb||f?1:40:20;Va=Nb?Nb:kb?1:40;Ob=ta-Jb-la;Pb=20+la;Qb=ta-la;q=0;aa=Kb;E=Ib;A=Va;Aa=Ob;Ba=Pb;m=Va;Fb=Qb;Gb=Va;r=ib-A-aa;u=ta-q-E;ma=ta-Aa-Ba}function S(){var a=null===Rb?+d.select(ua).style("height").replace("px",""):Rb;return 0<a?a:320}function Z(){return+d.select(ua).style("width").replace("px",
"")}function Q(){return r+2+A+aa}function P(){return 40}function ja(){return A+20}function hb(){return u-q+42}function Eb(){Sb=f?10:0;Tb=f?u:r;lb=f?0:u;mb=f?r:1;l=H(Sb,Tb,n(l)?l.domain():void 0,function(){return J.tickOffset()});y=C(lb,mb,n(y)?y.domain():void 0);T=C(lb,mb,n(T)?T.domain():void 0);ba=H(0,r,n(U)?U:void 0,function(a){return 0===a%1?Da.tickOffset():0});Wa=C(ma,10);Xa=C(ma,10);J=M(l,zc);na=d.svg.axis().scale(y).orient(Ac);Ya=d.svg.axis().scale(T).orient(Bc);Da=M(ba,Cc)}function H(a,b,c,
k){var p=(z?d.time.scale():d.scale.linear()).range([a,b]);p.orgDomain=function(){return p.domain()};n(c)&&p.domain(c);t(k)&&(k=function(){return 0});if(ca){var e=p,s,p=function(a){return e(a)+k(a)};for(s in e)p[s]=e[s];p.orgDomain=function(){return e.domain()};p.domain=function(a){if(!arguments.length)return a=e.domain(),[a[0],a[1]+1];e.domain(a);return p}}return p}function C(a,b){return d.scale.linear().range([a,b])}function D(a){return"y2"===N(a)?T:y}function R(a){return"y2"===N(a)?Xa:Wa}function M(a,
b){var c=(ca?wc():d.svg.axis()).scale(a).orient(b);c.tickFormat(I());ca?c.categories(Ea).tickCentered(Dc):c.tickOffset=function(){return 0};return c}function N(a){return a in Ub?Ub[a]:"y"}function I(){var a=z?Ec:ca?Fc:function(a){return a};Za&&(a="function"===typeof Za?Za:z?function(a){return d.time.format(Za)(a)}:a);return a}function xc(a){return d.min(a,function(a){return d.min(a.values,function(a){return a.value})})}function yc(a){var b={},c,k;a.forEach(function(a){b[a.id]=[];a.values.forEach(function(c){b[a.id].push(c.value)})});
for(c=0;c<w.length;c++)for(k=1;k<w[c].length;k++)Fa(w[c][k])&&(t(b[w[c][k]])||b[w[c][k]].forEach(function(a,d){N(w[c][k])===N(w[c][0])&&(b[w[c][0]][d]+=1*a)}));return d.max(Object.keys(b).map(function(a){return d.max(b[a])}))}function ka(a){var b=$a(function(b){return N(b.id)===a}),c="y2"===a?Gc:Hc,k="y2"===a?Ic:Jc,c=null!==c?c:xc(b),k=null!==k?k:yc(b),p=0.1*Math.abs(k-c),d=p,e=p,f="y2"===a?Kc:Lc;null!==f&&(c=Math.max(Math.abs(c),Math.abs(k)),k=c-f,c=f-c);"y"===a&&null!==Ga&&(d=n(Ga.top)?Ga.top:p,
e=n(Ga.bottom)?Ga.bottom:p);"y2"===a&&null!==Ha&&(d=n(Ha.top)?Ha.top:p,e=n(Ha.bottom)?Ha.bottom:p);return[Mc(b,"bar")?0:c-e,k+d]}function $(a){var b;a?(a=l.domain(),b=F.extent()):(a=U,b=l.domain());return(a[1]-a[0])/(b[1]-b[0])}function Sa(a){for(var b=0;b<a.length;b++)if(!(a[b]in ab))return!1;return!0}function Ta(a){for(var b=[],c=0;c<a.length;c++)a[c]in ab&&b.push(Vb(ab[a[c]]));return b}function Ca(a){return"start"in a?l(z?oa(a.start):a.start):0}function Hb(a){var b=Ca(a);a=("end"in a?l(z?oa(a.end):
a.end):r)-b;return 0>a?0:a}function nb(a){var b=Ia[a.id];a.name=n(b)?b:a.id;return a}function Wb(a){var b=a[0],c={},k=[],p,d;for(p=1;p<a.length;p++){c={};for(d=0;d<a[p].length;d++)c[b[d]]=a[p][d];k.push(c)}return k}function Xb(a){var b=[],c,k,d;for(c=0;c<a.length;c++)for(d=a[c][0],k=1;k<a[c].length;k++)t(b[k-1])&&(b[k-1]={}),b[k-1][d]=a[c][k];return b}function Ja(a){var b=d.keys(a[0]).filter(function(a){return a!==V}),c,k;if(z&&!V)return O.alert('data.x must be specified when axis.x.type == "timeseries"'),
[];ob&&t(g.data.x)&&(g.data.x=a.map(function(a){return a[V]}));c=0;a.forEach(function(a){if(z){if(!(V in a))throw Error("'"+V+"' must be included in data");k=oa(a[V]);if(null===k)throw Error("Failed to parse timeseries date in data");a.x=k}else a.x=ob?n(a[V])?a[V]:g.data.x[c]:c;null===bb&&(bb=new Date(a.x));pb=new Date(a.x);c++});b=b.map(function(b){var c=Nc(b);return{id:c,id_org:b,values:a.map(function(a){return{x:a.x,value:null===a[b]||isNaN(a[b])?null:+a[b],id:c}})}});b.forEach(function(a){ab[a.id_org]=
Vb(a)});return b}function Vb(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}}function va(){return d.max(g.data.targets,function(a){return a.values.length})}function qb(a){a=t(a)?g.data.targets:a;return a.map(function(a){return a.id})}function rb(a){var b=qb(),c;for(c=0;c<b.length;c++)if(b[c]===a)return!0;return!1}function $a(a){return n(a)?g.data.targets.filter(a):g.data.targets}function Fc(a){return a<Ea.length?Ea[a]:a}function sb(a){return"-shapes -shapes-"+
a.id}function Yb(a){return sb(a)+" -line -line-"+a.id}function Oc(a){return sb(a)+" -circles -circles-"+a.id}function Zb(a){return sb(a)+" -bars -bars-"+a.id}function Pc(a,b){return"-shape -shape-"+b+" -circle -circle-"+b}function $b(a,b){return"-shape -shape-"+b+" -bar -bar-"+b}function Qc(a,b){return"region region-"+b+" "+("classes"in a?[].concat(a.classes).join(" "):"")}function cb(a){return l(a.x)}function Ka(a){return l(z?oa(a.value):a.value)}function ac(a){return y(a.value)}function da(a){return l(a.x)}
function ea(a){return D(a.id)(a.value)}function Rc(){var a={},b=0,c,k;$a(Fa).forEach(function(d){for(c=0;c<w.length;c++)if(!(0>w[c].indexOf(d.id)))for(k=0;k<w[c].length;k++)if(w[c][k]in a){a[d.id]=a[w[c][k]];break}t(a[d.id])&&(a[d.id]=b++)});a.__max__=b-1;return a}function bc(a,b,c,k){var d=k?ba:l;return function(k){var e=k.id in c?c[k.id]:0;return d(k.x)-a*(b/2-e)}}function cc(a,b,c,k){var d=Object.keys(b);return function(e,f){var g=0,h=k?R(e.id):D(e.id);$a(Fa).forEach(function(c){c.id!==e.id&&b[c.id]===
b[e.id]&&d.indexOf(c.id)<d.indexOf(e.id)&&(g+=a(c.values[f]))});return c?g:h(e.value)-g}}function dc(a,b){var c=null===a?function(a){return a}:function(b){return a-b};return function(a){var d=b?R(a.id):D(a.id);return c(d(a.value))}}function tb(a,b){var c=t(a)?qb():a;"string"===typeof c&&(c=[c]);for(var d=0;d<c.length;d++)fa[c[d]]=b}function Mc(a,b){var c=!1;a.forEach(function(a){fa[a.id]===b&&(c=!0);a.id in fa||"line"!==b||(c=!0)});return c}function ub(a){a="string"===typeof a?a:a.id;return!(a in
fa)||"line"===fa[a]||"spline"===fa[a]}function Fa(a){return"bar"===fa["string"===typeof a?a:a.id]}function Sc(a){return ub(a)?a.values:[]}function ec(a){return Fa(a)?a.values:[]}function fc(a,b){var c=d.mouse(a),k=d.select(a),e=1*k.attr("cx"),k=1*k.attr("cy");return Math.sqrt(Math.pow(e-c[0],2)+Math.pow(k-c[1],2))<b}function gc(a){var b=d.mouse(a),c=d.select(a);a=1*c.attr("x");var k=1*c.attr("y"),c=1*c.attr("width");return a-10<b[0]&&b[0]<a+c+10&&k-10<b[1]}function Tc(a,b){var c;for(c=0;c<b.length;c++)if(b[c].start<
a&&a<=b[c].end)return!0;return!1}function hc(a,b,c){Uc(a,b);h.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).data([b]).enter().append("circle").attr("class",function(){return"selected-circle selected-circle-"+c}).attr("cx",f?ea:da).attr("cy",f?da:ea).attr("stroke",function(){return W(b.id)}).attr("r",1.4*La).transition().duration(100).attr("r",La)}function vb(a,b,c){Vc(a,b);h.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).transition().duration(100).attr("r",
0).remove()}function ic(a,b,c,d){a?hc(b,c,d):vb(b,c,d)}function Wc(){}function jc(){}function kc(a,b,c,d){}function lc(a){return a.filter(function(a){return null!==a.value})}function Xc(a,b,c,d){var e,g,s="M",h,l,v,m,r,q=[];if(n(d))for(e=0;e<d.length;e++)q[e]={},t(d[e].start)?q[e].start=a[0].x:q[e].start=z?oa(d[e].start):d[e].start,t(d[e].end)?q[e].end=a[a.length-1].x:q[e].end=z?oa(d[e].end):d[e].end;m=f?function(a){return c(a.value)}:function(a){return b(a.x)};r=f?function(a){return b(a.x)}:function(a){return c(a.value)};
d=z?function(a,d,e,k){var f=a.x.getTime();a=d.x-a.x;d=new Date(f+a*(e+k));return"M"+b(new Date(f+a*e))+" "+c(l(e))+" "+b(d)+" "+c(l(e+k))}:function(a,d,e,k){return"M"+b(h(e))+" "+c(l(e))+" "+b(h(e+k))+" "+c(l(e+k))};for(e=0;e<a.length;e++)if(t(q)||!Tc(a[e].x,q))s+=" "+m(a[e])+" "+r(a[e]);else{h=H(a[e-1].x,a[e].x);l=C(a[e-1].value,a[e].value);g=b(a[e].x)-b(a[e-1].x);v=c(a[e].value)-c(a[e-1].value);g=Math.sqrt(Math.pow(g,2)+Math.pow(v,2));v=2/g;var u=2*v;for(g=v;1>=g;g+=u)s+=d(a[e-1],a[e],g,v)}return s}
function wb(a){var b,c;db=d.select(ua);if(db.empty())O.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{db.html("");g.data.x=void 0;g.data.targets=Ja(a);sa();Eb();l.domain(d.extent(a.map(function(a){return a.x})));y.domain(ka("y"));T.domain(ka("y2"));ba.domain(l.domain());Wa.domain(y.domain());Xa.domain(T.domain());J.ticks(10>a.length?a.length:10);na.ticks(Yc).outerTickSize(0).tickFormat(Zc);Ya.ticks($c).outerTickSize(0).tickFormat(ad);
U=l.domain();F.x(ba);pa&&G.x(l);Ma=d.select(ua).append("svg").attr("width",r+A+aa).attr("height",u+q+E).on("mouseenter",bd).on("mouseleave",cd);eb=Ma.append("defs");eb.append("clipPath").attr("id",xb).append("rect").attr("y",q).attr("width",r).attr("height",u-q);eb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-A).attr("y",-20).attr("width",Q).attr("height",P);eb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-A+1).attr("y",q-1).attr("width",ja).attr("height",
hb);h=Ma.append("g").attr("transform",K.main);x=wa?Ma.append("g").attr("transform",K.context):null;xa=ya?Ma.append("g").attr("transform",K.legend):null;X=d.select(ua).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");h.append("g").attr("class","x axis").attr("clip-path",f?"":"url(#xaxis-clip)").attr("transform",K.x).call(f?na:J).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(dd);
h.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?J:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(ed);Mb&&h.append("g").attr("class","y2 axis").attr("transform",K.y2).call(Ya);b=h.append("g").attr("clip-path",Na).attr("class","grid");mc&&b.append("g").attr("class","xgrids");yb&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(yb).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",f?"":"rotate(-90)").attr("dx",f?0:-q).attr("dy",-6).text(function(a){return a.text}));fd&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",f?0:-10).attr("x2",f?r:-10).attr("y1",f?-10:q).attr("y2",f?-10:u);nc&&b.append("g").attr("class","ygrids");zb&&b.append("g").attr("class",
"ygrid-lines").selectAll("ygrid-line").data(zb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",Na).attr("class","regions");h.append("g").attr("clip-path",Na).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",pa?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",ga&&
qa?"pointer":null).on("mouseover",function(a,b){if(!fb){var c=g.data.targets.map(function(a){return nb(a.values[b])}),d,e;if(0<Object.keys(Ia).length){e=[];for(var l in Ia)for(d=0;d<c.length;d++)if(c[d].id===l){e.push(c[d]);c.shift(d);break}c=e.concat(c)}oc&&h.selectAll(".-circle-"+b).classed(ha,!0).attr("r",pc);h.selectAll(".-bar-"+b).classed(ha,!0);h.selectAll("line.xgrid-focus").style("visibility","visible").data([c[0]]).attr(f?"y1":"x1",cb).attr(f?"y2":"x2",cb)}}).on("mouseout",function(a,b){h.select("line.xgrid-focus").style("visibility",
"hidden");X.style("display","none");h.selectAll(".-circle-"+b).filter(function(){return d.select(this).classed(ha)}).classed(ha,!1).attr("r",Ab);h.selectAll(".-bar-"+b).classed(ha,!1)}).on("mousemove",function(a,b){var c=g.data.targets.map(function(a){return nb(a.values[b])});X.html(qc(c)).style("visibility","hidden").style("display","block");var e=X.property("offsetWidth"),n=X.property("offsetHeight");X.style("top",(d.mouse(this)[1]+15+n<S()?d.mouse(this)[1]+15:d.mouse(this)[1]-n)+"px").style("left",
f?d.mouse(this)[0]:l(c[0].x)+60+e<(null===Ua?Z():Ua)?l(c[0].x)+60+"px":l(c[0].x)-e+30+"px").style("visibility","visible");ga&&!fb&&(qa||h.selectAll(".-shape-"+b).filter(function(a){return ra(a)}).each(function(){var a=d.select(this).classed(ha,!0);"circle"===this.nodeName&&a.attr("r",pc);d.select(".event-rect-"+b).style("cursor",null)}).filter(function(){var a=d.select(this);if("circle"===this.nodeName)return fc(this,La);if("rect"===this.nodeName)return gc(this,a.attr("x"),a.attr("y"))}).each(function(){var a=
d.select(this);a.classed(ha)||(a.classed(ha,!0),"circle"===this.nodeName&&a.attr("r",La));d.select(".event-rect-"+b).style("cursor","pointer")}))}).on("click",function(a,b){Bb?Bb=!1:h.selectAll(".-shape-"+b).each(function(a){var c=d.select(this),e=c.classed(ia),k=!1,f;"circle"===this.nodeName?(k=fc(this,1.5*La),f=ic):"rect"===this.nodeName&&(k=gc(this),f=kc);if(qa||k)ga&&ra(a)&&(c.classed(ia,!e),f(!e,c,a,b)),gd(a,c)})}).call(d.behavior.drag().origin(Object).on("drag",function(){if(ga&&(!pa||G.altDomain)){var a=
Cb[0],b=Cb[1],c=d.mouse(this),e=c[0],c=c[1],f=Math.min(a,e),g=Math.max(a,e),l=qa?q:Math.min(b,c),n=qa?u:Math.max(b,c);h.select(".dragarea").attr("x",f).attr("y",l).attr("width",g-f).attr("height",n-l);h.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ra(a)}).each(function(a,b){var c=d.select(this),e=c.classed(ia),k=c.classed(Db),h,p,s,m;h=!1;"circle"===this.nodeName?(h=1*c.attr("cx"),p=1*c.attr("cy"),m=ic,h=f<h&&h<g&&l<p&&p<n):"rect"===this.nodeName&&(h=1*c.attr("x"),p=1*c.attr("y"),
s=1*c.attr("width"),m=kc,h=f<h+s&&h<g&&p<n);h^k&&(c.classed(Db,!k),c.classed(ia,!e),m(!e,c,a,b))})}}).on("dragstart",function(){ga&&(Cb=d.mouse(this),h.select(".chart").append("rect").attr("class","dragarea").style("opacity",0.1),fb=!0)}).on("dragend",function(){ga&&(h.select(".dragarea").transition().duration(100).style("opacity",0).remove(),h.selectAll(".-shape").classed(Db,!1),fb=!1)})).call(G).on("dblclick.zoom",null);h.select(".chart").append("g").attr("class","chart-bars");h.select(".chart").append("g").attr("class",
"chart-lines");if(pa)h.insert("rect",hd?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",u).style("opacity",0).style("cursor","ew-resize").call(G).on("dblclick.zoom",null);null!==Oa&&F.extent("function"!==typeof Oa?Oa:z?Oa(bb,pb):Oa(0,va()-1));wa&&(x.append("g").attr("clip-path",Na).attr("class","chart"),x.select(".chart").append("g").attr("class","chart-bars"),x.select(".chart").append("g").attr("class","chart-lines"),x.append("g").attr("clip-path",Na).attr("class","x brush").call(F).selectAll("rect").attr("height",
ma),x.append("g").attr("class","x axis").attr("transform",K.subx).call(Da));ya&&gb(g.data.targets);rc(g.data.targets);B({withTransition:!1,withUpdateXDomain:!0});if(id){if(z&&"string"===typeof za){za=oa(za);for(a=0;a<g.data.targets[0].values.length&&0!==g.data.targets[0].values[a].x-za;a++);za=a}X.html(qc(g.data.targets.map(function(a){return nb(a.values[za])})));X.style("top",sc.top).style("left",sc.left).style("display","block")}null==O.onresize&&(O.onresize=jd)}}function B(a){var b,c,e=Rc(),p=
e.__max__+1,m,s,t,w,v;a=n(a)?a:{};b=n(a.withY)?a.withY:!0;w=n(a.withSubchart)?a.withSubchart:!0;v=n(a.withTransition)?a.withTransition:!0;a=n(a.withUpdateXDomain)?a.withUpdateXDomain:!1;v=v?250:0;a&&(l.domain(F.empty()?U:F.extent()),pa&&G.x(l).updateScaleExtent());y.domain(ka("y"));T.domain(ka("y2"));h.select(".x.axis").transition().duration(f?v:0).call(f?na:J);h.select(".y.axis").transition().duration(f?0:v).call(f?J:na);h.select(".y2.axis").transition().call(Ya);h.select(".x.axis .-axis-x-label").attr("x",
r);Wa.domain(y.domain());Xa.domain(T.domain());X.style("display","none");h.select("line.xgrid-focus").style("visibility","hidden").attr("y2",u);if(mc){if("year"===kd)for(a=[],s=bb.getFullYear(),m=pb.getFullYear();s<=m;s++)a.push(new Date(s+"-01-01 00:00:00"));else a=l.ticks(10);a=h.select(".xgrids").selectAll(".xgrid").data(a);a.enter().append("line").attr("class","xgrid");a.exit().remove();h.selectAll(".xgrid").attr("x1",function(a){return l(a)-J.tickOffset()}).attr("x2",function(a){return l(a)-
J.tickOffset()}).attr("y1",q).attr("y2",u)}yb&&(a=h.selectAll(".xgrid-lines"),a.selectAll("line").attr("x1",f?0:Ka).attr("x2",f?r:Ka).attr("y1",f?Ka:q).attr("y2",f?Ka:u),a.selectAll("text").attr("x",f?r:0).attr("y",Ka));b&&nc&&(a=h.select(".ygrids").selectAll(".ygrid").data(y.ticks(10)),a.enter().append("line").attr("class","ygrid"),a.attr("x1",f?y:0).attr("x2",f?y:r).attr("y1",f?0:y).attr("y2",f?u:y).attr("opacity",0).transition().attr("opacity",1),a.exit().remove());b&&zb&&h.select(".ygrid-lines").selectAll(".ygrid-line").attr("y1",
ac).attr("y2",ac);m=ca?1.2*J.tickOffset()/p:0.6*((f?u:r)*$(!1)/(va()-1));s=dc(f?null:u);b=bc(m,p,e);a=cc(s,e,f);c=h.selectAll(".-bars").selectAll(".-bar").data(ec);c.transition().duration(v).attr("x",f?a:b).attr("y",f?b:a).attr("width",f?s:m).attr("height",f?m:s);c.enter().append("rect").attr("class",$b).attr("x",f?a:b).attr("y",f?b:a).attr("width",f?s:m).attr("height",f?m:s).style("opacity",0).transition().duration(v).style("opacity",1);c.exit().transition().duration(v).style("opacity",0).remove();
h.selectAll(".-line").transition().duration(v).attr("d",ld);b=h.selectAll(".-circles").selectAll(".-circle").data(Sc);b.transition().duration(v).style("opacity",function(a){return null===a.value?0:1}).attr("cx",f?ea:da).attr("cy",f?da:ea);b.enter().append("circle").style("opacity",function(a){return null===a.value?0:1}).attr("class",Pc).attr("cx",f?ea:da).attr("cy",f?da:ea).attr("r",Ab);b.exit().remove();wa&&(null!==d.event&&"zoom"===d.event.type&&F.extent(l.orgDomain()).update(),w&&(x.select(".x.axis").transition().duration(f?
v:0).call(f?na:Da),F.empty()||F.extent(l.orgDomain()).update(),m=ca?1.2*Da.tickOffset()/p:0.6*((f?u:r)*$(!0)/(va()-1)),s=dc(ma,!0),b=bc(m,p,e,!0),a=cc(s,e,!1,!0),e=x.selectAll(".-bars").selectAll(".-bar").data(ec),e.transition().duration(v).attr("x",b).attr("y",a).attr("width",m).attr("height",s),e.enter().append("rect").attr("class",$b).attr("x",b).attr("y",a).attr("width",m).attr("height",s).style("opacity",0).transition().style("opacity",1),e.exit().transition().style("opacity",0).remove(),x.selectAll(".-line").transition().duration(v).attr("d",
md)));h.selectAll(".selected-circles").filter(function(a){return Fa(a)}).selectAll("circle").remove();h.selectAll(".selected-circle").transition().duration(v).attr("cx",f?ea:da).attr("cy",f?da:ea);ob?(t=function(a,b){var c=0<b?g.data.targets[0].values[b-1].x:void 0,d=b<va()-1?g.data.targets[0].values[b+1].x:void 0;return(l(d?d:a.x+50)-l(c?c:a.x-50))/2},e=function(a,b){var c=0<b?g.data.targets[0].values[b-1].x:void 0;return(l(a.x)+l(c?c:a.x-50))/2}):(t=(f?u:r)*$()/(va()-1),e=function(a){return l(a.x)-
t/2});h.selectAll(".event-rect").attr("x",f?0:e).attr("y",f?e:0).attr("width",f?r:t).attr("height",f?t:u);e=h.select(".regions").selectAll("rect.region").data(L);e.enter().append("rect");e.attr("class",Qc).attr("x",f?0:Ca).attr("y",f?Ca:q).attr("width",f?r:Hb).attr("height",f?Hb:u).style("fill-opacity",function(a){return n(a.opacity)?a.opacity:0.1});e.exit().transition().duration(v).style("fill-opacity",0).remove()}function nd(){"mousemove"===d.event.sourceEvent.type&&G.altDomain?(l.domain(G.altDomain),
G.x(l).updateScaleExtent()):(ca&&l.orgDomain()[0]===U[0]&&l.domain([U[0]-1E-10,l.orgDomain()[1]]),B({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===d.event.sourceEvent.type&&(Bb=!0))}function jd(){sa();Eb();F.x(ba);pa&&G.x(l);d.select("svg").attr("width",ib).attr("height",ta);d.select("#"+xb).select("rect").attr("width",r).attr("height",u);d.select("#xaxis-clip").select("rect").attr("width",Q);d.select(".zoom-rect").attr("width",r).attr("height",u);h.select(".x.axis").attr("transform",
K.x);h.select(".y2.axis").attr("transform",K.y2);wa&&(x.select(".x.brush").selectAll("rect").attr("height",ma),x.attr("transform",K.context),x.select(".x.axis").attr("transform",K.subx));ya&&(xa.attr("transform",K.legend),gb(g.data.targets,{withTransition:!1}));B({withTransition:!1,withUpdateXDomain:!0})}function rc(a){var b;h.select(".chart-bars").selectAll(".chart-bar").data(a).enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("pointer-events","none").style("opacity",
0).append("g").attr("class",Zb).style("fill",function(a){return W(a.id)}).style("stroke",function(a){return W(a.id)}).style("stroke-width",0).style("cursor",function(a){return ra(a)?"pointer":null});b=h.select(".chart-lines").selectAll(".chart-line").data(a).enter().append("g").attr("class",function(a){return"chart-line target target-"+a.id}).style("pointer-events","none").style("opacity",0);b.append("path").attr("class",Yb).style("stroke",function(a){return W(a.id)});b.append("g").attr("class",function(a){return"selected-circles selected-circles-"+
a.id});b.append("g").attr("class",Oc).style("fill",function(a){return W(a.id)}).style("cursor",function(a){return ra(a)?"pointer":null});a.forEach(function(a){h.selectAll(".selected-circles-"+a.id).selectAll(".selected-circle").each(function(b){b.value=a.values[b.x].value})});wa&&(b=x.select(".chart-bars").selectAll(".chart-bar").data(a),b=b.enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("opacity",0),b.append("g").attr("class",Zb).style("fill",function(a){return W(a.id)}),
b=x.select(".chart-lines").selectAll(".chart-line").data(a),b=b.enter().append("g").attr("class",function(a){return"chart-line target target-"+a.id}).style("opacity",0),b.append("path").attr("class",Yb).style("stroke",function(a){return W(a.id)}));ya&&gb(a);d.selectAll(".target").transition().style("opacity",1)}function Pa(a,b){g.data.targets.forEach(function(b){for(var d=0;d<a.length;d++)if(b.id===a[d].id){b.values=a[d].values;a.splice(d,1);break}});g.data.targets=g.data.targets.concat(a);rc(g.data.targets);
B();b()}function gb(a,b){var c=qb(a),e,f=r/2-Qa*Object.keys(a).length/2,h;b=t(b)?{}:b;h=n(b.withTransition)?b.withTransition:!0;e=xa.selectAll(".legend-item").data(c).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+a}).style("cursor","pointer").on("click",function(a){od(a)}).on("mouseover",function(a){d.selectAll(".legend-item").filter(function(b){return b!==a}).transition().duration(100).style("opacity",0.3);g.focus(a)}).on("mouseout",function(){d.selectAll(".legend-item").transition().duration(100).style("opacity",
1);g.revert()});e.append("rect").attr("class","legend-item-event").style("fill-opacity",0).attr("x",-200).attr("y",function(){return la/2-16}).attr("width",Qa).attr("height",24);e.append("rect").attr("class","legend-item-tile").style("fill",function(a){return W(a)}).attr("x",-200).attr("y",function(){return la/2-9}).attr("width",10).attr("height",10);e.append("text").text(function(a){return n(Ia[a])?Ia[a]:a}).attr("x",-200).attr("y",function(){return la/2});xa.selectAll("rect.legend-item-event").data(c).transition().duration(h?
250:0).attr("x",function(a,b){return f+Qa*b});xa.selectAll("rect.legend-item-tile").data(c).transition().duration(h?250:0).attr("x",function(a,b){return f+Qa*b});xa.selectAll("text").data(c).transition().duration(h?250:0).attr("x",function(a,b){return f+Qa*b+14})}function Ra(a){return n(a)?".target-"+a:".target"}var g={data:{}},ab={},ha="_expanded_",ia="_selected_",Db="_included_",ua=e(["bindto"],"#chart"),Ua=e(["size","width"],null),Rb=e(["size","height"],null),Nb=e(["padding","left"],null),Lb=e(["padding",
"right"],null),pa=e(["zoom","enabled"],!1),tc=e(["zoom","extent"],null),hd=e(["zoom","privileged"],!1),bd=e(["onenter"],function(){}),cd=e(["onleave"],function(){});if(!("data"in Y))throw Error("data is required in config");var V=e(["data","x"],void 0),pd=e(["data","x_format"],"%Y-%m-%d"),Nc=e(["data","id_converter"],function(a){return a}),Ia=e(["data","names"],{}),w=e(["data","groups"],[]),Ub=e(["data","axes"],{}),fa=e(["data","types"],{}),uc=e(["data","regions"],{}),qd=e(["data","colors"],{}),ga=
e(["data","selection","enabled"],!1),qa=e(["data","selection","grouped"],!1),ra=e(["data","selection","isselectable"],function(){return!0}),wa=e(["subchart","show"],!1),Jb=wa?e(["subchart","size","height"],60):0,rd=e(["color","pattern"],null),ya=e(["legend","show"],!0),Qa=e(["legend","item","width"],80),od=e(["legend","item","onclick"],function(){}),vc=e(["axis","x","type"],"indexed"),Ea=e(["axis","x","categories"],[]),Dc=e(["axis","x","tick","centered"],!1),Za=e(["axis","x","tick","format"],null),
Oa=e(["axis","x","default"],null),dd=e(["axis","x","label"],null),Jc=e(["axis","y","max"],null),Hc=e(["axis","y","min"],null),Lc=e(["axis","y","center"],null),ed=e(["axis","y","label"],null),kb=e(["axis","y","inner"],!1),Zc=e(["axis","y","format"],function(a){return a}),Ga=e(["axis","y","padding"],null),Yc=e(["axis","y","ticks"],10),Mb=e(["axis","y2","show"],!1),Ic=e(["axis","y2","max"],null),Gc=e(["axis","y2","min"],null),Kc=e(["axis","y2","center"],null),jb=e(["axis","y2","inner"],!1),ad=e(["axis",
"y2","format"],function(a){return a}),Ha=e(["axis","y2","padding"],null),$c=e(["axis","y2","ticks"],10),f=e(["axis","rotated"],!1),mc=e(["grid","x","show"],!1),kd=e(["grid","x","type"],"tick"),yb=e(["grid","x","lines"],null),nc=e(["grid","y","show"],!1),zb=e(["grid","y","lines"],null),Ab=e(["point","show"],!0)?e(["point","r"],2.5):0,fd=e(["point","focus","line","enabled"],!0),oc=e(["point","focus","expand","enabled"],!0),pc=e(["point","focus","expand","r"],oc?4:Ab),La=e(["point","focus","select",
"r"],8),gd=e(["point","onclick"],function(){}),Uc=e(["point","onselected"],function(){}),Vc=e(["point","onunselected"],function(){}),L=e(["regions"],[]),qc=e(["tooltip","contents"],function(a){var b="<table class='-tooltip'><tr><th colspan='2'>"+I()(a[0].x)+"</th></tr>",c,d,e;for(c=0;c<a.length;c++)n(a[c])?(d=n(a[c].value)?(Math.round(100*a[c].value)/100).toFixed(2):"-",e=a[c].name):e=d="-",b+="<tr class='-tooltip-name-"+a[c].id+"'><td class='name'><span style='background-color:"+W(a[c].id)+"'></span>"+
e+"</td><td class='value'>"+d+"</td></tr>";return b+"</table>"}),id=e(["tooltip","init","show"],!1),za=e(["tooltip","init","x"],0),sc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),xb=ua.replace("#","")+"-clip",Na="url(#"+xb+")",z="timeseries"===vc,ca="categorized"===vc,ob=!z&&V,Cb=null,fb=!1,Bb=!1,la=ya?40:0,oa=d.time.format(pd).parse,W=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]}}(qd,rd),Ec=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)}}(),Ib,Pb,Kb,Va,Ob,Qb,r,u,ma,ib,ta,Sb,Tb,lb,mb,l,y,T,ba,Wa,Xa,J,na,Ya,Da,zc=f?"left":"bottom",Ac=f?kb?"top":"bottom":kb?"right":"left",Bc=f?jb?"bottom":"top":jb?"left":"right",Cc="bottom",K={main:function(){return"translate("+A+","+q+")"},context:function(){return"translate("+m+","+Aa+")"},legend:function(){return"translate("+Gb+","+Fb+")"},y2:function(){return"translate("+
(f?0:r)+","+(f?10:0)+")"},x:function(){return"translate(0,"+u+")"},subx:function(){return"translate(0,"+ma+")"}},ld=function(){var a=d.svg.line().x(f?function(a){return D(a.id)(a.value)}:cb).y(f?cb:function(a){return D(a.id)(a.value)});return function(b){var c=lc(b.values),d;if(ub(b))return"spline"===fa["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0<Object.keys(uc).length?Xc(c,l,D(b.id),uc[b.id]):a(c);d=l(c[0].x);b=D(b.id)(c[0].value);return f?"M "+b+" "+d:"M "+d+
" "+b}}(),md=function(){var a=d.svg.line().x(function(a){return ba(a.x)}).y(function(a){return R(a.id)(a.value)});return function(b){var c=lc(b.values);return ub(b)?a(c):"M "+ba(c[0].x)+" "+R(b.id)(c[0].value)}}(),F=d.svg.brush().on("brush",function(){B({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),G=d.behavior.zoom().on("zoomstart",function(){G.altDomain=d.event.sourceEvent.altKey?l.orgDomain():null}).on("zoom",pa?nd:null);F.update=function(){x&&x.select(".x.brush").call(this);
return this};G.orgScaleExtent=function(){var a=tc?tc:[1,10];return[a[0],Math.max(va()/a[1],a[1])]};G.updateScaleExtent=function(){var a=l.orgDomain(),a=(a[1]-a[0])/(U[1]-U[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var Ma,eb,h,x,xa,X,db,bb=null,pb=null,U;g.focus=function(a){g.defocus();d.selectAll(Ra(a)).filter(function(a){return rb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};g.defocus=function(a){d.selectAll(Ra(a)).filter(function(a){return rb(a.id)}).classed("focused",
!1).transition().duration(100).style("opacity",0.3)};g.revert=function(a){d.selectAll(Ra(a)).filter(function(a){return rb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};g.show=function(a){d.selectAll(Ra(a)).transition().style("opacity",1)};g.hide=function(a){d.selectAll(Ra(a)).transition().style("opacity",0)};g.unzoom=function(){F.clear().update();B({withUpdateXDomain:!0})};g.load=function(a){t(a.done)&&(a.done=function(){});"categories"in a&&ca&&(Ea=a.categories,J.categories(Ea));
if("cacheIds"in a&&Sa(a.cacheIds))Pa(Ta(a.cacheIds),a.done);else if("data"in a)Pa(Ja(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Pa(Ja(c),a.done)});else if("rows"in a)Pa(Ja(Wb(a.rows)),a.done);else if("columns"in a)Pa(Ja(Xb(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();ya&&(d.selectAll(".legend-item-"+
a).remove(),gb(g.data.targets));0<g.data.targets.length&&B()};g.selected=function(a){a=n(a)?"-"+a:"";return d.merge(h.selectAll(".-shapes"+a).selectAll(".-shape").filter(function(){return d.select(this).classed(ia)}).map(function(a){return a.map(function(a){return a.__data__})}))};g.select=function(a,b,c){ga&&h.selectAll(".-shapes").selectAll(".-shape").each(function(e,f){var g="circle"===this.nodeName?hc:Wc,h="circle"===this.nodeName?vb:jc;0<=b.indexOf(f)?ra(e)&&(qa||t(a)||0<=a.indexOf(e.id))&&g(d.select(this).classed(ia,
!0),e,f):n(c)&&c&&h(d.select(this).classed(ia,!1),e,f)})};g.unselect=function(a,b){ga&&h.selectAll(".-shapes").selectAll(".-shape").each(function(c,e){var f="circle"===this.nodeName?vb:jc;(t(b)||0<=b.indexOf(e))&&ra(c)&&(qa||t(a)||0<=a.indexOf(c.id))&&f(d.select(this).classed(ia,!1),c,e)})};g.toLine=function(a){tb(a,"line");B()};g.toSpline=function(a){tb(a,"spline");B()};g.toBar=function(a){tb(a,"bar");B()};g.groups=function(a){if(t(a))return w;w=a;B();return w};g.regions=function(a){if(t(a))return L;
L=a;B();return L};g.regions.add=function(a){if(t(a))return L;L=L.concat(a);B();return L};g.regions.remove=function(a,b){var c=[].concat(a);b=n(b)?b:{};c.forEach(function(a){var c=d.selectAll("."+a);n(b.duration)&&(c=c.transition().duration(b.duration).style("fill-opacity",0));c.remove();L=L.filter(function(b){return 0>b.classes.indexOf(a)})});return L};g.data.get=function(a){a=g.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};g.data.getAsTarget=function(a){var b=
$a(function(b){return b.id===a});return 0<b.length?b[0]:void 0};g.destroy=function(){g.data.targets=void 0;g.data.x=void 0;db.html("");O.onresize=null};if("url"in Y.data)d.csv(Y.data.url,function(a,b){wb(b)});else if("rows"in Y.data)wb(Wb(Y.data.rows));else if("columns"in Y.data)wb(Xb(Y.data.columns));else throw Error("url or rows or columns is required.");return g}})(window);