Browse Source

Fix height and brush extent when resized

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
318f706c26
  1. 119
      c3.js
  2. 126
      c3.min.js

119
c3.js

@ -31,7 +31,7 @@
var __bindto = getConfig(['size','width'], '#chart');
var __size_width = getConfig(['size','width'], null),
__size_height = getConfig(['size','height'], 280);
__size_height = getConfig(['size','height'], null);
var __zoom_enabled = getConfig(['zoom','enabled'], false);
@ -165,7 +165,8 @@
/*-- Set Chart Params --*/
var bottom, bottom2, right, top2, top3, margin, margin2, margin3, width, height, height2, height3;
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;
// TODO: Enable set position
@ -175,19 +176,21 @@
subXAxis = isCategorized ? categoryAxis() : d3.svg.axis();
function updateSizes () {
bottom = 20 + __subchart_size_height + legendHeight,
right = __axis_y2_show && !__axis_rotated && !__axis_y2_inner ? 50 : 1,
left = __axis_y_inner ? 0 : 40,
top2 = __size_height - __subchart_size_height - legendHeight,
bottom2 = 20 + legendHeight,
top3 = __size_height - legendHeight,
margin = {top: 0, right: right, bottom: bottom, left: left},
margin2 = {top: top2, right: 20, bottom: bottom2, left: left},
margin3 = {top: top3, right: 20, bottom: 0, left: left},
width = (__size_width == null ? getParentWidth() : __size_width) - margin.left - margin.right,
height = __size_height - margin.top - margin.bottom,
height2 = __size_height - margin2.top - margin2.bottom,
height3 = __size_height - margin3.top - margin3.bottom;
currentWidth = getCurrentWidth();
currentHeight = getCurrentHeight();
bottom = 20 + __subchart_size_height + legendHeight;
right = __axis_y2_show && !__axis_rotated && !__axis_y2_inner ? 50 : 1;
left = __axis_y_inner ? 0 : 40;
top2 = currentHeight - __subchart_size_height - legendHeight;
bottom2 = 20 + legendHeight;
top3 = currentHeight - legendHeight;
margin = {top: 0, right: right, bottom: bottom, left: left};
margin2 = {top: top2, right: 20, bottom: bottom2, left: left};
margin3 = {top: top3, right: 20, bottom: 0, left: left};
width = currentWidth - margin.left - margin.right;
height = currentHeight - margin.top - margin.bottom;
height2 = currentHeight - margin2.top - margin2.bottom;
height3 = currentHeight - margin3.top - margin3.bottom;
}
updateSizes();
@ -242,6 +245,15 @@
};
updateScales();
var translate = {
main : function () { return "translate(" + margin.left + "," + margin.top + ")" },
context : function () { return "translate(" + margin2.left + "," + margin2.top + ")" },
legend : function () { return "translate(" + margin3.left + "," + margin3.top + ")" },
y2 : function () { return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 10 : 0) + ")" },
x : function () { return "translate(0," + height + ")" },
subx : function () { return "translate(0," + height2 + ")" }
}
// Set up axies
if (isTimeSeries) {
xAxis.tickFormat(customTimeFormat);
@ -335,16 +347,16 @@
// Define regions
var main = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
.attr("transform", translate.main);
var context = null;
if (__subchart_show) {
context = svg.append("g")
.attr("transform", "translate(" + margin2.left + "," + margin2.top + ")");
.attr("transform", translate.context);
}
var legend = null;
if (__legend_show) {
legend = svg.append("g")
.attr("transform", "translate(" + margin3.left + "," + margin3.top + ")");
.attr("transform", translate.legend);
}
// Define tooltip
@ -358,9 +370,17 @@
/*-- Define Functions --*/
function getCurrentWidth () {
return __size_width === null ? getParentWidth() : __size_width;
}
function getCurrentHeight () {
return __size_height === null ? getParentHeight() : __size_height;
}
function getParentWidth () {
// TODO: if rotated, use height
return +d3.select(__bindto).style("width").replace('px','');
return +d3.select(__bindto).style("width").replace('px',''); // TODO: if rotated, use height
}
function getParentHeight () {
return +d3.select(__bindto).style('height').replace('px',''); // TODO: if rotated, use width
}
//-- Scale --//
@ -848,10 +868,6 @@
var orgXDomain;
function translateForY2 () {
return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 10 : 0) + ")";
}
function init (data) {
var targets = c3.data.targets = convertDataToTargets(data);
var rectX, rectW;
@ -885,7 +901,7 @@
main.append("g")
.attr("class", "x axis")
.attr("clip-path", __axis_rotated ? "" : "url(#xaxis-clip)")
.attr("transform", "translate(0," + height + ")")
.attr("transform", translate.x)
.call(__axis_rotated ? yAxis : xAxis);
main.append("g")
.attr("class", "y axis")
@ -901,7 +917,7 @@
if (__axis_y2_show) {
main.append("g")
.attr("class", "y2 axis")
.attr("transform", translateForY2)
.attr("transform", translate.y2)
.call(yAxis2);
}
@ -1204,7 +1220,7 @@
// Add Axis
context.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height2 + ")")
.attr("transform", translate.subx)
.call(subXAxis);
}
@ -1243,6 +1259,7 @@
var barX, barY, barW, barH;
var rectX, rectW;
var withY, withSubchart, withTransition, withUpdateXDomain;
var duration;
// Hide tooltip and grid
main.select('line.xgrid-focus').style("visibility", "hidden");
@ -1254,6 +1271,8 @@
withTransition = isDefined(options.withTransition) ? options.withTransition : true;
withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : true;
duration = withTransition ? 250 : 0;
// ATTENTION: call here to update tickOffset
if (withUpdateXDomain) {
x.domain(brush.empty() ? subX.domain() : brush.extent());
@ -1262,9 +1281,9 @@
y.domain(getYDomain(c3.data.targets, 'y'));
y2.domain(getYDomain(c3.data.targets, 'y2'));
main.selectAll(".x.axis").transition().duration(__axis_rotated ? 250 : 0).call(__axis_rotated ? yAxis : xAxis);
main.selectAll(".y.axis").transition().duration(__axis_rotated ? 0 : 250).call(__axis_rotated ? xAxis : yAxis);
main.selectAll(".y2.axis").transition().call(yAxis2);
main.select(".x.axis").transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : xAxis);
main.select(".y.axis").transition().duration(__axis_rotated ? 0 : duration).call(__axis_rotated ? xAxis : yAxis);
main.select(".y2.axis").transition().call(yAxis2);
// Update sub domain
subY.domain(y.domain());
@ -1338,7 +1357,7 @@
barY = getBarY(barH, barIndices, __axis_rotated);
mainBar = main.selectAll('.-bars').selectAll('.-bar')
.data(barData);
mainBar.transition().duration(withTransition ? 250 : 0)
mainBar.transition().duration(duration)
.attr("x", __axis_rotated ? barY : barX)
.attr("y", __axis_rotated ? barX : barY)
.attr("width", __axis_rotated ? barH : barW)
@ -1350,19 +1369,19 @@
.attr("width", __axis_rotated ? barH : barW)
.attr("height", __axis_rotated ? barW : barH)
.style("opacity", 0)
.transition().duration(withTransition ? 250 : 0)
.transition().duration(duration)
.style('opacity', 1);
mainBar.exit().transition().duration(withTransition ? 250 : 0)
mainBar.exit().transition().duration(duration)
.style('opacity', 0)
.remove();
// lines and cricles
main.selectAll('.-line')
.transition().duration(withTransition ? 250 : 0)
.transition().duration(duration)
.attr("d", lineOnMain);
mainCircle = main.selectAll('.-circles').selectAll('.-circle')
.data(lineData);
mainCircle.transition().duration(withTransition ? 250 : 0)
mainCircle.transition().duration(duration)
.attr("cx", __axis_rotated ? circleY : circleX)
.attr("cy", __axis_rotated ? circleX : circleY);
mainCircle.enter().append("circle")
@ -1374,6 +1393,9 @@
// 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);
@ -1381,7 +1403,7 @@
barY = getBarY(barH, barIndices, false, true);
contextBar = context.selectAll('.-bars').selectAll('.-bar')
.data(barData);
contextBar.transition().duration(withTransition ? 250 : 0)
contextBar.transition().duration(duration)
.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH);
contextBar.enter().append('rect')
.attr("class", classBar)
@ -1395,7 +1417,7 @@
// lines
context.selectAll('.-line')
.transition().duration(withTransition ? 250 : 0)
.transition().duration(duration)
.attr("d", lineOnSub);
}
@ -1405,7 +1427,7 @@
.selectAll('circle')
.remove();
main.selectAll('.selected-circle')
.transition().duration(withTransition ? 250 : 0)
.transition().duration(duration)
.attr("cx", __axis_rotated ? circleY : circleX)
.attr("cy", __axis_rotated ? circleX : circleY);
@ -1429,7 +1451,7 @@
.attr("width", __axis_rotated ? width : regionWidth)
.attr("height", __axis_rotated ? regionWidth : height)
.style("fill-opacity", function(d){ return isDefined(d.opacity) ? d.opacity : .1; });
mainRegion.exit().transition().duration(withTransition ? 250 : 0)
mainRegion.exit().transition().duration(duration)
.style("fill-opacity", 0)
.remove();
}
@ -1456,15 +1478,24 @@
// Update sizes and scales
updateSizes();
updateScales();
// Set x for brush again because of scale update
brush.x(subX).extent(x.domain());
// Set x for zoom again because of scale update
if (__zoom_enabled) zoom.x(x);
// Resize svg
d3.select('svg').attr('width', width + margin.left + margin.right);
d3.select('#'+clipId).select('rect').attr('width', width);
// Update sizes
d3.select('svg').attr('width', currentWidth).attr('height', currentHeight);
d3.select('#'+clipId).select('rect').attr('width', width).attr('height', height);
d3.select('#xaxis-clip').select('rect').attr('width', width + 2);
d3.select('.zoom-rect').attr('width', width);
// Update Axis translate
d3.select('g.y2.axis').attr("transform", translateForY2)
context.select('.x.brush').selectAll('rect').attr('height', height2);
context.select('.x.brush').call(brush);
// Update g positions
context.attr("transform", translate.context);
legend.attr("transform", translate.legend);
// Update axis positions
main.select('.x.axis').attr("transform", translate.x);
main.select('.y2.axis').attr("transform", translate.y2);
context.select('.x.axis').attr("transform", translate.subx);
// Update legend
if (__legend_show) updateLegend(c3.data.targets, {withTransition:false});
// Draw with new sizes & scales

126
c3.min.js vendored

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

Loading…
Cancel
Save