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