Browse Source

Fix extent when resize and zoom on categorized axis

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
23508846c2
  1. 202
      c3.js
  2. 127
      c3.min.js

202
c3.js

@ -165,15 +165,13 @@
/*-- Set Chart Params --*/
var bottom, bottom2, right, left, top2, top3, margin, margin2, margin3, width, height, height2, height3;
var currentWidth, currentHeight;
var xMin, xMax, yMin, yMax, x, y, y2, subX, subY, subY2;
var bottom, bottom2, right, left, top2, top3, margin, margin2, margin3, width, height, height2, height3, currentWidth, currentHeight;
var xMin, xMax, yMin, yMax, x, y, y2, subX, subY, subY2, xAxis, yAxis, yAxis2, subXAxis;
// TODO: Enable set position
var xAxis = isCategorized ? categoryAxis() : d3.svg.axis(),
yAxis = d3.svg.axis(),
yAxis2 = d3.svg.axis(),
subXAxis = isCategorized ? categoryAxis() : d3.svg.axis();
var xOrient = __axis_rotated ? "left" : "bottom",
yOrient = __axis_rotated ? (__axis_y_inner ? "top" : "bottom") : (__axis_y_inner ? "right" : "left"),
y2Orient = __axis_rotated ? (__axis_y2_inner ? "bottom" : "top") : (__axis_y2_inner ? "left" : "right"),
subXOrient = "bottom";
function updateSizes () {
currentWidth = getCurrentWidth();
@ -195,53 +193,23 @@
updateSizes();
function updateScales () {
var _x, _y, _y2, _subX;
// update edges
xMin = __axis_rotated ? 10 : 0;
xMax = __axis_rotated ? height : width;
yMin = __axis_rotated ? 0 : height;
yMax = __axis_rotated ? width : 1;
// update scales
_x = getX(xMin, xMax);
_y = getY(yMin, yMax);
_y2 = getY(yMin, yMax);
_subX = getX(0, width);
x = isDefined(x) ? _x.domain(x.domain()) : _x;
y = isDefined(y) ? _y.domain(y.domain()) : _y;
y2 = isDefined(y2) ? _y2.domain(y2.domain()) : _y2;
subX = isDefined(subX) ? _subX.domain(subX.domain()) : _subX;
x = getX(xMin, xMax, isDefined(x) ? x.domain() : undefined, function(d){ return xAxis.tickOffset() });
y = getY(yMin, yMax, isDefined(y) ? y.domain() : undefined);
y2 = getY(yMin, yMax, isDefined(y2) ? y2.domain() : undefined);
subX = getX(0, width, isDefined(orgXDomain) ? orgXDomain : undefined, function(d){ return d % 1 === 0 ? subXAxis.tickOffset() : 0 });
subY = getY(height2, 10);
subY2 = getY(height2, 10);
// update axies
xAxis.scale(x).orient(__axis_rotated ? "left" : "bottom");
yAxis.scale(y).orient(__axis_rotated ? (__axis_y_inner ? "top" : "bottom") : (__axis_y_inner ? "right" : "left"));
yAxis2.scale(y2).orient(__axis_rotated ? (__axis_y2_inner ? "bottom" : "top") : (__axis_y2_inner ? "left" : "right"));
subXAxis.scale(subX).orient("bottom");
// Use custom scale if needed
if (isCategorized) {
// TODO: fix this
// TODO: fix x_grid
(function () {
var _x = x, _subX = subX;
var keys = Object.keys(x), key, i;
x = function(d){ return _x(d) + xAxis.tickOffset(); };
subX = function(d){ return _subX(d) + subXAxis.tickOffset(); };
for (i = 0; i < keys.length; i++) {
key = keys[i];
x[key] = _x[key];
subX[key] = _subX[key];
}
x.domain = function (domain) {
if (!arguments.length) {
var domain = _x.domain();
domain[1]++;
return domain;
}
_x.domain(domain);
return x;
};
})();
}
xAxis = getXAxis(x, xOrient);
yAxis = getYAxis(y, yOrient);
yAxis2 = getYAxis(y2, y2Orient);
subXAxis = getXAxis(subX, subXOrient);
};
updateScales();
@ -254,24 +222,6 @@
subx : function () { return "translate(0," + height2 + ")" }
}
// Set up axies
if (isTimeSeries) {
xAxis.tickFormat(customTimeFormat);
}
if (isCategorized) {
xAxis.categories(__axis_x_categories).tickCentered(__axis_x_tick_centered);
subXAxis.categories(__axis_x_categories).tickCentered(__axis_x_tick_centered);
} else {
// TODO: fix
xAxis.tickOffset = function () {
return 0;
};
// TODO: fix
subXAxis.tickOffset = function () {
return 0;
};
}
// For main region
var lineOnMain = (function () {
var line = d3.svg.line()
@ -386,13 +336,56 @@
//-- Scale --//
function getX (min, max) {
return ((isTimeSeries) ? d3.time.scale() : d3.scale.linear()).range([min, max]);
function getX (min, max, domain, offset) {
var scale = ((isTimeSeries) ? d3.time.scale() : d3.scale.linear()).range([min, max]);
// Set function and values for c3
scale.orgDomain = function () { return scale.domain(); }
if (isDefined(domain)) scale.domain(domain);
if (isUndefined(offset)) offset = function(d){ return 0; };
// Define customized scale if categorized axis
if (isCategorized) {
var _scale = scale, key;
scale = function(d){ return _scale(d) + offset(d); };
for (key in _scale) {
scale[key] = _scale[key];
}
scale.orgDomain = function () {
return _scale.domain();
};
scale.domain = function (domain) {
if (!arguments.length) {
var domain = _scale.domain();
return [domain[0], domain[1]+1];
}
_scale.domain(domain);
return scale;
};
}
return scale;
}
function getY (min, max) {
return d3.scale.linear().range([min, max]);
}
//-- Axis --//
function getXAxis (scale, orient) {
var axis = (isCategorized ? categoryAxis() : d3.svg.axis()).scale(scale).orient(orient);
if (isTimeSeries) {
axis.tickFormat(customTimeFormat);
}
if (isCategorized) {
axis.categories(__axis_x_categories).tickCentered(__axis_x_tick_centered);
} else {
// TODO: fix
axis.tickOffset = function () { return 0; }
}
return axis;
}
function getYAxis (scale, orient) {
return d3.svg.axis().scale(scale).orient(orient);
}
//-- Domain --//
function getYDomainMin (targets) {
@ -1277,7 +1270,7 @@
// ATTENTION: call here to update tickOffset
if (withUpdateXDomain) {
x.domain(brush.empty() ? subX.domain() : brush.extent());
x.domain(brush.empty() ? orgXDomain : brush.extent());
if (__zoom_enabled) zoom.x(x);
}
y.domain(getYDomain(c3.data.targets, 'y'));
@ -1291,12 +1284,6 @@
subY.domain(y.domain());
subY2.domain(y2.domain());
// Update brush extent if zoom
if (__subchart_show && d3.event !== null && d3.event.type === 'zoom') {
brush.extent(x.domain());
if ( ! brush.empty()) context.select('.x.brush').call(brush);
}
// grid
if (__grid_x_show) {
if (__grid_x_type === 'year') {
@ -1394,33 +1381,45 @@
mainCircle.exit().remove();
// subchart
if (withSubchart && __subchart_show) {
// Update axis
// TODO: fix when rotated
context.select('.x.axis').transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : subXAxis);
// bars
barW = getBarW(subXAxis, barTargetsNum, true);
barH = getBarH(height2, true);
barX = getBarX(barW, barTargetsNum, barIndices, true);
barY = getBarY(barH, barIndices, false, true);
contextBar = context.selectAll('.-bars').selectAll('.-bar')
.data(barData);
contextBar.transition().duration(duration)
.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH);
contextBar.enter().append('rect')
.attr("class", classBar)
.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH)
.style("opacity", 0)
.transition()
.style('opacity', 1);
contextBar.exit().transition()
.style('opacity', 0)
.remove();
// lines
context.selectAll('.-line')
.transition().duration(duration)
.attr("d", lineOnSub);
if (__subchart_show) {
// reflect main chart to extent on subchart if zoomed
if (d3.event !== null && d3.event.type === 'zoom') {
brush.extent(x.orgDomain());
context.select('.x.brush').call(brush);
}
// update subchart elements if needed
if (withSubchart) {
// axies
// TODO: fix when rotated
context.select('.x.axis').transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : subXAxis);
// extent rect
if ( ! brush.empty()) {
brush.extent(x.orgDomain());
context.select('.x.brush').call(brush);
}
// bars
barW = getBarW(subXAxis, barTargetsNum, true);
barH = getBarH(height2, true);
barX = getBarX(barW, barTargetsNum, barIndices, true);
barY = getBarY(barH, barIndices, false, true);
contextBar = context.selectAll('.-bars').selectAll('.-bar')
.data(barData);
contextBar.transition().duration(duration)
.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH);
contextBar.enter().append('rect')
.attr("class", classBar)
.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH)
.style("opacity", 0)
.transition()
.style('opacity', 1);
contextBar.exit().transition()
.style('opacity', 0)
.remove();
// lines
context.selectAll('.-line')
.transition().duration(duration)
.attr("d", lineOnSub);
}
}
// circles for select
@ -1482,8 +1481,6 @@
updateScales();
// Set x for brush again because of scale update
brush.x(subX);
// Update extent width if extent specified
if ( ! brush.empty()) brush.extent(x.domain());
// Set x for zoom again because of scale update
if (__zoom_enabled) zoom.x(x);
// Update sizes
@ -1497,7 +1494,6 @@
// Update context sizes and positions
if (__subchart_show) {
context.select('.x.brush').selectAll('rect').attr('height', height2);
context.select('.x.brush').call(brush);
context.attr("transform", translate.context);
context.select('.x.axis').attr("transform", translate.subx);
}

127
c3.min.js vendored

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

Loading…
Cancel
Save