Browse Source

Refactor

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
bf2d86d2cb
  1. 254
      c3.js
  2. 127
      c3.min.js

254
c3.js

@ -143,7 +143,12 @@
var legendHeight = __legend_show ? 40 : 0;
var customTimeFormat = timeFormat([
var parseDate = d3.time.format(__data_x_format).parse;
var color = generateColor(__data_colors, __color_pattern);
var customTimeFormat = (function () {
var formats = [
[d3.time.format("%Y/%-m/%-d"), function() { return true }],
[d3.time.format("%-m/%-d"), function(d) { return d.getMonth() }],
[d3.time.format("%-m/%-d"), function(d) { return d.getDate() != 1 }],
@ -152,16 +157,13 @@
[d3.time.format("%I:%M"), function(d) { return d.getMinutes() }],
[d3.time.format(":%S"), function(d) { return d.getSeconds() }],
[d3.time.format(".%L"), function(d) { return d.getMilliseconds() }]
]);
function timeFormat(formats) {
];
return function(date) {
var i = formats.length - 1, f = formats[i];
while (!f[1](date)) f = formats[--i];
return f[0](date);
};
}
var parseDate = d3.time.format(__data_x_format).parse;
})();
/*-- Set Chart Params --*/
@ -173,6 +175,19 @@
y2Orient = __axis_rotated ? (__axis_y2_inner ? "bottom" : "top") : (__axis_y2_inner ? "left" : "right"),
subXOrient = "bottom";
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 + ")" }
}
/*-- Define Functions --*/
//-- Sizes --//
function updateSizes () {
currentWidth = getCurrentWidth();
currentHeight = getCurrentHeight();
@ -190,7 +205,21 @@
height2 = currentHeight - margin2.top - margin2.bottom;
height3 = currentHeight - margin3.top - margin3.bottom;
}
updateSizes();
function getCurrentWidth () {
return __size_width === null ? getParentWidth() : __size_width;
}
function getCurrentHeight () {
var h = __size_height === null ? getParentHeight() : __size_height;
return h > 0 ? h : 320;
}
function getParentWidth () {
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
}
//-- Scales --//
function updateScales () {
// update edges
@ -205,126 +234,12 @@
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
// update axes
xAxis = getXAxis(x, xOrient);
yAxis = getYAxis(y, yOrient);
yAxis2 = getYAxis(y2, y2Orient);
subXAxis = getXAxis(subX, subXOrient);
};
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 + ")" }
}
// For main region
var lineOnMain = (function () {
var line = d3.svg.line()
.x(__axis_rotated ? function(d){ return getYScale(d.id)(d.value); } : xx)
.y(__axis_rotated ? xx : function(d){ return getYScale(d.id)(d.value); });
return function (d) {
var x0, y0;
if (isLineType(d)) {
isSplineType(d) ? line.interpolate("cardinal") : line.interpolate("linear");
return Object.keys(__data_regions).length > 0 ? lineWithRegions(d.values, x, getYScale(d.id), __data_regions[d.id]) : line(d.values);
} else {
x0 = x(d.values[0].x);
y0 = getYScale(d.id)(d.values[0].value);
return __axis_rotated ? "M "+y0+" "+x0 : "M "+x0+" "+y0;
}
};
})();
// For brush region
var lineOnSub = (function () {
var line = d3.svg.line()
.x(function(d){ return subX(d.x) })
.y(function(d){ return getSubYScale(d.id)(d.value) });
return function (d) {
return isLineType(d) ? line(d.values) : "M " + subX(d.values[0].x)+ " " + getSubYScale(d.id)(d.values[0].value);
};
})();
// Define color
var color = generateColor(__data_colors, __color_pattern);
// Define svgs
var svg = d3.select(__bindto).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
// Define defs
var defs = svg.append("defs");
defs.append("clipPath")
.attr("id", clipId)
.append("rect")
.attr("y", margin.top)
.attr("width", width)
.attr("height", height-margin.top);
defs.append("clipPath")
.attr("id", "xaxis-clip")
.append("rect")
.attr("x", -1)
.attr("y", -1)
.attr("width", width + 2)
.attr("height", 40);
defs.append("clipPath")
.attr("id", "yaxis-clip")
.append("rect")
.attr("x", -margin.left + 1)
.attr("y", margin.top - 1)
.attr("width", margin.left)
.attr("height", height - margin.top + 2);
// Define regions
var main = svg.append("g")
.attr("transform", translate.main);
var context = null;
if (__subchart_show) {
context = svg.append("g")
.attr("transform", translate.context);
}
var legend = null;
if (__legend_show) {
legend = svg.append("g")
.attr("transform", translate.legend);
}
// Define tooltip
var tooltip = d3.select(__bindto)
.style("position", "relative")
.append("div")
.style("position", "absolute")
.style("width", "30%") // TODO: cul actual width when show
.style("z-index", "10")
.style("visibility", "hidden");
/*-- Define Functions --*/
function getCurrentWidth () {
return __size_width === null ? getParentWidth() : __size_width;
}
function getCurrentHeight () {
var h = __size_height === null ? getParentHeight() : __size_height;
return h > 0 ? h : 320;
}
function getParentWidth () {
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 --//
function getX (min, max, domain, offset) {
var scale = ((isTimeSeries) ? d3.time.scale() : d3.scale.linear()).range([min, max]);
// Set function and values for c3
@ -362,7 +277,7 @@
return getAxisId(id) === 'y2' ? subY2 : subY;
}
//-- Axis --//
//-- Axes --//
function getXAxis (scale, orient) {
var axis = (isCategorized ? categoryAxis() : d3.svg.axis()).scale(scale).orient(orient);
@ -778,6 +693,34 @@
//-- Shape --//
// For main region
var lineOnMain = (function () {
var line = d3.svg.line()
.x(__axis_rotated ? function(d){ return getYScale(d.id)(d.value); } : xx)
.y(__axis_rotated ? xx : function(d){ return getYScale(d.id)(d.value); });
return function (d) {
var x0, y0;
if (isLineType(d)) {
isSplineType(d) ? line.interpolate("cardinal") : line.interpolate("linear");
return Object.keys(__data_regions).length > 0 ? lineWithRegions(d.values, x, getYScale(d.id), __data_regions[d.id]) : line(d.values);
} else {
x0 = x(d.values[0].x);
y0 = getYScale(d.id)(d.values[0].value);
return __axis_rotated ? "M "+y0+" "+x0 : "M "+x0+" "+y0;
}
};
})();
// For brush region
var lineOnSub = (function () {
var line = d3.svg.line()
.x(function(d){ return subX(d.x) })
.y(function(d){ return getSubYScale(d.id)(d.value) });
return function (d) {
return isLineType(d) ? line(d.values) : "M " + subX(d.values[0].x)+ " " + getSubYScale(d.id)(d.values[0].value);
};
})();
function lineWithRegions (d, x, y, _regions) {
var prev = -1, i, j;
var s = "M", sWithRegion;
@ -847,18 +790,18 @@
return s;
}
/*-- Define brush --*/
//-- Define brush/zoom -//
var brush = d3.svg.brush().on("brush", redrawForBrush);
var zoom = d3.behavior.zoom().on("zoom", __zoom_enabled ? redrawForZoom : null);
/*-- Draw Chart --*/
// for brush area culculation
var firstDate = null,
lastDate = null;
// for svg elements
var svg, defs, main, context, legend, tooltip;
var orgXDomain;
// for brush area culculation
var firstDate = null, lastDate = null, orgXDomain;
function init (data) {
var targets = c3.data.targets = convertDataToTargets(data);
@ -868,14 +811,19 @@
// TODO: set names if names not specified
// Init sizes and scales
updateSizes();
updateScales();
// Set domains for each scale
x.domain(d3.extent(data.map(function(d){ return d.x; })));
y.domain(getYDomain(targets, 'y'));
y2.domain(getYDomain(targets, 'y2'));
subX.domain(x.domain());
subY.domain(y.domain());
subY2.domain(y2.domain());
// Set axes attrs
xAxis.ticks(data.length < 10 ? data.length : 10);
yAxis.ticks(__axis_y_ticks).outerTickSize(0).tickFormat(__axis_y_format);
yAxis2.ticks(__axis_y2_ticks).outerTickSize(0).tickFormat(__axis_y2_format);
@ -883,10 +831,54 @@
// Save original x domain for zoom update
orgXDomain = x.domain();
// MEMO: must set x here for timeseries data
// Set initialized scales to brush and zoom
brush.x(subX);
if (__zoom_enabled) zoom.x(x);
/*-- Basic Elements --*/
// Define svgs
svg = d3.select(__bindto).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
// Define defs
defs = svg.append("defs");
defs.append("clipPath")
.attr("id", clipId)
.append("rect")
.attr("y", margin.top)
.attr("width", width)
.attr("height", height-margin.top);
defs.append("clipPath")
.attr("id", "xaxis-clip")
.append("rect")
.attr("x", -1)
.attr("y", -1)
.attr("width", width + 2)
.attr("height", 40);
defs.append("clipPath")
.attr("id", "yaxis-clip")
.append("rect")
.attr("x", -margin.left + 1)
.attr("y", margin.top - 1)
.attr("width", margin.left)
.attr("height", height - margin.top + 2);
// Define regions
main = svg.append("g").attr("transform", translate.main);
context = __subchart_show ? svg.append("g").attr("transform", translate.context) : null;
legend = __legend_show ? svg.append("g").attr("transform", translate.legend) : null;
// Define tooltip
tooltip = d3.select(__bindto)
.style("position", "relative")
.append("div")
.style("position", "absolute")
.style("width", "30%") // TODO: cul actual width when show
.style("z-index", "10")
.style("visibility", "hidden");
/*-- Main Region --*/
// Add Axis
@ -1387,7 +1379,7 @@
}
// update subchart elements if needed
if (withSubchart) {
// axies
// axes
// TODO: fix when rotated
context.select('.x.axis').transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : subXAxis);
// extent rect

127
c3.min.js vendored

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

Loading…
Cancel
Save