Browse Source

Add destory() as destructor and fix duplicated chart generation - #6

pull/8/merge
Masayuki Tanaka 11 years ago
parent
commit
a7e485a053
  1. 31
      c3.js
  2. 135
      c3.min.js

31
c3.js

@ -903,7 +903,6 @@
var firstDate = null, lastDate = null, orgXDomain;
function init(data) {
var targets = c3.data.targets = convertDataToTargets(data);
var grid, xgridLine;
var i;
@ -911,8 +910,13 @@
if (selectChart.empty()) {
window.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');
return;
} else {
selectChart.html("");
}
c3.data.x = undefined;
c3.data.targets = convertDataToTargets(data);
// TODO: set names if names not specified
// Init sizes and scales
@ -1326,10 +1330,10 @@
/*-- Legend Region --*/
if (__legend_show) { updateLegend(targets); }
if (__legend_show) { updateLegend(c3.data.targets); }
// Set targets
updateTargets(targets);
updateTargets(c3.data.targets);
// Draw with targets
redraw({withTransition: false, withUpdateXDomain: true});
@ -1338,18 +1342,23 @@
if (__tooltip_init_show) {
if (isTimeSeries && typeof __tooltip_init_x === 'string') {
__tooltip_init_x = parseDate(__tooltip_init_x);
for (i = 0; i < targets[0].values.length; i++) {
if ((targets[0].values[i].x - __tooltip_init_x) === 0) { break; }
for (i = 0; i < c3.data.targets[0].values.length; i++) {
if ((c3.data.targets[0].values[i].x - __tooltip_init_x) === 0) { break; }
}
__tooltip_init_x = i;
}
tooltip.html(__tooltip_contents(targets.map(function (d) {
tooltip.html(__tooltip_contents(c3.data.targets.map(function (d) {
return addName(d.values[__tooltip_init_x]);
})));
tooltip.style("top", __tooltip_init_position.top)
.style("left", __tooltip_init_position.left)
.style("visibility", "visible");
}
// Bind resize event
if (window.onresize == null) {
window.onresize = resize;
}
}
function redraw(options) {
@ -2009,6 +2018,13 @@
return targets.length > 0 ? targets[0] : undefined;
};
c3.destroy = function () {
c3.data.targets = undefined;
c3.data.x = undefined;
selectChart.html("");
window.onresize = null;
};
/*-- Load data and init chart with defined functions --*/
if ('url' in config.data) {
@ -2024,9 +2040,6 @@
throw Error('url or rows or columns is required.');
}
// Bind resize event
window.onresize = resize;
return c3;
};

135
c3.min.js vendored

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

Loading…
Cancel
Save