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.
 
 
 
 

58 lines
29 KiB

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