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.

62 lines
30 KiB

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