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.

74 lines
36 KiB

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