diff options
author | href <href@random.sh> | 2021-09-01 10:30:18 +0200 |
---|---|---|
committer | href <href@random.sh> | 2021-09-01 10:30:18 +0200 |
commit | 75687711f35355bc30e4829439384aab28fcac6d (patch) | |
tree | 8f3256f472893c39720a684d390e890a152f7303 /priv/static/js | |
parent | link: post_* callbacks; html & pdftitle. (diff) |
Commit all the changes that hasn't been committed + updates.
Diffstat (limited to 'priv/static/js')
33 files changed, 8306 insertions, 0 deletions
diff --git a/priv/static/js/d3.v4.min.js b/priv/static/js/d3.v4.min.js new file mode 100644 index 0000000..607d187 --- /dev/null +++ b/priv/static/js/d3.v4.min.js @@ -0,0 +1,2 @@ +// https://d3js.org Version 4.13.0. Copyright 2018 Mike Bostock. +(function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})})(this,function(t){"use strict";function n(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function e(t){return 1===t.length&&(t=function(t){return function(e,r){return n(t(e),r)}}(t)),{left:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)<0?r=o+1:i=o}return r},right:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)>0?i=o:r=o+1}return r}}}function r(t,n){return[t,n]}function i(t){return null===t?NaN:+t}function o(t,n){var e,r,o=t.length,u=0,a=-1,c=0,s=0;if(null==n)for(;++a<o;)isNaN(e=i(t[a]))||(s+=(r=e-c)*(e-(c+=r/++u)));else for(;++a<o;)isNaN(e=i(n(t[a],a,t)))||(s+=(r=e-c)*(e-(c+=r/++u)));if(u>1)return s/(u-1)}function u(t,n){var e=o(t,n);return e?Math.sqrt(e):e}function a(t,n){var e,r,i,o=t.length,u=-1;if(null==n){for(;++u<o;)if(null!=(e=t[u])&&e>=e)for(r=i=e;++u<o;)null!=(e=t[u])&&(r>e&&(r=e),i<e&&(i=e))}else for(;++u<o;)if(null!=(e=n(t[u],u,t))&&e>=e)for(r=i=e;++u<o;)null!=(e=n(t[u],u,t))&&(r>e&&(r=e),i<e&&(i=e));return[r,i]}function c(t){return function(){return t}}function s(t){return t}function f(t,n,e){t=+t,n=+n,e=(i=arguments.length)<2?(n=t,t=0,1):i<3?1:+e;for(var r=-1,i=0|Math.max(0,Math.ceil((n-t)/e)),o=new Array(i);++r<i;)o[r]=t+r*e;return o}function l(t,n,e){var r,i,o,u,a=-1;if(n=+n,t=+t,e=+e,t===n&&e>0)return[t];if((r=n<t)&&(i=t,t=n,n=i),0===(u=h(t,n,e))||!isFinite(u))return[];if(u>0)for(t=Math.ceil(t/u),n=Math.floor(n/u),o=new Array(i=Math.ceil(n-t+1));++a<i;)o[a]=(t+a)*u;else for(t=Math.floor(t*u),n=Math.ceil(n*u),o=new Array(i=Math.ceil(t-n+1));++a<i;)o[a]=(t-a)/u;return r&&o.reverse(),o}function h(t,n,e){var r=(n-t)/Math.max(0,e),i=Math.floor(Math.log(r)/Math.LN10),o=r/Math.pow(10,i);return i>=0?(o>=Hs?10:o>=js?5:o>=Xs?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(o>=Hs?10:o>=js?5:o>=Xs?2:1)}function p(t,n,e){var r=Math.abs(n-t)/Math.max(0,e),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),o=r/i;return o>=Hs?i*=10:o>=js?i*=5:o>=Xs&&(i*=2),n<t?-i:i}function d(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function v(t,n,e){if(null==e&&(e=i),r=t.length){if((n=+n)<=0||r<2)return+e(t[0],0,t);if(n>=1)return+e(t[r-1],r-1,t);var r,o=(r-1)*n,u=Math.floor(o),a=+e(t[u],u,t);return a+(+e(t[u+1],u+1,t)-a)*(o-u)}}function g(t){for(var n,e,r,i=t.length,o=-1,u=0;++o<i;)u+=t[o].length;for(e=new Array(u);--i>=0;)for(n=(r=t[i]).length;--n>=0;)e[--u]=r[n];return e}function _(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&r>e&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&r>e&&(r=e);return r}function y(t){if(!(i=t.length))return[];for(var n=-1,e=_(t,m),r=new Array(e);++n<e;)for(var i,o=-1,u=r[n]=new Array(i);++o<i;)u[o]=t[o][n];return r}function m(t){return t.length}function x(t){return t}function b(t){return"translate("+(t+.5)+",0)"}function w(t){return"translate(0,"+(t+.5)+")"}function M(){return!this.__axis}function T(t,n){function e(e){var h=null==i?n.ticks?n.ticks.apply(n,r):n.domain():i,p=null==o?n.tickFormat?n.tickFormat.apply(n,r):x:o,d=Math.max(u,0)+c,v=n.range(),g=+v[0]+.5,_=+v[v.length-1]+.5,y=(n.bandwidth?function(t){var n=Math.max(0,t.bandwidth()-1)/2;return t.round()&&(n=Math.round(n)),function(e){return+t(e)+n}}:function(t){return function(n){return+t(n)}})(n.copy()),m=e.selection?e.selection():e,b=m.selectAll(".domain").data([null]),w=m.selectAll(".tick").data(h,n).order(),T=w.exit(),N=w.enter().append("g").attr("class","tick"),k=w.select("line"),S=w.select("text");b=b.merge(b.enter().insert("path",".tick").attr("class","domain").attr("stroke","#000")),w=w.merge(N),k=k.merge(N.append("line").attr("stroke","#000").attr(f+"2",s*u)),S=S.merge(N.append("text").attr("fill","#000").attr(f,s*d).attr("dy",t===$s?"0em":t===Zs?"0.71em":"0.32em")),e!==m&&(b=b.transition(e),w=w.transition(e),k=k.transition(e),S=S.transition(e),T=T.transition(e).attr("opacity",Qs).attr("transform",function(t){return isFinite(t=y(t))?l(t):this.getAttribute("transform")}),N.attr("opacity",Qs).attr("transform",function(t){var n=this.parentNode.__axis;return l(n&&isFinite(n=n(t))?n:y(t))})),T.remove(),b.attr("d",t===Gs||t==Ws?"M"+s*a+","+g+"H0.5V"+_+"H"+s*a:"M"+g+","+s*a+"V0.5H"+_+"V"+s*a),w.attr("opacity",1).attr("transform",function(t){return l(y(t))}),k.attr(f+"2",s*u),S.attr(f,s*d).text(p),m.filter(M).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",t===Ws?"start":t===Gs?"end":"middle"),m.each(function(){this.__axis=y})}var r=[],i=null,o=null,u=6,a=6,c=3,s=t===$s||t===Gs?-1:1,f=t===Gs||t===Ws?"x":"y",l=t===$s||t===Zs?b:w;return e.scale=function(t){return arguments.length?(n=t,e):n},e.ticks=function(){return r=Vs.call(arguments),e},e.tickArguments=function(t){return arguments.length?(r=null==t?[]:Vs.call(t),e):r.slice()},e.tickValues=function(t){return arguments.length?(i=null==t?null:Vs.call(t),e):i&&i.slice()},e.tickFormat=function(t){return arguments.length?(o=t,e):o},e.tickSize=function(t){return arguments.length?(u=a=+t,e):u},e.tickSizeInner=function(t){return arguments.length?(u=+t,e):u},e.tickSizeOuter=function(t){return arguments.length?(a=+t,e):a},e.tickPadding=function(t){return arguments.length?(c=+t,e):c},e}function N(){for(var t,n=0,e=arguments.length,r={};n<e;++n){if(!(t=arguments[n]+"")||t in r)throw new Error("illegal type: "+t);r[t]=[]}return new k(r)}function k(t){this._=t}function S(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=Js,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}function E(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),tf.hasOwnProperty(n)?{space:tf[n],local:t}:t}function A(t){var n=E(t);return(n.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e===Ks&&n.documentElement.namespaceURI===Ks?n.createElement(t):n.createElementNS(e,t)}})(n)}function C(){}function z(t){return null==t?C:function(){return this.querySelector(t)}}function P(){return[]}function R(t){return null==t?P:function(){return this.querySelectorAll(t)}}function L(t){return new Array(t.length)}function q(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function D(t,n,e,r,i,o){for(var u,a=0,c=n.length,s=o.length;a<s;++a)(u=n[a])?(u.__data__=o[a],r[a]=u):e[a]=new q(t,o[a]);for(;a<c;++a)(u=n[a])&&(i[a]=u)}function U(t,n,e,r,i,o,u){var a,c,s,f={},l=n.length,h=o.length,p=new Array(l);for(a=0;a<l;++a)(c=n[a])&&(p[a]=s=uf+u.call(c,c.__data__,a,n),s in f?i[a]=c:f[s]=c);for(a=0;a<h;++a)(c=f[s=uf+u.call(t,o[a],a,o)])?(r[a]=c,c.__data__=o[a],f[s]=null):e[a]=new q(t,o[a]);for(a=0;a<l;++a)(c=n[a])&&f[p[a]]===c&&(i[a]=c)}function O(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function F(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function I(t,n){return t.style.getPropertyValue(n)||F(t).getComputedStyle(t,null).getPropertyValue(n)}function Y(t){return t.trim().split(/^|\s+/)}function B(t){return t.classList||new H(t)}function H(t){this._node=t,this._names=Y(t.getAttribute("class")||"")}function j(t,n){for(var e=B(t),r=-1,i=n.length;++r<i;)e.add(n[r])}function X(t,n){for(var e=B(t),r=-1,i=n.length;++r<i;)e.remove(n[r])}function V(){this.textContent=""}function $(){this.innerHTML=""}function W(){this.nextSibling&&this.parentNode.appendChild(this)}function Z(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function G(){return null}function Q(){var t=this.parentNode;t&&t.removeChild(this)}function J(){return this.parentNode.insertBefore(this.cloneNode(!1),this.nextSibling)}function K(){return this.parentNode.insertBefore(this.cloneNode(!0),this.nextSibling)}function tt(t,n,e){return t=nt(t,n,e),function(n){var e=n.relatedTarget;e&&(e===this||8&e.compareDocumentPosition(this))||t.call(this,n)}}function nt(n,e,r){return function(i){var o=t.event;t.event=i;try{n.call(this,this.__data__,e,r)}finally{t.event=o}}}function et(t){return function(){var n=this.__on;if(n){for(var e,r=0,i=-1,o=n.length;r<o;++r)e=n[r],t.type&&e.type!==t.type||e.name!==t.name?n[++i]=e:this.removeEventListener(e.type,e.listener,e.capture);++i?n.length=i:delete this.__on}}}function rt(t,n,e){var r=af.hasOwnProperty(t.type)?tt:nt;return function(i,o,u){var a,c=this.__on,s=r(n,o,u);if(c)for(var f=0,l=c.length;f<l;++f)if((a=c[f]).type===t.type&&a.name===t.name)return this.removeEventListener(a.type,a.listener,a.capture),this.addEventListener(a.type,a.listener=s,a.capture=e),void(a.value=n);this.addEventListener(t.type,s,e),a={type:t.type,name:t.name,value:n,listener:s,capture:e},c?c.push(a):this.__on=[a]}}function it(n,e,r,i){var o=t.event;n.sourceEvent=t.event,t.event=n;try{return e.apply(r,i)}finally{t.event=o}}function ot(t,n,e){var r=F(t),i=r.CustomEvent;"function"==typeof i?i=new i(n,e):(i=r.document.createEvent("Event"),e?(i.initEvent(n,e.bubbles,e.cancelable),i.detail=e.detail):i.initEvent(n,!1,!1)),t.dispatchEvent(i)}function ut(t,n){this._groups=t,this._parents=n}function at(){return new ut([[document.documentElement]],cf)}function ct(t){return"string"==typeof t?new ut([[document.querySelector(t)]],[document.documentElement]):new ut([[t]],cf)}function st(){return new ft}function ft(){this._="@"+(++sf).toString(36)}function lt(){for(var n,e=t.event;n=e.sourceEvent;)e=n;return e}function ht(t,n){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var r=e.createSVGPoint();return r.x=n.clientX,r.y=n.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}var i=t.getBoundingClientRect();return[n.clientX-i.left-t.clientLeft,n.clientY-i.top-t.clientTop]}function pt(t){var n=lt();return n.changedTouches&&(n=n.changedTouches[0]),ht(t,n)}function dt(t,n,e){arguments.length<3&&(e=n,n=lt().changedTouches);for(var r,i=0,o=n?n.length:0;i<o;++i)if((r=n[i]).identifier===e)return ht(t,r);return null}function vt(){t.event.stopImmediatePropagation()}function gt(){t.event.preventDefault(),t.event.stopImmediatePropagation()}function _t(t){var n=t.document.documentElement,e=ct(t).on("dragstart.drag",gt,!0);"onselectstart"in n?e.on("selectstart.drag",gt,!0):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function yt(t,n){var e=t.document.documentElement,r=ct(t).on("dragstart.drag",null);n&&(r.on("click.drag",gt,!0),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in e?r.on("selectstart.drag",null):(e.style.MozUserSelect=e.__noselect,delete e.__noselect)}function mt(t){return function(){return t}}function xt(t,n,e,r,i,o,u,a,c,s){this.target=t,this.type=n,this.subject=e,this.identifier=r,this.active=i,this.x=o,this.y=u,this.dx=a,this.dy=c,this._=s}function bt(){return!t.event.button}function wt(){return this.parentNode}function Mt(n){return null==n?{x:t.event.x,y:t.event.y}:n}function Tt(){return"ontouchstart"in this}function Nt(t,n,e){t.prototype=n.prototype=e,e.constructor=t}function kt(t,n){var e=Object.create(t.prototype);for(var r in n)e[r]=n[r];return e}function St(){}function Et(t){var n;return t=(t+"").trim().toLowerCase(),(n=pf.exec(t))?(n=parseInt(n[1],16),new Rt(n>>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1)):(n=df.exec(t))?At(parseInt(n[1],16)):(n=vf.exec(t))?new Rt(n[1],n[2],n[3],1):(n=gf.exec(t))?new Rt(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=_f.exec(t))?Ct(n[1],n[2],n[3],n[4]):(n=yf.exec(t))?Ct(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=mf.exec(t))?Lt(n[1],n[2]/100,n[3]/100,1):(n=xf.exec(t))?Lt(n[1],n[2]/100,n[3]/100,n[4]):bf.hasOwnProperty(t)?At(bf[t]):"transparent"===t?new Rt(NaN,NaN,NaN,0):null}function At(t){return new Rt(t>>16&255,t>>8&255,255&t,1)}function Ct(t,n,e,r){return r<=0&&(t=n=e=NaN),new Rt(t,n,e,r)}function zt(t){return t instanceof St||(t=Et(t)),t?(t=t.rgb(),new Rt(t.r,t.g,t.b,t.opacity)):new Rt}function Pt(t,n,e,r){return 1===arguments.length?zt(t):new Rt(t,n,e,null==r?1:r)}function Rt(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Lt(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Dt(t,n,e,r)}function qt(t,n,e,r){return 1===arguments.length?function(t){if(t instanceof Dt)return new Dt(t.h,t.s,t.l,t.opacity);if(t instanceof St||(t=Et(t)),!t)return new Dt;if(t instanceof Dt)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),u=NaN,a=o-i,c=(o+i)/2;return a?(u=n===o?(e-r)/a+6*(e<r):e===o?(r-n)/a+2:(n-e)/a+4,a/=c<.5?o+i:2-o-i,u*=60):a=c>0&&c<1?0:u,new Dt(u,a,c,t.opacity)}(t):new Dt(t,n,e,null==r?1:r)}function Dt(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Ut(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}function Ot(t){if(t instanceof It)return new It(t.l,t.a,t.b,t.opacity);if(t instanceof Vt){var n=t.h*wf;return new It(t.l,Math.cos(n)*t.c,Math.sin(n)*t.c,t.opacity)}t instanceof Rt||(t=zt(t));var e=jt(t.r),r=jt(t.g),i=jt(t.b),o=Yt((.4124564*e+.3575761*r+.1804375*i)/Tf),u=Yt((.2126729*e+.7151522*r+.072175*i)/Nf);return new It(116*u-16,500*(o-u),200*(u-Yt((.0193339*e+.119192*r+.9503041*i)/kf)),t.opacity)}function Ft(t,n,e,r){return 1===arguments.length?Ot(t):new It(t,n,e,null==r?1:r)}function It(t,n,e,r){this.l=+t,this.a=+n,this.b=+e,this.opacity=+r}function Yt(t){return t>Cf?Math.pow(t,1/3):t/Af+Sf}function Bt(t){return t>Ef?t*t*t:Af*(t-Sf)}function Ht(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function jt(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Xt(t,n,e,r){return 1===arguments.length?function(t){if(t instanceof Vt)return new Vt(t.h,t.c,t.l,t.opacity);t instanceof It||(t=Ot(t));var n=Math.atan2(t.b,t.a)*Mf;return new Vt(n<0?n+360:n,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}(t):new Vt(t,n,e,null==r?1:r)}function Vt(t,n,e,r){this.h=+t,this.c=+n,this.l=+e,this.opacity=+r}function $t(t,n,e,r){return 1===arguments.length?function(t){if(t instanceof Wt)return new Wt(t.h,t.s,t.l,t.opacity);t instanceof Rt||(t=zt(t));var n=t.r/255,e=t.g/255,r=t.b/255,i=(Df*r+Lf*n-qf*e)/(Df+Lf-qf),o=r-i,u=(Rf*(e-i)-zf*o)/Pf,a=Math.sqrt(u*u+o*o)/(Rf*i*(1-i)),c=a?Math.atan2(u,o)*Mf-120:NaN;return new Wt(c<0?c+360:c,a,i,t.opacity)}(t):new Wt(t,n,e,null==r?1:r)}function Wt(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Zt(t,n,e,r,i){var o=t*t,u=o*t;return((1-3*t+3*o-u)*n+(4-6*o+3*u)*e+(1+3*t+3*o-3*u)*r+u*i)/6}function Gt(t){var n=t.length-1;return function(e){var r=e<=0?e=0:e>=1?(e=1,n-1):Math.floor(e*n),i=t[r],o=t[r+1],u=r>0?t[r-1]:2*i-o,a=r<n-1?t[r+2]:2*o-i;return Zt((e-r/n)*n,u,i,o,a)}}function Qt(t){var n=t.length;return function(e){var r=Math.floor(((e%=1)<0?++e:e)*n),i=t[(r+n-1)%n],o=t[r%n],u=t[(r+1)%n],a=t[(r+2)%n];return Zt((e-r/n)*n,i,o,u,a)}}function Jt(t){return function(){return t}}function Kt(t,n){return function(e){return t+e*n}}function tn(t,n){var e=n-t;return e?Kt(t,e>180||e<-180?e-360*Math.round(e/360):e):Jt(isNaN(t)?n:t)}function nn(t){return 1==(t=+t)?en:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):Jt(isNaN(n)?e:n)}}function en(t,n){var e=n-t;return e?Kt(t,e):Jt(isNaN(t)?n:t)}function rn(t){return function(n){var e,r,i=n.length,o=new Array(i),u=new Array(i),a=new Array(i);for(e=0;e<i;++e)r=Pt(n[e]),o[e]=r.r||0,u[e]=r.g||0,a[e]=r.b||0;return o=t(o),u=t(u),a=t(a),r.opacity=1,function(t){return r.r=o(t),r.g=u(t),r.b=a(t),r+""}}}function on(t,n){var e,r=n?n.length:0,i=t?Math.min(r,t.length):0,o=new Array(i),u=new Array(r);for(e=0;e<i;++e)o[e]=fn(t[e],n[e]);for(;e<r;++e)u[e]=n[e];return function(t){for(e=0;e<i;++e)u[e]=o[e](t);return u}}function un(t,n){var e=new Date;return t=+t,n-=t,function(r){return e.setTime(t+n*r),e}}function an(t,n){return t=+t,n-=t,function(e){return t+n*e}}function cn(t,n){var e,r={},i={};null!==t&&"object"==typeof t||(t={}),null!==n&&"object"==typeof n||(n={});for(e in n)e in t?r[e]=fn(t[e],n[e]):i[e]=n[e];return function(t){for(e in r)i[e]=r[e](t);return i}}function sn(t,n){var e,r,i,o=Vf.lastIndex=$f.lastIndex=0,u=-1,a=[],c=[];for(t+="",n+="";(e=Vf.exec(t))&&(r=$f.exec(n));)(i=r.index)>o&&(i=n.slice(o,i),a[u]?a[u]+=i:a[++u]=i),(e=e[0])===(r=r[0])?a[u]?a[u]+=r:a[++u]=r:(a[++u]=null,c.push({i:u,x:an(e,r)})),o=$f.lastIndex;return o<n.length&&(i=n.slice(o),a[u]?a[u]+=i:a[++u]=i),a.length<2?c[0]?function(t){return function(n){return t(n)+""}}(c[0].x):function(t){return function(){return t}}(n):(n=c.length,function(t){for(var e,r=0;r<n;++r)a[(e=c[r]).i]=e.x(t);return a.join("")})}function fn(t,n){var e,r=typeof n;return null==n||"boolean"===r?Jt(n):("number"===r?an:"string"===r?(e=Et(n))?(n=e,Hf):sn:n instanceof Et?Hf:n instanceof Date?un:Array.isArray(n)?on:"function"!=typeof n.valueOf&&"function"!=typeof n.toString||isNaN(n)?cn:an)(t,n)}function ln(t,n){return t=+t,n-=t,function(e){return Math.round(t+n*e)}}function hn(t,n,e,r,i,o){var u,a,c;return(u=Math.sqrt(t*t+n*n))&&(t/=u,n/=u),(c=t*e+n*r)&&(e-=t*c,r-=n*c),(a=Math.sqrt(e*e+r*r))&&(e/=a,r/=a,c/=a),t*r<n*e&&(t=-t,n=-n,c=-c,u=-u),{translateX:i,translateY:o,rotate:Math.atan2(n,t)*Wf,skewX:Math.atan(c)*Wf,scaleX:u,scaleY:a}}function pn(t,n,e,r){function i(t){return t.length?t.pop()+" ":""}return function(o,u){var a=[],c=[];return o=t(o),u=t(u),function(t,r,i,o,u,a){if(t!==i||r!==o){var c=u.push("translate(",null,n,null,e);a.push({i:c-4,x:an(t,i)},{i:c-2,x:an(r,o)})}else(i||o)&&u.push("translate("+i+n+o+e)}(o.translateX,o.translateY,u.translateX,u.translateY,a,c),function(t,n,e,o){t!==n?(t-n>180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:an(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,u.rotate,a,c),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:an(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,u.skewX,a,c),function(t,n,e,r,o,u){if(t!==e||n!==r){var a=o.push(i(o)+"scale(",null,",",null,")");u.push({i:a-4,x:an(t,e)},{i:a-2,x:an(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,u.scaleX,u.scaleY,a,c),o=u=null,function(t){for(var n,e=-1,r=c.length;++e<r;)a[(n=c[e]).i]=n.x(t);return a.join("")}}}function dn(t){return((t=Math.exp(t))+1/t)/2}function vn(t,n){var e,r,i=t[0],o=t[1],u=t[2],a=n[0],c=n[1],s=n[2],f=a-i,l=c-o,h=f*f+l*l;if(h<nl)r=Math.log(s/u)/Jf,e=function(t){return[i+t*f,o+t*l,u*Math.exp(Jf*t*r)]};else{var p=Math.sqrt(h),d=(s*s-u*u+tl*h)/(2*u*Kf*p),v=(s*s-u*u-tl*h)/(2*s*Kf*p),g=Math.log(Math.sqrt(d*d+1)-d),_=Math.log(Math.sqrt(v*v+1)-v);r=(_-g)/Jf,e=function(t){var n=t*r,e=dn(g),a=u/(Kf*p)*(e*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(Jf*n+g)-function(t){return((t=Math.exp(t))-1/t)/2}(g));return[i+a*f,o+a*l,u*e/dn(Jf*n+g)]}}return e.duration=1e3*r,e}function gn(t){return function(n,e){var r=t((n=qt(n)).h,(e=qt(e)).h),i=en(n.s,e.s),o=en(n.l,e.l),u=en(n.opacity,e.opacity);return function(t){return n.h=r(t),n.s=i(t),n.l=o(t),n.opacity=u(t),n+""}}}function _n(t){return function(n,e){var r=t((n=Xt(n)).h,(e=Xt(e)).h),i=en(n.c,e.c),o=en(n.l,e.l),u=en(n.opacity,e.opacity);return function(t){return n.h=r(t),n.c=i(t),n.l=o(t),n.opacity=u(t),n+""}}}function yn(t){return function n(e){function r(n,r){var i=t((n=$t(n)).h,(r=$t(r)).h),o=en(n.s,r.s),u=en(n.l,r.l),a=en(n.opacity,r.opacity);return function(t){return n.h=i(t),n.s=o(t),n.l=u(Math.pow(t,e)),n.opacity=a(t),n+""}}return e=+e,r.gamma=n,r}(1)}function mn(){return pl||(gl(xn),pl=vl.now()+dl)}function xn(){pl=0}function bn(){this._call=this._time=this._next=null}function wn(t,n,e){var r=new bn;return r.restart(t,n,e),r}function Mn(){mn(),++cl;for(var t,n=Yf;n;)(t=pl-n._time)>=0&&n._call.call(null,t),n=n._next;--cl}function Tn(){pl=(hl=vl.now())+dl,cl=sl=0;try{Mn()}finally{cl=0,function(){var t,n,e=Yf,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:Yf=n);Bf=t,kn(r)}(),pl=0}}function Nn(){var t=vl.now(),n=t-hl;n>ll&&(dl-=n,hl=t)}function kn(t){if(!cl){sl&&(sl=clearTimeout(sl));t-pl>24?(t<1/0&&(sl=setTimeout(Tn,t-vl.now()-dl)),fl&&(fl=clearInterval(fl))):(fl||(hl=vl.now(),fl=setInterval(Nn,ll)),cl=1,gl(Tn))}}function Sn(t,n,e){var r=new bn;return n=null==n?0:+n,r.restart(function(e){r.stop(),t(e+n)},n,e),r}function En(t,n,e,r,i,o){var u=t.__transition;if(u){if(e in u)return}else t.__transition={};(function(t,n,e){function r(c){var s,f,l,h;if(e.state!==xl)return o();for(s in a)if((h=a[s]).name===e.name){if(h.state===wl)return Sn(r);h.state===Ml?(h.state=Nl,h.timer.stop(),h.on.call("interrupt",t,t.__data__,h.index,h.group),delete a[s]):+s<n&&(h.state=Nl,h.timer.stop(),delete a[s])}if(Sn(function(){e.state===wl&&(e.state=Ml,e.timer.restart(i,e.delay,e.time),i(c))}),e.state=bl,e.on.call("start",t,t.__data__,e.index,e.group),e.state===bl){for(e.state=wl,u=new Array(l=e.tween.length),s=0,f=-1;s<l;++s)(h=e.tween[s].value.call(t,t.__data__,e.index,e.group))&&(u[++f]=h);u.length=f+1}}function i(n){for(var r=n<e.duration?e.ease.call(null,n/e.duration):(e.timer.restart(o),e.state=Tl,1),i=-1,a=u.length;++i<a;)u[i].call(null,r);e.state===Tl&&(e.on.call("end",t,t.__data__,e.index,e.group),o())}function o(){e.state=Nl,e.timer.stop(),delete a[n];for(var r in a)return;delete t.__transition}var u,a=t.__transition;a[n]=e,e.timer=wn(function(t){e.state=xl,e.timer.restart(r,e.delay,e.time),e.delay<=t&&r(t-e.delay)},0,e.time)})(t,e,{name:n,index:r,group:i,on:_l,tween:yl,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:ml})}function An(t,n){var e=zn(t,n);if(e.state>ml)throw new Error("too late; already scheduled");return e}function Cn(t,n){var e=zn(t,n);if(e.state>bl)throw new Error("too late; already started");return e}function zn(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function Pn(t,n){var e,r,i,o=t.__transition,u=!0;if(o){n=null==n?null:n+"";for(i in o)(e=o[i]).name===n?(r=e.state>bl&&e.state<Tl,e.state=Nl,e.timer.stop(),r&&e.on.call("interrupt",t,t.__data__,e.index,e.group),delete o[i]):u=!1;u&&delete t.__transition}}function Rn(t,n,e){var r=t._id;return t.each(function(){var t=Cn(this,r);(t.value||(t.value={}))[n]=e.apply(this,arguments)}),function(t){return zn(t,r).value[n]}}function Ln(t,n){var e;return("number"==typeof n?an:n instanceof Et?Hf:(e=Et(n))?(n=e,Hf):sn)(t,n)}function qn(t,n,e,r){this._groups=t,this._parents=n,this._name=e,this._id=r}function Dn(t){return at().transition(t)}function Un(){return++Sl}function On(t){return((t*=2)<=1?t*t:--t*(2-t)+1)/2}function Fn(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}function In(t){return(1-Math.cos(Pl*t))/2}function Yn(t){return((t*=2)<=1?Math.pow(2,10*t-10):2-Math.pow(2,10-10*t))/2}function Bn(t){return((t*=2)<=1?1-Math.sqrt(1-t*t):Math.sqrt(1-(t-=2)*t)+1)/2}function Hn(t){return(t=+t)<Ll?Hl*t*t:t<Dl?Hl*(t-=ql)*t+Ul:t<Fl?Hl*(t-=Ol)*t+Il:Hl*(t-=Yl)*t+Bl}function jn(t,n){for(var e;!(e=t.__transition)||!(e=e[n]);)if(!(t=t.parentNode))return Ql.time=mn(),Ql;return e}function Xn(t){return function(){return t}}function Vn(){t.event.stopImmediatePropagation()}function $n(){t.event.preventDefault(),t.event.stopImmediatePropagation()}function Wn(t){return{type:t}}function Zn(){return!t.event.button}function Gn(){var t=this.ownerSVGElement||this;return[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function Qn(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function Jn(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}function Kn(n){function e(t){var e=t.property("__brush",a).selectAll(".overlay").data([Wn("overlay")]);e.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",uh.overlay).merge(e).each(function(){var t=Qn(this).extent;ct(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])}),t.selectAll(".selection").data([Wn("selection")]).enter().append("rect").attr("class","selection").attr("cursor",uh.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var i=t.selectAll(".handle").data(n.handles,function(t){return t.type});i.exit().remove(),i.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return uh[t.type]}),t.each(r).attr("fill","none").attr("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush touchstart.brush",u)}function r(){var t=ct(this),n=Qn(this).selection;n?(t.selectAll(".selection").style("display",null).attr("x",n[0][0]).attr("y",n[0][1]).attr("width",n[1][0]-n[0][0]).attr("height",n[1][1]-n[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?n[1][0]-h/2:n[0][0]-h/2}).attr("y",function(t){return"s"===t.type[0]?n[1][1]-h/2:n[0][1]-h/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?n[1][0]-n[0][0]+h:h}).attr("height",function(t){return"e"===t.type||"w"===t.type?n[1][1]-n[0][1]+h:h})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function i(t,n){return t.__brush.emitter||new o(t,n)}function o(t,n){this.that=t,this.args=n,this.state=t.__brush,this.active=0}function u(){function e(){var t=pt(w);!L||x||b||(Math.abs(t[0]-D[0])>Math.abs(t[1]-D[1])?b=!0:x=!0),D=t,m=!0,$n(),o()}function o(){var t;switch(_=D[0]-q[0],y=D[1]-q[1],T){case th:case Kl:N&&(_=Math.max(C-a,Math.min(P-p,_)),s=a+_,d=p+_),k&&(y=Math.max(z-l,Math.min(R-v,y)),h=l+y,g=v+y);break;case nh:N<0?(_=Math.max(C-a,Math.min(P-a,_)),s=a+_,d=p):N>0&&(_=Math.max(C-p,Math.min(P-p,_)),s=a,d=p+_),k<0?(y=Math.max(z-l,Math.min(R-l,y)),h=l+y,g=v):k>0&&(y=Math.max(z-v,Math.min(R-v,y)),h=l,g=v+y);break;case eh:N&&(s=Math.max(C,Math.min(P,a-_*N)),d=Math.max(C,Math.min(P,p+_*N))),k&&(h=Math.max(z,Math.min(R,l-y*k)),g=Math.max(z,Math.min(R,v+y*k)))}d<s&&(N*=-1,t=a,a=p,p=t,t=s,s=d,d=t,M in ah&&F.attr("cursor",uh[M=ah[M]])),g<h&&(k*=-1,t=l,l=v,v=t,t=h,h=g,g=t,M in ch&&F.attr("cursor",uh[M=ch[M]])),S.selection&&(A=S.selection),x&&(s=A[0][0],d=A[1][0]),b&&(h=A[0][1],g=A[1][1]),A[0][0]===s&&A[0][1]===h&&A[1][0]===d&&A[1][1]===g||(S.selection=[[s,h],[d,g]],r.call(w),U.brush())}function u(){if(Vn(),t.event.touches){if(t.event.touches.length)return;c&&clearTimeout(c),c=setTimeout(function(){c=null},500),O.on("touchmove.brush touchend.brush touchcancel.brush",null)}else yt(t.event.view,m),I.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);O.attr("pointer-events","all"),F.attr("cursor",uh.overlay),S.selection&&(A=S.selection),Jn(A)&&(S.selection=null,r.call(w)),U.end()}if(t.event.touches){if(t.event.changedTouches.length<t.event.touches.length)return $n()}else if(c)return;if(f.apply(this,arguments)){var a,s,l,h,p,d,v,g,_,y,m,x,b,w=this,M=t.event.target.__data__.type,T="selection"===(t.event.metaKey?M="overlay":M)?Kl:t.event.altKey?eh:nh,N=n===ih?null:sh[M],k=n===rh?null:fh[M],S=Qn(w),E=S.extent,A=S.selection,C=E[0][0],z=E[0][1],P=E[1][0],R=E[1][1],L=N&&k&&t.event.shiftKey,q=pt(w),D=q,U=i(w,arguments).beforestart();"overlay"===M?S.selection=A=[[a=n===ih?C:q[0],l=n===rh?z:q[1]],[p=n===ih?P:a,v=n===rh?R:l]]:(a=A[0][0],l=A[0][1],p=A[1][0],v=A[1][1]),s=a,h=l,d=p,g=v;var O=ct(w).attr("pointer-events","none"),F=O.selectAll(".overlay").attr("cursor",uh[M]);if(t.event.touches)O.on("touchmove.brush",e,!0).on("touchend.brush touchcancel.brush",u,!0);else{var I=ct(t.event.view).on("keydown.brush",function(){switch(t.event.keyCode){case 16:L=N&&k;break;case 18:T===nh&&(N&&(p=d-_*N,a=s+_*N),k&&(v=g-y*k,l=h+y*k),T=eh,o());break;case 32:T!==nh&&T!==eh||(N<0?p=d-_:N>0&&(a=s-_),k<0?v=g-y:k>0&&(l=h-y),T=th,F.attr("cursor",uh.selection),o());break;default:return}$n()},!0).on("keyup.brush",function(){switch(t.event.keyCode){case 16:L&&(x=b=L=!1,o());break;case 18:T===eh&&(N<0?p=d:N>0&&(a=s),k<0?v=g:k>0&&(l=h),T=nh,o());break;case 32:T===th&&(t.event.altKey?(N&&(p=d-_*N,a=s+_*N),k&&(v=g-y*k,l=h+y*k),T=eh):(N<0?p=d:N>0&&(a=s),k<0?v=g:k>0&&(l=h),T=nh),F.attr("cursor",uh[M]),o());break;default:return}$n()},!0).on("mousemove.brush",e,!0).on("mouseup.brush",u,!0);_t(t.event.view)}Vn(),Pn(w),r.call(w),U.start()}}function a(){var t=this.__brush||{selection:null};return t.extent=s.apply(this,arguments),t.dim=n,t}var c,s=Gn,f=Zn,l=N(e,"start","brush","end"),h=6;return e.move=function(t,e){t.selection?t.on("start.brush",function(){i(this,arguments).beforestart().start()}).on("interrupt.brush end.brush",function(){i(this,arguments).end()}).tween("brush",function(){function t(t){u.selection=1===t&&Jn(s)?null:f(t),r.call(o),a.brush()}var o=this,u=o.__brush,a=i(o,arguments),c=u.selection,s=n.input("function"==typeof e?e.apply(this,arguments):e,u.extent),f=fn(c,s);return c&&s?t:t(1)}):t.each(function(){var t=arguments,o=this.__brush,u=n.input("function"==typeof e?e.apply(this,t):e,o.extent),a=i(this,t).beforestart();Pn(this),o.selection=null==u||Jn(u)?null:u,r.call(this),a.start().brush().end()})},o.prototype={beforestart:function(){return 1==++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(){return this.starting&&(this.starting=!1,this.emit("start")),this},brush:function(){return this.emit("brush"),this},end:function(){return 0==--this.active&&(delete this.state.emitter,this.emit("end")),this},emit:function(t){it(new function(t,n,e){this.target=t,this.type=n,this.selection=e}(e,t,n.output(this.state.selection)),l.apply,l,[t,this.that,this.args])}},e.extent=function(t){return arguments.length?(s="function"==typeof t?t:Xn([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),e):s},e.filter=function(t){return arguments.length?(f="function"==typeof t?t:Xn(!!t),e):f},e.handleSize=function(t){return arguments.length?(h=+t,e):h},e.on=function(){var t=l.on.apply(l,arguments);return t===l?e:t},e}function te(t){return function(){return t}}function ne(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function ee(){return new ne}function re(t){return t.source}function ie(t){return t.target}function oe(t){return t.radius}function ue(t){return t.startAngle}function ae(t){return t.endAngle}function ce(){}function se(t,n){var e=new ce;if(t instanceof ce)t.each(function(t,n){e.set(n,t)});else if(Array.isArray(t)){var r,i=-1,o=t.length;if(null==n)for(;++i<o;)e.set(i,t[i]);else for(;++i<o;)e.set(n(r=t[i],i,t),r)}else if(t)for(var u in t)e.set(u,t[u]);return e}function fe(){return{}}function le(t,n,e){t[n]=e}function he(){return se()}function pe(t,n,e){t.set(n,e)}function de(){}function ve(t,n){var e=new de;if(t instanceof de)t.each(function(t){e.add(t)});else if(t){var r=-1,i=t.length;if(null==n)for(;++r<i;)e.add(t[r]);else for(;++r<i;)e.add(n(t[r],r,t))}return e}function ge(t){return new Function("d","return {"+t.map(function(t,n){return JSON.stringify(t)+": d["+n+"]"}).join(",")+"}")}function _e(t){function n(t,n){function e(){if(s)return Mh;if(f)return f=!1,wh;var n,e,r=a;if(t.charCodeAt(r)===Th){for(;a++<u&&t.charCodeAt(a)!==Th||t.charCodeAt(++a)===Th;);return(n=a)>=u?s=!0:(e=t.charCodeAt(a++))===Nh?f=!0:e===kh&&(f=!0,t.charCodeAt(a)===Nh&&++a),t.slice(r+1,n-1).replace(/""/g,'"')}for(;a<u;){if((e=t.charCodeAt(n=a++))===Nh)f=!0;else if(e===kh)f=!0,t.charCodeAt(a)===Nh&&++a;else if(e!==o)continue;return t.slice(r,n)}return s=!0,t.slice(r,u)}var r,i=[],u=t.length,a=0,c=0,s=u<=0,f=!1;for(t.charCodeAt(u-1)===Nh&&--u,t.charCodeAt(u-1)===kh&&--u;(r=e())!==Mh;){for(var l=[];r!==wh&&r!==Mh;)l.push(r),r=e();n&&null==(l=n(l,c++))||i.push(l)}return i}function e(n){return n.map(r).join(t)}function r(t){return null==t?"":i.test(t+="")?'"'+t.replace(/"/g,'""')+'"':t}var i=new RegExp('["'+t+"\n\r]"),o=t.charCodeAt(0);return{parse:function(t,e){var r,i,o=n(t,function(t,n){if(r)return r(t,n-1);i=t,r=e?function(t,n){var e=ge(t);return function(r,i){return n(e(r),i,t)}}(t,e):ge(t)});return o.columns=i||[],o},parseRows:n,format:function(n,e){return null==e&&(e=function(t){var n=Object.create(null),e=[];return t.forEach(function(t){for(var r in t)r in n||e.push(n[r]=r)}),e}(n)),[e.map(r).join(t)].concat(n.map(function(n){return e.map(function(t){return r(n[t])}).join(t)})).join("\n")},formatRows:function(t){return t.map(e).join("\n")}}}function ye(t){return function(){return t}}function me(){return 1e-6*(Math.random()-.5)}function xe(t,n,e,r){if(isNaN(n)||isNaN(e))return t;var i,o,u,a,c,s,f,l,h,p=t._root,d={data:r},v=t._x0,g=t._y0,_=t._x1,y=t._y1;if(!p)return t._root=d,t;for(;p.length;)if((s=n>=(o=(v+_)/2))?v=o:_=o,(f=e>=(u=(g+y)/2))?g=u:y=u,i=p,!(p=p[l=f<<1|s]))return i[l]=d,t;if(a=+t._x.call(null,p.data),c=+t._y.call(null,p.data),n===a&&e===c)return d.next=p,i?i[l]=d:t._root=d,t;do{i=i?i[l]=new Array(4):t._root=new Array(4),(s=n>=(o=(v+_)/2))?v=o:_=o,(f=e>=(u=(g+y)/2))?g=u:y=u}while((l=f<<1|s)==(h=(c>=u)<<1|a>=o));return i[h]=p,i[l]=d,t}function be(t,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function we(t){return t[0]}function Me(t){return t[1]}function Te(t,n,e){var r=new Ne(null==n?we:n,null==e?Me:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Ne(t,n,e,r,i,o){this._x=t,this._y=n,this._x0=e,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function ke(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}function Se(t){return t.x+t.vx}function Ee(t){return t.y+t.vy}function Ae(t){return t.index}function Ce(t,n){var e=t.get(n);if(!e)throw new Error("missing: "+n);return e}function ze(t){return t.x}function Pe(t){return t.y}function Re(t,n){if((e=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var e,r=t.slice(0,e);return[r.length>1?r[0]+r.slice(2):r,+t.slice(e+1)]}function Le(t){return(t=Re(Math.abs(t)))?t[1]:NaN}function qe(t,n){var e=Re(t,n);if(!e)return t+"";var r=e[0],i=e[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}function De(t){return new Ue(t)}function Ue(t){if(!(n=Bh.exec(t)))throw new Error("invalid format: "+t);var n,e=n[1]||" ",r=n[2]||">",i=n[3]||"-",o=n[4]||"",u=!!n[5],a=n[6]&&+n[6],c=!!n[7],s=n[8]&&+n[8].slice(1),f=n[9]||"";"n"===f?(c=!0,f="g"):Yh[f]||(f=""),(u||"0"===e&&"="===r)&&(u=!0,e="0",r="="),this.fill=e,this.align=r,this.sign=i,this.symbol=o,this.zero=u,this.width=a,this.comma=c,this.precision=s,this.type=f}function Oe(t){return t}function Fe(t){function n(t){function n(t){var n,r,u,f=g,x=_;if("c"===v)x=y(t)+x,t="";else{var b=(t=+t)<0;if(t=y(Math.abs(t),d),b&&0==+t&&(b=!1),f=(b?"("===s?s:"-":"-"===s||"("===s?"":s)+f,x=("s"===v?jh[8+Oh/3]:"")+x+(b&&"("===s?")":""),m)for(n=-1,r=t.length;++n<r;)if(48>(u=t.charCodeAt(n))||u>57){x=(46===u?i+t.slice(n+1):t.slice(n))+x,t=t.slice(0,n);break}}p&&!l&&(t=e(t,1/0));var w=f.length+t.length+x.length,M=w<h?new Array(h-w+1).join(a):"";switch(p&&l&&(t=e(M+t,M.length?h-x.length:1/0),M=""),c){case"<":t=f+t+x+M;break;case"=":t=f+M+t+x;break;case"^":t=M.slice(0,w=M.length>>1)+f+t+x+M.slice(w);break;default:t=M+f+t+x}return o(t)}var a=(t=De(t)).fill,c=t.align,s=t.sign,f=t.symbol,l=t.zero,h=t.width,p=t.comma,d=t.precision,v=t.type,g="$"===f?r[0]:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",_="$"===f?r[1]:/[%p]/.test(v)?u:"",y=Yh[v],m=!v||/[defgprs%]/.test(v);return d=null==d?v?6:12:/[gprs]/.test(v)?Math.max(1,Math.min(21,d)):Math.max(0,Math.min(20,d)),n.toString=function(){return t+""},n}var e=t.grouping&&t.thousands?function(t,n){return function(e,r){for(var i=e.length,o=[],u=0,a=t[0],c=0;i>0&&a>0&&(c+a+1>r&&(a=Math.max(1,r-c)),o.push(e.substring(i-=a,i+a)),!((c+=a+1)>r));)a=t[u=(u+1)%t.length];return o.reverse().join(n)}}(t.grouping,t.thousands):Oe,r=t.currency,i=t.decimal,o=t.numerals?function(t){return function(n){return n.replace(/[0-9]/g,function(n){return t[+n]})}}(t.numerals):Oe,u=t.percent||"%";return{format:n,formatPrefix:function(t,e){var r=n((t=De(t),t.type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Le(e)/3))),o=Math.pow(10,-i),u=jh[8+i/3];return function(t){return r(o*t)+u}}}}function Ie(n){return Hh=Fe(n),t.format=Hh.format,t.formatPrefix=Hh.formatPrefix,Hh}function Ye(t){return Math.max(0,-Le(Math.abs(t)))}function Be(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Le(n)/3)))-Le(Math.abs(t)))}function He(t,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,Le(n)-Le(t))+1}function je(){return new Xe}function Xe(){this.reset()}function Ve(t,n,e){var r=t.s=n+e,i=r-n,o=r-i;t.t=n-o+(e-i)}function $e(t){return t>1?0:t<-1?Np:Math.acos(t)}function We(t){return t>1?kp:t<-1?-kp:Math.asin(t)}function Ze(t){return(t=Fp(t/2))*t}function Ge(){}function Qe(t,n){t&&jp.hasOwnProperty(t.type)&&jp[t.type](t,n)}function Je(t,n,e){var r,i=-1,o=t.length-e;for(n.lineStart();++i<o;)r=t[i],n.point(r[0],r[1],r[2]);n.lineEnd()}function Ke(t,n){var e=-1,r=t.length;for(n.polygonStart();++e<r;)Je(t[e],n,1);n.polygonEnd()}function tr(t,n){t&&Hp.hasOwnProperty(t.type)?Hp[t.type](t,n):Qe(t,n)}function nr(){$p.point=rr}function er(){ir(Xh,Vh)}function rr(t,n){$p.point=ir,Xh=t,Vh=n,$h=t*=Cp,Wh=Lp(n=(n*=Cp)/2+Sp),Zh=Fp(n)}function ir(t,n){n=(n*=Cp)/2+Sp;var e=(t*=Cp)-$h,r=e>=0?1:-1,i=r*e,o=Lp(n),u=Fp(n),a=Zh*u,c=Wh*o+a*Lp(i),s=a*r*Fp(i);Xp.add(Rp(s,c)),$h=t,Wh=o,Zh=u}function or(t){return[Rp(t[1],t[0]),We(t[2])]}function ur(t){var n=t[0],e=t[1],r=Lp(e);return[r*Lp(n),r*Fp(n),Fp(e)]}function ar(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]}function cr(t,n){return[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]]}function sr(t,n){t[0]+=n[0],t[1]+=n[1],t[2]+=n[2]}function fr(t,n){return[t[0]*n,t[1]*n,t[2]*n]}function lr(t){var n=Yp(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=n,t[1]/=n,t[2]/=n}function hr(t,n){ip.push(op=[Gh=t,Jh=t]),n<Qh&&(Qh=n),n>Kh&&(Kh=n)}function pr(t,n){var e=ur([t*Cp,n*Cp]);if(rp){var r=cr(rp,e),i=cr([r[1],-r[0],0],r);lr(i),i=or(i);var o,u=t-tp,a=u>0?1:-1,c=i[0]*Ap*a,s=zp(u)>180;s^(a*tp<c&&c<a*t)?(o=i[1]*Ap)>Kh&&(Kh=o):(c=(c+360)%360-180,s^(a*tp<c&&c<a*t)?(o=-i[1]*Ap)<Qh&&(Qh=o):(n<Qh&&(Qh=n),n>Kh&&(Kh=n))),s?t<tp?mr(Gh,t)>mr(Gh,Jh)&&(Jh=t):mr(t,Jh)>mr(Gh,Jh)&&(Gh=t):Jh>=Gh?(t<Gh&&(Gh=t),t>Jh&&(Jh=t)):t>tp?mr(Gh,t)>mr(Gh,Jh)&&(Jh=t):mr(t,Jh)>mr(Gh,Jh)&&(Gh=t)}else ip.push(op=[Gh=t,Jh=t]);n<Qh&&(Qh=n),n>Kh&&(Kh=n),rp=e,tp=t}function dr(){Zp.point=pr}function vr(){op[0]=Gh,op[1]=Jh,Zp.point=hr,rp=null}function gr(t,n){if(rp){var e=t-tp;Wp.add(zp(e)>180?e+(e>0?360:-360):e)}else np=t,ep=n;$p.point(t,n),pr(t,n)}function _r(){$p.lineStart()}function yr(){gr(np,ep),$p.lineEnd(),zp(Wp)>Mp&&(Gh=-(Jh=180)),op[0]=Gh,op[1]=Jh,rp=null}function mr(t,n){return(n-=t)<0?n+360:n}function xr(t,n){return t[0]-n[0]}function br(t,n){return t[0]<=t[1]?t[0]<=n&&n<=t[1]:n<t[0]||t[1]<n}function wr(t,n){t*=Cp;var e=Lp(n*=Cp);Mr(e*Lp(t),e*Fp(t),Fp(n))}function Mr(t,n,e){cp+=(t-cp)/++up,sp+=(n-sp)/up,fp+=(e-fp)/up}function Tr(){Gp.point=Nr}function Nr(t,n){t*=Cp;var e=Lp(n*=Cp);mp=e*Lp(t),xp=e*Fp(t),bp=Fp(n),Gp.point=kr,Mr(mp,xp,bp)}function kr(t,n){t*=Cp;var e=Lp(n*=Cp),r=e*Lp(t),i=e*Fp(t),o=Fp(n),u=Rp(Yp((u=xp*o-bp*i)*u+(u=bp*r-mp*o)*u+(u=mp*i-xp*r)*u),mp*r+xp*i+bp*o);ap+=u,lp+=u*(mp+(mp=r)),hp+=u*(xp+(xp=i)),pp+=u*(bp+(bp=o)),Mr(mp,xp,bp)}function Sr(){Gp.point=wr}function Er(){Gp.point=Cr}function Ar(){zr(_p,yp),Gp.point=wr}function Cr(t,n){_p=t,yp=n,t*=Cp,n*=Cp,Gp.point=zr;var e=Lp(n);mp=e*Lp(t),xp=e*Fp(t),bp=Fp(n),Mr(mp,xp,bp)}function zr(t,n){t*=Cp;var e=Lp(n*=Cp),r=e*Lp(t),i=e*Fp(t),o=Fp(n),u=xp*o-bp*i,a=bp*r-mp*o,c=mp*i-xp*r,s=Yp(u*u+a*a+c*c),f=We(s),l=s&&-f/s;dp+=l*u,vp+=l*a,gp+=l*c,ap+=f,lp+=f*(mp+(mp=r)),hp+=f*(xp+(xp=i)),pp+=f*(bp+(bp=o)),Mr(mp,xp,bp)}function Pr(t){return function(){return t}}function Rr(t,n){function e(e,r){return e=t(e,r),n(e[0],e[1])}return t.invert&&n.invert&&(e.invert=function(e,r){return(e=n.invert(e,r))&&t.invert(e[0],e[1])}),e}function Lr(t,n){return[t>Np?t-Ep:t<-Np?t+Ep:t,n]}function qr(t,n,e){return(t%=Ep)?n||e?Rr(Ur(t),Or(n,e)):Ur(t):n||e?Or(n,e):Lr}function Dr(t){return function(n,e){return n+=t,[n>Np?n-Ep:n<-Np?n+Ep:n,e]}}function Ur(t){var n=Dr(t);return n.invert=Dr(-t),n}function Or(t,n){function e(t,n){var e=Lp(n),a=Lp(t)*e,c=Fp(t)*e,s=Fp(n),f=s*r+a*i;return[Rp(c*o-f*u,a*r-s*i),We(f*o+c*u)]}var r=Lp(t),i=Fp(t),o=Lp(n),u=Fp(n);return e.invert=function(t,n){var e=Lp(n),a=Lp(t)*e,c=Fp(t)*e,s=Fp(n),f=s*o-c*u;return[Rp(c*o+s*u,a*r+f*i),We(f*r-a*i)]},e}function Fr(t){function n(n){return n=t(n[0]*Cp,n[1]*Cp),n[0]*=Ap,n[1]*=Ap,n}return t=qr(t[0]*Cp,t[1]*Cp,t.length>2?t[2]*Cp:0),n.invert=function(n){return n=t.invert(n[0]*Cp,n[1]*Cp),n[0]*=Ap,n[1]*=Ap,n},n}function Ir(t,n,e,r,i,o){if(e){var u=Lp(n),a=Fp(n),c=r*e;null==i?(i=n+r*Ep,o=n-c/2):(i=Yr(u,i),o=Yr(u,o),(r>0?i<o:i>o)&&(i+=r*Ep));for(var s,f=i;r>0?f>o:f<o;f-=c)s=or([u,-a*Lp(f),-a*Fp(f)]),t.point(s[0],s[1])}}function Yr(t,n){(n=ur(n))[0]-=t,lr(n);var e=$e(-n[1]);return((-n[2]<0?-e:e)+Ep-Mp)%Ep}function Br(){var t,n=[];return{point:function(n,e){t.push([n,e])},lineStart:function(){n.push(t=[])},lineEnd:Ge,rejoin:function(){n.length>1&&n.push(n.pop().concat(n.shift()))},result:function(){var e=n;return n=[],t=null,e}}}function Hr(t,n){return zp(t[0]-n[0])<Mp&&zp(t[1]-n[1])<Mp}function jr(t,n,e,r){this.x=t,this.z=n,this.o=e,this.e=r,this.v=!1,this.n=this.p=null}function Xr(t,n,e,r,i){var o,u,a=[],c=[];if(t.forEach(function(t){if(!((n=t.length-1)<=0)){var n,e,r=t[0],u=t[n];if(Hr(r,u)){for(i.lineStart(),o=0;o<n;++o)i.point((r=t[o])[0],r[1]);i.lineEnd()}else a.push(e=new jr(r,t,null,!0)),c.push(e.o=new jr(r,null,e,!1)),a.push(e=new jr(u,t,null,!1)),c.push(e.o=new jr(u,null,e,!0))}}),a.length){for(c.sort(n),Vr(a),Vr(c),o=0,u=c.length;o<u;++o)c[o].e=e=!e;for(var s,f,l=a[0];;){for(var h=l,p=!0;h.v;)if((h=h.n)===l)return;s=h.z,i.lineStart();do{if(h.v=h.o.v=!0,h.e){if(p)for(o=0,u=s.length;o<u;++o)i.point((f=s[o])[0],f[1]);else r(h.x,h.n.x,1,i);h=h.n}else{if(p)for(s=h.p.z,o=s.length-1;o>=0;--o)i.point((f=s[o])[0],f[1]);else r(h.x,h.p.x,-1,i);h=h.p}s=(h=h.o).z,p=!p}while(!h.v);i.lineEnd()}}}function Vr(t){if(n=t.length){for(var n,e,r=0,i=t[0];++r<n;)i.n=e=t[r],e.p=i,i=e;i.n=e=t[0],e.p=i}}function $r(t,n){var e=n[0],r=n[1],i=[Fp(e),-Lp(e),0],o=0,u=0;cd.reset();for(var a=0,c=t.length;a<c;++a)if(f=(s=t[a]).length)for(var s,f,l=s[f-1],h=l[0],p=l[1]/2+Sp,d=Fp(p),v=Lp(p),g=0;g<f;++g,h=y,d=x,v=b,l=_){var _=s[g],y=_[0],m=_[1]/2+Sp,x=Fp(m),b=Lp(m),w=y-h,M=w>=0?1:-1,T=M*w,N=T>Np,k=d*x;if(cd.add(Rp(k*M*Fp(T),v*b+k*Lp(T))),o+=N?w+M*Ep:w,N^h>=e^y>=e){var S=cr(ur(l),ur(_));lr(S);var E=cr(i,S);lr(E);var A=(N^w>=0?-1:1)*We(E[2]);(r>A||r===A&&(S[0]||S[1]))&&(u+=N^w>=0?1:-1)}}return(o<-Mp||o<Mp&&cd<-Mp)^1&u}function Wr(t,n,e,r){return function(i){function o(n,e){t(n,e)&&i.point(n,e)}function u(t,n){v.point(t,n)}function a(){x.point=u,v.lineStart()}function c(){x.point=o,v.lineEnd()}function s(t,n){d.push([t,n]),y.point(t,n)}function f(){y.lineStart(),d=[]}function l(){s(d[0][0],d[0][1]),y.lineEnd();var t,n,e,r,o=y.clean(),u=_.result(),a=u.length;if(d.pop(),h.push(d),d=null,a)if(1&o){if(e=u[0],(n=e.length-1)>0){for(m||(i.polygonStart(),m=!0),i.lineStart(),t=0;t<n;++t)i.point((r=e[t])[0],r[1]);i.lineEnd()}}else a>1&&2&o&&u.push(u.pop().concat(u.shift())),p.push(u.filter(Zr))}var h,p,d,v=n(i),_=Br(),y=n(_),m=!1,x={point:o,lineStart:a,lineEnd:c,polygonStart:function(){x.point=s,x.lineStart=f,x.lineEnd=l,p=[],h=[]},polygonEnd:function(){x.point=o,x.lineStart=a,x.lineEnd=c,p=g(p);var t=$r(h,r);p.length?(m||(i.polygonStart(),m=!0),Xr(p,Gr,t,e,i)):t&&(m||(i.polygonStart(),m=!0),i.lineStart(),e(null,null,1,i),i.lineEnd()),m&&(i.polygonEnd(),m=!1),p=h=null},sphere:function(){i.polygonStart(),i.lineStart(),e(null,null,1,i),i.lineEnd(),i.polygonEnd()}};return x}}function Zr(t){return t.length>1}function Gr(t,n){return((t=t.x)[0]<0?t[1]-kp-Mp:kp-t[1])-((n=n.x)[0]<0?n[1]-kp-Mp:kp-n[1])}function Qr(t){function n(t,n){return Lp(t)*Lp(n)>i}function e(t,n,e){var r=[1,0,0],o=cr(ur(t),ur(n)),u=ar(o,o),a=o[0],c=u-a*a;if(!c)return!e&&t;var s=i*u/c,f=-i*a/c,l=cr(r,o),h=fr(r,s);sr(h,fr(o,f));var p=l,d=ar(h,p),v=ar(p,p),g=d*d-v*(ar(h,h)-1);if(!(g<0)){var _=Yp(g),y=fr(p,(-d-_)/v);if(sr(y,h),y=or(y),!e)return y;var m,x=t[0],b=n[0],w=t[1],M=n[1];b<x&&(m=x,x=b,b=m);var T=b-x,N=zp(T-Np)<Mp;if(!N&&M<w&&(m=w,w=M,M=m),N||T<Mp?N?w+M>0^y[1]<(zp(y[0]-x)<Mp?w:M):w<=y[1]&&y[1]<=M:T>Np^(x<=y[0]&&y[0]<=b)){var k=fr(p,(-d+_)/v);return sr(k,h),[y,or(k)]}}}function r(n,e){var r=u?t:Np-t,i=0;return n<-r?i|=1:n>r&&(i|=2),e<-r?i|=4:e>r&&(i|=8),i}var i=Lp(t),o=6*Cp,u=i>0,a=zp(i)>Mp;return Wr(n,function(t){var i,o,c,s,f;return{lineStart:function(){s=c=!1,f=1},point:function(l,h){var p,d=[l,h],v=n(l,h),g=u?v?0:r(l,h):v?r(l+(l<0?Np:-Np),h):0;if(!i&&(s=c=v)&&t.lineStart(),v!==c&&(!(p=e(i,d))||Hr(i,p)||Hr(d,p))&&(d[0]+=Mp,d[1]+=Mp,v=n(d[0],d[1])),v!==c)f=0,v?(t.lineStart(),p=e(d,i),t.point(p[0],p[1])):(p=e(i,d),t.point(p[0],p[1]),t.lineEnd()),i=p;else if(a&&i&&u^v){var _;g&o||!(_=e(d,i,!0))||(f=0,u?(t.lineStart(),t.point(_[0][0],_[0][1]),t.point(_[1][0],_[1][1]),t.lineEnd()):(t.point(_[1][0],_[1][1]),t.lineEnd(),t.lineStart(),t.point(_[0][0],_[0][1])))}!v||i&&Hr(i,d)||t.point(d[0],d[1]),i=d,c=v,o=g},lineEnd:function(){c&&t.lineEnd(),i=null},clean:function(){return f|(s&&c)<<1}}},function(n,e,r,i){Ir(i,t,o,r,n,e)},u?[0,-t]:[-Np,t-Np])}function Jr(t,n,e,r){function i(i,o){return t<=i&&i<=e&&n<=o&&o<=r}function o(i,o,a,s){var f=0,l=0;if(null==i||(f=u(i,a))!==(l=u(o,a))||c(i,o)<0^a>0)do{s.point(0===f||3===f?t:e,f>1?r:n)}while((f=(f+a+4)%4)!==l);else s.point(o[0],o[1])}function u(r,i){return zp(r[0]-t)<Mp?i>0?0:3:zp(r[0]-e)<Mp?i>0?2:1:zp(r[1]-n)<Mp?i>0?1:0:i>0?3:2}function a(t,n){return c(t.x,n.x)}function c(t,n){var e=u(t,1),r=u(n,1);return e!==r?e-r:0===e?n[1]-t[1]:1===e?t[0]-n[0]:2===e?t[1]-n[1]:n[0]-t[0]}return function(u){function c(t,n){i(t,n)&&w.point(t,n)}function s(o,u){var a=i(o,u);if(l&&h.push([o,u]),x)p=o,d=u,v=a,x=!1,a&&(w.lineStart(),w.point(o,u));else if(a&&m)w.point(o,u);else{var c=[_=Math.max(ld,Math.min(fd,_)),y=Math.max(ld,Math.min(fd,y))],s=[o=Math.max(ld,Math.min(fd,o)),u=Math.max(ld,Math.min(fd,u))];!function(t,n,e,r,i,o){var u,a=t[0],c=t[1],s=0,f=1,l=n[0]-a,h=n[1]-c;if(u=e-a,l||!(u>0)){if(u/=l,l<0){if(u<s)return;u<f&&(f=u)}else if(l>0){if(u>f)return;u>s&&(s=u)}if(u=i-a,l||!(u<0)){if(u/=l,l<0){if(u>f)return;u>s&&(s=u)}else if(l>0){if(u<s)return;u<f&&(f=u)}if(u=r-c,h||!(u>0)){if(u/=h,h<0){if(u<s)return;u<f&&(f=u)}else if(h>0){if(u>f)return;u>s&&(s=u)}if(u=o-c,h||!(u<0)){if(u/=h,h<0){if(u>f)return;u>s&&(s=u)}else if(h>0){if(u<s)return;u<f&&(f=u)}return s>0&&(t[0]=a+s*l,t[1]=c+s*h),f<1&&(n[0]=a+f*l,n[1]=c+f*h),!0}}}}}(c,s,t,n,e,r)?a&&(w.lineStart(),w.point(o,u),b=!1):(m||(w.lineStart(),w.point(c[0],c[1])),w.point(s[0],s[1]),a||w.lineEnd(),b=!1)}_=o,y=u,m=a}var f,l,h,p,d,v,_,y,m,x,b,w=u,M=Br(),T={point:c,lineStart:function(){T.point=s,l&&l.push(h=[]),x=!0,m=!1,_=y=NaN},lineEnd:function(){f&&(s(p,d),v&&m&&M.rejoin(),f.push(M.result())),T.point=c,m&&w.lineEnd()},polygonStart:function(){w=M,f=[],l=[],b=!0},polygonEnd:function(){var n=function(){for(var n=0,e=0,i=l.length;e<i;++e)for(var o,u,a=l[e],c=1,s=a.length,f=a[0],h=f[0],p=f[1];c<s;++c)o=h,u=p,h=(f=a[c])[0],p=f[1],u<=r?p>r&&(h-o)*(r-u)>(p-u)*(t-o)&&++n:p<=r&&(h-o)*(r-u)<(p-u)*(t-o)&&--n;return n}(),e=b&&n,i=(f=g(f)).length;(e||i)&&(u.polygonStart(),e&&(u.lineStart(),o(null,null,1,u),u.lineEnd()),i&&Xr(f,a,n,o,u),u.polygonEnd()),w=u,f=l=h=null}};return T}}function Kr(){pd.point=pd.lineEnd=Ge}function ti(t,n){Qp=t*=Cp,Jp=Fp(n*=Cp),Kp=Lp(n),pd.point=ni}function ni(t,n){t*=Cp;var e=Fp(n*=Cp),r=Lp(n),i=zp(t-Qp),o=Lp(i),u=r*Fp(i),a=Kp*e-Jp*r*o,c=Jp*e+Kp*r*o;hd.add(Rp(Yp(u*u+a*a),c)),Qp=t,Jp=e,Kp=r}function ei(t){return hd.reset(),tr(t,pd),+hd}function ri(t,n){return dd[0]=t,dd[1]=n,ei(vd)}function ii(t,n){return!(!t||!_d.hasOwnProperty(t.type))&&_d[t.type](t,n)}function oi(t,n){return 0===ri(t,n)}function ui(t,n){var e=ri(t[0],t[1]);return ri(t[0],n)+ri(n,t[1])<=e+Mp}function ai(t,n){return!!$r(t.map(ci),si(n))}function ci(t){return(t=t.map(si)).pop(),t}function si(t){return[t[0]*Cp,t[1]*Cp]}function fi(t,n,e){var r=f(t,n-Mp,e).concat(n);return function(t){return r.map(function(n){return[t,n]})}}function li(t,n,e){var r=f(t,n-Mp,e).concat(n);return function(t){return r.map(function(n){return[n,t]})}}function hi(){function t(){return{type:"MultiLineString",coordinates:n()}}function n(){return f(qp(o/_)*_,i,_).map(p).concat(f(qp(s/y)*y,c,y).map(d)).concat(f(qp(r/v)*v,e,v).filter(function(t){return zp(t%_)>Mp}).map(l)).concat(f(qp(a/g)*g,u,g).filter(function(t){return zp(t%y)>Mp}).map(h))}var e,r,i,o,u,a,c,s,l,h,p,d,v=10,g=v,_=90,y=360,m=2.5;return t.lines=function(){return n().map(function(t){return{type:"LineString",coordinates:t}})},t.outline=function(){return{type:"Polygon",coordinates:[p(o).concat(d(c).slice(1),p(i).reverse().slice(1),d(s).reverse().slice(1))]}},t.extent=function(n){return arguments.length?t.extentMajor(n).extentMinor(n):t.extentMinor()},t.extentMajor=function(n){return arguments.length?(o=+n[0][0],i=+n[1][0],s=+n[0][1],c=+n[1][1],o>i&&(n=o,o=i,i=n),s>c&&(n=s,s=c,c=n),t.precision(m)):[[o,s],[i,c]]},t.extentMinor=function(n){return arguments.length?(r=+n[0][0],e=+n[1][0],a=+n[0][1],u=+n[1][1],r>e&&(n=r,r=e,e=n),a>u&&(n=a,a=u,u=n),t.precision(m)):[[r,a],[e,u]]},t.step=function(n){return arguments.length?t.stepMajor(n).stepMinor(n):t.stepMinor()},t.stepMajor=function(n){return arguments.length?(_=+n[0],y=+n[1],t):[_,y]},t.stepMinor=function(n){return arguments.length?(v=+n[0],g=+n[1],t):[v,g]},t.precision=function(n){return arguments.length?(m=+n,l=fi(a,u,90),h=li(r,e,m),p=fi(s,c,90),d=li(o,i,m),t):m},t.extentMajor([[-180,-90+Mp],[180,90-Mp]]).extentMinor([[-180,-80-Mp],[180,80+Mp]])}function pi(t){return t}function di(){xd.point=vi}function vi(t,n){xd.point=gi,td=ed=t,nd=rd=n}function gi(t,n){md.add(rd*t-ed*n),ed=t,rd=n}function _i(){gi(td,nd)}function yi(t,n){kd+=t,Sd+=n,++Ed}function mi(){qd.point=xi}function xi(t,n){qd.point=bi,yi(ud=t,ad=n)}function bi(t,n){var e=t-ud,r=n-ad,i=Yp(e*e+r*r);Ad+=i*(ud+t)/2,Cd+=i*(ad+n)/2,zd+=i,yi(ud=t,ad=n)}function wi(){qd.point=yi}function Mi(){qd.point=Ni}function Ti(){ki(id,od)}function Ni(t,n){qd.point=ki,yi(id=ud=t,od=ad=n)}function ki(t,n){var e=t-ud,r=n-ad,i=Yp(e*e+r*r);Ad+=i*(ud+t)/2,Cd+=i*(ad+n)/2,zd+=i,Pd+=(i=ad*t-ud*n)*(ud+t),Rd+=i*(ad+n),Ld+=3*i,yi(ud=t,ad=n)}function Si(t){this._context=t}function Ei(t,n){Bd.point=Ai,Ud=Fd=t,Od=Id=n}function Ai(t,n){Fd-=t,Id-=n,Yd.add(Yp(Fd*Fd+Id*Id)),Fd=t,Id=n}function Ci(){this._string=[]}function zi(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function Pi(t){return function(n){var e=new Ri;for(var r in t)e[r]=t[r];return e.stream=n,e}}function Ri(){}function Li(t,n,e){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=r&&t.clipExtent(null),tr(e,t.stream(Nd)),n(Nd.result()),null!=r&&t.clipExtent(r),t}function qi(t,n,e){return Li(t,function(e){var r=n[1][0]-n[0][0],i=n[1][1]-n[0][1],o=Math.min(r/(e[1][0]-e[0][0]),i/(e[1][1]-e[0][1])),u=+n[0][0]+(r-o*(e[1][0]+e[0][0]))/2,a=+n[0][1]+(i-o*(e[1][1]+e[0][1]))/2;t.scale(150*o).translate([u,a])},e)}function Di(t,n,e){return qi(t,[[0,0],n],e)}function Ui(t,n,e){return Li(t,function(e){var r=+n,i=r/(e[1][0]-e[0][0]),o=(r-i*(e[1][0]+e[0][0]))/2,u=-i*e[0][1];t.scale(150*i).translate([o,u])},e)}function Oi(t,n,e){return Li(t,function(e){var r=+n,i=r/(e[1][1]-e[0][1]),o=-i*e[0][0],u=(r-i*(e[1][1]+e[0][1]))/2;t.scale(150*i).translate([o,u])},e)}function Fi(t,n){return+n?function(t,n){function e(r,i,o,u,a,c,s,f,l,h,p,d,v,g){var _=s-r,y=f-i,m=_*_+y*y;if(m>4*n&&v--){var x=u+h,b=a+p,w=c+d,M=Yp(x*x+b*b+w*w),T=We(w/=M),N=zp(zp(w)-1)<Mp||zp(o-l)<Mp?(o+l)/2:Rp(b,x),k=t(N,T),S=k[0],E=k[1],A=S-r,C=E-i,z=y*A-_*C;(z*z/m>n||zp((_*A+y*C)/m-.5)>.3||u*h+a*p+c*d<jd)&&(e(r,i,o,u,a,c,S,E,N,x/=M,b/=M,w,v,g),g.point(S,E),e(S,E,N,x,b,w,s,f,l,h,p,d,v,g))}}return function(n){function r(e,r){e=t(e,r),n.point(e[0],e[1])}function i(){_=NaN,w.point=o,n.lineStart()}function o(r,i){var o=ur([r,i]),u=t(r,i);e(_,y,g,m,x,b,_=u[0],y=u[1],g=r,m=o[0],x=o[1],b=o[2],Hd,n),n.point(_,y)}function u(){w.point=r,n.lineEnd()}function a(){i(),w.point=c,w.lineEnd=s}function c(t,n){o(f=t,n),l=_,h=y,p=m,d=x,v=b,w.point=o}function s(){e(_,y,g,m,x,b,l,h,f,p,d,v,Hd,n),w.lineEnd=u,u()}var f,l,h,p,d,v,g,_,y,m,x,b,w={point:r,lineStart:i,lineEnd:u,polygonStart:function(){n.polygonStart(),w.lineStart=a},polygonEnd:function(){n.polygonEnd(),w.lineStart=i}};return w}}(t,n):function(t){return Pi({point:function(n,e){n=t(n,e),this.stream.point(n[0],n[1])}})}(t)}function Ii(t){return Yi(function(){return t})()}function Yi(t){function n(t){return t=s(t[0]*Cp,t[1]*Cp),[t[0]*v+u,a-t[1]*v]}function e(t,n){return t=o(t,n),[t[0]*v+u,a-t[1]*v]}function r(){s=Rr(c=qr(x,b,w),o);var t=o(y,m);return u=g-t[0]*v,a=_+t[1]*v,i()}function i(){return p=d=null,n}var o,u,a,c,s,f,l,h,p,d,v=150,g=480,_=250,y=0,m=0,x=0,b=0,w=0,M=null,T=sd,N=null,k=pi,S=.5,E=Fi(e,S);return n.stream=function(t){return p&&d===t?p:p=Xd(function(t){return Pi({point:function(n,e){var r=t(n,e);return this.stream.point(r[0],r[1])}})}(c)(T(E(k(d=t)))))},n.preclip=function(t){return arguments.length?(T=t,M=void 0,i()):T},n.postclip=function(t){return arguments.length?(k=t,N=f=l=h=null,i()):k},n.clipAngle=function(t){return arguments.length?(T=+t?Qr(M=t*Cp):(M=null,sd),i()):M*Ap},n.clipExtent=function(t){return arguments.length?(k=null==t?(N=f=l=h=null,pi):Jr(N=+t[0][0],f=+t[0][1],l=+t[1][0],h=+t[1][1]),i()):null==N?null:[[N,f],[l,h]]},n.scale=function(t){return arguments.length?(v=+t,r()):v},n.translate=function(t){return arguments.length?(g=+t[0],_=+t[1],r()):[g,_]},n.center=function(t){return arguments.length?(y=t[0]%360*Cp,m=t[1]%360*Cp,r()):[y*Ap,m*Ap]},n.rotate=function(t){return arguments.length?(x=t[0]%360*Cp,b=t[1]%360*Cp,w=t.length>2?t[2]%360*Cp:0,r()):[x*Ap,b*Ap,w*Ap]},n.precision=function(t){return arguments.length?(E=Fi(e,S=t*t),i()):Yp(S)},n.fitExtent=function(t,e){return qi(n,t,e)},n.fitSize=function(t,e){return Di(n,t,e)},n.fitWidth=function(t,e){return Ui(n,t,e)},n.fitHeight=function(t,e){return Oi(n,t,e)},function(){return o=t.apply(this,arguments),n.invert=o.invert&&function(t){return(t=s.invert((t[0]-u)/v,(a-t[1])/v))&&[t[0]*Ap,t[1]*Ap]},r()}}function Bi(t){var n=0,e=Np/3,r=Yi(t),i=r(n,e);return i.parallels=function(t){return arguments.length?r(n=t[0]*Cp,e=t[1]*Cp):[n*Ap,e*Ap]},i}function Hi(t,n){function e(t,n){var e=Yp(o-2*i*Fp(n))/i;return[e*Fp(t*=i),u-e*Lp(t)]}var r=Fp(t),i=(r+Fp(n))/2;if(zp(i)<Mp)return function(t){function n(t,n){return[t*e,Fp(n)/e]}var e=Lp(t);return n.invert=function(t,n){return[t/e,We(n*e)]},n}(t);var o=1+r*(2*i-r),u=Yp(o)/i;return e.invert=function(t,n){var e=u-n;return[Rp(t,zp(e))/i*Ip(e),We((o-(t*t+e*e)*i*i)/(2*i))]},e}function ji(){return Bi(Hi).scale(155.424).center([0,33.6442])}function Xi(){return ji().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function Vi(t){return function(n,e){var r=Lp(n),i=Lp(e),o=t(r*i);return[o*i*Fp(n),o*Fp(e)]}}function $i(t){return function(n,e){var r=Yp(n*n+e*e),i=t(r),o=Fp(i),u=Lp(i);return[Rp(n*o,r*u),We(r&&e*o/r)]}}function Wi(t,n){return[t,Up(Bp((kp+n)/2))]}function Zi(t){function n(){var n=Np*a(),u=o(Fr(o.rotate()).invert([0,0]));return s(null==f?[[u[0]-n,u[1]-n],[u[0]+n,u[1]+n]]:t===Wi?[[Math.max(u[0]-n,f),e],[Math.min(u[0]+n,r),i]]:[[f,Math.max(u[1]-n,e)],[r,Math.min(u[1]+n,i)]])}var e,r,i,o=Ii(t),u=o.center,a=o.scale,c=o.translate,s=o.clipExtent,f=null;return o.scale=function(t){return arguments.length?(a(t),n()):a()},o.translate=function(t){return arguments.length?(c(t),n()):c()},o.center=function(t){return arguments.length?(u(t),n()):u()},o.clipExtent=function(t){return arguments.length?(null==t?f=e=r=i=null:(f=+t[0][0],e=+t[0][1],r=+t[1][0],i=+t[1][1]),n()):null==f?null:[[f,e],[r,i]]},n()}function Gi(t){return Bp((kp+t)/2)}function Qi(t,n){function e(t,n){o>0?n<-kp+Mp&&(n=-kp+Mp):n>kp-Mp&&(n=kp-Mp);var e=o/Op(Gi(n),i);return[e*Fp(i*t),o-e*Lp(i*t)]}var r=Lp(t),i=t===n?Fp(t):Up(r/Lp(n))/Up(Gi(n)/Gi(t)),o=r*Op(Gi(t),i)/i;return i?(e.invert=function(t,n){var e=o-n,r=Ip(i)*Yp(t*t+e*e);return[Rp(t,zp(e))/i*Ip(e),2*Pp(Op(o/r,1/i))-kp]},e):Wi}function Ji(t,n){return[t,n]}function Ki(t,n){function e(t,n){var e=o-n,r=i*t;return[e*Fp(r),o-e*Lp(r)]}var r=Lp(t),i=t===n?Fp(t):(r-Lp(n))/(n-t),o=r/i+t;return zp(i)<Mp?Ji:(e.invert=function(t,n){var e=o-n;return[Rp(t,zp(e))/i*Ip(e),o-Ip(i)*Yp(t*t+e*e)]},e)}function to(t,n){var e=Lp(n),r=Lp(t)*e;return[e*Fp(t)/r,Fp(n)/r]}function no(t,n,e,r){return 1===t&&1===n&&0===e&&0===r?pi:Pi({point:function(i,o){this.stream.point(i*t+e,o*n+r)}})}function eo(t,n){var e=n*n,r=e*e;return[t*(.8707-.131979*e+r*(r*(.003971*e-.001529*r)-.013791)),n*(1.007226+e*(.015085+r*(.028874*e-.044475-.005916*r)))]}function ro(t,n){return[Lp(n)*Fp(t),Fp(n)]}function io(t,n){var e=Lp(n),r=1+Lp(t)*e;return[e*Fp(t)/r,Fp(n)/r]}function oo(t,n){return[Up(Bp((kp+n)/2)),-t]}function uo(t,n){return t.parent===n.parent?1:2}function ao(t,n){return t+n.x}function co(t,n){return Math.max(t,n.y)}function so(t){var n=0,e=t.children,r=e&&e.length;if(r)for(;--r>=0;)n+=e[r].value;else n=1;t.value=n}function fo(t,n){var e,r,i,o,u,a=new vo(t),c=+t.value&&(a.value=t.value),s=[a];for(null==n&&(n=lo);e=s.pop();)if(c&&(e.value=+e.data.value),(i=n(e.data))&&(u=i.length))for(e.children=new Array(u),o=u-1;o>=0;--o)s.push(r=e.children[o]=new vo(i[o])),r.parent=e,r.depth=e.depth+1;return a.eachBefore(po)}function lo(t){return t.children}function ho(t){t.data=t.data.data}function po(t){var n=0;do{t.height=n}while((t=t.parent)&&t.height<++n)}function vo(t){this.data=t,this.depth=this.height=0,this.parent=null}function go(t){for(var n,e,r=0,i=(t=function(t){for(var n,e,r=t.length;r;)e=Math.random()*r--|0,n=t[r],t[r]=t[e],t[e]=n;return t}(Wd.call(t))).length,o=[];r<i;)n=t[r],e&&yo(e,n)?++r:(e=function(t){switch(t.length){case 1:return function(t){return{x:t.x,y:t.y,r:t.r}}(t[0]);case 2:return xo(t[0],t[1]);case 3:return bo(t[0],t[1],t[2])}}(o=function(t,n){var e,r;if(mo(n,t))return[n];for(e=0;e<t.length;++e)if(_o(n,t[e])&&mo(xo(t[e],n),t))return[t[e],n];for(e=0;e<t.length-1;++e)for(r=e+1;r<t.length;++r)if(_o(xo(t[e],t[r]),n)&&_o(xo(t[e],n),t[r])&&_o(xo(t[r],n),t[e])&&mo(bo(t[e],t[r],n),t))return[t[e],t[r],n];throw new Error}(o,n)),r=0);return e}function _o(t,n){var e=t.r-n.r,r=n.x-t.x,i=n.y-t.y;return e<0||e*e<r*r+i*i}function yo(t,n){var e=t.r-n.r+1e-6,r=n.x-t.x,i=n.y-t.y;return e>0&&e*e>r*r+i*i}function mo(t,n){for(var e=0;e<n.length;++e)if(!yo(t,n[e]))return!1;return!0}function xo(t,n){var e=t.x,r=t.y,i=t.r,o=n.x,u=n.y,a=n.r,c=o-e,s=u-r,f=a-i,l=Math.sqrt(c*c+s*s);return{x:(e+o+c/l*f)/2,y:(r+u+s/l*f)/2,r:(l+i+a)/2}}function bo(t,n,e){var r=t.x,i=t.y,o=t.r,u=n.x,a=n.y,c=n.r,s=e.x,f=e.y,l=e.r,h=r-u,p=r-s,d=i-a,v=i-f,g=c-o,_=l-o,y=r*r+i*i-o*o,m=y-u*u-a*a+c*c,x=y-s*s-f*f+l*l,b=p*d-h*v,w=(d*x-v*m)/(2*b)-r,M=(v*g-d*_)/b,T=(p*m-h*x)/(2*b)-i,N=(h*_-p*g)/b,k=M*M+N*N-1,S=2*(o+w*M+T*N),E=w*w+T*T-o*o,A=-(k?(S+Math.sqrt(S*S-4*k*E))/(2*k):E/S);return{x:r+w+M*A,y:i+T+N*A,r:A}}function wo(t,n,e){var r=t.x,i=t.y,o=n.r+e.r,u=t.r+e.r,a=n.x-r,c=n.y-i,s=a*a+c*c;if(s){var f=.5+((u*=u)-(o*=o))/(2*s),l=Math.sqrt(Math.max(0,2*o*(u+s)-(u-=s)*u-o*o))/(2*s);e.x=r+f*a+l*c,e.y=i+f*c-l*a}else e.x=r+u,e.y=i}function Mo(t,n){var e=n.x-t.x,r=n.y-t.y,i=t.r+n.r;return i*i-1e-6>e*e+r*r}function To(t){var n=t._,e=t.next._,r=n.r+e.r,i=(n.x*e.r+e.x*n.r)/r,o=(n.y*e.r+e.y*n.r)/r;return i*i+o*o}function No(t){this._=t,this.next=null,this.previous=null}function ko(t){if(!(i=t.length))return 0;var n,e,r,i,o,u,a,c,s,f,l;if(n=t[0],n.x=0,n.y=0,!(i>1))return n.r;if(e=t[1],n.x=-e.r,e.x=n.r,e.y=0,!(i>2))return n.r+e.r;wo(e,n,r=t[2]),n=new No(n),e=new No(e),r=new No(r),n.next=r.previous=e,e.next=n.previous=r,r.next=e.previous=n;t:for(a=3;a<i;++a){wo(n._,e._,r=t[a]),r=new No(r),c=e.next,s=n.previous,f=e._.r,l=n._.r;do{if(f<=l){if(Mo(c._,r._)){e=c,n.next=e,e.previous=n,--a;continue t}f+=c._.r,c=c.next}else{if(Mo(s._,r._)){(n=s).next=e,e.previous=n,--a;continue t}l+=s._.r,s=s.previous}}while(c!==s.next);for(r.previous=n,r.next=e,n.next=e.previous=e=r,o=To(n);(r=r.next)!==e;)(u=To(r))<o&&(n=r,o=u);e=n.next}for(n=[e._],r=e;(r=r.next)!==e;)n.push(r._);for(r=go(n),a=0;a<i;++a)n=t[a],n.x-=r.x,n.y-=r.y;return r.r}function So(t){if("function"!=typeof t)throw new Error;return t}function Eo(){return 0}function Ao(t){return function(){return t}}function Co(t){return Math.sqrt(t.value)}function zo(t){return function(n){n.children||(n.r=Math.max(0,+t(n)||0))}}function Po(t,n){return function(e){if(r=e.children){var r,i,o,u=r.length,a=t(e)*n||0;if(a)for(i=0;i<u;++i)r[i].r+=a;if(o=ko(r),a)for(i=0;i<u;++i)r[i].r-=a;e.r=o+a}}}function Ro(t){return function(n){var e=n.parent;n.r*=t,e&&(n.x=e.x+t*n.x,n.y=e.y+t*n.y)}}function Lo(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function qo(t,n,e,r,i){for(var o,u=t.children,a=-1,c=u.length,s=t.value&&(r-n)/t.value;++a<c;)(o=u[a]).y0=e,o.y1=i,o.x0=n,o.x1=n+=o.value*s}function Do(t){return t.id}function Uo(t){return t.parentId}function Oo(t,n){return t.parent===n.parent?1:2}function Fo(t){var n=t.children;return n?n[0]:t.t}function Io(t){var n=t.children;return n?n[n.length-1]:t.t}function Yo(t,n,e){var r=e/(n.i-t.i);n.c-=r,n.s+=e,t.c+=r,n.z+=e,n.m+=e}function Bo(t,n,e){return t.a.parent===n.parent?t.a:e}function Ho(t,n){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=n}function jo(t,n,e,r,i){for(var o,u=t.children,a=-1,c=u.length,s=t.value&&(i-e)/t.value;++a<c;)(o=u[a]).x0=n,o.x1=r,o.y0=e,o.y1=e+=o.value*s}function Xo(t,n,e,r,i,o){for(var u,a,c,s,f,l,h,p,d,v,g,_=[],y=n.children,m=0,x=0,b=y.length,w=n.value;m<b;){c=i-e,s=o-r;do{f=y[x++].value}while(!f&&x<b);for(l=h=f,g=f*f*(v=Math.max(s/c,c/s)/(w*t)),d=Math.max(h/g,g/l);x<b;++x){if(f+=a=y[x].value,a<l&&(l=a),a>h&&(h=a),g=f*f*v,(p=Math.max(h/g,g/l))>d){f-=a;break}d=p}_.push(u={value:f,dice:c<s,children:y.slice(m,x)}),u.dice?qo(u,e,r,i,w?r+=s*f/w:o):jo(u,e,r,w?e+=c*f/w:i,o),w-=f,m=x}return _}function Vo(t,n,e){return(n[0]-t[0])*(e[1]-t[1])-(n[1]-t[1])*(e[0]-t[0])}function $o(t,n){return t[0]-n[0]||t[1]-n[1]}function Wo(t){for(var n=t.length,e=[0,1],r=2,i=2;i<n;++i){for(;r>1&&Vo(t[e[r-2]],t[e[r-1]],t[i])<=0;)--r;e[r++]=i}return e.slice(0,r)}function Zo(t){this._size=t,this._call=this._error=null,this._tasks=[],this._data=[],this._waiting=this._active=this._ended=this._start=0}function Go(t){if(!t._start)try{(function(t){for(;t._start=t._waiting&&t._active<t._size;){var n=t._ended+t._active,e=t._tasks[n],r=e.length-1,i=e[r];e[r]=function(t,n){return function(e,r){t._tasks[n]&&(--t._active,++t._ended,t._tasks[n]=null,null==t._error&&(null!=e?Qo(t,e):(t._data[n]=r,t._waiting?Go(t):Jo(t))))}}(t,n),--t._waiting,++t._active,e=i.apply(null,e),t._tasks[n]&&(t._tasks[n]=e||ev)}})(t)}catch(n){if(t._tasks[t._ended+t._active-1])Qo(t,n);else if(!t._data)throw n}}function Qo(t,n){var e,r=t._tasks.length;for(t._error=n,t._data=void 0,t._waiting=NaN;--r>=0;)if((e=t._tasks[r])&&(t._tasks[r]=null,e.abort))try{e.abort()}catch(n){}t._active=NaN,Jo(t)}function Jo(t){if(!t._active&&t._call){var n=t._data;t._data=void 0,t._call(t._error,n)}}function Ko(t){if(null==t)t=1/0;else if(!((t=+t)>=1))throw new Error("invalid concurrency");return new Zo(t)}function tu(){return Math.random()}function nu(t,n){function e(t){var n,e=s.status;if(!e&&function(t){var n=t.responseType;return n&&"text"!==n?t.response:t.responseText}(s)||e>=200&&e<300||304===e){if(o)try{n=o.call(r,s)}catch(t){return void a.call("error",r,t)}else n=s;a.call("load",r,n)}else a.call("error",r,t)}var r,i,o,u,a=N("beforesend","progress","load","error"),c=se(),s=new XMLHttpRequest,f=null,l=null,h=0;if("undefined"==typeof XDomainRequest||"withCredentials"in s||!/^(http(s)?:)?\/\//.test(t)||(s=new XDomainRequest),"onload"in s?s.onload=s.onerror=s.ontimeout=e:s.onreadystatechange=function(t){s.readyState>3&&e(t)},s.onprogress=function(t){a.call("progress",r,t)},r={header:function(t,n){return t=(t+"").toLowerCase(),arguments.length<2?c.get(t):(null==n?c.remove(t):c.set(t,n+""),r)},mimeType:function(t){return arguments.length?(i=null==t?null:t+"",r):i},responseType:function(t){return arguments.length?(u=t,r):u},timeout:function(t){return arguments.length?(h=+t,r):h},user:function(t){return arguments.length<1?f:(f=null==t?null:t+"",r)},password:function(t){return arguments.length<1?l:(l=null==t?null:t+"",r)},response:function(t){return o=t,r},get:function(t,n){return r.send("GET",t,n)},post:function(t,n){return r.send("POST",t,n)},send:function(n,e,o){return s.open(n,t,!0,f,l),null==i||c.has("accept")||c.set("accept",i+",*/*"),s.setRequestHeader&&c.each(function(t,n){s.setRequestHeader(n,t)}),null!=i&&s.overrideMimeType&&s.overrideMimeType(i),null!=u&&(s.responseType=u),h>0&&(s.timeout=h),null==o&&"function"==typeof e&&(o=e,e=null),null!=o&&1===o.length&&(o=function(t){return function(n,e){t(null==n?e:null)}}(o)),null!=o&&r.on("error",o).on("load",function(t){o(null,t)}),a.call("beforesend",r,s),s.send(null==e?null:e),r},abort:function(){return s.abort(),r},on:function(){var t=a.on.apply(a,arguments);return t===a?r:t}},null!=n){if("function"!=typeof n)throw new Error("invalid callback: "+n);return r.get(n)}return r}function eu(t,n){return function(e,r){var i=nu(e).mimeType(t).response(n);if(null!=r){if("function"!=typeof r)throw new Error("invalid callback: "+r);return i.get(r)}return i}}function ru(t,n){return function(e,r,i){arguments.length<3&&(i=r,r=null);var o=nu(e).mimeType(t);return o.row=function(t){return arguments.length?o.response(function(t,n){return function(e){return t(e.responseText,n)}}(n,r=t)):r},o.row(r),i?o.get(i):o}}function iu(t){function n(n){var o=n+"",u=e.get(o);if(!u){if(i!==yv)return i;e.set(o,u=r.push(n))}return t[(u-1)%t.length]}var e=se(),r=[],i=yv;return t=null==t?[]:_v.call(t),n.domain=function(t){if(!arguments.length)return r.slice();r=[],e=se();for(var i,o,u=-1,a=t.length;++u<a;)e.has(o=(i=t[u])+"")||e.set(o,r.push(i));return n},n.range=function(e){return arguments.length?(t=_v.call(e),n):t.slice()},n.unknown=function(t){return arguments.length?(i=t,n):i},n.copy=function(){return iu().domain(r).range(t).unknown(i)},n}function ou(){function t(){var t=i().length,r=u[1]<u[0],h=u[r-0],p=u[1-r];n=(p-h)/Math.max(1,t-c+2*s),a&&(n=Math.floor(n)),h+=(p-h-n*(t-c))*l,e=n*(1-c),a&&(h=Math.round(h),e=Math.round(e));var d=f(t).map(function(t){return h+n*t});return o(r?d.reverse():d)}var n,e,r=iu().unknown(void 0),i=r.domain,o=r.range,u=[0,1],a=!1,c=0,s=0,l=.5;return delete r.unknown,r.domain=function(n){return arguments.length?(i(n),t()):i()},r.range=function(n){return arguments.length?(u=[+n[0],+n[1]],t()):u.slice()},r.rangeRound=function(n){return u=[+n[0],+n[1]],a=!0,t()},r.bandwidth=function(){return e},r.step=function(){return n},r.round=function(n){return arguments.length?(a=!!n,t()):a},r.padding=function(n){return arguments.length?(c=s=Math.max(0,Math.min(1,n)),t()):c},r.paddingInner=function(n){return arguments.length?(c=Math.max(0,Math.min(1,n)),t()):c},r.paddingOuter=function(n){return arguments.length?(s=Math.max(0,Math.min(1,n)),t()):s},r.align=function(n){return arguments.length?(l=Math.max(0,Math.min(1,n)),t()):l},r.copy=function(){return ou().domain(i()).range(u).round(a).paddingInner(c).paddingOuter(s).align(l)},t()}function uu(t){var n=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return uu(n())},t}function au(t){return function(){return t}}function cu(t){return+t}function su(t,n){return(n-=t=+t)?function(e){return(e-t)/n}:au(n)}function fu(t,n,e,r){var i=t[0],o=t[1],u=n[0],a=n[1];return o<i?(i=e(o,i),u=r(a,u)):(i=e(i,o),u=r(u,a)),function(t){return u(i(t))}}function lu(t,n,e,r){var i=Math.min(t.length,n.length)-1,o=new Array(i),u=new Array(i),a=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),n=n.slice().reverse());++a<i;)o[a]=e(t[a],t[a+1]),u[a]=r(n[a],n[a+1]);return function(n){var e=Os(t,n,1,i)-1;return u[e](o[e](n))}}function hu(t,n){return n.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp())}function pu(t,n){function e(){return i=Math.min(a.length,c.length)>2?lu:fu,o=u=null,r}function r(n){return(o||(o=i(a,c,f?function(t){return function(n,e){var r=t(n=+n,e=+e);return function(t){return t<=n?0:t>=e?1:r(t)}}}(t):t,s)))(+n)}var i,o,u,a=mv,c=mv,s=fn,f=!1;return r.invert=function(t){return(u||(u=i(c,a,su,f?function(t){return function(n,e){var r=t(n=+n,e=+e);return function(t){return t<=0?n:t>=1?e:r(t)}}}(n):n)))(+t)},r.domain=function(t){return arguments.length?(a=gv.call(t,cu),e()):a.slice()},r.range=function(t){return arguments.length?(c=_v.call(t),e()):c.slice()},r.rangeRound=function(t){return c=_v.call(t),s=ln,e()},r.clamp=function(t){return arguments.length?(f=!!t,e()):f},r.interpolate=function(t){return arguments.length?(s=t,e()):s},e()}function du(n){var e=n.domain;return n.ticks=function(t){var n=e();return l(n[0],n[n.length-1],null==t?10:t)},n.tickFormat=function(n,r){return function(n,e,r){var i,o=n[0],u=n[n.length-1],a=p(o,u,null==e?10:e);switch((r=De(null==r?",f":r)).type){case"s":var c=Math.max(Math.abs(o),Math.abs(u));return null!=r.precision||isNaN(i=Be(a,c))||(r.precision=i),t.formatPrefix(r,c);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=He(a,Math.max(Math.abs(o),Math.abs(u))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=Ye(a))||(r.precision=i-2*("%"===r.type))}return t.format(r)}(e(),n,r)},n.nice=function(t){null==t&&(t=10);var r,i=e(),o=0,u=i.length-1,a=i[o],c=i[u];return c<a&&(r=a,a=c,c=r,r=o,o=u,u=r),(r=h(a,c,t))>0?r=h(a=Math.floor(a/r)*r,c=Math.ceil(c/r)*r,t):r<0&&(r=h(a=Math.ceil(a*r)/r,c=Math.floor(c*r)/r,t)),r>0?(i[o]=Math.floor(a/r)*r,i[u]=Math.ceil(c/r)*r,e(i)):r<0&&(i[o]=Math.ceil(a*r)/r,i[u]=Math.floor(c*r)/r,e(i)),n},n}function vu(){var t=pu(su,an);return t.copy=function(){return hu(t,vu())},du(t)}function gu(){function t(t){return+t}var n=[0,1];return t.invert=t,t.domain=t.range=function(e){return arguments.length?(n=gv.call(e,cu),t):n.slice()},t.copy=function(){return gu().domain(n)},du(t)}function _u(t,n){var e,r=0,i=(t=t.slice()).length-1,o=t[r],u=t[i];return u<o&&(e=r,r=i,i=e,e=o,o=u,u=e),t[r]=n.floor(o),t[i]=n.ceil(u),t}function yu(t,n){return(n=Math.log(n/t))?function(e){return Math.log(e/t)/n}:au(n)}function mu(t,n){return t<0?function(e){return-Math.pow(-n,e)*Math.pow(-t,1-e)}:function(e){return Math.pow(n,e)*Math.pow(t,1-e)}}function xu(t){return isFinite(t)?+("1e"+t):t<0?0:t}function bu(t){return 10===t?xu:t===Math.E?Math.exp:function(n){return Math.pow(t,n)}}function wu(t){return t===Math.E?Math.log:10===t&&Math.log10||2===t&&Math.log2||(t=Math.log(t),function(n){return Math.log(n)/t})}function Mu(t){return function(n){return-t(-n)}}function Tu(){function n(){return o=wu(i),u=bu(i),r()[0]<0&&(o=Mu(o),u=Mu(u)),e}var e=pu(yu,mu).domain([1,10]),r=e.domain,i=10,o=wu(10),u=bu(10);return e.base=function(t){return arguments.length?(i=+t,n()):i},e.domain=function(t){return arguments.length?(r(t),n()):r()},e.ticks=function(t){var n,e=r(),a=e[0],c=e[e.length-1];(n=c<a)&&(p=a,a=c,c=p);var s,f,h,p=o(a),d=o(c),v=null==t?10:+t,g=[];if(!(i%1)&&d-p<v){if(p=Math.round(p)-1,d=Math.round(d)+1,a>0){for(;p<d;++p)for(f=1,s=u(p);f<i;++f)if(!((h=s*f)<a)){if(h>c)break;g.push(h)}}else for(;p<d;++p)for(f=i-1,s=u(p);f>=1;--f)if(!((h=s*f)<a)){if(h>c)break;g.push(h)}}else g=l(p,d,Math.min(d-p,v)).map(u);return n?g.reverse():g},e.tickFormat=function(n,r){if(null==r&&(r=10===i?".0e":","),"function"!=typeof r&&(r=t.format(r)),n===1/0)return r;null==n&&(n=10);var a=Math.max(1,i*n/e.ticks().length);return function(t){var n=t/u(Math.round(o(t)));return n*i<i-.5&&(n*=i),n<=a?r(t):""}},e.nice=function(){return r(_u(r(),{floor:function(t){return u(Math.floor(o(t)))},ceil:function(t){return u(Math.ceil(o(t)))}}))},e.copy=function(){return hu(e,Tu().base(i))},e}function Nu(t,n){return t<0?-Math.pow(-t,n):Math.pow(t,n)}function ku(){var t=1,n=pu(function(n,e){return(e=Nu(e,t)-(n=Nu(n,t)))?function(r){return(Nu(r,t)-n)/e}:au(e)},function(n,e){return e=Nu(e,t)-(n=Nu(n,t)),function(r){return Nu(n+e*r,1/t)}}),e=n.domain;return n.exponent=function(n){return arguments.length?(t=+n,e(e())):t},n.copy=function(){return hu(n,ku().exponent(t))},du(n)}function Su(){function t(){var t=0,n=Math.max(1,i.length);for(o=new Array(n-1);++t<n;)o[t-1]=v(r,t/n);return e}function e(t){if(!isNaN(t=+t))return i[Os(o,t)]}var r=[],i=[],o=[];return e.invertExtent=function(t){var n=i.indexOf(t);return n<0?[NaN,NaN]:[n>0?o[n-1]:r[0],n<o.length?o[n]:r[r.length-1]]},e.domain=function(e){if(!arguments.length)return r.slice();r=[];for(var i,o=0,u=e.length;o<u;++o)null==(i=e[o])||isNaN(i=+i)||r.push(i);return r.sort(n),t()},e.range=function(n){return arguments.length?(i=_v.call(n),t()):i.slice()},e.quantiles=function(){return o.slice()},e.copy=function(){return Su().domain(r).range(i)},e}function Eu(){function t(t){if(t<=t)return u[Os(o,t,0,i)]}function n(){var n=-1;for(o=new Array(i);++n<i;)o[n]=((n+1)*r-(n-i)*e)/(i+1);return t}var e=0,r=1,i=1,o=[.5],u=[0,1];return t.domain=function(t){return arguments.length?(e=+t[0],r=+t[1],n()):[e,r]},t.range=function(t){return arguments.length?(i=(u=_v.call(t)).length-1,n()):u.slice()},t.invertExtent=function(t){var n=u.indexOf(t);return n<0?[NaN,NaN]:n<1?[e,o[0]]:n>=i?[o[i-1],r]:[o[n-1],o[n]]},t.copy=function(){return Eu().domain([e,r]).range(u)},du(t)}function Au(){function t(t){if(t<=t)return e[Os(n,t,0,r)]}var n=[.5],e=[0,1],r=1;return t.domain=function(i){return arguments.length?(n=_v.call(i),r=Math.min(n.length,e.length-1),t):n.slice()},t.range=function(i){return arguments.length?(e=_v.call(i),r=Math.min(n.length,e.length-1),t):e.slice()},t.invertExtent=function(t){var r=e.indexOf(t);return[n[r-1],n[r]]},t.copy=function(){return Au().domain(n).range(e)},t}function Cu(t,n,e,r){function i(n){return t(n=new Date(+n)),n}return i.floor=i,i.ceil=function(e){return t(e=new Date(e-1)),n(e,1),t(e),e},i.round=function(t){var n=i(t),e=i.ceil(t);return t-n<e-t?n:e},i.offset=function(t,e){return n(t=new Date(+t),null==e?1:Math.floor(e)),t},i.range=function(e,r,o){var u,a=[];if(e=i.ceil(e),o=null==o?1:Math.floor(o),!(e<r&&o>0))return a;do{a.push(u=new Date(+e)),n(e,o),t(e)}while(u<e&&e<r);return a},i.filter=function(e){return Cu(function(n){if(n>=n)for(;t(n),!e(n);)n.setTime(n-1)},function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;n(t,-1),!e(t););else for(;--r>=0;)for(;n(t,1),!e(t););})},e&&(i.count=function(n,r){return xv.setTime(+n),bv.setTime(+r),t(xv),t(bv),Math.floor(e(xv,bv))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(n){return r(n)%t==0}:function(n){return i.count(0,n)%t==0}):i:null}),i}function zu(t){return Cu(function(n){n.setDate(n.getDate()-(n.getDay()+7-t)%7),n.setHours(0,0,0,0)},function(t,n){t.setDate(t.getDate()+7*n)},function(t,n){return(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Tv)/Nv})}function Pu(t){return Cu(function(n){n.setUTCDate(n.getUTCDate()-(n.getUTCDay()+7-t)%7),n.setUTCHours(0,0,0,0)},function(t,n){t.setUTCDate(t.getUTCDate()+7*n)},function(t,n){return(n-t)/Nv})}function Ru(t){if(0<=t.y&&t.y<100){var n=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return n.setFullYear(t.y),n}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Lu(t){if(0<=t.y&&t.y<100){var n=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return n.setUTCFullYear(t.y),n}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function qu(t){return{y:t,m:0,d:1,H:0,M:0,S:0,L:0}}function Du(t){function n(t,n){return function(e){var r,i,o,u=[],a=-1,c=0,s=t.length;for(e instanceof Date||(e=new Date(+e));++a<s;)37===t.charCodeAt(a)&&(u.push(t.slice(c,a)),null!=(i=Mg[r=t.charAt(++a)])?r=t.charAt(++a):i="e"===r?" ":"0",(o=n[r])&&(r=o(e,i)),u.push(r),c=a+1);return u.push(t.slice(c,a)),u.join("")}}function e(t,n){return function(e){var i,o,u=qu(1900);if(r(u,t,e+="",0)!=e.length)return null;if("Q"in u)return new Date(u.Q);if("p"in u&&(u.H=u.H%12+12*u.p),"V"in u){if(u.V<1||u.V>53)return null;"w"in u||(u.w=1),"Z"in u?(i=(o=(i=Lu(qu(u.y))).getUTCDay())>4||0===o?og.ceil(i):og(i),i=eg.offset(i,7*(u.V-1)),u.y=i.getUTCFullYear(),u.m=i.getUTCMonth(),u.d=i.getUTCDate()+(u.w+6)%7):(i=(o=(i=n(qu(u.y))).getDay())>4||0===o?qv.ceil(i):qv(i),i=Pv.offset(i,7*(u.V-1)),u.y=i.getFullYear(),u.m=i.getMonth(),u.d=i.getDate()+(u.w+6)%7)}else("W"in u||"U"in u)&&("w"in u||(u.w="u"in u?u.u%7:"W"in u?1:0),o="Z"in u?Lu(qu(u.y)).getUTCDay():n(qu(u.y)).getDay(),u.m=0,u.d="W"in u?(u.w+6)%7+7*u.W-(o+5)%7:u.w+7*u.U-(o+6)%7);return"Z"in u?(u.H+=u.Z/100|0,u.M+=u.Z%100,Lu(u)):n(u)}}function r(t,n,e,r){for(var i,o,u=0,a=n.length,c=e.length;u<a;){if(r>=c)return-1;if(37===(i=n.charCodeAt(u++))){if(i=n.charAt(u++),!(o=T[i in Mg?n.charAt(u++):i])||(r=o(t,e,r))<0)return-1}else if(i!=e.charCodeAt(r++))return-1}return r}var i=t.dateTime,o=t.date,u=t.time,a=t.periods,c=t.days,s=t.shortDays,f=t.months,l=t.shortMonths,h=Fu(a),p=Iu(a),d=Fu(c),v=Iu(c),g=Fu(s),_=Iu(s),y=Fu(f),m=Iu(f),x=Fu(l),b=Iu(l),w={a:function(t){return s[t.getDay()]},A:function(t){return c[t.getDay()]},b:function(t){return l[t.getMonth()]},B:function(t){return f[t.getMonth()]},c:null,d:ua,e:ua,f:la,H:aa,I:ca,j:sa,L:fa,m:ha,M:pa,p:function(t){return a[+(t.getHours()>=12)]},Q:Ya,s:Ba,S:da,u:va,U:ga,V:_a,w:ya,W:ma,x:null,X:null,y:xa,Y:ba,Z:wa,"%":Ia},M={a:function(t){return s[t.getUTCDay()]},A:function(t){return c[t.getUTCDay()]},b:function(t){return l[t.getUTCMonth()]},B:function(t){return f[t.getUTCMonth()]},c:null,d:Ma,e:Ma,f:Ea,H:Ta,I:Na,j:ka,L:Sa,m:Aa,M:Ca,p:function(t){return a[+(t.getUTCHours()>=12)]},Q:Ya,s:Ba,S:za,u:Pa,U:Ra,V:La,w:qa,W:Da,x:null,X:null,y:Ua,Y:Oa,Z:Fa,"%":Ia},T={a:function(t,n,e){var r=g.exec(n.slice(e));return r?(t.w=_[r[0].toLowerCase()],e+r[0].length):-1},A:function(t,n,e){var r=d.exec(n.slice(e));return r?(t.w=v[r[0].toLowerCase()],e+r[0].length):-1},b:function(t,n,e){var r=x.exec(n.slice(e));return r?(t.m=b[r[0].toLowerCase()],e+r[0].length):-1},B:function(t,n,e){var r=y.exec(n.slice(e));return r?(t.m=m[r[0].toLowerCase()],e+r[0].length):-1},c:function(t,n,e){return r(t,i,n,e)},d:Gu,e:Gu,f:ea,H:Ju,I:Ju,j:Qu,L:na,m:Zu,M:Ku,p:function(t,n,e){var r=h.exec(n.slice(e));return r?(t.p=p[r[0].toLowerCase()],e+r[0].length):-1},Q:ia,s:oa,S:ta,u:Bu,U:Hu,V:ju,w:Yu,W:Xu,x:function(t,n,e){return r(t,o,n,e)},X:function(t,n,e){return r(t,u,n,e)},y:$u,Y:Vu,Z:Wu,"%":ra};return w.x=n(o,w),w.X=n(u,w),w.c=n(i,w),M.x=n(o,M),M.X=n(u,M),M.c=n(i,M),{format:function(t){var e=n(t+="",w);return e.toString=function(){return t},e},parse:function(t){var n=e(t+="",Ru);return n.toString=function(){return t},n},utcFormat:function(t){var e=n(t+="",M);return e.toString=function(){return t},e},utcParse:function(t){var n=e(t,Lu);return n.toString=function(){return t},n}}}function Uu(t,n,e){var r=t<0?"-":"",i=(r?-t:t)+"",o=i.length;return r+(o<e?new Array(e-o+1).join(n)+i:i)}function Ou(t){return t.replace(kg,"\\$&")}function Fu(t){return new RegExp("^(?:"+t.map(Ou).join("|")+")","i")}function Iu(t){for(var n={},e=-1,r=t.length;++e<r;)n[t[e].toLowerCase()]=e;return n}function Yu(t,n,e){var r=Tg.exec(n.slice(e,e+1));return r?(t.w=+r[0],e+r[0].length):-1}function Bu(t,n,e){var r=Tg.exec(n.slice(e,e+1));return r?(t.u=+r[0],e+r[0].length):-1}function Hu(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.U=+r[0],e+r[0].length):-1}function ju(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.V=+r[0],e+r[0].length):-1}function Xu(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.W=+r[0],e+r[0].length):-1}function Vu(t,n,e){var r=Tg.exec(n.slice(e,e+4));return r?(t.y=+r[0],e+r[0].length):-1}function $u(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),e+r[0].length):-1}function Wu(t,n,e){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(n.slice(e,e+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),e+r[0].length):-1}function Zu(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.m=r[0]-1,e+r[0].length):-1}function Gu(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.d=+r[0],e+r[0].length):-1}function Qu(t,n,e){var r=Tg.exec(n.slice(e,e+3));return r?(t.m=0,t.d=+r[0],e+r[0].length):-1}function Ju(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.H=+r[0],e+r[0].length):-1}function Ku(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.M=+r[0],e+r[0].length):-1}function ta(t,n,e){var r=Tg.exec(n.slice(e,e+2));return r?(t.S=+r[0],e+r[0].length):-1}function na(t,n,e){var r=Tg.exec(n.slice(e,e+3));return r?(t.L=+r[0],e+r[0].length):-1}function ea(t,n,e){var r=Tg.exec(n.slice(e,e+6));return r?(t.L=Math.floor(r[0]/1e3),e+r[0].length):-1}function ra(t,n,e){var r=Ng.exec(n.slice(e,e+1));return r?e+r[0].length:-1}function ia(t,n,e){var r=Tg.exec(n.slice(e));return r?(t.Q=+r[0],e+r[0].length):-1}function oa(t,n,e){var r=Tg.exec(n.slice(e));return r?(t.Q=1e3*+r[0],e+r[0].length):-1}function ua(t,n){return Uu(t.getDate(),n,2)}function aa(t,n){return Uu(t.getHours(),n,2)}function ca(t,n){return Uu(t.getHours()%12||12,n,2)}function sa(t,n){return Uu(1+Pv.count(Gv(t),t),n,3)}function fa(t,n){return Uu(t.getMilliseconds(),n,3)}function la(t,n){return fa(t,n)+"000"}function ha(t,n){return Uu(t.getMonth()+1,n,2)}function pa(t,n){return Uu(t.getMinutes(),n,2)}function da(t,n){return Uu(t.getSeconds(),n,2)}function va(t){var n=t.getDay();return 0===n?7:n}function ga(t,n){return Uu(Lv.count(Gv(t),t),n,2)}function _a(t,n){var e=t.getDay();return t=e>=4||0===e?Ov(t):Ov.ceil(t),Uu(Ov.count(Gv(t),t)+(4===Gv(t).getDay()),n,2)}function ya(t){return t.getDay()}function ma(t,n){return Uu(qv.count(Gv(t),t),n,2)}function xa(t,n){return Uu(t.getFullYear()%100,n,2)}function ba(t,n){return Uu(t.getFullYear()%1e4,n,4)}function wa(t){var n=t.getTimezoneOffset();return(n>0?"-":(n*=-1,"+"))+Uu(n/60|0,"0",2)+Uu(n%60,"0",2)}function Ma(t,n){return Uu(t.getUTCDate(),n,2)}function Ta(t,n){return Uu(t.getUTCHours(),n,2)}function Na(t,n){return Uu(t.getUTCHours()%12||12,n,2)}function ka(t,n){return Uu(1+eg.count(xg(t),t),n,3)}function Sa(t,n){return Uu(t.getUTCMilliseconds(),n,3)}function Ea(t,n){return Sa(t,n)+"000"}function Aa(t,n){return Uu(t.getUTCMonth()+1,n,2)}function Ca(t,n){return Uu(t.getUTCMinutes(),n,2)}function za(t,n){return Uu(t.getUTCSeconds(),n,2)}function Pa(t){var n=t.getUTCDay();return 0===n?7:n}function Ra(t,n){return Uu(ig.count(xg(t),t),n,2)}function La(t,n){var e=t.getUTCDay();return t=e>=4||0===e?cg(t):cg.ceil(t),Uu(cg.count(xg(t),t)+(4===xg(t).getUTCDay()),n,2)}function qa(t){return t.getUTCDay()}function Da(t,n){return Uu(og.count(xg(t),t),n,2)}function Ua(t,n){return Uu(t.getUTCFullYear()%100,n,2)}function Oa(t,n){return Uu(t.getUTCFullYear()%1e4,n,4)}function Fa(){return"+0000"}function Ia(){return"%"}function Ya(t){return+t}function Ba(t){return Math.floor(+t/1e3)}function Ha(n){return bg=Du(n),t.timeFormat=bg.format,t.timeParse=bg.parse,t.utcFormat=bg.utcFormat,t.utcParse=bg.utcParse,bg}function ja(t){return new Date(t)}function Xa(t){return t instanceof Date?+t:+new Date(+t)}function Va(t,n,r,i,o,u,a,c,s){function f(e){return(a(e)<e?g:u(e)<e?_:o(e)<e?y:i(e)<e?m:n(e)<e?r(e)<e?x:b:t(e)<e?w:M)(e)}function l(n,r,i,o){if(null==n&&(n=10),"number"==typeof n){var u=Math.abs(i-r)/n,a=e(function(t){return t[2]}).right(T,u);a===T.length?(o=p(r/Dg,i/Dg,n),n=t):a?(o=(a=T[u/T[a-1][2]<T[a][2]/u?a-1:a])[1],n=a[0]):(o=Math.max(p(r,i,n),1),n=c)}return null==o?n:n.every(o)}var h=pu(su,an),d=h.invert,v=h.domain,g=s(".%L"),_=s(":%S"),y=s("%I:%M"),m=s("%I %p"),x=s("%a %d"),b=s("%b %d"),w=s("%B"),M=s("%Y"),T=[[a,1,Cg],[a,5,5*Cg],[a,15,15*Cg],[a,30,30*Cg],[u,1,zg],[u,5,5*zg],[u,15,15*zg],[u,30,30*zg],[o,1,Pg],[o,3,3*Pg],[o,6,6*Pg],[o,12,12*Pg],[i,1,Rg],[i,2,2*Rg],[r,1,Lg],[n,1,qg],[n,3,3*qg],[t,1,Dg]];return h.invert=function(t){return new Date(d(t))},h.domain=function(t){return arguments.length?v(gv.call(t,Xa)):v().map(ja)},h.ticks=function(t,n){var e,r=v(),i=r[0],o=r[r.length-1],u=o<i;return u&&(e=i,i=o,o=e),e=l(t,i,o,n),e=e?e.range(i,o+1):[],u?e.reverse():e},h.tickFormat=function(t,n){return null==n?f:s(n)},h.nice=function(t,n){var e=v();return(t=l(t,e[0],e[e.length-1],n))?v(_u(e,t)):h},h.copy=function(){return hu(h,Va(t,n,r,i,o,u,a,c,s))},h}function $a(t){return t.match(/.{6}/g).map(function(t){return"#"+t})}function Wa(t){var n=t.length;return function(e){return t[Math.max(0,Math.min(n-1,Math.floor(e*n)))]}}function Za(t){function n(n){var o=(n-e)/(r-e);return t(i?Math.max(0,Math.min(1,o)):o)}var e=0,r=1,i=!1;return n.domain=function(t){return arguments.length?(e=+t[0],r=+t[1],n):[e,r]},n.clamp=function(t){return arguments.length?(i=!!t,n):i},n.interpolator=function(e){return arguments.length?(t=e,n):t},n.copy=function(){return Za(t).domain([e,r]).clamp(i)},du(n)}function Ga(t){return function(){return t}}function Qa(t){return t>=1?i_:t<=-1?-i_:Math.asin(t)}function Ja(t){return t.innerRadius}function Ka(t){return t.outerRadius}function tc(t){return t.startAngle}function nc(t){return t.endAngle}function ec(t){return t&&t.padAngle}function rc(t,n,e,r,i,o,u){var a=t-e,c=n-r,s=(u?o:-o)/n_(a*a+c*c),f=s*c,l=-s*a,h=t+f,p=n+l,d=e+f,v=r+l,g=(h+d)/2,_=(p+v)/2,y=d-h,m=v-p,x=y*y+m*m,b=i-o,w=h*v-d*p,M=(m<0?-1:1)*n_(Jg(0,b*b*x-w*w)),T=(w*m-y*M)/x,N=(-w*y-m*M)/x,k=(w*m+y*M)/x,S=(-w*y+m*M)/x,E=T-g,A=N-_,C=k-g,z=S-_;return E*E+A*A>C*C+z*z&&(T=k,N=S),{cx:T,cy:N,x01:-f,y01:-l,x11:T*(i/b-1),y11:N*(i/b-1)}}function ic(t){this._context=t}function oc(t){return new ic(t)}function uc(t){return t[0]}function ac(t){return t[1]}function cc(){function t(t){var a,c,s,f=t.length,l=!1;for(null==i&&(u=o(s=ee())),a=0;a<=f;++a)!(a<f&&r(c=t[a],a,t))===l&&((l=!l)?u.lineStart():u.lineEnd()),l&&u.point(+n(c,a,t),+e(c,a,t));if(s)return u=null,s+""||null}var n=uc,e=ac,r=Ga(!0),i=null,o=oc,u=null;return t.x=function(e){return arguments.length?(n="function"==typeof e?e:Ga(+e),t):n},t.y=function(n){return arguments.length?(e="function"==typeof n?n:Ga(+n),t):e},t.defined=function(n){return arguments.length?(r="function"==typeof n?n:Ga(!!n),t):r},t.curve=function(n){return arguments.length?(o=n,null!=i&&(u=o(i)),t):o},t.context=function(n){return arguments.length?(null==n?i=u=null:u=o(i=n),t):i},t}function sc(){function t(t){var n,f,l,h,p,d=t.length,v=!1,g=new Array(d),_=new Array(d);for(null==a&&(s=c(p=ee())),n=0;n<=d;++n){if(!(n<d&&u(h=t[n],n,t))===v)if(v=!v)f=n,s.areaStart(),s.lineStart();else{for(s.lineEnd(),s.lineStart(),l=n-1;l>=f;--l)s.point(g[l],_[l]);s.lineEnd(),s.areaEnd()}v&&(g[n]=+e(h,n,t),_[n]=+i(h,n,t),s.point(r?+r(h,n,t):g[n],o?+o(h,n,t):_[n]))}if(p)return s=null,p+""||null}function n(){return cc().defined(u).curve(c).context(a)}var e=uc,r=null,i=Ga(0),o=ac,u=Ga(!0),a=null,c=oc,s=null;return t.x=function(n){return arguments.length?(e="function"==typeof n?n:Ga(+n),r=null,t):e},t.x0=function(n){return arguments.length?(e="function"==typeof n?n:Ga(+n),t):e},t.x1=function(n){return arguments.length?(r=null==n?null:"function"==typeof n?n:Ga(+n),t):r},t.y=function(n){return arguments.length?(i="function"==typeof n?n:Ga(+n),o=null,t):i},t.y0=function(n){return arguments.length?(i="function"==typeof n?n:Ga(+n),t):i},t.y1=function(n){return arguments.length?(o=null==n?null:"function"==typeof n?n:Ga(+n),t):o},t.lineX0=t.lineY0=function(){return n().x(e).y(i)},t.lineY1=function(){return n().x(e).y(o)},t.lineX1=function(){return n().x(r).y(i)},t.defined=function(n){return arguments.length?(u="function"==typeof n?n:Ga(!!n),t):u},t.curve=function(n){return arguments.length?(c=n,null!=a&&(s=c(a)),t):c},t.context=function(n){return arguments.length?(null==n?a=s=null:s=c(a=n),t):a},t}function fc(t,n){return n<t?-1:n>t?1:n>=t?0:NaN}function lc(t){return t}function hc(t){this._curve=t}function pc(t){function n(n){return new hc(t(n))}return n._curve=t,n}function dc(t){var n=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?n(pc(t)):n()._curve},t}function vc(){return dc(cc().curve(u_))}function gc(){var t=sc().curve(u_),n=t.curve,e=t.lineX0,r=t.lineX1,i=t.lineY0,o=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return dc(e())},delete t.lineX0,t.lineEndAngle=function(){return dc(r())},delete t.lineX1,t.lineInnerRadius=function(){return dc(i())},delete t.lineY0,t.lineOuterRadius=function(){return dc(o())},delete t.lineY1,t.curve=function(t){return arguments.length?n(pc(t)):n()._curve},t}function _c(t,n){return[(n=+n)*Math.cos(t-=Math.PI/2),n*Math.sin(t)]}function yc(t){return t.source}function mc(t){return t.target}function xc(t){function n(){var n,a=a_.call(arguments),c=e.apply(this,a),s=r.apply(this,a);if(u||(u=n=ee()),t(u,+i.apply(this,(a[0]=c,a)),+o.apply(this,a),+i.apply(this,(a[0]=s,a)),+o.apply(this,a)),n)return u=null,n+""||null}var e=yc,r=mc,i=uc,o=ac,u=null;return n.source=function(t){return arguments.length?(e=t,n):e},n.target=function(t){return arguments.length?(r=t,n):r},n.x=function(t){return arguments.length?(i="function"==typeof t?t:Ga(+t),n):i},n.y=function(t){return arguments.length?(o="function"==typeof t?t:Ga(+t),n):o},n.context=function(t){return arguments.length?(u=null==t?null:t,n):u},n}function bc(t,n,e,r,i){t.moveTo(n,e),t.bezierCurveTo(n=(n+r)/2,e,n,i,r,i)}function wc(t,n,e,r,i){t.moveTo(n,e),t.bezierCurveTo(n,e=(e+i)/2,r,e,r,i)}function Mc(t,n,e,r,i){var o=_c(n,e),u=_c(n,e=(e+i)/2),a=_c(r,e),c=_c(r,i);t.moveTo(o[0],o[1]),t.bezierCurveTo(u[0],u[1],a[0],a[1],c[0],c[1])}function Tc(){}function Nc(t,n,e){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+n)/6,(t._y0+4*t._y1+e)/6)}function kc(t){this._context=t}function Sc(t){this._context=t}function Ec(t){this._context=t}function Ac(t,n){this._basis=new kc(t),this._beta=n}function Cc(t,n,e){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-n),t._y2+t._k*(t._y1-e),t._x2,t._y2)}function zc(t,n){this._context=t,this._k=(1-n)/6}function Pc(t,n){this._context=t,this._k=(1-n)/6}function Rc(t,n){this._context=t,this._k=(1-n)/6}function Lc(t,n,e){var r=t._x1,i=t._y1,o=t._x2,u=t._y2;if(t._l01_a>e_){var a=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,c=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*a-t._x0*t._l12_2a+t._x2*t._l01_2a)/c,i=(i*a-t._y0*t._l12_2a+t._y2*t._l01_2a)/c}if(t._l23_a>e_){var s=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,f=3*t._l23_a*(t._l23_a+t._l12_a);o=(o*s+t._x1*t._l23_2a-n*t._l12_2a)/f,u=(u*s+t._y1*t._l23_2a-e*t._l12_2a)/f}t._context.bezierCurveTo(r,i,o,u,t._x2,t._y2)}function qc(t,n){this._context=t,this._alpha=n}function Dc(t,n){this._context=t,this._alpha=n}function Uc(t,n){this._context=t,this._alpha=n}function Oc(t){this._context=t}function Fc(t){return t<0?-1:1}function Ic(t,n,e){var r=t._x1-t._x0,i=n-t._x1,o=(t._y1-t._y0)/(r||i<0&&-0),u=(e-t._y1)/(i||r<0&&-0),a=(o*i+u*r)/(r+i);return(Fc(o)+Fc(u))*Math.min(Math.abs(o),Math.abs(u),.5*Math.abs(a))||0}function Yc(t,n){var e=t._x1-t._x0;return e?(3*(t._y1-t._y0)/e-n)/2:n}function Bc(t,n,e){var r=t._x0,i=t._y0,o=t._x1,u=t._y1,a=(o-r)/3;t._context.bezierCurveTo(r+a,i+a*n,o-a,u-a*e,o,u)}function Hc(t){this._context=t}function jc(t){this._context=new Xc(t)}function Xc(t){this._context=t}function Vc(t){this._context=t}function $c(t){var n,e,r=t.length-1,i=new Array(r),o=new Array(r),u=new Array(r);for(i[0]=0,o[0]=2,u[0]=t[0]+2*t[1],n=1;n<r-1;++n)i[n]=1,o[n]=4,u[n]=4*t[n]+2*t[n+1];for(i[r-1]=2,o[r-1]=7,u[r-1]=8*t[r-1]+t[r],n=1;n<r;++n)e=i[n]/o[n-1],o[n]-=e,u[n]-=e*u[n-1];for(i[r-1]=u[r-1]/o[r-1],n=r-2;n>=0;--n)i[n]=(u[n]-i[n+1])/o[n];for(o[r-1]=(t[r]+i[r-1])/2,n=0;n<r-1;++n)o[n]=2*t[n+1]-i[n+1];return[i,o]}function Wc(t,n){this._context=t,this._t=n}function Zc(t,n){if((i=t.length)>1)for(var e,r,i,o=1,u=t[n[0]],a=u.length;o<i;++o)for(r=u,u=t[n[o]],e=0;e<a;++e)u[e][1]+=u[e][0]=isNaN(r[e][1])?r[e][0]:r[e][1]}function Gc(t){for(var n=t.length,e=new Array(n);--n>=0;)e[n]=n;return e}function Qc(t,n){return t[n]}function Jc(t){var n=t.map(Kc);return Gc(t).sort(function(t,e){return n[t]-n[e]})}function Kc(t){for(var n,e=0,r=-1,i=t.length;++r<i;)(n=+t[r][1])&&(e+=n);return e}function ts(t){return function(){return t}}function ns(t){return t[0]}function es(t){return t[1]}function rs(){this._=null}function is(t){t.U=t.C=t.L=t.R=t.P=t.N=null}function os(t,n){var e=n,r=n.R,i=e.U;i?i.L===e?i.L=r:i.R=r:t._=r,r.U=i,e.U=r,e.R=r.L,e.R&&(e.R.U=e),r.L=e}function us(t,n){var e=n,r=n.L,i=e.U;i?i.L===e?i.L=r:i.R=r:t._=r,r.U=i,e.U=r,e.L=r.R,e.L&&(e.L.U=e),r.R=e}function as(t){for(;t.L;)t=t.L;return t}function cs(t,n,e,r){var i=[null,null],o=D_.push(i)-1;return i.left=t,i.right=n,e&&fs(i,t,n,e),r&&fs(i,n,t,r),L_[t.index].halfedges.push(o),L_[n.index].halfedges.push(o),i}function ss(t,n,e){var r=[n,e];return r.left=t,r}function fs(t,n,e,r){t[0]||t[1]?t.left===e?t[1]=r:t[0]=r:(t[0]=r,t.left=n,t.right=e)}function ls(t,n,e,r,i){var o,u=t[0],a=t[1],c=u[0],s=u[1],f=0,l=1,h=a[0]-c,p=a[1]-s;if(o=n-c,h||!(o>0)){if(o/=h,h<0){if(o<f)return;o<l&&(l=o)}else if(h>0){if(o>l)return;o>f&&(f=o)}if(o=r-c,h||!(o<0)){if(o/=h,h<0){if(o>l)return;o>f&&(f=o)}else if(h>0){if(o<f)return;o<l&&(l=o)}if(o=e-s,p||!(o>0)){if(o/=p,p<0){if(o<f)return;o<l&&(l=o)}else if(p>0){if(o>l)return;o>f&&(f=o)}if(o=i-s,p||!(o<0)){if(o/=p,p<0){if(o>l)return;o>f&&(f=o)}else if(p>0){if(o<f)return;o<l&&(l=o)}return!(f>0||l<1)||(f>0&&(t[0]=[c+f*h,s+f*p]),l<1&&(t[1]=[c+l*h,s+l*p]),!0)}}}}}function hs(t,n,e,r,i){var o=t[1];if(o)return!0;var u,a,c=t[0],s=t.left,f=t.right,l=s[0],h=s[1],p=f[0],d=f[1],v=(l+p)/2,g=(h+d)/2;if(d===h){if(v<n||v>=r)return;if(l>p){if(c){if(c[1]>=i)return}else c=[v,e];o=[v,i]}else{if(c){if(c[1]<e)return}else c=[v,i];o=[v,e]}}else if(u=(l-p)/(d-h),a=g-u*v,u<-1||u>1)if(l>p){if(c){if(c[1]>=i)return}else c=[(e-a)/u,e];o=[(i-a)/u,i]}else{if(c){if(c[1]<e)return}else c=[(i-a)/u,i];o=[(e-a)/u,e]}else if(h<d){if(c){if(c[0]>=r)return}else c=[n,u*n+a];o=[r,u*r+a]}else{if(c){if(c[0]<n)return}else c=[r,u*r+a];o=[n,u*n+a]}return t[0]=c,t[1]=o,!0}function ps(t,n){var e=t.site,r=n.left,i=n.right;return e===i&&(i=r,r=e),i?Math.atan2(i[1]-r[1],i[0]-r[0]):(e===r?(r=n[1],i=n[0]):(r=n[0],i=n[1]),Math.atan2(r[0]-i[0],i[1]-r[1]))}function ds(t,n){return n[+(n.left!==t.site)]}function vs(t,n){return n[+(n.left===t.site)]}function gs(t){var n=t.P,e=t.N;if(n&&e){var r=n.site,i=t.site,o=e.site;if(r!==o){var u=i[0],a=i[1],c=r[0]-u,s=r[1]-a,f=o[0]-u,l=o[1]-a,h=2*(c*l-s*f);if(!(h>=-I_)){var p=c*c+s*s,d=f*f+l*l,v=(l*p-s*d)/h,g=(c*d-f*p)/h,_=U_.pop()||new function(){is(this),this.x=this.y=this.arc=this.site=this.cy=null};_.arc=t,_.site=i,_.x=v+u,_.y=(_.cy=g+a)+Math.sqrt(v*v+g*g),t.circle=_;for(var y=null,m=q_._;m;)if(_.y<m.y||_.y===m.y&&_.x<=m.x){if(!m.L){y=m.P;break}m=m.L}else{if(!m.R){y=m;break}m=m.R}q_.insert(y,_),y||(P_=_)}}}}function _s(t){var n=t.circle;n&&(n.P||(P_=n.N),q_.remove(n),U_.push(n),is(n),t.circle=null)}function ys(t){var n=O_.pop()||new function(){is(this),this.edge=this.site=this.circle=null};return n.site=t,n}function ms(t){_s(t),R_.remove(t),O_.push(t),is(t)}function xs(t){var n=t.circle,e=n.x,r=n.cy,i=[e,r],o=t.P,u=t.N,a=[t];ms(t);for(var c=o;c.circle&&Math.abs(e-c.circle.x)<F_&&Math.abs(r-c.circle.cy)<F_;)o=c.P,a.unshift(c),ms(c),c=o;a.unshift(c),_s(c);for(var s=u;s.circle&&Math.abs(e-s.circle.x)<F_&&Math.abs(r-s.circle.cy)<F_;)u=s.N,a.push(s),ms(s),s=u;a.push(s),_s(s);var f,l=a.length;for(f=1;f<l;++f)s=a[f],c=a[f-1],fs(s.edge,c.site,s.site,i);c=a[0],(s=a[l-1]).edge=cs(c.site,s.site,null,i),gs(c),gs(s)}function bs(t){for(var n,e,r,i,o=t[0],u=t[1],a=R_._;a;)if((r=ws(a,u)-o)>F_)a=a.L;else{if(!((i=o-function(t,n){var e=t.N;if(e)return ws(e,n);var r=t.site;return r[1]===n?r[0]:1/0}(a,u))>F_)){r>-F_?(n=a.P,e=a):i>-F_?(n=a,e=a.N):n=e=a;break}if(!a.R){n=a;break}a=a.R}(function(t){L_[t.index]={site:t,halfedges:[]}})(t);var c=ys(t);if(R_.insert(n,c),n||e){if(n===e)return _s(n),e=ys(n.site),R_.insert(c,e),c.edge=e.edge=cs(n.site,c.site),gs(n),void gs(e);if(e){_s(n),_s(e);var s=n.site,f=s[0],l=s[1],h=t[0]-f,p=t[1]-l,d=e.site,v=d[0]-f,g=d[1]-l,_=2*(h*g-p*v),y=h*h+p*p,m=v*v+g*g,x=[(g*y-p*m)/_+f,(h*m-v*y)/_+l];fs(e.edge,s,d,x),c.edge=cs(s,t,null,x),e.edge=cs(t,d,null,x),gs(n),gs(e)}else c.edge=cs(n.site,c.site)}}function ws(t,n){var e=t.site,r=e[0],i=e[1],o=i-n;if(!o)return r;var u=t.P;if(!u)return-1/0;var a=(e=u.site)[0],c=e[1],s=c-n;if(!s)return a;var f=a-r,l=1/o-1/s,h=f/s;return l?(-h+Math.sqrt(h*h-2*l*(f*f/(-2*s)-c+s/2+i-o/2)))/l+r:(r+a)/2}function Ms(t,n,e){return(t[0]-e[0])*(n[1]-t[1])-(t[0]-n[0])*(e[1]-t[1])}function Ts(t,n){return n[1]-t[1]||n[0]-t[0]}function Ns(t,n){var e,r,i,o=t.sort(Ts).pop();for(D_=[],L_=new Array(t.length),R_=new rs,q_=new rs;;)if(i=P_,o&&(!i||o[1]<i.y||o[1]===i.y&&o[0]<i.x))o[0]===e&&o[1]===r||(bs(o),e=o[0],r=o[1]),o=t.pop();else{if(!i)break;xs(i.arc)}if(function(){for(var t,n,e,r,i=0,o=L_.length;i<o;++i)if((t=L_[i])&&(r=(n=t.halfedges).length)){var u=new Array(r),a=new Array(r);for(e=0;e<r;++e)u[e]=e,a[e]=ps(t,D_[n[e]]);for(u.sort(function(t,n){return a[n]-a[t]}),e=0;e<r;++e)a[e]=n[u[e]];for(e=0;e<r;++e)n[e]=a[e]}}(),n){var u=+n[0][0],a=+n[0][1],c=+n[1][0],s=+n[1][1];(function(t,n,e,r){for(var i,o=D_.length;o--;)hs(i=D_[o],t,n,e,r)&&ls(i,t,n,e,r)&&(Math.abs(i[0][0]-i[1][0])>F_||Math.abs(i[0][1]-i[1][1])>F_)||delete D_[o]})(u,a,c,s),function(t,n,e,r){var i,o,u,a,c,s,f,l,h,p,d,v,g=L_.length,_=!0;for(i=0;i<g;++i)if(o=L_[i]){for(u=o.site,a=(c=o.halfedges).length;a--;)D_[c[a]]||c.splice(a,1);for(a=0,s=c.length;a<s;)d=(p=vs(o,D_[c[a]]))[0],v=p[1],l=(f=ds(o,D_[c[++a%s]]))[0],h=f[1],(Math.abs(d-l)>F_||Math.abs(v-h)>F_)&&(c.splice(a,0,D_.push(ss(u,p,Math.abs(d-t)<F_&&r-v>F_?[t,Math.abs(l-t)<F_?h:r]:Math.abs(v-r)<F_&&e-d>F_?[Math.abs(h-r)<F_?l:e,r]:Math.abs(d-e)<F_&&v-n>F_?[e,Math.abs(l-e)<F_?h:n]:Math.abs(v-n)<F_&&d-t>F_?[Math.abs(h-n)<F_?l:t,n]:null))-1),++s);s&&(_=!1)}if(_){var y,m,x,b=1/0;for(i=0,_=null;i<g;++i)(o=L_[i])&&(x=(y=(u=o.site)[0]-t)*y+(m=u[1]-n)*m)<b&&(b=x,_=o);if(_){var w=[t,n],M=[t,r],T=[e,r],N=[e,n];_.halfedges.push(D_.push(ss(u=_.site,w,M))-1,D_.push(ss(u,M,T))-1,D_.push(ss(u,T,N))-1,D_.push(ss(u,N,w))-1)}}for(i=0;i<g;++i)(o=L_[i])&&(o.halfedges.length||delete L_[i])}(u,a,c,s)}this.edges=D_,this.cells=L_,R_=q_=D_=L_=null}function ks(t){return function(){return t}}function Ss(t,n,e){this.k=t,this.x=n,this.y=e}function Es(t){return t.__zoom||Y_}function As(){t.event.stopImmediatePropagation()}function Cs(){t.event.preventDefault(),t.event.stopImmediatePropagation()}function zs(){return!t.event.button}function Ps(){var t,n,e=this;return e instanceof SVGElement?(t=(e=e.ownerSVGElement||e).width.baseVal.value,n=e.height.baseVal.value):(t=e.clientWidth,n=e.clientHeight),[[0,0],[t,n]]}function Rs(){return this.__zoom||Y_}function Ls(){return-t.event.deltaY*(t.event.deltaMode?120:1)/500}function qs(){return"ontouchstart"in this}function Ds(t,n,e){var r=t.invertX(n[0][0])-e[0][0],i=t.invertX(n[1][0])-e[1][0],o=t.invertY(n[0][1])-e[0][1],u=t.invertY(n[1][1])-e[1][1];return t.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),u>o?(o+u)/2:Math.min(0,o)||Math.max(0,u))}var Us=e(n),Os=Us.right,Fs=Us.left,Is=Array.prototype,Ys=Is.slice,Bs=Is.map,Hs=Math.sqrt(50),js=Math.sqrt(10),Xs=Math.sqrt(2),Vs=Array.prototype.slice,$s=1,Ws=2,Zs=3,Gs=4,Qs=1e-6,Js={value:function(){}};k.prototype=N.prototype={constructor:k,on:function(t,n){var e,r=this._,i=function(t,n){return t.trim().split(/^|\s+/).map(function(t){var e="",r=t.indexOf(".");if(r>=0&&(e=t.slice(r+1),t=t.slice(0,r)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})}(t+"",r),o=-1,u=i.length;{if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++o<u;)if(e=(t=i[o]).type)r[e]=S(r[e],t.name,n);else if(null==n)for(e in r)r[e]=S(r[e],t.name,null);return this}for(;++o<u;)if((e=(t=i[o]).type)&&(e=function(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}(r[e],t.name)))return e}},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new k(t)},call:function(t,n){if((e=arguments.length-2)>0)for(var e,r,i=new Array(e),o=0;o<e;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,e=(r=this._[t]).length;o<e;++o)r[o].value.apply(n,i)},apply:function(t,n,e){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(n,e)}};var Ks="http://www.w3.org/1999/xhtml",tf={svg:"http://www.w3.org/2000/svg",xhtml:Ks,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},nf=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var ef=document.documentElement;if(!ef.matches){var rf=ef.webkitMatchesSelector||ef.msMatchesSelector||ef.mozMatchesSelector||ef.oMatchesSelector;nf=function(t){return function(){return rf.call(this,t)}}}}var of=nf;q.prototype={constructor:q,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,n){return this._parent.insertBefore(t,n)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var uf="$";H.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var n=this._names.indexOf(t);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var af={};if(t.event=null,"undefined"!=typeof document){"onmouseenter"in document.documentElement||(af={mouseenter:"mouseover",mouseleave:"mouseout"})}var cf=[null];ut.prototype=at.prototype={constructor:ut,select:function(t){"function"!=typeof t&&(t=z(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,u,a=n[i],c=a.length,s=r[i]=new Array(c),f=0;f<c;++f)(o=a[f])&&(u=t.call(o,o.__data__,f,a))&&("__data__"in o&&(u.__data__=o.__data__),s[f]=u);return new ut(r,this._parents)},selectAll:function(t){"function"!=typeof t&&(t=R(t));for(var n=this._groups,e=n.length,r=[],i=[],o=0;o<e;++o)for(var u,a=n[o],c=a.length,s=0;s<c;++s)(u=a[s])&&(r.push(t.call(u,u.__data__,s,a)),i.push(u));return new ut(r,i)},filter:function(t){"function"!=typeof t&&(t=of(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,u=n[i],a=u.length,c=r[i]=[],s=0;s<a;++s)(o=u[s])&&t.call(o,o.__data__,s,u)&&c.push(o);return new ut(r,this._parents)},data:function(t,n){if(!t)return p=new Array(this.size()),s=-1,this.each(function(t){p[++s]=t}),p;var e=n?U:D,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var o=i.length,u=new Array(o),a=new Array(o),c=new Array(o),s=0;s<o;++s){var f=r[s],l=i[s],h=l.length,p=t.call(f,f&&f.__data__,s,r),d=p.length,v=a[s]=new Array(d),g=u[s]=new Array(d);e(f,l,v,g,c[s]=new Array(h),p,n);for(var _,y,m=0,x=0;m<d;++m)if(_=v[m]){for(m>=x&&(x=m+1);!(y=g[x])&&++x<d;);_._next=y||null}}return u=new ut(u,r),u._enter=a,u._exit=c,u},enter:function(){return new ut(this._enter||this._groups.map(L),this._parents)},exit:function(){return new ut(this._exit||this._groups.map(L),this._parents)},merge:function(t){for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),u=new Array(r),a=0;a<o;++a)for(var c,s=n[a],f=e[a],l=s.length,h=u[a]=new Array(l),p=0;p<l;++p)(c=s[p]||f[p])&&(h[p]=c);for(;a<r;++a)u[a]=n[a];return new ut(u,this._parents)},order:function(){for(var t=this._groups,n=-1,e=t.length;++n<e;)for(var r,i=t[n],o=i.length-1,u=i[o];--o>=0;)(r=i[o])&&(u&&u!==r.nextSibling&&u.parentNode.insertBefore(r,u),u=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=O);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o<r;++o){for(var u,a=e[o],c=a.length,s=i[o]=new Array(c),f=0;f<c;++f)(u=a[f])&&(s[f]=u);s.sort(n)}return new ut(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){var t=new Array(this.size()),n=-1;return this.each(function(){t[++n]=this}),t},node:function(){for(var t=this._groups,n=0,e=t.length;n<e;++n)for(var r=t[n],i=0,o=r.length;i<o;++i){var u=r[i];if(u)return u}return null},size:function(){var t=0;return this.each(function(){++t}),t},empty:function(){return!this.node()},each:function(t){for(var n=this._groups,e=0,r=n.length;e<r;++e)for(var i,o=n[e],u=0,a=o.length;u<a;++u)(i=o[u])&&t.call(i,i.__data__,u,o);return this},attr:function(t,n){var e=E(t);if(arguments.length<2){var r=this.node();return e.local?r.getAttributeNS(e.space,e.local):r.getAttribute(e)}return this.each((null==n?e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}}:"function"==typeof n?e.local?function(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}:function(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}:e.local?function(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}:function(t,n){return function(){this.setAttribute(t,n)}})(e,n))},style:function(t,n,e){return arguments.length>1?this.each((null==n?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof n?function(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}:function(t,n,e){return function(){this.style.setProperty(t,n,e)}})(t,n,null==e?"":e)):I(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?function(t){return function(){delete this[t]}}:"function"==typeof n?function(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}:function(t,n){return function(){this[t]=n}})(t,n)):this.node()[t]},classed:function(t,n){var e=Y(t+"");if(arguments.length<2){for(var r=B(this.node()),i=-1,o=e.length;++i<o;)if(!r.contains(e[i]))return!1;return!0}return this.each(("function"==typeof n?function(t,n){return function(){(n.apply(this,arguments)?j:X)(this,t)}}:n?function(t){return function(){j(this,t)}}:function(t){return function(){X(this,t)}})(e,n))},text:function(t){return arguments.length?this.each(null==t?V:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}:function(t){return function(){this.textContent=t}})(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?$:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}:function(t){return function(){this.innerHTML=t}})(t)):this.node().innerHTML},raise:function(){return this.each(W)},lower:function(){return this.each(Z)},append:function(t){var n="function"==typeof t?t:A(t);return this.select(function(){return this.appendChild(n.apply(this,arguments))})},insert:function(t,n){var e="function"==typeof t?t:A(t),r=null==n?G:"function"==typeof n?n:z(n);return this.select(function(){return this.insertBefore(e.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(Q)},clone:function(t){return this.select(t?K:J)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,n,e){var r,i,o=function(t){return t.trim().split(/^|\s+/).map(function(t){var n="",e=t.indexOf(".");return e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}})}(t+""),u=o.length;if(!(arguments.length<2)){for(a=n?rt:et,null==e&&(e=!1),r=0;r<u;++r)this.each(a(o[r],n,e));return this}var a=this.node().__on;if(a)for(var c,s=0,f=a.length;s<f;++s)for(r=0,c=a[s];r<u;++r)if((i=o[r]).type===c.type&&i.name===c.name)return c.value},dispatch:function(t,n){return this.each(("function"==typeof n?function(t,n){return function(){return ot(this,t,n.apply(this,arguments))}}:function(t,n){return function(){return ot(this,t,n)}})(t,n))}};var sf=0;ft.prototype=st.prototype={constructor:ft,get:function(t){for(var n=this._;!(n in t);)if(!(t=t.parentNode))return;return t[n]},set:function(t,n){return t[this._]=n},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}},xt.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};var ff="\\s*([+-]?\\d+)\\s*",lf="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",hf="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",pf=/^#([0-9a-f]{3})$/,df=/^#([0-9a-f]{6})$/,vf=new RegExp("^rgb\\("+[ff,ff,ff]+"\\)$"),gf=new RegExp("^rgb\\("+[hf,hf,hf]+"\\)$"),_f=new RegExp("^rgba\\("+[ff,ff,ff,lf]+"\\)$"),yf=new RegExp("^rgba\\("+[hf,hf,hf,lf]+"\\)$"),mf=new RegExp("^hsl\\("+[lf,hf,hf]+"\\)$"),xf=new RegExp("^hsla\\("+[lf,hf,hf,lf]+"\\)$"),bf={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Nt(St,Et,{displayable:function(){return this.rgb().displayable()},toString:function(){return this.rgb()+""}}),Nt(Rt,Pt,kt(St,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Rt(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Rt(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255&&0<=this.opacity&&this.opacity<=1},toString:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}})),Nt(Dt,qt,kt(St,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Dt(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Dt(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new Rt(Ut(t>=240?t-240:t+120,i,r),Ut(t,i,r),Ut(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1}}));var wf=Math.PI/180,Mf=180/Math.PI,Tf=.95047,Nf=1,kf=1.08883,Sf=4/29,Ef=6/29,Af=3*Ef*Ef,Cf=Ef*Ef*Ef;Nt(It,Ft,kt(St,{brighter:function(t){return new It(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker:function(t){return new It(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,n=isNaN(this.a)?t:t+this.a/500,e=isNaN(this.b)?t:t-this.b/200;return t=Nf*Bt(t),n=Tf*Bt(n),e=kf*Bt(e),new Rt(Ht(3.2404542*n-1.5371385*t-.4985314*e),Ht(-.969266*n+1.8760108*t+.041556*e),Ht(.0556434*n-.2040259*t+1.0572252*e),this.opacity)}})),Nt(Vt,Xt,kt(St,{brighter:function(t){return new Vt(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker:function(t){return new Vt(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb:function(){return Ot(this).rgb()}}));var zf=-.29227,Pf=-.90649,Rf=1.97294,Lf=Rf*Pf,qf=1.78277*Rf,Df=1.78277*zf- -.14861*Pf;Nt(Wt,$t,kt(St,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Wt(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Wt(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*wf,n=+this.l,e=isNaN(this.s)?0:this.s*n*(1-n),r=Math.cos(t),i=Math.sin(t);return new Rt(255*(n+e*(-.14861*r+1.78277*i)),255*(n+e*(zf*r+Pf*i)),255*(n+e*(Rf*r)),this.opacity)}}));var Uf,Of,Ff,If,Yf,Bf,Hf=function t(n){function e(t,n){var e=r((t=Pt(t)).r,(n=Pt(n)).r),i=r(t.g,n.g),o=r(t.b,n.b),u=en(t.opacity,n.opacity);return function(n){return t.r=e(n),t.g=i(n),t.b=o(n),t.opacity=u(n),t+""}}var r=nn(n);return e.gamma=t,e}(1),jf=rn(Gt),Xf=rn(Qt),Vf=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,$f=new RegExp(Vf.source,"g"),Wf=180/Math.PI,Zf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1},Gf=pn(function(t){return"none"===t?Zf:(Uf||(Uf=document.createElement("DIV"),Of=document.documentElement,Ff=document.defaultView),Uf.style.transform=t,t=Ff.getComputedStyle(Of.appendChild(Uf),null).getPropertyValue("transform"),Of.removeChild(Uf),t=t.slice(7,-1).split(","),hn(+t[0],+t[1],+t[2],+t[3],+t[4],+t[5]))},"px, ","px)","deg)"),Qf=pn(function(t){return null==t?Zf:(If||(If=document.createElementNS("http://www.w3.org/2000/svg","g")),If.setAttribute("transform",t),(t=If.transform.baseVal.consolidate())?(t=t.matrix,hn(t.a,t.b,t.c,t.d,t.e,t.f)):Zf)},", ",")",")"),Jf=Math.SQRT2,Kf=2,tl=4,nl=1e-12,el=gn(tn),rl=gn(en),il=_n(tn),ol=_n(en),ul=yn(tn),al=yn(en),cl=0,sl=0,fl=0,ll=1e3,hl=0,pl=0,dl=0,vl="object"==typeof performance&&performance.now?performance:Date,gl="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};bn.prototype=wn.prototype={constructor:bn,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?mn():+e)+(null==n?0:+n),this._next||Bf===this||(Bf?Bf._next=this:Yf=this,Bf=this),this._call=t,this._time=e,kn()},stop:function(){this._call&&(this._call=null,this._time=1/0,kn())}};var _l=N("start","end","interrupt"),yl=[],ml=0,xl=1,bl=2,wl=3,Ml=4,Tl=5,Nl=6,kl=at.prototype.constructor,Sl=0,El=at.prototype;qn.prototype=Dn.prototype={constructor:qn,select:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=z(t));for(var r=this._groups,i=r.length,o=new Array(i),u=0;u<i;++u)for(var a,c,s=r[u],f=s.length,l=o[u]=new Array(f),h=0;h<f;++h)(a=s[h])&&(c=t.call(a,a.__data__,h,s))&&("__data__"in a&&(c.__data__=a.__data__),l[h]=c,En(l[h],n,e,h,l,zn(a,e)));return new qn(o,this._parents,n,e)},selectAll:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=R(t));for(var r=this._groups,i=r.length,o=[],u=[],a=0;a<i;++a)for(var c,s=r[a],f=s.length,l=0;l<f;++l)if(c=s[l]){for(var h,p=t.call(c,c.__data__,l,s),d=zn(c,e),v=0,g=p.length;v<g;++v)(h=p[v])&&En(h,n,e,v,p,d);o.push(p),u.push(c)}return new qn(o,u,n,e)},filter:function(t){"function"!=typeof t&&(t=of(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,u=n[i],a=u.length,c=r[i]=[],s=0;s<a;++s)(o=u[s])&&t.call(o,o.__data__,s,u)&&c.push(o);return new qn(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),u=new Array(r),a=0;a<o;++a)for(var c,s=n[a],f=e[a],l=s.length,h=u[a]=new Array(l),p=0;p<l;++p)(c=s[p]||f[p])&&(h[p]=c);for(;a<r;++a)u[a]=n[a];return new qn(u,this._parents,this._name,this._id)},selection:function(){return new kl(this._groups,this._parents)},transition:function(){for(var t=this._name,n=this._id,e=Un(),r=this._groups,i=r.length,o=0;o<i;++o)for(var u,a=r[o],c=a.length,s=0;s<c;++s)if(u=a[s]){var f=zn(u,n);En(u,t,e,s,a,{time:f.time+f.delay+f.duration,delay:0,duration:f.duration,ease:f.ease})}return new qn(r,this._parents,t,e)},call:El.call,nodes:El.nodes,node:El.node,size:El.size,empty:El.empty,each:El.each,on:function(t,n){var e=this._id;return arguments.length<2?zn(this.node(),e).on.on(t):this.each(function(t,n,e){var r,i,o=function(t){return(t+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||"start"===t})}(n)?An:Cn;return function(){var u=o(this,t),a=u.on;a!==r&&(i=(r=a).copy()).on(n,e),u.on=i}}(e,t,n))},attr:function(t,n){var e=E(t),r="transform"===e?Qf:Ln;return this.attrTween(t,"function"==typeof n?(e.local?function(t,n,e){var r,i,o;return function(){var u,a=e(this);if(null!=a)return(u=this.getAttributeNS(t.space,t.local))===a?null:u===r&&a===i?o:o=n(r=u,i=a);this.removeAttributeNS(t.space,t.local)}}:function(t,n,e){var r,i,o;return function(){var u,a=e(this);if(null!=a)return(u=this.getAttribute(t))===a?null:u===r&&a===i?o:o=n(r=u,i=a);this.removeAttribute(t)}})(e,r,Rn(this,"attr."+t,n)):null==n?(e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}})(e):(e.local?function(t,n,e){var r,i;return function(){var o=this.getAttributeNS(t.space,t.local);return o===e?null:o===r?i:i=n(r=o,e)}}:function(t,n,e){var r,i;return function(){var o=this.getAttribute(t);return o===e?null:o===r?i:i=n(r=o,e)}})(e,r,n+""))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=E(t);return this.tween(e,(r.local?function(t,n){function e(){var e=this,r=n.apply(e,arguments);return r&&function(n){e.setAttributeNS(t.space,t.local,r(n))}}return e._value=n,e}:function(t,n){function e(){var e=this,r=n.apply(e,arguments);return r&&function(n){e.setAttribute(t,r(n))}}return e._value=n,e})(r,n))},style:function(t,n,e){var r="transform"==(t+="")?Gf:Ln;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=I(this,t),u=(this.style.removeProperty(t),I(this,t));return o===u?null:o===e&&u===r?i:i=n(e=o,r=u)}}(t,r)).on("end.style."+t,function(t){return function(){this.style.removeProperty(t)}}(t)):this.styleTween(t,"function"==typeof n?function(t,n,e){var r,i,o;return function(){var u=I(this,t),a=e(this);return null==a&&(this.style.removeProperty(t),a=I(this,t)),u===a?null:u===r&&a===i?o:o=n(r=u,i=a)}}(t,r,Rn(this,"style."+t,n)):function(t,n,e){var r,i;return function(){var o=I(this,t);return o===e?null:o===r?i:i=n(r=o,e)}}(t,r,n+""),e)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){function r(){var r=this,i=n.apply(r,arguments);return i&&function(n){r.style.setProperty(t,i(n),e)}}return r._value=n,r}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(Rn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=zn(this.node(),e).tween,o=0,u=i.length;o<u;++o)if((r=i[o]).name===t)return r.value;return null}return this.each((null==n?function(t,n){var e,r;return function(){var i=Cn(this,t),o=i.tween;if(o!==e)for(var u=0,a=(r=e=o).length;u<a;++u)if(r[u].name===n){(r=r.slice()).splice(u,1);break}i.tween=r}}:function(t,n,e){var r,i;if("function"!=typeof e)throw new Error;return function(){var o=Cn(this,t),u=o.tween;if(u!==r){i=(r=u).slice();for(var a={name:n,value:e},c=0,s=i.length;c<s;++c)if(i[c].name===n){i[c]=a;break}c===s&&i.push(a)}o.tween=i}})(e,t,n))},delay:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){An(this,t).delay=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){An(this,t).delay=n}})(n,t)):zn(this.node(),n).delay},duration:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){Cn(this,t).duration=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){Cn(this,t).duration=n}})(n,t)):zn(this.node(),n).duration},ease:function(t){var n=this._id;return arguments.length?this.each(function(t,n){if("function"!=typeof n)throw new Error;return function(){Cn(this,t).ease=n}}(n,t)):zn(this.node(),n).ease}};var Al=function t(n){function e(t){return Math.pow(t,n)}return n=+n,e.exponent=t,e}(3),Cl=function t(n){function e(t){return 1-Math.pow(1-t,n)}return n=+n,e.exponent=t,e}(3),zl=function t(n){function e(t){return((t*=2)<=1?Math.pow(t,n):2-Math.pow(2-t,n))/2}return n=+n,e.exponent=t,e}(3),Pl=Math.PI,Rl=Pl/2,Ll=4/11,ql=6/11,Dl=8/11,Ul=.75,Ol=9/11,Fl=10/11,Il=.9375,Yl=21/22,Bl=63/64,Hl=1/Ll/Ll,jl=function t(n){function e(t){return t*t*((n+1)*t-n)}return n=+n,e.overshoot=t,e}(1.70158),Xl=function t(n){function e(t){return--t*t*((n+1)*t+n)+1}return n=+n,e.overshoot=t,e}(1.70158),Vl=function t(n){function e(t){return((t*=2)<1?t*t*((n+1)*t-n):(t-=2)*t*((n+1)*t+n)+2)/2}return n=+n,e.overshoot=t,e}(1.70158),$l=2*Math.PI,Wl=function t(n,e){function r(t){return n*Math.pow(2,10*--t)*Math.sin((i-t)/e)}var i=Math.asin(1/(n=Math.max(1,n)))*(e/=$l);return r.amplitude=function(n){return t(n,e*$l)},r.period=function(e){return t(n,e)},r}(1,.3),Zl=function t(n,e){function r(t){return 1-n*Math.pow(2,-10*(t=+t))*Math.sin((t+i)/e)}var i=Math.asin(1/(n=Math.max(1,n)))*(e/=$l);return r.amplitude=function(n){return t(n,e*$l)},r.period=function(e){return t(n,e)},r}(1,.3),Gl=function t(n,e){function r(t){return((t=2*t-1)<0?n*Math.pow(2,10*t)*Math.sin((i-t)/e):2-n*Math.pow(2,-10*t)*Math.sin((i+t)/e))/2}var i=Math.asin(1/(n=Math.max(1,n)))*(e/=$l);return r.amplitude=function(n){return t(n,e*$l)},r.period=function(e){return t(n,e)},r}(1,.3),Ql={time:null,delay:0,duration:250,ease:Fn};at.prototype.interrupt=function(t){return this.each(function(){Pn(this,t)})},at.prototype.transition=function(t){var n,e;t instanceof qn?(n=t._id,t=t._name):(n=Un(),(e=Ql).time=mn(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var u,a=r[o],c=a.length,s=0;s<c;++s)(u=a[s])&&En(u,t,n,s,a,e||jn(u,n));return new qn(r,this._parents,t,n)};var Jl=[null],Kl={name:"drag"},th={name:"space"},nh={name:"handle"},eh={name:"center"},rh={name:"x",handles:["e","w"].map(Wn),input:function(t,n){return t&&[[t[0],n[0][1]],[t[1],n[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},ih={name:"y",handles:["n","s"].map(Wn),input:function(t,n){return t&&[[n[0][0],t[0]],[n[1][0],t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},oh={name:"xy",handles:["n","e","s","w","nw","ne","se","sw"].map(Wn),input:function(t){return t},output:function(t){return t}},uh={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},ah={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},ch={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},sh={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},fh={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1},lh=Math.cos,hh=Math.sin,ph=Math.PI,dh=ph/2,vh=2*ph,gh=Math.max,_h=Array.prototype.slice,yh=Math.PI,mh=2*yh,xh=mh-1e-6;ne.prototype=ee.prototype={constructor:ne,moveTo:function(t,n){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+n)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,n){this._+="L"+(this._x1=+t)+","+(this._y1=+n)},quadraticCurveTo:function(t,n,e,r){this._+="Q"+ +t+","+ +n+","+(this._x1=+e)+","+(this._y1=+r)},bezierCurveTo:function(t,n,e,r,i,o){this._+="C"+ +t+","+ +n+","+ +e+","+ +r+","+(this._x1=+i)+","+(this._y1=+o)},arcTo:function(t,n,e,r,i){t=+t,n=+n,e=+e,r=+r,i=+i;var o=this._x1,u=this._y1,a=e-t,c=r-n,s=o-t,f=u-n,l=s*s+f*f;if(i<0)throw new Error("negative radius: "+i);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=n);else if(l>1e-6)if(Math.abs(f*a-c*s)>1e-6&&i){var h=e-o,p=r-u,d=a*a+c*c,v=h*h+p*p,g=Math.sqrt(d),_=Math.sqrt(l),y=i*Math.tan((yh-Math.acos((d+l-v)/(2*g*_)))/2),m=y/_,x=y/g;Math.abs(m-1)>1e-6&&(this._+="L"+(t+m*s)+","+(n+m*f)),this._+="A"+i+","+i+",0,0,"+ +(f*h>s*p)+","+(this._x1=t+x*a)+","+(this._y1=n+x*c)}else this._+="L"+(this._x1=t)+","+(this._y1=n);else;},arc:function(t,n,e,r,i,o){t=+t,n=+n;var u=(e=+e)*Math.cos(r),a=e*Math.sin(r),c=t+u,s=n+a,f=1^o,l=o?r-i:i-r;if(e<0)throw new Error("negative radius: "+e);null===this._x1?this._+="M"+c+","+s:(Math.abs(this._x1-c)>1e-6||Math.abs(this._y1-s)>1e-6)&&(this._+="L"+c+","+s),e&&(l<0&&(l=l%mh+mh),l>xh?this._+="A"+e+","+e+",0,1,"+f+","+(t-u)+","+(n-a)+"A"+e+","+e+",0,1,"+f+","+(this._x1=c)+","+(this._y1=s):l>1e-6&&(this._+="A"+e+","+e+",0,"+ +(l>=yh)+","+f+","+(this._x1=t+e*Math.cos(i))+","+(this._y1=n+e*Math.sin(i))))},rect:function(t,n,e,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+n)+"h"+ +e+"v"+ +r+"h"+-e+"Z"},toString:function(){return this._}};ce.prototype=se.prototype={constructor:ce,has:function(t){return"$"+t in this},get:function(t){return this["$"+t]},set:function(t,n){return this["$"+t]=n,this},remove:function(t){var n="$"+t;return n in this&&delete this[n]},clear:function(){for(var t in this)"$"===t[0]&&delete this[t]},keys:function(){var t=[];for(var n in this)"$"===n[0]&&t.push(n.slice(1));return t},values:function(){var t=[];for(var n in this)"$"===n[0]&&t.push(this[n]);return t},entries:function(){var t=[];for(var n in this)"$"===n[0]&&t.push({key:n.slice(1),value:this[n]});return t},size:function(){var t=0;for(var n in this)"$"===n[0]&&++t;return t},empty:function(){for(var t in this)if("$"===t[0])return!1;return!0},each:function(t){for(var n in this)"$"===n[0]&&t(this[n],n.slice(1),this)}};var bh=se.prototype;de.prototype=ve.prototype={constructor:de,has:bh.has,add:function(t){return t+="",this["$"+t]=t,this},remove:bh.remove,clear:bh.clear,values:bh.keys,size:bh.size,empty:bh.empty,each:bh.each};var wh={},Mh={},Th=34,Nh=10,kh=13,Sh=_e(","),Eh=Sh.parse,Ah=Sh.parseRows,Ch=Sh.format,zh=Sh.formatRows,Ph=_e("\t"),Rh=Ph.parse,Lh=Ph.parseRows,qh=Ph.format,Dh=Ph.formatRows,Uh=Te.prototype=Ne.prototype;Uh.copy=function(){var t,n,e=new Ne(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=ke(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(4)}):r.target[i]=ke(n));return e},Uh.add=function(t){var n=+this._x.call(null,t),e=+this._y.call(null,t);return xe(this.cover(n,e),n,e,t)},Uh.addAll=function(t){var n,e,r,i,o=t.length,u=new Array(o),a=new Array(o),c=1/0,s=1/0,f=-1/0,l=-1/0;for(e=0;e<o;++e)isNaN(r=+this._x.call(null,n=t[e]))||isNaN(i=+this._y.call(null,n))||(u[e]=r,a[e]=i,r<c&&(c=r),r>f&&(f=r),i<s&&(s=i),i>l&&(l=i));for(f<c&&(c=this._x0,f=this._x1),l<s&&(s=this._y0,l=this._y1),this.cover(c,s).cover(f,l),e=0;e<o;++e)xe(this,u[e],a[e],t[e]);return this},Uh.cover=function(t,n){if(isNaN(t=+t)||isNaN(n=+n))return this;var e=this._x0,r=this._y0,i=this._x1,o=this._y1;if(isNaN(e))i=(e=Math.floor(t))+1,o=(r=Math.floor(n))+1;else{if(!(e>t||t>i||r>n||n>o))return this;var u,a,c=i-e,s=this._root;switch(a=(n<(r+o)/2)<<1|t<(e+i)/2){case 0:do{u=new Array(4),u[a]=s,s=u}while(c*=2,i=e+c,o=r+c,t>i||n>o);break;case 1:do{u=new Array(4),u[a]=s,s=u}while(c*=2,e=i-c,o=r+c,e>t||n>o);break;case 2:do{u=new Array(4),u[a]=s,s=u}while(c*=2,i=e+c,r=o-c,t>i||r>n);break;case 3:do{u=new Array(4),u[a]=s,s=u}while(c*=2,e=i-c,r=o-c,e>t||r>n)}this._root&&this._root.length&&(this._root=s)}return this._x0=e,this._y0=r,this._x1=i,this._y1=o,this},Uh.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},Uh.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},Uh.find=function(t,n,e){var r,i,o,u,a,c,s,f=this._x0,l=this._y0,h=this._x1,p=this._y1,d=[],v=this._root;for(v&&d.push(new be(v,f,l,h,p)),null==e?e=1/0:(f=t-e,l=n-e,h=t+e,p=n+e,e*=e);c=d.pop();)if(!(!(v=c.node)||(i=c.x0)>h||(o=c.y0)>p||(u=c.x1)<f||(a=c.y1)<l))if(v.length){var g=(i+u)/2,_=(o+a)/2;d.push(new be(v[3],g,_,u,a),new be(v[2],i,_,g,a),new be(v[1],g,o,u,_),new be(v[0],i,o,g,_)),(s=(n>=_)<<1|t>=g)&&(c=d[d.length-1],d[d.length-1]=d[d.length-1-s],d[d.length-1-s]=c)}else{var y=t-+this._x.call(null,v.data),m=n-+this._y.call(null,v.data),x=y*y+m*m;if(x<e){var b=Math.sqrt(e=x);f=t-b,l=n-b,h=t+b,p=n+b,r=v.data}}return r},Uh.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(u=+this._y.call(null,t)))return this;var n,e,r,i,o,u,a,c,s,f,l,h,p=this._root,d=this._x0,v=this._y0,g=this._x1,_=this._y1;if(!p)return this;if(p.length)for(;;){if((s=o>=(a=(d+g)/2))?d=a:g=a,(f=u>=(c=(v+_)/2))?v=c:_=c,n=p,!(p=p[l=f<<1|s]))return this;if(!p.length)break;(n[l+1&3]||n[l+2&3]||n[l+3&3])&&(e=n,h=l)}for(;p.data!==t;)if(r=p,!(p=p.next))return this;return(i=p.next)&&delete p.next,r?(i?r.next=i:delete r.next,this):n?(i?n[l]=i:delete n[l],(p=n[0]||n[1]||n[2]||n[3])&&p===(n[3]||n[2]||n[1]||n[0])&&!p.length&&(e?e[h]=p:this._root=p),this):(this._root=i,this)},Uh.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},Uh.root=function(){return this._root},Uh.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},Uh.visit=function(t){var n,e,r,i,o,u,a=[],c=this._root;for(c&&a.push(new be(c,this._x0,this._y0,this._x1,this._y1));n=a.pop();)if(!t(c=n.node,r=n.x0,i=n.y0,o=n.x1,u=n.y1)&&c.length){var s=(r+o)/2,f=(i+u)/2;(e=c[3])&&a.push(new be(e,s,f,o,u)),(e=c[2])&&a.push(new be(e,r,f,s,u)),(e=c[1])&&a.push(new be(e,s,i,o,f)),(e=c[0])&&a.push(new be(e,r,i,s,f))}return this},Uh.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new be(this._root,this._x0,this._y0,this._x1,this._y1));n=e.pop();){var i=n.node;if(i.length){var o,u=n.x0,a=n.y0,c=n.x1,s=n.y1,f=(u+c)/2,l=(a+s)/2;(o=i[0])&&e.push(new be(o,u,a,f,l)),(o=i[1])&&e.push(new be(o,f,a,c,l)),(o=i[2])&&e.push(new be(o,u,l,f,s)),(o=i[3])&&e.push(new be(o,f,l,c,s))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.y1);return this},Uh.x=function(t){return arguments.length?(this._x=t,this):this._x},Uh.y=function(t){return arguments.length?(this._y=t,this):this._y};var Oh,Fh=10,Ih=Math.PI*(3-Math.sqrt(5)),Yh={"":function(t,n){t:for(var e,r=(t=t.toPrecision(n)).length,i=1,o=-1;i<r;++i)switch(t[i]){case".":o=e=i;break;case"0":0===o&&(o=i),e=i;break;case"e":break t;default:o>0&&(o=0)}return o>0?t.slice(0,o)+t.slice(e+1):t},"%":function(t,n){return(100*t).toFixed(n)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,n){return t.toExponential(n)},f:function(t,n){return t.toFixed(n)},g:function(t,n){return t.toPrecision(n)},o:function(t){return Math.round(t).toString(8)},p:function(t,n){return qe(100*t,n)},r:qe,s:function(t,n){var e=Re(t,n);if(!e)return t+"";var r=e[0],i=e[1],o=i-(Oh=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,u=r.length;return o===u?r:o>u?r+new Array(o-u+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+Re(t,Math.max(0,n+o-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},Bh=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;De.prototype=Ue.prototype,Ue.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(null==this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(null==this.precision?"":"."+Math.max(0,0|this.precision))+this.type};var Hh,jh=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];Ie({decimal:".",thousands:",",grouping:[3],currency:["$",""]}),Xe.prototype={constructor:Xe,reset:function(){this.s=this.t=0},add:function(t){Ve(wp,t,this.t),Ve(this,wp.s,this.s),this.s?this.t+=wp.t:this.s=wp.t},valueOf:function(){return this.s}};var Xh,Vh,$h,Wh,Zh,Gh,Qh,Jh,Kh,tp,np,ep,rp,ip,op,up,ap,cp,sp,fp,lp,hp,pp,dp,vp,gp,_p,yp,mp,xp,bp,wp=new Xe,Mp=1e-6,Tp=1e-12,Np=Math.PI,kp=Np/2,Sp=Np/4,Ep=2*Np,Ap=180/Np,Cp=Np/180,zp=Math.abs,Pp=Math.atan,Rp=Math.atan2,Lp=Math.cos,qp=Math.ceil,Dp=Math.exp,Up=Math.log,Op=Math.pow,Fp=Math.sin,Ip=Math.sign||function(t){return t>0?1:t<0?-1:0},Yp=Math.sqrt,Bp=Math.tan,Hp={Feature:function(t,n){Qe(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++r<i;)Qe(e[r].geometry,n)}},jp={Sphere:function(t,n){n.sphere()},Point:function(t,n){t=t.coordinates,n.point(t[0],t[1],t[2])},MultiPoint:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)t=e[r],n.point(t[0],t[1],t[2])},LineString:function(t,n){Je(t.coordinates,n,0)},MultiLineString:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)Je(e[r],n,0)},Polygon:function(t,n){Ke(t.coordinates,n)},MultiPolygon:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)Ke(e[r],n)},GeometryCollection:function(t,n){for(var e=t.geometries,r=-1,i=e.length;++r<i;)Qe(e[r],n)}},Xp=je(),Vp=je(),$p={point:Ge,lineStart:Ge,lineEnd:Ge,polygonStart:function(){Xp.reset(),$p.lineStart=nr,$p.lineEnd=er},polygonEnd:function(){var t=+Xp;Vp.add(t<0?Ep+t:t),this.lineStart=this.lineEnd=this.point=Ge},sphere:function(){Vp.add(Ep)}},Wp=je(),Zp={point:hr,lineStart:dr,lineEnd:vr,polygonStart:function(){Zp.point=gr,Zp.lineStart=_r,Zp.lineEnd=yr,Wp.reset(),$p.polygonStart()},polygonEnd:function(){$p.polygonEnd(),Zp.point=hr,Zp.lineStart=dr,Zp.lineEnd=vr,Xp<0?(Gh=-(Jh=180),Qh=-(Kh=90)):Wp>Mp?Kh=90:Wp<-Mp&&(Qh=-90),op[0]=Gh,op[1]=Jh}},Gp={sphere:Ge,point:wr,lineStart:Tr,lineEnd:Sr,polygonStart:function(){Gp.lineStart=Er,Gp.lineEnd=Ar},polygonEnd:function(){Gp.lineStart=Tr,Gp.lineEnd=Sr}};Lr.invert=Lr;var Qp,Jp,Kp,td,nd,ed,rd,id,od,ud,ad,cd=je(),sd=Wr(function(){return!0},function(t){var n,e=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),n=1},point:function(o,u){var a=o>0?Np:-Np,c=zp(o-e);zp(c-Np)<Mp?(t.point(e,r=(r+u)/2>0?kp:-kp),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),t.point(o,r),n=0):i!==a&&c>=Np&&(zp(e-i)<Mp&&(e-=i*Mp),zp(o-a)<Mp&&(o-=a*Mp),r=function(t,n,e,r){var i,o,u=Fp(t-e);return zp(u)>Mp?Pp((Fp(n)*(o=Lp(r))*Fp(e)-Fp(r)*(i=Lp(n))*Fp(t))/(i*o*u)):(n+r)/2}(e,r,o,u),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),n=0),t.point(e=o,r=u),i=a},lineEnd:function(){t.lineEnd(),e=r=NaN},clean:function(){return 2-n}}},function(t,n,e,r){var i;if(null==t)i=e*kp,r.point(-Np,i),r.point(0,i),r.point(Np,i),r.point(Np,0),r.point(Np,-i),r.point(0,-i),r.point(-Np,-i),r.point(-Np,0),r.point(-Np,i);else if(zp(t[0]-n[0])>Mp){var o=t[0]<n[0]?Np:-Np;i=e*o/2,r.point(-o,i),r.point(0,i),r.point(o,i)}else r.point(n[0],n[1])},[-Np,-kp]),fd=1e9,ld=-fd,hd=je(),pd={sphere:Ge,point:Ge,lineStart:function(){pd.point=ti,pd.lineEnd=Kr},lineEnd:Ge,polygonStart:Ge,polygonEnd:Ge},dd=[null,null],vd={type:"LineString",coordinates:dd},gd={Feature:function(t,n){return ii(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++r<i;)if(ii(e[r].geometry,n))return!0;return!1}},_d={Sphere:function(){return!0},Point:function(t,n){return oi(t.coordinates,n)},MultiPoint:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)if(oi(e[r],n))return!0;return!1},LineString:function(t,n){return ui(t.coordinates,n)},MultiLineString:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)if(ui(e[r],n))return!0;return!1},Polygon:function(t,n){return ai(t.coordinates,n)},MultiPolygon:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)if(ai(e[r],n))return!0;return!1},GeometryCollection:function(t,n){for(var e=t.geometries,r=-1,i=e.length;++r<i;)if(ii(e[r],n))return!0;return!1}},yd=je(),md=je(),xd={point:Ge,lineStart:Ge,lineEnd:Ge,polygonStart:function(){xd.lineStart=di,xd.lineEnd=_i},polygonEnd:function(){xd.lineStart=xd.lineEnd=xd.point=Ge,yd.add(zp(md)),md.reset()},result:function(){var t=yd/2;return yd.reset(),t}},bd=1/0,wd=bd,Md=-bd,Td=Md,Nd={point:function(t,n){t<bd&&(bd=t),t>Md&&(Md=t),n<wd&&(wd=n),n>Td&&(Td=n)},lineStart:Ge,lineEnd:Ge,polygonStart:Ge,polygonEnd:Ge,result:function(){var t=[[bd,wd],[Md,Td]];return Md=Td=-(wd=bd=1/0),t}},kd=0,Sd=0,Ed=0,Ad=0,Cd=0,zd=0,Pd=0,Rd=0,Ld=0,qd={point:yi,lineStart:mi,lineEnd:wi,polygonStart:function(){qd.lineStart=Mi,qd.lineEnd=Ti},polygonEnd:function(){qd.point=yi,qd.lineStart=mi,qd.lineEnd=wi},result:function(){var t=Ld?[Pd/Ld,Rd/Ld]:zd?[Ad/zd,Cd/zd]:Ed?[kd/Ed,Sd/Ed]:[NaN,NaN];return kd=Sd=Ed=Ad=Cd=zd=Pd=Rd=Ld=0,t}};Si.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,n){switch(this._point){case 0:this._context.moveTo(t,n),this._point=1;break;case 1:this._context.lineTo(t,n);break;default:this._context.moveTo(t+this._radius,n),this._context.arc(t,n,this._radius,0,Ep)}},result:Ge};var Dd,Ud,Od,Fd,Id,Yd=je(),Bd={point:Ge,lineStart:function(){Bd.point=Ei},lineEnd:function(){Dd&&Ai(Ud,Od),Bd.point=Ge},polygonStart:function(){Dd=!0},polygonEnd:function(){Dd=null},result:function(){var t=+Yd;return Yd.reset(),t}};Ci.prototype={_radius:4.5,_circle:zi(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,n){switch(this._point){case 0:this._string.push("M",t,",",n),this._point=1;break;case 1:this._string.push("L",t,",",n);break;default:null==this._circle&&(this._circle=zi(this._radius)),this._string.push("M",t,",",n,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}},Ri.prototype={constructor:Ri,point:function(t,n){this.stream.point(t,n)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Hd=16,jd=Lp(30*Cp),Xd=Pi({point:function(t,n){this.stream.point(t*Cp,n*Cp)}}),Vd=Vi(function(t){return Yp(2/(1+t))});Vd.invert=$i(function(t){return 2*We(t/2)});var $d=Vi(function(t){return(t=$e(t))&&t/Fp(t)});$d.invert=$i(function(t){return t}),Wi.invert=function(t,n){return[t,2*Pp(Dp(n))-kp]},Ji.invert=Ji,to.invert=$i(Pp),eo.invert=function(t,n){var e,r=n,i=25;do{var o=r*r,u=o*o;r-=e=(r*(1.007226+o*(.015085+u*(.028874*o-.044475-.005916*u)))-n)/(1.007226+o*(.045255+u*(.259866*o-.311325-.005916*11*u)))}while(zp(e)>Mp&&--i>0);return[t/(.8707+(o=r*r)*(o*(o*o*o*(.003971-.001529*o)-.013791)-.131979)),r]},ro.invert=$i(We),io.invert=$i(function(t){return 2*Pp(t)}),oo.invert=function(t,n){return[-n,2*Pp(Dp(t))-kp]},vo.prototype=fo.prototype={constructor:vo,count:function(){return this.eachAfter(so)},each:function(t){var n,e,r,i,o=this,u=[o];do{for(n=u.reverse(),u=[];o=n.pop();)if(t(o),e=o.children)for(r=0,i=e.length;r<i;++r)u.push(e[r])}while(u.length);return this},eachAfter:function(t){for(var n,e,r,i=this,o=[i],u=[];i=o.pop();)if(u.push(i),n=i.children)for(e=0,r=n.length;e<r;++e)o.push(n[e]);for(;i=u.pop();)t(i);return this},eachBefore:function(t){for(var n,e,r=this,i=[r];r=i.pop();)if(t(r),n=r.children)for(e=n.length-1;e>=0;--e)i.push(n[e]);return this},sum:function(t){return this.eachAfter(function(n){for(var e=+t(n.data)||0,r=n.children,i=r&&r.length;--i>=0;)e+=r[i].value;n.value=e})},sort:function(t){return this.eachBefore(function(n){n.children&&n.children.sort(t)})},path:function(t){for(var n=this,e=function(t,n){if(t===n)return t;var e=t.ancestors(),r=n.ancestors(),i=null;for(t=e.pop(),n=r.pop();t===n;)i=t,t=e.pop(),n=r.pop();return i}(n,t),r=[n];n!==e;)n=n.parent,r.push(n);for(var i=r.length;t!==e;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,n=[t];t=t.parent;)n.push(t);return n},descendants:function(){var t=[];return this.each(function(n){t.push(n)}),t},leaves:function(){var t=[];return this.eachBefore(function(n){n.children||t.push(n)}),t},links:function(){var t=this,n=[];return t.each(function(e){e!==t&&n.push({source:e.parent,target:e})}),n},copy:function(){return fo(this).eachBefore(ho)}};var Wd=Array.prototype.slice,Zd="$",Gd={depth:-1},Qd={};Ho.prototype=Object.create(vo.prototype);var Jd=(1+Math.sqrt(5))/2,Kd=function t(n){function e(t,e,r,i,o){Xo(n,t,e,r,i,o)}return e.ratio=function(n){return t((n=+n)>1?n:1)},e}(Jd),tv=function t(n){function e(t,e,r,i,o){if((u=t._squarify)&&u.ratio===n)for(var u,a,c,s,f,l=-1,h=u.length,p=t.value;++l<h;){for(c=(a=u[l]).children,s=a.value=0,f=c.length;s<f;++s)a.value+=c[s].value;a.dice?qo(a,e,r,i,r+=(o-r)*a.value/p):jo(a,e,r,e+=(i-e)*a.value/p,o),p-=a.value}else t._squarify=u=Xo(n,t,e,r,i,o),u.ratio=n}return e.ratio=function(n){return t((n=+n)>1?n:1)},e}(Jd),nv=[].slice,ev={};Zo.prototype=Ko.prototype={constructor:Zo,defer:function(t){if("function"!=typeof t)throw new Error("invalid callback");if(this._call)throw new Error("defer after await");if(null!=this._error)return this;var n=nv.call(arguments,1);return n.push(t),++this._waiting,this._tasks.push(n),Go(this),this},abort:function(){return null==this._error&&Qo(this,new Error("abort")),this},await:function(t){if("function"!=typeof t)throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=function(n,e){t.apply(null,[n].concat(e))},Jo(this),this},awaitAll:function(t){if("function"!=typeof t)throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=t,Jo(this),this}};var rv=function t(n){function e(t,e){return t=null==t?0:+t,e=null==e?1:+e,1===arguments.length?(e=t,t=0):e-=t,function(){return n()*e+t}}return e.source=t,e}(tu),iv=function t(n){function e(t,e){var r,i;return t=null==t?0:+t,e=null==e?1:+e,function(){var o;if(null!=r)o=r,r=null;else do{r=2*n()-1,o=2*n()-1,i=r*r+o*o}while(!i||i>1);return t+e*o*Math.sqrt(-2*Math.log(i)/i)}}return e.source=t,e}(tu),ov=function t(n){function e(){var t=iv.source(n).apply(this,arguments);return function(){return Math.exp(t())}}return e.source=t,e}(tu),uv=function t(n){function e(t){return function(){for(var e=0,r=0;r<t;++r)e+=n();return e}}return e.source=t,e}(tu),av=function t(n){function e(t){var e=uv.source(n)(t);return function(){return e()/t}}return e.source=t,e}(tu),cv=function t(n){function e(t){return function(){return-Math.log(1-n())/t}}return e.source=t,e}(tu),sv=eu("text/html",function(t){return document.createRange().createContextualFragment(t.responseText)}),fv=eu("application/json",function(t){return JSON.parse(t.responseText)}),lv=eu("text/plain",function(t){return t.responseText}),hv=eu("application/xml",function(t){var n=t.responseXML;if(!n)throw new Error("parse error");return n}),pv=ru("text/csv",Eh),dv=ru("text/tab-separated-values",Rh),vv=Array.prototype,gv=vv.map,_v=vv.slice,yv={name:"implicit"},mv=[0,1],xv=new Date,bv=new Date,wv=Cu(function(){},function(t,n){t.setTime(+t+n)},function(t,n){return n-t});wv.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?Cu(function(n){n.setTime(Math.floor(n/t)*t)},function(n,e){n.setTime(+n+e*t)},function(n,e){return(e-n)/t}):wv:null};var Mv=wv.range,Tv=6e4,Nv=6048e5,kv=Cu(function(t){t.setTime(1e3*Math.floor(t/1e3))},function(t,n){t.setTime(+t+1e3*n)},function(t,n){return(n-t)/1e3},function(t){return t.getUTCSeconds()}),Sv=kv.range,Ev=Cu(function(t){t.setTime(Math.floor(t/Tv)*Tv)},function(t,n){t.setTime(+t+n*Tv)},function(t,n){return(n-t)/Tv},function(t){return t.getMinutes()}),Av=Ev.range,Cv=Cu(function(t){var n=t.getTimezoneOffset()*Tv%36e5;n<0&&(n+=36e5),t.setTime(36e5*Math.floor((+t-n)/36e5)+n)},function(t,n){t.setTime(+t+36e5*n)},function(t,n){return(n-t)/36e5},function(t){return t.getHours()}),zv=Cv.range,Pv=Cu(function(t){t.setHours(0,0,0,0)},function(t,n){t.setDate(t.getDate()+n)},function(t,n){return(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Tv)/864e5},function(t){return t.getDate()-1}),Rv=Pv.range,Lv=zu(0),qv=zu(1),Dv=zu(2),Uv=zu(3),Ov=zu(4),Fv=zu(5),Iv=zu(6),Yv=Lv.range,Bv=qv.range,Hv=Dv.range,jv=Uv.range,Xv=Ov.range,Vv=Fv.range,$v=Iv.range,Wv=Cu(function(t){t.setDate(1),t.setHours(0,0,0,0)},function(t,n){t.setMonth(t.getMonth()+n)},function(t,n){return n.getMonth()-t.getMonth()+12*(n.getFullYear()-t.getFullYear())},function(t){return t.getMonth()}),Zv=Wv.range,Gv=Cu(function(t){t.setMonth(0,1),t.setHours(0,0,0,0)},function(t,n){t.setFullYear(t.getFullYear()+n)},function(t,n){return n.getFullYear()-t.getFullYear()},function(t){return t.getFullYear()});Gv.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Cu(function(n){n.setFullYear(Math.floor(n.getFullYear()/t)*t),n.setMonth(0,1),n.setHours(0,0,0,0)},function(n,e){n.setFullYear(n.getFullYear()+e*t)}):null};var Qv=Gv.range,Jv=Cu(function(t){t.setUTCSeconds(0,0)},function(t,n){t.setTime(+t+n*Tv)},function(t,n){return(n-t)/Tv},function(t){return t.getUTCMinutes()}),Kv=Jv.range,tg=Cu(function(t){t.setUTCMinutes(0,0,0)},function(t,n){t.setTime(+t+36e5*n)},function(t,n){return(n-t)/36e5},function(t){return t.getUTCHours()}),ng=tg.range,eg=Cu(function(t){t.setUTCHours(0,0,0,0)},function(t,n){t.setUTCDate(t.getUTCDate()+n)},function(t,n){return(n-t)/864e5},function(t){return t.getUTCDate()-1}),rg=eg.range,ig=Pu(0),og=Pu(1),ug=Pu(2),ag=Pu(3),cg=Pu(4),sg=Pu(5),fg=Pu(6),lg=ig.range,hg=og.range,pg=ug.range,dg=ag.range,vg=cg.range,gg=sg.range,_g=fg.range,yg=Cu(function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)},function(t,n){t.setUTCMonth(t.getUTCMonth()+n)},function(t,n){return n.getUTCMonth()-t.getUTCMonth()+12*(n.getUTCFullYear()-t.getUTCFullYear())},function(t){return t.getUTCMonth()}),mg=yg.range,xg=Cu(function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},function(t,n){t.setUTCFullYear(t.getUTCFullYear()+n)},function(t,n){return n.getUTCFullYear()-t.getUTCFullYear()},function(t){return t.getUTCFullYear()});xg.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Cu(function(n){n.setUTCFullYear(Math.floor(n.getUTCFullYear()/t)*t),n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},function(n,e){n.setUTCFullYear(n.getUTCFullYear()+e*t)}):null};var bg,wg=xg.range,Mg={"-":"",_:" ",0:"0"},Tg=/^\s*\d+/,Ng=/^%/,kg=/[\\^$*+?|[\]().{}]/g;Ha({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});var Sg="%Y-%m-%dT%H:%M:%S.%LZ",Eg=Date.prototype.toISOString?function(t){return t.toISOString()}:t.utcFormat(Sg),Ag=+new Date("2000-01-01T00:00:00.000Z")?function(t){var n=new Date(t);return isNaN(n)?null:n}:t.utcParse(Sg),Cg=1e3,zg=60*Cg,Pg=60*zg,Rg=24*Pg,Lg=7*Rg,qg=30*Rg,Dg=365*Rg,Ug=$a("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),Og=$a("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6"),Fg=$a("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9"),Ig=$a("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5"),Yg=al($t(300,.5,0),$t(-240,.5,1)),Bg=al($t(-100,.75,.35),$t(80,1.5,.8)),Hg=al($t(260,.75,.35),$t(80,1.5,.8)),jg=$t(),Xg=Wa($a("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725")),Vg=Wa($a("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),$g=Wa($a("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),Wg=Wa($a("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921")),Zg=Math.abs,Gg=Math.atan2,Qg=Math.cos,Jg=Math.max,Kg=Math.min,t_=Math.sin,n_=Math.sqrt,e_=1e-12,r_=Math.PI,i_=r_/2,o_=2*r_;ic.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:this._context.lineTo(t,n)}}};var u_=pc(oc);hc.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,n){this._curve.point(n*Math.sin(t),n*-Math.cos(t))}};var a_=Array.prototype.slice,c_={draw:function(t,n){var e=Math.sqrt(n/r_);t.moveTo(e,0),t.arc(0,0,e,0,o_)}},s_={draw:function(t,n){var e=Math.sqrt(n/5)/2;t.moveTo(-3*e,-e),t.lineTo(-e,-e),t.lineTo(-e,-3*e),t.lineTo(e,-3*e),t.lineTo(e,-e),t.lineTo(3*e,-e),t.lineTo(3*e,e),t.lineTo(e,e),t.lineTo(e,3*e),t.lineTo(-e,3*e),t.lineTo(-e,e),t.lineTo(-3*e,e),t.closePath()}},f_=Math.sqrt(1/3),l_=2*f_,h_={draw:function(t,n){var e=Math.sqrt(n/l_),r=e*f_;t.moveTo(0,-e),t.lineTo(r,0),t.lineTo(0,e),t.lineTo(-r,0),t.closePath()}},p_=Math.sin(r_/10)/Math.sin(7*r_/10),d_=Math.sin(o_/10)*p_,v_=-Math.cos(o_/10)*p_,g_={draw:function(t,n){var e=Math.sqrt(.8908130915292852*n),r=d_*e,i=v_*e;t.moveTo(0,-e),t.lineTo(r,i);for(var o=1;o<5;++o){var u=o_*o/5,a=Math.cos(u),c=Math.sin(u);t.lineTo(c*e,-a*e),t.lineTo(a*r-c*i,c*r+a*i)}t.closePath()}},__={draw:function(t,n){var e=Math.sqrt(n),r=-e/2;t.rect(r,r,e,e)}},y_=Math.sqrt(3),m_={draw:function(t,n){var e=-Math.sqrt(n/(3*y_));t.moveTo(0,2*e),t.lineTo(-y_*e,-e),t.lineTo(y_*e,-e),t.closePath()}},x_=Math.sqrt(3)/2,b_=1/Math.sqrt(12),w_=3*(b_/2+1),M_={draw:function(t,n){var e=Math.sqrt(n/w_),r=e/2,i=e*b_,o=r,u=e*b_+e,a=-o,c=u;t.moveTo(r,i),t.lineTo(o,u),t.lineTo(a,c),t.lineTo(-.5*r-x_*i,x_*r+-.5*i),t.lineTo(-.5*o-x_*u,x_*o+-.5*u),t.lineTo(-.5*a-x_*c,x_*a+-.5*c),t.lineTo(-.5*r+x_*i,-.5*i-x_*r),t.lineTo(-.5*o+x_*u,-.5*u-x_*o),t.lineTo(-.5*a+x_*c,-.5*c-x_*a),t.closePath()}},T_=[c_,s_,h_,__,g_,m_,M_];kc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Nc(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Nc(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Sc.prototype={areaStart:Tc,areaEnd:Tc,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x2=t,this._y2=n;break;case 1:this._point=2,this._x3=t,this._y3=n;break;case 2:this._point=3,this._x4=t,this._y4=n,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+n)/6);break;default:Nc(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Ec.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var e=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+n)/6;this._line?this._context.lineTo(e,r):this._context.moveTo(e,r);break;case 3:this._point=4;default:Nc(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Ac.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,n=this._y,e=t.length-1;if(e>0)for(var r,i=t[0],o=n[0],u=t[e]-i,a=n[e]-o,c=-1;++c<=e;)r=c/e,this._basis.point(this._beta*t[c]+(1-this._beta)*(i+r*u),this._beta*n[c]+(1-this._beta)*(o+r*a));this._x=this._y=null,this._basis.lineEnd()},point:function(t,n){this._x.push(+t),this._y.push(+n)}};var N_=function t(n){function e(t){return 1===n?new kc(t):new Ac(t,n)}return e.beta=function(n){return t(+n)},e}(.85);zc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Cc(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2,this._x1=t,this._y1=n;break;case 2:this._point=3;default:Cc(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var k_=function t(n){function e(t){return new zc(t,n)}return e.tension=function(n){return t(+n)},e}(0);Pc.prototype={areaStart:Tc,areaEnd:Tc,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:Cc(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var S_=function t(n){function e(t){return new Pc(t,n)}return e.tension=function(n){return t(+n)},e}(0);Rc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Cc(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var E_=function t(n){function e(t){return new Rc(t,n)}return e.tension=function(n){return t(+n)},e}(0);qc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3;default:Lc(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var A_=function t(n){function e(t){return n?new qc(t,n):new zc(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);Dc.prototype={areaStart:Tc,areaEnd:Tc,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:Lc(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var C_=function t(n){function e(t){return n?new Dc(t,n):new Pc(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);Uc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Lc(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var z_=function t(n){function e(t){return n?new Uc(t,n):new Rc(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);Oc.prototype={areaStart:Tc,areaEnd:Tc,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,n){t=+t,n=+n,this._point?this._context.lineTo(t,n):(this._point=1,this._context.moveTo(t,n))}},Hc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Bc(this,this._t0,Yc(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){var e=NaN;if(t=+t,n=+n,t!==this._x1||n!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3,Bc(this,Yc(this,e=Ic(this,t,n)),e);break;default:Bc(this,this._t0,e=Ic(this,t,n))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n,this._t0=e}}},(jc.prototype=Object.create(Hc.prototype)).point=function(t,n){Hc.prototype.point.call(this,n,t)},Xc.prototype={moveTo:function(t,n){this._context.moveTo(n,t)},closePath:function(){this._context.closePath()},lineTo:function(t,n){this._context.lineTo(n,t)},bezierCurveTo:function(t,n,e,r,i,o){this._context.bezierCurveTo(n,t,r,e,o,i)}},Vc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,n=this._y,e=t.length;if(e)if(this._line?this._context.lineTo(t[0],n[0]):this._context.moveTo(t[0],n[0]),2===e)this._context.lineTo(t[1],n[1]);else for(var r=$c(t),i=$c(n),o=0,u=1;u<e;++o,++u)this._context.bezierCurveTo(r[0][o],i[0][o],r[1][o],i[1][o],t[u],n[u]);(this._line||0!==this._line&&1===e)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,n){this._x.push(+t),this._y.push(+n)}},Wc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,n),this._context.lineTo(t,n);else{var e=this._x*(1-this._t)+t*this._t;this._context.lineTo(e,this._y),this._context.lineTo(e,n)}}this._x=t,this._y=n}},rs.prototype={constructor:rs,insert:function(t,n){var e,r,i;if(t){if(n.P=t,n.N=t.N,t.N&&(t.N.P=n),t.N=n,t.R){for(t=t.R;t.L;)t=t.L;t.L=n}else t.R=n;e=t}else this._?(t=as(this._),n.P=null,n.N=t,t.P=t.L=n,e=t):(n.P=n.N=null,this._=n,e=null);for(n.L=n.R=null,n.U=e,n.C=!0,t=n;e&&e.C;)e===(r=e.U).L?(i=r.R)&&i.C?(e.C=i.C=!1,r.C=!0,t=r):(t===e.R&&(os(this,e),e=(t=e).U),e.C=!1,r.C=!0,us(this,r)):(i=r.L)&&i.C?(e.C=i.C=!1,r.C=!0,t=r):(t===e.L&&(us(this,e),e=(t=e).U),e.C=!1,r.C=!0,os(this,r)),e=t.U;this._.C=!1},remove:function(t){t.N&&(t.N.P=t.P),t.P&&(t.P.N=t.N),t.N=t.P=null;var n,e,r,i=t.U,o=t.L,u=t.R;if(e=o?u?as(u):o:u,i?i.L===t?i.L=e:i.R=e:this._=e,o&&u?(r=e.C,e.C=t.C,e.L=o,o.U=e,e!==u?(i=e.U,e.U=t.U,t=e.R,i.L=t,e.R=u,u.U=e):(e.U=i,i=e,t=e.R)):(r=t.C,t=e),t&&(t.U=i),!r)if(t&&t.C)t.C=!1;else{do{if(t===this._)break;if(t===i.L){if((n=i.R).C&&(n.C=!1,i.C=!0,os(this,i),n=i.R),n.L&&n.L.C||n.R&&n.R.C){n.R&&n.R.C||(n.L.C=!1,n.C=!0,us(this,n),n=i.R),n.C=i.C,i.C=n.R.C=!1,os(this,i),t=this._;break}}else if((n=i.L).C&&(n.C=!1,i.C=!0,us(this,i),n=i.L),n.L&&n.L.C||n.R&&n.R.C){n.L&&n.L.C||(n.R.C=!1,n.C=!0,os(this,n),n=i.L),n.C=i.C,i.C=n.L.C=!1,us(this,i),t=this._;break}n.C=!0,t=i,i=i.U}while(!t.C);t&&(t.C=!1)}}};var P_,R_,L_,q_,D_,U_=[],O_=[],F_=1e-6,I_=1e-12;Ns.prototype={constructor:Ns,polygons:function(){var t=this.edges;return this.cells.map(function(n){var e=n.halfedges.map(function(e){return ds(n,t[e])});return e.data=n.site.data,e})},triangles:function(){var t=[],n=this.edges;return this.cells.forEach(function(e,r){if(o=(i=e.halfedges).length)for(var i,o,u,a=e.site,c=-1,s=n[i[o-1]],f=s.left===a?s.right:s.left;++c<o;)u=f,f=(s=n[i[c]]).left===a?s.right:s.left,u&&f&&r<u.index&&r<f.index&&Ms(a,u,f)<0&&t.push([a.data,u.data,f.data])}),t},links:function(){return this.edges.filter(function(t){return t.right}).map(function(t){return{source:t.left.data,target:t.right.data}})},find:function(t,n,e){for(var r,i,o=this,u=o._found||0,a=o.cells.length;!(i=o.cells[u]);)if(++u>=a)return null;var c=t-i.site[0],s=n-i.site[1],f=c*c+s*s;do{i=o.cells[r=u],u=null,i.halfedges.forEach(function(e){var r=o.edges[e],a=r.left;if(a!==i.site&&a||(a=r.right)){var c=t-a[0],s=n-a[1],l=c*c+s*s;l<f&&(f=l,u=a.index)}})}while(null!==u);return o._found=r,null==e||f<=e*e?i.site:null}},Ss.prototype={constructor:Ss,scale:function(t){return 1===t?this:new Ss(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new Ss(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Y_=new Ss(1,0,0);Es.prototype=Ss.prototype,t.version="4.13.0",t.bisect=Os,t.bisectRight=Os,t.bisectLeft=Fs,t.ascending=n,t.bisector=e,t.cross=function(t,n,e){var i,o,u,a,c=t.length,s=n.length,f=new Array(c*s);for(null==e&&(e=r),i=u=0;i<c;++i)for(a=t[i],o=0;o<s;++o,++u)f[u]=e(a,n[o]);return f},t.descending=function(t,n){return n<t?-1:n>t?1:n>=t?0:NaN},t.deviation=u,t.extent=a,t.histogram=function(){function t(t){var i,o,u=t.length,a=new Array(u);for(i=0;i<u;++i)a[i]=n(t[i],i,t);var c=e(a),s=c[0],l=c[1],h=r(a,s,l);Array.isArray(h)||(h=p(s,l,h),h=f(Math.ceil(s/h)*h,Math.floor(l/h)*h,h));for(var d=h.length;h[0]<=s;)h.shift(),--d;for(;h[d-1]>l;)h.pop(),--d;var v,g=new Array(d+1);for(i=0;i<=d;++i)(v=g[i]=[]).x0=i>0?h[i-1]:s,v.x1=i<d?h[i]:l;for(i=0;i<u;++i)s<=(o=a[i])&&o<=l&&g[Os(h,o,0,d)].push(t[i]);return g}var n=s,e=a,r=d;return t.value=function(e){return arguments.length?(n="function"==typeof e?e:c(e),t):n},t.domain=function(n){return arguments.length?(e="function"==typeof n?n:c([n[0],n[1]]),t):e},t.thresholds=function(n){return arguments.length?(r="function"==typeof n?n:Array.isArray(n)?c(Ys.call(n)):c(n),t):r},t},t.thresholdFreedmanDiaconis=function(t,e,r){return t=Bs.call(t,i).sort(n),Math.ceil((r-e)/(2*(v(t,.75)-v(t,.25))*Math.pow(t.length,-1/3)))},t.thresholdScott=function(t,n,e){return Math.ceil((e-n)/(3.5*u(t)*Math.pow(t.length,-1/3)))},t.thresholdSturges=d,t.max=function(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&e>r&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&e>r&&(r=e);return r},t.mean=function(t,n){var e,r=t.length,o=r,u=-1,a=0;if(null==n)for(;++u<r;)isNaN(e=i(t[u]))?--o:a+=e;else for(;++u<r;)isNaN(e=i(n(t[u],u,t)))?--o:a+=e;if(o)return a/o},t.median=function(t,e){var r,o=t.length,u=-1,a=[];if(null==e)for(;++u<o;)isNaN(r=i(t[u]))||a.push(r);else for(;++u<o;)isNaN(r=i(e(t[u],u,t)))||a.push(r);return v(a.sort(n),.5)},t.merge=g,t.min=_,t.pairs=function(t,n){null==n&&(n=r);for(var e=0,i=t.length-1,o=t[0],u=new Array(i<0?0:i);e<i;)u[e]=n(o,o=t[++e]);return u},t.permute=function(t,n){for(var e=n.length,r=new Array(e);e--;)r[e]=t[n[e]];return r},t.quantile=v,t.range=f,t.scan=function(t,e){if(r=t.length){var r,i,o=0,u=0,a=t[u];for(null==e&&(e=n);++o<r;)(e(i=t[o],a)<0||0!==e(a,a))&&(a=i,u=o);return 0===e(a,a)?u:void 0}},t.shuffle=function(t,n,e){for(var r,i,o=(null==e?t.length:e)-(n=null==n?0:+n);o;)i=Math.random()*o--|0,r=t[o+n],t[o+n]=t[i+n],t[i+n]=r;return t},t.sum=function(t,n){var e,r=t.length,i=-1,o=0;if(null==n)for(;++i<r;)(e=+t[i])&&(o+=e);else for(;++i<r;)(e=+n(t[i],i,t))&&(o+=e);return o},t.ticks=l,t.tickIncrement=h,t.tickStep=p,t.transpose=y,t.variance=o,t.zip=function(){return y(arguments)},t.axisTop=function(t){return T($s,t)},t.axisRight=function(t){return T(Ws,t)},t.axisBottom=function(t){return T(Zs,t)},t.axisLeft=function(t){return T(Gs,t)},t.brush=function(){return Kn(oh)},t.brushX=function(){return Kn(rh)},t.brushY=function(){return Kn(ih)},t.brushSelection=function(t){var n=t.__brush;return n?n.dim.output(n.selection):null},t.chord=function(){function t(t){var o,u,a,c,s,l,h=t.length,p=[],d=f(h),v=[],g=[],_=g.groups=new Array(h),y=new Array(h*h);for(o=0,s=-1;++s<h;){for(u=0,l=-1;++l<h;)u+=t[s][l];p.push(u),v.push(f(h)),o+=u}for(e&&d.sort(function(t,n){return e(p[t],p[n])}),r&&v.forEach(function(n,e){n.sort(function(n,i){return r(t[e][n],t[e][i])})}),c=(o=gh(0,vh-n*h)/o)?n:vh/h,u=0,s=-1;++s<h;){for(a=u,l=-1;++l<h;){var m=d[s],x=v[m][l],b=t[m][x],w=u,M=u+=b*o;y[x*h+m]={index:m,subindex:x,startAngle:w,endAngle:M,value:b}}_[m]={index:m,startAngle:a,endAngle:u,value:p[m]},u+=c}for(s=-1;++s<h;)for(l=s-1;++l<h;){var T=y[l*h+s],N=y[s*h+l];(T.value||N.value)&&g.push(T.value<N.value?{source:N,target:T}:{source:T,target:N})}return i?g.sort(i):g}var n=0,e=null,r=null,i=null;return t.padAngle=function(e){return arguments.length?(n=gh(0,e),t):n},t.sortGroups=function(n){return arguments.length?(e=n,t):e},t.sortSubgroups=function(n){return arguments.length?(r=n,t):r},t.sortChords=function(n){return arguments.length?(null==n?i=null:(i=function(t){return function(n,e){return t(n.source.value+n.target.value,e.source.value+e.target.value)}}(n))._=n,t):i&&i._},t},t.ribbon=function(){function t(){var t,a=_h.call(arguments),c=n.apply(this,a),s=e.apply(this,a),f=+r.apply(this,(a[0]=c,a)),l=i.apply(this,a)-dh,h=o.apply(this,a)-dh,p=f*lh(l),d=f*hh(l),v=+r.apply(this,(a[0]=s,a)),g=i.apply(this,a)-dh,_=o.apply(this,a)-dh;if(u||(u=t=ee()),u.moveTo(p,d),u.arc(0,0,f,l,h),l===g&&h===_||(u.quadraticCurveTo(0,0,v*lh(g),v*hh(g)),u.arc(0,0,v,g,_)),u.quadraticCurveTo(0,0,p,d),u.closePath(),t)return u=null,t+""||null}var n=re,e=ie,r=oe,i=ue,o=ae,u=null;return t.radius=function(n){return arguments.length?(r="function"==typeof n?n:te(+n),t):r},t.startAngle=function(n){return arguments.length?(i="function"==typeof n?n:te(+n),t):i},t.endAngle=function(n){return arguments.length?(o="function"==typeof n?n:te(+n),t):o},t.source=function(e){return arguments.length?(n=e,t):n},t.target=function(n){return arguments.length?(e=n,t):e},t.context=function(n){return arguments.length?(u=null==n?null:n,t):u},t},t.nest=function(){function t(n,i,u,a){if(i>=o.length)return null!=e&&n.sort(e),null!=r?r(n):n;for(var c,s,f,l=-1,h=n.length,p=o[i++],d=se(),v=u();++l<h;)(f=d.get(c=p(s=n[l])+""))?f.push(s):d.set(c,[s]);return d.each(function(n,e){a(v,e,t(n,i,u,a))}),v}function n(t,e){if(++e>o.length)return t;var i,a=u[e-1];return null!=r&&e>=o.length?i=t.entries():(i=[],t.each(function(t,r){i.push({key:r,values:n(t,e)})})),null!=a?i.sort(function(t,n){return a(t.key,n.key)}):i}var e,r,i,o=[],u=[];return i={object:function(n){return t(n,0,fe,le)},map:function(n){return t(n,0,he,pe)},entries:function(e){return n(t(e,0,he,pe),0)},key:function(t){return o.push(t),i},sortKeys:function(t){return u[o.length-1]=t,i},sortValues:function(t){return e=t,i},rollup:function(t){return r=t,i}}},t.set=ve,t.map=se,t.keys=function(t){var n=[];for(var e in t)n.push(e);return n},t.values=function(t){var n=[];for(var e in t)n.push(t[e]);return n},t.entries=function(t){var n=[];for(var e in t)n.push({key:e,value:t[e]});return n},t.color=Et,t.rgb=Pt,t.hsl=qt,t.lab=Ft,t.hcl=Xt,t.cubehelix=$t,t.dispatch=N,t.drag=function(){function n(t){t.on("mousedown.drag",e).filter(g).on("touchstart.drag",o).on("touchmove.drag",u).on("touchend.drag touchcancel.drag",a).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function e(){if(!h&&p.apply(this,arguments)){var n=c("mouse",d.apply(this,arguments),pt,this,arguments);n&&(ct(t.event.view).on("mousemove.drag",r,!0).on("mouseup.drag",i,!0),_t(t.event.view),vt(),l=!1,s=t.event.clientX,f=t.event.clientY,n("start"))}}function r(){if(gt(),!l){var n=t.event.clientX-s,e=t.event.clientY-f;l=n*n+e*e>x}_.mouse("drag")}function i(){ct(t.event.view).on("mousemove.drag mouseup.drag",null),yt(t.event.view,l),gt(),_.mouse("end")}function o(){if(p.apply(this,arguments)){var n,e,r=t.event.changedTouches,i=d.apply(this,arguments),o=r.length;for(n=0;n<o;++n)(e=c(r[n].identifier,i,dt,this,arguments))&&(vt(),e("start"))}}function u(){var n,e,r=t.event.changedTouches,i=r.length;for(n=0;n<i;++n)(e=_[r[n].identifier])&&(gt(),e("drag"))}function a(){var n,e,r=t.event.changedTouches,i=r.length;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),n=0;n<i;++n)(e=_[r[n].identifier])&&(vt(),e("end"))}function c(e,r,i,o,u){var a,c,s,f=i(r,e),l=y.copy();if(it(new xt(n,"beforestart",a,e,m,f[0],f[1],0,0,l),function(){return null!=(t.event.subject=a=v.apply(o,u))&&(c=a.x-f[0]||0,s=a.y-f[1]||0,!0)}))return function t(h){var p,d=f;switch(h){case"start":_[e]=t,p=m++;break;case"end":delete _[e],--m;case"drag":f=i(r,e),p=m}it(new xt(n,h,a,e,p,f[0]+c,f[1]+s,f[0]-d[0],f[1]-d[1],l),l.apply,l,[h,o,u])}}var s,f,l,h,p=bt,d=wt,v=Mt,g=Tt,_={},y=N("start","drag","end"),m=0,x=0;return n.filter=function(t){return arguments.length?(p="function"==typeof t?t:mt(!!t),n):p},n.container=function(t){return arguments.length?(d="function"==typeof t?t:mt(t),n):d},n.subject=function(t){return arguments.length?(v="function"==typeof t?t:mt(t),n):v},n.touchable=function(t){return arguments.length?(g="function"==typeof t?t:mt(!!t),n):g},n.on=function(){var t=y.on.apply(y,arguments);return t===y?n:t},n.clickDistance=function(t){return arguments.length?(x=(t=+t)*t,n):Math.sqrt(x)},n},t.dragDisable=_t,t.dragEnable=yt,t.dsvFormat=_e,t.csvParse=Eh,t.csvParseRows=Ah,t.csvFormat=Ch,t.csvFormatRows=zh,t.tsvParse=Rh,t.tsvParseRows=Lh,t.tsvFormat=qh,t.tsvFormatRows=Dh,t.easeLinear=function(t){return+t},t.easeQuad=On,t.easeQuadIn=function(t){return t*t},t.easeQuadOut=function(t){return t*(2-t)},t.easeQuadInOut=On,t.easeCubic=Fn,t.easeCubicIn=function(t){return t*t*t},t.easeCubicOut=function(t){return--t*t*t+1},t.easeCubicInOut=Fn,t.easePoly=zl,t.easePolyIn=Al,t.easePolyOut=Cl,t.easePolyInOut=zl,t.easeSin=In,t.easeSinIn=function(t){return 1-Math.cos(t*Rl)},t.easeSinOut=function(t){return Math.sin(t*Rl)},t.easeSinInOut=In,t.easeExp=Yn,t.easeExpIn=function(t){return Math.pow(2,10*t-10)},t.easeExpOut=function(t){return 1-Math.pow(2,-10*t)},t.easeExpInOut=Yn,t.easeCircle=Bn,t.easeCircleIn=function(t){return 1-Math.sqrt(1-t*t)},t.easeCircleOut=function(t){return Math.sqrt(1- --t*t)},t.easeCircleInOut=Bn,t.easeBounce=Hn,t.easeBounceIn=function(t){return 1-Hn(1-t)},t.easeBounceOut=Hn,t.easeBounceInOut=function(t){return((t*=2)<=1?1-Hn(1-t):Hn(t-1)+1)/2},t.easeBack=Vl,t.easeBackIn=jl,t.easeBackOut=Xl,t.easeBackInOut=Vl,t.easeElastic=Zl,t.easeElasticIn=Wl,t.easeElasticOut=Zl,t.easeElasticInOut=Gl,t.forceCenter=function(t,n){function e(){var e,i,o=r.length,u=0,a=0;for(e=0;e<o;++e)u+=(i=r[e]).x,a+=i.y;for(u=u/o-t,a=a/o-n,e=0;e<o;++e)(i=r[e]).x-=u,i.y-=a}var r;return null==t&&(t=0),null==n&&(n=0),e.initialize=function(t){r=t},e.x=function(n){return arguments.length?(t=+n,e):t},e.y=function(t){return arguments.length?(n=+t,e):n},e},t.forceCollide=function(t){function n(){for(var t,n,r,c,s,f,l,h=i.length,p=0;p<a;++p)for(n=Te(i,Se,Ee).visitAfter(e),t=0;t<h;++t)r=i[t],f=o[r.index],l=f*f,c=r.x+r.vx,s=r.y+r.vy,n.visit(function(t,n,e,i,o){var a=t.data,h=t.r,p=f+h;if(!a)return n>c+p||i<c-p||e>s+p||o<s-p;if(a.index>r.index){var d=c-a.x-a.vx,v=s-a.y-a.vy,g=d*d+v*v;g<p*p&&(0===d&&(d=me(),g+=d*d),0===v&&(v=me(),g+=v*v),g=(p-(g=Math.sqrt(g)))/g*u,r.vx+=(d*=g)*(p=(h*=h)/(l+h)),r.vy+=(v*=g)*p,a.vx-=d*(p=1-p),a.vy-=v*p)}})}function e(t){if(t.data)return t.r=o[t.data.index];for(var n=t.r=0;n<4;++n)t[n]&&t[n].r>t.r&&(t.r=t[n].r)}function r(){if(i){var n,e,r=i.length;for(o=new Array(r),n=0;n<r;++n)e=i[n],o[e.index]=+t(e,n,i)}}var i,o,u=1,a=1;return"function"!=typeof t&&(t=ye(null==t?1:+t)),n.initialize=function(t){i=t,r()},n.iterations=function(t){return arguments.length?(a=+t,n):a},n.strength=function(t){return arguments.length?(u=+t,n):u},n.radius=function(e){return arguments.length?(t="function"==typeof e?e:ye(+e),r(),n):t},n},t.forceLink=function(t){function n(n){for(var e=0,r=t.length;e<p;++e)for(var i,a,c,f,l,h,d,v=0;v<r;++v)a=(i=t[v]).source,f=(c=i.target).x+c.vx-a.x-a.vx||me(),l=c.y+c.vy-a.y-a.vy||me(),f*=h=((h=Math.sqrt(f*f+l*l))-u[v])/h*n*o[v],l*=h,c.vx-=f*(d=s[v]),c.vy-=l*d,a.vx+=f*(d=1-d),a.vy+=l*d}function e(){if(a){var n,e,l=a.length,h=t.length,p=se(a,f);for(n=0,c=new Array(l);n<h;++n)(e=t[n]).index=n,"object"!=typeof e.source&&(e.source=Ce(p,e.source)),"object"!=typeof e.target&&(e.target=Ce(p,e.target)),c[e.source.index]=(c[e.source.index]||0)+1,c[e.target.index]=(c[e.target.index]||0)+1;for(n=0,s=new Array(h);n<h;++n)e=t[n],s[n]=c[e.source.index]/(c[e.source.index]+c[e.target.index]);o=new Array(h),r(),u=new Array(h),i()}}function r(){if(a)for(var n=0,e=t.length;n<e;++n)o[n]=+l(t[n],n,t)}function i(){if(a)for(var n=0,e=t.length;n<e;++n)u[n]=+h(t[n],n,t)}var o,u,a,c,s,f=Ae,l=function(t){return 1/Math.min(c[t.source.index],c[t.target.index])},h=ye(30),p=1;return null==t&&(t=[]),n.initialize=function(t){a=t,e()},n.links=function(r){return arguments.length?(t=r,e(),n):t},n.id=function(t){return arguments.length?(f=t,n):f},n.iterations=function(t){return arguments.length?(p=+t,n):p},n.strength=function(t){return arguments.length?(l="function"==typeof t?t:ye(+t),r(),n):l},n.distance=function(t){return arguments.length?(h="function"==typeof t?t:ye(+t),i(),n):h},n},t.forceManyBody=function(){function t(t){var n,a=i.length,c=Te(i,ze,Pe).visitAfter(e);for(u=t,n=0;n<a;++n)o=i[n],c.visit(r)}function n(){if(i){var t,n,e=i.length;for(a=new Array(e),t=0;t<e;++t)n=i[t],a[n.index]=+c(n,t,i)}}function e(t){var n,e,r,i,o,u=0,c=0;if(t.length){for(r=i=o=0;o<4;++o)(n=t[o])&&(e=Math.abs(n.value))&&(u+=n.value,c+=e,r+=e*n.x,i+=e*n.y);t.x=r/c,t.y=i/c}else{(n=t).x=n.data.x,n.y=n.data.y;do{u+=a[n.data.index]}while(n=n.next)}t.value=u}function r(t,n,e,r){if(!t.value)return!0;var i=t.x-o.x,c=t.y-o.y,h=r-n,p=i*i+c*c;if(h*h/l<p)return p<f&&(0===i&&(i=me(),p+=i*i),0===c&&(c=me(),p+=c*c),p<s&&(p=Math.sqrt(s*p)),o.vx+=i*t.value*u/p,o.vy+=c*t.value*u/p),!0;if(!(t.length||p>=f)){(t.data!==o||t.next)&&(0===i&&(i=me(),p+=i*i),0===c&&(c=me(),p+=c*c),p<s&&(p=Math.sqrt(s*p)));do{t.data!==o&&(h=a[t.data.index]*u/p,o.vx+=i*h,o.vy+=c*h)}while(t=t.next)}}var i,o,u,a,c=ye(-30),s=1,f=1/0,l=.81;return t.initialize=function(t){i=t,n()},t.strength=function(e){return arguments.length?(c="function"==typeof e?e:ye(+e),n(),t):c},t.distanceMin=function(n){return arguments.length?(s=n*n,t):Math.sqrt(s)},t.distanceMax=function(n){return arguments.length?(f=n*n,t):Math.sqrt(f)},t.theta=function(n){return arguments.length?(l=n*n,t):Math.sqrt(l)},t},t.forceRadial=function(t,n,e){function r(t){for(var r=0,i=o.length;r<i;++r){var c=o[r],s=c.x-n||1e-6,f=c.y-e||1e-6,l=Math.sqrt(s*s+f*f),h=(a[r]-l)*u[r]*t/l;c.vx+=s*h,c.vy+=f*h}}function i(){if(o){var n,e=o.length;for(u=new Array(e),a=new Array(e),n=0;n<e;++n)a[n]=+t(o[n],n,o),u[n]=isNaN(a[n])?0:+c(o[n],n,o)}}var o,u,a,c=ye(.1);return"function"!=typeof t&&(t=ye(+t)),null==n&&(n=0),null==e&&(e=0),r.initialize=function(t){o=t,i()},r.strength=function(t){return arguments.length?(c="function"==typeof t?t:ye(+t),i(),r):c},r.radius=function(n){return arguments.length?(t="function"==typeof n?n:ye(+n),i(),r):t},r.x=function(t){return arguments.length?(n=+t,r):n},r.y=function(t){return arguments.length?(e=+t,r):e},r},t.forceSimulation=function(t){function n(){e(),p.call("tick",o),u<a&&(h.stop(),p.call("end",o))}function e(){var n,e,r=t.length;for(u+=(s-u)*c,l.each(function(t){t(u)}),n=0;n<r;++n)null==(e=t[n]).fx?e.x+=e.vx*=f:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=f:(e.y=e.fy,e.vy=0)}function r(){for(var n,e=0,r=t.length;e<r;++e){if(n=t[e],n.index=e,isNaN(n.x)||isNaN(n.y)){var i=Fh*Math.sqrt(e),o=e*Ih;n.x=i*Math.cos(o),n.y=i*Math.sin(o)}(isNaN(n.vx)||isNaN(n.vy))&&(n.vx=n.vy=0)}}function i(n){return n.initialize&&n.initialize(t),n}var o,u=1,a=.001,c=1-Math.pow(a,1/300),s=0,f=.6,l=se(),h=wn(n),p=N("tick","end");return null==t&&(t=[]),r(),o={tick:e,restart:function(){return h.restart(n),o},stop:function(){return h.stop(),o},nodes:function(n){return arguments.length?(t=n,r(),l.each(i),o):t},alpha:function(t){return arguments.length?(u=+t,o):u},alphaMin:function(t){return arguments.length?(a=+t,o):a},alphaDecay:function(t){return arguments.length?(c=+t,o):+c},alphaTarget:function(t){return arguments.length?(s=+t,o):s},velocityDecay:function(t){return arguments.length?(f=1-t,o):1-f},force:function(t,n){return arguments.length>1?(null==n?l.remove(t):l.set(t,i(n)),o):l.get(t)},find:function(n,e,r){var i,o,u,a,c,s=0,f=t.length;for(null==r?r=1/0:r*=r,s=0;s<f;++s)(u=(i=n-(a=t[s]).x)*i+(o=e-a.y)*o)<r&&(c=a,r=u);return c},on:function(t,n){return arguments.length>1?(p.on(t,n),o):p.on(t)}}},t.forceX=function(t){function n(t){for(var n,e=0,u=r.length;e<u;++e)(n=r[e]).vx+=(o[e]-n.x)*i[e]*t}function e(){if(r){var n,e=r.length;for(i=new Array(e),o=new Array(e),n=0;n<e;++n)i[n]=isNaN(o[n]=+t(r[n],n,r))?0:+u(r[n],n,r)}}var r,i,o,u=ye(.1);return"function"!=typeof t&&(t=ye(null==t?0:+t)),n.initialize=function(t){r=t,e()},n.strength=function(t){return arguments.length?(u="function"==typeof t?t:ye(+t),e(),n):u},n.x=function(r){return arguments.length?(t="function"==typeof r?r:ye(+r),e(),n):t},n},t.forceY=function(t){function n(t){for(var n,e=0,u=r.length;e<u;++e)(n=r[e]).vy+=(o[e]-n.y)*i[e]*t}function e(){if(r){var n,e=r.length;for(i=new Array(e),o=new Array(e),n=0;n<e;++n)i[n]=isNaN(o[n]=+t(r[n],n,r))?0:+u(r[n],n,r)}}var r,i,o,u=ye(.1);return"function"!=typeof t&&(t=ye(null==t?0:+t)),n.initialize=function(t){r=t,e()},n.strength=function(t){return arguments.length?(u="function"==typeof t?t:ye(+t),e(),n):u},n.y=function(r){return arguments.length?(t="function"==typeof r?r:ye(+r),e(),n):t},n},t.formatDefaultLocale=Ie,t.formatLocale=Fe,t.formatSpecifier=De,t.precisionFixed=Ye,t.precisionPrefix=Be,t.precisionRound=He,t.geoArea=function(t){return Vp.reset(),tr(t,$p),2*Vp},t.geoBounds=function(t){var n,e,r,i,o,u,a;if(Kh=Jh=-(Gh=Qh=1/0),ip=[],tr(t,Zp),e=ip.length){for(ip.sort(xr),n=1,o=[r=ip[0]];n<e;++n)br(r,(i=ip[n])[0])||br(r,i[1])?(mr(r[0],i[1])>mr(r[0],r[1])&&(r[1]=i[1]),mr(i[0],r[1])>mr(r[0],r[1])&&(r[0]=i[0])):o.push(r=i);for(u=-1/0,n=0,r=o[e=o.length-1];n<=e;r=i,++n)i=o[n],(a=mr(r[1],i[0]))>u&&(u=a,Gh=i[0],Jh=r[1])}return ip=op=null,Gh===1/0||Qh===1/0?[[NaN,NaN],[NaN,NaN]]:[[Gh,Qh],[Jh,Kh]]},t.geoCentroid=function(t){up=ap=cp=sp=fp=lp=hp=pp=dp=vp=gp=0,tr(t,Gp);var n=dp,e=vp,r=gp,i=n*n+e*e+r*r;return i<Tp&&(n=lp,e=hp,r=pp,ap<Mp&&(n=cp,e=sp,r=fp),(i=n*n+e*e+r*r)<Tp)?[NaN,NaN]:[Rp(e,n)*Ap,We(r/Yp(i))*Ap]},t.geoCircle=function(){function t(){var t=r.apply(this,arguments),a=i.apply(this,arguments)*Cp,c=o.apply(this,arguments)*Cp;return n=[],e=qr(-t[0]*Cp,-t[1]*Cp,0).invert,Ir(u,a,c,1),t={type:"Polygon",coordinates:[n]},n=e=null,t}var n,e,r=Pr([0,0]),i=Pr(90),o=Pr(6),u={point:function(t,r){n.push(t=e(t,r)),t[0]*=Ap,t[1]*=Ap}};return t.center=function(n){return arguments.length?(r="function"==typeof n?n:Pr([+n[0],+n[1]]),t):r},t.radius=function(n){return arguments.length?(i="function"==typeof n?n:Pr(+n),t):i},t.precision=function(n){return arguments.length?(o="function"==typeof n?n:Pr(+n),t):o},t},t.geoClipAntimeridian=sd,t.geoClipCircle=Qr,t.geoClipExtent=function(){var t,n,e,r=0,i=0,o=960,u=500;return e={stream:function(e){return t&&n===e?t:t=Jr(r,i,o,u)(n=e)},extent:function(a){return arguments.length?(r=+a[0][0],i=+a[0][1],o=+a[1][0],u=+a[1][1],t=n=null,e):[[r,i],[o,u]]}}},t.geoClipRectangle=Jr,t.geoContains=function(t,n){return(t&&gd.hasOwnProperty(t.type)?gd[t.type]:ii)(t,n)},t.geoDistance=ri,t.geoGraticule=hi,t.geoGraticule10=function(){return hi()()},t.geoInterpolate=function(t,n){var e=t[0]*Cp,r=t[1]*Cp,i=n[0]*Cp,o=n[1]*Cp,u=Lp(r),a=Fp(r),c=Lp(o),s=Fp(o),f=u*Lp(e),l=u*Fp(e),h=c*Lp(i),p=c*Fp(i),d=2*We(Yp(Ze(o-r)+u*c*Ze(i-e))),v=Fp(d),g=d?function(t){var n=Fp(t*=d)/v,e=Fp(d-t)/v,r=e*f+n*h,i=e*l+n*p,o=e*a+n*s;return[Rp(i,r)*Ap,Rp(o,Yp(r*r+i*i))*Ap]}:function(){return[e*Ap,r*Ap]};return g.distance=d,g},t.geoLength=ei,t.geoPath=function(t,n){function e(t){return t&&("function"==typeof o&&i.pointRadius(+o.apply(this,arguments)),tr(t,r(i))),i.result()}var r,i,o=4.5;return e.area=function(t){return tr(t,r(xd)),xd.result()},e.measure=function(t){return tr(t,r(Bd)),Bd.result()},e.bounds=function(t){return tr(t,r(Nd)),Nd.result()},e.centroid=function(t){return tr(t,r(qd)),qd.result()},e.projection=function(n){return arguments.length?(r=null==n?(t=null,pi):(t=n).stream,e):t},e.context=function(t){return arguments.length?(i=null==t?(n=null,new Ci):new Si(n=t),"function"!=typeof o&&i.pointRadius(o),e):n},e.pointRadius=function(t){return arguments.length?(o="function"==typeof t?t:(i.pointRadius(+t),+t),e):o},e.projection(t).context(n)},t.geoAlbers=Xi,t.geoAlbersUsa=function(){function t(t){var n=t[0],e=t[1];return a=null,i.point(n,e),a||(o.point(n,e),a)||(u.point(n,e),a)}function n(){return e=r=null,t}var e,r,i,o,u,a,c=Xi(),s=ji().rotate([154,0]).center([-2,58.5]).parallels([55,65]),f=ji().rotate([157,0]).center([-3,19.9]).parallels([8,18]),l={point:function(t,n){a=[t,n]}};return t.invert=function(t){var n=c.scale(),e=c.translate(),r=(t[0]-e[0])/n,i=(t[1]-e[1])/n;return(i>=.12&&i<.234&&r>=-.425&&r<-.214?s:i>=.166&&i<.234&&r>=-.214&&r<-.115?f:c).invert(t)},t.stream=function(t){return e&&r===t?e:e=function(t){var n=t.length;return{point:function(e,r){for(var i=-1;++i<n;)t[i].point(e,r)},sphere:function(){for(var e=-1;++e<n;)t[e].sphere()},lineStart:function(){for(var e=-1;++e<n;)t[e].lineStart()},lineEnd:function(){for(var e=-1;++e<n;)t[e].lineEnd()},polygonStart:function(){for(var e=-1;++e<n;)t[e].polygonStart()},polygonEnd:function(){for(var e=-1;++e<n;)t[e].polygonEnd()}}}([c.stream(r=t),s.stream(t),f.stream(t)])},t.precision=function(t){return arguments.length?(c.precision(t),s.precision(t),f.precision(t),n()):c.precision()},t.scale=function(n){return arguments.length?(c.scale(n),s.scale(.35*n),f.scale(n),t.translate(c.translate())):c.scale()},t.translate=function(t){if(!arguments.length)return c.translate();var e=c.scale(),r=+t[0],a=+t[1];return i=c.translate(t).clipExtent([[r-.455*e,a-.238*e],[r+.455*e,a+.238*e]]).stream(l),o=s.translate([r-.307*e,a+.201*e]).clipExtent([[r-.425*e+Mp,a+.12*e+Mp],[r-.214*e-Mp,a+.234*e-Mp]]).stream(l),u=f.translate([r-.205*e,a+.212*e]).clipExtent([[r-.214*e+Mp,a+.166*e+Mp],[r-.115*e-Mp,a+.234*e-Mp]]).stream(l),n()},t.fitExtent=function(n,e){return qi(t,n,e)},t.fitSize=function(n,e){return Di(t,n,e)},t.fitWidth=function(n,e){return Ui(t,n,e)},t.fitHeight=function(n,e){return Oi(t,n,e)},t.scale(1070)},t.geoAzimuthalEqualArea=function(){return Ii(Vd).scale(124.75).clipAngle(179.999)},t.geoAzimuthalEqualAreaRaw=Vd,t.geoAzimuthalEquidistant=function(){return Ii($d).scale(79.4188).clipAngle(179.999)},t.geoAzimuthalEquidistantRaw=$d,t.geoConicConformal=function(){return Bi(Qi).scale(109.5).parallels([30,30])},t.geoConicConformalRaw=Qi,t.geoConicEqualArea=ji,t.geoConicEqualAreaRaw=Hi,t.geoConicEquidistant=function(){return Bi(Ki).scale(131.154).center([0,13.9389])},t.geoConicEquidistantRaw=Ki,t.geoEquirectangular=function(){return Ii(Ji).scale(152.63)},t.geoEquirectangularRaw=Ji,t.geoGnomonic=function(){return Ii(to).scale(144.049).clipAngle(60)},t.geoGnomonicRaw=to,t.geoIdentity=function(){function t(){return i=o=null,u}var n,e,r,i,o,u,a=1,c=0,s=0,f=1,l=1,h=pi,p=null,d=pi;return u={stream:function(t){return i&&o===t?i:i=h(d(o=t))},postclip:function(i){return arguments.length?(d=i,p=n=e=r=null,t()):d},clipExtent:function(i){return arguments.length?(d=null==i?(p=n=e=r=null,pi):Jr(p=+i[0][0],n=+i[0][1],e=+i[1][0],r=+i[1][1]),t()):null==p?null:[[p,n],[e,r]]},scale:function(n){return arguments.length?(h=no((a=+n)*f,a*l,c,s),t()):a},translate:function(n){return arguments.length?(h=no(a*f,a*l,c=+n[0],s=+n[1]),t()):[c,s]},reflectX:function(n){return arguments.length?(h=no(a*(f=n?-1:1),a*l,c,s),t()):f<0},reflectY:function(n){return arguments.length?(h=no(a*f,a*(l=n?-1:1),c,s),t()):l<0},fitExtent:function(t,n){return qi(u,t,n)},fitSize:function(t,n){return Di(u,t,n)},fitWidth:function(t,n){return Ui(u,t,n)},fitHeight:function(t,n){return Oi(u,t,n)}}},t.geoProjection=Ii,t.geoProjectionMutator=Yi,t.geoMercator=function(){return Zi(Wi).scale(961/Ep)},t.geoMercatorRaw=Wi,t.geoNaturalEarth1=function(){return Ii(eo).scale(175.295)},t.geoNaturalEarth1Raw=eo,t.geoOrthographic=function(){return Ii(ro).scale(249.5).clipAngle(90+Mp)},t.geoOrthographicRaw=ro,t.geoStereographic=function(){return Ii(io).scale(250).clipAngle(142)},t.geoStereographicRaw=io,t.geoTransverseMercator=function(){var t=Zi(oo),n=t.center,e=t.rotate;return t.center=function(t){return arguments.length?n([-t[1],t[0]]):(t=n(),[t[1],-t[0]])},t.rotate=function(t){return arguments.length?e([t[0],t[1],t.length>2?t[2]+90:90]):(t=e(),[t[0],t[1],t[2]-90])},e([0,0,90]).scale(159.155)},t.geoTransverseMercatorRaw=oo,t.geoRotation=Fr,t.geoStream=tr,t.geoTransform=function(t){return{stream:Pi(t)}},t.cluster=function(){function t(t){var o,u=0;t.eachAfter(function(t){var e=t.children;e?(t.x=function(t){return t.reduce(ao,0)/t.length}(e),t.y=function(t){return 1+t.reduce(co,0)}(e)):(t.x=o?u+=n(t,o):0,t.y=0,o=t)});var a=function(t){for(var n;n=t.children;)t=n[0];return t}(t),c=function(t){for(var n;n=t.children;)t=n[n.length-1];return t}(t),s=a.x-n(a,c)/2,f=c.x+n(c,a)/2;return t.eachAfter(i?function(n){n.x=(n.x-t.x)*e,n.y=(t.y-n.y)*r}:function(n){n.x=(n.x-s)/(f-s)*e,n.y=(1-(t.y?n.y/t.y:1))*r})}var n=uo,e=1,r=1,i=!1;return t.separation=function(e){return arguments.length?(n=e,t):n},t.size=function(n){return arguments.length?(i=!1,e=+n[0],r=+n[1],t):i?null:[e,r]},t.nodeSize=function(n){return arguments.length?(i=!0,e=+n[0],r=+n[1],t):i?[e,r]:null},t},t.hierarchy=fo,t.pack=function(){function t(t){return t.x=e/2,t.y=r/2,n?t.eachBefore(zo(n)).eachAfter(Po(i,.5)).eachBefore(Ro(1)):t.eachBefore(zo(Co)).eachAfter(Po(Eo,1)).eachAfter(Po(i,t.r/Math.min(e,r))).eachBefore(Ro(Math.min(e,r)/(2*t.r))),t}var n=null,e=1,r=1,i=Eo;return t.radius=function(e){return arguments.length?(n=function(t){return null==t?null:So(t)}(e),t):n},t.size=function(n){return arguments.length?(e=+n[0],r=+n[1],t):[e,r]},t.padding=function(n){return arguments.length?(i="function"==typeof n?n:Ao(+n),t):i},t},t.packSiblings=function(t){return ko(t),t},t.packEnclose=go,t.partition=function(){function t(t){var o=t.height+1;return t.x0=t.y0=r,t.x1=n,t.y1=e/o,t.eachBefore(function(t,n){return function(e){e.children&&qo(e,e.x0,t*(e.depth+1)/n,e.x1,t*(e.depth+2)/n);var i=e.x0,o=e.y0,u=e.x1-r,a=e.y1-r;u<i&&(i=u=(i+u)/2),a<o&&(o=a=(o+a)/2),e.x0=i,e.y0=o,e.x1=u,e.y1=a}}(e,o)),i&&t.eachBefore(Lo),t}var n=1,e=1,r=0,i=!1;return t.round=function(n){return arguments.length?(i=!!n,t):i},t.size=function(r){return arguments.length?(n=+r[0],e=+r[1],t):[n,e]},t.padding=function(n){return arguments.length?(r=+n,t):r},t},t.stratify=function(){function t(t){var r,i,o,u,a,c,s,f=t.length,l=new Array(f),h={};for(i=0;i<f;++i)r=t[i],a=l[i]=new vo(r),null!=(c=n(r,i,t))&&(c+="")&&(h[s=Zd+(a.id=c)]=s in h?Qd:a);for(i=0;i<f;++i)if(a=l[i],null!=(c=e(t[i],i,t))&&(c+="")){if(!(u=h[Zd+c]))throw new Error("missing: "+c);if(u===Qd)throw new Error("ambiguous: "+c);u.children?u.children.push(a):u.children=[a],a.parent=u}else{if(o)throw new Error("multiple roots");o=a}if(!o)throw new Error("no root");if(o.parent=Gd,o.eachBefore(function(t){t.depth=t.parent.depth+1,--f}).eachBefore(po),o.parent=null,f>0)throw new Error("cycle");return o}var n=Do,e=Uo;return t.id=function(e){return arguments.length?(n=So(e),t):n},t.parentId=function(n){return arguments.length?(e=So(n),t):e},t},t.tree=function(){function t(t){var c=function(t){for(var n,e,r,i,o,u=new Ho(t,0),a=[u];n=a.pop();)if(r=n._.children)for(n.children=new Array(o=r.length),i=o-1;i>=0;--i)a.push(e=n.children[i]=new Ho(r[i],i)),e.parent=n;return(u.parent=new Ho(null,0)).children=[u],u}(t);if(c.eachAfter(n),c.parent.m=-c.z,c.eachBefore(e),a)t.eachBefore(r);else{var s=t,f=t,l=t;t.eachBefore(function(t){t.x<s.x&&(s=t),t.x>f.x&&(f=t),t.depth>l.depth&&(l=t)});var h=s===f?1:i(s,f)/2,p=h-s.x,d=o/(f.x+h+p),v=u/(l.depth||1);t.eachBefore(function(t){t.x=(t.x+p)*d,t.y=t.depth*v})}return t}function n(t){var n=t.children,e=t.parent.children,r=t.i?e[t.i-1]:null;if(n){(function(t){for(var n,e=0,r=0,i=t.children,o=i.length;--o>=0;)(n=i[o]).z+=e,n.m+=e,e+=n.s+(r+=n.c)})(t);var o=(n[0].z+n[n.length-1].z)/2;r?(t.z=r.z+i(t._,r._),t.m=t.z-o):t.z=o}else r&&(t.z=r.z+i(t._,r._));t.parent.A=function(t,n,e){if(n){for(var r,o=t,u=t,a=n,c=o.parent.children[0],s=o.m,f=u.m,l=a.m,h=c.m;a=Io(a),o=Fo(o),a&&o;)c=Fo(c),(u=Io(u)).a=t,(r=a.z+l-o.z-s+i(a._,o._))>0&&(Yo(Bo(a,t,e),t,r),s+=r,f+=r),l+=a.m,s+=o.m,h+=c.m,f+=u.m;a&&!Io(u)&&(u.t=a,u.m+=l-f),o&&!Fo(c)&&(c.t=o,c.m+=s-h,e=t)}return e}(t,r,t.parent.A||e[0])}function e(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function r(t){t.x*=o,t.y=t.depth*u}var i=Oo,o=1,u=1,a=null;return t.separation=function(n){return arguments.length?(i=n,t):i},t.size=function(n){return arguments.length?(a=!1,o=+n[0],u=+n[1],t):a?null:[o,u]},t.nodeSize=function(n){return arguments.length?(a=!0,o=+n[0],u=+n[1],t):a?[o,u]:null},t},t.treemap=function(){function t(t){return t.x0=t.y0=0,t.x1=i,t.y1=o,t.eachBefore(n),u=[0],r&&t.eachBefore(Lo),t}function n(t){var n=u[t.depth],r=t.x0+n,i=t.y0+n,o=t.x1-n,h=t.y1-n;o<r&&(r=o=(r+o)/2),h<i&&(i=h=(i+h)/2),t.x0=r,t.y0=i,t.x1=o,t.y1=h,t.children&&(n=u[t.depth+1]=a(t)/2,r+=l(t)-n,i+=c(t)-n,o-=s(t)-n,h-=f(t)-n,o<r&&(r=o=(r+o)/2),h<i&&(i=h=(i+h)/2),e(t,r,i,o,h))}var e=Kd,r=!1,i=1,o=1,u=[0],a=Eo,c=Eo,s=Eo,f=Eo,l=Eo;return t.round=function(n){return arguments.length?(r=!!n,t):r},t.size=function(n){return arguments.length?(i=+n[0],o=+n[1],t):[i,o]},t.tile=function(n){return arguments.length?(e=So(n),t):e},t.padding=function(n){return arguments.length?t.paddingInner(n).paddingOuter(n):t.paddingInner()},t.paddingInner=function(n){return arguments.length?(a="function"==typeof n?n:Ao(+n),t):a},t.paddingOuter=function(n){return arguments.length?t.paddingTop(n).paddingRight(n).paddingBottom(n).paddingLeft(n):t.paddingTop()},t.paddingTop=function(n){return arguments.length?(c="function"==typeof n?n:Ao(+n),t):c},t.paddingRight=function(n){return arguments.length?(s="function"==typeof n?n:Ao(+n),t):s},t.paddingBottom=function(n){return arguments.length?(f="function"==typeof n?n:Ao(+n),t):f},t.paddingLeft=function(n){return arguments.length?(l="function"==typeof n?n:Ao(+n),t):l},t},t.treemapBinary=function(t,n,e,r,i){function o(t,n,e,r,i,u,a){if(t>=n-1){var s=c[t];return s.x0=r,s.y0=i,s.x1=u,void(s.y1=a)}for(var l=f[t],h=e/2+l,p=t+1,d=n-1;p<d;){var v=p+d>>>1;f[v]<h?p=v+1:d=v}h-f[p-1]<f[p]-h&&t+1<p&&--p;var g=f[p]-l,_=e-g;if(u-r>a-i){var y=(r*_+u*g)/e;o(t,p,g,r,i,y,a),o(p,n,_,y,i,u,a)}else{var m=(i*_+a*g)/e;o(t,p,g,r,i,u,m),o(p,n,_,r,m,u,a)}}var u,a,c=t.children,s=c.length,f=new Array(s+1);for(f[0]=a=u=0;u<s;++u)f[u+1]=a+=c[u].value;o(0,s,t.value,n,e,r,i)},t.treemapDice=qo,t.treemapSlice=jo,t.treemapSliceDice=function(t,n,e,r,i){(1&t.depth?jo:qo)(t,n,e,r,i)},t.treemapSquarify=Kd,t.treemapResquarify=tv,t.interpolate=fn,t.interpolateArray=on,t.interpolateBasis=Gt,t.interpolateBasisClosed=Qt,t.interpolateDate=un,t.interpolateNumber=an,t.interpolateObject=cn,t.interpolateRound=ln,t.interpolateString=sn,t.interpolateTransformCss=Gf,t.interpolateTransformSvg=Qf,t.interpolateZoom=vn,t.interpolateRgb=Hf,t.interpolateRgbBasis=jf,t.interpolateRgbBasisClosed=Xf,t.interpolateHsl=el,t.interpolateHslLong=rl,t.interpolateLab=function(t,n){var e=en((t=Ft(t)).l,(n=Ft(n)).l),r=en(t.a,n.a),i=en(t.b,n.b),o=en(t.opacity,n.opacity);return function(n){return t.l=e(n),t.a=r(n),t.b=i(n),t.opacity=o(n),t+""}},t.interpolateHcl=il,t.interpolateHclLong=ol,t.interpolateCubehelix=ul,t.interpolateCubehelixLong=al,t.quantize=function(t,n){for(var e=new Array(n),r=0;r<n;++r)e[r]=t(r/(n-1));return e},t.path=ee,t.polygonArea=function(t){for(var n,e=-1,r=t.length,i=t[r-1],o=0;++e<r;)n=i,i=t[e],o+=n[1]*i[0]-n[0]*i[1];return o/2},t.polygonCentroid=function(t){for(var n,e,r=-1,i=t.length,o=0,u=0,a=t[i-1],c=0;++r<i;)n=a,a=t[r],c+=e=n[0]*a[1]-a[0]*n[1],o+=(n[0]+a[0])*e,u+=(n[1]+a[1])*e;return c*=3,[o/c,u/c]},t.polygonHull=function(t){if((e=t.length)<3)return null;var n,e,r=new Array(e),i=new Array(e);for(n=0;n<e;++n)r[n]=[+t[n][0],+t[n][1],n];for(r.sort($o),n=0;n<e;++n)i[n]=[r[n][0],-r[n][1]];var o=Wo(r),u=Wo(i),a=u[0]===o[0],c=u[u.length-1]===o[o.length-1],s=[];for(n=o.length-1;n>=0;--n)s.push(t[r[o[n]][2]]);for(n=+a;n<u.length-c;++n)s.push(t[r[u[n]][2]]);return s},t.polygonContains=function(t,n){for(var e,r,i=t.length,o=t[i-1],u=n[0],a=n[1],c=o[0],s=o[1],f=!1,l=0;l<i;++l)e=(o=t[l])[0],(r=o[1])>a!=s>a&&u<(c-e)*(a-r)/(s-r)+e&&(f=!f),c=e,s=r;return f},t.polygonLength=function(t){for(var n,e,r=-1,i=t.length,o=t[i-1],u=o[0],a=o[1],c=0;++r<i;)n=u,e=a,n-=u=(o=t[r])[0],e-=a=o[1],c+=Math.sqrt(n*n+e*e);return c},t.quadtree=Te,t.queue=Ko,t.randomUniform=rv,t.randomNormal=iv,t.randomLogNormal=ov,t.randomBates=av,t.randomIrwinHall=uv,t.randomExponential=cv,t.request=nu,t.html=sv,t.json=fv,t.text=lv,t.xml=hv,t.csv=pv,t.tsv=dv,t.scaleBand=ou,t.scalePoint=function(){return uu(ou().paddingInner(1))},t.scaleIdentity=gu,t.scaleLinear=vu,t.scaleLog=Tu,t.scaleOrdinal=iu,t.scaleImplicit=yv,t.scalePow=ku,t.scaleSqrt=function(){return ku().exponent(.5)},t.scaleQuantile=Su,t.scaleQuantize=Eu,t.scaleThreshold=Au,t.scaleTime=function(){return Va(Gv,Wv,Lv,Pv,Cv,Ev,kv,wv,t.timeFormat).domain([new Date(2e3,0,1),new Date(2e3,0,2)])},t.scaleUtc=function(){return Va(xg,yg,ig,eg,tg,Jv,kv,wv,t.utcFormat).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)])},t.schemeCategory10=Ug,t.schemeCategory20b=Og,t.schemeCategory20c=Fg,t.schemeCategory20=Ig,t.interpolateCubehelixDefault=Yg,t.interpolateRainbow=function(t){(t<0||t>1)&&(t-=Math.floor(t));var n=Math.abs(t-.5);return jg.h=360*t-100,jg.s=1.5-1.5*n,jg.l=.8-.9*n,jg+""},t.interpolateWarm=Bg,t.interpolateCool=Hg,t.interpolateViridis=Xg,t.interpolateMagma=Vg,t.interpolateInferno=$g,t.interpolatePlasma=Wg,t.scaleSequential=Za,t.create=function(t){return ct(A(t).call(document.documentElement))},t.creator=A,t.local=st,t.matcher=of,t.mouse=pt,t.namespace=E,t.namespaces=tf,t.clientPoint=ht,t.select=ct,t.selectAll=function(t){return"string"==typeof t?new ut([document.querySelectorAll(t)],[document.documentElement]):new ut([null==t?[]:t],cf)},t.selection=at,t.selector=z,t.selectorAll=R,t.style=I,t.touch=dt,t.touches=function(t,n){null==n&&(n=lt().touches);for(var e=0,r=n?n.length:0,i=new Array(r);e<r;++e)i[e]=ht(t,n[e]);return i},t.window=F,t.customEvent=it,t.arc=function(){function t(){var t,s,f=+n.apply(this,arguments),l=+e.apply(this,arguments),h=o.apply(this,arguments)-i_,p=u.apply(this,arguments)-i_,d=Zg(p-h),v=p>h;if(c||(c=t=ee()),l<f&&(s=l,l=f,f=s),l>e_)if(d>o_-e_)c.moveTo(l*Qg(h),l*t_(h)),c.arc(0,0,l,h,p,!v),f>e_&&(c.moveTo(f*Qg(p),f*t_(p)),c.arc(0,0,f,p,h,v));else{var g,_,y=h,m=p,x=h,b=p,w=d,M=d,T=a.apply(this,arguments)/2,N=T>e_&&(i?+i.apply(this,arguments):n_(f*f+l*l)),k=Kg(Zg(l-f)/2,+r.apply(this,arguments)),S=k,E=k;if(N>e_){var A=Qa(N/f*t_(T)),C=Qa(N/l*t_(T));(w-=2*A)>e_?(A*=v?1:-1,x+=A,b-=A):(w=0,x=b=(h+p)/2),(M-=2*C)>e_?(C*=v?1:-1,y+=C,m-=C):(M=0,y=m=(h+p)/2)}var z=l*Qg(y),P=l*t_(y),R=f*Qg(b),L=f*t_(b);if(k>e_){var q=l*Qg(m),D=l*t_(m),U=f*Qg(x),O=f*t_(x);if(d<r_){var F=w>e_?function(t,n,e,r,i,o,u,a){var c=e-t,s=r-n,f=u-i,l=a-o,h=(f*(n-o)-l*(t-i))/(l*c-f*s);return[t+h*c,n+h*s]}(z,P,U,O,q,D,R,L):[R,L],I=z-F[0],Y=P-F[1],B=q-F[0],H=D-F[1],j=1/t_(function(t){return t>1?0:t<-1?r_:Math.acos(t)}((I*B+Y*H)/(n_(I*I+Y*Y)*n_(B*B+H*H)))/2),X=n_(F[0]*F[0]+F[1]*F[1]);S=Kg(k,(f-X)/(j-1)),E=Kg(k,(l-X)/(j+1))}}M>e_?E>e_?(g=rc(U,O,z,P,l,E,v),_=rc(q,D,R,L,l,E,v),c.moveTo(g.cx+g.x01,g.cy+g.y01),E<k?c.arc(g.cx,g.cy,E,Gg(g.y01,g.x01),Gg(_.y01,_.x01),!v):(c.arc(g.cx,g.cy,E,Gg(g.y01,g.x01),Gg(g.y11,g.x11),!v),c.arc(0,0,l,Gg(g.cy+g.y11,g.cx+g.x11),Gg(_.cy+_.y11,_.cx+_.x11),!v),c.arc(_.cx,_.cy,E,Gg(_.y11,_.x11),Gg(_.y01,_.x01),!v))):(c.moveTo(z,P),c.arc(0,0,l,y,m,!v)):c.moveTo(z,P),f>e_&&w>e_?S>e_?(g=rc(R,L,q,D,f,-S,v),_=rc(z,P,U,O,f,-S,v),c.lineTo(g.cx+g.x01,g.cy+g.y01),S<k?c.arc(g.cx,g.cy,S,Gg(g.y01,g.x01),Gg(_.y01,_.x01),!v):(c.arc(g.cx,g.cy,S,Gg(g.y01,g.x01),Gg(g.y11,g.x11),!v),c.arc(0,0,f,Gg(g.cy+g.y11,g.cx+g.x11),Gg(_.cy+_.y11,_.cx+_.x11),v),c.arc(_.cx,_.cy,S,Gg(_.y11,_.x11),Gg(_.y01,_.x01),!v))):c.arc(0,0,f,b,x,v):c.lineTo(R,L)}else c.moveTo(0,0);if(c.closePath(),t)return c=null,t+""||null}var n=Ja,e=Ka,r=Ga(0),i=null,o=tc,u=nc,a=ec,c=null;return t.centroid=function(){var t=(+n.apply(this,arguments)+ +e.apply(this,arguments))/2,r=(+o.apply(this,arguments)+ +u.apply(this,arguments))/2-r_/2;return[Qg(r)*t,t_(r)*t]},t.innerRadius=function(e){return arguments.length?(n="function"==typeof e?e:Ga(+e),t):n},t.outerRadius=function(n){return arguments.length?(e="function"==typeof n?n:Ga(+n),t):e},t.cornerRadius=function(n){return arguments.length?(r="function"==typeof n?n:Ga(+n),t):r},t.padRadius=function(n){return arguments.length?(i=null==n?null:"function"==typeof n?n:Ga(+n),t):i},t.startAngle=function(n){return arguments.length?(o="function"==typeof n?n:Ga(+n),t):o},t.endAngle=function(n){return arguments.length?(u="function"==typeof n?n:Ga(+n),t):u},t.padAngle=function(n){return arguments.length?(a="function"==typeof n?n:Ga(+n),t):a},t.context=function(n){return arguments.length?(c=null==n?null:n,t):c},t},t.area=sc,t.line=cc,t.pie=function(){function t(t){var a,c,s,f,l,h=t.length,p=0,d=new Array(h),v=new Array(h),g=+i.apply(this,arguments),_=Math.min(o_,Math.max(-o_,o.apply(this,arguments)-g)),y=Math.min(Math.abs(_)/h,u.apply(this,arguments)),m=y*(_<0?-1:1);for(a=0;a<h;++a)(l=v[d[a]=a]=+n(t[a],a,t))>0&&(p+=l);for(null!=e?d.sort(function(t,n){return e(v[t],v[n])}):null!=r&&d.sort(function(n,e){return r(t[n],t[e])}),a=0,s=p?(_-h*m)/p:0;a<h;++a,g=f)c=d[a],f=g+((l=v[c])>0?l*s:0)+m,v[c]={data:t[c],index:a,value:l,startAngle:g,endAngle:f,padAngle:y};return v}var n=lc,e=fc,r=null,i=Ga(0),o=Ga(o_),u=Ga(0);return t.value=function(e){return arguments.length?(n="function"==typeof e?e:Ga(+e),t):n},t.sortValues=function(n){return arguments.length?(e=n,r=null,t):e},t.sort=function(n){return arguments.length?(r=n,e=null,t):r},t.startAngle=function(n){return arguments.length?(i="function"==typeof n?n:Ga(+n),t):i},t.endAngle=function(n){return arguments.length?(o="function"==typeof n?n:Ga(+n),t):o},t.padAngle=function(n){return arguments.length?(u="function"==typeof n?n:Ga(+n),t):u},t},t.areaRadial=gc,t.radialArea=gc,t.lineRadial=vc,t.radialLine=vc,t.pointRadial=_c,t.linkHorizontal=function(){return xc(bc)},t.linkVertical=function(){return xc(wc)},t.linkRadial=function(){var t=xc(Mc);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t},t.symbol=function(){function t(){var t;if(r||(r=t=ee()),n.apply(this,arguments).draw(r,+e.apply(this,arguments)),t)return r=null,t+""||null}var n=Ga(c_),e=Ga(64),r=null;return t.type=function(e){return arguments.length?(n="function"==typeof e?e:Ga(e),t):n},t.size=function(n){return arguments.length?(e="function"==typeof n?n:Ga(+n),t):e},t.context=function(n){return arguments.length?(r=null==n?null:n,t):r},t},t.symbols=T_,t.symbolCircle=c_,t.symbolCross=s_,t.symbolDiamond=h_,t.symbolSquare=__,t.symbolStar=g_,t.symbolTriangle=m_,t.symbolWye=M_,t.curveBasisClosed=function(t){return new Sc(t)},t.curveBasisOpen=function(t){return new Ec(t)},t.curveBasis=function(t){return new kc(t)},t.curveBundle=N_,t.curveCardinalClosed=S_,t.curveCardinalOpen=E_,t.curveCardinal=k_,t.curveCatmullRomClosed=C_,t.curveCatmullRomOpen=z_,t.curveCatmullRom=A_,t.curveLinearClosed=function(t){return new Oc(t)},t.curveLinear=oc,t.curveMonotoneX=function(t){return new Hc(t)},t.curveMonotoneY=function(t){return new jc(t)},t.curveNatural=function(t){return new Vc(t)},t.curveStep=function(t){return new Wc(t,.5)},t.curveStepAfter=function(t){return new Wc(t,1)},t.curveStepBefore=function(t){return new Wc(t,0)},t.stack=function(){function t(t){var o,u,a=n.apply(this,arguments),c=t.length,s=a.length,f=new Array(s);for(o=0;o<s;++o){for(var l,h=a[o],p=f[o]=new Array(c),d=0;d<c;++d)p[d]=l=[0,+i(t[d],h,d,t)],l.data=t[d];p.key=h}for(o=0,u=e(f);o<s;++o)f[u[o]].index=o;return r(f,u),f}var n=Ga([]),e=Gc,r=Zc,i=Qc;return t.keys=function(e){return arguments.length?(n="function"==typeof e?e:Ga(a_.call(e)),t):n},t.value=function(n){return arguments.length?(i="function"==typeof n?n:Ga(+n),t):i},t.order=function(n){return arguments.length?(e=null==n?Gc:"function"==typeof n?n:Ga(a_.call(n)),t):e},t.offset=function(n){return arguments.length?(r=null==n?Zc:n,t):r},t},t.stackOffsetExpand=function(t,n){if((r=t.length)>0){for(var e,r,i,o=0,u=t[0].length;o<u;++o){for(i=e=0;e<r;++e)i+=t[e][o][1]||0;if(i)for(e=0;e<r;++e)t[e][o][1]/=i}Zc(t,n)}},t.stackOffsetDiverging=function(t,n){if((a=t.length)>1)for(var e,r,i,o,u,a,c=0,s=t[n[0]].length;c<s;++c)for(o=u=0,e=0;e<a;++e)(i=(r=t[n[e]][c])[1]-r[0])>=0?(r[0]=o,r[1]=o+=i):i<0?(r[1]=u,r[0]=u+=i):r[0]=o},t.stackOffsetNone=Zc,t.stackOffsetSilhouette=function(t,n){if((e=t.length)>0){for(var e,r=0,i=t[n[0]],o=i.length;r<o;++r){for(var u=0,a=0;u<e;++u)a+=t[u][r][1]||0;i[r][1]+=i[r][0]=-a/2}Zc(t,n)}},t.stackOffsetWiggle=function(t,n){if((i=t.length)>0&&(r=(e=t[n[0]]).length)>0){for(var e,r,i,o=0,u=1;u<r;++u){for(var a=0,c=0,s=0;a<i;++a){for(var f=t[n[a]],l=f[u][1]||0,h=(l-(f[u-1][1]||0))/2,p=0;p<a;++p){var d=t[n[p]];h+=(d[u][1]||0)-(d[u-1][1]||0)}c+=l,s+=h*l}e[u-1][1]+=e[u-1][0]=o,c&&(o-=s/c)}e[u-1][1]+=e[u-1][0]=o,Zc(t,n)}},t.stackOrderAscending=Jc,t.stackOrderDescending=function(t){return Jc(t).reverse()},t.stackOrderInsideOut=function(t){var n,e,r=t.length,i=t.map(Kc),o=Gc(t).sort(function(t,n){return i[n]-i[t]}),u=0,a=0,c=[],s=[];for(n=0;n<r;++n)e=o[n],u<a?(u+=i[e],c.push(e)):(a+=i[e],s.push(e));return s.reverse().concat(c)},t.stackOrderNone=Gc,t.stackOrderReverse=function(t){return Gc(t).reverse()},t.timeInterval=Cu,t.timeMillisecond=wv,t.timeMilliseconds=Mv,t.utcMillisecond=wv,t.utcMilliseconds=Mv,t.timeSecond=kv,t.timeSeconds=Sv,t.utcSecond=kv,t.utcSeconds=Sv,t.timeMinute=Ev,t.timeMinutes=Av,t.timeHour=Cv,t.timeHours=zv,t.timeDay=Pv,t.timeDays=Rv,t.timeWeek=Lv,t.timeWeeks=Yv,t.timeSunday=Lv,t.timeSundays=Yv,t.timeMonday=qv,t.timeMondays=Bv,t.timeTuesday=Dv,t.timeTuesdays=Hv,t.timeWednesday=Uv,t.timeWednesdays=jv,t.timeThursday=Ov,t.timeThursdays=Xv,t.timeFriday=Fv,t.timeFridays=Vv,t.timeSaturday=Iv,t.timeSaturdays=$v,t.timeMonth=Wv,t.timeMonths=Zv,t.timeYear=Gv,t.timeYears=Qv,t.utcMinute=Jv,t.utcMinutes=Kv,t.utcHour=tg,t.utcHours=ng,t.utcDay=eg,t.utcDays=rg,t.utcWeek=ig,t.utcWeeks=lg,t.utcSunday=ig,t.utcSundays=lg,t.utcMonday=og,t.utcMondays=hg,t.utcTuesday=ug,t.utcTuesdays=pg,t.utcWednesday=ag,t.utcWednesdays=dg,t.utcThursday=cg,t.utcThursdays=vg,t.utcFriday=sg,t.utcFridays=gg,t.utcSaturday=fg,t.utcSaturdays=_g,t.utcMonth=yg,t.utcMonths=mg,t.utcYear=xg,t.utcYears=wg,t.timeFormatDefaultLocale=Ha,t.timeFormatLocale=Du,t.isoFormat=Eg,t.isoParse=Ag,t.now=mn,t.timer=wn,t.timerFlush=Mn,t.timeout=Sn,t.interval=function(t,n,e){var r=new bn,i=n;return null==n?(r.restart(t,n,e),r):(n=+n,e=null==e?mn():+e,r.restart(function o(u){u+=i,r.restart(o,i+=n,e),t(u)},n,e),r)},t.transition=Dn,t.active=function(t,n){var e,r,i=t.__transition;if(i){n=null==n?null:n+"";for(r in i)if((e=i[r]).state>xl&&e.name===n)return new qn([[t]],Jl,n,+r)}return null},t.interrupt=Pn,t.voronoi=function(){function t(t){return new Ns(t.map(function(r,i){var o=[Math.round(n(r,i,t)/F_)*F_,Math.round(e(r,i,t)/F_)*F_];return o.index=i,o.data=r,o}),r)}var n=ns,e=es,r=null;return t.polygons=function(n){return t(n).polygons()},t.links=function(n){return t(n).links()},t.triangles=function(n){return t(n).triangles()},t.x=function(e){return arguments.length?(n="function"==typeof e?e:ts(+e),t):n},t.y=function(n){return arguments.length?(e="function"==typeof n?n:ts(+n),t):e},t.extent=function(n){return arguments.length?(r=null==n?null:[[+n[0][0],+n[0][1]],[+n[1][0],+n[1][1]]],t):r&&[[r[0][0],r[0][1]],[r[1][0],r[1][1]]]},t.size=function(n){return arguments.length?(r=null==n?null:[[0,0],[+n[0],+n[1]]],t):r&&[r[1][0]-r[0][0],r[1][1]-r[0][1]]},t},t.zoom=function(){function n(t){t.property("__zoom",Rs).on("wheel.zoom",c).on("mousedown.zoom",s).on("dblclick.zoom",f).filter(x).on("touchstart.zoom",l).on("touchmove.zoom",h).on("touchend.zoom touchcancel.zoom",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function e(t,n){return(n=Math.max(b[0],Math.min(b[1],n)))===t.k?t:new Ss(n,t.x,t.y)}function r(t,n,e){var r=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return r===t.x&&i===t.y?t:new Ss(t.k,r,i)}function i(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function o(t,n,e){t.on("start.zoom",function(){u(this,arguments).start()}).on("interrupt.zoom end.zoom",function(){u(this,arguments).end()}).tween("zoom",function(){var t=arguments,r=u(this,t),o=_.apply(this,t),a=e||i(o),c=Math.max(o[1][0]-o[0][0],o[1][1]-o[0][1]),s=this.__zoom,f="function"==typeof n?n.apply(this,t):n,l=T(s.invert(a).concat(c/s.k),f.invert(a).concat(c/f.k));return function(t){if(1===t)t=f;else{var n=l(t),e=c/n[2];t=new Ss(e,a[0]-n[0]*e,a[1]-n[1]*e)}r.zoom(null,t)}})}function u(t,n){for(var e,r=0,i=k.length;r<i;++r)if((e=k[r]).that===t)return e;return new a(t,n)}function a(t,n){this.that=t,this.args=n,this.index=-1,this.active=0,this.extent=_.apply(t,n)}function c(){if(g.apply(this,arguments)){var t=u(this,arguments),n=this.__zoom,i=Math.max(b[0],Math.min(b[1],n.k*Math.pow(2,m.apply(this,arguments)))),o=pt(this);if(t.wheel)t.mouse[0][0]===o[0]&&t.mouse[0][1]===o[1]||(t.mouse[1]=n.invert(t.mouse[0]=o)),clearTimeout(t.wheel);else{if(n.k===i)return;t.mouse=[o,n.invert(o)],Pn(this),t.start()}Cs(),t.wheel=setTimeout(function(){t.wheel=null,t.end()},A),t.zoom("mouse",y(r(e(n,i),t.mouse[0],t.mouse[1]),t.extent,w))}}function s(){if(!v&&g.apply(this,arguments)){var n=u(this,arguments),e=ct(t.event.view).on("mousemove.zoom",function(){if(Cs(),!n.moved){var e=t.event.clientX-o,i=t.event.clientY-a;n.moved=e*e+i*i>C}n.zoom("mouse",y(r(n.that.__zoom,n.mouse[0]=pt(n.that),n.mouse[1]),n.extent,w))},!0).on("mouseup.zoom",function(){e.on("mousemove.zoom mouseup.zoom",null),yt(t.event.view,n.moved),Cs(),n.end()},!0),i=pt(this),o=t.event.clientX,a=t.event.clientY;_t(t.event.view),As(),n.mouse=[i,this.__zoom.invert(i)],Pn(this),n.start()}}function f(){if(g.apply(this,arguments)){var i=this.__zoom,u=pt(this),a=i.invert(u),c=i.k*(t.event.shiftKey?.5:2),s=y(r(e(i,c),u,a),_.apply(this,arguments),w);Cs(),M>0?ct(this).transition().duration(M).call(o,s,u):ct(this).call(n.transform,s)}}function l(){if(g.apply(this,arguments)){var n,e,r,i,o=u(this,arguments),a=t.event.changedTouches,c=a.length;for(As(),e=0;e<c;++e)i=[i=dt(this,a,(r=a[e]).identifier),this.__zoom.invert(i),r.identifier],o.touch0?o.touch1||(o.touch1=i):(o.touch0=i,n=!0);if(d&&(d=clearTimeout(d),!o.touch1))return o.end(),void((i=ct(this).on("dblclick.zoom"))&&i.apply(this,arguments));n&&(d=setTimeout(function(){d=null},E),Pn(this),o.start())}}function h(){var n,i,o,a,c=u(this,arguments),s=t.event.changedTouches,f=s.length;for(Cs(),d&&(d=clearTimeout(d)),n=0;n<f;++n)o=dt(this,s,(i=s[n]).identifier),c.touch0&&c.touch0[2]===i.identifier?c.touch0[0]=o:c.touch1&&c.touch1[2]===i.identifier&&(c.touch1[0]=o);if(i=c.that.__zoom,c.touch1){var l=c.touch0[0],h=c.touch0[1],p=c.touch1[0],v=c.touch1[1],g=(g=p[0]-l[0])*g+(g=p[1]-l[1])*g,_=(_=v[0]-h[0])*_+(_=v[1]-h[1])*_;i=e(i,Math.sqrt(g/_)),o=[(l[0]+p[0])/2,(l[1]+p[1])/2],a=[(h[0]+v[0])/2,(h[1]+v[1])/2]}else{if(!c.touch0)return;o=c.touch0[0],a=c.touch0[1]}c.zoom("touch",y(r(i,o,a),c.extent,w))}function p(){var n,e,r=u(this,arguments),i=t.event.changedTouches,o=i.length;for(As(),v&&clearTimeout(v),v=setTimeout(function(){v=null},E),n=0;n<o;++n)e=i[n],r.touch0&&r.touch0[2]===e.identifier?delete r.touch0:r.touch1&&r.touch1[2]===e.identifier&&delete r.touch1;r.touch1&&!r.touch0&&(r.touch0=r.touch1,delete r.touch1),r.touch0?r.touch0[1]=this.__zoom.invert(r.touch0[0]):r.end()}var d,v,g=zs,_=Ps,y=Ds,m=Ls,x=qs,b=[0,1/0],w=[[-1/0,-1/0],[1/0,1/0]],M=250,T=vn,k=[],S=N("start","zoom","end"),E=500,A=150,C=0;return n.transform=function(t,n){var e=t.selection?t.selection():t;e.property("__zoom",Rs),t!==e?o(t,n):e.interrupt().each(function(){u(this,arguments).start().zoom(null,"function"==typeof n?n.apply(this,arguments):n).end()})},n.scaleBy=function(t,e){n.scaleTo(t,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)})},n.scaleTo=function(t,o){n.transform(t,function(){var t=_.apply(this,arguments),n=this.__zoom,u=i(t),a=n.invert(u),c="function"==typeof o?o.apply(this,arguments):o;return y(r(e(n,c),u,a),t,w)})},n.translateBy=function(t,e,r){n.transform(t,function(){return y(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof r?r.apply(this,arguments):r),_.apply(this,arguments),w)})},n.translateTo=function(t,e,r){n.transform(t,function(){var t=_.apply(this,arguments),n=this.__zoom,o=i(t);return y(Y_.translate(o[0],o[1]).scale(n.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof r?-r.apply(this,arguments):-r),t,w)})},a.prototype={start:function(){return 1==++this.active&&(this.index=k.push(this)-1,this.emit("start")),this},zoom:function(t,n){return this.mouse&&"mouse"!==t&&(this.mouse[1]=n.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=n.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=n.invert(this.touch1[0])),this.that.__zoom=n,this.emit("zoom"),this},end:function(){return 0==--this.active&&(k.splice(this.index,1),this.index=-1,this.emit("end")),this},emit:function(t){it(new function(t,n,e){this.target=t,this.type=n,this.transform=e}(n,t,this.that.__zoom),S.apply,S,[t,this.that,this.args])}},n.wheelDelta=function(t){return arguments.length?(m="function"==typeof t?t:ks(+t),n):m},n.filter=function(t){return arguments.length?(g="function"==typeof t?t:ks(!!t),n):g},n.touchable=function(t){return arguments.length?(x="function"==typeof t?t:ks(!!t),n):x},n.extent=function(t){return arguments.length?(_="function"==typeof t?t:ks([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),n):_},n.scaleExtent=function(t){return arguments.length?(b[0]=+t[0],b[1]=+t[1],n):[b[0],b[1]]},n.translateExtent=function(t){return arguments.length?(w[0][0]=+t[0][0],w[1][0]=+t[1][0],w[0][1]=+t[0][1],w[1][1]=+t[1][1],n):[[w[0][0],w[0][1]],[w[1][0],w[1][1]]]},n.constrain=function(t){return arguments.length?(y=t,n):y},n.duration=function(t){return arguments.length?(M=+t,n):M},n.interpolate=function(t){return arguments.length?(T=t,n):T},n.on=function(){var t=S.on.apply(S,arguments);return t===S?n:t},n.clickDistance=function(t){return arguments.length?(C=(t=+t)*t,n):Math.sqrt(C)},n},t.zoomTransform=Es,t.zoomIdentity=Y_,Object.defineProperty(t,"__esModule",{value:!0})});
\ No newline at end of file diff --git a/priv/static/js/jquery3.1.0.min.js b/priv/static/js/jquery3.1.0.min.js new file mode 100644 index 0000000..f6a6a99 --- /dev/null +++ b/priv/static/js/jquery3.1.0.min.js @@ -0,0 +1,4 @@ +/*! jQuery v3.1.0 | (c) jQuery Foundation | jquery.org/license */ +!function(a,b){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement("script");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q="3.1.0",r=function(a,b){return new r.fn.init(a,b)},s=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null!=a?a<0?this[a+this.length]:this[a]:f.call(this)},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.prevObject=this,b},each:function(a){return r.each(this,a)},map:function(a){return this.pushStack(r.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(f.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(a<0?b:0);return this.pushStack(c>=0&&c<b?[this[c]]:[])},end:function(){return this.prevObject||this.constructor()},push:h,sort:c.sort,splice:c.splice},r.extend=r.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||r.isFunction(g)||(g={}),h===i&&(g=this,h--);h<i;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(r.isPlainObject(d)||(e=r.isArray(d)))?(e?(e=!1,f=c&&r.isArray(c)?c:[]):f=c&&r.isPlainObject(c)?c:{},g[b]=r.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},r.extend({expando:"jQuery"+(q+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===r.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){var b=r.type(a);return("number"===b||"string"===b)&&!isNaN(a-parseFloat(a))},isPlainObject:function(a){var b,c;return!(!a||"[object Object]"!==k.call(a))&&(!(b=e(a))||(c=l.call(b,"constructor")&&b.constructor,"function"==typeof c&&m.call(c)===n))},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?j[k.call(a)]||"object":typeof a},globalEval:function(a){p(a)},camelCase:function(a){return a.replace(t,"ms-").replace(u,v)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b){var c,d=0;if(w(a)){for(c=a.length;d<c;d++)if(b.call(a[d],d,a[d])===!1)break}else for(d in a)if(b.call(a[d],d,a[d])===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(s,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(w(Object(a))?r.merge(c,"string"==typeof a?[a]:a):h.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:i.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;d<c;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;f<g;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,e,f=0,h=[];if(w(a))for(d=a.length;f<d;f++)e=b(a[f],f,c),null!=e&&h.push(e);else for(f in a)e=b(a[f],f,c),null!=e&&h.push(e);return g.apply([],h)},guid:1,proxy:function(a,b){var c,d,e;if("string"==typeof b&&(c=a[b],b=a,a=c),r.isFunction(a))return d=f.call(arguments,2),e=function(){return a.apply(b||this,d.concat(f.call(arguments)))},e.guid=a.guid=a.guid||r.guid++,e},now:Date.now,support:o}),"function"==typeof Symbol&&(r.fn[Symbol.iterator]=c[Symbol.iterator]),r.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(a,b){j["[object "+b+"]"]=b.toLowerCase()});function w(a){var b=!!a&&"length"in a&&a.length,c=r.type(a);return"function"!==c&&!r.isWindow(a)&&("array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a)}var x=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c]===b)return c;return-1},J="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",K="[\\x20\\t\\r\\n\\f]",L="(?:\\\\.|[\\w-]|[^\0-\\xa0])+",M="\\["+K+"*("+L+")(?:"+K+"*([*^$|!~]?=)"+K+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+L+"))|)"+K+"*\\]",N=":("+L+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+M+")*)|.*)\\)|)",O=new RegExp(K+"+","g"),P=new RegExp("^"+K+"+|((?:^|[^\\\\])(?:\\\\.)*)"+K+"+$","g"),Q=new RegExp("^"+K+"*,"+K+"*"),R=new RegExp("^"+K+"*([>+~]|"+K+")"+K+"*"),S=new RegExp("="+K+"*([^\\]'\"]*?)"+K+"*\\]","g"),T=new RegExp(N),U=new RegExp("^"+L+"$"),V={ID:new RegExp("^#("+L+")"),CLASS:new RegExp("^\\.("+L+")"),TAG:new RegExp("^("+L+"|[*])"),ATTR:new RegExp("^"+M),PSEUDO:new RegExp("^"+N),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+K+"*(even|odd|(([+-]|)(\\d*)n|)"+K+"*(?:([+-]|)"+K+"*(\\d+)|))"+K+"*\\)|)","i"),bool:new RegExp("^(?:"+J+")$","i"),needsContext:new RegExp("^"+K+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+K+"*((?:-\\d)?\\d*)"+K+"*\\)|)(?=[^-]|$)","i")},W=/^(?:input|select|textarea|button)$/i,X=/^h\d$/i,Y=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,$=/[+~]/,_=new RegExp("\\\\([\\da-f]{1,6}"+K+"?|("+K+")|.)","ig"),aa=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:d<0?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ba=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g,ca=function(a,b){return b?"\0"===a?"\ufffd":a.slice(0,-1)+"\\"+a.charCodeAt(a.length-1).toString(16)+" ":"\\"+a},da=function(){m()},ea=ta(function(a){return a.disabled===!0},{dir:"parentNode",next:"legend"});try{G.apply(D=H.call(v.childNodes),v.childNodes),D[v.childNodes.length].nodeType}catch(fa){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s=b&&b.ownerDocument,w=b?b.nodeType:9;if(d=d||[],"string"!=typeof a||!a||1!==w&&9!==w&&11!==w)return d;if(!e&&((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,p)){if(11!==w&&(l=Z.exec(a)))if(f=l[1]){if(9===w){if(!(j=b.getElementById(f)))return d;if(j.id===f)return d.push(j),d}else if(s&&(j=s.getElementById(f))&&t(b,j)&&j.id===f)return d.push(j),d}else{if(l[2])return G.apply(d,b.getElementsByTagName(a)),d;if((f=l[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(f)),d}if(c.qsa&&!A[a+" "]&&(!q||!q.test(a))){if(1!==w)s=b,r=a;else if("object"!==b.nodeName.toLowerCase()){(k=b.getAttribute("id"))?k=k.replace(ba,ca):b.setAttribute("id",k=u),o=g(a),h=o.length;while(h--)o[h]="#"+k+" "+sa(o[h]);r=o.join(","),s=$.test(a)&&qa(b.parentNode)||b}if(r)try{return G.apply(d,s.querySelectorAll(r)),d}catch(x){}finally{k===u&&b.removeAttribute("id")}}}return i(a.replace(P,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("fieldset");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=c.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&a.sourceIndex-b.sourceIndex;if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return function(b){return"label"in b&&b.disabled===a||"form"in b&&b.disabled===a||"form"in b&&b.disabled===!1&&(b.isDisabled===a||b.isDisabled!==!a&&("label"in b||!ea(b))!==a)}}function pa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function qa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return!!b&&"HTML"!==b.nodeName},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=n.documentElement,p=!f(n),v!==n&&(e=n.defaultView)&&e.top!==e&&(e.addEventListener?e.addEventListener("unload",da,!1):e.attachEvent&&e.attachEvent("onunload",da)),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(n.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=Y.test(n.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!n.getElementsByName||!n.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c?[c]:[]}},d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){if("undefined"!=typeof b.getElementsByClassName&&p)return b.getElementsByClassName(a)},r=[],q=[],(c.qsa=Y.test(n.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="<a id='"+u+"'></a><select id='"+u+"-\r\\' msallowcapture=''><option selected=''></option></select>",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+K+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+K+"*(?:value|"+J+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){a.innerHTML="<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>";var b=n.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+K+"*[*^$|!~]?="),2!==a.querySelectorAll(":enabled").length&&q.push(":enabled",":disabled"),o.appendChild(a).disabled=!0,2!==a.querySelectorAll(":disabled").length&&q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=Y.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"*"),s.call(a,"[s!='']:x"),r.push("!=",N)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=Y.test(o.compareDocumentPosition),t=b||Y.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===n||a.ownerDocument===v&&t(v,a)?-1:b===n||b.ownerDocument===v&&t(v,b)?1:k?I(k,a)-I(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,g=[a],h=[b];if(!e||!f)return a===n?-1:b===n?1:e?-1:f?1:k?I(k,a)-I(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)g.unshift(c);c=b;while(c=c.parentNode)h.unshift(c);while(g[d]===h[d])d++;return d?la(g[d],h[d]):g[d]===v?-1:h[d]===v?1:0},n):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(S,"='$1']"),c.matchesSelector&&p&&!A[b+" "]&&(!r||!r.test(b))&&(!q||!q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.escape=function(a){return(a+"").replace(ba,ca)},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(_,aa),a[3]=(a[3]||a[4]||a[5]||"").replace(_,aa),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return V.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&T.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(_,aa).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+K+")"+a+"("+K+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:!b||(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(O," ")+" ").indexOf(c)>-1:"|="===b&&(e===c||e.slice(0,c.length+1)===c+"-"))}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h,t=!1;if(q){if(f){while(p){m=b;while(m=m[p])if(h?m.nodeName.toLowerCase()===r:1===m.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){m=q,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n&&j[2],m=n&&q.childNodes[n];while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if(1===m.nodeType&&++t&&m===b){k[a]=[w,n,t];break}}else if(s&&(m=b,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n),t===!1)while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if((h?m.nodeName.toLowerCase()===r:1===m.nodeType)&&++t&&(s&&(l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),k[a]=[w,t]),m===b))break;return t-=e,t===d||t%d===0&&t/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(P,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(_,aa),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return U.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(_,aa).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:oa(!1),disabled:oa(!0),checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:pa(function(){return[0]}),last:pa(function(a,b){return[b-1]}),eq:pa(function(a,b,c){return[c<0?c+b:c]}),even:pa(function(a,b){for(var c=0;c<b;c+=2)a.push(c);return a}),odd:pa(function(a,b){for(var c=1;c<b;c+=2)a.push(c);return a}),lt:pa(function(a,b,c){for(var d=c<0?c+b:c;--d>=0;)a.push(d);return a}),gt:pa(function(a,b,c){for(var d=c<0?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=ma(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=na(b);function ra(){}ra.prototype=d.filters=d.pseudos,d.setFilters=new ra,g=ga.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){c&&!(e=Q.exec(h))||(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=R.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(P," ")}),h=h.slice(c.length));for(g in d.filter)!(e=V[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?ga.error(a):z(a,i).slice(0)};function sa(a){for(var b=0,c=a.length,d="";b<c;b++)d+=a[b].value;return d}function ta(a,b,c){var d=b.dir,e=b.next,f=e||d,g=c&&"parentNode"===f,h=x++;return b.first?function(b,c,e){while(b=b[d])if(1===b.nodeType||g)return a(b,c,e)}:function(b,c,i){var j,k,l,m=[w,h];if(i){while(b=b[d])if((1===b.nodeType||g)&&a(b,c,i))return!0}else while(b=b[d])if(1===b.nodeType||g)if(l=b[u]||(b[u]={}),k=l[b.uniqueID]||(l[b.uniqueID]={}),e&&e===b.nodeName.toLowerCase())b=b[d]||b;else{if((j=k[f])&&j[0]===w&&j[1]===h)return m[2]=j[2];if(k[f]=m,m[2]=a(b,c,i))return!0}}}function ua(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function va(a,b,c){for(var d=0,e=b.length;d<e;d++)ga(a,b[d],c);return c}function wa(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;h<i;h++)(f=a[h])&&(c&&!c(f,d,e)||(g.push(f),j&&b.push(h)));return g}function xa(a,b,c,d,e,f){return d&&!d[u]&&(d=xa(d)),e&&!e[u]&&(e=xa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||va(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:wa(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=wa(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?I(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=wa(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ya(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=ta(function(a){return a===b},h,!0),l=ta(function(a){return I(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];i<f;i++)if(c=d.relative[a[i].type])m=[ta(ua(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;e<f;e++)if(d.relative[a[e].type])break;return xa(i>1&&ua(m),i>1&&sa(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(P,"$1"),c,i<e&&ya(a.slice(i,e)),e<f&&ya(a=a.slice(e)),e<f&&sa(a))}m.push(c)}return ua(m)}function za(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,o,q,r=0,s="0",t=f&&[],u=[],v=j,x=f||e&&d.find.TAG("*",k),y=w+=null==v?1:Math.random()||.1,z=x.length;for(k&&(j=g===n||g||k);s!==z&&null!=(l=x[s]);s++){if(e&&l){o=0,g||l.ownerDocument===n||(m(l),h=!p);while(q=a[o++])if(q(l,g||n,h)){i.push(l);break}k&&(w=y)}c&&((l=!q&&l)&&r--,f&&t.push(l))}if(r+=s,c&&s!==r){o=0;while(q=b[o++])q(t,u,g,h);if(f){if(r>0)while(s--)t[s]||u[s]||(u[s]=E.call(i));u=wa(u)}G.apply(i,u),k&&!f&&u.length>0&&r+b.length>1&&ga.uniqueSort(i)}return k&&(w=y,j=v),t};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=ya(b[c]),f[u]?d.push(f):e.push(f);f=A(a,za(e,d)),f.selector=a}return f},i=ga.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(_,aa),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=V.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(_,aa),$.test(j[0].type)&&qa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&sa(j),!a)return G.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,!b||$.test(a)&&qa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("fieldset"))}),ja(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){if(!c)return a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){if(!c&&"input"===a.nodeName.toLowerCase())return a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(J,function(a,b,c){var d;if(!c)return a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);r.find=x,r.expr=x.selectors,r.expr[":"]=r.expr.pseudos,r.uniqueSort=r.unique=x.uniqueSort,r.text=x.getText,r.isXMLDoc=x.isXML,r.contains=x.contains,r.escapeSelector=x.escape;var y=function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&r(a).is(c))break;d.push(a)}return d},z=function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c},A=r.expr.match.needsContext,B=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i,C=/^.[^:#\[\.,]*$/;function D(a,b,c){if(r.isFunction(b))return r.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return r.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(C.test(b))return r.filter(b,a,c);b=r.filter(b,a)}return r.grep(a,function(a){return i.call(b,a)>-1!==c&&1===a.nodeType})}r.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?r.find.matchesSelector(d,a)?[d]:[]:r.find.matches(a,r.grep(b,function(a){return 1===a.nodeType}))},r.fn.extend({find:function(a){var b,c,d=this.length,e=this;if("string"!=typeof a)return this.pushStack(r(a).filter(function(){for(b=0;b<d;b++)if(r.contains(e[b],this))return!0}));for(c=this.pushStack([]),b=0;b<d;b++)r.find(a,e[b],c);return d>1?r.uniqueSort(c):c},filter:function(a){return this.pushStack(D(this,a||[],!1))},not:function(a){return this.pushStack(D(this,a||[],!0))},is:function(a){return!!D(this,"string"==typeof a&&A.test(a)?r(a):a||[],!1).length}});var E,F=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,G=r.fn.init=function(a,b,c){var e,f;if(!a)return this;if(c=c||E,"string"==typeof a){if(e="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:F.exec(a),!e||!e[1]&&b)return!b||b.jquery?(b||c).find(a):this.constructor(b).find(a);if(e[1]){if(b=b instanceof r?b[0]:b,r.merge(this,r.parseHTML(e[1],b&&b.nodeType?b.ownerDocument||b:d,!0)),B.test(e[1])&&r.isPlainObject(b))for(e in b)r.isFunction(this[e])?this[e](b[e]):this.attr(e,b[e]);return this}return f=d.getElementById(e[2]),f&&(this[0]=f,this.length=1),this}return a.nodeType?(this[0]=a,this.length=1,this):r.isFunction(a)?void 0!==c.ready?c.ready(a):a(r):r.makeArray(a,this)};G.prototype=r.fn,E=r(d);var H=/^(?:parents|prev(?:Until|All))/,I={children:!0,contents:!0,next:!0,prev:!0};r.fn.extend({has:function(a){var b=r(a,this),c=b.length;return this.filter(function(){for(var a=0;a<c;a++)if(r.contains(this,b[a]))return!0})},closest:function(a,b){var c,d=0,e=this.length,f=[],g="string"!=typeof a&&r(a);if(!A.test(a))for(;d<e;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&r.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?r.uniqueSort(f):f)},index:function(a){return a?"string"==typeof a?i.call(r(a),this[0]):i.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(r.uniqueSort(r.merge(this.get(),r(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function J(a,b){while((a=a[b])&&1!==a.nodeType);return a}r.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return y(a,"parentNode")},parentsUntil:function(a,b,c){return y(a,"parentNode",c)},next:function(a){return J(a,"nextSibling")},prev:function(a){return J(a,"previousSibling")},nextAll:function(a){return y(a,"nextSibling")},prevAll:function(a){return y(a,"previousSibling")},nextUntil:function(a,b,c){return y(a,"nextSibling",c)},prevUntil:function(a,b,c){return y(a,"previousSibling",c)},siblings:function(a){return z((a.parentNode||{}).firstChild,a)},children:function(a){return z(a.firstChild)},contents:function(a){return a.contentDocument||r.merge([],a.childNodes)}},function(a,b){r.fn[a]=function(c,d){var e=r.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=r.filter(d,e)),this.length>1&&(I[a]||r.uniqueSort(e),H.test(a)&&e.reverse()),this.pushStack(e)}});var K=/\S+/g;function L(a){var b={};return r.each(a.match(K)||[],function(a,c){b[c]=!0}),b}r.Callbacks=function(a){a="string"==typeof a?L(a):r.extend({},a);var b,c,d,e,f=[],g=[],h=-1,i=function(){for(e=a.once,d=b=!0;g.length;h=-1){c=g.shift();while(++h<f.length)f[h].apply(c[0],c[1])===!1&&a.stopOnFalse&&(h=f.length,c=!1)}a.memory||(c=!1),b=!1,e&&(f=c?[]:"")},j={add:function(){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this},remove:function(){return r.each(arguments,function(a,b){var c;while((c=r.inArray(b,f,c))>-1)f.splice(c,1),c<=h&&h--}),this},has:function(a){return a?r.inArray(a,f)>-1:f.length>0},empty:function(){return f&&(f=[]),this},disable:function(){return e=g=[],f=c="",this},disabled:function(){return!f},lock:function(){return e=g=[],c||b||(f=c=""),this},locked:function(){return!!e},fireWith:function(a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this},fire:function(){return j.fireWith(this,arguments),this},fired:function(){return!!d}};return j};function M(a){return a}function N(a){throw a}function O(a,b,c){var d;try{a&&r.isFunction(d=a.promise)?d.call(a).done(b).fail(c):a&&r.isFunction(d=a.then)?d.call(a,b,c):b.call(void 0,a)}catch(a){c.call(void 0,a)}}r.extend({Deferred:function(b){var c=[["notify","progress",r.Callbacks("memory"),r.Callbacks("memory"),2],["resolve","done",r.Callbacks("once memory"),r.Callbacks("once memory"),0,"resolved"],["reject","fail",r.Callbacks("once memory"),r.Callbacks("once memory"),1,"rejected"]],d="pending",e={state:function(){return d},always:function(){return f.done(arguments).fail(arguments),this},"catch":function(a){return e.then(null,a)},pipe:function(){var a=arguments;return r.Deferred(function(b){r.each(c,function(c,d){var e=r.isFunction(a[d[4]])&&a[d[4]];f[d[1]](function(){var a=e&&e.apply(this,arguments);a&&r.isFunction(a.promise)?a.promise().progress(b.notify).done(b.resolve).fail(b.reject):b[d[0]+"With"](this,e?[a]:arguments)})}),a=null}).promise()},then:function(b,d,e){var f=0;function g(b,c,d,e){return function(){var h=this,i=arguments,j=function(){var a,j;if(!(b<f)){if(a=d.apply(h,i),a===c.promise())throw new TypeError("Thenable self-resolution");j=a&&("object"==typeof a||"function"==typeof a)&&a.then,r.isFunction(j)?e?j.call(a,g(f,c,M,e),g(f,c,N,e)):(f++,j.call(a,g(f,c,M,e),g(f,c,N,e),g(f,c,M,c.notifyWith))):(d!==M&&(h=void 0,i=[a]),(e||c.resolveWith)(h,i))}},k=e?j:function(){try{j()}catch(a){r.Deferred.exceptionHook&&r.Deferred.exceptionHook(a,k.stackTrace),b+1>=f&&(d!==N&&(h=void 0,i=[a]),c.rejectWith(h,i))}};b?k():(r.Deferred.getStackHook&&(k.stackTrace=r.Deferred.getStackHook()),a.setTimeout(k))}}return r.Deferred(function(a){c[0][3].add(g(0,a,r.isFunction(e)?e:M,a.notifyWith)),c[1][3].add(g(0,a,r.isFunction(b)?b:M)),c[2][3].add(g(0,a,r.isFunction(d)?d:N))}).promise()},promise:function(a){return null!=a?r.extend(a,e):e}},f={};return r.each(c,function(a,b){var g=b[2],h=b[5];e[b[1]]=g.add,h&&g.add(function(){d=h},c[3-a][2].disable,c[0][2].lock),g.add(b[3].fire),f[b[0]]=function(){return f[b[0]+"With"](this===f?void 0:this,arguments),this},f[b[0]+"With"]=g.fireWith}),e.promise(f),b&&b.call(f,f),f},when:function(a){var b=arguments.length,c=b,d=Array(c),e=f.call(arguments),g=r.Deferred(),h=function(a){return function(c){d[a]=this,e[a]=arguments.length>1?f.call(arguments):c,--b||g.resolveWith(d,e)}};if(b<=1&&(O(a,g.done(h(c)).resolve,g.reject),"pending"===g.state()||r.isFunction(e[c]&&e[c].then)))return g.then();while(c--)O(e[c],h(c),g.reject);return g.promise()}});var P=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;r.Deferred.exceptionHook=function(b,c){a.console&&a.console.warn&&b&&P.test(b.name)&&a.console.warn("jQuery.Deferred exception: "+b.message,b.stack,c)},r.readyException=function(b){a.setTimeout(function(){throw b})};var Q=r.Deferred();r.fn.ready=function(a){return Q.then(a)["catch"](function(a){r.readyException(a)}),this},r.extend({isReady:!1,readyWait:1,holdReady:function(a){a?r.readyWait++:r.ready(!0)},ready:function(a){(a===!0?--r.readyWait:r.isReady)||(r.isReady=!0,a!==!0&&--r.readyWait>0||Q.resolveWith(d,[r]))}}),r.ready.then=Q.then;function R(){d.removeEventListener("DOMContentLoaded",R),a.removeEventListener("load",R),r.ready()}"complete"===d.readyState||"loading"!==d.readyState&&!d.documentElement.doScroll?a.setTimeout(r.ready):(d.addEventListener("DOMContentLoaded",R),a.addEventListener("load",R));var S=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===r.type(c)){e=!0;for(h in c)S(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0, +r.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(r(a),c)})),b))for(;h<i;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},T=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function U(){this.expando=r.expando+U.uid++}U.uid=1,U.prototype={cache:function(a){var b=a[this.expando];return b||(b={},T(a)&&(a.nodeType?a[this.expando]=b:Object.defineProperty(a,this.expando,{value:b,configurable:!0}))),b},set:function(a,b,c){var d,e=this.cache(a);if("string"==typeof b)e[r.camelCase(b)]=c;else for(d in b)e[r.camelCase(d)]=b[d];return e},get:function(a,b){return void 0===b?this.cache(a):a[this.expando]&&a[this.expando][r.camelCase(b)]},access:function(a,b,c){return void 0===b||b&&"string"==typeof b&&void 0===c?this.get(a,b):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d=a[this.expando];if(void 0!==d){if(void 0!==b){r.isArray(b)?b=b.map(r.camelCase):(b=r.camelCase(b),b=b in d?[b]:b.match(K)||[]),c=b.length;while(c--)delete d[b[c]]}(void 0===b||r.isEmptyObject(d))&&(a.nodeType?a[this.expando]=void 0:delete a[this.expando])}},hasData:function(a){var b=a[this.expando];return void 0!==b&&!r.isEmptyObject(b)}};var V=new U,W=new U,X=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,Y=/[A-Z]/g;function Z(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(Y,"-$&").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c||"false"!==c&&("null"===c?null:+c+""===c?+c:X.test(c)?JSON.parse(c):c)}catch(e){}W.set(a,b,c)}else c=void 0;return c}r.extend({hasData:function(a){return W.hasData(a)||V.hasData(a)},data:function(a,b,c){return W.access(a,b,c)},removeData:function(a,b){W.remove(a,b)},_data:function(a,b,c){return V.access(a,b,c)},_removeData:function(a,b){V.remove(a,b)}}),r.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=W.get(f),1===f.nodeType&&!V.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=r.camelCase(d.slice(5)),Z(f,d,e[d])));V.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){W.set(this,a)}):S(this,function(b){var c;if(f&&void 0===b){if(c=W.get(f,a),void 0!==c)return c;if(c=Z(f,a),void 0!==c)return c}else this.each(function(){W.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){W.remove(this,a)})}}),r.extend({queue:function(a,b,c){var d;if(a)return b=(b||"fx")+"queue",d=V.get(a,b),c&&(!d||r.isArray(c)?d=V.access(a,b,r.makeArray(c)):d.push(c)),d||[]},dequeue:function(a,b){b=b||"fx";var c=r.queue(a,b),d=c.length,e=c.shift(),f=r._queueHooks(a,b),g=function(){r.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return V.get(a,c)||V.access(a,c,{empty:r.Callbacks("once memory").add(function(){V.remove(a,[b+"queue",c])})})}}),r.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?r.queue(this[0],a):void 0===b?this:this.each(function(){var c=r.queue(this,a,b);r._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&r.dequeue(this,a)})},dequeue:function(a){return this.each(function(){r.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=r.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=V.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var $=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,_=new RegExp("^(?:([+-])=|)("+$+")([a-z%]*)$","i"),aa=["Top","Right","Bottom","Left"],ba=function(a,b){return a=b||a,"none"===a.style.display||""===a.style.display&&r.contains(a.ownerDocument,a)&&"none"===r.css(a,"display")},ca=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};function da(a,b,c,d){var e,f=1,g=20,h=d?function(){return d.cur()}:function(){return r.css(a,b,"")},i=h(),j=c&&c[3]||(r.cssNumber[b]?"":"px"),k=(r.cssNumber[b]||"px"!==j&&+i)&&_.exec(r.css(a,b));if(k&&k[3]!==j){j=j||k[3],c=c||[],k=+i||1;do f=f||".5",k/=f,r.style(a,b,k+j);while(f!==(f=h()/i)&&1!==f&&--g)}return c&&(k=+k||+i||0,e=c[1]?k+(c[1]+1)*c[2]:+c[2],d&&(d.unit=j,d.start=k,d.end=e)),e}var ea={};function fa(a){var b,c=a.ownerDocument,d=a.nodeName,e=ea[d];return e?e:(b=c.body.appendChild(c.createElement(d)),e=r.css(b,"display"),b.parentNode.removeChild(b),"none"===e&&(e="block"),ea[d]=e,e)}function ga(a,b){for(var c,d,e=[],f=0,g=a.length;f<g;f++)d=a[f],d.style&&(c=d.style.display,b?("none"===c&&(e[f]=V.get(d,"display")||null,e[f]||(d.style.display="")),""===d.style.display&&ba(d)&&(e[f]=fa(d))):"none"!==c&&(e[f]="none",V.set(d,"display",c)));for(f=0;f<g;f++)null!=e[f]&&(a[f].style.display=e[f]);return a}r.fn.extend({show:function(){return ga(this,!0)},hide:function(){return ga(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){ba(this)?r(this).show():r(this).hide()})}});var ha=/^(?:checkbox|radio)$/i,ia=/<([a-z][^\/\0>\x20\t\r\n\f]+)/i,ja=/^$|\/(?:java|ecma)script/i,ka={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};ka.optgroup=ka.option,ka.tbody=ka.tfoot=ka.colgroup=ka.caption=ka.thead,ka.th=ka.td;function la(a,b){var c="undefined"!=typeof a.getElementsByTagName?a.getElementsByTagName(b||"*"):"undefined"!=typeof a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&r.nodeName(a,b)?r.merge([a],c):c}function ma(a,b){for(var c=0,d=a.length;c<d;c++)V.set(a[c],"globalEval",!b||V.get(b[c],"globalEval"))}var na=/<|&#?\w+;/;function oa(a,b,c,d,e){for(var f,g,h,i,j,k,l=b.createDocumentFragment(),m=[],n=0,o=a.length;n<o;n++)if(f=a[n],f||0===f)if("object"===r.type(f))r.merge(m,f.nodeType?[f]:f);else if(na.test(f)){g=g||l.appendChild(b.createElement("div")),h=(ia.exec(f)||["",""])[1].toLowerCase(),i=ka[h]||ka._default,g.innerHTML=i[1]+r.htmlPrefilter(f)+i[2],k=i[0];while(k--)g=g.lastChild;r.merge(m,g.childNodes),g=l.firstChild,g.textContent=""}else m.push(b.createTextNode(f));l.textContent="",n=0;while(f=m[n++])if(d&&r.inArray(f,d)>-1)e&&e.push(f);else if(j=r.contains(f.ownerDocument,f),g=la(l.appendChild(f),"script"),j&&ma(g),c){k=0;while(f=g[k++])ja.test(f.type||"")&&c.push(f)}return l}!function(){var a=d.createDocumentFragment(),b=a.appendChild(d.createElement("div")),c=d.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),o.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",o.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var pa=d.documentElement,qa=/^key/,ra=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,sa=/^([^.]*)(?:\.(.+)|)/;function ta(){return!0}function ua(){return!1}function va(){try{return d.activeElement}catch(a){}}function wa(a,b,c,d,e,f){var g,h;if("object"==typeof b){"string"!=typeof c&&(d=d||c,c=void 0);for(h in b)wa(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&("string"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=ua;else if(!e)return a;return 1===f&&(g=e,e=function(a){return r().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=r.guid++)),a.each(function(){r.event.add(this,b,e,d,c)})}r.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=V.get(a);if(q){c.handler&&(f=c,c=f.handler,e=f.selector),e&&r.find.matchesSelector(pa,e),c.guid||(c.guid=r.guid++),(i=q.events)||(i=q.events={}),(g=q.handle)||(g=q.handle=function(b){return"undefined"!=typeof r&&r.event.triggered!==b.type?r.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(K)||[""],j=b.length;while(j--)h=sa.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n&&(l=r.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=r.event.special[n]||{},k=r.extend({type:n,origType:p,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&r.expr.match.needsContext.test(e),namespace:o.join(".")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,o,g)!==!1||a.addEventListener&&a.addEventListener(n,g)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),r.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=V.hasData(a)&&V.get(a);if(q&&(i=q.events)){b=(b||"").match(K)||[""],j=b.length;while(j--)if(h=sa.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n){l=r.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp("(^|\\.)"+o.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&p!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,o,q.handle)!==!1||r.removeEvent(a,n,q.handle),delete i[n])}else for(n in i)r.event.remove(a,n+b[j],c,d,!0);r.isEmptyObject(i)&&V.remove(a,"handle events")}},dispatch:function(a){var b=r.event.fix(a),c,d,e,f,g,h,i=new Array(arguments.length),j=(V.get(this,"events")||{})[b.type]||[],k=r.event.special[b.type]||{};for(i[0]=b,c=1;c<arguments.length;c++)i[c]=arguments[c];if(b.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,b)!==!1){h=r.event.handlers.call(this,b,j),c=0;while((f=h[c++])&&!b.isPropagationStopped()){b.currentTarget=f.elem,d=0;while((g=f.handlers[d++])&&!b.isImmediatePropagationStopped())b.rnamespace&&!b.rnamespace.test(g.namespace)||(b.handleObj=g,b.data=g.data,e=((r.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(b.result=e)===!1&&(b.preventDefault(),b.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,b),b.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&("click"!==a.type||isNaN(a.button)||a.button<1))for(;i!==this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(d=[],c=0;c<h;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?r(e,this).index(i)>-1:r.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},addProp:function(a,b){Object.defineProperty(r.Event.prototype,a,{enumerable:!0,configurable:!0,get:r.isFunction(b)?function(){if(this.originalEvent)return b(this.originalEvent)}:function(){if(this.originalEvent)return this.originalEvent[a]},set:function(b){Object.defineProperty(this,a,{enumerable:!0,configurable:!0,writable:!0,value:b})}})},fix:function(a){return a[r.expando]?a:new r.Event(a)},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==va()&&this.focus)return this.focus(),!1},delegateType:"focusin"},blur:{trigger:function(){if(this===va()&&this.blur)return this.blur(),!1},delegateType:"focusout"},click:{trigger:function(){if("checkbox"===this.type&&this.click&&r.nodeName(this,"input"))return this.click(),!1},_default:function(a){return r.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}}},r.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c)},r.Event=function(a,b){return this instanceof r.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?ta:ua,this.target=a.target&&3===a.target.nodeType?a.target.parentNode:a.target,this.currentTarget=a.currentTarget,this.relatedTarget=a.relatedTarget):this.type=a,b&&r.extend(this,b),this.timeStamp=a&&a.timeStamp||r.now(),void(this[r.expando]=!0)):new r.Event(a,b)},r.Event.prototype={constructor:r.Event,isDefaultPrevented:ua,isPropagationStopped:ua,isImmediatePropagationStopped:ua,isSimulated:!1,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=ta,a&&!this.isSimulated&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=ta,a&&!this.isSimulated&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=ta,a&&!this.isSimulated&&a.stopImmediatePropagation(),this.stopPropagation()}},r.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,"char":!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(a){var b=a.button;return null==a.which&&qa.test(a.type)?null!=a.charCode?a.charCode:a.keyCode:!a.which&&void 0!==b&&ra.test(a.type)?1&b?1:2&b?3:4&b?2:0:a.which}},r.event.addProp),r.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){r.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return e&&(e===d||r.contains(d,e))||(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),r.fn.extend({on:function(a,b,c,d){return wa(this,a,b,c,d)},one:function(a,b,c,d){return wa(this,a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,r(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return b!==!1&&"function"!=typeof b||(c=b,b=void 0),c===!1&&(c=ua),this.each(function(){r.event.remove(this,a,c,b)})}});var xa=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,ya=/<script|<style|<link/i,za=/checked\s*(?:[^=]|=\s*.checked.)/i,Aa=/^true\/(.*)/,Ba=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;function Ca(a,b){return r.nodeName(a,"table")&&r.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a:a}function Da(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function Ea(a){var b=Aa.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function Fa(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(V.hasData(a)&&(f=V.access(a),g=V.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;c<d;c++)r.event.add(b,e,j[e][c])}W.hasData(a)&&(h=W.access(a),i=r.extend({},h),W.set(b,i))}}function Ga(a,b){var c=b.nodeName.toLowerCase();"input"===c&&ha.test(a.type)?b.checked=a.checked:"input"!==c&&"textarea"!==c||(b.defaultValue=a.defaultValue)}function Ha(a,b,c,d){b=g.apply([],b);var e,f,h,i,j,k,l=0,m=a.length,n=m-1,q=b[0],s=r.isFunction(q);if(s||m>1&&"string"==typeof q&&!o.checkClone&&za.test(q))return a.each(function(e){var f=a.eq(e);s&&(b[0]=q.call(this,e,f.html())),Ha(f,b,c,d)});if(m&&(e=oa(b,a[0].ownerDocument,!1,a,d),f=e.firstChild,1===e.childNodes.length&&(e=f),f||d)){for(h=r.map(la(e,"script"),Da),i=h.length;l<m;l++)j=e,l!==n&&(j=r.clone(j,!0,!0),i&&r.merge(h,la(j,"script"))),c.call(a[l],j,l);if(i)for(k=h[h.length-1].ownerDocument,r.map(h,Ea),l=0;l<i;l++)j=h[l],ja.test(j.type||"")&&!V.access(j,"globalEval")&&r.contains(k,j)&&(j.src?r._evalUrl&&r._evalUrl(j.src):p(j.textContent.replace(Ba,""),k))}return a}function Ia(a,b,c){for(var d,e=b?r.filter(b,a):a,f=0;null!=(d=e[f]);f++)c||1!==d.nodeType||r.cleanData(la(d)),d.parentNode&&(c&&r.contains(d.ownerDocument,d)&&ma(la(d,"script")),d.parentNode.removeChild(d));return a}r.extend({htmlPrefilter:function(a){return a.replace(xa,"<$1></$2>")},clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=r.contains(a.ownerDocument,a);if(!(o.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||r.isXMLDoc(a)))for(g=la(h),f=la(a),d=0,e=f.length;d<e;d++)Ga(f[d],g[d]);if(b)if(c)for(f=f||la(a),g=g||la(h),d=0,e=f.length;d<e;d++)Fa(f[d],g[d]);else Fa(a,h);return g=la(h,"script"),g.length>0&&ma(g,!i&&la(a,"script")),h},cleanData:function(a){for(var b,c,d,e=r.event.special,f=0;void 0!==(c=a[f]);f++)if(T(c)){if(b=c[V.expando]){if(b.events)for(d in b.events)e[d]?r.event.remove(c,d):r.removeEvent(c,d,b.handle);c[V.expando]=void 0}c[W.expando]&&(c[W.expando]=void 0)}}}),r.fn.extend({detach:function(a){return Ia(this,a,!0)},remove:function(a){return Ia(this,a)},text:function(a){return S(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)},append:function(){return Ha(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ca(this,a);b.appendChild(a)}})},prepend:function(){return Ha(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ca(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return Ha(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return Ha(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(r.cleanData(la(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null!=a&&a,b=null==b?a:b,this.map(function(){return r.clone(this,a,b)})},html:function(a){return S(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!ya.test(a)&&!ka[(ia.exec(a)||["",""])[1].toLowerCase()]){a=r.htmlPrefilter(a);try{for(;c<d;c++)b=this[c]||{},1===b.nodeType&&(r.cleanData(la(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=[];return Ha(this,arguments,function(b){var c=this.parentNode;r.inArray(this,a)<0&&(r.cleanData(la(this)),c&&c.replaceChild(b,this))},a)}}),r.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){r.fn[a]=function(a){for(var c,d=[],e=r(a),f=e.length-1,g=0;g<=f;g++)c=g===f?this:this.clone(!0),r(e[g])[b](c),h.apply(d,c.get());return this.pushStack(d)}});var Ja=/^margin/,Ka=new RegExp("^("+$+")(?!px)[a-z%]+$","i"),La=function(b){var c=b.ownerDocument.defaultView;return c&&c.opener||(c=a),c.getComputedStyle(b)};!function(){function b(){if(i){i.style.cssText="box-sizing:border-box;position:relative;display:block;margin:auto;border:1px;padding:1px;top:1%;width:50%",i.innerHTML="",pa.appendChild(h);var b=a.getComputedStyle(i);c="1%"!==b.top,g="2px"===b.marginLeft,e="4px"===b.width,i.style.marginRight="50%",f="4px"===b.marginRight,pa.removeChild(h),i=null}}var c,e,f,g,h=d.createElement("div"),i=d.createElement("div");i.style&&(i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",o.clearCloneStyle="content-box"===i.style.backgroundClip,h.style.cssText="border:0;width:8px;height:0;top:0;left:-9999px;padding:0;margin-top:1px;position:absolute",h.appendChild(i),r.extend(o,{pixelPosition:function(){return b(),c},boxSizingReliable:function(){return b(),e},pixelMarginRight:function(){return b(),f},reliableMarginLeft:function(){return b(),g}}))}();function Ma(a,b,c){var d,e,f,g,h=a.style;return c=c||La(a),c&&(g=c.getPropertyValue(b)||c[b],""!==g||r.contains(a.ownerDocument,a)||(g=r.style(a,b)),!o.pixelMarginRight()&&Ka.test(g)&&Ja.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+"":g}function Na(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}var Oa=/^(none|table(?!-c[ea]).+)/,Pa={position:"absolute",visibility:"hidden",display:"block"},Qa={letterSpacing:"0",fontWeight:"400"},Ra=["Webkit","Moz","ms"],Sa=d.createElement("div").style;function Ta(a){if(a in Sa)return a;var b=a[0].toUpperCase()+a.slice(1),c=Ra.length;while(c--)if(a=Ra[c]+b,a in Sa)return a}function Ua(a,b,c){var d=_.exec(b);return d?Math.max(0,d[2]-(c||0))+(d[3]||"px"):b}function Va(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;f<4;f+=2)"margin"===c&&(g+=r.css(a,c+aa[f],!0,e)),d?("content"===c&&(g-=r.css(a,"padding"+aa[f],!0,e)),"margin"!==c&&(g-=r.css(a,"border"+aa[f]+"Width",!0,e))):(g+=r.css(a,"padding"+aa[f],!0,e),"padding"!==c&&(g+=r.css(a,"border"+aa[f]+"Width",!0,e)));return g}function Wa(a,b,c){var d,e=!0,f=La(a),g="border-box"===r.css(a,"boxSizing",!1,f);if(a.getClientRects().length&&(d=a.getBoundingClientRect()[b]),d<=0||null==d){if(d=Ma(a,b,f),(d<0||null==d)&&(d=a.style[b]),Ka.test(d))return d;e=g&&(o.boxSizingReliable()||d===a.style[b]),d=parseFloat(d)||0}return d+Va(a,b,c||(g?"border":"content"),e,f)+"px"}r.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Ma(a,"opacity");return""===c?"1":c}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=r.camelCase(b),i=a.style;return b=r.cssProps[h]||(r.cssProps[h]=Ta(h)||h),g=r.cssHooks[b]||r.cssHooks[h],void 0===c?g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b]:(f=typeof c,"string"===f&&(e=_.exec(c))&&e[1]&&(c=da(a,b,e),f="number"),null!=c&&c===c&&("number"===f&&(c+=e&&e[3]||(r.cssNumber[h]?"":"px")),o.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),g&&"set"in g&&void 0===(c=g.set(a,c,d))||(i[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=r.camelCase(b);return b=r.cssProps[h]||(r.cssProps[h]=Ta(h)||h),g=r.cssHooks[b]||r.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=Ma(a,b,d)),"normal"===e&&b in Qa&&(e=Qa[b]),""===c||c?(f=parseFloat(e),c===!0||isFinite(f)?f||0:e):e}}),r.each(["height","width"],function(a,b){r.cssHooks[b]={get:function(a,c,d){if(c)return!Oa.test(r.css(a,"display"))||a.getClientRects().length&&a.getBoundingClientRect().width?Wa(a,b,d):ca(a,Pa,function(){return Wa(a,b,d)})},set:function(a,c,d){var e,f=d&&La(a),g=d&&Va(a,b,d,"border-box"===r.css(a,"boxSizing",!1,f),f);return g&&(e=_.exec(c))&&"px"!==(e[3]||"px")&&(a.style[b]=c,c=r.css(a,b)),Ua(a,c,g)}}}),r.cssHooks.marginLeft=Na(o.reliableMarginLeft,function(a,b){if(b)return(parseFloat(Ma(a,"marginLeft"))||a.getBoundingClientRect().left-ca(a,{marginLeft:0},function(){return a.getBoundingClientRect().left}))+"px"}),r.each({margin:"",padding:"",border:"Width"},function(a,b){r.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];d<4;d++)e[a+aa[d]+b]=f[d]||f[d-2]||f[0];return e}},Ja.test(a)||(r.cssHooks[a+b].set=Ua)}),r.fn.extend({css:function(a,b){return S(this,function(a,b,c){var d,e,f={},g=0;if(r.isArray(b)){for(d=La(a),e=b.length;g<e;g++)f[b[g]]=r.css(a,b[g],!1,d);return f}return void 0!==c?r.style(a,b,c):r.css(a,b)},a,b,arguments.length>1)}});function Xa(a,b,c,d,e){return new Xa.prototype.init(a,b,c,d,e)}r.Tween=Xa,Xa.prototype={constructor:Xa,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||r.easing._default,this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(r.cssNumber[c]?"":"px")},cur:function(){var a=Xa.propHooks[this.prop];return a&&a.get?a.get(this):Xa.propHooks._default.get(this)},run:function(a){var b,c=Xa.propHooks[this.prop];return this.options.duration?this.pos=b=r.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Xa.propHooks._default.set(this),this}},Xa.prototype.init.prototype=Xa.prototype,Xa.propHooks={_default:{get:function(a){var b;return 1!==a.elem.nodeType||null!=a.elem[a.prop]&&null==a.elem.style[a.prop]?a.elem[a.prop]:(b=r.css(a.elem,a.prop,""),b&&"auto"!==b?b:0)},set:function(a){r.fx.step[a.prop]?r.fx.step[a.prop](a):1!==a.elem.nodeType||null==a.elem.style[r.cssProps[a.prop]]&&!r.cssHooks[a.prop]?a.elem[a.prop]=a.now:r.style(a.elem,a.prop,a.now+a.unit)}}},Xa.propHooks.scrollTop=Xa.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},r.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2},_default:"swing"},r.fx=Xa.prototype.init,r.fx.step={};var Ya,Za,$a=/^(?:toggle|show|hide)$/,_a=/queueHooks$/;function ab(){Za&&(a.requestAnimationFrame(ab),r.fx.tick())}function bb(){return a.setTimeout(function(){Ya=void 0}),Ya=r.now()}function cb(a,b){var c,d=0,e={height:a};for(b=b?1:0;d<4;d+=2-b)c=aa[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function db(a,b,c){for(var d,e=(gb.tweeners[b]||[]).concat(gb.tweeners["*"]),f=0,g=e.length;f<g;f++)if(d=e[f].call(c,b,a))return d}function eb(a,b,c){var d,e,f,g,h,i,j,k,l="width"in b||"height"in b,m=this,n={},o=a.style,p=a.nodeType&&ba(a),q=V.get(a,"fxshow");c.queue||(g=r._queueHooks(a,"fx"),null==g.unqueued&&(g.unqueued=0,h=g.empty.fire,g.empty.fire=function(){g.unqueued||h()}),g.unqueued++,m.always(function(){m.always(function(){g.unqueued--,r.queue(a,"fx").length||g.empty.fire()})}));for(d in b)if(e=b[d],$a.test(e)){if(delete b[d],f=f||"toggle"===e,e===(p?"hide":"show")){if("show"!==e||!q||void 0===q[d])continue;p=!0}n[d]=q&&q[d]||r.style(a,d)}if(i=!r.isEmptyObject(b),i||!r.isEmptyObject(n)){l&&1===a.nodeType&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=q&&q.display,null==j&&(j=V.get(a,"display")),k=r.css(a,"display"),"none"===k&&(j?k=j:(ga([a],!0),j=a.style.display||j,k=r.css(a,"display"),ga([a]))),("inline"===k||"inline-block"===k&&null!=j)&&"none"===r.css(a,"float")&&(i||(m.done(function(){o.display=j}),null==j&&(k=o.display,j="none"===k?"":k)),o.display="inline-block")),c.overflow&&(o.overflow="hidden",m.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]})),i=!1;for(d in n)i||(q?"hidden"in q&&(p=q.hidden):q=V.access(a,"fxshow",{display:j}),f&&(q.hidden=!p),p&&ga([a],!0),m.done(function(){p||ga([a]),V.remove(a,"fxshow");for(d in n)r.style(a,d,n[d])})),i=db(p?q[d]:0,d,m),d in q||(q[d]=i.start,p&&(i.end=i.start,i.start=0))}}function fb(a,b){var c,d,e,f,g;for(c in a)if(d=r.camelCase(c),e=b[d],f=a[c],r.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=r.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function gb(a,b,c){var d,e,f=0,g=gb.prefilters.length,h=r.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=Ya||bb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;g<i;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),f<1&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:r.extend({},b),opts:r.extend(!0,{specialEasing:{},easing:r.easing._default},c),originalProperties:b,originalOptions:c,startTime:Ya||bb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=r.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;c<d;c++)j.tweens[c].run(1);return b?(h.notifyWith(a,[j,1,0]),h.resolveWith(a,[j,b])):h.rejectWith(a,[j,b]),this}}),k=j.props;for(fb(k,j.opts.specialEasing);f<g;f++)if(d=gb.prefilters[f].call(j,a,k,j.opts))return r.isFunction(d.stop)&&(r._queueHooks(j.elem,j.opts.queue).stop=r.proxy(d.stop,d)),d;return r.map(k,db,j),r.isFunction(j.opts.start)&&j.opts.start.call(a,j),r.fx.timer(r.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}r.Animation=r.extend(gb,{tweeners:{"*":[function(a,b){var c=this.createTween(a,b);return da(c.elem,a,_.exec(b),c),c}]},tweener:function(a,b){r.isFunction(a)?(b=a,a=["*"]):a=a.match(K);for(var c,d=0,e=a.length;d<e;d++)c=a[d],gb.tweeners[c]=gb.tweeners[c]||[],gb.tweeners[c].unshift(b)},prefilters:[eb],prefilter:function(a,b){b?gb.prefilters.unshift(a):gb.prefilters.push(a)}}),r.speed=function(a,b,c){var e=a&&"object"==typeof a?r.extend({},a):{complete:c||!c&&b||r.isFunction(a)&&a,duration:a,easing:c&&b||b&&!r.isFunction(b)&&b};return r.fx.off||d.hidden?e.duration=0:e.duration="number"==typeof e.duration?e.duration:e.duration in r.fx.speeds?r.fx.speeds[e.duration]:r.fx.speeds._default,null!=e.queue&&e.queue!==!0||(e.queue="fx"),e.old=e.complete,e.complete=function(){r.isFunction(e.old)&&e.old.call(this),e.queue&&r.dequeue(this,e.queue)},e},r.fn.extend({fadeTo:function(a,b,c,d){return this.filter(ba).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=r.isEmptyObject(a),f=r.speed(b,c,d),g=function(){var b=gb(this,r.extend({},a),f);(e||V.get(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=r.timers,g=V.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&_a.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));!b&&c||r.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=V.get(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=r.timers,g=d?d.length:0;for(c.finish=!0,r.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;b<g;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),r.each(["toggle","show","hide"],function(a,b){var c=r.fn[b];r.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(cb(b,!0),a,d,e)}}),r.each({slideDown:cb("show"),slideUp:cb("hide"),slideToggle:cb("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){r.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),r.timers=[],r.fx.tick=function(){var a,b=0,c=r.timers;for(Ya=r.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||r.fx.stop(),Ya=void 0},r.fx.timer=function(a){r.timers.push(a),a()?r.fx.start():r.timers.pop()},r.fx.interval=13,r.fx.start=function(){Za||(Za=a.requestAnimationFrame?a.requestAnimationFrame(ab):a.setInterval(r.fx.tick,r.fx.interval))},r.fx.stop=function(){a.cancelAnimationFrame?a.cancelAnimationFrame(Za):a.clearInterval(Za),Za=null},r.fx.speeds={slow:600,fast:200,_default:400},r.fn.delay=function(b,c){return b=r.fx?r.fx.speeds[b]||b:b,c=c||"fx",this.queue(c,function(c,d){var e=a.setTimeout(c,b);d.stop=function(){a.clearTimeout(e)}})},function(){var a=d.createElement("input"),b=d.createElement("select"),c=b.appendChild(d.createElement("option"));a.type="checkbox",o.checkOn=""!==a.value,o.optSelected=c.selected,a=d.createElement("input"),a.value="t",a.type="radio",o.radioValue="t"===a.value}();var hb,ib=r.expr.attrHandle;r.fn.extend({attr:function(a,b){return S(this,r.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){r.removeAttr(this,a)})}}),r.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return"undefined"==typeof a.getAttribute?r.prop(a,b,c):(1===f&&r.isXMLDoc(a)||(e=r.attrHooks[b.toLowerCase()]||(r.expr.match.bool.test(b)?hb:void 0)),void 0!==c?null===c?void r.removeAttr(a,b):e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:(a.setAttribute(b,c+""),c):e&&"get"in e&&null!==(d=e.get(a,b))?d:(d=r.find.attr(a,b),null==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&"radio"===b&&r.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}},removeAttr:function(a,b){var c,d=0,e=b&&b.match(K); +if(e&&1===a.nodeType)while(c=e[d++])a.removeAttribute(c)}}),hb={set:function(a,b,c){return b===!1?r.removeAttr(a,c):a.setAttribute(c,c),c}},r.each(r.expr.match.bool.source.match(/\w+/g),function(a,b){var c=ib[b]||r.find.attr;ib[b]=function(a,b,d){var e,f,g=b.toLowerCase();return d||(f=ib[g],ib[g]=e,e=null!=c(a,b,d)?g:null,ib[g]=f),e}});var jb=/^(?:input|select|textarea|button)$/i,kb=/^(?:a|area)$/i;r.fn.extend({prop:function(a,b){return S(this,r.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[r.propFix[a]||a]})}}),r.extend({prop:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return 1===f&&r.isXMLDoc(a)||(b=r.propFix[b]||b,e=r.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=r.find.attr(a,"tabindex");return b?parseInt(b,10):jb.test(a.nodeName)||kb.test(a.nodeName)&&a.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),o.optSelected||(r.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null},set:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex)}}),r.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){r.propFix[this.toLowerCase()]=this});var lb=/[\t\r\n\f]/g;function mb(a){return a.getAttribute&&a.getAttribute("class")||""}r.fn.extend({addClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).addClass(a.call(this,b,mb(this)))});if("string"==typeof a&&a){b=a.match(K)||[];while(c=this[i++])if(e=mb(c),d=1===c.nodeType&&(" "+e+" ").replace(lb," ")){g=0;while(f=b[g++])d.indexOf(" "+f+" ")<0&&(d+=f+" ");h=r.trim(d),e!==h&&c.setAttribute("class",h)}}return this},removeClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).removeClass(a.call(this,b,mb(this)))});if(!arguments.length)return this.attr("class","");if("string"==typeof a&&a){b=a.match(K)||[];while(c=this[i++])if(e=mb(c),d=1===c.nodeType&&(" "+e+" ").replace(lb," ")){g=0;while(f=b[g++])while(d.indexOf(" "+f+" ")>-1)d=d.replace(" "+f+" "," ");h=r.trim(d),e!==h&&c.setAttribute("class",h)}}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):r.isFunction(a)?this.each(function(c){r(this).toggleClass(a.call(this,c,mb(this),b),b)}):this.each(function(){var b,d,e,f;if("string"===c){d=0,e=r(this),f=a.match(K)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else void 0!==a&&"boolean"!==c||(b=mb(this),b&&V.set(this,"__className__",b),this.setAttribute&&this.setAttribute("class",b||a===!1?"":V.get(this,"__className__")||""))})},hasClass:function(a){var b,c,d=0;b=" "+a+" ";while(c=this[d++])if(1===c.nodeType&&(" "+mb(c)+" ").replace(lb," ").indexOf(b)>-1)return!0;return!1}});var nb=/\r/g,ob=/[\x20\t\r\n\f]+/g;r.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=r.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,r(this).val()):a,null==e?e="":"number"==typeof e?e+="":r.isArray(e)&&(e=r.map(e,function(a){return null==a?"":a+""})),b=r.valHooks[this.type]||r.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=r.valHooks[e.type]||r.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(nb,""):null==c?"":c)}}}),r.extend({valHooks:{option:{get:function(a){var b=r.find.attr(a,"value");return null!=b?b:r.trim(r.text(a)).replace(ob," ")}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type,g=f?null:[],h=f?e+1:d.length,i=e<0?h:f?e:0;i<h;i++)if(c=d[i],(c.selected||i===e)&&!c.disabled&&(!c.parentNode.disabled||!r.nodeName(c.parentNode,"optgroup"))){if(b=r(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=r.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=r.inArray(r.valHooks.option.get(d),f)>-1)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),r.each(["radio","checkbox"],function(){r.valHooks[this]={set:function(a,b){if(r.isArray(b))return a.checked=r.inArray(r(a).val(),b)>-1}},o.checkOn||(r.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var pb=/^(?:focusinfocus|focusoutblur)$/;r.extend(r.event,{trigger:function(b,c,e,f){var g,h,i,j,k,m,n,o=[e||d],p=l.call(b,"type")?b.type:b,q=l.call(b,"namespace")?b.namespace.split("."):[];if(h=i=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!pb.test(p+r.event.triggered)&&(p.indexOf(".")>-1&&(q=p.split("."),p=q.shift(),q.sort()),k=p.indexOf(":")<0&&"on"+p,b=b[r.expando]?b:new r.Event(p,"object"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=q.join("."),b.rnamespace=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:r.makeArray(c,[b]),n=r.event.special[p]||{},f||!n.trigger||n.trigger.apply(e,c)!==!1)){if(!f&&!n.noBubble&&!r.isWindow(e)){for(j=n.delegateType||p,pb.test(j+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),i=h;i===(e.ownerDocument||d)&&o.push(i.defaultView||i.parentWindow||a)}g=0;while((h=o[g++])&&!b.isPropagationStopped())b.type=g>1?j:n.bindType||p,m=(V.get(h,"events")||{})[b.type]&&V.get(h,"handle"),m&&m.apply(h,c),m=k&&h[k],m&&m.apply&&T(h)&&(b.result=m.apply(h,c),b.result===!1&&b.preventDefault());return b.type=p,f||b.isDefaultPrevented()||n._default&&n._default.apply(o.pop(),c)!==!1||!T(e)||k&&r.isFunction(e[p])&&!r.isWindow(e)&&(i=e[k],i&&(e[k]=null),r.event.triggered=p,e[p](),r.event.triggered=void 0,i&&(e[k]=i)),b.result}},simulate:function(a,b,c){var d=r.extend(new r.Event,c,{type:a,isSimulated:!0});r.event.trigger(d,null,b)}}),r.fn.extend({trigger:function(a,b){return this.each(function(){r.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];if(c)return r.event.trigger(a,b,c,!0)}}),r.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(a,b){r.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),r.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),o.focusin="onfocusin"in a,o.focusin||r.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){r.event.simulate(b,a.target,r.event.fix(a))};r.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=V.access(d,b);e||d.addEventListener(a,c,!0),V.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=V.access(d,b)-1;e?V.access(d,b,e):(d.removeEventListener(a,c,!0),V.remove(d,b))}}});var qb=a.location,rb=r.now(),sb=/\?/;r.parseXML=function(b){var c;if(!b||"string"!=typeof b)return null;try{c=(new a.DOMParser).parseFromString(b,"text/xml")}catch(d){c=void 0}return c&&!c.getElementsByTagName("parsererror").length||r.error("Invalid XML: "+b),c};var tb=/\[\]$/,ub=/\r?\n/g,vb=/^(?:submit|button|image|reset|file)$/i,wb=/^(?:input|select|textarea|keygen)/i;function xb(a,b,c,d){var e;if(r.isArray(b))r.each(b,function(b,e){c||tb.test(a)?d(a,e):xb(a+"["+("object"==typeof e&&null!=e?b:"")+"]",e,c,d)});else if(c||"object"!==r.type(b))d(a,b);else for(e in b)xb(a+"["+e+"]",b[e],c,d)}r.param=function(a,b){var c,d=[],e=function(a,b){var c=r.isFunction(b)?b():b;d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(null==c?"":c)};if(r.isArray(a)||a.jquery&&!r.isPlainObject(a))r.each(a,function(){e(this.name,this.value)});else for(c in a)xb(c,a[c],b,e);return d.join("&")},r.fn.extend({serialize:function(){return r.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=r.prop(this,"elements");return a?r.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!r(this).is(":disabled")&&wb.test(this.nodeName)&&!vb.test(a)&&(this.checked||!ha.test(a))}).map(function(a,b){var c=r(this).val();return null==c?null:r.isArray(c)?r.map(c,function(a){return{name:b.name,value:a.replace(ub,"\r\n")}}):{name:b.name,value:c.replace(ub,"\r\n")}}).get()}});var yb=/%20/g,zb=/#.*$/,Ab=/([?&])_=[^&]*/,Bb=/^(.*?):[ \t]*([^\r\n]*)$/gm,Cb=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Db=/^(?:GET|HEAD)$/,Eb=/^\/\//,Fb={},Gb={},Hb="*/".concat("*"),Ib=d.createElement("a");Ib.href=qb.href;function Jb(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(K)||[];if(r.isFunction(c))while(d=f[e++])"+"===d[0]?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Kb(a,b,c,d){var e={},f=a===Gb;function g(h){var i;return e[h]=!0,r.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function Lb(a,b){var c,d,e=r.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&r.extend(!0,a,d),a}function Mb(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader("Content-Type"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+" "+i[0]]){f=e;break}g||(g=e)}f=f||g}if(f)return f!==i[0]&&i.unshift(f),c[f]}function Nb(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}r.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:qb.href,type:"GET",isLocal:Cb.test(qb.protocol),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Hb,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":r.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Lb(Lb(a,r.ajaxSettings),b):Lb(r.ajaxSettings,a)},ajaxPrefilter:Jb(Fb),ajaxTransport:Jb(Gb),ajax:function(b,c){"object"==typeof b&&(c=b,b=void 0),c=c||{};var e,f,g,h,i,j,k,l,m,n,o=r.ajaxSetup({},c),p=o.context||o,q=o.context&&(p.nodeType||p.jquery)?r(p):r.event,s=r.Deferred(),t=r.Callbacks("once memory"),u=o.statusCode||{},v={},w={},x="canceled",y={readyState:0,getResponseHeader:function(a){var b;if(k){if(!h){h={};while(b=Bb.exec(g))h[b[1].toLowerCase()]=b[2]}b=h[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return k?g:null},setRequestHeader:function(a,b){return null==k&&(a=w[a.toLowerCase()]=w[a.toLowerCase()]||a,v[a]=b),this},overrideMimeType:function(a){return null==k&&(o.mimeType=a),this},statusCode:function(a){var b;if(a)if(k)y.always(a[y.status]);else for(b in a)u[b]=[u[b],a[b]];return this},abort:function(a){var b=a||x;return e&&e.abort(b),A(0,b),this}};if(s.promise(y),o.url=((b||o.url||qb.href)+"").replace(Eb,qb.protocol+"//"),o.type=c.method||c.type||o.method||o.type,o.dataTypes=(o.dataType||"*").toLowerCase().match(K)||[""],null==o.crossDomain){j=d.createElement("a");try{j.href=o.url,j.href=j.href,o.crossDomain=Ib.protocol+"//"+Ib.host!=j.protocol+"//"+j.host}catch(z){o.crossDomain=!0}}if(o.data&&o.processData&&"string"!=typeof o.data&&(o.data=r.param(o.data,o.traditional)),Kb(Fb,o,c,y),k)return y;l=r.event&&o.global,l&&0===r.active++&&r.event.trigger("ajaxStart"),o.type=o.type.toUpperCase(),o.hasContent=!Db.test(o.type),f=o.url.replace(zb,""),o.hasContent?o.data&&o.processData&&0===(o.contentType||"").indexOf("application/x-www-form-urlencoded")&&(o.data=o.data.replace(yb,"+")):(n=o.url.slice(f.length),o.data&&(f+=(sb.test(f)?"&":"?")+o.data,delete o.data),o.cache===!1&&(f=f.replace(Ab,""),n=(sb.test(f)?"&":"?")+"_="+rb++ +n),o.url=f+n),o.ifModified&&(r.lastModified[f]&&y.setRequestHeader("If-Modified-Since",r.lastModified[f]),r.etag[f]&&y.setRequestHeader("If-None-Match",r.etag[f])),(o.data&&o.hasContent&&o.contentType!==!1||c.contentType)&&y.setRequestHeader("Content-Type",o.contentType),y.setRequestHeader("Accept",o.dataTypes[0]&&o.accepts[o.dataTypes[0]]?o.accepts[o.dataTypes[0]]+("*"!==o.dataTypes[0]?", "+Hb+"; q=0.01":""):o.accepts["*"]);for(m in o.headers)y.setRequestHeader(m,o.headers[m]);if(o.beforeSend&&(o.beforeSend.call(p,y,o)===!1||k))return y.abort();if(x="abort",t.add(o.complete),y.done(o.success),y.fail(o.error),e=Kb(Gb,o,c,y)){if(y.readyState=1,l&&q.trigger("ajaxSend",[y,o]),k)return y;o.async&&o.timeout>0&&(i=a.setTimeout(function(){y.abort("timeout")},o.timeout));try{k=!1,e.send(v,A)}catch(z){if(k)throw z;A(-1,z)}}else A(-1,"No Transport");function A(b,c,d,h){var j,m,n,v,w,x=c;k||(k=!0,i&&a.clearTimeout(i),e=void 0,g=h||"",y.readyState=b>0?4:0,j=b>=200&&b<300||304===b,d&&(v=Mb(o,y,d)),v=Nb(o,v,y,j),j?(o.ifModified&&(w=y.getResponseHeader("Last-Modified"),w&&(r.lastModified[f]=w),w=y.getResponseHeader("etag"),w&&(r.etag[f]=w)),204===b||"HEAD"===o.type?x="nocontent":304===b?x="notmodified":(x=v.state,m=v.data,n=v.error,j=!n)):(n=x,!b&&x||(x="error",b<0&&(b=0))),y.status=b,y.statusText=(c||x)+"",j?s.resolveWith(p,[m,x,y]):s.rejectWith(p,[y,x,n]),y.statusCode(u),u=void 0,l&&q.trigger(j?"ajaxSuccess":"ajaxError",[y,o,j?m:n]),t.fireWith(p,[y,x]),l&&(q.trigger("ajaxComplete",[y,o]),--r.active||r.event.trigger("ajaxStop")))}return y},getJSON:function(a,b,c){return r.get(a,b,c,"json")},getScript:function(a,b){return r.get(a,void 0,b,"script")}}),r.each(["get","post"],function(a,b){r[b]=function(a,c,d,e){return r.isFunction(c)&&(e=e||d,d=c,c=void 0),r.ajax(r.extend({url:a,type:b,dataType:e,data:c,success:d},r.isPlainObject(a)&&a))}}),r._evalUrl=function(a){return r.ajax({url:a,type:"GET",dataType:"script",cache:!0,async:!1,global:!1,"throws":!0})},r.fn.extend({wrapAll:function(a){var b;return this[0]&&(r.isFunction(a)&&(a=a.call(this[0])),b=r(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this},wrapInner:function(a){return r.isFunction(a)?this.each(function(b){r(this).wrapInner(a.call(this,b))}):this.each(function(){var b=r(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=r.isFunction(a);return this.each(function(c){r(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(a){return this.parent(a).not("body").each(function(){r(this).replaceWith(this.childNodes)}),this}}),r.expr.pseudos.hidden=function(a){return!r.expr.pseudos.visible(a)},r.expr.pseudos.visible=function(a){return!!(a.offsetWidth||a.offsetHeight||a.getClientRects().length)},r.ajaxSettings.xhr=function(){try{return new a.XMLHttpRequest}catch(b){}};var Ob={0:200,1223:204},Pb=r.ajaxSettings.xhr();o.cors=!!Pb&&"withCredentials"in Pb,o.ajax=Pb=!!Pb,r.ajaxTransport(function(b){var c,d;if(o.cors||Pb&&!b.crossDomain)return{send:function(e,f){var g,h=b.xhr();if(h.open(b.type,b.url,b.async,b.username,b.password),b.xhrFields)for(g in b.xhrFields)h[g]=b.xhrFields[g];b.mimeType&&h.overrideMimeType&&h.overrideMimeType(b.mimeType),b.crossDomain||e["X-Requested-With"]||(e["X-Requested-With"]="XMLHttpRequest");for(g in e)h.setRequestHeader(g,e[g]);c=function(a){return function(){c&&(c=d=h.onload=h.onerror=h.onabort=h.onreadystatechange=null,"abort"===a?h.abort():"error"===a?"number"!=typeof h.status?f(0,"error"):f(h.status,h.statusText):f(Ob[h.status]||h.status,h.statusText,"text"!==(h.responseType||"text")||"string"!=typeof h.responseText?{binary:h.response}:{text:h.responseText},h.getAllResponseHeaders()))}},h.onload=c(),d=h.onerror=c("error"),void 0!==h.onabort?h.onabort=d:h.onreadystatechange=function(){4===h.readyState&&a.setTimeout(function(){c&&d()})},c=c("abort");try{h.send(b.hasContent&&b.data||null)}catch(i){if(c)throw i}},abort:function(){c&&c()}}}),r.ajaxPrefilter(function(a){a.crossDomain&&(a.contents.script=!1)}),r.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\b(?:java|ecma)script\b/},converters:{"text script":function(a){return r.globalEval(a),a}}}),r.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET")}),r.ajaxTransport("script",function(a){if(a.crossDomain){var b,c;return{send:function(e,f){b=r("<script>").prop({charset:a.scriptCharset,src:a.url}).on("load error",c=function(a){b.remove(),c=null,a&&f("error"===a.type?404:200,a.type)}),d.head.appendChild(b[0])},abort:function(){c&&c()}}}});var Qb=[],Rb=/(=)\?(?=&|$)|\?\?/;r.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=Qb.pop()||r.expando+"_"+rb++;return this[a]=!0,a}}),r.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(Rb.test(b.url)?"url":"string"==typeof b.data&&0===(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&Rb.test(b.data)&&"data");if(h||"jsonp"===b.dataTypes[0])return e=b.jsonpCallback=r.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(Rb,"$1"+e):b.jsonp!==!1&&(b.url+=(sb.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||r.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){void 0===f?r(a).removeProp(e):a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,Qb.push(e)),g&&r.isFunction(f)&&f(g[0]),g=f=void 0}),"script"}),o.createHTMLDocument=function(){var a=d.implementation.createHTMLDocument("").body;return a.innerHTML="<form></form><form></form>",2===a.childNodes.length}(),r.parseHTML=function(a,b,c){if("string"!=typeof a)return[];"boolean"==typeof b&&(c=b,b=!1);var e,f,g;return b||(o.createHTMLDocument?(b=d.implementation.createHTMLDocument(""),e=b.createElement("base"),e.href=d.location.href,b.head.appendChild(e)):b=d),f=B.exec(a),g=!c&&[],f?[b.createElement(f[1])]:(f=oa([a],b,g),g&&g.length&&r(g).remove(),r.merge([],f.childNodes))},r.fn.load=function(a,b,c){var d,e,f,g=this,h=a.indexOf(" ");return h>-1&&(d=r.trim(a.slice(h)),a=a.slice(0,h)),r.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(e="POST"),g.length>0&&r.ajax({url:a,type:e||"GET",dataType:"html",data:b}).done(function(a){f=arguments,g.html(d?r("<div>").append(r.parseHTML(a)).find(d):a)}).always(c&&function(a,b){g.each(function(){c.apply(this,f||[a.responseText,b,a])})}),this},r.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){r.fn[b]=function(a){return this.on(b,a)}}),r.expr.pseudos.animated=function(a){return r.grep(r.timers,function(b){return a===b.elem}).length};function Sb(a){return r.isWindow(a)?a:9===a.nodeType&&a.defaultView}r.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=r.css(a,"position"),l=r(a),m={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=r.css(a,"top"),i=r.css(a,"left"),j=("absolute"===k||"fixed"===k)&&(f+i).indexOf("auto")>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),r.isFunction(b)&&(b=b.call(a,c,r.extend({},h))),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),"using"in b?b.using.call(a,m):l.css(m)}},r.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){r.offset.setOffset(this,a,b)});var b,c,d,e,f=this[0];if(f)return f.getClientRects().length?(d=f.getBoundingClientRect(),d.width||d.height?(e=f.ownerDocument,c=Sb(e),b=e.documentElement,{top:d.top+c.pageYOffset-b.clientTop,left:d.left+c.pageXOffset-b.clientLeft}):d):{top:0,left:0}},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return"fixed"===r.css(c,"position")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),r.nodeName(a[0],"html")||(d=a.offset()),d={top:d.top+r.css(a[0],"borderTopWidth",!0),left:d.left+r.css(a[0],"borderLeftWidth",!0)}),{top:b.top-d.top-r.css(c,"marginTop",!0),left:b.left-d.left-r.css(c,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent;while(a&&"static"===r.css(a,"position"))a=a.offsetParent;return a||pa})}}),r.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c="pageYOffset"===b;r.fn[a]=function(d){return S(this,function(a,d,e){var f=Sb(a);return void 0===e?f?f[b]:a[d]:void(f?f.scrollTo(c?f.pageXOffset:e,c?e:f.pageYOffset):a[d]=e)},a,d,arguments.length)}}),r.each(["top","left"],function(a,b){r.cssHooks[b]=Na(o.pixelPosition,function(a,c){if(c)return c=Ma(a,b),Ka.test(c)?r(a).position()[b]+"px":c})}),r.each({Height:"height",Width:"width"},function(a,b){r.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){r.fn[d]=function(e,f){var g=arguments.length&&(c||"boolean"!=typeof e),h=c||(e===!0||f===!0?"margin":"border");return S(this,function(b,c,e){var f;return r.isWindow(b)?0===d.indexOf("outer")?b["inner"+a]:b.document.documentElement["client"+a]:9===b.nodeType?(f=b.documentElement,Math.max(b.body["scroll"+a],f["scroll"+a],b.body["offset"+a],f["offset"+a],f["client"+a])):void 0===e?r.css(b,c,h):r.style(b,c,e,h)},b,g?e:void 0,g)}})}),r.fn.extend({bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}}),r.parseJSON=JSON.parse,"function"==typeof define&&define.amd&&define("jquery",[],function(){return r});var Tb=a.jQuery,Ub=a.$;return r.noConflict=function(b){return a.$===r&&(a.$=Ub),b&&a.jQuery===r&&(a.jQuery=Tb),r},b||(a.jQuery=a.$=r),r}); diff --git a/priv/static/js/metricsgraphics.min.js b/priv/static/js/metricsgraphics.min.js new file mode 100644 index 0000000..19e96b7 --- /dev/null +++ b/priv/static/js/metricsgraphics.min.js @@ -0,0 +1 @@ +!function(t,e){"function"==typeof define&&define.amd?define(["d3"],e):"object"==typeof exports?module.exports=e(require("d3")):t.MG=e(t.d3)}(this,function(E){"use strict";var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function k(){return"undefined"!=typeof jQuery||"undefined"!=typeof $}function i(t,e){return t[e.x_accessor]>=e.processed.min_x&&t[e.x_accessor]<=e.processed.max_x&&t[e.y_accessor]>=e.processed.min_y&&t[e.y_accessor]<=e.processed.max_y}function u(t){return"[object Array]"===Object.prototype.toString.call(t)}function a(t){var e=t.map(function(t){return!0===u(t)&&0<t.length});return E.sum(e)===t.length}function n(t){var e=t.map(function(t){return!0==(e=t,"[object Object]"===Object.prototype.toString.call(e));var e});return E.sum(e)===t.length}function e(t){return u(e=t)&&0===e.length||n(t);var e}function w(t){return t.height-t.bottom}function v(t){return w(t)-t.buffer}function M(t){return t.top}function b(t){return M(t)+t.buffer}function G(t){return t.left}function Y(t){return G(t)+t.buffer}function A(t){return t.width-t.right}function P(t){return A(t)-t.buffer}function _(t){t.exit().remove()}function D(t,e){t.selectAll(e).remove()}function S(t,e){return t.append("g").classed(e,!0)}function r(t,e){var r=O(t.target),a=h(t.data),n=r.selectAll("line."+e).data(a);return n.enter().append("line").attr("class",e).attr("opacity",.3),_(n),_(n),n}function m(t,e,r){e.color_accessor?(t.attr("stroke",e.scalefns.colorf),t.classed(r,!1)):(t.attr("stroke",null),t.classed(r,!0))}function l(t,e){e&&t.attr({dy:0,transform:function(){var t=E.select(this);return"rotate("+e+" "+t.attr("x")+","+t.attr("y")+")"}})}function g(t){if(!(t=t.node()))return!1;for(var e=0;e<t.length;e++)if(o(t[e],t))return!0;return!1}function o(t,e){for(var r=t.getBoundingClientRect(),a=0;a<e.length;a++)if(e[a]!=t){var n=e[a].getBoundingClientRect();if(r.top===n.top&&!(n.left>r.right||n.right<r.left))return!0}return!1}function s(t,e){var r=h(t.data);return"string"==typeof(r=r[0][t[e+"_accessor"]])?"categorical":"numerical"}function O(t){return E.select(t).select("svg")}function h(t){var e=[];return e.concat.apply(e,t)}function z(t){if("string"==typeof t)return F(t);if(t instanceof window.HTMLElement){var e=t.getAttribute("data-mg-uid");return e||(void 0===MG._next_elem_id&&(MG._next_elem_id=0),e="mg-"+MG._next_elem_id++,t.setAttribute("data-mg-uid",e)),e}return console.warn("The specified target should be a string or an HTMLElement.",t),F(t)}function F(t){return t.replace(/[^a-zA-Z0-9 _-]+/g,"").replace(/ +?/g,"")}function d(t,e){return Number(E.select(t).style(e).replace(/px/g,""))}function f(t){return d(t,"width")}("undefined"==typeof window?global:window).MG={version:"2.11"},MG.convert={},MG.convert.date=function(t,e,r){r=void 0===r?"%Y-%m-%d":r;var a=E.timeParse(r);return t=t.map(function(t){return t[e]=a(t[e].trim()),t})},MG.convert.number=function(t,e){return t=t.map(function(t){return t[e]=Number(t[e]),t})},MG.time_format=function(t,e){return t?E.utcFormat(e):E.timeFormat(e)};var t=function(t,e,r){var a={};if(null===t)return t;if(Array.prototype.forEach&&t.forEach===Array.prototype.forEach)t.forEach(e,r);else if(t.length===+t.length){for(var n=0,o=t.length;n<o;n++)if(e.call(r,t[n],n,t)===a)return}else for(var i in t)if(e.call(r,t[i],i,t)===a)return;return t};function p(r){return t(Array.prototype.slice.call(arguments,1),function(t){if(t)for(var e in t)void 0===r[e]&&(r[e]=t[e])}),r}function x(t){return"[object Date]"===Object.prototype.toString.call(t)}function y(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function C(t){return"[object Function]"===Object.prototype.toString.call(t)}function T(t,e){var r,a=[],n=[];for(r=0;r<e.length;r++)a[e[r]]=!0;for(r=0;r<t.length;r++)a[t[r]]||n.push(t[r]);return n}function R(t,e){console.warn("Deprecation: "+t+(e?". This feature will be removed in "+e+".":" the near future.")),console.trace()}function L(t,e,r){var a,n=0;for(t.textContent=e,a=t.getBBox();a.width>r&&(t.textContent=e.slice(0,--n)+"...",a=t.getBBox(),"..."!==t.textContent););}function j(t){var e=O(t.target);if(e.select(".mg-header").remove(),t.target&&t.title){var r=e.insert("text").attr("class","mg-header").attr("x",t.center_title_full_width?t.width/2:(t.width+t.left-t.right)/2).attr("y",t.title_y_position).attr("text-anchor","middle").attr("dy","0.55em");if(r.append("tspan").attr("class","mg-chart-title").text(t.title),t.show_tooltips&&t.description&&k()){r.append("tspan").attr("class","mg-chart-description").attr("dx","0.3em").text("");var a=$(r.node());a.popover({html:!0,animation:!1,placement:"top",content:t.description,container:t.target,trigger:"manual",template:'<div class="popover mg-popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'}).on("mouseenter",function(){E.selectAll(t.target).selectAll(".mg-popover").remove(),$(this).popover("show"),$(E.select(t.target).select(".popover").node()).on("mouseleave",function(){a.popover("hide")})}).on("mouseleave",function(){setTimeout(function(){$(".popover:hover").length||a.popover("hide")},120)})}else t.show_tooltips&&t.description&&"undefined"==typeof $&&(t.error="In order to enable tooltips, please make sure you include jQuery.")}t.error&&Xe(t)}function X(e,t,r,a,n){e.scalefns[t]=function(t){return void 0===n?e.scales[r](t[a]):e.scales[r](t[a])+n}}function U(t,e){return"bottom"===t||"top"===t?[Y(e),P(e)]:"left"===t||"right"===t?[v(e),e.top]:void 0}function N(t,e){return E.set(t.map(function(t){return t[e]})).values()}function B(e){var t;return null===e.color_domain?"number"===e.color_type?t=E.extent(e.data[0],function(t){return t[e.color_accessor]}):"category"===e.color_type&&(t=N(e.data[0],e.color_accessor)):t=e.color_domain,t}function I(t){return null===t.color_range?"number"===t.color_type?["blue","red"]:null:t.color_range}function H(t,e,r){var a=xt(t),n=a.secondary(t.processed.min_x,t.processed.max_x);0===n.length&&(n=[t.scales.X.ticks(t.xax_count)[0]]);var o,i,s,c=S(r,"mg-year-marker");"default"===a.timeframe&&t.show_year_markers&&(o=t,i=c,s=n,a.yformat,i.selectAll(".mg-year-marker").data(s).enter().append("line").attr("x1",function(t){return o.scales.X(t).toFixed(2)}).attr("x2",function(t){return o.scales.X(t).toFixed(2)}).attr("y1",M(o)).attr("y2",w(o))),"years"!=a.tick_diff_timeframe&&function(t,e,r,a,n){var o,i,s,c,l,u=e.position,d=e.namespace,f=t.scales[d.toUpperCase()],p=E.select(t.target).select(".mg-x-axis text").node().getBoundingClientRect();"top"===u&&(o=function(t,e){return f(t).toFixed(2)},i=M(t)-7*t.xax_tick_length/3-p.height,s=".50em",c="middle",l=function(t){return n(new Date(t))});"bottom"===u&&(o=function(t,e){return f(t).toFixed(2)},i=w(t)+7*t.xax_tick_length/3+.8*p.height,s=".50em",c="middle",l=function(t){return n(new Date(t))});r.selectAll(".mg-year-marker").data(a).enter().append("text").attr("x",o).attr("y",i).attr("dy",s).attr("text-anchor",c).text(l)}(t,e,c,n,a.yformat)}function q(t,a,e){var r,n,o,i,s,c,l,u=e.namespace,d=(r=a,o=(n=e).position,i=n.namespace,s=r[i+"ax_tick_length"],c=r.scales[i.toUpperCase()],l={},"left"===o&&(l.x=G(r)-3*s/2,l.y=function(t){return c(t).toFixed(2)},l.dx=-3,l.dy=".35em",l.textAnchor="end",l.text=function(t){return J(r)(t)}),"right"===o&&(l.x=A(r)+3*s/2,l.y=function(t){return c(t).toFixed(2)},l.dx=3,l.dy=".35em",l.textAnchor="start",l.text=function(t){return J(r)(t)}),"top"===o&&(l.x=function(t){return c(t).toFixed(2)},l.y=(M(r)-7*s/3).toFixed(2),l.dx=0,l.dy="0em",l.textAnchor="middle",l.text=function(t){return ht(r)(t)}),"bottom"===o&&(l.x=function(t){return c(t).toFixed(2)},l.y=(w(r)+7*s/3).toFixed(2),l.dx=0,l.dy=".50em",l.textAnchor="middle",l.text=function(t){return ht(r)(t)}),l),f=a.processed[u+"_ticks"],p=t.selectAll(".mg-yax-labels").data(f).enter().append("text").attr("x",d.x).attr("dx",d.dx).attr("y",d.y).attr("dy",d.dy).attr("text-anchor",d.textAnchor).text(d.text);("x"==u&&(a.time_series&&a.european_clock?(p.append("tspan").classed("mg-european-hours",!0).text(function(t,e){var r=new Date(t);return 0===e?E.timeFormat("%H")(r):""}),p.append("tspan").classed("mg-european-minutes-seconds",!0).text(function(t,e){var r=new Date(t);return":"+a.processed.xax_format(r)})):p.text(function(t){return a.xax_units+a.processed.xax_format(t)}),a.time_series&&(a.show_years||a.show_secondary_x_label)&&H(a,e,t)),g(p))&&(p.filter(function(t,e){return(e+1)%2==0}).remove(),O(a.target).selectAll(".mg-"+u+"ax-ticks").filter(function(t,e){return(e+1)%2==0}).remove())}function V(t,e,r){var a,n,o,i,s,c,l,u,d=r.namespace,f=e.processed[d+"_ticks"].length,p=(a=e,o=(n=r).namespace,i=n.position,s=a.processed[o+"_ticks"].length,c=a.processed[o+"_ticks"],l=a.scales[o.toUpperCase()],u={},"left"===i&&(u.x1=G(a),u.x2=G(a),u.y1=l(c[0]).toFixed(2),u.y2=l(c[s-1]).toFixed(2)),"right"===i&&(u.x1=A(a),u.x2=A(a),u.y1=l(c[0]).toFixed(2),u.y2=l(c[s-1]).toFixed(2)),"top"===i&&(u.x1=G(a),u.x2=A(a),u.y1=M(a),u.y2=M(a)),"bottom"===i&&(u.x1=G(a),u.x2=A(a),u.y1=w(a),u.y2=w(a)),"left"!==i&&"right"!==i||(a.axes_not_compact?(u.y1=w(a),u.y2=M(a)):s&&(u.y1=l(c[0]).toFixed(2),u.y2=l(c[s-1]).toFixed(2))),u);e[d+"_extended_ticks"]||e[d+"_extended_ticks"]||!f||t.append("line").attr("x1",p.x1).attr("x2",p.x2).attr("y1",p.y1).attr("y2",p.y2)}function W(t,e){t.rug_buffer_size="point"===t.chart_type?t.buffer/2:2*t.buffer/3;var r,a,n,o,i,s,c,l,u,d,f=(r=t,a="mg-"+e.namespace+"-rug",n=O(r.target),o=h(r.data),(i=n.selectAll("line."+a).data(o)).enter().append("svg:line").attr("class",a).attr("opacity",.3),_(i),_(i),i),p=(s=t,l=(c=e).position,u=c.namespace,d={},"left"===l&&(d.x1=G(s)+1,d.x2=G(s)+s.rug_buffer_size,d.y1=s.scalefns[u+"f"],d.y2=s.scalefns[u+"f"]),"right"===l&&(d.x1=A(s)-1,d.x2=A(s)-s.rug_buffer_size,d.y1=s.scalefns[u+"f"],d.y2=s.scalefns[u+"f"]),"top"===l&&(d.x1=s.scalefns[u+"f"],d.x2=s.scalefns[u+"f"],d.y1=M(s)+1,d.y2=M(s)+s.rug_buffer_size),"bottom"===l&&(d.x1=s.scalefns[u+"f"],d.x2=s.scalefns[u+"f"],d.y1=w(s)-1,d.y2=w(s)-s.rug_buffer_size),d);f.attr("x1",p.x1).attr("x2",p.x2).attr("y1",p.y1).attr("y2",p.y2),m(f,t,"mg-"+e.namespace+"-rug-mono")}function Q(p,_){var m=_.namespace,t="mg-"+m+"-axis",g=p.scales[m.toUpperCase()],e=p.scales[(m+"group").toUpperCase()],h=m+"group_accessor",r=O(p.target);D(r,"."+t);var x,y=S(r,t);(e.domain&&e.domain()?e.domain():["1"]).forEach(function(t){var e,r,a,n,o,i,s,c,l,u,d=(e=p,a=t,n=(r=_).namespace,o=r.position,i=e.scales[n.toUpperCase()],s=e.scales[(n+"group").toUpperCase()],c={cat:{},group:{}},"left"===o&&(c.cat.x=Y(e)-e.buffer,c.cat.y=function(t){return s(a)+i(t)+i.bandwidth()/2},c.cat.dy=".35em",c.cat.textAnchor="end",c.group.x=Y(e)-e.buffer,c.group.y=s(a)+(s.bandwidth?s.bandwidth()/2:0),c.group.dy=".35em",c.group.textAnchor=(e["rotate_"+n+"_labels"],"end")),"right"===o&&(c.cat.x=P(e)-e.buffer,c.cat.y=function(t){return s(a)+i(t)+i.bandwidth()/2},c.cat.dy=".35em",c.cat.textAnchor="start",c.group.x=P(e)-e.buffer,c.group.y=s(a)+(s.bandwidth?s.bandwidth()/2:0),c.group.dy=".35em",c.group.textAnchor="start"),"top"===o&&(c.cat.x=function(t){return s(a)+i(t)+i.bandwidth()/2},c.cat.y=b(e)+e.buffer,c.cat.dy=".35em",c.cat.textAnchor=e["rotate_"+n+"_labels"]?"start":"middle",c.group.x=s(a)+(s.bandwidth?s.bandwidth()/2:0),c.group.y=b(e)+e.buffer,c.group.dy=".35em",c.group.textAnchor=e["rotate_"+n+"_labels"]?"start":"middle"),"bottom"===o&&(c.cat.x=function(t){return s(a)+i(t)+i.bandwidth()/2},c.cat.y=v(e)+e.buffer,c.cat.dy=".35em",c.cat.textAnchor=e["rotate_"+n+"_labels"]?"start":"middle",c.group.x=s(a)+(s.bandwidth?s.bandwidth()/2-i.bandwidth()/2:0),c.group.y=v(e)+e.buffer,c.group.dy=".35em",c.group.textAnchor=e["rotate_"+n+"_labels"]?"start":"middle"),c);if(x=S(y,"mg-group-"+F(t)),null!==p[h])var f=x.append("text").classed("mg-barplot-group-label",!0).attr("x",d.group.x).attr("y",d.group.y).attr("dy",d.group.dy).attr("text-anchor",d.group.textAnchor).text(t);else f=x.selectAll("text").data(g.domain()).enter().append("text").attr("x",d.cat.x).attr("y",d.cat.y).attr("dy",d.cat.dy).attr("text-anchor",d.cat.textAnchor).text(String);p["rotate_"+m+"_labels"]&&(l=f,(u=p["rotate_"+m+"_labels"])&&l.attr("transform",function(){var t=E.select(this);return"rotate("+u+" "+t.attr("x")+","+t.attr("y")+")"}))})}MG.merge_with_defaults=p,MG.clone=function(t){var e,r;if(null===t||"object"!==(void 0===t?"undefined":c(t)))return t;if(x(t))return(e=new Date).setTime(t.getTime()),e;if(y(t)){e=[];for(var a=0,n=t.length;a<n;a++)e[a]=MG.clone(t[a]);return e}if(r=t,"[object Object]"===Object.prototype.toString.call(r)){for(var o in e={},t)t.hasOwnProperty(o)&&(e[o]=MG.clone(t[o]));return e}throw new Error("Unable to copy obj! Its type isn't supported.")},MG.arr_diff=T,MG.warn_deprecation=R,MG.truncate_text=L,MG.wrap_text=function(t,i,s,c){t.each(function(){for(var t,e=E.select(this),r=e.text().split(s||/\s+/).reverse(),a=[],n=0,o=(e.attr("y"),e.text(null).append("tspan").attr("x",0).attr("y","0em").attr(c||{}));t=r.pop();)a.push(t),o.text(a.join(" ")),(null===i||o.node().getComputedTextLength()>i)&&(a.pop(),o.text(a.join(" ")),a=[t],o=e.append("tspan").attr("x",0).attr("y",1.1*++n+0+"em").attr(c||{}).text(t))})},MG.register=function(t,e,r){MG.charts[t]={descriptor:e,defaults:r||{}}},MG._hooks={},MG.add_hook=function(t,e,r){var a;if(MG._hooks[t]||(MG._hooks[t]=[]),0<(a=MG._hooks[t]).filter(function(t){return t.func===e}).length)throw"That function is already registered.";a.push({func:e,context:r})},MG.call_hook=function(t){var r,e=MG._hooks[t],a=[].slice.apply(arguments,[1]);return e&&e.forEach(function(t){if(t.func){var e=r||a;e&&e.constructor!==Array&&(e=[e]),e=[].concat.apply([],e),r=t.func.apply(t.context,e)}}),r||a},MG.globals={},MG.deprecations={rollover_callback:{replacement:"mouseover",version:"2.0"},rollout_callback:{replacement:"mouseout",version:"2.0"},x_rollover_format:{replacement:"x_mouseover",version:"2.10"},y_rollover_format:{replacement:"y_mouseover",version:"2.10"},show_years:{replacement:"show_secondary_x_label",version:"2.1"},xax_start_at_min:{replacement:"axes_not_compact",version:"2.7"},interpolate_tension:{replacement:"interpolate",version:"2.10"}},MG.globals.link=!1,MG.globals.version="1.1",MG.charts={},MG.data_graphic=function(t){var e={missing_is_zero:!1,missing_is_hidden:!1,missing_is_hidden_accessor:null,legend:"",legend_target:"",error:"",animate_on_load:!1,top:65,title_y_position:10,center_title_full_width:!1,bottom:45,right:10,left:50,buffer:8,width:350,height:220,full_width:!1,full_height:!1,small_height_threshold:120,small_width_threshold:160,xax_count:6,xax_tick_length:5,axes_not_compact:!0,yax_count:3,yax_tick_length:5,x_extended_ticks:!1,y_extended_ticks:!1,y_scale_type:"linear",max_x:null,max_y:null,min_x:null,min_y:null,min_y_from_data:!1,point_size:2.5,active_point_on_lines:!1,active_point_accessor:"active",active_point_size:2,points_always_visible:!1,x_accessor:"date",xax_units:"",x_label:"",x_sort:!0,x_axis:!0,y_axis:!0,x_axis_position:"bottom",y_axis_position:"left",x_axis_type:null,y_axis_type:null,ygroup_accessor:null,xgroup_accessor:null,y_padding_percentage:.05,y_outer_padding_percentage:.1,ygroup_padding_percentage:.25,ygroup_outer_padding_percentage:0,x_padding_percentage:.05,x_outer_padding_percentage:.1,xgroup_padding_percentage:.25,xgroup_outer_padding_percentage:0,y_categorical_show_guides:!1,x_categorical_show_guide:!1,rotate_x_labels:0,rotate_y_labels:0,y_accessor:"value",y_label:"",yax_units:"",yax_units_append:!1,x_rug:!1,y_rug:!1,mouseover_align:"right",x_mouseover:null,y_mouseover:null,transition_on_update:!0,mouseover:null,click:null,show_rollover_text:!0,show_confidence_band:null,xax_format:null,area:!0,flip_area_under_y_value:null,chart_type:"line",data:[],decimals:2,format:"count",inflator:10/9,linked:!1,linked_format:"%Y-%m-%d",list:!1,baselines:null,markers:null,scalefns:{},scales:{},utc_time:!1,european_clock:!1,show_year_markers:!1,show_secondary_x_label:!0,target:"#viz",interpolate:E.curveCatmullRom.alpha(0),custom_line_color_map:[],colors:null,max_data_size:null,aggregate_rollover:!1,show_tooltips:!0,showActivePoint:!0,brush:null,zoom_target:null,brushing_selection_changed:null};MG.call_hook("global.defaults",e),t||(t={});var r=MG.charts[t.chart_type||e.chart_type];for(var a in p(t,r.defaults,e),t.list&&(t.x_accessor=0,t.y_accessor=1),MG.deprecations)if(t.hasOwnProperty(a)){var n=MG.deprecations[a],o="Use of `args."+a+"` has been deprecated",i=n.replacement;if(i&&(t[i]?o+=". The replacement - `args."+i+"` - has already been defined. This definition will be discarded.":t[i]=t[a]),n.warned)continue;n.warned=!0,i&&(o+=" in favor of `args."+i+"`"),R(o,n.version)}return MG.call_hook("global.before_init",t),new r.descriptor(t),t.data},k()&&(function(m){var g=function(t,e){this.type=null,this.options=null,this.enabled=null,this.timeout=null,this.hoverState=null,this.$element=null,this.inState=null,this.init("tooltip",t,e)};g.VERSION="3.3.5",g.TRANSITION_DURATION=150,g.DEFAULTS={animation:!0,placement:"top",selector:!1,template:'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},g.prototype.init=function(t,e,r){if(this.enabled=!0,this.type=t,this.$element=m(e),this.options=this.getOptions(r),this.$viewport=this.options.viewport&&m(m.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var a=this.options.trigger.split(" "),n=a.length;n--;){var o=a[n];if("click"==o)this.$element.on("click."+this.type,this.options.selector,m.proxy(this.toggle,this));else if("manual"!=o){var i="hover"==o?"mouseenter":"focusin",s="hover"==o?"mouseleave":"focusout";this.$element.on(i+"."+this.type,this.options.selector,m.proxy(this.enter,this)),this.$element.on(s+"."+this.type,this.options.selector,m.proxy(this.leave,this))}}this.options.selector?this._options=m.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},g.prototype.getDefaults=function(){return g.DEFAULTS},g.prototype.getOptions=function(t){return(t=m.extend({},this.getDefaults(),this.$element.data(),t)).delay&&"number"==typeof t.delay&&(t.delay={show:t.delay,hide:t.delay}),t},g.prototype.getDelegateOptions=function(){var r={},a=this.getDefaults();return this._options&&m.each(this._options,function(t,e){a[t]!=e&&(r[t]=e)}),r},g.prototype.enter=function(t){var e=t instanceof this.constructor?t:m(t.currentTarget).data("bs."+this.type);if(e||(e=new this.constructor(t.currentTarget,this.getDelegateOptions()),m(t.currentTarget).data("bs."+this.type,e)),t instanceof m.Event&&(e.inState["focusin"==t.type?"focus":"hover"]=!0),e.tip().hasClass("in")||"in"==e.hoverState)e.hoverState="in";else{if(clearTimeout(e.timeout),e.hoverState="in",!e.options.delay||!e.options.delay.show)return e.show();e.timeout=setTimeout(function(){"in"==e.hoverState&&e.show()},e.options.delay.show)}},g.prototype.isInStateTrue=function(){for(var t in this.inState)if(this.inState[t])return!0;return!1},g.prototype.leave=function(t){var e=t instanceof this.constructor?t:m(t.currentTarget).data("bs."+this.type);if(e||(e=new this.constructor(t.currentTarget,this.getDelegateOptions()),m(t.currentTarget).data("bs."+this.type,e)),t instanceof m.Event&&(e.inState["focusout"==t.type?"focus":"hover"]=!1),!e.isInStateTrue()){if(clearTimeout(e.timeout),e.hoverState="out",!e.options.delay||!e.options.delay.hide)return e.hide();e.timeout=setTimeout(function(){"out"==e.hoverState&&e.hide()},e.options.delay.hide)}},g.prototype.show=function(){var t=m.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(t);var e=m.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(t.isDefaultPrevented()||!e)return;var r=this,a=this.tip(),n=this.getUID(this.type);this.setContent(),a.attr("id",n),this.$element.attr("aria-describedby",n),this.options.animation&&a.addClass("fade");var o="function"==typeof this.options.placement?this.options.placement.call(this,a[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,s=i.test(o);s&&(o=o.replace(i,"")||"top"),a.detach().css({top:0,left:0,display:"block"}).addClass(o).data("bs."+this.type,this),this.options.container?a.appendTo(this.options.container):a.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var c=this.getPosition(),l=a[0].offsetWidth,u=a[0].offsetHeight;if(s){var d=o,f=this.getPosition(this.$viewport);o="bottom"==o&&c.bottom+u>f.bottom?"top":"top"==o&&c.top-u<f.top?"bottom":"right"==o&&c.right+l>f.width?"left":"left"==o&&c.left-l<f.left?"right":o,a.removeClass(d).addClass(o)}var p=this.getCalculatedOffset(o,c,l,u);this.applyPlacement(p,o);var _=function(){var t=r.hoverState;r.$element.trigger("shown.bs."+r.type),r.hoverState=null,"out"==t&&r.leave(r)};m.support.transition&&this.$tip.hasClass("fade")?a.one("bsTransitionEnd",_).emulateTransitionEnd(g.TRANSITION_DURATION):_()}},g.prototype.applyPlacement=function(t,e){var r=this.tip(),a=r[0].offsetWidth,n=r[0].offsetHeight,o=parseInt(r.css("margin-top"),10),i=parseInt(r.css("margin-left"),10);isNaN(o)&&(o=0),isNaN(i)&&(i=0),t.top+=o,t.left+=i,m.offset.setOffset(r[0],m.extend({using:function(t){r.css({top:Math.round(t.top),left:Math.round(t.left)})}},t),0),r.addClass("in");var s=r[0].offsetWidth,c=r[0].offsetHeight;"top"==e&&c!=n&&(t.top=t.top+n-c);var l=this.getViewportAdjustedDelta(e,t,s,c);l.left?t.left+=l.left:t.top+=l.top;var u=/top|bottom/.test(e),d=u?2*l.left-a+s:2*l.top-n+c,f=u?"offsetWidth":"offsetHeight";r.offset(t),this.replaceArrow(d,r[0][f],u)},g.prototype.replaceArrow=function(t,e,r){this.arrow().css(r?"left":"top",50*(1-t/e)+"%").css(r?"top":"left","")},g.prototype.setContent=function(){var t=this.tip(),e=this.getTitle();t.find(".tooltip-inner")[this.options.html?"html":"text"](e),t.removeClass("fade in top bottom left right")},g.prototype.hide=function(t){var e=this,r=m(this.$tip),a=m.Event("hide.bs."+this.type);function n(){"in"!=e.hoverState&&r.detach(),e.$element.removeAttr("aria-describedby").trigger("hidden.bs."+e.type),t&&t()}if(this.$element.trigger(a),!a.isDefaultPrevented())return r.removeClass("in"),m.support.transition&&r.hasClass("fade")?r.one("bsTransitionEnd",n).emulateTransitionEnd(g.TRANSITION_DURATION):n(),this.hoverState=null,this},g.prototype.fixTitle=function(){var t=this.$element;(t.attr("title")||"string"!=typeof t.attr("data-original-title"))&&t.attr("data-original-title",t.attr("title")||"").attr("title","")},g.prototype.hasContent=function(){return this.getTitle()},g.prototype.getPosition=function(t){var e=(t=t||this.$element)[0],r="BODY"==e.tagName,a=e.getBoundingClientRect();null==a.width&&(a=m.extend({},a,{width:a.right-a.left,height:a.bottom-a.top}));var n=r?{top:0,left:0}:t.offset(),o={scroll:r?document.documentElement.scrollTop||document.body.scrollTop:t.scrollTop()},i=r?{width:m(window).width(),height:m(window).height()}:null;return m.extend({},a,o,i,n)},g.prototype.getCalculatedOffset=function(t,e,r,a){return"bottom"==t?{top:e.top+e.height,left:e.left+e.width/2-r/2}:"top"==t?{top:e.top-a,left:e.left+e.width/2-r/2}:"left"==t?{top:e.top+e.height/2-a/2,left:e.left-r}:{top:e.top+e.height/2-a/2,left:e.left+e.width}},g.prototype.getViewportAdjustedDelta=function(t,e,r,a){var n={top:0,left:0};if(!this.$viewport)return n;var o=this.options.viewport&&this.options.viewport.padding||0,i=this.getPosition(this.$viewport);if(/right|left/.test(t)){var s=e.top-o-i.scroll,c=e.top+o-i.scroll+a;s<i.top?n.top=i.top-s:c>i.top+i.height&&(n.top=i.top+i.height-c)}else{var l=e.left-o,u=e.left+o+r;l<i.left?n.left=i.left-l:u>i.right&&(n.left=i.left+i.width-u)}return n},g.prototype.getTitle=function(){var t=this.$element,e=this.options;return t.attr("data-original-title")||("function"==typeof e.title?e.title.call(t[0]):e.title)},g.prototype.getUID=function(t){for(;t+=~~(1e6*Math.random()),document.getElementById(t););return t},g.prototype.tip=function(){if(!this.$tip&&(this.$tip=m(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},g.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},g.prototype.enable=function(){this.enabled=!0},g.prototype.disable=function(){this.enabled=!1},g.prototype.toggleEnabled=function(){this.enabled=!this.enabled},g.prototype.toggle=function(t){var e=this;t&&((e=m(t.currentTarget).data("bs."+this.type))||(e=new this.constructor(t.currentTarget,this.getDelegateOptions()),m(t.currentTarget).data("bs."+this.type,e))),t?(e.inState.click=!e.inState.click,e.isInStateTrue()?e.enter(e):e.leave(e)):e.tip().hasClass("in")?e.leave(e):e.enter(e)},g.prototype.destroy=function(){var t=this;clearTimeout(this.timeout),this.hide(function(){t.$element.off("."+t.type).removeData("bs."+t.type),t.$tip&&t.$tip.detach(),t.$tip=null,t.$arrow=null,t.$viewport=null})};var t=m.fn.tooltip;m.fn.tooltip=function(a){return this.each(function(){var t=m(this),e=t.data("bs.tooltip"),r="object"==(void 0===a?"undefined":c(a))&&a;!e&&/destroy|hide/.test(a)||(e||t.data("bs.tooltip",e=new g(this,r)),"string"==typeof a&&e[a]())})},m.fn.tooltip.Constructor=g,m.fn.tooltip.noConflict=function(){return m.fn.tooltip=t,this}}(jQuery),function(n){var o=function(t,e){this.init("popover",t,e)};if(!n.fn.tooltip)throw new Error("Popover requires tooltip.js");o.VERSION="3.3.5",o.DEFAULTS=n.extend({},n.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:'<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'}),((o.prototype=n.extend({},n.fn.tooltip.Constructor.prototype)).constructor=o).prototype.getDefaults=function(){return o.DEFAULTS},o.prototype.setContent=function(){var t=this.tip(),e=this.getTitle(),r=this.getContent();t.find(".popover-title")[this.options.html?"html":"text"](e),t.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof r?"html":"append":"text"](r),t.removeClass("fade top bottom left right in"),t.find(".popover-title").html()||t.find(".popover-title").hide()},o.prototype.hasContent=function(){return this.getTitle()||this.getContent()},o.prototype.getContent=function(){var t=this.$element,e=this.options;return t.attr("data-content")||("function"==typeof e.content?e.content.call(t[0]):e.content)},o.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var t=n.fn.popover;n.fn.popover=function(a){return this.each(function(){var t=n(this),e=t.data("bs.popover"),r="object"==(void 0===a?"undefined":c(a))&&a;!e&&/destroy|hide/.test(a)||(e||t.data("bs.popover",e=new o(this,r)),"string"==typeof a&&e[a]())})},n.fn.popover.Constructor=o,n.fn.popover.noConflict=function(){return n.fn.popover=t,this}}(jQuery)),MG.chart_title=j,MG.scale_factory=function(o){var i={use_inflator:!1,zero_bottom:!1,scaleType:"numerical"};return this.namespace=function(t){return i.namespace=t,i.namespace_accessor_name=i.namespace+"_accessor",i.scale_name=i.namespace.toUpperCase(),i.scalefn_name=i.namespace+"f",this},this.scaleName=function(t){return i.scale_name=t.toUpperCase(),i.scalefn_name=t+"f",this},this.inflateDomain=function(t){return i.use_inflator=t,this},this.zeroBottom=function(t){return i.zero_bottom=t,this},this.numericalDomainFromData=function(){var t,e=[];0<arguments.length&&(e=arguments);for(var r=0;r<o.data.length;r++)0<o.data[r].length&&(t=o.data[r]);i.is_time_series=!!x(t[0][o[i.namespace_accessor_name]]),X(o,i.scalefn_name,i.scale_name,o[i.namespace_accessor_name]),function(t,e,r){var a=e.namespace,n=e.namespace_accessor_name,o=e.use_inflator,i=e.zero_bottom,s=t[n],c=h(t.data).map(function(t){return t[s]}).concat(h(r));"log"===t[a+"_scale_type"]&&(c=c.filter(function(t){return 0<t}));var l=E.extent(c),u=l[0],d=l[1];i&&!t["min_"+a+"_from_data"]&&0<u&&!e.is_time_series&&(u="log"===t[a+"_scale_type"]?1:0),"log"!==t[a+"_scale_type"]&&u<0&&!e.is_time_series&&(u-=(u-u*t.inflator)*o),e.is_time_series||(d=d<0?d+(d-d*t.inflator)*o:d*(o?t.inflator:1)),u=null!=t["min_"+a]?t["min_"+a]:u,d=null!=t["max_"+a]?t["max_"+a]:d,u===d&&null==t["min_"+a]&&null==t["max_"+a]&&(x(u)?d=new Date(MG.clone(u).setDate(u.getDate()+1)):"number"==typeof u&&(d=u+1,t.xax_count=2)),t.processed["min_"+a]=u,t.processed["max_"+a]=d,t.processed["zoom_"+a]&&(t.processed["min_"+a]=t.processed["zoom_"+a][0],t.processed["max_"+a]=t.processed["zoom_"+a][1]),MG.call_hook("x_axis.process_min_max",t,t.processed.min_x,t.processed.max_x),MG.call_hook("y_axis.process_min_max",t,t.processed.min_y,t.processed.max_y)}(o,i,e,i.use_inflator);var a=o.utc_time?E.scaleUtc():E.scaleTime();return o.scales[i.scale_name]=i.is_time_series?a:C(o[i.namespace+"_scale_type"])?o.y_scale_type():"log"===o[i.namespace+"_scale_type"]?E.scaleLog():E.scaleLinear(),o.scales[i.scale_name].domain([o.processed["min_"+i.namespace],o.processed["max_"+i.namespace]]),i.scaleType="numerical",this},this.categoricalDomain=function(t){return o.scales[i.scale_name]=E.scaleOrdinal().domain(t),X(o,i.scalefn_name,i.scale_name,o[i.namespace_accessor_name]),this},this.categoricalDomainFromData=function(){var t=h(o.data);return i.categoricalVariables=E.set(t.map(function(t){return t[o[i.namespace_accessor_name]]})).values(),o.scales[i.scale_name]=E.scaleBand().domain(i.categoricalVariables),i.scaleType="categorical",this},this.numericalRange=function(t){return"string"==typeof t?o.scales[i.scale_name].range(U(t,o)):o.scales[i.scale_name].range(t),this},this.categoricalRangeBands=function(t,e){void 0===e&&(e=!1);var r=i.namespace,a=o[r+"_padding_percentage"],n=o[r+"_outer_padding_percentage"];return"string"==typeof t?o.scales[i.scale_name].range(U(t,o)).paddingInner(a).paddingOuter(n):o.scales[i.scale_name].range(t).paddingInner(a).paddingOuter(n),X(o,i.scalefn_name,i.scale_name,o[i.namespace_accessor_name],e?o.scales[i.scale_name].bandwidth()/2:0),this},this.categoricalRange=function(t){return o.scales[i.scale_name].range(t),X(o,i.scalefn_name,i.scale_name,o[i.namespace_accessor_name]),this},this.categoricalColorRange=function(){return o.scales[i.scale_name]=10<o.scales[i.scale_name].domain().length?E.scaleOrdinal(E.schemeCategory20):E.scaleOrdinal(E.schemeCategory10),o.scales[i.scale_name].domain(i.categoricalVariables),X(o,i.scalefn_name,i.scale_name,o[i.namespace_accessor_name]),this},this.clamp=function(t){return o.scales[i.scale_name].clamp(t),this},this};var Z={};function K(t){if(t.y_rug){t.rug_buffer_size="point"===t.chart_type?t.buffer/2:2*t.buffer/3;var e=r(t,"mg-y-rug");e.attr("x1",t.left+1).attr("x2",t.left+t.rug_buffer_size).attr("y1",t.scalefns.yf).attr("y2",t.scalefns.yf),m(e,t,"mg-y-rug-mono")}}function J(r){var t=r.yax_format;if(!t){var a=r.decimals;"count"===r.format?(1<r.processed.y_ticks.length&&(a=Math.max(0,-Math.floor(Math.log(Math.abs(r.processed.y_ticks[1]-r.processed.y_ticks[0]))/Math.LN10))),t=function(t){var e;return e=0!==a?E.format(",."+a+"f"):t<1e3?E.format(",.0f"):E.format(",.2s"),r.yax_units_append?e(t)+r.yax_units:r.yax_units+e(t)}):t=function(t){return E.format(".0%")(t)}}return t}function tt(t){var e=O(t.target),r=t.scales.X.domain();if(r[0]<=0&&0<=r[1]){var a=t.scales.Y.range(),n=t.categorical_groups.length?t.scales.YGROUP(t.categorical_groups[t.categorical_groups.length-1]):t.scales.YGROUP();e.append("svg:line").attr("x1",t.scales.X(0)).attr("x2",t.scales.X(0)).attr("y1",a[0]+b(t)).attr("y2",a[a.length-1]+n).attr("stroke","black").attr("opacity",.2)}}function et(t,e){e.y_label&&t.append("text").attr("class","label").attr("x",function(){return-1*(b(e)+(v(e)-b(e))/2)}).attr("y",function(){return e.left/2}).attr("dy","-1.2em").attr("text-anchor","middle").text(function(t){return e.y_label}).attr("transform",function(t){return"rotate(-90)"})}function rt(t){t.processed||(t.processed={});var e=O(t.target);if(MG.call_hook("y_axis.process_min_max",t,t.processed.min_y,t.processed.max_y),D(e,".mg-y-axis"),!t.y_axis)return this;var r,a,n,o,i,s,c,l,u,d=S(e,"mg-y-axis");return et(d,t),ke(t,"y"),r=d,i=(a=t).processed.y_ticks.length,a.x_extended_ticks||a.y_extended_ticks||!i||(a.axes_not_compact&&"bar"!==a.chart_type?(n=a.height-a.bottom,o=a.top):i?(n=a.scales.Y(a.processed.y_ticks[0]).toFixed(2),o=a.scales.Y(a.processed.y_ticks[i-1]).toFixed(2)):o=n=0,r.append("line").attr("x1",a.left).attr("x2",a.left).attr("y1",n).attr("y2",o)),s=t,d.selectAll(".mg-yax-ticks").data(s.processed.y_ticks).enter().append("line").classed("mg-extended-yax-ticks",s.y_extended_ticks).attr("x1",s.left).attr("x2",function(){return s.y_extended_ticks?s.width-s.right:s.left-s.yax_tick_length}).attr("y1",function(t){return s.scales.Y(t).toFixed(2)}).attr("y2",function(t){return s.scales.Y(t).toFixed(2)}),c=d,u=J(l=t),c.selectAll(".mg-yax-labels").data(l.processed.y_ticks).enter().append("text").attr("x",l.left-3*l.yax_tick_length/2).attr("dx",-3).attr("y",function(t){return l.scales.Y(t).toFixed(2)}).attr("dy",".35em").attr("text-anchor","end").text(function(t){return u(t)}),t.y_rug&&K(t),this}function at(o){var t=O(o.target);D(t,".mg-y-axis");var i,s=S(t,"mg-y-axis");(o.categorical_groups.length?o.categorical_groups:["1"]).forEach(function(t){var e,r,a,n;(i=S(s,"mg-group-"+F(t)),null!==o.ygroup_accessor)?(a=t,n=o,i.append("svg:text").classed("mg-barplot-group-label",!0).attr("x",n.left-n.buffer).attr("y",n.scales.YGROUP(a)+n.scales.YGROUP.bandwidth()/2).attr("dy",".35em").attr("text-anchor","end").text(a)):l((e=t,r=o,i.selectAll("text").data(r.scales.Y.domain()).enter().append("svg:text").attr("x",r.left-r.buffer).attr("y",function(t){return r.scales.YGROUP(e)+r.scales.Y(t)+r.scales.Y.bandwidth()/2}).attr("dy",".35em").attr("text-anchor","end").text(String)),o.rotate_y_labels)})}function nt(t){if(t.x_rug){t.rug_buffer_size="point"===t.chart_type?t.buffer/2:t.buffer;var e=r(t,"mg-x-rug");e.attr("x1",t.scalefns.xf).attr("x2",t.scalefns.xf).attr("y1",t.height-t.bottom-t.rug_buffer_size).attr("y2",t.height-t.bottom),m(e,t,"mg-x-rug-mono")}}function ot(t){var e,r,a,n=O(t.target);if((e=t).processed||(e.processed={}),a=(r=t).chart_type,r.processed.xax_format||(r.xax_format?r.processed.xax_format=r.xax_format:"line"===a||"point"===a||"histogram"===a?r.processed.xax_format=ht(r):"bar"===a&&(r.processed.xax_format=ct(r))),D(n,".mg-x-axis"),!t.x_axis)return this;var o,i,s,c,l,u,d,f,p,_,m=S(n,"mg-x-axis");return o=m,ke(i=t,"x"),l=o,u=(c=i).scales.X.ticks(c.xax_count).length-1,c.x_extended_ticks||l.append("line").attr("x1",function(){return 0===c.xax_count?Y(c):c.axes_not_compact&&"bar"!==c.chart_type?c.left:c.scales.X(c.scales.X.ticks(c.xax_count)[0]).toFixed(2)}).attr("x2",function(){return 0===c.xax_count||c.axes_not_compact&&"bar"!==c.chart_type?A(c):c.scales.X(c.scales.X.ticks(c.xax_count)[u]).toFixed(2)}).attr("y1",c.height-c.bottom).attr("y2",c.height-c.bottom),s=i,o.selectAll(".mg-xax-ticks").data(s.processed.x_ticks).enter().append("line").attr("x1",function(t){return s.scales.X(t).toFixed(2)}).attr("x2",function(t){return s.scales.X(t).toFixed(2)}).attr("y1",s.height-s.bottom).attr("y2",function(){return s.x_extended_ticks?s.top:s.height-s.bottom+s.xax_tick_length}).attr("class",function(){if(s.x_extended_ticks)return"mg-extended-xax-ticks"}).classed("mg-xax-ticks",!0),function(a,t){var e=t.selectAll(".mg-xax-labels").data(a.processed.x_ticks).enter().append("text").attr("x",function(t){return a.scales.X(t).toFixed(2)}).attr("y",(a.height-a.bottom+7*a.xax_tick_length/3).toFixed(2)).attr("dy",".50em").attr("text-anchor","middle");if(a.time_series&&a.european_clock?(e.append("tspan").classed("mg-european-hours",!0).text(function(t,e){var r=new Date(t);return 0===e?E.timeFormat("%H")(r):""}),e.append("tspan").classed("mg-european-minutes-seconds",!0).text(function(t,e){var r=new Date(t);return":"+a.processed.xax_format(r)})):e.text(function(t){return a.xax_units+a.processed.xax_format(t)}),g(e)){e.filter(function(t,e){return(e+1)%2==0}).remove();var r=O(a.target);r.selectAll(".mg-xax-ticks").filter(function(t,e){return(e+1)%2==0}).remove()}}(f=t,d=m),_=d,(p=f).time_series&&(p.show_years||p.show_secondary_x_label)&&function(t,e){var r=xt(t),a=r.secondary(t.processed.min_x,t.processed.max_x);if(0===a.length){var n=t.scales.X.ticks(t.xax_count)[0];a=[n]}var o,i,s,c,l,u,d,f=S(e,"mg-year-marker");"default"===r.timeframe&&t.show_year_markers&&(o=t,i=f,s=a,r.yformat,i.selectAll(".mg-year-marker").data(s).enter().append("line").attr("x1",function(t){return o.scales.X(t).toFixed(2)}).attr("x2",function(t){return o.scales.X(t).toFixed(2)}).attr("y1",M(o)).attr("y2",w(o))),"years"!=r.tick_diff_time_frame&&(c=t,l=f,u=a,d=r.yformat,l.selectAll(".mg-year-marker").data(u).enter().append("text").attr("x",function(t,e){return c.scales.X(t).toFixed(2)}).attr("y",function(){var t=E.select(c.target).select(".mg-x-axis text").node().getBoundingClientRect();return w(c)+7*c.xax_tick_length/3+.8*t.height}).attr("dy",".50em").attr("text-anchor","middle").text(function(t){return d(new Date(t))}))}(p,_),t.x_label&&st(m,t),t.x_rug&&nt(t),this}function B(e){var t;return null===e.color_domain?"number"===e.color_type?t=E.extent(e.data[0],function(t){return t[e.color_accessor]}):"category"===e.color_type&&(t=E.set(e.data[0].map(function(t){return t[e.color_accessor]})).values()).sort():t=e.color_domain,t}function I(t){return null===t.color_range?"number"===t.color_type?["blue","red"]:null:t.color_range}function it(t){return null===t.size_range?[1,5]:t.size_range}function st(t,e){e.x_label&&t.append("text").attr("class","label").attr("x",function(){return Y(e)+(P(e)-Y(e))/2}).attr("dx",null!=e.x_label_nudge_x?e.x_label_nudge_x:0).attr("y",function(){var t=E.select(e.target).select(".mg-x-axis text").node().getBoundingClientRect();return w(e)+e.xax_tick_length*(7/3)+.8*t.height+10}).attr("dy",".5em").attr("text-anchor","middle").text(function(t){return e.x_label})}function ct(r){return function(t){if(t<1&&-1<t&&0!==t)return r.xax_units+t.toFixed(r.decimals);var e=E.format(",.0f");return r.xax_units+e(t)}}function lt(t){var e;return ut(t)?e="millis":dt(t)?e="seconds":ft(t)?e="less-than-a-day":pt(t)?e="four-days":_t(t)?e="many-days":mt(t)?e="many-months":e=365<=t/86400?"years":"default",e}function ut(t){return t<1}function dt(t){return t<60}function ft(t){return t/3600<24}function pt(t){return t/3600<96}function _t(t){return t/86400<60}function mt(t){return t/86400<365}function gt(t){if(t.time_series){var e=(t.processed.max_x-t.processed.min_x)/1e3,r=(t.processed.x_ticks[1]-t.processed.x_ticks[0])/1e3;t.processed.x_time_frame=lt(e),t.processed.x_tick_diff_time_frame=lt(r),t.processed.main_x_time_format=(a=t.utc_time,ut(n=r)?MG.time_format(a,"%M:%S.%L"):dt(n)?MG.time_format(a,"%M:%S"):ft(n)?MG.time_format(a,"%H:%M"):pt(n)||_t(n)?MG.time_format(a,"%b %d"):mt(n)?MG.time_format(a,"%b"):MG.time_format(a,"%Y"))}var a,n}function ht(r){if(r.xax_format)return r.xax_format;var t=h(r.processed.original_data||r.data)[0],a=t[r.processed.original_x_accessor||r.x_accessor];return void 0===a&&(a=t),function(t){return gt(r),x(a)?r.processed.main_x_time_format(new Date(t)):"number"==typeof a?(e=t%1!=0?E.format(",."+r.decimals+"f"):t<1e3?E.format(",.0f"):E.format(",.2s"),r.xax_units+e(t)):r.xax_units+t;var e}}function xt(t){var e={timeframe:t.processed.x_time_frame,tick_diff_timeframe:t.processed.x_tick_diff_time_frame};switch(e.timeframe){case"millis":case"seconds":e.secondary=E.timeDays,t.european_clock?e.yformat=MG.time_format(t.utc_time,"%b %d"):e.yformat=MG.time_format(t.utc_time,"%I %p");break;case"less-than-a-day":case"four-days":e.secondary=E.timeDays,e.yformat=MG.time_format(t.utc_time,"%b %d");break;case"many-days":case"many-months":e.secondary=E.timeYears,e.yformat=MG.time_format(t.utc_time,"%Y");break;default:e.secondary=E.timeYears,e.yformat=MG.time_format(t.utc_time,"%Y")}return e}function yt(t){var e=parseInt(t.width);t.full_width&&(e=f(t.target)),"categorical"===t.x_axis_type&&null===e&&(e=Dt(t,"x")),t.width=e}function vt(t){var e=parseInt(t.height);t.full_height&&(e=d(t.target,"height")),"categorical"===t.y_axis_type&&null===e&&(e=Dt(t,"y")),t.height=e}function bt(t,e){(!t.selectAll(".mg-main-line").empty()&&"line"!==e.chart_type||!t.selectAll(".mg-points").empty()&&"point"!==e.chart_type||!t.selectAll(".mg-histogram").empty()&&"histogram"!==e.chart_type||!t.selectAll(".mg-barplot").empty()&&"bar"!==e.chart_type)&&t.remove()}function wt(t,e){return O(e.target).empty()&&(t=E.select(e.target).append("svg").classed("linked",e.linked).attr("width",e.width).attr("height",e.height)),t}function kt(t,e){e.width!==Number(t.attr("width"))&&t.attr("width",e.width),e.height!==Number(t.attr("height"))&&t.attr("height",e.height)}function Mt(t,e){t.attr("viewBox","0 0 "+e.width+" "+e.height),(e.full_width||e.full_height)&&t.attr("preserveAspectRatio","xMinYMin meet")}function Gt(t,e){t.empty()&&console.warn('The specified target element "'+e.target+'" could not be found in the page. The chart will not be rendered.')}function At(t,e){var r,a,n,o="x"===e?t.width:t.height;!function(t,e){var r=t[e+"group_accessor"];if(t.categorical_groups=[],r){var a=t.data[0];t.categorical_groups=E.set(a.map(function(t){return t[r]})).values()}}(t,e),function(t,e){var r=t[e+"group_accessor"];if(t.total_bars=t.data[0].length,r){var a=(n=t.data[0],o=r,n.map(function(t){return t[o]}).reduce(function(t,e){return t[e]=t[e]+1||1,t},{}));a=E.max(Object.keys(a).map(function(t){return a[t]})),t.bars_per_group=a}else t.bars_per_group=t.data[0].length;var n,o}(t,e),function(t,e,r){var a=e+"group_height";if(r){var n="y"===e?(t.height-t.top-t.bottom-2*t.buffer)/(t.categorical_groups.length||1):(t.width-t.left-t.right-2*t.buffer)/(t.categorical_groups.length||1);t[a]=n}else{var o=(1+t[e+"_padding_percentage"])*t.bar_thickness;t[a]=t.bars_per_group*o+2*t[e+"_outer_padding_percentage"]*o}}(t,e,o),o&&(n=(r=t)[(a=e)+"group_height"]/(r.bars_per_group+r[a+"_outer_padding_percentage"]),r.bar_thickness=n-n*r[a+"_padding_percentage"])}function Dt(t,e){return t[e+"group_height"]*(t.categorical_groups.length||1)+("y"===e?t.top+t.bottom+2*t.buffer:t.left+t.right+2*t.buffer)+t.categorical_groups.length*t[e+"group_height"]*(t[e+"group_padding_percentage"]+t[e+"group_outer_padding_percentage"])}function Ot(t){var e;(e=t=t)||(e={}),e.processed||(e.processed={}),t=e=p(e,{target:null,title:null,description:null});var r=E.select(t.target);Gt(r,t);var a,n,o,i,s,c,l,u=r.selectAll("svg");return"categorical"===t.y_axis_type&&At(t,"y"),"categorical"===t.x_axis_type&&At(t,"x"),n=(a=t).chart_type,a.processed.xax_format||(a.xax_format?a.processed.xax_format=a.xax_format:"line"===n||"point"===n||"histogram"===n?a.processed.xax_format=ht(a):"bar"===n&&(a.processed.xax_format=ct(a))),i=h((o=t).processed.original_data||o.data)[0],o.time_series=x(i[o.processed.original_x_accessor||o.x_accessor]),yt(t),vt(t),bt(u,t),u=wt(u,t),c=t,(s=u).selectAll(".mg-clip-path").remove(),s.append("defs").attr("class","mg-clip-path").append("clipPath").attr("id","mg-plot-window-"+z(c.target)).append("svg:rect").attr("x",G(c)).attr("y",M(c)).attr("width",c.width-c.left-c.right-c.buffer).attr("height",c.height-c.top-c.bottom-c.buffer+1),kt(u,t),Mt(u,t),(l=u).classed("mg-missing",!1),l.selectAll(".mg-missing-text").remove(),l.selectAll(".mg-missing-pane").remove(),j(t),function(t,e){var r=0;if(t.selectAll(".mg-main-line").nodes().length>=e.data.length)if(0<e.custom_line_color_map.length){var a=T(function(t){for(var e=new Array(t),r=0;r<e.length;r++)e[r]=r+1;return e}(e.max_data_size),e.custom_line_color_map);for(r=0;r<a.length;r++)t.selectAll(".mg-main-line.mg-line"+a[r]+"-color").remove()}else{var n=e.data.length;for(r=t.selectAll(".mg-main-line").nodes()?t.selectAll(".mg-main-line").nodes().length:0;n<r;r--)t.selectAll(".mg-main-line.mg-line"+r+"-color").remove()}}(u,t),this}function zt(t){return t.label}function Ft(e){return function(t){return e.scales.X(t[e.x_accessor])>=Y(e)&&e.scales.X(t[e.x_accessor])<=P(e)}}function Ct(e){return function(t){return e.scales.X(t[e.x_accessor])}}function Tt(t){var e=t.scales.Y;return function(t){return e(t.value).toFixed(2)}}function Rt(t,e,r,a,n,o){var i;t&&(n(i=a.append("g").attr("class",e),r),o(i,r))}function Et(t,e){var r,a=(r=Ct(e),function(t){return r(t).toFixed(2)});t.selectAll(".mg-markers").data(e.markers.filter(Ft(e))).enter().append("line").attr("x1",a).attr("x2",a).attr("y1",e.top).attr("y2",v(e)).attr("class",function(t){return t.lineclass}).attr("stroke-dasharray","3,1")}function Yt(t,e){t.selectAll(".mg-markers").data(e.markers.filter(Ft(e))).enter().append("text").attr("class",function(t){return t.textclass||""}).classed("mg-marker-text",!0).attr("x",Ct(e)).attr("y","bottom"===e.x_axis_position?.95*M(e):w(e)+e.buffer).attr("text-anchor","middle").text(zt).each(function(t){t.click&&E.select(this).style("cursor","pointer").on("click",t.click),t.mouseover&&E.select(this).style("cursor","pointer").on("mouseover",t.mouseover),t.mouseout&&E.select(this).style("cursor","pointer").on("mouseout",t.mouseout)}),function(t,e){if(t&&1!=t.length)for(var r=0;r<t.length;r++)if(o(t[r],t)){var a=E.select(t[r]),n=+a.attr("y");n+8>=e.top&&(n=e.top-16),a.attr("y",n)}}(t.selectAll(".mg-marker-text").nodes(),e)}function $t(t,e){var r=Tt(e);t.selectAll(".mg-baselines").data(e.baselines).enter().append("line").attr("x1",Y(e)).attr("x2",P(e)).attr("y1",r).attr("y2",r)}function Pt(t,e){var r=Tt(e);t.selectAll(".mg-baselines").data(e.baselines).enter().append("text").attr("x",P(e)).attr("y",r).attr("dy",-3).attr("text-anchor","end").text(zt)}function St(t){var e,r,a,n,o,i=O(t.target);return(e=i).selectAll(".mg-markers").remove(),e.selectAll(".mg-baselines").remove(),a=i,Rt((r=t).markers,"mg-markers",r,a,Et,Yt),o=i,Rt((n=t).baselines,"mg-baselines",n,o,$t,Pt),this}function Lt(t){t.selectAll(".mg-active-datapoint-container").selectAll("*").remove()}function jt(t,e){t.select(".mg-active-datapoint").remove();var r,a="right"===e.mouseover_align?"end":"left"===e.mouseover_align?"start":"middle",n="right"===e.mouseover_align?P(e):"left"===e.mouseover_align?Y(e):(e.width-e.left-e.right)/2+e.left,o=t.select(".mg-active-datapoint-container").append("text").attr("class","mg-active-datapoint").attr("xml:space","preserve").attr("text-anchor",a),i=.75,s="bottom"===e.x_axis_position?M(e)*i:w(e)+3*e.buffer;e.markers&&t.selectAll(".mg-marker-text").each(function(){r?r!==E.select(this).attr("y")&&(i=.56):r=E.select(this).attr("y")});o.attr("transform","translate("+n+","+s+")")}function Xt(t,e){jt(e.svg,t);var r,a,o={row_number:0,rargs:e,mouseover_row:function(t){return o.row_number+=1,e=o.row_number,r=o.text_container,a=t,n=r.append("tspan").attr("x",0).attr("y",1.1*e+"em"),{rargs:a,text:function(t){return e=t,{bold:function(){return r.attr("font-weight","bold")},font_size:function(t){return r.attr("font-size",t)},x:function(t){return r.attr("x",t)},y:function(t){return r.attr("y",t)},elem:r=n.append("tspan").text(e)};var e,r}};var e,r,a,n},text_container:(r=e.svg,a=r.select(".mg-active-datapoint"),a.selectAll("*").remove(),a)};return o}Z.categorical=function(t,e){e.namespace;Q(t,e),function(d,t){var f,p,_,m,e=t.namespace,g=(d.scalefns[e+"f"],d.scalefns[e+"groupf"],d.scales[(e+"group").toUpperCase()]),h=d.scales[e.toUpperCase()],x=t.position,r=O(d.target),a=g.domain&&g.domain()?g.domain():[null];D(r,".mg-category-guides");var y=S(r,"mg-category-guides");a.forEach(function(e){h.domain().forEach(function(t){"left"!==x&&"right"!==x||(f=Y(d),p=P(d),_=h(t)+g(e)+h.bandwidth()/2,m=h(t)+g(e)+h.bandwidth()/2),"top"!==x&&"bottom"!==x||(f=h(t)+g(e)+h.bandwidth()/2*(null===e),p=h(t)+g(e)+h.bandwidth()/2*(null===e),_=v(d),m=b(d)),y.append("line").attr("x1",f).attr("x2",p).attr("y1",_).attr("y2",m).attr("stroke-dasharray","2,1")});var t,r,a,n,o,i,s,c,l=g(e)+h(h.domain()[0])+h.bandwidth()/2*(null===e||"top"!==x&&"bottom"!=x),u=g(e)+h(h.domain()[h.domain().length-1])+h.bandwidth()/2*(null===e||"top"!==x&&"bottom"!=x);"left"!==x&&"right"!==x||(t=Y(d),r=Y(d),a=l,n=u,o=P(d),i=P(d),s=l,c=u),"bottom"!==x&&"top"!==x||(t=l,r=u,a=v(d),n=v(d),o=l,i=u,s=b(d),c=b(d)),y.append("line").attr("x1",t).attr("x2",r).attr("y1",a).attr("y2",n).attr("stroke-dasharray","2,1"),y.append("line").attr("x1",o).attr("x2",i).attr("y1",s).attr("y2",c).attr("stroke-dasharray","2,1")})}(t,e)},Z.numerical=function(t,e){var r=e.namespace,a=r+"_axis",n="mg-"+r+"-axis",o=O(t.target);if(D(o,"."+n),!t[a])return this;var i,s,c,l,u,d,f,p,_,m,g,h,x,y,v,b=S(o,n);return function(t,e){var r=t[e+"_accessor"],a=t.scales[e.toUpperCase()].ticks(t[e+"ax_count"]),n=t.processed["max_"+e];function o(t){return 1e3===t?3:1e6===t?7:Math.log(t)/Math.LN10}"log"===t[e+"_scale_type"]&&(a=a.filter(function(t){return Math.abs(o(t))%1<1e-6||Math.abs(o(t))%1>1-1e-6}));var i=a.length,s=!0;t.data.forEach(function(t,e){t.forEach(function(t,e){if(t[r]%1!=0)return s=!1})}),s&&n<i&&"count"===t.format&&(a=a.filter(function(t){return t%1==0})),t.processed[e+"_ticks"]=a}(t,r),V(b,t,e),i=b,s=t,p=(c=e).namespace,_=c.position,m=s.scales[p.toUpperCase()],g=s.processed[p+"_ticks"],h="mg-"+p+"ax-ticks",x="mg-extended-"+p+"ax-ticks",y=s[p+"_extended_ticks"],v=s[p+"ax_tick_length"],"left"===_&&(l=G(s),u=y?A(s):G(s)-v,d=function(t){return m(t).toFixed(2)},f=function(t){return m(t).toFixed(2)}),"right"===_&&(l=A(s),u=y?G(s):A(s)+v,d=function(t){return m(t).toFixed(2)},f=function(t){return m(t).toFixed(2)}),"top"===_&&(l=function(t){return m(t).toFixed(2)},u=function(t){return m(t).toFixed(2)},d=M(s),f=y?w(s):M(s)-v),"bottom"===_&&(l=function(t){return m(t).toFixed(2)},u=function(t){return m(t).toFixed(2)},d=w(s),f=y?M(s):w(s)+v),i.selectAll("."+h).data(g).enter().append("line").classed(x,y).attr("x1",l).attr("x2",u).attr("y1",d).attr("y2",f),q(b,t,e),t[r+"_label"]&&e.label(o.select(".mg-"+r+"-axis"),t),t[r+"_rug"]&&W(t,e),t.show_bar_zero&&tt(t),this},MG.axis_factory=function(t){var e={type:"numerical"};return this.namespace=function(t){return e.namespace=t,this},this.rug=function(t){return e.rug=t,this},this.label=function(t){return e.label=t,this},this.type=function(t){return e.type=t,this},this.position=function(t){return e.position=t,this},this.zeroLine=function(t){return e.zeroLine=t,this},this.draw=function(){return Z[e.type](t,e),this},this},MG.y_rug=K,MG.y_axis=rt,MG.y_axis_categorical=function(t){return t.y_axis&&(at(t),t.show_bar_zero&&tt(t),t.ygroup_accessor&&(r=O((e=t).target),(a=e.scales.YGROUP.domain())[0],a[a.length-1],r.select(".mg-category-guides").selectAll("mg-group-lines").data(a).enter().append("line").attr("x1",Y(e)).attr("x2",Y(e)).attr("y1",function(t){return e.scales.YGROUP(t)}).attr("y2",function(t){return e.scales.YGROUP(t)+e.ygroup_height}).attr("stroke-width",1)),t.y_categorical_show_guides&&(o=O((n=t).target),i=[],n.data[0].forEach(function(t){-1===i.indexOf(t[n.y_accessor])&&o.select(".mg-category-guides").append("line").attr("x1",Y(n)).attr("x2",P(n)).attr("y1",n.scalefns.yf(t)+n.scalefns.ygroupf(t)).attr("y2",n.scalefns.yf(t)+n.scalefns.ygroupf(t)).attr("stroke-dasharray","2,1")}))),this;var e,r,a,n,o,i},MG.x_rug=nt,MG.x_axis=ot,MG.x_axis_categorical=function(t){var e=O(t.target),r=0;"bar"===t.chart_type&&(r=t.buffer+5),mg_add_categorical_scale(t,"X",t.categorical_variables.reverse(),t.left,P(t)-r),X(t,"xf","X","value"),D(e,".mg-x-axis");var a=S(e,"mg-x-axis");return t.x_axis&&(n=a,o=t,i=r,s=n.selectAll("text").data(o.categorical_variables).enter().append("text"),s.attr("x",function(t){return o.scales.X(t)+o.scales.X.bandwidth()/2+o.buffer*o.bar_outer_padding_percentage+i/2}).attr("y",v(o)).attr("dy",".35em").attr("text-anchor","middle").text(String),o.truncate_x_labels&&s.each(function(t,e){var r=o.scales.X.bandwidth();L(this,t,r)}),l(s,o.rotate_x_labels)),this;var n,o,i,s},MG.init=Ot,MG.markers=St;var Ut=function(n,o){return function(a){return["x","y"].every(function(t){return!(t in o)||(e=a[n[t+"_accessor"]],r=o[t],e>Math.min(r[0],r[1])&&e<Math.max(r[0],r[1]));var e,r})}},Nt=function(e,r){var t=e.processed.raw_data||e.data;"raw_data"in e.processed||(e.processed.raw_domain={x:e.scales.X.domain(),y:e.scales.Y.domain()},e.processed.raw_data=t),"point"===e.chart_type&&(a(t)?e.data=t.map(function(t){return t.filter(Ut(e,r))}):e.data=t.filter(Ut(e,r))),["x","y"].forEach(function(t){t in r?e.processed["zoom_"+t]=r[t]:delete e.processed["zoom_"+t]}),e.processed.subplot&&(r!==e.processed.raw_domain?MG.create_brushing_pattern(e.processed.subplot,It(e.processed.subplot,r)):MG.remove_brushing_pattern(e.processed.subplot)),new MG.charts[e.chart_type||defaults.chart_type].descriptor(e)},Bt=function(r,a){return["x","y"].reduce(function(t,e){return e in a&&(t[e]=a[e].map(function(t){return+r.scales[e.toUpperCase()].invert(t)}),"y"===e&&t[e].reverse()),t},{})},It=function(r,a){return["x","y"].reduce(function(t,e){return e in a&&(t[e]=a[e].map(function(t){return+r.scales[e.toUpperCase()](t)}),"y"===e&&t[e].reverse()),t},{})};MG.convert_range_to_domain=Bt,MG.zoom_to_data_domain=Nt,MG.zoom_to_data_range=function(t,e){var r=Bt(t,e);Nt(t,r)},MG.zoom_to_raw_range=function(t){"raw_domain"in t.processed&&(Nt(t,t.processed.raw_domain),delete t.processed.raw_domain,delete t.processed.raw_data)};var Ht=function(t){return E.select(t.target).select(".mg-extent").size()?E.select(t.target).select(".mg-extent"):E.select(t.target).select(".mg-rollover-rect, .mg-voronoi").insert("g","*").classed("mg-brush",!0).append("rect").classed("mg-extent",!0)},qt=function(t,e){var r=e.x[0],a=e.x[1]-e.x[0],n=e.y[0],o=e.y[1]-e.y[0];Ht(t).attr("x",r).attr("width",a).attr("y",n).attr("height",o).attr("opacity",1)},Vt=function(t){Ht(t).attr("width",0).attr("height",0).attr("opacity",0)};MG.add_brush_function=function(t){if("categorical"===t.x_axis_type||"categorical"===t.y_axis_type)return console.warn('The option "brush" does not support axis type "categorical" currently.');t.zoom_target||(t.zoom_target=t),t.zoom_target!==t&&(t.zoom_target.processed.subplot=t);var i,r,s,a,e,c,n,o,l,u,d=void 0;switch(t.brush){case"x":d={x:!0,y:!1};break;case"y":d={x:!1,y:!0};break;case"xy":d={x:!0,y:!0};break;default:d={x:!0,y:!0}}r=(i=t).zoom_target,s=d,a=E.select(i.target).select("svg"),e=a.select(".mg-rollover-rect, .mg-voronoi"),c=e.node(),o=n=!1,l=[],u=function(){var t=i.left,e=i.width-i.right-i.buffer,r=i.top,a=i.height-i.bottom-i.buffer,n=E.mouse(c),o={};return o.x=s.x?[Math.max(t,Math.min(l[0],n[0])),Math.min(e,Math.max(l[0],n[0]))]:[t,e],o.y=s.y?[Math.max(r,Math.min(l[1],n[1])),Math.min(a,Math.max(l[1],n[1]))]:[r,a],o},e.classed("mg-brush-container",!0),e.on("mousedown."+i.target,function(){n=!(o=!0),l=E.mouse(c),a.classed("mg-brushed",!1),a.classed("mg-brushing-in-progress",!0),Vt(i)}),E.select(document).on("mousemove."+i.target,function(){o&&(n=!0,e.classed("mg-brushing",!0),qt(i,u()))}),E.select(document).on("mouseup."+i.target,function(){if(o){o=!1,a.classed("mg-brushing-in-progress",!1);var t=u();if(n)if(n=!1,r===i)MG.zoom_to_data_range(r,t),a.select(".mg-rollover-rect, .mg-voronoi").classed("mg-brushed",!0);else{var e=MG.convert_range_to_domain(i,t);MG.zoom_to_data_domain(r,e)}else MG.zoom_to_raw_range(r);C(i.brushing_selection_changed)&&i.brushing_selection_changed(i,t)}})},MG.create_brushing_pattern=qt,MG.remove_brushing_pattern=Vt;var Wt=new function(){var t,i=[];function s(){i.forEach(function(t){var e=E.select(t).select("svg");if(!e.empty()&&(0<e.node().parentNode.offsetWidth||0<e.node().parentNode.offsetHeight)){var r=0!==e.attr("width")?e.attr("height")/e.attr("width"):0,a=f(t);e.attr("width",a),e.attr("height",r*a)}})}return"undefined"!=typeof MutationObserver?t=MutationObserver:"undefined"!=typeof WebKitMutationObserver&&(t=WebKitMutationObserver),{add_target:function(n){if(0===i.length&&window.addEventListener("resize",s,!0),-1===i.indexOf(n)&&(i.push(n),t)){var o=new t(function(t){var e,r,a=E.select(n).node();a&&!t.some(function(t){for(var e=0;e<t.removedNodes.length;e++)if(t.removedNodes[e]===a)return!0})||(o.disconnect(),e=n,-1!==(r=i.indexOf(e))&&i.splice(r,1),0===i.length&&window.removeEventListener("resize",s,!0))});o.observe(E.select(n).node().parentNode,{childList:!0})}}}};function Qt(t){var e;((e=t).full_width||e.full_height)&&Wt.add_target(e.target)}k()&&function(s){if("function"==typeof s().dropdown)return;var c='[data-toggle="dropdown"]',a=function(t){s(t).on("click.bs.dropdown",this.toggle)};function o(a){a&&3===a.which||(s(".dropdown-backdrop").remove(),s(c).each(function(){var t=s(this),e=l(t),r={relatedTarget:this};e.hasClass("open")&&(e.trigger(a=s.Event("hide.bs.dropdown",r)),a.isDefaultPrevented()||(t.attr("aria-expanded","false"),e.removeClass("open").trigger("hidden.bs.dropdown",r)))}))}function l(t){var e=t.attr("data-target");e||(e=(e=t.attr("href"))&&/#[A-Za-z]/.test(e)&&e.replace(/.*(?=#[^\s]*$)/,""));var r=e&&s(e);return r&&r.length?r:t.parent()}a.VERSION="3.3.1",a.prototype.toggle=function(t){var e=s(this);if(!e.is(".disabled, :disabled")){var r=l(e),a=r.hasClass("open");if(o(),!a){"ontouchstart"in document.documentElement&&!r.closest(".navbar-nav").length&&s('<div class="dropdown-backdrop"/>').insertAfter(s(this)).on("click",o);var n={relatedTarget:this};if(r.trigger(t=s.Event("show.bs.dropdown",n)),t.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),r.toggleClass("open").trigger("shown.bs.dropdown",n)}return!1}},a.prototype.keydown=function(t){if(/(38|40|27|32)/.test(t.which)&&!/input|textarea/i.test(t.target.tagName)){var e=s(this);if(t.preventDefault(),t.stopPropagation(),!e.is(".disabled, :disabled")){var r=l(e),a=r.hasClass("open");if(!a&&27!=t.which||a&&27==t.which)return 27==t.which&&r.find(c).trigger("focus"),e.trigger("click");var n=" li:not(.divider):visible a",o=r.find('[role="menu"]'+n+', [role="listbox"]'+n);if(o.length){var i=o.index(t.target);38==t.which&&0<i&&i--,40==t.which&&i<o.length-1&&i++,~i||(i=0),o.eq(i).trigger("focus")}}}};var t=s.fn.dropdown;s.fn.dropdown=function(r){return this.each(function(){var t=s(this),e=t.data("bs.dropdown");e||t.data("bs.dropdown",e=new a(this)),"string"==typeof r&&e[r].call(t)})},s.fn.dropdown.Constructor=a,s.fn.dropdown.noConflict=function(){return s.fn.dropdown=t,this},s(document).on("click.bs.dropdown.data-api",o).on("click.bs.dropdown.data-api",".dropdown form",function(t){t.stopPropagation()}).on("click.bs.dropdown.data-api",c,a.prototype.toggle).on("keydown.bs.dropdown.data-api",c,a.prototype.keydown).on("keydown.bs.dropdown.data-api",'[role="menu"]',a.prototype.keydown).on("keydown.bs.dropdown.data-api",'[role="listbox"]',a.prototype.keydown)}(jQuery),MG.button_layout=function(t){return this.target=t,this.feature_set={},this.public_name={},this.sorters={},this.manual=[],this.manual_map={},this.manual_callback={},this._strip_punctuation=function(t){return t.replace(/[^a-zA-Z0-9 _]+/g,"").replace(/ +?/g,"")},this.data=function(t){return this._data=t,this},this.manual_button=function(t,e,r){return this.feature_set[t]=e,this.manual_map[this._strip_punctuation(t)]=t,this.manual_callback[t]=r,this},this.button=function(t){return 1<arguments.length&&(this.public_name[t]=arguments[1]),2<arguments.length&&(this.sorters[t]=arguments[2]),this.feature_set[t]=[],this},this.callback=function(t){return this._callback=t,this},this.display=function(){var e,t,r,a,n=this._callback,o=this.manual_callback,i=this.manual_map;r=Object.keys(this.feature_set);var s,c=function(t){return e[t]};for(s=0;s<this._data.length;s++){e=this._data[s],t=r.map(c);for(var l=0;l<r.length;l++)a=r[l],-1===this.feature_set[a].indexOf(t[l])&&this.feature_set[a].push(t[l])}for(a in this.feature_set)this.sorters.hasOwnProperty(a)&&this.feature_set[a].sort(this.sorters[a]);$(this.target).empty(),$(this.target).append("<div class='col-lg-12 segments text-center'></div>");var u=function(){var t,e=$(this).data("key"),r=$(this).data("feature");return $("."+r+"-btns button.btn span.title").html(e),i.hasOwnProperty(r)?(t=i[r],o[t](e)):n(r,e),!1};for(var d in this.feature_set){for(r=this.feature_set[d],$(this.target+" div.segments").append('<div class="btn-group '+this._strip_punctuation(d)+'-btns text-left"><button type="button" class="btn btn-default btn-lg dropdown-toggle" data-toggle="dropdown"><span class=\'which-button\'>'+(this.public_name.hasOwnProperty(d)?this.public_name[d]:d)+"</span><span class='title'>"+(this.manual_callback.hasOwnProperty(d)?this.feature_set[d][0]:"all")+'</span><span class="caret"></span></button><ul class="dropdown-menu" role="menu">'+(this.manual_callback.hasOwnProperty(d)?"":'<li><a href="#" data-feature="'+d+'" data-key="all">All</a></li>')+(this.manual_callback.hasOwnProperty(d)?"":'<li class="divider"></li>')+"</ul></div>"),s=0;s<r.length;s++)"all"!==r[s]&&void 0!==r[s]&&$(this.target+" div."+this._strip_punctuation(d)+"-btns ul.dropdown-menu").append('<li><a href="#" data-feature="'+this._strip_punctuation(d)+'" data-key="'+r[s]+'">'+r[s]+"</a></li>");$("."+this._strip_punctuation(d)+"-btns .dropdown-menu li a").on("click",u)}return this},this};var Zt=function(t,e,r){var a=e.line_id,n=r.color,o=r.colors;t.classed("mg-hover-line-color",null===n).classed("mg-hover-line"+a+"-color",null===o).attr("fill",null===o?"":o[a-1])},Kt=function(r,t,e){t.existing_band=e.selectAll(".mg-confidence-band").nodes(),r.show_confidence_band&&(t.confidence_area=E.area().defined(t.line.defined()).x(r.scalefns.xf).y0(function(t){var e=r.show_confidence_band[0];return null!=t[e]?r.scales.Y(t[e]):r.scales.Y(t[r.y_accessor])}).y1(function(t){var e=r.show_confidence_band[1];return null!=t[e]?r.scales.Y(t[e]):r.scales.Y(t[r.y_accessor])}).curve(r.interpolate))},Jt=function(t,e){var r=t.scalefns,a=t.scales,n=t.interpolate,o=t.flip_area_under_y_value,i=Number.isFinite(o)?a.Y(o):a.Y.range()[0];e.area=E.area().defined(e.line.defined()).x(r.xf).y0(function(){return i}).y1(r.yf).curve(n)},te=function(t,e){var r=t.y_accessor,a=t.scalefns,n=t.scales,o=t.interpolate;e.flat_line=E.line().defined(function(t){return(void 0===t._missing||!0!==t._missing)&&null!==t[r]}).x(a.xf).y(function(){return n.Y(e.data_median)}).curve(o)},ee=function(t,e){var r=t.scalefns,a=t.interpolate,n=t.missing_is_zero,o=t.y_accessor;e.line=E.line().x(r.xf).y(r.yf).curve(a),n||(e.line=e.line.defined(function(t){return(void 0===t._missing||!0!==t._missing)&&null!==t[o]}))},re=function(t,e,r,a){var n=t.show_confidence_band,o=t.transition_on_update,i=t.data,s=t.target;if(n){r.select(".mg-confidence-band-"+a).empty()&&r.append("path").attr("class","mg-confidence-band mg-confidence-band-"+a),r.select(".mg-confidence-band-"+a).transition().duration(function(){return o?1e3:0}).attr("d",e.confidence_area(i[a-1])).attr("clip-path","url(#mg-plot-window-"+z(s)+")")}},ae=function(t,e,r,a,n){var o=t.data,i=t.target,s=t.colors,c=r.selectAll(".mg-main-area.mg-area"+n);e.display_area?c.empty()?r.append("path").classed("mg-main-area",!0).classed("mg-area"+n,!0).classed("mg-area-color",null===s).classed("mg-area"+n+"-color",null===s).attr("d",e.area(o[a])).attr("fill",null===s?"":s[n-1]).attr("clip-path","url(#mg-plot-window-"+z(i)+")"):(r.node().appendChild(c.node()),c.transition().duration(e.update_transition_duration).attr("d",e.area(o[a])).attr("clip-path","url(#mg-plot-window-"+z(i)+")")):c.empty()||c.remove()},ne=function(t,e){t.classed("mg-line-color",!0).classed("mg-line"+e+"-color",!0)},oe=function(t,e,r,a,n,o){if(a.empty()){var i=r.append("path").attr("class","mg-main-line mg-line"+o);g=i,h=n,x=o,(y=t.colors)&&y.constructor===Array?(g.attr("stroke",y[h]),y.length<h+1&&ne(g,x)):ne(g,x),l=e,u=i,d=n,f=(c=t).animate_on_load,p=c.data,_=c.y_accessor,m=c.target,f?(l.data_median=E.median(p[d],function(t){return t[_]}),u.attr("d",l.flat_line(p[d])).transition().duration(1e3).attr("d",l.line(p[d])).attr("clip-path","url(#mg-plot-window-"+z(m)+")")):u.attr("d",l.line(p[d])).attr("clip-path","url(#mg-plot-window-"+z(m)+")")}else{r.node().appendChild(a.node());var s=a.transition().duration(e.update_transition_duration);e.display_area||!t.transition_on_update||t.missing_is_hidden?s.attr("d",e.line(t.data[n])):s.attrTween("d",je(e.line(t.data[n]),4))}var c,l,u,d,f,p,_,m,g,h,x,y},ie=function(t,e,r,a){var n,o=void 0;if(t.legend)if(u(t.legend)?o=t.legend[r]:(n=t.legend,"[object Function]"===Object.prototype.toString.call(n)&&(o=t.legend(t.data[r]))),t.legend_target)t.colors&&t.colors.constructor===Array?e.legend_text="<span style='color:"+t.colors[r]+"'>— "+o+" </span>"+e.legend_text:e.legend_text="<span class='mg-line"+a+"-legend-color'>— "+o+" </span>"+e.legend_text;else{var i=void 0,s=void 0,c=void 0;"left"===t.y_axis_position?(i=t.data[r][t.data[r].length-1],s="start",c=t.buffer):(i=t.data[r][0],s="end",c=-t.buffer);var l=e.legend_group.append("svg:text").attr("x",t.scalefns.xf(i)).attr("dx",c).attr("y",t.scalefns.yf(i)).attr("dy",".35em").attr("font-size",10).attr("text-anchor",s).attr("font-weight","300").text(o);t.colors&&t.colors.constructor===Array?t.colors.length<r+1?l.classed("mg-line"+a+"-legend-color",!0):l.attr("fill",t.colors[r]):l.classed("mg-line-legend-color",!0).classed("mg-line"+a+"-legend-color",!0),function(t,e){if(t&&1!=t.length){var r,a,n;t.sort(function(t,e){return E.select(e).attr("y")-E.select(t).attr("y")}),t.reverse();for(var o=0;o<t.length;o++){a=E.select(t[o]).text();for(var i=0;i<t.length;i++)if(n=E.select(t[i]).text(),!1!==(l=t[o],u=t[i],void 0,d=l.getBoundingClientRect(),f=u.getBoundingClientRect(),r=d.top<=f.bottom&&d.top>=f.top&&f.bottom-d.top)&&a!==n){var s=E.select(t[o]),c=+s.attr("y");c+=r,s.attr("y",c)}}}var l,u,d,f}(e.legend_group.selectAll(".mg-line-legend text").nodes())}},se=function(e,t,r,a,n,o){var i,s,c,l=E.voronoi().x(function(t){return e.scales.X(t[e.x_accessor]).toFixed(2)}).y(function(t){return e.scales.Y(t[e.y_accessor]).toFixed(2)}).extent([[e.buffer,e.buffer+(e.title?e.title_y_position:0)],[e.width-e.buffer,e.height-e.buffer]]);S(t,"mg-voronoi").selectAll("path").data(l.polygons((s=e,c=s.data,E.merge(c)))).enter().append("path").filter(function(t){return void 0!==t&&0<t.length}).attr("d",function(t){return null==t?null:"M"+t.join("L")+"Z"}).datum(function(t){return null==t?null:t.data}).attr("class",(i=e,function(t){var e=void 0;if(i.linked){var r=t[i.x_accessor],a=MG.time_format(i.utc_time,i.linked_format);return e="roll_"+("number"==typeof r?t.line_id-1:a(r))+" mg-line"+t.line_id,null===i.color&&(e+=" mg-line"+t.line_id+"-color"),e}return e="mg-line"+t.line_id,null===i.color&&(e+=" mg-line"+t.line_id+"-color"),e})).on("click",o).on("mouseover",r).on("mouseout",a).on("mousemove",n),le(e,t)},ce=function(a,t,e,r,n,o){var i,s,c,l,u,d=(s=(i=a).x_accessor,c=i.data,l=i.x_sort,(u=E.nest().key(function(t){return t[s]}).entries(E.merge(c))).forEach(function(t){var e=t.values[0];t.key=e[s]}),l?u.sort(function(t,e){return new Date(t.key)-new Date(e.key)}):u),f=d.map(function(t){var e=t.key;return a.scales.X(e)});t.append("g").attr("class","mg-rollover-rect").selectAll(".mg-rollover-rects").data(d).enter().append("rect").attr("x",function(t,e){return 1===f.length?Y(a):0===e?f[e].toFixed(2):((f[e-1]+f[e])/2).toFixed(2)}).attr("y",a.top).attr("width",function(t,e){return 1===f.length?P(a):0===e?((f[e+1]-f[e])/2).toFixed(2):e===f.length-1?((f[e]-f[e-1])/2).toFixed(2):((f[e+1]-f[e-1])/2).toFixed(2)}).attr("class",function(t){var e=t.values,r=e.map(function(t){var e=t.line_id,r=ue(e);return null===a.colors&&(r+=" "+de(e)),r}).join(" ");return a.linked&&0<e.length&&(r+=" "+fe(pe(e[0],a))),r}).attr("height",a.height-a.bottom-a.top-a.buffer).attr("opacity",0).on("click",o).on("mouseover",e).on("mouseout",r).on("mousemove",n),_e(a,t)},le=function(t,e){for(var r=t.data,a=t.custom_line_color_map,n=0;n<r.length;n++){var o=n+1;0<a.length&&void 0!==a[n]&&(o=a[n]),1!==r[n].length||e.selectAll(".mg-voronoi .mg-line"+o).empty()||(e.selectAll(".mg-voronoi .mg-line"+o).on("mouseover")(r[n][0],0),e.selectAll(".mg-voronoi .mg-line"+o).on("mouseout")(r[n][0],0))}},ue=function(t){return"mg-line"+t},de=function(t){return"mg-line"+t+"-color"},fe=function(t){return"roll_"+t},pe=function(t,e){var r=e.x_accessor,a=e.utc_time,n=e.linked_format,o=t[r],i=MG.time_format(a,n);return"number"==typeof o?o.toString().replace(".","_"):i(o)},_e=function(t,e){var r=t.data,a=e.selectAll(".mg-rollover-rect rect"),n=a.nodes()[0][0]||a.nodes()[0];0<r.filter(function(t){return 1===t.length}).length&&a.on("mouseover")(n.__data__,0)},me=function(t){var e=t.data;return 1===e.length&&1===e[0].length},ge=function(t,e){var r=t.existing_band;r[0]&&r[0].length>e.selectAll(".mg-main-line").node().length&&e.selectAll(".mg-confidence-band").remove()},he=function(t){var e,r,a,n,o,i,s,c={},l=O(t.target);D(l,".mg-line-legend"),e=c,r=l,t.legend&&(e.legend_group=S(r,"mg-line-legend")),c.data_median=0,c.update_transition_duration=t.transition_on_update?1e3:0,c.display_area=t.area&&!t.use_data_y_min&&t.data.length<=1&&!1===t.aggregate_rollover||Array.isArray(t.area)&&0<t.area.length,c.legend_text="",o=l,ee(a=t,n=c),Jt(a,n),te(a,n),Kt(a,n,o),c.existing_band=l.selectAll(".mg-confidence-band").nodes(),!1!==MG.call_hook("line.before_all_series",[t])&&function(e,t,r){ge(t,r),e.active_point_on_lines&&r.selectAll("circle.mg-shown-active-point").remove();for(var a=e.data.length-1;0<=a;a--){var n=e.data[a];MG.call_hook("line.before_each_series",[n,e]);var o=a+1;if(0<e.custom_line_color_map.length&&(o=e.custom_line_color_map[a]),e.data[a].line_id=o,e.active_point_on_lines&&r.selectAll("circle-"+o).data(e.data[a]).enter().filter(function(t){return t[e.active_point_accessor]}).append("circle").attr("class","mg-area"+o+"-color mg-shown-active-point").attr("cx",e.scalefns.xf).attr("cy",e.scalefns.yf).attr("r",function(){return e.active_point_size}),0!==n.length){var i=r.select("path.mg-main-line.mg-line"+o);re(e,t,r,o),Array.isArray(e.area)?e.area[o-1]&&ae(e,t,r,a,o):ae(e,t,r,a,o),oe(e,t,r,i,a,o),ie(e,t,a,o),MG.call_hook("line.after_each_series",[n,i,e])}}}(t,c,l),i=t.legend_target,s=c.legend_text,i&&E.select(i).html(s)},xe=function(t,e){var r,a,n,o,i,s,c,l,u,d,f,p,_=O(t.target);t.showActivePoint&&0===_.selectAll(".mg-active-datapoint-container").nodes().length&&S(_,"mg-active-datapoint-container"),D(r=_,".mg-rollover-rect"),D(r,".mg-voronoi"),D(r,".mg-active-datapoint"),D(r,".mg-line-rollover-circle"),n=_,o=(a=t).data,i=a.colors,s=n.selectAll(".mg-line-rollover-circle").data(o).enter().append("circle").attr("cx",0).attr("cy",0).attr("r",0),i&&i.constructor===Array?s.attr("class",function(t){return"mg-line"+t.line_id}).attr("fill",function(t,e){return i[e]}).attr("stroke",function(t,e){return i[e]}):s.attr("class",function(t,e){var r=t.line_id;return["mg-line"+r,"mg-line"+r+"-color","mg-area"+r+"-color"].join(" ")}),s.classed("mg-line-rollover-circle",!0),function(t){for(var e=t.data,r=t.custom_line_color_map,a=0;a<e.length;a++)for(var n=0;n<e[a].length;n++)e[a][n].index=a+1,0<r.length?e[a][n].line_id=r[a]:e[a][n].line_id=a+1}(t),f=(d=t).data,p=d.aggregate_rollover,1<f.length&&!p?se(t,_,e.rolloverOn(t),e.rolloverOff(t),e.rolloverMove(t),e.rolloverClick(t)):(l=(c=t).data,u=c.aggregate_rollover,1<l.length&&u?ce(t,_,e.rolloverOn(t),e.rolloverOff(t),e.rolloverMove(t),e.rolloverClick(t)):function(a,t,e,r,n,o){var i=1;0<a.custom_line_color_map.length&&(i=a.custom_line_color_map[0]);var s,c,l=t.append("g").attr("class","mg-rollover-rect"),u=a.data[0].map(a.scalefns.xf);l.selectAll(".mg-rollover-rects").data(a.data[0]).enter().append("rect").attr("class",function(t,e){var r=de(i)+" "+ue(t.line_id);return a.linked&&(r+=r+" "+fe(pe(t,a))),r}).attr("x",function(t,e){return 1===u.length?Y(a):0===e?u[e].toFixed(2):((u[e-1]+u[e])/2).toFixed(2)}).attr("y",function(t,e){return 1<a.data.length?a.scalefns.yf(t)-6:a.top}).attr("width",function(t,e){return 1===u.length?P(a):0===e?((u[e+1]-u[e])/2).toFixed(2):e===u.length-1?((u[e]-u[e-1])/2).toFixed(2):((u[e+1]-u[e-1])/2).toFixed(2)}).attr("height",function(t,e){return 1<a.data.length?12:a.height-a.bottom-a.top-a.buffer}).attr("opacity",0).on("click",o).on("mouseover",e).on("mouseout",r).on("mousemove",n),me(a)&&(s=t,c=a.data,s.select(".mg-rollover-rect rect").on("mouseover")(c[0][0],0))}(t,_,e.rolloverOn(t),e.rolloverOff(t),e.rolloverMove(t),e.rolloverClick(t)))},ye=function(t,e,r){var a=t.scales,n=t.x_accessor,o=t.y_accessor,i=t.point_size;e.select("circle.mg-line-rollover-circle.mg-line"+r.line_id).attr("cx",a.X(r[n]).toFixed(2)).attr("cy",a.Y(r[o]).toFixed(2)).attr("r",i).style("opacity",1)},ve=function(t,e,r){var a=t.scales,n=t.x_accessor,o=t.y_accessor,i=t.point_size;e.selectAll("circle.mg-line-rollover-circle.mg-line"+r.line_id).classed("mg-line-rollover-circle",!0).attr("cx",function(){return a.X(r[n]).toFixed(2)}).attr("cy",function(){return a.Y(r[o]).toFixed(2)}).attr("r",i).style("opacity",1)};MG.register("line",function(t){this.init=function(e){if(!(this.args=e).data||0===e.data.length)return e.internal_error="No data was supplied",t=e,console.error("INTERNAL ERROR : ",t.target," : ",t.internal_error),this;var t;e.internal_error=void 0,Me(e),Ae(e),MG.call_hook("line.before_destroy",this),Ot(e),new MG.scale_factory(e).namespace("x").numericalDomainFromData().numericalRange("bottom");var r=(e.baselines||[]).map(function(t){return t[e.y_accessor]});return new MG.scale_factory(e).namespace("y").zeroBottom(!0).inflateDomain(!0).numericalDomainFromData(r).numericalRange("left"),e.x_axis&&new MG.axis_factory(e).namespace("x").type("numerical").position(e.x_axis_position).rug(nt(e)).label(st).draw(),e.y_axis&&new MG.axis_factory(e).namespace("y").type("numerical").position(e.y_axis_position).rug(K(e)).label(et).draw(),this.markers(),this.mainPlot(),this.rollover(),this.windowListeners(),e.brush&&MG.add_brush_function(e),MG.call_hook("line.after_init",this),this},this.mainPlot=function(){return he(t),this},this.markers=function(){return St(t),this},this.rollover=function(){return xe(t,this),MG.call_hook("line.after_rollover",t),this},this.rolloverClick=function(r){return function(t,e){r.click&&r.click(t,e)}},this.rolloverOn=function(n){var o=O(n.target);return function(r,t){if(function(a,n,t){if(a.aggregate_rollover&&1<a.data.length)n.selectAll("circle.mg-line-rollover-circle").style("opacity",0),t.values.forEach(function(t,e,r){a.missing_is_hidden&&r[e]._missing||i(t,a)&&ye(a,n,t)});else{if(a.missing_is_hidden&&t._missing||null===t[a.y_accessor])return;i(t,a)&&ve(a,n,t)}}(n,o,r),function(t,e,r){if(t.linked&&!MG.globals.link&&(MG.globals.link=!0,!t.aggregate_rollover||void 0!==e[t.y_accessor]||e.values&&0<e.values.length)){var a=e.values?e.values[0]:e,n=pe(a,t);E.selectAll("."+ue(a.line_id)+"."+fe(n)).each(function(t){E.select(this).on("mouseover")(t,r)})}}(n,r,t),o.selectAll("text").filter(function(t,e){return r===t}).attr("opacity",.3),n.show_rollover_text&&!(n.missing_is_hidden&&r._missing||null===r[n.y_accessor])){var e=Xt(n,{svg:o}),a=e.mouseover_row();n.aggregate_rollover&&a.text((n.aggregate_rollover&&1<n.data.length?function(t,e){return Pe(t,e,t.x_mouseover,"key",t.time_series)}:Se)(n,r)),(n.aggregate_rollover&&1<n.data.length?r.values:[r]).forEach(function(t){n.aggregate_rollover&&(a=e.mouseover_row()),n.legend&&Zt(a.text(n.legend[t.index-1]+" ").bold(),t,n),Zt(a.text("— ").elem,t,n),n.aggregate_rollover||a.text(Se(n,t)),a.text(Le(n,t,n.time_series))})}n.mouseover&&n.mouseover(r,t)}},this.rolloverOff=function(c){var l=O(c.target);return function(t,e){var r,a,n,o,i,s;!function(t,e,a){var r=t.linked,n=t.utc_time,o=t.linked_format,i=t.x_accessor;if(r&&MG.globals.link){MG.globals.link=!1;var s=MG.time_format(n,o);(e.values?e.values:[e]).forEach(function(t){var e=t[i],r="number"==typeof e?a:s(e);E.selectAll(".roll_"+r).each(function(t){E.select(this).on("mouseout")(t)})})}}(c,t,e),c.aggregate_rollover?l.selectAll("circle.mg-line-rollover-circle").filter(function(t){return 1<t.length}).style("opacity",0):(a=l,n=t,o=(r=c).custom_line_color_map,i=r.data,s=n.line_id,a.selectAll("circle.mg-line-rollover-circle.mg-line"+s).style("opacity",function(){var t=s-1;return 0<o.length&&void 0!==o.indexOf(s)&&(t=o.indexOf(s)),1===i[t].length?1:0})),1<c.data[0].length&&Lt(l),c.mouseout&&c.mouseout(t,e)}},this.rolloverMove=function(r){return function(t,e){r.mousemove&&r.mousemove(t,e)}},this.windowListeners=function(){return Qt(this.args),this},this.init(t)});function be(t,e,r){var a,n,o,i,s,c=Xt(t,{svg:e}).mouseover_row();if(null!==t.color_accessor&&"category"===t.color_type){var l=r[t.color_accessor];c.text(l+" ").bold().attr("fill",t.scalefns.colorf(r))}a=t,n=c.text("● ").elem,o=r,i=a.color_accessor,s=a.scalefns,null!==i?(n.attr("fill",s.colorf(o)),n.attr("stroke",s.colorf(o))):n.classed("mg-points-mono",!0),c.text(Se(t,r)),c.text(Le(t,r,t.time_series))}MG.register("histogram",function(r){var a=this;this.init=function(e){Me(a.args=e),De(e),Ot(e),new MG.scale_factory(e).namespace("x").numericalDomainFromData().numericalRange("bottom");var t=(e.baselines||[]).map(function(t){return t[e.y_accessor]});return new MG.scale_factory(e).namespace("y").zeroBottom(!0).inflateDomain(!0).numericalDomainFromData(t).numericalRange("left"),ot(e),rt(e),a.mainPlot(),a.markers(),a.rollover(),a.windowListeners(),a},this.mainPlot=function(){var t=O(r.target);return t.selectAll(".mg-histogram").remove(),t.append("g").attr("class","mg-histogram").selectAll(".mg-bar").data(r.data[0]).enter().append("g").attr("class","mg-bar").attr("transform",function(t){return"translate("+r.scales.X(t[r.x_accessor]).toFixed(2)+","+r.scales.Y(t[r.y_accessor]).toFixed(2)+")"}).append("rect").attr("x",1).attr("width",function(t,e){return 1===r.data[0].length?(r.scalefns.xf(r.data[0][0])-r.bar_margin).toFixed(0):e!==r.data[0].length-1?(r.scalefns.xf(r.data[0][e+1])-r.scalefns.xf(t)).toFixed(0):(r.scalefns.xf(r.data[0][1])-r.scalefns.xf(r.data[0][0])).toFixed(0)}).attr("height",function(t){return 0===t[r.y_accessor]?0:(r.height-r.bottom-r.buffer-r.scales.Y(t[r.y_accessor])).toFixed(2)}),a},this.markers=function(){return St(r),a},this.rollover=function(){var t=O(r.target);return 0===t.selectAll(".mg-active-datapoint-container").nodes().length&&S(t,"mg-active-datapoint-container"),t.selectAll(".mg-rollover-rect").remove(),t.selectAll(".mg-active-datapoint").remove(),t.append("g").attr("class","mg-rollover-rect").selectAll(".mg-bar").data(r.data[0]).enter().append("g").attr("class",function(t,e){return r.linked?"mg-rollover-rects roll_"+e:"mg-rollover-rects"}).attr("transform",function(t){return"translate("+r.scales.X(t[r.x_accessor])+",0)"}).append("rect").attr("x",1).attr("y",r.buffer+(r.title?r.title_y_position:0)).attr("width",function(t,e){return 1===r.data[0].length?(r.scalefns.xf(r.data[0][0])-r.bar_margin).toFixed(0):e!==r.data[0].length-1?(r.scalefns.xf(r.data[0][e+1])-r.scalefns.xf(t)).toFixed(0):(r.scalefns.xf(r.data[0][1])-r.scalefns.xf(r.data[0][0])).toFixed(0)}).attr("height",function(t){return r.height}).attr("opacity",0).on("mouseover",a.rolloverOn(r)).on("mouseout",a.rolloverOff(r)).on("mousemove",a.rolloverMove(r)),a},this.rolloverOn=function(e){var n=O(e.target);return function(r,a){if(n.selectAll("text").filter(function(t,e){return r===t}).attr("opacity",.3),e.processed.xax_format||MG.time_format(e.utc_time,"%b %e, %Y"),Ee(e),n.selectAll(".mg-bar rect").filter(function(t,e){return e===a}).classed("active",!0),e.linked&&!MG.globals.link&&(MG.globals.link=!0,E.selectAll(".mg-rollover-rects.roll_"+a+" rect").each(function(t){E.select(this).on("mouseover")(t,a)})),e.show_rollover_text){var t=Xt(e,{svg:n}).mouseover_row();t.text("▟ ").elem.classed("hist-symbol",!0),t.text(Se(e,r)),t.text(Le(e,r,e.time_series))}e.mouseover&&(jt(n,e),e.mouseover(r,a))}},this.rolloverOff=function(r){var a=O(r.target);return function(t,e){r.linked&&MG.globals.link&&(MG.globals.link=!1,E.selectAll(".mg-rollover-rects.roll_"+e+" rect").each(function(t){E.select(this).on("mouseout")(t,e)})),a.selectAll(".mg-bar rect").classed("active",!1),Lt(a),r.mouseout&&r.mouseout(t,e)}},this.rolloverMove=function(r){return function(t,e){r.mousemove&&r.mousemove(t,e)}},this.windowListeners=function(){return Qt(a.args),a},this.init(r)},{binned:!1,bins:null,processed_x_accessor:"x",processed_y_accessor:"y",processed_dx_accessor:"dx",bar_margin:1});var we=function(t,e){var r=e.x_accessor,a=e.y_accessor;return t.filter(function(t){return(null===e.min_x||t[r]>=e.min_x)&&(null===e.max_x||t[r]<=e.max_x)&&(null===e.min_y||t[a]>=e.min_y)&&(null===e.max_y||t[a]<=e.max_y)})};MG.register("point",function(a){var o=this;this.init=function(e){if((this.args=e).x_axis_type=s(e,"x"),e.y_axis_type=s(e,"y"),Me(e),Oe(e),Ot(e),"categorical"===e.x_axis_type?(MG.scale_factory(e).namespace("x").categoricalDomainFromData().categoricalRangeBands([0,e.xgroup_height],null===e.xgroup_accessor),e.xgroup_accessor?new MG.scale_factory(e).namespace("xgroup").categoricalDomainFromData().categoricalRangeBands("bottom"):(e.scales.XGROUP=function(){return Y(e)},e.scalefns.xgroupf=function(){return Y(e)}),e.scalefns.xoutf=function(t){return e.scalefns.xf(t)+e.scalefns.xgroupf(t)}):(MG.scale_factory(e).namespace("x").inflateDomain(!0).zeroBottom("categorical"===e.y_axis_type).numericalDomainFromData((e.baselines||[]).map(function(t){return t[e.x_accessor]})).numericalRange("bottom"),e.scalefns.xoutf=e.scalefns.xf),"categorical"===e.y_axis_type)MG.scale_factory(e).namespace("y").zeroBottom(!0).categoricalDomainFromData().categoricalRangeBands([0,e.ygroup_height],!0),e.ygroup_accessor?new MG.scale_factory(e).namespace("ygroup").categoricalDomainFromData().categoricalRangeBands("left"):(e.scales.YGROUP=function(){return b(e)},e.scalefns.ygroupf=function(){return b(e)}),e.scalefns.youtf=function(t){return e.scalefns.yf(t)+e.scalefns.ygroupf(t)};else{var t=(e.baselines||[]).map(function(t){return t[e.y_accessor]});MG.scale_factory(e).namespace("y").inflateDomain(!0).zeroBottom("categorical"===e.x_axis_type).numericalDomainFromData(t).numericalRange("left"),e.scalefns.youtf=function(t){return e.scalefns.yf(t)}}if(null!==e.color_accessor){var r=MG.scale_factory(e).namespace("color");"number"===e.color_type?r.numericalDomainFromData(B(e)).numericalRange(I(e)).clamp(!0):e.color_domain?r.categoricalDomain(e.color_domain).categoricalRange(e.color_range):r.categoricalDomainFromData().categoricalColorRange()}return e.size_accessor&&new MG.scale_factory(e).namespace("size").numericalDomainFromData().numericalRange(it(e)).clamp(!0),new MG.axis_factory(e).namespace("x").type(e.x_axis_type).zeroLine("categorical"===e.y_axis_type).position(e.x_axis_position).rug(nt(e)).label(st).draw(),new MG.axis_factory(e).namespace("y").type(e.y_axis_type).zeroLine("categorical"===e.x_axis_type).position(e.y_axis_position).rug(K(e)).label(et).draw(),this.mainPlot(),this.markers(),this.rollover(),this.windowListeners(),e.brush&&MG.add_brush_function(e),this},this.markers=function(){return St(a),a.least_squares&&ze(a),this},this.mainPlot=function(){var t=O(a.target),e=we(a.data[0],a);t.selectAll(".mg-points").remove();var r=t.append("g").classed("mg-points",!0).selectAll("circle").data(e).enter().append("circle").attr("class",function(t,e){return"path-"+e}).attr("cx",a.scalefns.xoutf).attr("cy",function(t){return a.scalefns.youtf(t)});return null!==a.color_accessor?(r.attr("fill",a.scalefns.colorf),r.attr("stroke",a.scalefns.colorf)):r.classed("mg-points-mono",!0),null!==a.size_accessor?r.attr("r",a.scalefns.sizef):r.attr("r",a.point_size),this},this.rollover=function(){var t=O(a.target);0===t.selectAll(".mg-active-datapoint-container").nodes().length&&S(t,"mg-active-datapoint-container"),t.selectAll(".mg-voronoi").remove();var e=E.voronoi().x(a.scalefns.xoutf).y(a.scalefns.youtf).extent([[a.buffer,a.buffer+(a.title?a.title_y_position:0)],[a.width-a.buffer,a.height-a.buffer]]);return t.append("g").attr("class","mg-voronoi").selectAll("path").data(e.polygons(we(a.data[0],a))).enter().append("path").attr("d",function(t){return null==t?null:"M"+t.join(",")+"Z"}).attr("class",function(t,e){return"path-"+e}).style("fill-opacity",0).on("mouseover",this.rolloverOn(a)).on("mouseout",this.rolloverOff(a)).on("mousemove",this.rolloverMove(a)),1===a.data[0].length&&be(a,t,a.data[0][0]),this},this.rolloverOn=function(a){var n=O(a.target);return function(t,e){n.selectAll(".mg-points circle").classed("selected",!1);var r=n.selectAll(".mg-points circle.path-"+e).classed("selected",!0);a.size_accessor?r.attr("r",function(t){return a.scalefns.sizef(t)+a.active_point_size_increase}):r.attr("r",a.point_size+a.active_point_size_increase),a.linked&&!MG.globals.link&&(MG.globals.link=!0,E.selectAll(".mg-voronoi .path-"+e).each(function(){E.select(o).on("mouseover")(t,e)})),a.show_rollover_text&&be(a,n,t.data),a.mouseover&&a.mouseover(t,e)}},this.rolloverOff=function(a){var n=O(a.target);return function(t,e){a.linked&&MG.globals.link&&(MG.globals.link=!1,E.selectAll(".mg-voronoi .path-"+e).each(function(){E.select(o).on("mouseout")(t,e)}));var r=n.selectAll(".mg-points circle").classed("unselected",!1).classed("selected",!1);a.size_accessor?r.attr("r",a.scalefns.sizef):r.attr("r",a.point_size),1<a.data[0].length&&Lt(n),a.mouseout&&a.mouseout(t,e)}},this.rolloverMove=function(r){return function(t,e){r.mousemove&&r.mousemove(t,e)}},this.update=function(t){return this},this.windowListeners=function(){return Qt(this.args),this},this.init(a)},{y_padding_percentage:.05,y_outer_padding_percentage:.2,ygroup_padding_percentage:0,ygroup_outer_padding_percentage:0,x_padding_percentage:.05,x_outer_padding_percentage:.2,xgroup_padding_percentage:0,xgroup_outer_padding_percentage:0,y_categorical_show_guides:!0,x_categorical_show_guides:!0,buffer:16,ls:!1,lowess:!1,point_size:2.5,label_accessor:null,size_accessor:null,color_accessor:null,size_range:null,color_range:null,size_domain:null,color_domain:null,active_point_size_increase:1,color_type:"number"});MG.register("bar",function(M){var G=this;this.args=M,this.init=function(e){if((G.args=e).x_axis_type=s(e,"x"),e.y_axis_type=s(e,"y"),"categorical"==e.x_axis_type?e.orientation="vertical":"categorical"==e.y_axis_type?e.orientation="horizontal":"categorical"!=e.x_axis_type&&"categorical"!=e.y_axis_type&&(e.orientation="vertical"),Me(e),Oe(e),Ot(e),"categorical"===e.x_axis_type?(MG.scale_factory(e).namespace("x").categoricalDomainFromData().categoricalRangeBands([0,e.xgroup_height],null===e.xgroup_accessor),e.xgroup_accessor?new MG.scale_factory(e).namespace("xgroup").categoricalDomainFromData().categoricalRangeBands("bottom"):(e.scales.XGROUP=function(t){return Y(e)},e.scalefns.xgroupf=function(t){return Y(e)}),e.scalefns.xoutf=function(t){return e.scalefns.xf(t)+e.scalefns.xgroupf(t)}):(MG.scale_factory(e).namespace("x").inflateDomain(!0).zeroBottom("categorical"===e.y_axis_type).numericalDomainFromData((e.baselines||[]).map(function(t){return t[e.x_accessor]})).numericalRange("bottom"),e.scalefns.xoutf=e.scalefns.xf),"categorical"===e.y_axis_type)MG.scale_factory(e).namespace("y").zeroBottom(!0).categoricalDomainFromData().categoricalRangeBands([0,e.ygroup_height],!0),e.ygroup_accessor?new MG.scale_factory(e).namespace("ygroup").categoricalDomainFromData().categoricalRangeBands("left"):(e.scales.YGROUP=function(){return b(e)},e.scalefns.ygroupf=function(t){return b(e)}),e.scalefns.youtf=function(t){return e.scalefns.yf(t)+e.scalefns.ygroupf(t)};else{var t=(e.baselines||[]).map(function(t){return t[e.y_accessor]});MG.scale_factory(e).namespace("y").inflateDomain(!0).zeroBottom("categorical"===e.x_axis_type).numericalDomainFromData(t).numericalRange("left"),e.scalefns.youtf=function(t){return e.scalefns.yf(t)}}return null!==e.ygroup_accessor&&(e.ycolor_accessor=e.y_accessor,MG.scale_factory(e).namespace("ycolor").scaleName("color").categoricalDomainFromData().categoricalColorRange()),null!==e.xgroup_accessor&&(e.xcolor_accessor=e.x_accessor,MG.scale_factory(e).namespace("xcolor").scaleName("color").categoricalDomainFromData().categoricalColorRange()),new MG.axis_factory(e).namespace("x").type(e.x_axis_type).zeroLine("categorical"===e.y_axis_type).position(e.x_axis_position).draw(),new MG.axis_factory(e).namespace("y").type(e.y_axis_type).zeroLine("categorical"===e.x_axis_type).position(e.y_axis_position).draw(),G.mainPlot(),G.markers(),G.rollover(),G.windowListeners(),G},this.mainPlot=function(){var t=O(M.target),e=M.data[0],r=t.select("g.mg-barplot"),a=r.empty(),n=void 0;a&&M.animate_on_load||M.transition_on_update,M.transition_duration,a&&(r=t.append("g").classed("mg-barplot",!0)),n=r.selectAll(".mg-bar").data(e).enter().append("rect").classed("mg-bar",!0).classed("default-bar",!M.scales.hasOwnProperty("COLOR"));var o=void 0,i=void 0,s=void 0,c=void 0,l=void 0,u=void 0,d=void 0,f=void 0,p=void 0,_=void 0,m=void 0,g=void 0,h=void 0,x=void 0,y=void 0,v=void 0;if("vertical"==M.orientation&&(o="height",i="width",s=M.y_axis_type,c=M.x_axis_type,l="y",u="x",d="categorical"==s?M.scalefns.youtf:M.scalefns.yf,f="categorical"==c?M.scalefns.xoutf:M.scalefns.xf,p=M.scales.Y,_=M.scales.X,m=M.y_accessor,g=M.x_accessor,h=function(t){var e=void 0;return e=d(t),t[m]<0&&(e=p(0)),e},x=function(t){return Math.abs(d(t)-p(0))},y=function(t){return Math.abs(p(t[M.reference_accessor])-p(0))},v=function(t){return p(t[M.reference_accessor])}),"horizontal"==M.orientation&&(o="width",i="height",s=M.x_axis_type,c=M.y_axis_type,l="x",u="y",d="categorical"==s?M.scalefns.xoutf:M.scalefns.xf,f="categorical"==c?M.scalefns.youtf:M.scalefns.yf,p=M.scales.X,_=M.scales.Y,m=M.x_accessor,g=M.y_accessor,h=function(t){return p(0)},x=function(t){return Math.abs(d(t)-p(0))},y=function(t){return Math.abs(p(t[M.reference_accessor])-p(0))},v=function(t){return p(0)}),n.attr(l,h),n.attr(u,function(t){var e=void 0;return"categorical"==c?e=f(t):(e=_(0),t[g]<0&&(e=f(t))),e-=M.bar_thickness/2}),M.scales.COLOR&&n.attr("fill",M.scalefns.colorf),n.attr(o,x).attr(i,function(t){return M.bar_thickness}),null!==M.reference_accessor){var b=e.filter(function(t){return t.hasOwnProperty(M.reference_accessor)});r.selectAll(".mg-categorical-reference").data(b).enter().append("rect").attr(l,v).attr(u,function(t){return f(t)-M.reference_thickness/2}).attr(o,y).attr(i,M.reference_thickness)}if(null!==M.comparison_accessor){var w=null;w=null===M.comparison_thickness?M.bar_thickness/2:M.comparison_thickness;var k=e.filter(function(t){return t.hasOwnProperty(M.comparison_accessor)});r.selectAll(".mg-categorical-comparison").data(k).enter().append("line").attr(l+"1",function(t){return p(t[M.comparison_accessor])}).attr(l+"2",function(t){return p(t[M.comparison_accessor])}).attr(u+"1",function(t){return f(t)-w/2}).attr(u+"2",function(t){return f(t)+w/2}).attr("stroke","black").attr("stroke-width",M.comparison_width)}return(M.legend||null!==M.color_accessor&&M.ygroup_accessor!==M.color_accessor)&&(M.legend_target?function(t){var e=t.legend_target,r=t.orientation,a=t.scales;if(e){var n=E.select(e).append("div").classed("mg-bar-target-legend",!0);("horizontal"==r?a.Y.domain():a.X.domain()).forEach(function(t){var e=n.append("span").classed("mg-bar-target-element",!0);e.append("span").classed("mg-bar-target-legend-shape",!0).style("color",a.COLOR(t)).text("◼ "),e.append("span").classed("mg-bar-target-legend-text",!0).text(t)})}}(M):function(t,r){var e=void 0;e="horizontal"==r.orientation?r.scales.Y.domain():r.scales.X.domain();var a=0,n=t.append("g").classed("mg-bar-legend",!0).append("text");n.selectAll("*").remove(),n.attr("width",r.right).attr("height",100).attr("text-anchor","start"),e.forEach(function(t){var e=n.append("tspan").attr("x",P(r)).attr("y",r.height/2).attr("dy",1.1*a+"em");e.append("tspan").text("■ ").attr("fill",r.scales.COLOR(t)).attr("font-size",20),e.append("tspan").text(t).attr("font-weight",300).attr("font-size",10),a++})}(t,M)),G},this.markers=function(){return St(M),G},this.rollover=function(){var t=O(M.target);0===t.selectAll(".mg-active-datapoint-container").nodes().length&&S(t,"mg-active-datapoint-container"),t.selectAll(".mg-rollover-rect").remove(),t.selectAll(".mg-active-datapoint").remove();var e=void 0,r=void 0,a=void 0,n=void 0,o=void 0,i=void 0,s=void 0,c=void 0,l=void 0,u=void 0,d=void 0,f=void 0;"vertical"==M.orientation&&(e="height",r="width",a=M.y_axis_type,n=M.x_axis_type,o="y",i="x","categorical"==a?M.scalefns.youtf:M.scalefns.yf,s="categorical"==n?M.scalefns.xoutf:M.scalefns.xf,c=M.scales.Y,l=M.scales.X,M.y_accessor,u=M.x_accessor,d=function(t){return b(M)},f=function(t){return M.height-M.top-M.bottom-2*M.buffer}),"horizontal"==M.orientation&&(e="width",r="height",a=M.x_axis_type,n=M.y_axis_type,o="x",i="y","categorical"==a?M.scalefns.xoutf:M.scalefns.xf,s="categorical"==n?M.scalefns.youtf:M.scalefns.yf,c=M.scales.X,l=M.scales.Y,M.x_accessor,u=M.y_accessor,d=function(t){return c(0)},f=function(t){return M.width-M.left-M.right-2*M.buffer});var p=void 0,_=void 0;"right"===M.rollover_align?(p=M.width-M.right,_="end"):"left"===M.rollover_align?(p=M.left,_="start"):(p=(M.width-M.left-M.right)/2+M.left,_="middle"),t.append("text").attr("class","mg-active-datapoint").attr("xml:space","preserve").attr("x",p).attr("y",.75*M.top).attr("dy",".35em").attr("text-anchor",_);var m=t.append("g").attr("class","mg-rollover-rect").selectAll(".mg-bar-rollover").data(M.data[0]).enter().append("rect").attr("class","mg-bar-rollover");return m.attr("opacity",0).attr(o,d).attr(i,function(t){var e=void 0;return"categorical"==n?e=s(t):(e=l(0),t[u]<0&&(e=s(t))),e-=M.bar_thickness/2}),m.attr(e,f),m.attr(r,function(t){return M.bar_thickness}),m.on("mouseover",G.rolloverOn(M)).on("mouseout",G.rolloverOff(M)).on("mousemove",G.rolloverMove(M)),G},this.rolloverOn=function(o){var i=O(o.target);return G.is_vertical?o.x_accessor:o.y_accessor,G.is_vertical?o.y_accessor:o.x_accessor,G.is_vertical?o.yax_units:o.xax_units,function(t,r){MG.time_format(o.utc_time,"%b %e, %Y"),Ee(o);var e=i.selectAll("g.mg-barplot .mg-bar").filter(function(t,e){return e===r}).classed("active",!0);if(o.scales.hasOwnProperty("COLOR")?e.attr("fill",E.rgb(o.scalefns.colorf(t)).darker()):e.classed("default-active",!0),o.show_rollover_text){var a=Xt(o,{svg:i}),n=a.mouseover_row();o.ygroup_accessor&&n.text(t[o.ygroup_accessor]+" ").bold(),n.text(Se(o,t)),n.text(o.y_accessor+": "+t[o.y_accessor]),(o.predictor_accessor||o.baseline_accessor)&&(n=a.mouseover_row(),o.predictor_accessor&&n.text(Pe(o,t,null,o.predictor_accessor,!1)),o.baseline_accessor&&n.text(Pe(o,t,null,o.baseline_accessor,!1)))}o.mouseover&&o.mouseover(t,r)}},this.rolloverOff=function(a){var n=O(a.target);return function(t,e){var r=n.selectAll("g.mg-barplot .mg-bar.active").classed("active",!1);a.scales.hasOwnProperty("COLOR")?r.attr("fill",a.scalefns.colorf(t)):r.classed("default-active",!1),n.select(".mg-active-datapoint").text(""),Lt(n),a.mouseout&&a.mouseout(t,e)}},this.rolloverMove=function(r){return function(t,e){r.mousemove&&r.mousemove(t,e)}},this.windowListeners=function(){return Qt(G.args),G},this.init(M)},{y_padding_percentage:.05,y_outer_padding_percentage:.2,ygroup_padding_percentage:0,ygroup_outer_padding_percentage:0,x_padding_percentage:.05,x_outer_padding_percentage:.2,xgroup_padding_percentage:0,xgroup_outer_padding_percentage:0,buffer:16,y_accessor:"factor",x_accessor:"value",reference_accessor:null,comparison_accessor:null,secondary_label_accessor:null,color_accessor:null,color_type:"category",color_domain:null,reference_thickness:1,comparison_width:3,comparison_thickness:null,legend:!1,legend_target:null,mouseover_align:"right",baseline_accessor:null,predictor_accessor:null,predictor_proportion:5,show_bar_zero:!0,binned:!0,truncate_x_labels:!0,truncate_y_labels:!0}),MG.data_table=function(t){return this.args=t,this.args.standard_col={width:150,font_size:12,font_weight:"normal"},this.args.columns=[],this.formatting_options=[["color","color"],["font-weight","font_weight"],["font-style","font_style"],["font-size","font_size"]],this._strip_punctuation=function(t){return t.replace(/[^a-zA-Z0-9 _]+/g,"").replace(/ +?/g,"")},this._format_element=function(a,n,o){this.formatting_options.forEach(function(t){var e=t[0],r=t[1];o[r]&&a.style(e,"string"==typeof o[r]||"number"==typeof o[r]?o[r]:o[r](n))})},this._add_column=function(t,e){var r=this.args.standard_col,a=p(MG.clone(t),MG.clone(r));a.type=e,this.args.columns.push(a)},this.target=function(){var t=arguments[0];return this.args.target=t,this},this.title=function(){return this._add_column(arguments[0],"title"),this},this.text=function(){return this._add_column(arguments[0],"text"),this},this.bullet=function(){return this},this.sparkline=function(){return this},this.number=function(){return this._add_column(arguments[0],"number"),this},this.display=function(){var t=this.args;j(t);var e,r,a,n,o,i,s,c,l,u,d,f,p=t.target,_=E.select(p).append("table").classed("mg-data-table",!0),m=_.append("colgroup"),g=_.append("thead"),h=_.append("tbody");for(a=g.append("tr"),f=0;f<t.columns.length;f++){var x=t.columns[f];i=x.type,c=void 0===(c=x.label)?"":c,n=a.append("th").style("width",x.width).style("text-align","title"===i?"left":"right").text(c),t.show_tooltips&&x.description&&k()&&(n.append("i").classed("fa",!0).classed("fa-question-circle",!0).classed("fa-inverse",!0),$(n.node()).popover({html:!0,animation:!1,content:x.description,trigger:"hover",placement:"top",container:$(n.node())}))}for(f=0;f<t.columns.length;f++)d=m.append("col"),"number"===t.columns[f].type&&d.attr("align","char").attr("char",".");for(var y=0;y<t.data.length;y++){a=h.append("tr");for(var v=0;v<t.columns.length;v++){if(o=(e=t.columns[v]).accessor,s=l=t.data[y][o],"number"===(i=e.type)){if(e.hasOwnProperty("round")&&!e.hasOwnProperty("format")&&(l=E.format("0,."+e.round+"f")(l)),e.hasOwnProperty("value_formatter")&&(l=e.value_formatter(l)),e.hasOwnProperty("format")){e.round&&(l=Math.round(l,e.round));var b,w=e.format;"percentage"===w&&(b=E.format(".0%")),"count"===w&&(b=E.format(",.0f")),"temperature"===w&&(b=function(t){return t+"°"}),l=b(l)}e.hasOwnProperty("currency")&&(l=e.currency+l)}u=a.append("td").classed("table-"+i,!0).classed("table-"+i+"-"+this._strip_punctuation(o),!0).attr("data-value",s).style("width",e.width).style("text-align","title"===i||"text"===i?"left":"right"),this._format_element(u,s,e),"title"===i?(r=u.append("div").text(l),this._format_element(r,l,e),t.columns[v].hasOwnProperty("secondary_accessor")&&u.append("div").text(t.data[y][t.columns[v].secondary_accessor]).classed("secondary-title",!0)):u.text(l)}}return this},this};function ke(t,e){var r,a,n;function o(t){return 1e3===t?3:1e6===t?7:Math.log(t)/Math.LN10}"x"===e?(r=t.x_accessor,a=t.scales.X.ticks(t.xax_count),n=t.processed.max_x):"y"===e&&(r=t.y_accessor,a=t.scales.Y.ticks(t.yax_count),n=t.processed.max_y),("x"===e&&"log"===t.x_scale_type||"y"===e&&"log"===t.y_scale_type)&&(a=a.filter(function(t){return Math.abs(o(t))%1<1e-6||Math.abs(o(t))%1>1-1e-6}));var i=a.length,s=!0;t.data.forEach(function(t,e){t.forEach(function(t,e){if(t[r]%1!=0)return s=!1})}),s&&n<i&&"count"===t.format&&(a=a.filter(function(t){return t%1==0})),"x"===e?t.processed.x_ticks=a:"y"===e&&(t.processed.y_ticks=a)}function Me(r){if(r.data=MG.clone(r.data),r.single_object=!1,r.array_of_objects=!1,r.array_of_arrays=!1,r.nested_array_of_arrays=!1,r.nested_array_of_objects=!1,a(r.data)?(r.nested_array_of_objects=r.data.map(function(t){return e(t)}),r.nested_array_of_arrays=r.data.map(function(t){return a(t)})):(r.array_of_objects=n(r.data),r.array_of_arrays=a(r.data)),"line"===r.chart_type?(r.array_of_objects||r.array_of_arrays)&&(r.data=[r.data]):y(r.data[0])||(r.data=[r.data]),Ge(r,"x_accessor"),Ge(r,"y_accessor"),void 0!==r.color&&(r.colors=r.color),null!==r.colors&&"string"==typeof r.colors&&(r.colors=[r.colors]),"line"===r.chart_type&&!0===r.x_sort)for(var t=0;t<r.data.length;t++)r.data[t].sort(function(t,e){return t[r.x_accessor]-e[r.x_accessor]});return this}function Ge(e,r){y(e[r])&&(e.data=e.data.map(function(t){return e[r].map(function(e){return t.map(function(t){if(void 0!==(t=MG.clone(t))[e])return t["multiline_"+r]=t[e],t}).filter(function(t){return void 0!==t})})})[0],e[r]="multiline_"+r)}function Ae(r){var t,e=0<E.sum(r.data.map(function(t){return 0<t.length&&x(t[0][r.x_accessor])}));if((r.missing_is_zero||r.missing_is_hidden)&&"line"===r.chart_type&&e)for(var a=0;a<r.data.length;a++)if(!(r.data[a].length<=1)){var n=r.data[a][0],o=r.data[a][r.data[a].length-1],i=[],s=MG.clone(n[r.x_accessor]).setDate(n[r.x_accessor].getDate()+1),c=r.min_x?r.min_x:s,l=r.max_x?r.max_x:o[r.x_accessor];if(t=lt((l-c)/1e3),-1!==["four-days","many-days","many-months","years","default"].indexOf(t)&&null===r.missing_is_hidden_accessor)for(var u=new Date(c);u<=l;u.setDate(u.getDate()+1)){var d={};u.setHours(0,0,0,0),Date.parse(u)===Date.parse(new Date(s))&&i.push(MG.clone(r.data[a][0]));var f=null;r.data[a].forEach(function(t,e){if(Date.parse(t[r.x_accessor])===Date.parse(new Date(u)))return f=t,!1}),f?((f[r.missing_is_hidden_accessor]||null===f[r.y_accessor])&&(f._missing=!0),i.push(f)):(d[r.x_accessor]=new Date(u),d[r.y_accessor]=0,d._missing=!0,i.push(d))}else for(var p=0;p<r.data[a].length;p+=1){var _=MG.clone(r.data[a][p]);_._missing=r.data[a][p][r.missing_is_hidden_accessor],i.push(_)}r.data[a]=i}return this}function De(e){var t,r=e.data[0];if(!1===e.binned){if("object"===c(r[0]))t=r.map(function(t){return t[e.x_accessor]});else{if("number"!=typeof r[0])return void console.log("TypeError: expected an array of numbers, found "+c(r[0]));t=r}var a=E.histogram();e.bins&&a.thresholds(e.bins);var n=a(t);e.processed_data=n.map(function(t){return{x:t.x0,y:t.length}})}else{var o,i;e.processed_data=r.map(function(t){return{x:t[e.x_accessor],y:t[e.y_accessor]}});for(var s=0;s<e.processed_data.length;s++)o=e.processed_data[s],s===e.processed_data.length-1?o.dx=e.processed_data[s-1].dx:(i=e.processed_data[s+1],o.dx=i.x-o.x)}return e.processed||(e.processed={}),e.processed.original_data=e.data,e.processed.original_x_accessor=e.x_accessor,e.processed.original_y_accessor=e.y_accessor,e.data=[e.processed_data],e.x_accessor=e.processed_x_accessor,e.y_accessor=e.processed_y_accessor,this}function Oe(e){var t=e.data[0],r=t.map(function(t){return t[e.x_accessor]}),a=t.map(function(t){return t[e.y_accessor]});return e.least_squares&&(e.ls_line=Fe(r,a)),this}function ze(e){var t=O(e.target),r=e.data[0],a=E.min(r,function(t){return t[e.x_accessor]}),n=E.max(r,function(t){return t[e.x_accessor]});E.select(e.target).selectAll(".mg-least-squares-line").remove(),t.append("svg:line").attr("x1",e.scales.X(a)).attr("x2",e.scales.X(n)).attr("y1",e.scales.Y(e.ls_line.fit(a))).attr("y2",e.scales.Y(e.ls_line.fit(n))).attr("class","mg-least-squares-line")}function Fe(t,e){var r,a,n;t.length;r=x(t[0])?t.map(function(t){return t.getTime()}):t,a=x(e[0])?e.map(function(t){return t.getTime()}):e;for(var o=E.mean(r),i=E.mean(a),s=0,c=0,l=0;l<r.length;l++)s+=((n=r[l])-o)*(a[l]-i),c+=(n-o)*(n-o);var u=s/c,d=i-u*o;return{x0:d,beta:u,fit:function(t){return d+t*u}}}function Ce(t,e){return 0<=t&&t<=1?Math.pow(1-Math.pow(t,e),e):0}function Te(t){var e,r,a,n,o,i,s,c=(a=t,n=E.sum(a.map(function(t){return t.w})),{xbar:E.sum(a.map(function(t){return t.w*t.x}))/n,ybar:E.sum(a.map(function(t){return t.w*t.y}))/n}),l=(o=t,i=r=c.xbar,s=e=c.ybar,E.sum(o.map(function(t){return Math.pow(t.w,2)*(t.x-i)*(t.y-s)}))/E.sum(o.map(function(t){return Math.pow(t.w,2)*Math.pow(t.x-i,2)})));return{beta:l,xbar:r,ybar:e,x0:e-l*r}}function Re(t,e,r,a,n){var o=Math.floor(t.length*r),i=t.slice();i.sort(function(t,e){return t<e?-1:e<t?1:0});for(var s,c,l,u,d,f=E.quantile(i,.98),p=E.quantile(i,.02),_=E.zip(t,e,n).sort(),m=Math.abs(f-p)/a,g=p,h=f,x=E.range(g,h,m),y=[],v=0;v<x.length;v+=1){c=x[v],s=_.map(function(t){return[Math.abs(t[0]-c),t[0],t[1],t[2]]}).sort().slice(0,o),d=E.max(s)[0];var b=Te(s=s.map(function(t){return{w:(e=t[0]/d,Ce(e,3)*t[3]),x:t[1],y:t[2]};var e}));u=b.x0,l=b.beta,y.push(u+l*c)}return{x:x,y:y}}function Ee(r){return"count"===r.format?function(t){var e;return e=t%1!=0?E.format(",."+r.decimals+"f"):E.format(",.0f"),r.yax_units_append?e(t)+r.yax_units:r.yax_units+e(t)}:function(t){var e=(r.decimals?"."+r.decimals:"")+"%";return E.format(e)(t)}}MG.register("missing-data",function(t){var R=this;this.init=function(t){yt(R.args=t),vt(t);var e=E.select(t.target);Gt(e,t);var r,a,n,o,i,s,c,l,u,d,f,p,_,m,g,h,x,y,v,b,w,k,M,G,A,D,O,z,F,C=e.selectAll("svg");if(bt(C,t),kt(C=wt(C,t),t),Mt(C,t),r=t.target,E.select(r).selectAll("svg *").remove(),C.classed("mg-missing",!0),(a=t.legend_target)&&E.select(a).html(""),j(t),t.show_missing_background){!function(t){for(var e=[],r=1;r<=50;r++)e.push({x:r,y:Math.random()-.03*r});t.data=e}(t),(G=t).scales.X=E.scaleLinear().domain([0,G.data.length]).range([Y(G),P(G)]),G.scalefns.yf=function(t){var e=t.y;return G.scales.Y(e)},(M=t).scales.Y=E.scaleLinear().domain([-2,2]).range([M.height-M.bottom-2*M.buffer,M.top]),M.scalefns.xf=function(t){var e=t.x;return M.scales.X(e)};var T=S(C,"mg-missing-pane");h=T,y=(x=t).title,v=x.buffer,b=x.title_y_position,w=x.width,k=x.height,h.append("svg:rect").classed("mg-missing-background",!0).attr("x",v).attr("y",v+2*(y?b:0)).attr("width",w-2*v).attr("height",k-2*v-2*(y?b:0)).attr("rx",15).attr("ry",15),d=T,p=(f=t).scalefns,_=f.interpolate,m=f.data,g=E.line().x(p.xf).y(p.yf).curve(_),d.append("path").attr("class","mg-main-line mg-line1-color").attr("d",g(m)),n=T,i=(o=t).scalefns,s=o.scales,c=o.interpolate,l=o.data,u=E.area().x(i.xf).y0(s.Y.range()[0]).y1(i.yf).curve(c),n.append("path").attr("class","mg-main-area mg-area1-color").attr("d",u(l))}return A=C,O=(D=t).missing_text,z=D.width,F=D.height,A.selectAll(".mg-missing-text").data([O]).enter().append("text").attr("class","mg-missing-text").attr("x",z/2).attr("y",F/2).attr("dy",".50em").attr("text-anchor","middle").text(O),R.windowListeners(),R},this.windowListeners=function(){return Qt(R.args),R},this.init(t)},{top:40,bottom:30,right:10,left:0,buffer:8,legend_target:"",width:350,height:220,missing_text:"Data currently missing or unavailable",scalefns:{},scales:{},show_tooltips:!0,show_missing_background:!0}),MG.raw_data_transformation=Me,MG.process_line=Ae,MG.process_histogram=De,MG.process_categorical_variables=function(t){return"vertical"===t.bar_orientation?t.x_accessor:t.y_accessor,"vertical"===t.bar_orientation?t.y_accessor:t.x_accessor,this},MG.process_point=Oe,MG.add_ls=ze,MG.add_lowess=function(e){var t=O(e.target),r=e.lowess_line,a=E.svg.line().x(function(t){return e.scales.X(t.x)}).y(function(t){return e.scales.Y(t.y)}).interpolate(e.interpolate);t.append("path").attr("d",a(r)).attr("class","mg-lowess-line")},MG.lowess_robust=function(t,e,r,a){var n,o,i=[];for(E.mean(e),o=0;o<t.length;o+=1)i.push(1);var s=(n=Re(t,e,r,a,i)).x,c=n.y;for(o=0;o<100;o+=1){i=E.zip(c,e).map(function(t){return Math.abs(t[1]-t[0])});var l=E.quantile(i.sort(),.5);s=(n=Re(t,e,r,a,i=i.map(function(t){return Ce(t/(6*l),2)}))).x,c=n.y}return E.zip(s,c).map(function(t){var e={};return e.x=t[0],e.y=t[1],e})},MG.lowess=function(t,e,r,a){for(var n=[],o=0;o<t.length;o+=1)n.push(1);Re(t,e,r,a,n)},MG.least_squares=Fe;var Ye=function(t,e,r,a){return"string"==typeof t?MG.time_format(a,t)(e[r]):"function"==typeof t?t(e):e[r]},$e=function(t,e,r){return"string"==typeof t?E.format("s")(e[r]):"function"==typeof t?t(e):e[r]};function Pe(t,e,r,a,n){var o,i=function(t){if(t.rollover_time_format)return MG.time_format(t.utc_time,t.rollover_time_format);switch(t.processed.x_time_frame){case"millis":return MG.time_format(t.utc_time,"%b %e, %Y %H:%M:%S.%L");case"seconds":return MG.time_format(t.utc_time,"%b %e, %Y %H:%M:%S");case"less-than-a-day":case"four-days":return MG.time_format(t.utc_time,"%b %e, %Y %I:%M%p")}return MG.time_format(t.utc_time,"%b %e, %Y")}(t);return o="string"==typeof e[a]?function(t){return t}:Ee(t),null!==r?n?Ye(r,e,a,t.utc):$e(r,e,a):n?i(new Date(+e[a]))+" ":(t.time_series?"":a+": ")+o(e[a])+" "}function Se(t,e){return Pe(t,e,t.x_mouseover,t.x_accessor,t.time_series)}function Le(t,e){return Pe(t,e,t.y_mouseover,t.y_accessor,!1)}function je(c,l){return function(){for(var a=this,n=a.cloneNode(),o=a.getTotalLength()||0,i=(n.setAttribute("d",c),n).getTotalLength()||0,t=[0],e=0,r=l/Math.max(o,i);(e+=r)<1;)t.push(e);t.push(1);var s=t.map(function(t){var e=a.getPointAtLength(t*o),r=n.getPointAtLength(t*i);return E.interpolate([e.x,e.y],[r.x,r.y])});return function(e){return e<1?"M"+s.map(function(t){return t(e)}).join("L"):c}}}function Xe(t){console.error("ERROR : ",t.target," : ",t.error),E.select(t.target).select(".mg-chart-title").append("tspan").attr("class","fa fa-x fa-exclamation-circle mg-warning").attr("dx","0.3em").text("")}return MG.format_rollover_number=Ee,MG.path_tween=je,MG.render_markup=function(t){switch("undefined"==typeof window?"undefined":c(window)){case"undefined":return function(t){var e,r=MG.virtual_window,a=E.select(r.document),n=r.document.createElement("div"),o=global.d3,i=global.window,s=global.document;global.d3=a,global.window=r,global.document=r.document;try{t(n)}catch(t){e=t}if(global.d3=o,global.window=i,global.document=s,e)throw e;return a.select(function(){return n}).html()}(t);default:return e=t,r=document.createElement("div"),e(r),E.select(r).html()}var e,r},MG.init_virtual_window=function(t,e){if(!MG.virtual_window||e){var r=t.jsdom({html:"",features:{QuerySelector:!0}});MG.virtual_window=r.defaultView}},MG.error=Xe,MG});
\ No newline at end of file diff --git a/priv/static/js/metricsgraphics/MG.js b/priv/static/js/metricsgraphics/MG.js new file mode 100644 index 0000000..7f24a0f --- /dev/null +++ b/priv/static/js/metricsgraphics/MG.js @@ -0,0 +1 @@ +(typeof window === 'undefined' ? global : window).MG = {version: '2.11'}; diff --git a/priv/static/js/metricsgraphics/charts/bar.js b/priv/static/js/metricsgraphics/charts/bar.js new file mode 100644 index 0000000..b39d59f --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/bar.js @@ -0,0 +1,792 @@ +{ + // TODO add styles to stylesheet instead + function scaffold({target, width, height, top, left, right, buffer}) { + const svg = mg_get_svg_child_of(target); + // main margins + svg.append('line') + .attr('x1', 0) + .attr('x2', width) + .attr('y1', top) + .attr('y2', top) + .attr('stroke', 'black'); + svg.append('line') + .attr('x1', 0) + .attr('x2', width) + .attr('y1', height - bottom) + .attr('y2', height - bottom) + .attr('stroke', 'black'); + + svg.append('line') + .attr('x1', left) + .attr('x2', left) + .attr('y1', 0) + .attr('y2', height) + .attr('stroke', 'black'); + + svg.append('line') + .attr('x1', width - right) + .attr('x2', width - right) + .attr('y1', 0) + .attr('y2', height) + .attr('stroke', 'black'); + + // plot area margins + svg.append('line') + .attr('x1', 0) + .attr('x2', width) + .attr('y1', height - bottom - buffer) + .attr('y2', height - bottom - buffer) + .attr('stroke', 'gray'); + + svg.append('line') + .attr('x1', 0) + .attr('x2', width) + .attr('y1', top + buffer) + .attr('y2', top + buffer) + .attr('stroke', 'gray'); + + svg.append('line') + .attr('x1', left + buffer) + .attr('x2', left + buffer) + .attr('y1', 0) + .attr('y2', args.height) + .attr('stroke', 'gray'); + svg.append('line') + .attr('x1', width - right - buffer) + .attr('x2', width - right - buffer) + .attr('y1', 0) + .attr('y2', height) + .attr('stroke', 'gray'); + } + + // barchart re-write. + function mg_targeted_legend({legend_target, orientation, scales}) { + let labels; + const plot = ''; + if (legend_target) { + + const div = d3.select(legend_target).append('div').classed('mg-bar-target-legend', true); + + if (orientation == 'horizontal') labels = scales.Y.domain(); + else labels = scales.X.domain(); + + labels.forEach(label => { + const outer_span = div.append('span').classed('mg-bar-target-element', true); + outer_span.append('span') + .classed('mg-bar-target-legend-shape', true) + .style('color', scales.COLOR(label)) + .text('\u25FC '); + outer_span.append('span') + .classed('mg-bar-target-legend-text', true) + .text(label); + }); + } + } + + function legend_on_graph(svg, args) { + // draw each element at the top right + // get labels + + let labels; + if (args.orientation=='horizontal') labels = args.scales.Y.domain(); + else labels = args.scales.X.domain(); + + let lineCount = 0; + const lineHeight = 1.1; + const g = svg.append('g').classed("mg-bar-legend", true); + const textContainer = g.append('text'); + + textContainer + .selectAll('*') + .remove(); + textContainer + .attr('width', args.right) + .attr('height', 100) + .attr('text-anchor', 'start'); + + labels.forEach(label => { + const sub_container = textContainer.append('tspan') + .attr('x', mg_get_plot_right(args)) + .attr('y', args.height / 2) + .attr('dy', `${lineCount * lineHeight}em`); + sub_container.append('tspan') + .text('\u25a0 ') + .attr('fill', args.scales.COLOR(label)) + .attr('font-size', 20); + sub_container.append('tspan') + .text(label) + .attr('font-weight', 300) + .attr('font-size', 10); + lineCount++; + }); + + // d.values.forEach(function (datum) { + // formatted_y = mg_format_y_rollover(args, num, datum); + + // if (args.y_rollover_format !== null) { + // formatted_y = number_rollover_format(args.y_rollover_format, datum, args.y_accessor); + // } else { + // formatted_y = args.yax_units + num(datum[args.y_accessor]); + // } + + // sub_container = textContainer.append('tspan').attr('x', 0).attr('y', (lineCount * lineHeight) + 'em'); + // formatted_y = mg_format_y_rollover(args, num, datum); + // mouseover_tspan(sub_container, '\u2014 ') + // .color(args, datum); + // mouseover_tspan(sub_container, formatted_x + ' ' + formatted_y); + + // lineCount++; + // }); + } + + function barChart(args) { + this.args = args; + + this.init = (args) => { + this.args = args; + args.x_axis_type = mg_infer_type(args, 'x'); + args.y_axis_type = mg_infer_type(args, 'y'); + + // this is specific to how rects work in svg, let's keep track of the bar orientation to + // plot appropriately. + if (args.x_axis_type == 'categorical') { + args.orientation = 'vertical'; + } else if (args.y_axis_type == 'categorical') { + args.orientation = 'horizontal'; + } else if (args.x_axis_type != 'categorical' && args.y_axis_type != 'categorical') { + // histogram. + args.orientation = 'vertical'; + } + + raw_data_transformation(args); + + process_point(args); + init(args); + + let xMaker; + let yMaker; + + if (args.x_axis_type === 'categorical') { + xMaker = MG.scale_factory(args) + .namespace('x') + .categoricalDomainFromData() + .categoricalRangeBands([0, args.xgroup_height], args.xgroup_accessor === null); + + if (args.xgroup_accessor) { + new MG.scale_factory(args) + .namespace('xgroup') + .categoricalDomainFromData() + .categoricalRangeBands('bottom'); + + } else { + args.scales.XGROUP = d => mg_get_plot_left(args); + args.scalefns.xgroupf = d => mg_get_plot_left(args); + } + + args.scalefns.xoutf = d => args.scalefns.xf(d) + args.scalefns.xgroupf(d); + } else { + xMaker = MG.scale_factory(args) + .namespace('x') + .inflateDomain(true) + .zeroBottom(args.y_axis_type === 'categorical') + .numericalDomainFromData((args.baselines || []).map(d => d[args.x_accessor])) + .numericalRange('bottom'); + + args.scalefns.xoutf = args.scalefns.xf; + } + + // y-scale generation. This needs to get simplified. + if (args.y_axis_type === 'categorical') { + yMaker = MG.scale_factory(args) + .namespace('y') + .zeroBottom(true) + .categoricalDomainFromData() + .categoricalRangeBands([0, args.ygroup_height], true); + + if (args.ygroup_accessor) { + + new MG.scale_factory(args) + .namespace('ygroup') + .categoricalDomainFromData() + .categoricalRangeBands('left'); + + } else { + args.scales.YGROUP = () => mg_get_plot_top(args); + args.scalefns.ygroupf = d => mg_get_plot_top(args); + + } + args.scalefns.youtf = d => args.scalefns.yf(d) + args.scalefns.ygroupf(d); + + } else { + const baselines = (args.baselines || []).map(d => d[args.y_accessor]); + + yMaker = MG.scale_factory(args) + .namespace('y') + .inflateDomain(true) + .zeroBottom(args.x_axis_type === 'categorical') + .numericalDomainFromData(baselines) + .numericalRange('left'); + + args.scalefns.youtf = d => args.scalefns.yf(d); + } + + if (args.ygroup_accessor !== null) { + args.ycolor_accessor = args.y_accessor; + MG.scale_factory(args) + .namespace('ycolor') + .scaleName('color') + .categoricalDomainFromData() + .categoricalColorRange(); + } + + if (args.xgroup_accessor !== null) { + args.xcolor_accessor = args.x_accessor; + MG.scale_factory(args) + .namespace('xcolor') + .scaleName('color') + .categoricalDomainFromData() + .categoricalColorRange(); + } + + // if (args.ygroup_accessor !== null) { + // MG.scale_factory(args) + // .namespace('ygroup') + // .categoricalDomainFromData() + // .categoricalColorRange(); + // } + + new MG.axis_factory(args) + .namespace('x') + .type(args.x_axis_type) + .zeroLine(args.y_axis_type === 'categorical') + .position(args.x_axis_position) + .draw(); + + new MG.axis_factory(args) + .namespace('y') + .type(args.y_axis_type) + .zeroLine(args.x_axis_type === 'categorical') + .position(args.y_axis_position) + .draw(); + + //mg_categorical_group_color_scale(args); + + this.mainPlot(); + this.markers(); + this.rollover(); + this.windowListeners(); + //scaffold(args) + + return this; + }; + + this.mainPlot = () => { + const svg = mg_get_svg_child_of(args.target); + const data = args.data[0]; + let barplot = svg.select('g.mg-barplot'); + const fresh_render = barplot.empty(); + + let bars, predictor_bars, pp, pp0, baseline_marks; + + const perform_load_animation = fresh_render && args.animate_on_load; + const should_transition = perform_load_animation || args.transition_on_update; + const transition_duration = args.transition_duration || 1000; + + // draw the plot on first render + if (fresh_render) { + barplot = svg.append('g') + .classed('mg-barplot', true); + } + + bars = barplot.selectAll('.mg-bar') + .data(data) + .enter() + .append('rect') + .classed('mg-bar', true) + .classed('default-bar', args.scales.hasOwnProperty('COLOR') ? false : true); + + // TODO - reimplement + + // reference_accessor {} + + // if (args.predictor_accessor) { + // predictor_bars = barplot.selectAll('.mg-bar-prediction') + // .data(data.filter(function(d) { + // return d.hasOwnProperty(args.predictor_accessor) })); + + // predictor_bars.exit().remove(); + + // predictor_bars.enter().append('rect') + // .classed('mg-bar-prediction', true); + // } + + // if (args.baseline_accessor) { + // baseline_marks = barplot.selectAll('.mg-bar-baseline') + // .data(data.filter(function(d) { + // return d.hasOwnProperty(args.baseline_accessor) })); + + // baseline_marks.exit().remove(); + + // baseline_marks.enter().append('line') + // .classed('mg-bar-baseline', true); + // } + + let appropriate_size; + + // setup transitions + // if (should_transition) { + // bars = bars.transition() + // .duration(transition_duration); + + // if (predictor_bars) { + // predictor_bars = predictor_bars.transition() + // .duration(transition_duration); + // } + + // if (baseline_marks) { + // baseline_marks = baseline_marks.transition() + // .duration(transition_duration); + // } + // } + + //appropriate_size = args.scales.Y_ingroup.rangeBand()/1.5; + let length, width, length_type, width_type, length_coord, width_coord, + length_scalefn, width_scalefn, length_scale, width_scale, + length_accessor, width_accessor, length_coord_map, width_coord_map, + length_map, width_map; + + let reference_length_map, reference_length_coord_fn; + + if (args.orientation == 'vertical') { + length = 'height'; + width = 'width'; + length_type = args.y_axis_type; + width_type = args.x_axis_type; + length_coord = 'y'; + width_coord = 'x'; + length_scalefn = length_type == 'categorical' ? args.scalefns.youtf : args.scalefns.yf; + width_scalefn = width_type == 'categorical' ? args.scalefns.xoutf : args.scalefns.xf; + length_scale = args.scales.Y; + width_scale = args.scales.X; + length_accessor = args.y_accessor; + width_accessor = args.x_accessor; + + length_coord_map = d => { + let l; + l = length_scalefn(d); + if (d[length_accessor] < 0) { + l = length_scale(0); + } + return l; + }; + + length_map = d => Math.abs(length_scalefn(d) - length_scale(0)); + + reference_length_map = d => Math.abs(length_scale(d[args.reference_accessor]) - length_scale(0)); + + reference_length_coord_fn = d => length_scale(d[args.reference_accessor]); + } + + if (args.orientation == 'horizontal') { + length = 'width'; + width = 'height'; + length_type = args.x_axis_type; + width_type = args.y_axis_type; + length_coord = 'x'; + width_coord = 'y'; + length_scalefn = length_type == 'categorical' ? args.scalefns.xoutf : args.scalefns.xf; + width_scalefn = width_type == 'categorical' ? args.scalefns.youtf : args.scalefns.yf; + length_scale = args.scales.X; + width_scale = args.scales.Y; + length_accessor = args.x_accessor; + width_accessor = args.y_accessor; + + length_coord_map = d => { + let l; + l = length_scale(0); + return l; + }; + + length_map = d => Math.abs(length_scalefn(d) - length_scale(0)); + + reference_length_map = d => Math.abs(length_scale(d[args.reference_accessor]) - length_scale(0)); + + reference_length_coord_fn = d => length_scale(0); + } + + // if (perform_load_animation) { + // bars.attr(length, 0); + + // if (predictor_bars) { + // predictor_bars.attr(length, 0); + // } + + // // if (baseline_marks) { + // // baseline_marks.attr({ + // // x1: args.scales.X(0), + // // x2: args.scales.X(0) + // // }); + // // } + // } + + bars.attr(length_coord, length_coord_map); + + // bars.attr(length_coord, 40) + //bars.attr(width_coord, 70) + + bars.attr(width_coord, d => { + let w; + if (width_type == 'categorical') { + w = width_scalefn(d); + } else { + w = width_scale(0); + if (d[width_accessor] < 0) { + w = width_scalefn(d); + } + } + w = w - args.bar_thickness/2; + return w; + }); + + if (args.scales.COLOR) { + bars.attr('fill', args.scalefns.colorf); + } + + bars + .attr(length, length_map) + .attr(width, d => args.bar_thickness); + + if (args.reference_accessor !== null) { + const reference_data = data.filter(d => d.hasOwnProperty(args.reference_accessor)); + const reference_bars = barplot.selectAll('.mg-categorical-reference') + .data(reference_data) + .enter() + .append('rect'); + + reference_bars + .attr(length_coord, reference_length_coord_fn) + .attr(width_coord, d => width_scalefn(d) - args.reference_thickness/2) + .attr(length, reference_length_map) + .attr(width, args.reference_thickness); + } + + if (args.comparison_accessor !== null) { + let comparison_thickness = null; + if (args.comparison_thickness === null) { + comparison_thickness = args.bar_thickness/2; + } else { + comparison_thickness = args.comparison_thickness; + } + + const comparison_data = data.filter(d => d.hasOwnProperty(args.comparison_accessor)); + const comparison_marks = barplot.selectAll('.mg-categorical-comparison') + .data(comparison_data) + .enter() + .append('line'); + + comparison_marks + .attr(`${length_coord}1`, d => length_scale(d[args.comparison_accessor])) + .attr(`${length_coord}2`, d => length_scale(d[args.comparison_accessor])) + .attr(`${width_coord}1`, d => width_scalefn(d) - comparison_thickness/2) + .attr(`${width_coord}2`, d => width_scalefn(d) + comparison_thickness/2) + .attr('stroke', 'black') + .attr('stroke-width', args.comparison_width); + } + + //bars.attr(width_coord, ); + // bars.attr('width', 50); + // bars.attr('height', 50); + // bars.attr('y', function(d){ + // var y = args.scales.Y(0); + // if (d[args.y_accessor] < 0) { + // y = args.scalefns.yf(d); + // } + // return y; + // }); + + // bars.attr('x', function(d){ + // return 40; + // }) + + // bars.attr('width', function(d){ + // return 100; + // }); + + // bars.attr('height', 100); + + // bars.attr('fill', 'black'); + // bars.attr('x', function(d) { + // var x = args.scales.X(0); + // if (d[args.x_accessor] < 0) { + // x = args.scalefns.xf(d); + // } + // return x; + // }) + // TODO - reimplement. + // if (args.predictor_accessor) { + // predictor_bars + // .attr('x', args.scales.X(0)) + // .attr('y', function(d) { + // return args.scalefns.ygroupf(d) + args.scalefns.yf(d) + args.scales.Y.rangeBand() * (7 / 16) // + pp0 * appropriate_size/(pp*2) + appropriate_size / 2; + // }) + // .attr('height', args.scales.Y.rangeBand() / 8) //appropriate_size / pp) + // .attr('width', function(d) { + // return args.scales.X(d[args.predictor_accessor]) - args.scales.X(0); + // }); + // } + + // TODO - reimplement. + // if (args.baseline_accessor) { + + // baseline_marks + // .attr('x1', function(d) { + // return args.scales.X(d[args.baseline_accessor]); }) + // .attr('x2', function(d) { + // return args.scales.X(d[args.baseline_accessor]); }) + // .attr('y1', function(d) { + // return args.scalefns.ygroupf(d) + args.scalefns.yf(d) + args.scales.Y.rangeBand() / 4 + // }) + // .attr('y2', function(d) { + // return args.scalefns.ygroupf(d) + args.scalefns.yf(d) + args.scales.Y.rangeBand() * 3 / 4 + // }); + // } + if (args.legend || (args.color_accessor !== null && args.ygroup_accessor !== args.color_accessor)) { + if (!args.legend_target) legend_on_graph(svg, args); + else mg_targeted_legend(args); + } + return this; + }; + + this.markers = () => { + markers(args); + return this; + }; + + this.rollover = () => { + const svg = mg_get_svg_child_of(args.target); + let g; + + if (svg.selectAll('.mg-active-datapoint-container').nodes().length === 0) { + mg_add_g(svg, 'mg-active-datapoint-container'); + } + + //remove the old rollovers if they already exist + svg.selectAll('.mg-rollover-rect').remove(); + svg.selectAll('.mg-active-datapoint').remove(); + + // get orientation + let length, width, length_type, width_type, length_coord, width_coord, + length_scalefn, width_scalefn, length_scale, width_scale, + length_accessor, width_accessor; + + let length_coord_map, width_coord_map, length_map, width_map; + + if (args.orientation == 'vertical') { + length = 'height'; + width = 'width'; + length_type = args.y_axis_type; + width_type = args.x_axis_type; + length_coord = 'y'; + width_coord = 'x'; + length_scalefn = length_type == 'categorical' ? args.scalefns.youtf : args.scalefns.yf; + width_scalefn = width_type == 'categorical' ? args.scalefns.xoutf : args.scalefns.xf; + length_scale = args.scales.Y; + width_scale = args.scales.X; + length_accessor = args.y_accessor; + width_accessor = args.x_accessor; + + length_coord_map = d => mg_get_plot_top(args); + + length_map = d => args.height -args.top-args.bottom-args.buffer*2; + } + + if (args.orientation == 'horizontal') { + length = 'width'; + width = 'height'; + length_type = args.x_axis_type; + width_type = args.y_axis_type; + length_coord = 'x'; + width_coord = 'y'; + length_scalefn = length_type == 'categorical' ? args.scalefns.xoutf : args.scalefns.xf; + width_scalefn = width_type == 'categorical' ? args.scalefns.youtf : args.scalefns.yf; + length_scale = args.scales.X; + width_scale = args.scales.Y; + length_accessor = args.x_accessor; + width_accessor = args.y_accessor; + + length_coord_map = d => { + let l; + l = length_scale(0); + return l; + }; + + length_map = d => args.width -args.left-args.right-args.buffer*2; + } + + //rollover text + let rollover_x, rollover_anchor; + if (args.rollover_align === 'right') { + rollover_x = args.width - args.right; + rollover_anchor = 'end'; + } else if (args.rollover_align === 'left') { + rollover_x = args.left; + rollover_anchor = 'start'; + } else { + rollover_x = (args.width - args.left - args.right) / 2 + args.left; + rollover_anchor = 'middle'; + } + + svg.append('text') + .attr('class', 'mg-active-datapoint') + .attr('xml:space', 'preserve') + .attr('x', rollover_x) + .attr('y', args.top * 0.75) + .attr('dy', '.35em') + .attr('text-anchor', rollover_anchor); + + g = svg.append('g') + .attr('class', 'mg-rollover-rect'); + + //draw rollover bars + const bars = g.selectAll(".mg-bar-rollover") + .data(args.data[0]).enter() + .append("rect") + .attr('class', 'mg-bar-rollover'); + + bars.attr('opacity', 0) + .attr(length_coord, length_coord_map) + .attr(width_coord, d => { + let w; + if (width_type == 'categorical') { + w = width_scalefn(d); + } else { + w = width_scale(0); + if (d[width_accessor] < 0) { + w = width_scalefn(d); + } + } + w = w - args.bar_thickness/2; + return w; + }); + + bars.attr(length, length_map); + bars.attr(width, d => args.bar_thickness); + + bars + .on('mouseover', this.rolloverOn(args)) + .on('mouseout', this.rolloverOff(args)) + .on('mousemove', this.rolloverMove(args)); + + return this; + }; + + this.rolloverOn = (args) => { + const svg = mg_get_svg_child_of(args.target); + const label_accessor = this.is_vertical ? args.x_accessor : args.y_accessor; + const data_accessor = this.is_vertical ? args.y_accessor : args.x_accessor; + const label_units = this.is_vertical ? args.yax_units : args.xax_units; + + return (d, i) => { + + const fmt = MG.time_format(args.utc_time, '%b %e, %Y'); + const num = format_rollover_number(args); + + //highlight active bar + const bar = svg.selectAll('g.mg-barplot .mg-bar') + .filter((d, j) => j === i).classed('active', true); + + if (args.scales.hasOwnProperty('COLOR')) { + bar.attr('fill', d3.rgb(args.scalefns.colorf(d)).darker()); + } else { + bar.classed('default-active', true); + } + + //update rollover text + if (args.show_rollover_text) { + const mouseover = mg_mouseover_text(args, { svg }); + let row = mouseover.mouseover_row(); + + if (args.ygroup_accessor) row.text(`${d[args.ygroup_accessor]} `).bold(); + + row.text(mg_format_x_mouseover(args, d)); + row.text(`${args.y_accessor}: ${d[args.y_accessor]}`); + if (args.predictor_accessor || args.baseline_accessor) { + row = mouseover.mouseover_row(); + + if (args.predictor_accessor) row.text(mg_format_data_for_mouseover(args, d, null, args.predictor_accessor, false)); + if (args.baseline_accessor) row.text(mg_format_data_for_mouseover(args, d, null, args.baseline_accessor, false)); + } + } + if (args.mouseover) { + args.mouseover(d, i); + } + }; + }; + + this.rolloverOff = (args) => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + //reset active bar + const bar = svg.selectAll('g.mg-barplot .mg-bar.active').classed('active', false); + + if (args.scales.hasOwnProperty('COLOR')) { + bar.attr('fill', args.scalefns.colorf(d)); + } else { + bar.classed('default-active', false); + } + + //reset active data point text + svg.select('.mg-active-datapoint') + .text(''); + + mg_clear_mouseover_container(svg); + + if (args.mouseout) { + args.mouseout(d, i); + } + }; + }; + + this.rolloverMove = (args) => (d, i) => { + if (args.mousemove) { + args.mousemove(d, i); + } + }; + + this.windowListeners = () => { + mg_window_listeners(this.args); + return this; + }; + + this.init(args); + } + + const options = { + buffer: [16, 'number'], + y_accessor: ['factor', 'string'], + x_accessor: ['value', 'string'], + reference_accessor: [null, 'string'], + comparison_accessor: [null, 'string'], + secondary_label_accessor: [null, 'string'], + color_accessor: [null, 'string'], + color_type: ['category', ['number', 'category']], + color_domain: [null, 'number[]'], + reference_thickness: [1, 'number'], + comparison_width: [3, 'number'], + comparison_thickness: [null, 'number'], + legend: [false, 'boolean'], + legend_target: [null, 'string'], + mouseover_align: ['right', ['right', 'left']], + baseline_accessor: [null, 'string'], + predictor_accessor: [null, 'string'], + predictor_proportion: [5, 'number'], + show_bar_zero: [true, 'boolean'], + binned: [true, 'boolean'], + truncate_x_labels: [true, 'boolean'], + truncate_y_labels: [true, 'boolean'] + }; + + MG.register('bar', barChart, options); + +} diff --git a/priv/static/js/metricsgraphics/charts/histogram.js b/priv/static/js/metricsgraphics/charts/histogram.js new file mode 100644 index 0000000..3fca8e3 --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/histogram.js @@ -0,0 +1,222 @@ +{ + function histogram(args) { + this.init = (args) => { + this.args = args; + + raw_data_transformation(args); + process_histogram(args); + init(args); + + new MG.scale_factory(args) + .namespace('x') + .numericalDomainFromData() + .numericalRange('bottom'); + + const baselines = (args.baselines || []).map(d => d[args.y_accessor]); + + new MG.scale_factory(args) + .namespace('y') + .zeroBottom(true) + .inflateDomain(true) + .numericalDomainFromData(baselines) + .numericalRange('left'); + + x_axis(args); + y_axis(args); + + this.mainPlot(); + this.markers(); + this.rollover(); + this.windowListeners(); + + return this; + }; + + this.mainPlot = () => { + const svg = mg_get_svg_child_of(args.target); + + //remove the old histogram, add new one + svg.selectAll('.mg-histogram').remove(); + + const g = svg.append('g') + .attr('class', 'mg-histogram'); + + const bar = g.selectAll('.mg-bar') + .data(args.data[0]) + .enter().append('g') + .attr('class', 'mg-bar') + .attr('transform', d => `translate(${args.scales.X(d[args.x_accessor]).toFixed(2)},${args.scales.Y(d[args.y_accessor]).toFixed(2)})`); + + //draw bars + bar.append('rect') + .attr('x', 1) + .attr('width', (d, i) => { + if (args.data[0].length === 1) { + return (args.scalefns.xf(args.data[0][0]) - args.bar_margin).toFixed(0); + } else if (i !== args.data[0].length - 1) { + return (args.scalefns.xf(args.data[0][i + 1]) - args.scalefns.xf(d)).toFixed(0); + } else { + return (args.scalefns.xf(args.data[0][1]) - args.scalefns.xf(args.data[0][0])).toFixed(0); + } + }) + .attr('height', d => { + if (d[args.y_accessor] === 0) { + return 0; + } + + return (args.height - args.bottom - args.buffer - args.scales.Y(d[args.y_accessor])).toFixed(2); + }); + + return this; + }; + + this.markers = () => { + markers(args); + return this; + }; + + this.rollover = () => { + const svg = mg_get_svg_child_of(args.target); + + if (svg.selectAll('.mg-active-datapoint-container').nodes().length === 0) { + mg_add_g(svg, 'mg-active-datapoint-container'); + } + + //remove the old rollovers if they already exist + svg.selectAll('.mg-rollover-rect').remove(); + svg.selectAll('.mg-active-datapoint').remove(); + + const g = svg.append('g') + .attr('class', 'mg-rollover-rect'); + + //draw rollover bars + const bar = g.selectAll('.mg-bar') + .data(args.data[0]) + .enter().append('g') + .attr('class', (d, i) => { + if (args.linked) { + return `mg-rollover-rects roll_${i}`; + } else { + return 'mg-rollover-rects'; + } + }) + .attr('transform', d => `translate(${args.scales.X(d[args.x_accessor])},${0})`); + + bar.append('rect') + .attr('x', 1) + .attr('y', args.buffer + (args.title ? args.title_y_position : 0)) + .attr('width', (d, i) => { + //if data set is of length 1 + if (args.data[0].length === 1) { + return (args.scalefns.xf(args.data[0][0]) - args.bar_margin).toFixed(0); + } else if (i !== args.data[0].length - 1) { + return (args.scalefns.xf(args.data[0][i + 1]) - args.scalefns.xf(d)).toFixed(0); + } else { + return (args.scalefns.xf(args.data[0][1]) - args.scalefns.xf(args.data[0][0])).toFixed(0); + } + }) + .attr('height', d => args.height) + .attr('opacity', 0) + .on('mouseover', this.rolloverOn(args)) + .on('mouseout', this.rolloverOff(args)) + .on('mousemove', this.rolloverMove(args)); + + return this; + }; + + this.rolloverOn = (args) => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + svg.selectAll('text') + .filter((g, j) => d === g) + .attr('opacity', 0.3); + + const fmt = args.processed.xax_format || MG.time_format(args.utc_time, '%b %e, %Y'); + const num = format_rollover_number(args); + + svg.selectAll('.mg-bar rect') + .filter((d, j) => j === i) + .classed('active', true); + + //trigger mouseover on all matching bars + if (args.linked && !MG.globals.link) { + MG.globals.link = true; + + //trigger mouseover on matching bars in .linked charts + d3.selectAll(`.mg-rollover-rects.roll_${i} rect`) + .each(function(d) { //use existing i + d3.select(this).on('mouseover')(d, i); + }); + } + + //update rollover text + if (args.show_rollover_text) { + const mo = mg_mouseover_text(args, { svg }); + const row = mo.mouseover_row(); + row.text('\u259F ').elem + .classed('hist-symbol', true); + + row.text(mg_format_x_mouseover(args, d)); // x + row.text(mg_format_y_mouseover(args, d, args.time_series === false)); + } + + if (args.mouseover) { + mg_setup_mouseover_container(svg, args); + args.mouseover(d, i); + } + }; + }; + + this.rolloverOff = (args) => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + if (args.linked && MG.globals.link) { + MG.globals.link = false; + + //trigger mouseout on matching bars in .linked charts + d3.selectAll(`.mg-rollover-rects.roll_${i} rect`) + .each(function(d) { //use existing i + d3.select(this).on('mouseout')(d, i); + }); + } + + //reset active bar + svg.selectAll('.mg-bar rect') + .classed('active', false); + + //reset active data point text + mg_clear_mouseover_container(svg); + + if (args.mouseout) { + args.mouseout(d, i); + } + }; + }; + + this.rolloverMove = (args) => (d, i) => { + if (args.mousemove) { + args.mousemove(d, i); + } + }; + + this.windowListeners = () => { + mg_window_listeners(this.args); + return this; + }; + + this.init(args); + } + + const options = { + bar_margin: [1, "number"], // the margin between bars + binned: [false, "boolean"], // determines whether the data is already binned + bins: [null, ['number', 'number[]', 'function']], // the number of bins to use. type: {null, number | thresholds | threshold_function} + processed_x_accessor: ['x', 'string'], + processed_y_accessor: ['y', 'string'], + processed_dx_accessor: ['dx', 'string'] + }; + + MG.register('histogram', histogram, options); +} diff --git a/priv/static/js/metricsgraphics/charts/line.js b/priv/static/js/metricsgraphics/charts/line.js new file mode 100644 index 0000000..f441af3 --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/line.js @@ -0,0 +1,922 @@ +{ + function mg_line_color_text(elem, line_id, {color, colors}) { + elem.classed('mg-hover-line-color', color === null) + .classed(`mg-hover-line${line_id}-color`, colors === null) + .attr('fill', colors === null ? '' : colors[line_id - 1]); + } + + function mg_line_graph_generators(args, plot, svg) { + mg_add_line_generator(args, plot); + mg_add_area_generator(args, plot); + mg_add_flat_line_generator(args, plot); + mg_add_confidence_band_generator(args, plot, svg); + } + + function mg_add_confidence_band_generator(args, plot, svg) { + plot.existing_band = svg.selectAll('.mg-confidence-band').nodes(); + if (args.show_confidence_band) { + plot.confidence_area = d3.area() + .defined(plot.line.defined()) + .x(args.scalefns.xf) + .y0(d => { + const l = args.show_confidence_band[0]; + if (d[l] != undefined) { + return args.scales.Y(d[l]); + } else { + return args.scales.Y(d[args.y_accessor]); + } + }) + .y1(d => { + const u = args.show_confidence_band[1]; + if (d[u] != undefined) { + return args.scales.Y(d[u]); + } else { + return args.scales.Y(d[args.y_accessor]); + } + }) + .curve(args.interpolate); + } + } + + function mg_add_area_generator({scalefns, scales, interpolate, flip_area_under_y_value}, plot) { + + const areaBaselineValue = (Number.isFinite(flip_area_under_y_value)) ? scales.Y(flip_area_under_y_value) : scales.Y.range()[0]; + + plot.area = d3.area() + .defined(plot.line.defined()) + .x(scalefns.xf) + .y0(() => { + return areaBaselineValue; + }) + .y1(scalefns.yf) + .curve(interpolate); + } + + function mg_add_flat_line_generator({y_accessor, scalefns, scales, interpolate}, plot) { + plot.flat_line = d3.line() + .defined(d => (d['_missing'] === undefined || d['_missing'] !== true) && d[y_accessor] !== null) + .x(scalefns.xf) + .y(() => scales.Y(plot.data_median)) + .curve(interpolate); + } + + function mg_add_line_generator({scalefns, interpolate, missing_is_zero, y_accessor}, plot) { + plot.line = d3.line() + .x(scalefns.xf) + .y(scalefns.yf) + .curve(interpolate); + + // if missing_is_zero is not set, then hide data points that fall in missing + // data ranges or that have been explicitly identified as missing in the + // data source. + if (!missing_is_zero) { + // a line is defined if the _missing attrib is not set to true + // and the y-accessor is not null + plot.line = plot.line.defined(d => (d['_missing'] === undefined || d['_missing'] !== true) && d[y_accessor] !== null); + } + } + + function mg_add_confidence_band( + {show_confidence_band, transition_on_update, data, target}, + plot, + svg, + which_line + ) { + if (show_confidence_band) { + let confidenceBand; + if (svg.select(`.mg-confidence-band-${which_line}`).empty()) { + svg.append('path') + .attr('class', `mg-confidence-band mg-confidence-band-${which_line}`); + } + + // transition this line's confidence band + confidenceBand = svg.select(`.mg-confidence-band-${which_line}`); + + confidenceBand + .transition() + .duration(() => (transition_on_update) ? 1000 : 0) + .attr('d', plot.confidence_area(data[which_line - 1])) + .attr('clip-path', `url(#mg-plot-window-${mg_target_ref(target)})`); + } + } + + function mg_add_area({data, target, colors}, plot, svg, which_line, line_id) { + const areas = svg.selectAll(`.mg-main-area.mg-area${line_id}`); + if (plot.display_area) { + // if area already exists, transition it + if (!areas.empty()) { + svg.node().appendChild(areas.node()); + + areas.transition() + .duration(plot.update_transition_duration) + .attr('d', plot.area(data[which_line])) + .attr('clip-path', `url(#mg-plot-window-${mg_target_ref(target)})`); + } else { // otherwise, add the area + svg.append('path') + .classed('mg-main-area', true) + .classed(`mg-area${line_id}`, true) + .classed('mg-area-color', colors === null) + .classed(`mg-area${line_id}-color`, colors === null) + .attr('d', plot.area(data[which_line])) + .attr('fill', colors === null ? '' : colors[line_id - 1]) + .attr('clip-path', `url(#mg-plot-window-${mg_target_ref(target)})`); + } + } else if (!areas.empty()) { + areas.remove(); + } + } + + function mg_default_color_for_path(this_path, line_id) { + this_path.classed('mg-line-color', true) + .classed(`mg-line${line_id}-color`, true); + } + + function mg_color_line({colors}, this_path, which_line, line_id) { + if (colors) { + // for now, if args.colors is not an array, then keep moving as if nothing happened. + // if args.colors is not long enough, default to the usual line_id color. + if (colors.constructor === Array) { + this_path.attr('stroke', colors[which_line]); + if (colors.length < which_line + 1) { + // Go with default coloring. + // this_path.classed('mg-line' + (line_id) + '-color', true); + mg_default_color_for_path(this_path, line_id); + } + } else { + // this_path.classed('mg-line' + (line_id) + '-color', true); + mg_default_color_for_path(this_path, line_id); + } + } else { + // this is the typical workflow + // this_path.classed('mg-line' + (line_id) + '-color', true); + mg_default_color_for_path(this_path, line_id); + } + } + + function mg_add_line_element({animate_on_load, data, y_accessor, target}, plot, this_path, which_line) { + if (animate_on_load) { + plot.data_median = d3.median(data[which_line], d => d[y_accessor]); + this_path.attr('d', plot.flat_line(data[which_line])) + .transition() + .duration(1000) + .attr('d', plot.line(data[which_line])) + .attr('clip-path', `url(#mg-plot-window-${mg_target_ref(target)})`); + } else { // or just add the line + this_path.attr('d', plot.line(data[which_line])) + .attr('clip-path', `url(#mg-plot-window-${mg_target_ref(target)})`); + } + } + + function mg_add_line(args, plot, svg, existing_line, which_line, line_id) { + if (!existing_line.empty()) { + svg.node().appendChild(existing_line.node()); + + const lineTransition = existing_line.transition() + .duration(plot.update_transition_duration); + + if (!plot.display_area && args.transition_on_update && !args.missing_is_hidden) { + lineTransition.attrTween('d', path_tween(plot.line(args.data[which_line]), 4)); + } else { + lineTransition.attr('d', plot.line(args.data[which_line])); + } + } else { // otherwise... + // if we're animating on load, animate the line from its median value + const this_path = svg.append('path') + .attr('class', `mg-main-line mg-line${line_id}`); + + mg_color_line(args, this_path, which_line, line_id); + mg_add_line_element(args, plot, this_path, which_line); + } + } + + function mg_add_legend_element(args, plot, which_line, line_id) { + let this_legend; + if (args.legend) { + if (is_array(args.legend)) { + this_legend = args.legend[which_line]; + } else if (is_function(args.legend)) { + this_legend = args.legend(args.data[which_line]); + } + + if (args.legend_target) { + if (args.colors && args.colors.constructor === Array) { + plot.legend_text = `<span style='color:${args.colors[which_line]}'>— ${this_legend} </span>${plot.legend_text}`; + } else { + plot.legend_text = `<span class='mg-line${line_id}-legend-color'>— ${this_legend} </span>${plot.legend_text}`; + } + } else { + let anchor_point, anchor_orientation, dx; + + if (args.y_axis_position === 'left') { + anchor_point = args.data[which_line][args.data[which_line].length - 1]; + anchor_orientation = 'start'; + dx = args.buffer; + } else { + anchor_point = args.data[which_line][0]; + anchor_orientation = 'end'; + dx = -args.buffer; + } + const legend_text = plot.legend_group.append('svg:text') + .attr('x', args.scalefns.xf(anchor_point)) + .attr('dx', dx) + .attr('y', args.scalefns.yf(anchor_point)) + .attr('dy', '.35em') + .attr('font-size', 10) + .attr('text-anchor', anchor_orientation) + .attr('font-weight', '300') + .text(this_legend); + + if (args.colors && args.colors.constructor === Array) { + if (args.colors.length < which_line + 1) { + legend_text.classed(`mg-line${line_id}-legend-color`, true); + } else { + legend_text.attr('fill', args.colors[which_line]); + } + } else { + legend_text.classed('mg-line-legend-color', true) + .classed(`mg-line${line_id}-legend-color`, true); + } + + mg_prevent_vertical_overlap(plot.legend_group.selectAll('.mg-line-legend text').nodes(), args); + } + } + } + + function mg_plot_legend_if_legend_target(target, legend) { + if (target) d3.select(target).html(legend); + } + + function mg_add_legend_group({legend}, plot, svg) { + if (legend) plot.legend_group = mg_add_g(svg, 'mg-line-legend'); + } + + function mg_remove_existing_line_rollover_elements(svg) { + // remove the old rollovers if they already exist + mg_selectAll_and_remove(svg, '.mg-rollover-rect'); + mg_selectAll_and_remove(svg, '.mg-voronoi'); + + // remove the old rollover text and circle if they already exist + mg_selectAll_and_remove(svg, '.mg-active-datapoint'); + mg_selectAll_and_remove(svg, '.mg-line-rollover-circle'); + //mg_selectAll_and_remove(svg, '.mg-active-datapoint-container'); + } + + function mg_add_rollover_circle({data, colors}, svg) { + // append circle + const circle = svg.selectAll('.mg-line-rollover-circle') + .data(data) + .enter().append('circle') + .attr('cx', 0) + .attr('cy', 0) + .attr('r', 0); + + if (colors && colors.constructor === Array) { + circle + .attr('class', ({__line_id__}) => `mg-line${__line_id__}`) + .attr('fill', (d, i) => colors[i]) + .attr('stroke', (d, i) => colors[i]); + } else { + circle.attr('class', ({__line_id__}, i) => [ + `mg-line${__line_id__}`, + `mg-line${__line_id__}-color`, + `mg-area${__line_id__}-color` + ].join(' ')); + } + circle.classed('mg-line-rollover-circle', true); + } + + function mg_set_unique_line_id_for_each_series({data, custom_line_color_map}) { + // update our data by setting a unique line id for each series + // increment from 1... unless we have a custom increment series + + for (let i = 0; i < data.length; i++) { + data[i].forEach(datum => { + datum.__index__ = i + 1; + datum.__line_id__ = (custom_line_color_map.length > 0) ? custom_line_color_map[i] : i + 1; + }); + } + } + + function mg_nest_data_for_voronoi({data}) { + return d3.merge(data); + } + + function mg_line_class_string(args) { + return d => { + let class_string; + + if (args.linked) { + const v = d[args.x_accessor]; + const formatter = MG.time_format(args.utc_time, args.linked_format); + + // only format when x-axis is date + const id = (typeof v === 'number') ? (d.__line_id__ - 1) : formatter(v); + class_string = `roll_${id} mg-line${d.__line_id__}`; + + if (args.color === null) { + class_string += ` mg-line${d.__line_id__}-color`; + } + return class_string; + + } else { + class_string = `mg-line${d.__line_id__}`; + if (args.color === null) class_string += ` mg-line${d.__line_id__}-color`; + return class_string; + } + }; + } + + function mg_add_voronoi_rollover(args, svg, rollover_on, rollover_off, rollover_move, rollover_click) { + const voronoi = d3.voronoi() + .x(d => args.scales.X(d[args.x_accessor]).toFixed(2)) + .y(d => args.scales.Y(d[args.y_accessor]).toFixed(2)) + .extent([ + [args.buffer, args.buffer + (args.title ? args.title_y_position : 0)], + [args.width - args.buffer, args.height - args.buffer] + ]); + + const g = mg_add_g(svg, 'mg-voronoi'); + g.selectAll('path') + .data(voronoi.polygons(mg_nest_data_for_voronoi(args))) + .enter() + .append('path') + .filter(d => d !== undefined && d.length > 0) + .attr('d', d => d == null ? null : `M${d.join('L')}Z`) + .datum(d => d == null ? null : d.data) // because of d3.voronoi, reassign d + .attr('class', mg_line_class_string(args)) + .on('click', rollover_click) + .on('mouseover', rollover_on) + .on('mouseout', rollover_off) + .on('mousemove', rollover_move); + + mg_configure_voronoi_rollover(args, svg); + } + + function nest_data_for_aggregate_rollover({x_accessor, data, x_sort}) { + const data_nested = d3.nest() + .key(d => d[x_accessor]) + .entries(d3.merge(data)); + data_nested.forEach(entry => { + const datum = entry.values[0]; + entry.key = datum[x_accessor]; + }); + + if (x_sort) { + return data_nested.sort((a, b) => new Date(a.key) - new Date(b.key)); + } else { + return data_nested; + } + } + + function mg_add_aggregate_rollover(args, svg, rollover_on, rollover_off, rollover_move, rollover_click) { + // Undo the keys getting coerced to strings, by setting the keys from the values + // This is necessary for when we have X axis keys that are things like + const data_nested = nest_data_for_aggregate_rollover(args); + + const xf = data_nested.map(({key}) => args.scales.X(key)); + + const g = svg.append('g') + .attr('class', 'mg-rollover-rect'); + + g.selectAll('.mg-rollover-rects') + .data(data_nested).enter() + .append('rect') + .attr('x', (d, i) => { + if (xf.length === 1) return mg_get_plot_left(args); + else if (i === 0) return xf[i].toFixed(2); + else return ((xf[i - 1] + xf[i]) / 2).toFixed(2); + }) + .attr('y', args.top) + .attr('width', (d, i) => { + if (xf.length === 1) return mg_get_plot_right(args); + else if (i === 0) return ((xf[i + 1] - xf[i]) / 2).toFixed(2); + else if (i === xf.length - 1) return ((xf[i] - xf[i - 1]) / 2).toFixed(2); + else return ((xf[i + 1] - xf[i - 1]) / 2).toFixed(2); + }) + .attr('class', ({values}) => { + let line_classes = values.map(({__line_id__}) => { + let lc = mg_line_class(__line_id__); + if (args.colors === null) lc += ` ${mg_line_color_class(__line_id__)}`; + return lc; + }).join(' '); + if (args.linked && values.length > 0) { + line_classes += ` ${mg_rollover_id_class(mg_rollover_format_id(values[0], args))}`; + } + + return line_classes; + }) + .attr('height', args.height - args.bottom - args.top - args.buffer) + .attr('opacity', 0) + .on('click', rollover_click) + .on('mouseover', rollover_on) + .on('mouseout', rollover_off) + .on('mousemove', rollover_move); + + mg_configure_aggregate_rollover(args, svg); + } + + function mg_configure_singleton_rollover({data}, svg) { + svg.select('.mg-rollover-rect rect') + .on('mouseover')(data[0][0], 0); + } + + function mg_configure_voronoi_rollover({data, custom_line_color_map}, svg) { + for (let i = 0; i < data.length; i++) { + let j = i + 1; + + if (custom_line_color_map.length > 0 && + custom_line_color_map[i] !== undefined) { + j = custom_line_color_map[i]; + } + + if (data[i].length === 1 && !svg.selectAll(`.mg-voronoi .mg-line${j}`).empty()) { + svg.selectAll(`.mg-voronoi .mg-line${j}`) + .on('mouseover')(data[i][0], 0); + + svg.selectAll(`.mg-voronoi .mg-line${j}`) + .on('mouseout')(data[i][0], 0); + } + } + } + + function mg_line_class(line_id) { + return `mg-line${line_id}`; + } + + function mg_line_color_class(line_id) { + return `mg-line${line_id}-color`; + } + + function mg_rollover_id_class(id) { + return `roll_${id}`; + } + + function mg_rollover_format_id(d, {x_accessor, utc_time, linked_format}) { + const v = d[x_accessor]; + const formatter = MG.time_format(utc_time, linked_format); + // only format when x-axis is date + return (typeof v === 'number') ? v.toString().replace('.', '_') : formatter(v); + } + + function mg_add_single_line_rollover(args, svg, rollover_on, rollover_off, rollover_move, rollover_click) { + // set to 1 unless we have a custom increment series + let line_id = 1; + if (args.custom_line_color_map.length > 0) { + line_id = args.custom_line_color_map[0]; + } + + const g = svg.append('g') + .attr('class', 'mg-rollover-rect'); + + const xf = args.data[0].map(args.scalefns.xf); + + g.selectAll('.mg-rollover-rects') + .data(args.data[0]).enter() + .append('rect') + .attr('class', (d, i) => { + let cl = `${mg_line_color_class(line_id)} ${mg_line_class(d.__line_id__)}`; + if (args.linked) cl += `${cl} ${mg_rollover_id_class(mg_rollover_format_id(d, args))}`; + return cl; + }) + .attr('x', (d, i) => { + // if data set is of length 1 + if (xf.length === 1) return mg_get_plot_left(args); + else if (i === 0) return xf[i].toFixed(2); + else return ((xf[i - 1] + xf[i]) / 2).toFixed(2); + }) + .attr('y', (d, i) => (args.data.length > 1) ? args.scalefns.yf(d) - 6 // multi-line chart sensitivity + : args.top) + .attr('width', (d, i) => { + // if data set is of length 1 + if (xf.length === 1) return mg_get_plot_right(args); + else if (i === 0) return ((xf[i + 1] - xf[i]) / 2).toFixed(2); + else if (i === xf.length - 1) return ((xf[i] - xf[i - 1]) / 2).toFixed(2); + else return ((xf[i + 1] - xf[i - 1]) / 2).toFixed(2); + }) + .attr('height', (d, i) => (args.data.length > 1) ? 12 // multi-line chart sensitivity + : args.height - args.bottom - args.top - args.buffer) + .attr('opacity', 0) + .on('click', rollover_click) + .on('mouseover', rollover_on) + .on('mouseout', rollover_off) + .on('mousemove', rollover_move); + + if (mg_is_singleton(args)) { + mg_configure_singleton_rollover(args, svg); + } + } + + function mg_configure_aggregate_rollover({data}, svg) { + const rect = svg.selectAll('.mg-rollover-rect rect'); + const rect_first = rect.nodes()[0][0] || rect.nodes()[0]; + if (data.filter(({length}) => length === 1).length > 0) { + rect.on('mouseover')(rect_first.__data__, 0); + } + } + + function mg_is_standard_multiline({data, aggregate_rollover}) { + return data.length > 1 && !aggregate_rollover; + } + + function mg_is_aggregated_rollover({data, aggregate_rollover}) { + return data.length > 1 && aggregate_rollover; + } + + function mg_is_singleton({data}) { + return data.length === 1 && data[0].length === 1; + } + + function mg_draw_all_line_elements(args, plot, svg) { + mg_remove_dangling_bands(plot, svg); + + // If option activated, remove existing active points if exists + if (args.active_point_on_lines) { + svg.selectAll('circle.mg-shown-active-point').remove(); + } + + for (let i = args.data.length - 1; i >= 0; i--) { + const this_data = args.data[i]; + + // passing the data for the current line + MG.call_hook('line.before_each_series', [this_data, args]); + + // override increment if we have a custom increment series + let line_id = i + 1; + if (args.custom_line_color_map.length > 0) { + line_id = args.custom_line_color_map[i]; + } + + args.data[i].__line_id__ = line_id; + + // If option activated, add active points for each lines + if (args.active_point_on_lines) { + svg.selectAll('circle-' + line_id) + .data(args.data[i]) + .enter() + .filter((d) => { + return d[args.active_point_accessor]; + }) + .append('circle') + .attr('class', 'mg-area' + (line_id) + '-color mg-shown-active-point') + .attr('cx', args.scalefns.xf) + .attr('cy', args.scalefns.yf) + .attr('r', () => { + return args.active_point_size; + }); + } + + const existing_line = svg.select(`path.mg-main-line.mg-line${line_id}`); + if (this_data.length === 0) { + existing_line.remove(); + continue; + } + + mg_add_confidence_band(args, plot, svg, line_id); + + if (Array.isArray(args.area)) { + if (args.area[line_id - 1]) { + mg_add_area(args, plot, svg, i, line_id); + } + } else { + mg_add_area(args, plot, svg, i, line_id); + } + + mg_add_line(args, plot, svg, existing_line, i, line_id); + mg_add_legend_element(args, plot, i, line_id); + + // passing the data for the current line + MG.call_hook('line.after_each_series', [this_data, existing_line, args]); + } + } + + function mg_remove_dangling_bands({existing_band}, svg) { + if (existing_band[0] && existing_band[0].length > svg.selectAll('.mg-main-line').node().length) { + svg.selectAll('.mg-confidence-band').remove(); + } + } + + function mg_line_main_plot(args) { + const plot = {}; + const svg = mg_get_svg_child_of(args.target); + + // remove any old legends if they exist + mg_selectAll_and_remove(svg, '.mg-line-legend'); + mg_add_legend_group(args, plot, svg); + + plot.data_median = 0; + plot.update_transition_duration = (args.transition_on_update) ? 1000 : 0; + plot.display_area = (args.area && !args.use_data_y_min && args.data.length <= 1 && args.aggregate_rollover === false) || (Array.isArray(args.area) && args.area.length > 0); + plot.legend_text = ''; + mg_line_graph_generators(args, plot, svg); + plot.existing_band = svg.selectAll('.mg-confidence-band').nodes(); + + // should we continue with the default line render? A `line.all_series` hook should return false to prevent the default. + const continueWithDefault = MG.call_hook('line.before_all_series', [args]); + if (continueWithDefault !== false) { + mg_draw_all_line_elements(args, plot, svg); + } + + mg_plot_legend_if_legend_target(args.legend_target, plot.legend_text); + } + + function mg_line_rollover_setup(args, graph) { + const svg = mg_get_svg_child_of(args.target); + + if (args.showActivePoint && svg.selectAll('.mg-active-datapoint-container').nodes().length === 0) { + mg_add_g(svg, 'mg-active-datapoint-container'); + } + + mg_remove_existing_line_rollover_elements(svg); + mg_add_rollover_circle(args, svg); + mg_set_unique_line_id_for_each_series(args); + + if (mg_is_standard_multiline(args)) { + mg_add_voronoi_rollover(args, svg, graph.rolloverOn(args), graph.rolloverOff(args), graph.rolloverMove(args), graph.rolloverClick(args)); + } else if (mg_is_aggregated_rollover(args)) { + mg_add_aggregate_rollover(args, svg, graph.rolloverOn(args), graph.rolloverOff(args), graph.rolloverMove(args), graph.rolloverClick(args)); + } else { + mg_add_single_line_rollover(args, svg, graph.rolloverOn(args), graph.rolloverOff(args), graph.rolloverMove(args), graph.rolloverClick(args)); + } + } + + function mg_update_rollover_circle(args, svg, d) { + if (args.aggregate_rollover && args.data.length > 1) { + // hide the circles in case a non-contiguous series is present + svg.selectAll('circle.mg-line-rollover-circle') + .style('opacity', 0); + + d.values.forEach((datum, index, list) => { + if (args.missing_is_hidden && list[index]['_missing']) { + return; + } + + if (mg_data_in_plot_bounds(datum, args)) mg_update_aggregate_rollover_circle(args, svg, datum); + }); + } else if ((args.missing_is_hidden && d['_missing']) || d[args.y_accessor] === null) { + // disable rollovers for hidden parts of the line + // recall that hidden parts are missing data ranges and possibly also + // data points that have been explicitly identified as missing + return; + } else { + // show circle on mouse-overed rect + if (mg_data_in_plot_bounds(d, args)) { + mg_update_generic_rollover_circle(args, svg, d); + } + } + } + + function mg_update_aggregate_rollover_circle({scales, x_accessor, y_accessor, point_size}, svg, datum) { + svg.select(`circle.mg-line-rollover-circle.mg-line${datum.__line_id__}`) + .attr('cx', scales.X(datum[x_accessor]).toFixed(2)) + .attr('cy', scales.Y(datum[y_accessor]).toFixed(2)) + .attr('r', point_size) + .style('opacity', 1); + } + + function mg_update_generic_rollover_circle({scales, x_accessor, y_accessor, point_size}, svg, d) { + svg.selectAll(`circle.mg-line-rollover-circle.mg-line${d.__line_id__}`) + .classed('mg-line-rollover-circle', true) + .attr('cx', () => scales.X(d[x_accessor]).toFixed(2)) + .attr('cy', () => scales.Y(d[y_accessor]).toFixed(2)) + .attr('r', point_size) + .style('opacity', 1); + } + + function mg_trigger_linked_mouseovers(args, d, i) { + if (args.linked && !MG.globals.link) { + MG.globals.link = true; + if (!args.aggregate_rollover || d[args.y_accessor] !== undefined || (d.values && d.values.length > 0)) { + const datum = d.values ? d.values[0] : d; + const id = mg_rollover_format_id(datum, args); + // trigger mouseover on matching line in .linked charts + d3.selectAll(`.${mg_line_class(datum.__line_id__)}.${mg_rollover_id_class(id)}`) + .each(function(d) { + d3.select(this) + .on('mouseover')(d, i); + }); + } + } + } + + function mg_trigger_linked_mouseouts({linked, utc_time, linked_format, x_accessor}, d, i) { + if (linked && MG.globals.link) { + MG.globals.link = false; + + const formatter = MG.time_format(utc_time, linked_format); + const datums = d.values ? d.values : [d]; + datums.forEach(datum => { + const v = datum[x_accessor]; + const id = (typeof v === 'number') ? i : formatter(v); + + // trigger mouseout on matching line in .linked charts + d3.selectAll(`.roll_${id}`) + .each(function(d) { + d3.select(this) + .on('mouseout')(d); + }); + }); + } + } + + function mg_remove_active_data_points_for_aggregate_rollover(args, svg) { + svg.selectAll('circle.mg-line-rollover-circle').filter(({length}) => length > 1) + .style('opacity', 0); + } + + function mg_remove_active_data_points_for_generic_rollover({custom_line_color_map, data}, svg, line_id) { + svg.selectAll(`circle.mg-line-rollover-circle.mg-line${line_id}`) + .style('opacity', () => { + let id = line_id - 1; + if (custom_line_color_map.length > 0 && + custom_line_color_map.indexOf(line_id) !== undefined + ) { + id = custom_line_color_map.indexOf(line_id); + } + + if (data[id].length === 1) { + return 1; + } else { + return 0; + } + }); + } + + function mg_remove_active_text(svg) { + svg.select('.mg-active-datapoint').text(''); + } + + function lineChart(args) { + this.init = function(args) { + this.args = args; + + if (!args.data || args.data.length === 0) { + args.internal_error = 'No data was supplied'; + internal_error(args); + return this; + } else { + args.internal_error = undefined; + } + + raw_data_transformation(args); + process_line(args); + + MG.call_hook('line.before_destroy', this); + + init(args); + + // TODO incorporate markers into calculation of x scales + new MG.scale_factory(args) + .namespace('x') + .numericalDomainFromData() + .numericalRange('bottom'); + + const baselines = (args.baselines || []).map(d => d[args.y_accessor]); + + new MG.scale_factory(args) + .namespace('y') + .zeroBottom(true) + .inflateDomain(true) + .numericalDomainFromData(baselines) + .numericalRange('left'); + + if (args.x_axis) { + new MG.axis_factory(args) + .namespace('x') + .type('numerical') + .position(args.x_axis_position) + .rug(x_rug(args)) + .label(mg_add_x_label) + .draw(); + } + + if (args.y_axis) { + new MG.axis_factory(args) + .namespace('y') + .type('numerical') + .position(args.y_axis_position) + .rug(y_rug(args)) + .label(mg_add_y_label) + .draw(); + } + + this.markers(); + this.mainPlot(); + this.rollover(); + this.windowListeners(); + if (args.brush) MG.add_brush_function(args); + MG.call_hook('line.after_init', this); + + return this; + }; + + this.mainPlot = function() { + mg_line_main_plot(args); + return this; + }; + + this.markers = function() { + markers(args); + return this; + }; + + this.rollover = function() { + mg_line_rollover_setup(args, this); + MG.call_hook('line.after_rollover', args); + + return this; + }; + + this.rolloverClick = args => (d, i) => { + if (args.click) { + args.click(d, i); + } + }; + + this.rolloverOn = args => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + mg_update_rollover_circle(args, svg, d); + mg_trigger_linked_mouseovers(args, d, i); + + svg.selectAll('text') + .filter((g, j) => d === g) + .attr('opacity', 0.3); + + // update rollover text except for missing data points + if (args.show_rollover_text && + !((args.missing_is_hidden && d['_missing']) || d[args.y_accessor] === null) + ) { + const mouseover = mg_mouseover_text(args, { svg }); + let row = mouseover.mouseover_row(); + if (args.aggregate_rollover) { + row.text((args.aggregate_rollover && args.data.length > 1 + ? mg_format_x_aggregate_mouseover + : mg_format_x_mouseover)(args, d)); + } + + const pts = args.aggregate_rollover && args.data.length > 1 + ? d.values + : [d]; + + pts.forEach(di => { + if (args.aggregate_rollover) { + row = mouseover.mouseover_row(); + } + + if (args.legend) { + mg_line_color_text(row.text(`${args.legend[di.__index__ - 1]} `).bold(), di.__line_id__, args); + } + + mg_line_color_text(row.text('\u2014 ').elem, di.__line_id__, args); + if (!args.aggregate_rollover) { + row.text(mg_format_x_mouseover(args, di)); + } + + row.text(mg_format_y_mouseover(args, di, args.time_series === false)); + }); + } + + if (args.mouseover) { + args.mouseover(d, i); + } + }; + }; + + this.rolloverOff = args => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + mg_trigger_linked_mouseouts(args, d, i); + if (args.aggregate_rollover) { + mg_remove_active_data_points_for_aggregate_rollover(args, svg); + } else { + mg_remove_active_data_points_for_generic_rollover(args, svg, d.__line_id__); + } + + if (args.data[0].length > 1) { + mg_clear_mouseover_container(svg); + } + + if (args.mouseout) { + args.mouseout(d, i); + } + }; + }; + + this.rolloverMove = args => (d, i) => { + if (args.mousemove) { + args.mousemove(d, i); + } + }; + + this.windowListeners = function() { + mg_window_listeners(this.args); + return this; + }; + + this.init(args); + } + + MG.register('line', lineChart); +} diff --git a/priv/static/js/metricsgraphics/charts/missing.js b/priv/static/js/metricsgraphics/charts/missing.js new file mode 100644 index 0000000..330d5c0 --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/missing.js @@ -0,0 +1,144 @@ +{ + function mg_missing_add_text(svg, {missing_text, width, height}) { + svg.selectAll('.mg-missing-text').data([missing_text]) + .enter().append('text') + .attr('class', 'mg-missing-text') + .attr('x', width / 2) + .attr('y', height / 2) + .attr('dy', '.50em') + .attr('text-anchor', 'middle') + .text(missing_text); + } + + function mg_missing_x_scale(args) { + args.scales.X = d3.scaleLinear() + .domain([0, args.data.length]) + .range([mg_get_plot_left(args), mg_get_plot_right(args)]); + args.scalefns.yf = ({y}) => args.scales.Y(y); + } + + function mg_missing_y_scale(args) { + args.scales.Y = d3.scaleLinear() + .domain([-2, 2]) + .range([args.height - args.bottom - args.buffer * 2, args.top]); + args.scalefns.xf = ({x}) => args.scales.X(x); + } + + function mg_make_fake_data(args) { + const data = []; + for (let x = 1; x <= 50; x++) { + data.push({ x, y: Math.random() - (x * 0.03) }); + } + args.data = data; + } + + function mg_add_missing_background_rect(g, {title, buffer, title_y_position, width, height}) { + g.append('svg:rect') + .classed('mg-missing-background', true) + .attr('x', buffer) + .attr('y', buffer + (title ? title_y_position : 0) * 2) + .attr('width', width - buffer * 2) + .attr('height', height - buffer * 2 - (title ? title_y_position : 0) * 2) + .attr('rx', 15) + .attr('ry', 15); + } + + function mg_missing_add_line(g, {scalefns, interpolate, data}) { + const line = d3.line() + .x(scalefns.xf) + .y(scalefns.yf) + .curve(interpolate); + + g.append('path') + .attr('class', 'mg-main-line mg-line1-color') + .attr('d', line(data)); + } + + function mg_missing_add_area(g, {scalefns, scales, interpolate, data}) { + const area = d3.area() + .x(scalefns.xf) + .y0(scales.Y.range()[0]) + .y1(scalefns.yf) + .curve(interpolate); + + g.append('path') + .attr('class', 'mg-main-area mg-area1-color') + .attr('d', area(data)); + } + + function mg_remove_all_children({target}) { + d3.select(target).selectAll('svg *').remove(); + } + + function mg_missing_remove_legend({legend_target}) { + if (legend_target) { + d3.select(legend_target).html(''); + } + } + + function missingData(args) { + this.init = (args) => { + this.args = args; + + mg_init_compute_width(args); + mg_init_compute_height(args); + + // create svg if one doesn't exist + + const container = d3.select(args.target); + mg_raise_container_error(container, args); + let svg = container.selectAll('svg'); + mg_remove_svg_if_chart_type_has_changed(svg, args); + svg = mg_add_svg_if_it_doesnt_exist(svg, args); + mg_adjust_width_and_height_if_changed(svg, args); + mg_set_viewbox_for_scaling(svg, args); + mg_remove_all_children(args); + + svg.classed('mg-missing', true); + mg_missing_remove_legend(args); + + chart_title(args); + + // are we adding a background placeholder + if (args.show_missing_background) { + mg_make_fake_data(args); + mg_missing_x_scale(args); + mg_missing_y_scale(args); + const g = mg_add_g(svg, 'mg-missing-pane'); + + mg_add_missing_background_rect(g, args); + mg_missing_add_line(g, args); + mg_missing_add_area(g, args); + } + + mg_missing_add_text(svg, args); + + this.windowListeners(); + + return this; + }; + + this.windowListeners = () => { + mg_window_listeners(this.args); + return this; + }; + + this.init(args); + } + + const defaults = { + top: [40, 'number'], // the size of the top margin + bottom: [30, 'number'], // the size of the bottom margin + right: [10, 'number'], // size of the right margin + left: [0, 'number'], // size of the left margin + buffer: [8, 'number'], // the buffer between the actual chart area and the margins + legend_target: ['', 'string'], + width: [350, 'number'], + height: [220, 'number'], + missing_text: ['Data currently missing or unavailable', 'string'], + show_tooltips: [true, 'boolean'], + show_missing_background: [true, 'boolean'] + }; + + MG.register('missing-data', missingData, defaults); +} diff --git a/priv/static/js/metricsgraphics/charts/point.js b/priv/static/js/metricsgraphics/charts/point.js new file mode 100644 index 0000000..b511f19 --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/point.js @@ -0,0 +1,383 @@ +function point_mouseover(args, svg, d) { + const mouseover = mg_mouseover_text(args, { svg }); + const row = mouseover.mouseover_row(); + + if (args.color_accessor !== null && args.color_type === 'category') { + const label = d[args.color_accessor]; + row.text(`${label} `).bold().attr('fill', args.scalefns.colorf(d)); + } + + mg_color_point_mouseover(args, row.text('\u25CF ').elem, d); // point shape + + row.text(mg_format_x_mouseover(args, d)); // x + row.text(mg_format_y_mouseover(args, d, args.time_series === false)); +} + +function mg_color_point_mouseover({color_accessor, scalefns}, elem, d) { + if (color_accessor !== null) { + elem.attr('fill', scalefns.colorf(d)); + elem.attr('stroke', scalefns.colorf(d)); + } else { + elem.classed('mg-points-mono', true); + } +} + + +{ + function mg_filter_out_plot_bounds(data, args) { + // max_x, min_x, max_y, min_y; + const x = args.x_accessor; + const y = args.y_accessor; + const new_data = data.filter(d => (args.min_x === null || d[x] >= args.min_x) && + (args.max_x === null || d[x] <= args.max_x) && + (args.min_y === null || d[y] >= args.min_y) && + (args.max_y === null || d[y] <= args.max_y)); + return new_data; + } + + function pointChart(args) { + this.init = function(args) { + this.args = args; + + // infer y_axis and x_axis type; + args.x_axis_type = mg_infer_type(args, 'x'); + args.y_axis_type = mg_infer_type(args, 'y'); + + raw_data_transformation(args); + + process_point(args); + init(args); + + let xMaker, yMaker; + + if (args.x_axis_type === 'categorical') { + xMaker = MG.scale_factory(args) + .namespace('x') + .categoricalDomainFromData() + .categoricalRangeBands([0, args.xgroup_height], args.xgroup_accessor === null); + + if (args.xgroup_accessor) { + new MG.scale_factory(args) + .namespace('xgroup') + .categoricalDomainFromData() + .categoricalRangeBands('bottom'); + + } else { + args.scales.XGROUP = () => mg_get_plot_left(args); + args.scalefns.xgroupf = () => mg_get_plot_left(args); + } + + args.scalefns.xoutf = d => args.scalefns.xf(d) + args.scalefns.xgroupf(d); + } else { + xMaker = MG.scale_factory(args) + .namespace('x') + .inflateDomain(true) + .zeroBottom(args.y_axis_type === 'categorical') + .numericalDomainFromData((args.baselines || []).map(d => d[args.x_accessor])) + .numericalRange('bottom'); + + args.scalefns.xoutf = args.scalefns.xf; + } + + // y-scale generation. This needs to get simplified. + if (args.y_axis_type === 'categorical') { + yMaker = MG.scale_factory(args) + .namespace('y') + .zeroBottom(true) + .categoricalDomainFromData() + .categoricalRangeBands([0, args.ygroup_height], true); + + if (args.ygroup_accessor) { + + new MG.scale_factory(args) + .namespace('ygroup') + .categoricalDomainFromData() + .categoricalRangeBands('left'); + + } else { + args.scales.YGROUP = () => mg_get_plot_top(args); + args.scalefns.ygroupf = () => mg_get_plot_top(args); + + } + args.scalefns.youtf = d => args.scalefns.yf(d) + args.scalefns.ygroupf(d); + + } else { + const baselines = (args.baselines || []).map(d => d[args.y_accessor]); + yMaker = MG.scale_factory(args) + .namespace('y') + .inflateDomain(true) + .zeroBottom(args.x_axis_type === 'categorical') + .numericalDomainFromData(baselines) + .numericalRange('left'); + + args.scalefns.youtf = d => args.scalefns.yf(d); + } + + /////// COLOR accessor + if (args.color_accessor !== null) { + const colorScale = MG.scale_factory(args).namespace('color'); + if (args.color_type === 'number') { + // do the color scale. + // etiher get color range, or what. + colorScale + .numericalDomainFromData(mg_get_color_domain(args)) + .numericalRange(mg_get_color_range(args)) + .clamp(true); + } else { + if (args.color_domain) { + colorScale + .categoricalDomain(args.color_domain) + .categoricalRange(args.color_range); + } else { + colorScale + .categoricalDomainFromData() + .categoricalColorRange(); + } + } + } + + if (args.size_accessor) { + new MG.scale_factory(args).namespace('size') + .numericalDomainFromData() + .numericalRange(mg_get_size_range(args)) + .clamp(true); + } + + new MG.axis_factory(args) + .namespace('x') + .type(args.x_axis_type) + .zeroLine(args.y_axis_type === 'categorical') + .position(args.x_axis_position) + .rug(x_rug(args)) + .label(mg_add_x_label) + .draw(); + + new MG.axis_factory(args) + .namespace('y') + .type(args.y_axis_type) + .zeroLine(args.x_axis_type === 'categorical') + .position(args.y_axis_position) + .rug(y_rug(args)) + .label(mg_add_y_label) + .draw(); + + this.mainPlot(); + this.markers(); + this.rollover(); + this.windowListeners(); + if (args.brush) MG.add_brush_function(args); + return this; + }; + + this.markers = function() { + markers(args); + if (args.least_squares) { + add_ls(args); + } + + return this; + }; + + this.mainPlot = function() { + const svg = mg_get_svg_child_of(args.target); + + const data = mg_filter_out_plot_bounds(args.data[0], args); + //remove the old points, add new one + svg.selectAll('.mg-points').remove(); + + const g = svg.append('g') + .classed('mg-points', true); + + const pts = g.selectAll('circle') + .data(data) + .enter().append('circle') + .attr('class', (d, i) => `path-${i}`) + .attr('cx', args.scalefns.xoutf) + .attr('cy', d => args.scalefns.youtf(d)); + + let highlights; + svg.selectAll('.mg-highlight').remove(); + if (args.highlight && mg_is_function(args.highlight)) { + highlights = svg.append('g') + .classed('mg-highlight', true) + .selectAll('circle') + .data(data.filter(args.highlight)) + .enter().append('circle') + .attr('cx', args.scalefns.xoutf) + .attr('cy', d => args.scalefns.youtf(d)); + } + + const elements = [pts].concat(highlights ? [highlights] : []); + //are we coloring our points, or just using the default color? + if (args.color_accessor !== null) { + elements.forEach(e => e.attr('fill', args.scalefns.colorf).attr('stroke', args.scalefns.colorf)); + } else { + elements.forEach(e => e.classed('mg-points-mono', true)); + } + + pts.attr('r', (args.size_accessor !== null) ? args.scalefns.sizef : args.point_size); + if (highlights) { + highlights.attr('r', (args.size_accessor !== null) ? (d, i) => args.scalefns.sizef(d, i) + 2 : args.point_size + 2); + } + + return this; + }; + + this.rollover = function() { + const svg = mg_get_svg_child_of(args.target); + + if (svg.selectAll('.mg-active-datapoint-container').nodes().length === 0) { + mg_add_g(svg, 'mg-active-datapoint-container'); + } + + //remove the old rollovers if they already exist + svg.selectAll('.mg-voronoi').remove(); + + //add rollover paths + const voronoi = d3.voronoi() + .x(args.scalefns.xoutf) + .y(args.scalefns.youtf) + .extent([ + [args.buffer, args.buffer + (args.title ? args.title_y_position : 0)], + [args.width - args.buffer, args.height - args.buffer] + ]); + + const paths = svg.append('g') + .attr('class', 'mg-voronoi'); + + paths.selectAll('path') + .data(voronoi.polygons(mg_filter_out_plot_bounds(args.data[0], args))) + .enter().append('path') + .attr('d', d => d == null ? null : `M${d.join(',')}Z`) + .attr('class', (d, i) => `path-${i}`) + .style('fill-opacity', 0) + .on('click', this.rolloverClick(args)) + .on('mouseover', this.rolloverOn(args)) + .on('mouseout', this.rolloverOff(args)) + .on('mousemove', this.rolloverMove(args)); + + if (args.data[0].length === 1) { + point_mouseover(args, svg, args.data[0][0]); + } + + return this; + }; + + this.rolloverClick = args => { + return (d, i) => { + if (args.click) { + args.click(d, i); + } + }; + }; + + this.rolloverOn = args => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + svg.selectAll('.mg-points circle') + .classed('selected', false); + + //highlight active point + const pts = svg.selectAll(`.mg-points circle.path-${i}`) + .classed('selected', true); + + if (args.size_accessor) { + pts.attr('r', di => args.scalefns.sizef(di) + args.active_point_size_increase); + } else { + pts.attr('r', args.point_size + args.active_point_size_increase); + } + + //trigger mouseover on all points for this class name in .linked charts + if (args.linked && !MG.globals.link) { + MG.globals.link = true; + + //trigger mouseover on matching point in .linked charts + d3.selectAll(`.mg-voronoi .path-${i}`) + .each(() => { + d3.select(this).on('mouseover')(d, i); + }); + } + + if (args.show_rollover_text) { + point_mouseover(args, svg, d.data); + } + + if (args.mouseover) { + args.mouseover(d, i); + } + }; + }; + + this.rolloverOff = args => { + const svg = mg_get_svg_child_of(args.target); + + return (d, i) => { + if (args.linked && MG.globals.link) { + MG.globals.link = false; + + d3.selectAll(`.mg-voronoi .path-${i}`) + .each(() => { + d3.select(this).on('mouseout')(d, i); + }); + } + + //reset active point + const pts = svg.selectAll('.mg-points circle') + .classed('unselected', false) + .classed('selected', false); + + if (args.size_accessor) { + pts.attr('r', args.scalefns.sizef); + } else { + pts.attr('r', args.point_size); + } + + //reset active data point text + if (args.data[0].length > 1) mg_clear_mouseover_container(svg); + + if (args.mouseout) { + args.mouseout(d, i); + } + }; + }; + + this.rolloverMove = args => (d, i) => { + if (args.mousemove) { + args.mousemove(d, i); + } + }; + + this.update = function(args) { + return this; + }; + + this.windowListeners = function() { + mg_window_listeners(this.args); + return this; + }; + + this.init(args); + } + + const options = { + color_accessor: [null, 'string'], // the data element to use to map points to colors + color_range: [null, 'array'], // the range used to color different groups of points + color_type: ['number', ['number', 'category']], // specifies whether the color scale is quantitative or qualitative + point_size: [2.5, 'number'], // the radius of the dots in the scatterplot + size_accessor: [null, 'string'], // should point sizes be mapped to data + size_range: [null, 'array'], // the range of point sizes + lowess: [false, 'boolean'], // specifies whether to show a lowess line of best-fit + least_squares: [false, 'boolean'], // specifies whether to show a least-squares line of best-fit + y_categorical_show_guides: [true, 'boolean'], + x_categorical_show_guides: [true, 'boolean'], + buffer: [16, 'string'], + label_accessor: [null, 'boolean'], + size_domain: [null, 'array'], + color_domain: [null, 'array'], + active_point_size_increase: [1, 'number'], + highlight: [null, 'function'] // if this callback function returns true, the selected point will be highlighted + }; + + MG.register('point', pointChart, options); +} diff --git a/priv/static/js/metricsgraphics/charts/table.js b/priv/static/js/metricsgraphics/charts/table.js new file mode 100644 index 0000000..3081d8c --- /dev/null +++ b/priv/static/js/metricsgraphics/charts/table.js @@ -0,0 +1,220 @@ +/* +Data Tables + +Along with histograms, bars, lines, and scatters, a simple data table can take you far. +We often just want to look at numbers, organized as a table, where columns are variables, +and rows are data points. Sometimes we want a cell to have a small graphic as the main +column element, in which case we want small multiples. sometimes we want to + +var table = New data_table(data) + .target('div#data-table') + .title({accessor: 'point_name', align: 'left'}) + .description({accessor: 'description'}) + .number({accessor: ''}) + +*/ + +MG.data_table = function(args) { + 'use strict'; + this.args = args; + this.args.standard_col = { width: 150, font_size: 12, font_weight: 'normal' }; + this.args.columns = []; + this.formatting_options = [ + ['color', 'color'], + ['font-weight', 'font_weight'], + ['font-style', 'font_style'], + ['font-size', 'font_size'] + ]; + + this._strip_punctuation = function(s) { + var punctuationless = s.replace(/[^a-zA-Z0-9 _]+/g, ''); + var finalString = punctuationless.replace(/ +?/g, ''); + return finalString; + }; + + this._format_element = function(element, value, args) { + this.formatting_options.forEach(function(fo) { + var attr = fo[0]; + var key = fo[1]; + if (args[key]) element.style(attr, + typeof args[key] === 'string' || + typeof args[key] === 'number' ? + args[key] : args[key](value)); + }); + }; + + this._add_column = function(_args, arg_type) { + var standard_column = this.args.standard_col; + var args = merge_with_defaults(MG.clone(_args), MG.clone(standard_column)); + args.type = arg_type; + this.args.columns.push(args); + }; + + this.target = function() { + var target = arguments[0]; + this.args.target = target; + return this; + }; + + this.title = function() { + this._add_column(arguments[0], 'title'); + return this; + }; + + this.text = function() { + this._add_column(arguments[0], 'text'); + return this; + }; + + this.bullet = function() { + /* + text label + main value + comparative measure + any number of ranges + + additional args: + no title + xmin, xmax + format: percentage + xax_formatter + */ + return this; + }; + + this.sparkline = function() { + return this; + }; + + this.number = function() { + this._add_column(arguments[0], 'number'); + return this; + }; + + this.display = function() { + var args = this.args; + + chart_title(args); + + var target = args.target; + var table = d3.select(target).append('table').classed('mg-data-table', true); + var colgroup = table.append('colgroup'); + var thead = table.append('thead'); + var tbody = table.append('tbody'); + var this_column; + var this_title; + + var tr, th, td_accessor, td_type, td_value, th_text, td_text, td; + var col; + var h; + + tr = thead.append('tr'); + + for (h = 0; h < args.columns.length; h++) { + var this_col = args.columns[h]; + td_type = this_col.type; + th_text = this_col.label; + th_text = th_text === undefined ? '' : th_text; + th = tr.append('th') + .style('width', this_col.width) + .style('text-align', td_type === 'title' ? 'left' : 'right') + .text(th_text); + + if (args.show_tooltips && this_col.description && mg_jquery_exists()) { + th.append('i') + .classed('fa', true) + .classed('fa-question-circle', true) + .classed('fa-inverse', true); + + $(th.node()).popover({ + html: true, + animation: false, + content: this_col.description, + trigger: 'hover', + placement: 'top', + container: $(th.node()) + }); + } + } + + for (h = 0; h < args.columns.length; h++) { + col = colgroup.append('col'); + if (args.columns[h].type === 'number') { + col.attr('align', 'char').attr('char', '.'); + } + } + + for (var i = 0; i < args.data.length; i++) { + tr = tbody.append('tr'); + for (var j = 0; j < args.columns.length; j++) { + this_column = args.columns[j]; + td_accessor = this_column.accessor; + td_value = td_text = args.data[i][td_accessor]; + td_type = this_column.type; + + if (td_type === 'number') { + //td_text may need to be rounded + if (this_column.hasOwnProperty('round') && !this_column.hasOwnProperty('format')) { + // round according to the number value in this_column.round + td_text = d3.format('0,.' + this_column.round + 'f')(td_text); + } + + if (this_column.hasOwnProperty('value_formatter')) { + // provide a function that formats the text according to the function this_column.format. + td_text = this_column.value_formatter(td_text); + } + + if (this_column.hasOwnProperty('format')) { + // this is a shorthand for percentage formatting, and others if need be. + // supported: 'percentage', 'count', 'temperature' + + if (this_column.round) { + td_text = Math.round(td_text, this_column.round); + } + + var this_format = this_column.format; + var formatter; + + if (this_format === 'percentage') formatter = d3.format('.0%'); + if (this_format === 'count') formatter = d3.format(',.0f'); + if (this_format === 'temperature') formatter = function(t) { + return t + '°'; }; + + td_text = formatter(td_text); + } + + if (this_column.hasOwnProperty('currency')) { + // this is another shorthand for formatting according to a currency amount, which gets appended to front of number + td_text = this_column.currency + td_text; + } + } + + td = tr.append('td') + .classed('table-' + td_type, true) + .classed('table-' + td_type + '-' + this._strip_punctuation(td_accessor), true) + .attr('data-value', td_value) + .style('width', this_column.width) + .style('text-align', td_type === 'title' || td_type === 'text' ? 'left' : 'right'); + + this._format_element(td, td_value, this_column); + + if (td_type === 'title') { + this_title = td.append('div').text(td_text); + this._format_element(this_title, td_text, this_column); + + if (args.columns[j].hasOwnProperty('secondary_accessor')) { + td.append('div') + .text(args.data[i][args.columns[j].secondary_accessor]) + .classed("secondary-title", true); + } + } else { + td.text(td_text); + } + } + } + + return this; + }; + + return this; +}; diff --git a/priv/static/js/metricsgraphics/common/bootstrap_tooltip_popover.js b/priv/static/js/metricsgraphics/common/bootstrap_tooltip_popover.js new file mode 100755 index 0000000..3d1d5b7 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/bootstrap_tooltip_popover.js @@ -0,0 +1,626 @@ +if (mg_jquery_exists()) { + /* ======================================================================== + * Bootstrap: tooltip.js v3.3.5 + * http://getbootstrap.com/javascript/#tooltip + * Inspired by the original jQuery.tipsy by Jason Frame + * ======================================================================== + * Copyright 2011-2015 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + + +function ($) { + 'use strict'; + + // TOOLTIP PUBLIC CLASS DEFINITION + // =============================== + + var Tooltip = function (element, options) { + this.type = null; + this.options = null; + this.enabled = null; + this.timeout = null; + this.hoverState = null; + this.$element = null; + this.inState = null; + + this.init('tooltip', element, options); + }; + + Tooltip.VERSION = '3.3.5'; + + Tooltip.TRANSITION_DURATION = 150; + + Tooltip.DEFAULTS = { + animation: true, + placement: 'top', + selector: false, + template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', + trigger: 'hover focus', + title: '', + delay: 0, + html: false, + container: false, + viewport: { + selector: 'body', + padding: 0 + } + }; + + Tooltip.prototype.init = function (type, element, options) { + this.enabled = true; + this.type = type; + this.$element = $(element); + this.options = this.getOptions(options); + this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport)); + this.inState = { click: false, hover: false, focus: false }; + + if (this.$element[0] instanceof document.constructor && !this.options.selector) { + throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!'); + } + + var triggers = this.options.trigger.split(' '); + + for (var i = triggers.length; i--;) { + var trigger = triggers[i]; + + if (trigger == 'click') { + this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)); + } else if (trigger != 'manual') { + var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'; + var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'; + + this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)); + this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)); + } + } + + this.options.selector ? + (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : + this.fixTitle(); + }; + + Tooltip.prototype.getDefaults = function () { + return Tooltip.DEFAULTS; + }; + + Tooltip.prototype.getOptions = function (options) { + options = $.extend({}, this.getDefaults(), this.$element.data(), options); + + if (options.delay && typeof options.delay == 'number') { + options.delay = { + show: options.delay, + hide: options.delay + }; + } + + return options; + }; + + Tooltip.prototype.getDelegateOptions = function () { + var options = {}; + var defaults = this.getDefaults(); + + this._options && $.each(this._options, function (key, value) { + if (defaults[key] != value) options[key] = value; + }); + + return options; + }; + + Tooltip.prototype.enter = function (obj) { + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget).data('bs.' + this.type); + + if (!self) { + self = new this.constructor(obj.currentTarget, this.getDelegateOptions()); + $(obj.currentTarget).data('bs.' + this.type, self); + } + + if (obj instanceof $.Event) { + self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true; + } + + if (self.tip().hasClass('in') || self.hoverState == 'in') { + self.hoverState = 'in'; + return; + } + + clearTimeout(self.timeout); + + self.hoverState = 'in'; + + if (!self.options.delay || !self.options.delay.show) return self.show(); + + self.timeout = setTimeout(function () { + if (self.hoverState == 'in') self.show(); + }, self.options.delay.show); + }; + + Tooltip.prototype.isInStateTrue = function () { + for (var key in this.inState) { + if (this.inState[key]) return true; + } + + return false; + }; + + Tooltip.prototype.leave = function (obj) { + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget).data('bs.' + this.type); + + if (!self) { + self = new this.constructor(obj.currentTarget, this.getDelegateOptions()); + $(obj.currentTarget).data('bs.' + this.type, self); + } + + if (obj instanceof $.Event) { + self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false; + } + + if (self.isInStateTrue()) return; + + clearTimeout(self.timeout); + + self.hoverState = 'out'; + + if (!self.options.delay || !self.options.delay.hide) return self.hide(); + + self.timeout = setTimeout(function () { + if (self.hoverState == 'out') self.hide(); + }, self.options.delay.hide); + }; + + Tooltip.prototype.show = function () { + var e = $.Event('show.bs.' + this.type); + + if (this.hasContent() && this.enabled) { + this.$element.trigger(e); + + var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]); + if (e.isDefaultPrevented() || !inDom) return; + var that = this; + + var $tip = this.tip(); + + var tipId = this.getUID(this.type); + + this.setContent(); + $tip.attr('id', tipId); + this.$element.attr('aria-describedby', tipId); + + if (this.options.animation) $tip.addClass('fade'); + + var placement = typeof this.options.placement == 'function' ? + this.options.placement.call(this, $tip[0], this.$element[0]) : + this.options.placement; + + var autoToken = /\s?auto?\s?/i; + var autoPlace = autoToken.test(placement); + if (autoPlace) placement = placement.replace(autoToken, '') || 'top'; + + $tip + .detach() + .css({ top: 0, left: 0, display: 'block' }) + .addClass(placement) + .data('bs.' + this.type, this); + + this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element); + this.$element.trigger('inserted.bs.' + this.type); + + var pos = this.getPosition(); + var actualWidth = $tip[0].offsetWidth; + var actualHeight = $tip[0].offsetHeight; + + if (autoPlace) { + var orgPlacement = placement; + var viewportDim = this.getPosition(this.$viewport); + + placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' : + placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' : + placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' : + placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' : + placement; + + $tip + .removeClass(orgPlacement) + .addClass(placement); + } + + var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight); + + this.applyPlacement(calculatedOffset, placement); + + var complete = function () { + var prevHoverState = that.hoverState; + that.$element.trigger('shown.bs.' + that.type); + that.hoverState = null; + + if (prevHoverState == 'out') that.leave(that); + }; + + $.support.transition && this.$tip.hasClass('fade') ? + $tip + .one('bsTransitionEnd', complete) + .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : + complete(); + } + }; + + Tooltip.prototype.applyPlacement = function (offset, placement) { + var $tip = this.tip(); + var width = $tip[0].offsetWidth; + var height = $tip[0].offsetHeight; + + // manually read margins because getBoundingClientRect includes difference + var marginTop = parseInt($tip.css('margin-top'), 10); + var marginLeft = parseInt($tip.css('margin-left'), 10); + + // we must check for NaN for ie 8/9 + if (isNaN(marginTop)) marginTop = 0; + if (isNaN(marginLeft)) marginLeft = 0; + + offset.top += marginTop; + offset.left += marginLeft; + + // $.fn.offset doesn't round pixel values + // so we use setOffset directly with our own function B-0 + $.offset.setOffset($tip[0], $.extend({ + using: function (props) { + $tip.css({ + top: Math.round(props.top), + left: Math.round(props.left) + }); + } + }, offset), 0); + + $tip.addClass('in'); + + // check to see if placing tip in new offset caused the tip to resize itself + var actualWidth = $tip[0].offsetWidth; + var actualHeight = $tip[0].offsetHeight; + + if (placement == 'top' && actualHeight != height) { + offset.top = offset.top + height - actualHeight; + } + + var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight); + + if (delta.left) offset.left += delta.left; + else offset.top += delta.top; + + var isVertical = /top|bottom/.test(placement); + var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight; + var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'; + + $tip.offset(offset); + this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical); + }; + + Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) { + this.arrow() + .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%') + .css(isVertical ? 'top' : 'left', ''); + }; + + Tooltip.prototype.setContent = function () { + var $tip = this.tip(); + var title = this.getTitle(); + + $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title); + $tip.removeClass('fade in top bottom left right'); + }; + + Tooltip.prototype.hide = function (callback) { + var that = this; + var $tip = $(this.$tip); + var e = $.Event('hide.bs.' + this.type); + + function complete() { + if (that.hoverState != 'in') $tip.detach(); + that.$element + .removeAttr('aria-describedby') + .trigger('hidden.bs.' + that.type); + callback && callback(); + } + + this.$element.trigger(e); + + if (e.isDefaultPrevented()) return; + + $tip.removeClass('in'); + + $.support.transition && $tip.hasClass('fade') ? + $tip + .one('bsTransitionEnd', complete) + .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : + complete(); + + this.hoverState = null; + + return this; + }; + + Tooltip.prototype.fixTitle = function () { + var $e = this.$element; + if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') { + $e.attr('data-original-title', $e.attr('title') || '').attr('title', ''); + } + }; + + Tooltip.prototype.hasContent = function () { + return this.getTitle(); + }; + + Tooltip.prototype.getPosition = function ($element) { + $element = $element || this.$element; + + var el = $element[0]; + var isBody = el.tagName == 'BODY'; + + var elRect = el.getBoundingClientRect(); + if (elRect.width == null) { + // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093 + elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top }); + } + var elOffset = isBody ? { top: 0, left: 0 } : $element.offset(); + var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }; + var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null; + + return $.extend({}, elRect, scroll, outerDims, elOffset); + }; + + Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { + return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : + /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }; + + }; + + Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { + var delta = { top: 0, left: 0 }; + if (!this.$viewport) return delta; + + var viewportPadding = this.options.viewport && this.options.viewport.padding || 0; + var viewportDimensions = this.getPosition(this.$viewport); + + if (/right|left/.test(placement)) { + var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll; + var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight; + if (topEdgeOffset < viewportDimensions.top) { // top overflow + delta.top = viewportDimensions.top - topEdgeOffset; + } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow + delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset; + } + } else { + var leftEdgeOffset = pos.left - viewportPadding; + var rightEdgeOffset = pos.left + viewportPadding + actualWidth; + if (leftEdgeOffset < viewportDimensions.left) { // left overflow + delta.left = viewportDimensions.left - leftEdgeOffset; + } else if (rightEdgeOffset > viewportDimensions.right) { // right overflow + delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset; + } + } + + return delta; + }; + + Tooltip.prototype.getTitle = function () { + var title; + var $e = this.$element; + var o = this.options; + + title = $e.attr('data-original-title') + || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title); + + return title; + }; + + Tooltip.prototype.getUID = function (prefix) { + do prefix += ~~(Math.random() * 1000000); + while (document.getElementById(prefix)); + return prefix; + }; + + Tooltip.prototype.tip = function () { + if (!this.$tip) { + this.$tip = $(this.options.template); + if (this.$tip.length != 1) { + throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!'); + } + } + return this.$tip; + }; + + Tooltip.prototype.arrow = function () { + return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')); + }; + + Tooltip.prototype.enable = function () { + this.enabled = true; + }; + + Tooltip.prototype.disable = function () { + this.enabled = false; + }; + + Tooltip.prototype.toggleEnabled = function () { + this.enabled = !this.enabled; + }; + + Tooltip.prototype.toggle = function (e) { + var self = this; + if (e) { + self = $(e.currentTarget).data('bs.' + this.type); + if (!self) { + self = new this.constructor(e.currentTarget, this.getDelegateOptions()); + $(e.currentTarget).data('bs.' + this.type, self); + } + } + + if (e) { + self.inState.click = !self.inState.click; + if (self.isInStateTrue()) self.enter(self); + else self.leave(self); + } else { + self.tip().hasClass('in') ? self.leave(self) : self.enter(self); + } + }; + + Tooltip.prototype.destroy = function () { + var that = this; + clearTimeout(this.timeout); + this.hide(function () { + that.$element.off('.' + that.type).removeData('bs.' + that.type); + if (that.$tip) { + that.$tip.detach(); + } + that.$tip = null; + that.$arrow = null; + that.$viewport = null; + }); + }; + + + // TOOLTIP PLUGIN DEFINITION + // ========================= + + function Plugin(option) { + return this.each(function () { + var $this = $(this); + var data = $this.data('bs.tooltip'); + var options = typeof option == 'object' && option; + + if (!data && /destroy|hide/.test(option)) return; + if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))); + if (typeof option == 'string') data[option](); + }); + } + + var old = $.fn.tooltip; + + $.fn.tooltip = Plugin; + $.fn.tooltip.Constructor = Tooltip; + + + // TOOLTIP NO CONFLICT + // =================== + + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old; + return this; + }; + + }(jQuery); + + + /* ======================================================================== + * Bootstrap: popover.js v3.3.5 + * http://getbootstrap.com/javascript/#popovers + * ======================================================================== + * Copyright 2011-2015 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + + +function ($) { + 'use strict'; + + // POPOVER PUBLIC CLASS DEFINITION + // =============================== + + var Popover = function (element, options) { + this.init('popover', element, options); + }; + + if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js'); + + Popover.VERSION = '3.3.5'; + + Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, { + placement: 'right', + trigger: 'click', + content: '', + template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>' + }); + + + // NOTE: POPOVER EXTENDS tooltip.js + // ================================ + + Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype); + + Popover.prototype.constructor = Popover; + + Popover.prototype.getDefaults = function () { + return Popover.DEFAULTS; + }; + + Popover.prototype.setContent = function () { + var $tip = this.tip(); + var title = this.getTitle(); + var content = this.getContent(); + + $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title); + $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events + this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text' + ](content); + + $tip.removeClass('fade top bottom left right in'); + + // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do + // this manually by checking the contents. + if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide(); + }; + + Popover.prototype.hasContent = function () { + return this.getTitle() || this.getContent(); + }; + + Popover.prototype.getContent = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-content') + || (typeof o.content == 'function' ? + o.content.call($e[0]) : + o.content); + }; + + Popover.prototype.arrow = function () { + return (this.$arrow = this.$arrow || this.tip().find('.arrow')); + }; + + + // POPOVER PLUGIN DEFINITION + // ========================= + + function Plugin(option) { + return this.each(function () { + var $this = $(this); + var data = $this.data('bs.popover'); + var options = typeof option == 'object' && option; + + if (!data && /destroy|hide/.test(option)) return; + if (!data) $this.data('bs.popover', (data = new Popover(this, options))); + if (typeof option == 'string') data[option](); + }); + } + + var old = $.fn.popover; + + $.fn.popover = Plugin; + $.fn.popover.Constructor = Popover; + + + // POPOVER NO CONFLICT + // =================== + + $.fn.popover.noConflict = function () { + $.fn.popover = old; + return this; + }; + + }(jQuery); +} diff --git a/priv/static/js/metricsgraphics/common/brush.js b/priv/static/js/metricsgraphics/common/brush.js new file mode 100644 index 0000000..4a4deff --- /dev/null +++ b/priv/static/js/metricsgraphics/common/brush.js @@ -0,0 +1,126 @@ +{ + +const get_extent_rect = args => { + return d3.select(args.target).select('.mg-extent').size() + ? d3.select(args.target).select('.mg-extent') + : d3.select(args.target) + .select('.mg-rollover-rect, .mg-voronoi') + .insert('g', '*') + .classed('mg-brush', true) + .append('rect') + .classed('mg-extent', true); +}; + +const create_brushing_pattern = (args, range) => { + const x = range.x[0]; + const width = range.x[1] - range.x[0]; + const y = range.y[0]; + const height = range.y[1] - range.y[0]; + get_extent_rect(args) + .attr('x', x) + .attr('width', width) + .attr('y', y) + .attr('height', height) + .attr('opacity', 1); +}; + +const remove_brushing_pattern = args => { + get_extent_rect(args) + .attr('width', 0) + .attr('height', 0) + .attr('opacity', 0); +}; + +const add_event_handler_for_brush = (args, target, axis) => { + const svg = d3.select(args.target).select('svg'); + const rollover = svg.select('.mg-rollover-rect, .mg-voronoi'); + const container = rollover.node(); + const targetUid = mg_target_ref(args.target); + let isDragging = false; + let mouseDown = false; + let origin = []; + + const calculateSelectionRange = () => { + const min_x = args.left; + const max_x = args.width - args.right - args.buffer; + const min_y = args.top; + const max_y = args.height - args.bottom - args.buffer; + const mouse = d3.mouse(container); + const range = {}; + range.x = axis.x ? [ + Math.max(min_x, Math.min(origin[0], mouse[0])), + Math.min(max_x, Math.max(origin[0], mouse[0])) + ] : [min_x, max_x]; + range.y = axis.y ? [ + Math.max(min_y, Math.min(origin[1], mouse[1])), + Math.min(max_y, Math.max(origin[1], mouse[1])) + ] : [min_y, max_y]; + return range; + }; + + rollover.classed('mg-brush-container', true); + rollover.on('mousedown.' + targetUid, () => { + mouseDown = true; + isDragging = false; + origin = d3.mouse(container); + svg.classed('mg-brushed', false); + svg.classed('mg-brushing-in-progress', true); + remove_brushing_pattern(args); + }); + d3.select(document).on('mousemove.' + targetUid, () => { + if (mouseDown) { + isDragging = true; + rollover.classed('mg-brushing', true); + create_brushing_pattern(args, calculateSelectionRange()); + } + }); + d3.select(document).on('mouseup.' + targetUid, () => { + if (!mouseDown) return; + mouseDown = false; + svg.classed('mg-brushing-in-progress', false); + const range = calculateSelectionRange(); + if (isDragging) { + isDragging = false; + if (target === args) { + MG.zoom_to_data_range(target, range); + if (args.click_to_zoom_out) + svg.select('.mg-rollover-rect, .mg-voronoi').classed('mg-brushed', true); + } else { + const domain = MG.convert_range_to_domain(args, range); + MG.zoom_to_data_domain(target, domain); + } + } else if (args.click_to_zoom_out) { + MG.zoom_to_raw_range(target); + } + if (mg_is_function(args.brushing_selection_changed)) + args.brushing_selection_changed(args, range); + }); +}; + +const add_brush_function = args => { + if (args.x_axis_type === 'categorical' || args.y_axis_type === 'categorical') + return console.warn('The option "brush" does not support axis type "categorical" currently.'); + if (!args.zoom_target) args.zoom_target = args; + if (args.zoom_target !== args) args.zoom_target.processed.subplot = args; + let brush_axis; + switch (args.brush) { + case 'x': + brush_axis = {x: true, y: false}; + break; + case 'y': + brush_axis = {x: false, y: true}; + break; + case 'xy': + brush_axis = {x: true, y: true}; + break; + default: + brush_axis = {x: true, y: true}; + } + add_event_handler_for_brush(args, args.zoom_target, brush_axis); +}; + +MG.add_brush_function = add_brush_function; +MG.create_brushing_pattern = create_brushing_pattern; +MG.remove_brushing_pattern = remove_brushing_pattern; + +} diff --git a/priv/static/js/metricsgraphics/common/chart_title.js b/priv/static/js/metricsgraphics/common/chart_title.js new file mode 100644 index 0000000..b2624dd --- /dev/null +++ b/priv/static/js/metricsgraphics/common/chart_title.js @@ -0,0 +1,67 @@ +function chart_title(args) { + 'use strict'; + + var svg = mg_get_svg_child_of(args.target); + + //remove the current title if it exists + svg.select('.mg-header').remove(); + + if (args.target && args.title) { + var chartTitle = svg.insert('text') + .attr('class', 'mg-header') + .attr('x', args.center_title_full_width ? args.width /2 : (args.width + args.left - args.right) / 2) + .attr('y', args.title_y_position) + .attr('text-anchor', 'middle') + .attr('dy', '0.55em'); + + //show the title + chartTitle.append('tspan') + .attr('class', 'mg-chart-title') + .text(args.title); + + //show and activate the description icon if we have a description + if (args.show_tooltips && args.description && mg_jquery_exists()) { + chartTitle.append('tspan') + .attr('class', 'mg-chart-description') + .attr('dx', '0.3em') + .text('\uf059'); + + //now that the title is an svg text element, we'll have to trigger + //mouseenter, mouseleave events manually for the popover to work properly + var $chartTitle = $(chartTitle.node()); + $chartTitle.popover({ + html: true, + animation: false, + placement: 'top', + content: args.description, + container: args.target, + trigger: 'manual', + template: '<div class="popover mg-popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>' + }).on('mouseenter', function() { + d3.selectAll(args.target) + .selectAll('.mg-popover') + .remove(); + + $(this).popover('show'); + $(d3.select(args.target).select('.popover').node()) + .on('mouseleave', function () { + $chartTitle.popover('hide'); + }); + }).on('mouseleave', function () { + setTimeout(function () { + if (!$('.popover:hover').length) { + $chartTitle.popover('hide'); + } + }, 120); + }); + } else if (args.show_tooltips && args.description && typeof $ === 'undefined') { + args.error = 'In order to enable tooltips, please make sure you include jQuery.'; + } + } + + if (args.error) { + error(args); + } +} + +MG.chart_title = chart_title; diff --git a/priv/static/js/metricsgraphics/common/data_graphic.js b/priv/static/js/metricsgraphics/common/data_graphic.js new file mode 100644 index 0000000..517b3fa --- /dev/null +++ b/priv/static/js/metricsgraphics/common/data_graphic.js @@ -0,0 +1,205 @@ +MG.globals = {}; +MG.deprecations = { + rollover_callback: { replacement: 'mouseover', version: '2.0' }, + rollout_callback: { replacement: 'mouseout', version: '2.0' }, + x_rollover_format: { replacement: 'x_mouseover', version: '2.10' }, + y_rollover_format: { replacement: 'y_mouseover', version: '2.10' }, + show_years: { replacement: 'show_secondary_x_label', version: '2.1' }, + xax_start_at_min: { replacement: 'axes_not_compact', version: '2.7' }, + interpolate_tension: { replacement: 'interpolate', version: '2.10' } +}; +MG.globals.link = false; +MG.globals.version = "1.1"; + +MG.options = { // <name>: [<defaultValue>, <availableType>] + x_axis_type: [null, ['categorical']], // TO BE INTRODUCED IN 2.10 + y_axis_type: [null, ['categorical']], // TO BE INTRODUCED IN 2.10 + y_padding_percentage: [0.05, 'number'], // for categorical scales + y_outer_padding_percentage: [0.1, 'number'], // for categorical scales + ygroup_padding_percentage: [0.25, 'number'], // for categorical scales + ygroup_outer_padding_percentage: [0, 'number'], // for categorical scales + x_padding_percentage: [0.05, 'number'], // for categorical scales + x_outer_padding_percentage: [0.1, 'number'], // for categorical scales + xgroup_padding_percentage: [0.25, 'number'], // for categorical scales + xgroup_outer_padding_percentage: [0, 'number'], // for categorical scales + ygroup_accessor: [null, 'string'], + xgroup_accessor: [null, 'string'], + y_categorical_show_guides: [false, 'boolean'], + x_categorical_show_guide: [false, 'boolean'], + rotate_x_labels: [0, 'number'], + rotate_y_labels: [0, 'number'], + scales: [{}], + scalefns: [{}], + // Data + data: [[], ['object[]', 'number[]']], // the data object + missing_is_zero: [false, 'boolean'], // assume missing observations are zero + missing_is_hidden: [false, 'boolean'], // show missing observations as missing line segments + missing_is_hidden_accessor: [null, 'string'], // the accessor for identifying observations as missing + utc_time: [false, 'boolean'], // determines whether to use a UTC or local time scale + x_accessor: ['date', 'string'], // the data element that's the x-accessor + x_sort: [true, 'boolean'], // determines whether to sort the x-axis' values + y_accessor: ['value', ['string', 'string[]']], // the data element that's the y-accessor + // Axes + axes_not_compact: [true, 'boolean'], // determines whether to draw compact or non-compact axes + european_clock: [false, 'boolean'], // determines whether to show labels using a 24-hour clock + inflator: [10/9, 'number'], // a multiplier for inflating max_x and max_y + max_x: [null, ['number', Date]], // the maximum x-value + max_y: [null, ['number', Date]], // the maximum y-value + min_x: [null, ['number', Date]], // the minimum x-value + min_y: [null, ['number', Date]], // the minimum y-value + min_y_from_data: [false, 'boolean'], // starts y-axis at data's minimum value + show_year_markers: [false, 'boolean'], // determines whether to show year markers along the x-axis + show_secondary_x_label: [true, 'boolean'], // determines whether to show years along the x-axis + small_text: [false, 'boolean'], + x_extended_ticks: [false, 'boolean'], // determines whether to extend the x-axis ticks across the chart + x_axis: [true, 'boolean'], // determines whether to display the x-axis + x_label: ['', 'string'], // the label to show below the x-axis + xax_count: [6, 'number'], // the number of x-axis ticks + xax_format: [null, 'function'], // a function that formats the x-axis' labels + xax_tick_length: [5, 'number'], // the x-axis' tick length in pixels + xax_units: ['', 'string'], // a prefix symbol to be shown alongside the x-axis' labels + x_scale_type: ['linear', 'log'], // the x-axis scale type + y_axis: [true, 'boolean'], // determines whether to display the y-axis + x_axis_position: ['bottom'], // string + y_axis_position: ['left'], // string + y_extended_ticks: [false, 'boolean'], // determines whether to extend the y-axis ticks across the chart + y_label: ['', 'string'], // the label to show beside the y-axis + y_scale_type: ['linear', ['linear', 'log']], // the y-axis scale type + yax_count: [3, 'number'], // the number of y-axis ticks + yax_format: [null, 'function'], // a function that formats the y-axis' labels + yax_tick_length: [5, 'number'], // the y-axis' tick length in pixels + yax_units: ['', 'string'], // a prefix symbol to be shown alongside the y-axis' labels + yax_units_append: [false, 'boolean'], // determines whether to append rather than prepend units + // GraphicOptions + aggregate_rollover: [false, 'boolean'], // links the lines in a multi-line graphic + animate_on_load: [false, 'boolean'], // determines whether lines are transitioned on first-load + area: [true, ['boolean', 'array']], // determines whether to fill the area below the line + flip_area_under_y_value: [null, 'number'], // Specify a Y baseline number value to flip area under it + baselines: [null, 'object[]'], // horizontal lines that indicate, say, goals. + chart_type: ['line', ['line', 'histogram', 'point', 'bar', 'missing-data']], // '{line, histogram, point, bar, missing-data}'], + color: [null, ['string', 'string[]']], + colors: [null, ['string', 'string[]']], + custom_line_color_map: [[], 'number[]'], // maps an arbitrary set of lines to colors + decimals: [2, 'number'], // the number of decimals to show in a rollover + error: ['', 'string'], // does the graphic have an error that we want to communicate to users + format: ['count', ['count', 'percentage']], // the format of the data object (count or percentage) + full_height: [false, 'boolean'], // sets height to that of the parent, adjusts dimensions on window resize + full_width: [false, 'boolean'], // sets width to that of the parent, adjusts dimensions on window resize + interpolate: [d3.curveCatmullRom.alpha(0), [d3.curveBasisClosed, d3.curveBasisOpen, d3.curveBasis, d3.curveBundle, d3.curveCardinalClosed, d3.curveCardinalOpen, d3.curveCardinal, d3.curveCatmullRomClosed, d3.curveCatmullRomOpen, d3.curveLinearClosed, d3.curveLinear, d3.curveMonotoneX, d3.curveMonotoneY, d3.curveNatural, d3.curveStep, d3.curveStepAfter, d3.curveStepBefore]], // the interpolation function to use for rendering lines + legend: ['', 'string[]'], // an array of literals used to label lines + legend_target: ['', 'string'], // the DOM element to insert the legend in + linked: [false, 'boolean'], // used to link multiple graphics together + linked_format: ['%Y-%m-%d', 'string'], // specifies the format of linked rollovers + list: [false, 'boolean'], // automatically maps the data to x and y accessors + markers: [null, 'object[]'], // vertical lines that indicate, say, milestones + max_data_size: [null, 'number'], // for use with custom_line_color_map + missing_text: [null, 'string'], // The text to display for missing graphics + show_missing_background: [true, 'boolean'], // Displays a background for missing graphics + mousemove_align: ['right', 'string'], // implemented in point.js + x_mouseover: [null, ['string', 'function']], + y_mouseover: [null, ['string', 'function']], + mouseover: [null, 'function'], // custom rollover function + mousemove: [null, 'function'], // custom rollover function + mouseout: [null, 'function'], // custom rollover function + click: [null, 'function'], + point_size: [2.5, 'number'], // the radius of the dots in the scatterplot + active_point_on_lines: [false, 'boolean'], // if set, active dot on lines will be displayed. + active_point_accessor: ['active', 'string'], // data accessor value to determine if a point is active or not + active_point_size: [2, 'number'], // the size of the dot that appears on a line when + points_always_visible: [false, 'boolean'], // whether to always display data points and not just on hover + rollover_time_format: [null, 'string'], // custom time format for rollovers + show_confidence_band: [null, 'string[]'], // determines whether to show a confidence band + show_rollover_text: [true, 'boolean'], // determines whether to show text for a data point on rollover + show_tooltips: [true, 'boolean'], // determines whether to display descriptions in tooltips + showActivePoint: [true, 'boolean'], // If enabled show active data point information in chart + target: ['#viz', ['string', HTMLElement]], // the DOM element to insert the graphic in + transition_on_update: [true, 'boolean'], // gracefully transitions the lines on data change + x_rug: [false, 'boolean'], // show a rug plot along the x-axis + y_rug: [false, 'boolean'], // show a rug plot along the y-axis + mouseover_align: ['right', ['right', 'left']], + brush: [null, ['xy','x','y']], // add brush function + brushing_selection_changed: [null, 'function'], // callback function on brushing. the first parameter are the arguments that correspond to this chart, the second parameter is the range of the selection + zoom_target: [null, 'object'], // the zooming target of brushing function + click_to_zoom_out: [true, 'boolean'], // if true and the graph is currently zoomed in, clicking on the graph will zoom out + // Layout + buffer: [8, 'number'], // the padding around the graphic + bottom: [45, 'number'], // the size of the bottom margin + center_title_full_width: [false, 'boolean'], // center title over entire graph + height: [220, 'number'], // the graphic's height + left: [50, 'number'], // the size of the left margin + right: [10, 'number'], // the size of the right margin + small_height_threshold: [120, 'number'], // maximum height for a small graphic + small_width_threshold: [160, 'number'], // maximum width for a small graphic + top: [65, 'number'], // the size of the top margin + width: [350, 'number'], // the graphic's width + title_y_position: [10, 'number'], // how many pixels from the top edge (0) should we show the title at + title: [null, 'string'], + description: [null, 'string'] +}; + +MG.charts = {}; + +MG.defaults = options_to_defaults(MG.options); + +MG.data_graphic = function(args) { + 'use strict'; + + MG.call_hook('global.defaults', MG.defaults); + + if (!args) { args = {}; } + + for (let key in args) { + if (!mg_validate_option(key, args[key])) { + if (!(key in MG.options)) { + console.warn(`Option ${key} not recognized`); + } else { + console.warn(`Option ${key} expected type ${MG.options[key][1]} but got ${args[key]} instead`); + } + } + } + + var selected_chart = MG.charts[args.chart_type || MG.defaults.chart_type]; + merge_with_defaults(args, selected_chart.defaults, MG.defaults); + + if (args.list) { + args.x_accessor = 0; + args.y_accessor = 1; + } + + // check for deprecated parameters + for (var key in MG.deprecations) { + if (args.hasOwnProperty(key)) { + var deprecation = MG.deprecations[key], + message = 'Use of `args.' + key + '` has been deprecated', + replacement = deprecation.replacement, + version; + + // transparently alias the deprecated + if (replacement) { + if (args[replacement]) { + message += '. The replacement - `args.' + replacement + '` - has already been defined. This definition will be discarded.'; + } else { + args[replacement] = args[key]; + } + } + + if (deprecation.warned) { + continue; + } + + deprecation.warned = true; + + if (replacement) { + message += ' in favor of `args.' + replacement + '`'; + } + + warn_deprecation(message, deprecation.version); + } + } + + MG.call_hook('global.before_init', args); + + new selected_chart.descriptor(args); + + return args.data; +}; diff --git a/priv/static/js/metricsgraphics/common/hooks.js b/priv/static/js/metricsgraphics/common/hooks.js new file mode 100644 index 0000000..5f2adb5 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/hooks.js @@ -0,0 +1,63 @@ +/** + Record of all registered hooks. + For internal use only. +*/ +MG._hooks = {}; + +/** + Add a hook callthrough to the stack. + + Hooks are executed in the order that they were registered. +*/ +MG.add_hook = function(name, func, context) { + var hooks; + + if (!MG._hooks[name]) { + MG._hooks[name] = []; + } + + hooks = MG._hooks[name]; + + var already_registered = + hooks.filter(function(hook) { + return hook.func === func; + }) + .length > 0; + + if (already_registered) { + throw 'That function is already registered.'; + } + + hooks.push({ + func: func, + context: context + }); +}; + +/** + Execute registered hooks. + + Optional arguments +*/ +MG.call_hook = function(name) { + var hooks = MG._hooks[name], + result = [].slice.apply(arguments, [1]), + processed; + + if (hooks) { + hooks.forEach(function(hook) { + if (hook.func) { + var params = processed || result; + + if (params && params.constructor !== Array) { + params = [params]; + } + + params = [].concat.apply([], params); + processed = hook.func.apply(hook.context, params); + } + }); + } + + return processed || result; +}; diff --git a/priv/static/js/metricsgraphics/common/init.js b/priv/static/js/metricsgraphics/common/init.js new file mode 100644 index 0000000..4b43e48 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/init.js @@ -0,0 +1,273 @@ +function mg_merge_args_with_defaults(args) { + var defaults = { + target: null, + title: null, + description: null + }; + + if (!args) { + args = {}; + } + + if (!args.processed) { + args.processed = {}; + } + + args = merge_with_defaults(args, defaults); + return args; +} + +function mg_is_time_series(args) { + var first_elem = mg_flatten_array(args.processed.original_data || args.data)[0]; + args.time_series = mg_is_date(first_elem[args.processed.original_x_accessor || args.x_accessor]); +} + +function mg_init_compute_width(args) { + var svg_width = parseInt(args.width); + if (args.full_width) { + svg_width = get_width(args.target); + } + if (args.x_axis_type === 'categorical' && svg_width === null) { + svg_width = mg_categorical_calculate_height(args, 'x'); + } + + args.width = svg_width; +} + +function mg_init_compute_height(args) { + var svg_height = parseInt(args.height); + if (args.full_height) { + svg_height = get_height(args.target); + } + if (args.y_axis_type === 'categorical' && svg_height === null) { + svg_height = mg_categorical_calculate_height(args, 'y'); + } + + args.height = svg_height; +} + +function mg_remove_svg_if_chart_type_has_changed(svg, args) { + if ((!svg.selectAll('.mg-main-line').empty() && args.chart_type !== 'line') || + (!svg.selectAll('.mg-points').empty() && args.chart_type !== 'point') || + (!svg.selectAll('.mg-histogram').empty() && args.chart_type !== 'histogram') || + (!svg.selectAll('.mg-barplot').empty() && args.chart_type !== 'bar') + ) { + svg.remove(); + } +} + +function mg_add_svg_if_it_doesnt_exist(svg, args) { + if (mg_get_svg_child_of(args.target).empty()) { + svg = d3.select(args.target) + .append('svg') + .classed('linked', args.linked) + .attr('width', args.width) + .attr('height', args.height); + } + return svg; +} + +function mg_add_clip_path_for_plot_area(svg, args) { + svg.selectAll('.mg-clip-path').remove(); + svg.append('defs') + .attr('class', 'mg-clip-path') + .append('clipPath') + .attr('id', 'mg-plot-window-' + mg_target_ref(args.target)) + .append('svg:rect') + .attr('x', mg_get_left(args)) + .attr('y', mg_get_top(args)) + .attr('width', args.width - args.left - args.right - args.buffer) + .attr('height', args.height - args.top - args.bottom - args.buffer + 1); +} + +function mg_adjust_width_and_height_if_changed(svg, args) { + if (args.width !== Number(svg.attr('width'))) { + svg.attr('width', args.width); + } + if (args.height !== Number(svg.attr('height'))) { + svg.attr('height', args.height); + } +} + +function mg_set_viewbox_for_scaling(svg, args) { + // we need to reconsider how we handle automatic scaling + svg.attr('viewBox', '0 0 ' + args.width + ' ' + args.height); + if (args.full_width || args.full_height) { + svg.attr('preserveAspectRatio', 'xMinYMin meet'); + } +} + +function mg_remove_missing_classes_and_text(svg) { + // remove missing class + svg.classed('mg-missing', false); + + // remove missing text + svg.selectAll('.mg-missing-text').remove(); + svg.selectAll('.mg-missing-pane').remove(); +} + +function mg_remove_outdated_lines(svg, args) { + // if we're updating an existing chart and we have fewer lines than + // before, remove the outdated lines, e.g. if we had 3 lines, and we're calling + // data_graphic() on the same target with 2 lines, remove the 3rd line + + var i = 0; + + if (svg.selectAll('.mg-main-line').nodes().length >= args.data.length) { + // now, the thing is we can't just remove, say, line3 if we have a custom + // line-color map, instead, see which are the lines to be removed, and delete those + if (args.custom_line_color_map.length > 0) { + var array_full_series = function(len) { + var arr = new Array(len); + for (var i = 0; i < arr.length; i++) { arr[i] = i + 1; } + return arr; + }; + + // get an array of lines ids to remove + var lines_to_remove = arr_diff( + array_full_series(args.max_data_size), + args.custom_line_color_map); + + for (i = 0; i < lines_to_remove.length; i++) { + svg.selectAll('.mg-main-line.mg-line' + lines_to_remove[i] + '-color') + .remove(); + } + } else { + // if we don't have a custom line-color map, just remove the lines from the end + var num_of_new = args.data.length; + var num_of_existing = (svg.selectAll('.mg-main-line').nodes()) ? svg.selectAll('.mg-main-line').nodes().length : 0; + + for (i = num_of_existing; i > num_of_new; i--) { + svg.selectAll('.mg-main-line.mg-line' + i + '-color') + .remove(); + } + } + } +} + +function mg_raise_container_error(container, args) { + if (container.empty()) { + console.warn('The specified target element "' + args.target + '" could not be found in the page. The chart will not be rendered.'); + return; + } +} + +function categoricalInitialization(args, ns) { + var which = ns === 'x' ? args.width : args.height; + mg_categorical_count_number_of_groups(args, ns); + mg_categorical_count_number_of_lanes(args, ns); + mg_categorical_calculate_group_length(args, ns, which); + if (which) mg_categorical_calculate_bar_thickness(args, ns); +} + +function selectXaxFormat(args) { + var c = args.chart_type; + if (!args.processed.xax_format) { + if (args.xax_format) { + args.processed.xax_format = args.xax_format; + } else { + if (c === 'line' || c === 'point' || c === 'histogram') { + args.processed.xax_format = mg_default_xax_format(args); + } else if (c === 'bar') { + args.processed.xax_format = mg_default_bar_xax_format(args); + } + } + } +} + +function mg_categorical_count_number_of_groups(args, ns) { + var accessor_string = ns + 'group_accessor'; + var accessor = args[accessor_string]; + args.categorical_groups = []; + if (accessor) { + var data = args.data[0]; + args.categorical_groups = d3.set(data.map(function(d) { + return d[accessor]; })).values(); + } +} + +function mg_categorical_count_number_of_lanes(args, ns) { + var accessor_string = ns + 'group_accessor'; + var groupAccessor = args[accessor_string]; + + args.total_bars = args.data[0].length; + if (groupAccessor) { + var group_bars = count_array_elements(pluck(args.data[0], groupAccessor)); + group_bars = d3.max(Object.keys(group_bars).map(function(d) { + return group_bars[d]; })); + args.bars_per_group = group_bars; + } else { + args.bars_per_group = args.data[0].length; + } +} + +function mg_categorical_calculate_group_length(args, ns, which) { + var groupHeight = ns + 'group_height'; + if (which) { + var gh = ns === 'y' ? + (args.height - args.top - args.bottom - args.buffer * 2) / (args.categorical_groups.length || 1) : + (args.width - args.left - args.right - args.buffer * 2) / (args.categorical_groups.length || 1); + + args[groupHeight] = gh; + } else { + var step = (1 + args[ns + '_padding_percentage']) * args.bar_thickness; + args[groupHeight] = args.bars_per_group * step + args[ns + '_outer_padding_percentage'] * 2 * step; //args.bar_thickness + (((args.bars_per_group-1) * args.bar_thickness) * (args.bar_padding_percentage + args.bar_outer_padding_percentage*2)); + } +} + +function mg_categorical_calculate_bar_thickness(args, ns) { + // take one group height. + var step = (args[ns + 'group_height']) / (args.bars_per_group + args[ns + '_outer_padding_percentage']); + args.bar_thickness = step - (step * args[ns + '_padding_percentage']); +} + +function mg_categorical_calculate_height(args, ns) { + var groupContribution = (args[ns + 'group_height']) * (args.categorical_groups.length || 1); + + var marginContribution = ns === 'y' + ? args.top + args.bottom + args.buffer * 2 + : args.left + args.right + args.buffer * 2; + + return groupContribution + marginContribution + + (args.categorical_groups.length * args[ns + 'group_height'] * (args[ns + 'group_padding_percentage'] + args[ns + 'group_outer_padding_percentage'])); +} + +function mg_barchart_extrapolate_group_and_thickness_from_height(args) { + // we need to set args.bar_thickness, group_height +} + +function init(args) { + 'use strict'; + args = arguments[0]; + args = mg_merge_args_with_defaults(args); + // If you pass in a dom element for args.target, the expectation + // of a string elsewhere will break. + var container = d3.select(args.target); + mg_raise_container_error(container, args); + + var svg = container.selectAll('svg'); + + // some things that will need to be calculated if we have a categorical axis. + if (args.y_axis_type === 'categorical') { categoricalInitialization(args, 'y'); } + if (args.x_axis_type === 'categorical') { categoricalInitialization(args, 'x'); } + + selectXaxFormat(args); + + mg_is_time_series(args); + mg_init_compute_width(args); + mg_init_compute_height(args); + + mg_remove_svg_if_chart_type_has_changed(svg, args); + svg = mg_add_svg_if_it_doesnt_exist(svg, args); + + mg_add_clip_path_for_plot_area(svg, args); + mg_adjust_width_and_height_if_changed(svg, args); + mg_set_viewbox_for_scaling(svg, args); + mg_remove_missing_classes_and_text(svg); + chart_title(args); + mg_remove_outdated_lines(svg, args); + + return this; +} + +MG.init = init; diff --git a/priv/static/js/metricsgraphics/common/markers.js b/priv/static/js/metricsgraphics/common/markers.js new file mode 100644 index 0000000..4371282 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/markers.js @@ -0,0 +1,132 @@ +function mg_return_label(d) { + return d.label; +} + +function mg_remove_existing_markers(svg) { + svg.selectAll('.mg-markers').remove(); + svg.selectAll('.mg-baselines').remove(); +} + +function mg_in_range(args) { + return function(d) { + return (args.scales.X(d[args.x_accessor]) >= mg_get_plot_left(args)) && (args.scales.X(d[args.x_accessor]) <= mg_get_plot_right(args)); + }; +} + +function mg_x_position(args) { + return function(d) { + return args.scales.X(d[args.x_accessor]); + }; +} + +function mg_x_position_fixed(args) { + var _mg_x_pos = mg_x_position(args); + return function(d) { + return _mg_x_pos(d).toFixed(2); + }; +} + +function mg_y_position_fixed(args) { + var _mg_y_pos = args.scales.Y; + return function(d) { + return _mg_y_pos(d.value).toFixed(2); + }; +} + +function mg_place_annotations(checker, class_name, args, svg, line_fcn, text_fcn) { + var g; + if (checker) { + g = svg.append('g').attr('class', class_name); + line_fcn(g, args); + text_fcn(g, args); + } +} + +function mg_place_markers(args, svg) { + mg_place_annotations(args.markers, 'mg-markers', args, svg, mg_place_marker_lines, mg_place_marker_text); +} + +function mg_place_baselines(args, svg) { + mg_place_annotations(args.baselines, 'mg-baselines', args, svg, mg_place_baseline_lines, mg_place_baseline_text); +} + +function mg_place_marker_lines(gm, args) { + var x_pos_fixed = mg_x_position_fixed(args); + gm.selectAll('.mg-markers') + .data(args.markers.filter(mg_in_range(args))) + .enter() + .append('line') + .attr('x1', x_pos_fixed) + .attr('x2', x_pos_fixed) + .attr('y1', args.top) + .attr('y2', mg_get_plot_bottom(args)) + .attr('class', function(d) { + return d.lineclass; + }) + .attr('stroke-dasharray', '3,1'); +} + +function mg_place_marker_text(gm, args) { + gm.selectAll('.mg-markers') + .data(args.markers.filter(mg_in_range(args))) + .enter() + .append('text') + .attr('class', function(d) { + return d.textclass || ''; }) + .classed('mg-marker-text', true) + .attr('x', mg_x_position(args)) + .attr('y', args.x_axis_position === 'bottom' ? mg_get_top(args) * 0.95 : mg_get_bottom(args) + args.buffer) + .attr('text-anchor', 'middle') + .text(mg_return_label) + .each(function(d) { + if (d.click) { + d3.select(this).style('cursor', 'pointer') + .on('click', d.click); + } + if (d.mouseover) { + d3.select(this).style('cursor', 'pointer') + .on('mouseover', d.mouseover); + } + if (d.mouseout) { + d3.select(this).style('cursor', 'pointer') + .on('mouseout', d.mouseout); + } + }); + + mg_prevent_horizontal_overlap(gm.selectAll('.mg-marker-text').nodes(), args); +} + +function mg_place_baseline_lines(gb, args) { + var y_pos = mg_y_position_fixed(args); + gb.selectAll('.mg-baselines') + .data(args.baselines) + .enter().append('line') + .attr('x1', mg_get_plot_left(args)) + .attr('x2', mg_get_plot_right(args)) + .attr('y1', y_pos) + .attr('y2', y_pos); +} + +function mg_place_baseline_text(gb, args) { + var y_pos = mg_y_position_fixed(args); + gb.selectAll('.mg-baselines') + .data(args.baselines) + .enter().append('text') + .attr('x', mg_get_plot_right(args)) + .attr('y', y_pos) + .attr('dy', -3) + .attr('text-anchor', 'end') + .text(mg_return_label); +} + +function markers(args) { + 'use strict'; + + var svg = mg_get_svg_child_of(args.target); + mg_remove_existing_markers(svg); + mg_place_markers(args, svg); + mg_place_baselines(args, svg); + return this; +} + +MG.markers = markers; diff --git a/priv/static/js/metricsgraphics/common/register.js b/priv/static/js/metricsgraphics/common/register.js new file mode 100644 index 0000000..032736f --- /dev/null +++ b/priv/static/js/metricsgraphics/common/register.js @@ -0,0 +1,16 @@ +function register(chartType, descriptor, options) { + const defaults = options ? options_to_defaults(options) : {}; + MG.charts[chartType] = { + descriptor: descriptor, + defaults: defaults, + }; + if (options) { + Object.keys(options).map(key => { + if (!(key in MG.options)) { + MG.options[key] = options[key]; + } + }); + } +} + +MG.register = register; diff --git a/priv/static/js/metricsgraphics/common/rollover.js b/priv/static/js/metricsgraphics/common/rollover.js new file mode 100644 index 0000000..c462d98 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/rollover.js @@ -0,0 +1,98 @@ +function mg_clear_mouseover_container(svg) { + svg.selectAll('.mg-active-datapoint-container').selectAll('*').remove(); +} + +function mg_setup_mouseover_container(svg, args) { + svg.select('.mg-active-datapoint').remove(); + var text_anchor = args.mouseover_align === 'right' + ? 'end' + : (args.mouseover_align === 'left' + ? 'start' + : 'middle'); + + var mouseover_x = (args.mouseover_align === 'right') + ? mg_get_plot_right(args) + : (args.mouseover_align === 'left' + ? mg_get_plot_left(args) + : (args.width - args.left - args.right) / 2 + args.left); + + var active_datapoint = svg.select('.mg-active-datapoint-container') + .attr('transform', 'translate(0 -18)') + .append('text') + .attr('class', 'mg-active-datapoint') + .attr('xml:space', 'preserve') + .attr('text-anchor', text_anchor); + + // set the rollover text's position; if we have markers on two lines, + // nudge up the rollover text a bit + var active_datapoint_y_nudge = 0.75; + + var y_position = (args.x_axis_position === 'bottom') + ? mg_get_top(args) * active_datapoint_y_nudge + : mg_get_bottom(args) + args.buffer * 3; + + if (args.markers) { + var yPos; + svg.selectAll('.mg-marker-text') + .each(function() { + if (!yPos) { + yPos = d3.select(this).attr('y'); + } else if (yPos !== d3.select(this).attr('y')) { + active_datapoint_y_nudge = 0.56; + } + }); + } + + active_datapoint + .attr('transform', 'translate(' + mouseover_x + ',' + (y_position) + ')'); +} + +function mg_mouseover_tspan(svg, text) { + let tspan = svg.append('tspan').text(text); + + return { + bold: () => tspan.attr('font-weight', 'bold'), + font_size: (pts) => tspan.attr('font-size', pts), + x: (x) => tspan.attr('x', x), + y: (y) => tspan.attr('y', y), + elem: tspan + }; +} + +function mg_reset_text_container(svg) { + var textContainer = svg.select('.mg-active-datapoint'); + textContainer + .selectAll('*') + .remove(); + return textContainer; +} + +function mg_mouseover_row(row_number, container, rargs) { + var lineHeight = 1.1; + var rrr = container.append('tspan') + .attr('x', 0) + .attr('y', (row_number * lineHeight) + 'em'); + + return { + rargs, + text: (text) => { + return mg_mouseover_tspan(rrr, text); + } + }; +} + +function mg_mouseover_text(args, rargs) { + mg_setup_mouseover_container(rargs.svg, args); + + let mouseOver = { + row_number: 0, + rargs, + mouseover_row: (rargs) => { + mouseOver.row_number += 1; + return mg_mouseover_row(mouseOver.row_number, mouseOver.text_container, rargs); + }, + text_container: mg_reset_text_container(rargs.svg) + }; + + return mouseOver; +} diff --git a/priv/static/js/metricsgraphics/common/scales.js b/priv/static/js/metricsgraphics/common/scales.js new file mode 100644 index 0000000..4e76285 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/scales.js @@ -0,0 +1,340 @@ +function mg_add_scale_function(args, scalefcn_name, scale, accessor, inflation) { + args.scalefns[scalefcn_name] = function(di) { + if (inflation === undefined) return args.scales[scale](di[accessor]); + else return args.scales[scale](di[accessor]) + inflation; + }; +} + +function mg_position(str, args) { + if (str === 'bottom' || str === 'top') { + return [mg_get_plot_left(args), mg_get_plot_right(args)]; + } + + if (str === 'left' || str === 'right') { + return [mg_get_plot_bottom(args), args.top]; + } +} + +function mg_cat_position(str, args) { + if (str === 'bottom' || str === 'top') { + return [mg_get_plot_left(args), mg_get_plot_right(args)]; + } + + if (str === 'left' || str === 'right') { + return [mg_get_plot_bottom(args), mg_get_plot_top(args)]; + } +} + +function MGScale(args) { + // big wrapper around d3 scale that automatically formats & calculates scale bounds + // according to the data, and handles other niceties. + var scaleArgs = {}; + scaleArgs.use_inflator = false; + scaleArgs.zero_bottom = false; + scaleArgs.scaleType = 'numerical'; + + this.namespace = function(_namespace) { + scaleArgs.namespace = _namespace; + scaleArgs.namespace_accessor_name = scaleArgs.namespace + '_accessor'; + scaleArgs.scale_name = scaleArgs.namespace.toUpperCase(); + scaleArgs.scalefn_name = scaleArgs.namespace + 'f'; + return this; + }; + + this.scaleName = function(scaleName) { + scaleArgs.scale_name = scaleName.toUpperCase(); + scaleArgs.scalefn_name = scaleName +'f'; + return this; + }; + + this.inflateDomain = function(tf) { + scaleArgs.use_inflator = tf; + return this; + }; + + this.zeroBottom = function(tf) { + scaleArgs.zero_bottom = tf; + return this; + }; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + /// all scale domains are either numerical (number, date, etc.) or categorical (factor, label, etc) ///// + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + // these functions automatically create the d3 scale function and place the domain. + + this.numericalDomainFromData = function() { + var other_flat_data_arrays = []; + + if (arguments.length > 0) { + other_flat_data_arrays = arguments; + } + + // pull out a non-empty array in args.data. + var illustrative_data; + for (var i = 0; i < args.data.length; i++) { + if (args.data[i].length > 0) { + illustrative_data = args.data[i]; + } + } + scaleArgs.is_time_series = mg_is_date(illustrative_data[0][args[scaleArgs.namespace_accessor_name]]) + ? true + : false; + + mg_add_scale_function(args, scaleArgs.scalefn_name, scaleArgs.scale_name, args[scaleArgs.namespace_accessor_name]); + + mg_min_max_numerical(args, scaleArgs, other_flat_data_arrays, scaleArgs.use_inflator); + + var time_scale = (args.utc_time) + ? d3.scaleUtc() + : d3.scaleTime(); + + args.scales[scaleArgs.scale_name] = (scaleArgs.is_time_series) + ? time_scale + : (mg_is_function(args[scaleArgs.namespace + '_scale_type'])) + ? args.y_scale_type() + : (args[scaleArgs.namespace + '_scale_type'] === 'log') + ? d3.scaleLog() + : d3.scaleLinear(); + + args.scales[scaleArgs.scale_name].domain([args.processed['min_' + scaleArgs.namespace], args.processed['max_' + scaleArgs.namespace]]); + scaleArgs.scaleType = 'numerical'; + + return this; + }; + + this.categoricalDomain = function(domain) { + args.scales[scaleArgs.scale_name] = d3.scaleOrdinal().domain(domain); + mg_add_scale_function(args, scaleArgs.scalefn_name, scaleArgs.scale_name, args[scaleArgs.namespace_accessor_name]); + return this; + }; + + this.categoricalDomainFromData = function() { + // make args.categorical_variables. + // lets make the categorical variables. + var all_data = mg_flatten_array(args.data); + //d3.set(data.map(function(d){return d[args.group_accessor]})).values() + scaleArgs.categoricalVariables = d3.set(all_data.map(function(d) { + return d[args[scaleArgs.namespace_accessor_name]]; })).values(); + args.scales[scaleArgs.scale_name] = d3.scaleBand() + .domain(scaleArgs.categoricalVariables); + + scaleArgs.scaleType = 'categorical'; + return this; + }; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////// all scale ranges are either positional (for axes, etc) or arbitrary (colors, size, etc) ////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.numericalRange = function(range) { + if (typeof range === 'string') { + args + .scales[scaleArgs.scale_name] + .range(mg_position(range, args)); + } else { + args + .scales[scaleArgs.scale_name] + .range(range); + } + + return this; + }; + + this.categoricalRangeBands = function(range, halfway) { + if (halfway === undefined) halfway = false; + + var namespace = scaleArgs.namespace; + var paddingPercentage = args[namespace + '_padding_percentage']; + var outerPaddingPercentage = args[namespace + '_outer_padding_percentage']; + if (typeof range === 'string') { + // if string, it's a location. Place it accordingly. + args.scales[scaleArgs.scale_name] + .range(mg_position(range, args)) + .paddingInner(paddingPercentage) + .paddingOuter(outerPaddingPercentage); + } else { + args.scales[scaleArgs.scale_name] + .range(range) + .paddingInner(paddingPercentage) + .paddingOuter(outerPaddingPercentage); + } + + mg_add_scale_function( + args, + scaleArgs.scalefn_name, + scaleArgs.scale_name, + args[scaleArgs.namespace_accessor_name], + halfway + ? args.scales[scaleArgs.scale_name].bandwidth() / 2 + : 0 + ); + + return this; + }; + + this.categoricalRange = function(range) { + args.scales[scaleArgs.scale_name].range(range); + mg_add_scale_function(args, scaleArgs.scalefn_name, scaleArgs.scale_name, args[scaleArgs.namespace_accessor_name]); + return this; + }; + + this.categoricalColorRange = function() { + args.scales[scaleArgs.scale_name] = args.scales[scaleArgs.scale_name].domain().length > 10 + ? d3.scaleOrdinal(d3.schemeCategory20) + : d3.scaleOrdinal(d3.schemeCategory10); + + args + .scales[scaleArgs.scale_name] + .domain(scaleArgs.categoricalVariables); + + mg_add_scale_function(args, scaleArgs.scalefn_name, scaleArgs.scale_name, args[scaleArgs.namespace_accessor_name]); + return this; + }; + + this.clamp = function(yn) { + args.scales[scaleArgs.scale_name].clamp(yn); + return this; + }; + + return this; +} + +MG.scale_factory = MGScale; + +/////////////////////////////// x, x_accessor, markers, baselines, etc. +function mg_min_max_numerical(args, scaleArgs, additional_data_arrays) { + // A BIT OF EXPLANATION ABOUT THIS FUNCTION + // This function pulls out all the accessor values in all the arrays in args.data. + // We also have this additional argument, additional_data_arrays, which is an array of arrays of raw data values. + // These values also get concatenated to the data pulled from args.data, and the extents are calculate from that. + // They are optional. + // + // This may seem arbitrary, but it gives us a lot of flexibility. For instance, if we're calculating + // the min and max for the y axis of a line chart, we're going to want to also factor in baselines (horizontal lines + // that might potentially be outside of the y value bounds). The easiest way to do this is in the line.js code + // & scale creation to just flatten the args.baselines array, pull out hte values, and feed it in + // so it appears in additional_data_arrays. + var namespace = scaleArgs.namespace; + var namespace_accessor_name = scaleArgs.namespace_accessor_name; + var use_inflator = scaleArgs.use_inflator; + var zero_bottom = scaleArgs.zero_bottom; + + var accessor = args[namespace_accessor_name]; + + // add together all relevant data arrays. + var all_data = mg_flatten_array(args.data) + .map(function(dp) { + return dp[accessor]; }) + .concat(mg_flatten_array(additional_data_arrays)); + + // do processing for log + if (args[namespace + '_scale_type'] === 'log') { + all_data = all_data.filter(function(d) { + return d > 0; + }); + } + + // use inflator? + var extents = d3.extent(all_data); + var min_val = extents[0]; + var max_val = extents[1]; + + // bolt scale domain to zero when the right conditions are met: + // not pulling the bottom of the range from data + // not zero-bottomed + // not a time series + if (zero_bottom && !args['min_' + namespace + '_from_data'] && min_val > 0 && !scaleArgs.is_time_series) { + min_val = args[namespace + '_scale_type'] === 'log' ? 1 : 0; + } + + if (args[namespace + '_scale_type'] !== 'log' && min_val < 0 && !scaleArgs.is_time_series) { + min_val = min_val - (min_val - min_val * args.inflator) * use_inflator; + } + + if (!scaleArgs.is_time_series) { + max_val = (max_val < 0) ? max_val + (max_val - max_val * args.inflator) * use_inflator : max_val * (use_inflator ? args.inflator : 1); + } + + min_val = args['min_' + namespace] != null ? args['min_' + namespace] : min_val; + max_val = args['max_' + namespace] != null ? args['max_' + namespace] : max_val; + // if there's a single data point, we should custom-set the max values + // so we're displaying some kind of range + if (min_val === max_val && args['min_' + namespace] == null && + args['max_' + namespace] == null) { + if (mg_is_date(min_val)) { + max_val = new Date(MG.clone(min_val).setDate(min_val.getDate() + 1)); + } else if (typeof min_val === 'number') { + max_val = min_val + 1; + mg_force_xax_count_to_be_two(args); + } + } + + args.processed['min_' + namespace] = min_val; + args.processed['max_' + namespace] = max_val; + if (args.processed['zoom_' + namespace]) { + args.processed['min_' + namespace] = args.processed['zoom_' + namespace][0]; + args.processed['max_' + namespace] = args.processed['zoom_' + namespace][1]; + } + MG.call_hook('x_axis.process_min_max', args, args.processed.min_x, args.processed.max_x); + MG.call_hook('y_axis.process_min_max', args, args.processed.min_y, args.processed.max_y); +} + +function mg_categorical_group_color_scale(args) { + if (args.color_accessor !== false) { + if (args.ygroup_accessor) { + // add a custom accessor element. + if (args.color_accessor === null) { + args.color_accessor = args.y_accessor; + } else {} + } + if (args.color_accessor !== null) { + new MG.scale_factory(args) + .namespace('color') + .categoricalDomainFromData() + .categoricalColorRange(); + } + } +} + +function mg_add_color_categorical_scale(args, domain, accessor) { + args.scales.color = d3.scaleOrdinal(d3.schemeCategory20).domain(domain); + args.scalefns.color = function(d) { + return args.scales.color(d[accessor]); + }; +} + +function mg_get_categorical_domain(data, accessor) { + return d3.set(data.map(function(d) { + return d[accessor]; })) + .values(); +} + +function mg_get_color_domain(args) { + var color_domain; + if (args.color_domain === null) { + if (args.color_type === 'number') { + color_domain = d3.extent(args.data[0], function(d) { + return d[args.color_accessor]; }); + } else if (args.color_type === 'category') { + color_domain = mg_get_categorical_domain(args.data[0], args.color_accessor); + + } + } else { + color_domain = args.color_domain; + } + return color_domain; +} + +function mg_get_color_range(args) { + var color_range; + if (args.color_range === null) { + if (args.color_type === 'number') { + color_range = ['blue', 'red']; + } else { + color_range = null; + } + } else { + color_range = args.color_range; + } + return color_range; +} diff --git a/priv/static/js/metricsgraphics/common/window_listeners.js b/priv/static/js/metricsgraphics/common/window_listeners.js new file mode 100644 index 0000000..6dad3e9 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/window_listeners.js @@ -0,0 +1,82 @@ +function MG_WindowResizeTracker() { + var targets = []; + + var Observer; + if (typeof MutationObserver !== "undefined") { + Observer = MutationObserver; + } else if (typeof WebKitMutationObserver !== "undefined") { + Observer = WebKitMutationObserver; + } + + function window_listener() { + targets.forEach(function(target) { + var svg = d3.select(target).select('svg'); + + // skip if svg is not visible + if (!svg.empty() && (svg.node().parentNode.offsetWidth > 0 || svg.node().parentNode.offsetHeight > 0)) { + var aspect = svg.attr('width') !== 0 ? (svg.attr('height') / svg.attr('width')) : 0; + + var newWidth = get_width(target); + + svg.attr('width', newWidth); + svg.attr('height', aspect * newWidth); + } + }); + } + + function remove_target(target) { + var index = targets.indexOf(target); + if (index !== -1) { + targets.splice(index, 1); + } + + if (targets.length === 0) { + window.removeEventListener('resize', window_listener, true); + } + } + + return { + add_target: function(target) { + if (targets.length === 0) { + window.addEventListener('resize', window_listener, true); + } + + if (targets.indexOf(target) === -1) { + targets.push(target); + + if (Observer) { + var observer = new Observer(function(mutations) { + var targetNode = d3.select(target).node(); + + if (!targetNode || mutations.some( + function(mutation) { + for (var i = 0; i < mutation.removedNodes.length; i++) { + if (mutation.removedNodes[i] === targetNode) { + return true; + } + } + })) { + observer.disconnect(); + remove_target(target); + } + }); + + observer.observe(d3.select(target).node().parentNode, { childList: true }); + } + } + } + }; +} + +var mg_window_resize_tracker = new MG_WindowResizeTracker(); + +function mg_window_listeners(args) { + mg_if_aspect_ratio_resize_svg(args); +} + +function mg_if_aspect_ratio_resize_svg(args) { + // have we asked the svg to fill a div, if so resize with div + if (args.full_width || args.full_height) { + mg_window_resize_tracker.add_target(args.target); + } +} diff --git a/priv/static/js/metricsgraphics/common/x_axis.js b/priv/static/js/metricsgraphics/common/x_axis.js new file mode 100644 index 0000000..c050f2b --- /dev/null +++ b/priv/static/js/metricsgraphics/common/x_axis.js @@ -0,0 +1,600 @@ +function x_rug(args) { + 'use strict'; + + if(!args.x_rug) { + return; + } + + args.rug_buffer_size = args.chart_type === 'point' + ? args.buffer / 2 + : args.buffer; + + var rug = mg_make_rug(args, 'mg-x-rug'); + + rug.attr('x1', args.scalefns.xf) + .attr('x2', args.scalefns.xf) + .attr('y1', args.height - args.bottom - args.rug_buffer_size) + .attr('y2', args.height - args.bottom); + + mg_add_color_accessor_to_rug(rug, args, 'mg-x-rug-mono'); +} + +MG.x_rug = x_rug; + +function mg_add_processed_object(args) { + if (!args.processed) { + args.processed = {}; + } +} + +// TODO ought to be deprecated, only used by histogram +function x_axis(args) { + 'use strict'; + + var svg = mg_get_svg_child_of(args.target); + mg_add_processed_object(args); + + mg_select_xax_format(args); + mg_selectAll_and_remove(svg, '.mg-x-axis'); + + if (!args.x_axis) { + return this; + } + + var g = mg_add_g(svg, 'mg-x-axis'); + + mg_add_x_ticks(g, args); + mg_add_x_tick_labels(g, args); + if (args.x_label) { mg_add_x_label(g, args); } + if (args.x_rug) { x_rug(args); } + + return this; +} + +MG.x_axis = x_axis; + +function x_axis_categorical(args) { + var svg = mg_get_svg_child_of(args.target); + var additional_buffer = 0; + if (args.chart_type === 'bar') { + additional_buffer = args.buffer + 5; + } + + mg_add_categorical_scale(args, 'X', args.categorical_variables.reverse(), args.left, mg_get_plot_right(args) - additional_buffer); + mg_add_scale_function(args, 'xf', 'X', 'value'); + mg_selectAll_and_remove(svg, '.mg-x-axis'); + + var g = mg_add_g(svg, 'mg-x-axis'); + + if (!args.x_axis) { + return this; + } + + mg_add_x_axis_categorical_labels(g, args, additional_buffer); + return this; +} + +function mg_add_x_axis_categorical_labels(g, args, additional_buffer) { + var labels = g.selectAll('text') + .data(args.categorical_variables) + .enter() + .append('text'); + + labels + .attr('x', function(d) { + return args.scales.X(d) + args.scales.X.bandwidth() / 2 + (args.buffer) * args.bar_outer_padding_percentage + (additional_buffer / 2); + }) + .attr('y', mg_get_plot_bottom(args)) + .attr('dy', '.35em') + .attr('text-anchor', 'middle') + .text(String); + + if (args.truncate_x_labels) { + labels.each(function(d, idx) { + var elem = this, width = args.scales.X.bandwidth(); + truncate_text(elem, d, width); + }); + } + mg_rotate_labels(labels, args.rotate_x_labels); +} + +MG.x_axis_categorical = x_axis_categorical; + +function mg_point_add_color_scale(args) { + var color_domain, color_range; + + if (args.color_accessor !== null) { + color_domain = mg_get_color_domain(args); + color_range = mg_get_color_range(args); + + if (args.color_type === 'number') { + args.scales.color = d3.scaleLinear() + .domain(color_domain) + .range(color_range) + .clamp(true); + } else { + args.scales.color = args.color_range !== null + ? d3.scaleOrdinal().range(color_range) + : (color_domain.length > 10 + ? d3.scaleOrdinal(d3.schemeCategory20) + : d3.scaleOrdinal(d3.schemeCategory10)); + + args.scales.color.domain(color_domain); + } + mg_add_scale_function(args, 'color', 'color', args.color_accessor); + } +} + +function mg_get_color_domain(args) { + var color_domain; + if (args.color_domain === null) { + if (args.color_type === 'number') { + color_domain = d3.extent(args.data[0], function(d) { + return d[args.color_accessor]; + }); + } else if (args.color_type === 'category') { + color_domain = d3.set(args.data[0] + .map(function(d) { + return d[args.color_accessor]; + })) + .values(); + + color_domain.sort(); + } + } else { + color_domain = args.color_domain; + } + return color_domain; +} + +function mg_get_color_range(args) { + var color_range; + if (args.color_range === null) { + if (args.color_type === 'number') { + color_range = ['blue', 'red']; + } else { + color_range = null; + } + } else { + color_range = args.color_range; + } + return color_range; +} + +function mg_point_add_size_scale(args) { + var min_size, max_size, size_domain, size_range; + if (args.size_accessor !== null) { + size_domain = mg_get_size_domain(args); + size_range = mg_get_size_range(args); + + args.scales.size = d3.scaleLinear() + .domain(size_domain) + .range(size_range) + .clamp(true); + + mg_add_scale_function(args, 'size', 'size', args.size_accessor); + } +} + +function mg_get_size_domain(args) { + return (args.size_domain === null) + ? d3.extent(args.data[0], function(d) { return d[args.size_accessor]; }) + : args.size_domain; +} + +function mg_get_size_range(args) { + var size_range; + if (args.size_range === null) { + size_range = [1, 5]; + } else { + size_range = args.size_range; + } + return size_range; +} + +function mg_add_x_label(g, args) { + if (args.x_label) { + g.append('text') + .attr('class', 'label') + .attr('x', function() { + return mg_get_plot_left(args) + (mg_get_plot_right(args) - mg_get_plot_left(args)) / 2; + }) + .attr('dx', args.x_label_nudge_x != null ? args.x_label_nudge_x : 0) + .attr('y', function() { + var xAxisTextElement = d3.select(args.target) + .select('.mg-x-axis text').node().getBoundingClientRect(); + return mg_get_bottom(args) + args.xax_tick_length * (7 / 3) + xAxisTextElement.height * 0.8 + 10; + }) + .attr('dy', '.5em') + .attr('text-anchor', 'middle') + .text(function(d) { + return args.x_label; + }); + } +} + +function mg_default_bar_xax_format(args) { + return function(d) { + if (d < 1.0 && d > -1.0 && d !== 0) { + // don't scale tiny values + return args.xax_units + d.toFixed(args.decimals); + } else { + var pf = d3.format(',.0f'); + return args.xax_units + pf(d); + } + }; +} + +function mg_get_time_frame(diff) { + // diff should be (max_x - min_x) / 1000, in other words, the difference in seconds. + var time_frame; + if (mg_milisec_diff(diff)) { + time_frame = 'millis'; + } else if (mg_sec_diff(diff)) { + time_frame = 'seconds'; + } else if (mg_day_diff(diff)) { + time_frame = 'less-than-a-day'; + } else if (mg_four_days(diff)) { + time_frame = 'four-days'; + } else if (mg_many_days(diff)) { // a handful of months? + time_frame = 'many-days'; + } else if (mg_many_months(diff)) { + time_frame = 'many-months'; + } else if (mg_years(diff)) { + time_frame = 'years'; + } else { + time_frame = 'default'; + } + return time_frame; +} + +function mg_milisec_diff(diff) { + return diff < 1; +} + +function mg_sec_diff(diff) { + return diff < 60; +} + +function mg_day_diff(diff) { + return diff / (60 * 60) < 24; +} + +function mg_four_days(diff) { + return diff / (60 * 60) < 24 * 4; +} + +function mg_many_days(diff) { + return diff / (60 * 60 * 24) < 60; +} + +function mg_many_months(diff) { + return diff / (60 * 60 * 24) < 365; +} + +function mg_years(diff) { + return diff / (60 * 60 * 24) >= 365; +} + +function mg_get_time_format(utc, diff) { + var main_time_format; + if (mg_milisec_diff(diff)) { + main_time_format = MG.time_format(utc, '%M:%S.%L'); + } else if (mg_sec_diff(diff)) { + main_time_format = MG.time_format(utc, '%M:%S'); + } else if (mg_day_diff(diff)) { + main_time_format = MG.time_format(utc, '%H:%M'); + } else if (mg_four_days(diff) || mg_many_days(diff)) { + main_time_format = MG.time_format(utc, '%b %d'); + } else if (mg_many_months(diff)) { + main_time_format = MG.time_format(utc, '%b'); + } else { + main_time_format = MG.time_format(utc, '%Y'); + } + return main_time_format; +} + +function mg_process_time_format(args) { + if (args.time_series) { + const diff = (args.processed.max_x - args.processed.min_x) / 1000; + const tickDiff = (args.processed.x_ticks[1] - args.processed.x_ticks[0]) / 1000; + args.processed.x_time_frame = mg_get_time_frame(diff); + args.processed.x_tick_diff_time_frame = mg_get_time_frame(tickDiff); + args.processed.main_x_time_format = mg_get_time_format(args.utc_time, tickDiff); + } +} + +function mg_default_xax_format(args) { + if (args.xax_format) { + return args.xax_format; + } + + var data = args.processed.original_data || args.data; + var flattened = mg_flatten_array(data)[0]; + var test_point_x = flattened[args.processed.original_x_accessor || args.x_accessor]; + if (test_point_x === undefined) { + test_point_x = flattened; + } + + return function(d) { + mg_process_time_format(args); + + if (mg_is_date(test_point_x)) { + return args.processed.main_x_time_format(new Date(d)); + } else if (typeof test_point_x === 'number') { + var is_float = d % 1 !== 0; + var pf; + + if (is_float) { + pf = d3.format(',.' + args.decimals + 'f'); + } else if (d < 1000) { + pf = d3.format(',.0f'); + } else { + pf = d3.format(',.2s'); + } + return args.xax_units + pf(d); + } else { + return args.xax_units + d; + } + }; +} + +function mg_add_x_ticks(g, args) { + mg_process_scale_ticks(args, 'x'); + mg_add_x_axis_rim(args, g); + mg_add_x_axis_tick_lines(args, g); +} + +function mg_add_x_axis_rim(args, g) { + var last_i = args.scales.X.ticks(args.xax_count).length - 1; + + if (!args.x_extended_ticks) { + g.append('line') + .attr('x1', function() { + if (args.xax_count === 0) { + return mg_get_plot_left(args); + } else if (args.axes_not_compact && args.chart_type !== 'bar') { + return args.left; + } else { + return (args.scales.X(args.scales.X.ticks(args.xax_count)[0])).toFixed(2); + } + }) + .attr('x2', function() { + if (args.xax_count === 0 || (args.axes_not_compact && args.chart_type !== 'bar')) { + return mg_get_right(args); + } else { + return args.scales.X(args.scales.X.ticks(args.xax_count)[last_i]).toFixed(2); + } + }) + .attr('y1', args.height - args.bottom) + .attr('y2', args.height - args.bottom); + } +} + +function mg_add_x_axis_tick_lines(args, g) { + g.selectAll('.mg-xax-ticks') + .data(args.processed.x_ticks).enter() + .append('line') + .attr('x1', function(d) { + return args.scales.X(d).toFixed(2); }) + .attr('x2', function(d) { + return args.scales.X(d).toFixed(2); }) + .attr('y1', args.height - args.bottom) + .attr('y2', function() { + return (args.x_extended_ticks) ? args.top : args.height - args.bottom + args.xax_tick_length; + }) + .attr('class', function() { + if (args.x_extended_ticks) { + return 'mg-extended-xax-ticks'; + } + }) + .classed('mg-xax-ticks', true); +} + +function mg_add_x_tick_labels(g, args) { + mg_add_primary_x_axis_label(args, g); + mg_add_secondary_x_axis_label(args, g); +} + +function mg_add_primary_x_axis_label(args, g) { + var labels = g.selectAll('.mg-xax-labels') + .data(args.processed.x_ticks).enter() + .append('text') + .attr('x', function(d) { + return args.scales.X(d).toFixed(2); + }) + .attr('y', (args.height - args.bottom + args.xax_tick_length * 7 / 3).toFixed(2)) + .attr('dy', '.50em') + .attr('text-anchor', 'middle'); + + if (args.time_series && args.european_clock) { + labels.append('tspan').classed('mg-european-hours', true).text(function(_d, i) { + var d = new Date(_d); + if (i === 0) return d3.timeFormat('%H')(d); + else return ''; + }); + labels.append('tspan').classed('mg-european-minutes-seconds', true).text(function(_d, i) { + var d = new Date(_d); + return ':' + args.processed.xax_format(d); + }); + } else { + labels.text(function(d) { + return args.xax_units + args.processed.xax_format(d); + }); + } + + // CHECK TO SEE IF OVERLAP for labels. If so, + // remove half of them. This is a dirty hack. + // We will need to figure out a more principled way of doing this. + if (mg_elements_are_overlapping(labels)) { + labels.filter(function(d, i) { + return (i + 1) % 2 === 0; + }).remove(); + + var svg = mg_get_svg_child_of(args.target); + svg.selectAll('.mg-xax-ticks') + .filter(function(d, i) { + return (i + 1) % 2 === 0; + }) + .remove(); + } +} + +function mg_add_secondary_x_axis_label(args, g) { + if (args.time_series && (args.show_years || args.show_secondary_x_label)) { + mg_add_secondary_x_axis_elements(args, g); + } +} + +function mg_get_yformat_and_secondary_time_function(args) { + let tf = { + timeframe: args.processed.x_time_frame, + tick_diff_timeframe: args.processed.x_tick_diff_time_frame + }; + switch (tf.timeframe) { + case 'millis': + case 'seconds': + tf.secondary = d3.timeDays; + if (args.european_clock) tf.yformat = MG.time_format(args.utc_time, '%b %d'); + else tf.yformat = MG.time_format(args.utc_time, '%I %p'); + break; + case 'less-than-a-day': + tf.secondary = d3.timeDays; + tf.yformat = MG.time_format(args.utc_time, '%b %d'); + break; + case 'four-days': + tf.secondary = d3.timeDays; + tf.yformat = MG.time_format(args.utc_time, '%b %d'); + break; + case 'many-days': + tf.secondary = d3.timeYears; + tf.yformat = MG.time_format(args.utc_time, '%Y'); + break; + case 'many-months': + tf.secondary = d3.timeYears; + tf.yformat = MG.time_format(args.utc_time, '%Y'); + break; + default: + tf.secondary = d3.timeYears; + tf.yformat = MG.time_format(args.utc_time, '%Y'); + } + return tf; +} + +function mg_add_secondary_x_axis_elements(args, g) { + var tf = mg_get_yformat_and_secondary_time_function(args); + + var years = tf.secondary(args.processed.min_x, args.processed.max_x); + if (years.length === 0) { + var first_tick = args.scales.X.ticks(args.xax_count)[0]; + years = [first_tick]; + } + + var yg = mg_add_g(g, 'mg-year-marker'); + if (tf.timeframe === 'default' && args.show_year_markers) { + mg_add_year_marker_line(args, yg, years, tf.yformat); + } + if (tf.tick_diff_time_frame != 'years') mg_add_year_marker_text(args, yg, years, tf.yformat); +} + +function mg_add_year_marker_line(args, g, years, yformat) { + g.selectAll('.mg-year-marker') + .data(years).enter() + .append('line') + .attr('x1', function(d) { + return args.scales.X(d).toFixed(2); + }) + .attr('x2', function(d) { + return args.scales.X(d).toFixed(2); + }) + .attr('y1', mg_get_top(args)) + .attr('y2', mg_get_bottom(args)); +} + +function mg_add_year_marker_text(args, g, years, yformat) { + g.selectAll('.mg-year-marker') + .data(years).enter() + .append('text') + .attr('x', function(d, i) { + return args.scales.X(d).toFixed(2); + }) + .attr('y', function() { + var xAxisTextElement = d3.select(args.target) + .select('.mg-x-axis text').node().getBoundingClientRect(); + return (mg_get_bottom(args) + args.xax_tick_length * 7 / 3) + (xAxisTextElement.height * 0.8); + }) + .attr('dy', '.50em') + .attr('text-anchor', 'middle') + .text(function(d) { + return yformat(new Date(d)); + }); +} + +function mg_min_max_x_for_nonbars(mx, args, data) { + var extent_x = d3.extent(data, function(d) { + return d[args.x_accessor]; + }); + mx.min = extent_x[0]; + mx.max = extent_x[1]; +} + +function mg_min_max_x_for_bars(mx, args, data) { + mx.min = d3.min(data, function(d) { + var trio = [ + d[args.x_accessor], + (d[args.baseline_accessor]) ? d[args.baseline_accessor] : 0, + (d[args.predictor_accessor]) ? d[args.predictor_accessor] : 0 + ]; + return Math.min.apply(null, trio); + }); + + if (mx.min > 0) mx.min = 0; + + mx.max = d3.max(data, function(d) { + var trio = [ + d[args.x_accessor], + (d[args.baseline_accessor]) ? d[args.baseline_accessor] : 0, + (d[args.predictor_accessor]) ? d[args.predictor_accessor] : 0 + ]; + return Math.max.apply(null, trio); + }); + return mx; +} + +function mg_min_max_x_for_dates(mx) { + var yesterday = MG.clone(mx.min).setDate(mx.min.getDate() - 1); + var tomorrow = MG.clone(mx.min).setDate(mx.min.getDate() + 1); + mx.min = yesterday; + mx.max = tomorrow; +} + +function mg_min_max_x_for_numbers(mx) { + // TODO do we want to rewrite this? + mx.min = mx.min - 1; + mx.max = mx.max + 1; +} + +function mg_min_max_x_for_strings(mx) { + // TODO shouldn't be allowing strings here to be coerced into numbers + mx.min = Number(mx.min) - 1; + mx.max = Number(mx.max) + 1; +} + +function mg_force_xax_count_to_be_two(args) { + args.xax_count = 2; +} + +function mg_select_xax_format(args) { + var c = args.chart_type; + if (!args.processed.xax_format) { + if (args.xax_format) { + args.processed.xax_format = args.xax_format; + } else { + if (c === 'line' || c === 'point' || c === 'histogram') { + args.processed.xax_format = mg_default_xax_format(args); + } else if (c === 'bar') { + args.processed.xax_format = mg_default_bar_xax_format(args); + } + } + } +} diff --git a/priv/static/js/metricsgraphics/common/y_axis.js b/priv/static/js/metricsgraphics/common/y_axis.js new file mode 100644 index 0000000..773d525 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/y_axis.js @@ -0,0 +1,1072 @@ +function processScaleTicks (args, axis) { + var accessor = args[axis + '_accessor']; + var scale_ticks = args.scales[axis.toUpperCase()].ticks(args[axis + 'ax_count']); + var max = args.processed['max_' + axis]; + + function log10 (val) { + if (val === 1000) { + return 3; + } + if (val === 1000000) { + return 7; + } + return Math.log(val) / Math.LN10; + } + + if (args[axis + '_scale_type'] === 'log') { + // get out only whole logs + scale_ticks = scale_ticks.filter(function (d) { + return Math.abs(log10(d)) % 1 < 1e-6 || Math.abs(log10(d)) % 1 > 1 - 1e-6; + }); + } + + // filter out fraction ticks if our data is ints and if xmax > number of generated ticks + var number_of_ticks = scale_ticks.length; + + // is our data object all ints? + var data_is_int = true; + args.data.forEach(function (d, i) { + d.forEach(function (d, i) { + if (d[accessor] % 1 !== 0) { + data_is_int = false; + return false; + } + }); + }); + + if (data_is_int && number_of_ticks > max && args.format === 'count') { + // remove non-integer ticks + scale_ticks = scale_ticks.filter(function (d) { + return d % 1 === 0; + }); + } + + args.processed[axis + '_ticks'] = scale_ticks; +} + +function rugPlacement (args, axisArgs) { + var position = axisArgs.position; + var ns = axisArgs.namespace; + var coordinates = {}; + if (position === 'left') { + coordinates.x1 = mg_get_left(args) + 1; + coordinates.x2 = mg_get_left(args) + args.rug_buffer_size; + coordinates.y1 = args.scalefns[ns + 'f']; + coordinates.y2 = args.scalefns[ns + 'f']; + } + if (position === 'right') { + coordinates.x1 = mg_get_right(args) - 1; + coordinates.x2 = mg_get_right(args) - args.rug_buffer_size; + coordinates.y1 = args.scalefns[ns + 'f']; + coordinates.y2 = args.scalefns[ns + 'f']; + } + if (position === 'top') { + coordinates.x1 = args.scalefns[ns + 'f']; + coordinates.x2 = args.scalefns[ns + 'f']; + coordinates.y1 = mg_get_top(args) + 1; + coordinates.y2 = mg_get_top(args) + args.rug_buffer_size; + } + if (position === 'bottom') { + coordinates.x1 = args.scalefns[ns + 'f']; + coordinates.x2 = args.scalefns[ns + 'f']; + coordinates.y1 = mg_get_bottom(args) - 1; + coordinates.y2 = mg_get_bottom(args) - args.rug_buffer_size; + } + return coordinates; +} + +function rimPlacement (args, axisArgs) { + var ns = axisArgs.namespace; + var position = axisArgs.position; + var tick_length = args.processed[ns + '_ticks'].length; + var ticks = args.processed[ns + '_ticks']; + var scale = args.scales[ns.toUpperCase()]; + var coordinates = {}; + + if (position === 'left') { + coordinates.x1 = mg_get_left(args); + coordinates.x2 = mg_get_left(args); + coordinates.y1 = tick_length ? scale(ticks[0]).toFixed(2) : mg_get_top(args); + coordinates.y2 = tick_length ? scale(ticks[tick_length - 1]).toFixed(2) : mg_get_bottom(args); + } + if (position === 'right') { + coordinates.x1 = mg_get_right(args); + coordinates.x2 = mg_get_right(args); + coordinates.y1 = tick_length ? scale(ticks[0]).toFixed(2) : mg_get_top(args); + coordinates.y2 = tick_length ? scale(ticks[tick_length - 1]).toFixed(2) : mg_get_bottom(args); + } + if (position === 'top') { + coordinates.x1 = mg_get_left(args); + coordinates.x2 = mg_get_right(args); + coordinates.y1 = mg_get_top(args); + coordinates.y2 = mg_get_top(args); + } + if (position === 'bottom') { + coordinates.x1 = mg_get_left(args); + coordinates.x2 = mg_get_right(args); + coordinates.y1 = mg_get_bottom(args); + coordinates.y2 = mg_get_bottom(args); + } + + if (position === 'left' || position === 'right') { + if (args.axes_not_compact) { + coordinates.y1 = mg_get_bottom(args); + coordinates.y2 = mg_get_top(args); + } else if (tick_length) { + coordinates.y1 = scale(ticks[0]).toFixed(2); + coordinates.y2 = scale(ticks[tick_length - 1]).toFixed(2); + } + } + + return coordinates; +} + +function labelPlacement (args, axisArgs) { + var position = axisArgs.position; + var ns = axisArgs.namespace; + var tickLength = args[ns + 'ax_tick_length']; + var scale = args.scales[ns.toUpperCase()]; + var coordinates = {}; + + if (position === 'left') { + coordinates.x = mg_get_left(args) - tickLength * 3 / 2; + coordinates.y = function (d) { + return scale(d).toFixed(2); + }; + coordinates.dx = -3; + coordinates.dy = '.35em'; + coordinates.textAnchor = 'end'; + coordinates.text = function (d) { + return mg_compute_yax_format(args)(d); + }; + } + if (position === 'right') { + coordinates.x = mg_get_right(args) + tickLength * 3 / 2; + coordinates.y = function (d) { + return scale(d).toFixed(2); + }; + coordinates.dx = 3; + coordinates.dy = '.35em'; + coordinates.textAnchor = 'start'; + coordinates.text = function (d) { + return mg_compute_yax_format(args)(d); }; + } + if (position === 'top') { + coordinates.x = function (d) { + return scale(d).toFixed(2); + }; + coordinates.y = (mg_get_top(args) - tickLength * 7 / 3).toFixed(2); + coordinates.dx = 0; + coordinates.dy = '0em'; + coordinates.textAnchor = 'middle'; + coordinates.text = function (d) { + return mg_default_xax_format(args)(d); + }; + } + if (position === 'bottom') { + coordinates.x = function (d) { + return scale(d).toFixed(2); + }; + coordinates.y = (mg_get_bottom(args) + tickLength * 7 / 3).toFixed(2); + coordinates.dx = 0; + coordinates.dy = '.50em'; + coordinates.textAnchor = 'middle'; + coordinates.text = function (d) { + return mg_default_xax_format(args)(d); + }; + } + + return coordinates; +} + +function addSecondaryLabelElements (args, axisArgs, g) { + var tf = mg_get_yformat_and_secondary_time_function(args); + var years = tf.secondary(args.processed.min_x, args.processed.max_x); + if (years.length === 0) { + var first_tick = args.scales.X.ticks(args.xax_count)[0]; + years = [first_tick]; + } + + var yg = mg_add_g(g, 'mg-year-marker'); + if (tf.timeframe === 'default' && args.show_year_markers) { + yearMarkerLine(args, axisArgs, yg, years, tf.yformat); + } + if (tf.tick_diff_timeframe != 'years') yearMarkerText(args, axisArgs, yg, years, tf.yformat); +} + +function yearMarkerLine (args, axisArgs, g, years, yformat) { + g.selectAll('.mg-year-marker') + .data(years).enter() + .append('line') + .attr('x1', function (d) { + return args.scales.X(d).toFixed(2); }) + .attr('x2', function (d) { + return args.scales.X(d).toFixed(2); }) + .attr('y1', mg_get_top(args)) + .attr('y2', mg_get_bottom(args)); +} + +function yearMarkerText (args, axisArgs, g, years, yformat) { + var position = axisArgs.position; + var ns = axisArgs.namespace; + var scale = args.scales[ns.toUpperCase()]; + var x, y, dy, textAnchor, textFcn; + var xAxisTextElement = d3.select(args.target) + .select('.mg-x-axis text').node().getBoundingClientRect(); + + if (position === 'top') { + x = function (d, i) { + return scale(d).toFixed(2); }; + y = (mg_get_top(args) - args.xax_tick_length * 7 / 3) - (xAxisTextElement.height); + dy = '.50em'; + textAnchor = 'middle'; + textFcn = function (d) { + return yformat(new Date(d)); }; + } + if (position === 'bottom') { + x = function (d, i) { + return scale(d).toFixed(2); }; + y = (mg_get_bottom(args) + args.xax_tick_length * 7 / 3) + (xAxisTextElement.height * 0.8); + dy = '.50em'; + textAnchor = 'middle'; + textFcn = function (d) { + return yformat(new Date(d)); }; + } + + g.selectAll('.mg-year-marker') + .data(years).enter() + .append('text') + .attr('x', x) + .attr('y', y) + .attr('dy', dy) + .attr('text-anchor', textAnchor) + .text(textFcn); +} + +function addNumericalLabels (g, args, axisArgs) { + var ns = axisArgs.namespace; + var coords = labelPlacement(args, axisArgs); + var ticks = args.processed[ns + '_ticks']; + + var labels = g.selectAll('.mg-yax-labels') + .data(ticks).enter() + .append('text') + .attr('x', coords.x) + .attr('dx', coords.dx) + .attr('y', coords.y) + .attr('dy', coords.dy) + .attr('text-anchor', coords.textAnchor) + .text(coords.text); + // move the labels if they overlap + if (ns == 'x') { + if (args.time_series && args.european_clock) { + labels.append('tspan').classed('mg-european-hours', true).text(function (_d, i) { + var d = new Date(_d); + if (i === 0) return d3.timeFormat('%H')(d); + else return ''; + }); + labels.append('tspan').classed('mg-european-minutes-seconds', true).text(function (_d, i) { + var d = new Date(_d); + return ':' + args.processed.xax_format(d); + }); + } else { + labels.text(function (d) { + return args.xax_units + args.processed.xax_format(d); + }); + } + + if (args.time_series && (args.show_years || args.show_secondary_x_label)) { + addSecondaryLabelElements(args, axisArgs, g); + } + } + + if (mg_elements_are_overlapping(labels)) { + labels.filter(function (d, i) { + return (i + 1) % 2 === 0; + }).remove(); + + var svg = mg_get_svg_child_of(args.target); + svg.selectAll('.mg-' + ns + 'ax-ticks').filter(function (d, i) { + return (i + 1) % 2 === 0; }) + .remove(); + } +} + +function addTickLines (g, args, axisArgs) { + // name + var ns = axisArgs.namespace; + var position = axisArgs.position; + var scale = args.scales[ns.toUpperCase()]; + + var ticks = args.processed[ns + '_ticks']; + var ticksClass = 'mg-' + ns + 'ax-ticks'; + var extendedTicksClass = 'mg-extended-' + ns + 'ax-ticks'; + var extendedTicks = args[ns + '_extended_ticks']; + var tickLength = args[ns + 'ax_tick_length']; + + var x1, x2, y1, y2; + + if (position === 'left') { + x1 = mg_get_left(args); + x2 = extendedTicks ? mg_get_right(args) : mg_get_left(args) - tickLength; + y1 = function (d) { + return scale(d).toFixed(2); + }; + y2 = function (d) { + return scale(d).toFixed(2); + }; + } + if (position === 'right') { + x1 = mg_get_right(args); + x2 = extendedTicks ? mg_get_left(args) : mg_get_right(args) + tickLength; + y1 = function (d) { + return scale(d).toFixed(2); + }; + y2 = function (d) { + return scale(d).toFixed(2); + }; + } + if (position === 'top') { + x1 = function (d) { + return scale(d).toFixed(2); + }; + x2 = function (d) { + return scale(d).toFixed(2); + }; + y1 = mg_get_top(args); + y2 = extendedTicks ? mg_get_bottom(args) : mg_get_top(args) - tickLength; + } + if (position === 'bottom') { + x1 = function (d) { + return scale(d).toFixed(2); + }; + x2 = function (d) { + return scale(d).toFixed(2); + }; + y1 = mg_get_bottom(args); + y2 = extendedTicks ? mg_get_top(args) : mg_get_bottom(args) + tickLength; + } + + g.selectAll('.' + ticksClass) + .data(ticks).enter() + .append('line') + .classed(extendedTicksClass, extendedTicks) + .attr('x1', x1) + .attr('x2', x2) + .attr('y1', y1) + .attr('y2', y2); +} + +function initializeAxisRim (g, args, axisArgs) { + var namespace = axisArgs.namespace; + var tick_length = args.processed[namespace + '_ticks'].length; + + var rim = rimPlacement(args, axisArgs); + + if (!args[namespace + '_extended_ticks'] && !args[namespace + '_extended_ticks'] && tick_length) { + g.append('line') + .attr('x1', rim.x1) + .attr('x2', rim.x2) + .attr('y1', rim.y1) + .attr('y2', rim.y2); + } +} + +function initializeRug (args, rug_class) { + var svg = mg_get_svg_child_of(args.target); + var all_data = mg_flatten_array(args.data); + var rug = svg.selectAll('line.' + rug_class).data(all_data); + + // set the attributes that do not change after initialization, per + rug.enter().append('svg:line').attr('class', rug_class).attr('opacity', 0.3); + + // remove rug elements that are no longer in use + mg_exit_and_remove(rug); + + // set coordinates of new rug elements + mg_exit_and_remove(rug); + return rug; +} + +function rug (args, axisArgs) { + 'use strict'; + args.rug_buffer_size = args.chart_type === 'point' ? args.buffer / 2 : args.buffer * 2 / 3; + + var rug = initializeRug(args, 'mg-' + axisArgs.namespace + '-rug'); + var rug_positions = rugPlacement(args, axisArgs); + rug.attr('x1', rug_positions.x1) + .attr('x2', rug_positions.x2) + .attr('y1', rug_positions.y1) + .attr('y2', rug_positions.y2); + + mg_add_color_accessor_to_rug(rug, args, 'mg-' + axisArgs.namespace + '-rug-mono'); +} + +function categoricalLabelPlacement (args, axisArgs, group) { + var ns = axisArgs.namespace; + var position = axisArgs.position; + var scale = args.scales[ns.toUpperCase()]; + var groupScale = args.scales[(ns + 'group').toUpperCase()]; + var coords = {}; + coords.cat = {}; + coords.group = {}; + // x, y, dy, text-anchor + + if (position === 'left') { + coords.cat.x = mg_get_plot_left(args) - args.buffer; + coords.cat.y = function (d) { + return groupScale(group) + scale(d) + scale.bandwidth() / 2; + }; + coords.cat.dy = '.35em'; + coords.cat.textAnchor = 'end'; + coords.group.x = mg_get_plot_left(args) - args.buffer; + coords.group.y = groupScale(group) + (groupScale.bandwidth ? groupScale.bandwidth() / 2 : 0); + coords.group.dy = '.35em'; + coords.group.textAnchor = args['rotate_' + ns + '_labels'] ? 'end' : 'end'; + } + + if (position === 'right') { + coords.cat.x = mg_get_plot_right(args) - args.buffer; + coords.cat.y = function (d) { + return groupScale(group) + scale(d) + scale.bandwidth() / 2; + }; + coords.cat.dy = '.35em'; + coords.cat.textAnchor = 'start'; + coords.group.x = mg_get_plot_right(args) - args.buffer; + coords.group.y = groupScale(group) + (groupScale.bandwidth ? groupScale.bandwidth() / 2 : 0); + coords.group.dy = '.35em'; + coords.group.textAnchor = 'start'; + } + + if (position === 'top') { + coords.cat.x = function (d) { + return groupScale(group) + scale(d) + scale.bandwidth() / 2; + }; + coords.cat.y = mg_get_plot_top(args) + args.buffer; + coords.cat.dy = '.35em'; + coords.cat.textAnchor = args['rotate_' + ns + '_labels'] ? 'start' : 'middle'; + coords.group.x = groupScale(group) + (groupScale.bandwidth ? groupScale.bandwidth() / 2 : 0); + coords.group.y = mg_get_plot_top(args) + args.buffer; + coords.group.dy = '.35em'; + coords.group.textAnchor = args['rotate_' + ns + '_labels'] ? 'start' : 'middle'; + } + + if (position === 'bottom') { + coords.cat.x = function (d) { + return groupScale(group) + scale(d) + scale.bandwidth() / 2; + }; + coords.cat.y = mg_get_plot_bottom(args) + args.buffer; + coords.cat.dy = '.35em'; + coords.cat.textAnchor = args['rotate_' + ns + '_labels'] ? 'start' : 'middle'; + coords.group.x = groupScale(group) + (groupScale.bandwidth ? groupScale.bandwidth() / 2 - scale.bandwidth() / 2 : 0); + coords.group.y = mg_get_plot_bottom(args) + args.buffer; + coords.group.dy = '.35em'; + coords.group.textAnchor = args['rotate_' + ns + '_labels'] ? 'start' : 'middle'; + } + + return coords; +} + +function categoricalLabels (args, axisArgs) { + var ns = axisArgs.namespace; + var nsClass = 'mg-' + ns + '-axis'; + var scale = args.scales[ns.toUpperCase()]; + var groupScale = args.scales[(ns + 'group').toUpperCase()]; + var groupAccessor = ns + 'group_accessor'; + + var svg = mg_get_svg_child_of(args.target); + mg_selectAll_and_remove(svg, '.' + nsClass); + var g = mg_add_g(svg, nsClass); + var group_g; + var groups = groupScale.domain && groupScale.domain() + ? groupScale.domain() + : ['1']; + + groups.forEach(function (group) { + // grab group placement stuff. + var coords = categoricalLabelPlacement(args, axisArgs, group); + + var labels; + group_g = mg_add_g(g, 'mg-group-' + mg_normalize(group)); + if (args[groupAccessor] !== null) { + labels = group_g.append('text') + .classed('mg-barplot-group-label', true) + .attr('x', coords.group.x) + .attr('y', coords.group.y) + .attr('dy', coords.group.dy) + .attr('text-anchor', coords.group.textAnchor) + .text(group); + + } else { + labels = group_g.selectAll('text') + .data(scale.domain()) + .enter() + .append('text') + .attr('x', coords.cat.x) + .attr('y', coords.cat.y) + .attr('dy', coords.cat.dy) + .attr('text-anchor', coords.cat.textAnchor) + .text(String); + } + if (args['rotate_' + ns + '_labels']) { + rotateLabels(labels, args['rotate_' + ns + '_labels']); + } + }); +} + +function categoricalGuides (args, axisArgs) { + // for each group + // for each data point + + var ns = axisArgs.namespace; + var scalef = args.scalefns[ns + 'f']; + var groupf = args.scalefns[ns + 'groupf']; + var groupScale = args.scales[(ns + 'group').toUpperCase()]; + var scale = args.scales[ns.toUpperCase()]; + var position = axisArgs.position; + + var svg = mg_get_svg_child_of(args.target); + var alreadyPlotted = []; + + var x1, x2, y1, y2; + var grs = (groupScale.domain && groupScale.domain()) ? groupScale.domain() : [null]; + + mg_selectAll_and_remove(svg, '.mg-category-guides'); + var g = mg_add_g(svg, 'mg-category-guides'); + + grs.forEach(function (group) { + scale.domain().forEach(function (cat) { + if (position === 'left' || position === 'right') { + x1 = mg_get_plot_left(args); + x2 = mg_get_plot_right(args); + y1 = scale(cat) + groupScale(group) + scale.bandwidth() / 2; + y2 = scale(cat) + groupScale(group) + scale.bandwidth() / 2; + } + + if (position === 'top' || position === 'bottom') { + x1 = scale(cat) + groupScale(group) + scale.bandwidth() / 2 * (group === null); + x2 = scale(cat) + groupScale(group) + scale.bandwidth() / 2 * (group === null); + y1 = mg_get_plot_bottom(args); + y2 = mg_get_plot_top(args); + } + + g.append('line') + .attr('x1', x1) + .attr('x2', x2) + .attr('y1', y1) + .attr('y2', y2) + .attr('stroke-dasharray', '2,1'); + }); + + var first = groupScale(group) + scale(scale.domain()[0]) + scale.bandwidth() / 2 * (group === null || (position !== 'top' && position != 'bottom')); + var last = groupScale(group) + scale(scale.domain()[scale.domain().length - 1]) + scale.bandwidth() / 2 * (group === null || (position !== 'top' && position != 'bottom')); + + var x11, x21, y11, y21, x12, x22, y12, y22; + if (position === 'left' || position === 'right') { + x11 = mg_get_plot_left(args); + x21 = mg_get_plot_left(args); + y11 = first; + y21 = last; + + x12 = mg_get_plot_right(args); + x22 = mg_get_plot_right(args); + y12 = first; + y22 = last; + } + + if (position === 'bottom' || position === 'top') { + x11 = first; + x21 = last; + y11 = mg_get_plot_bottom(args); + y21 = mg_get_plot_bottom(args); + + x12 = first; + x22 = last; + y12 = mg_get_plot_top(args); + y22 = mg_get_plot_top(args); + } + + g.append('line') + .attr('x1', x11) + .attr('x2', x21) + .attr('y1', y11) + .attr('y2', y21) + .attr('stroke-dasharray', '2,1'); + + g.append('line') + .attr('x1', x12) + .attr('x2', x22) + .attr('y1', y12) + .attr('y2', y22) + .attr('stroke-dasharray', '2,1'); + }); +} + +function rotateLabels (labels, rotation_degree) { + if (rotation_degree) { + labels.attr('transform', function () { + var elem = d3.select(this); + return 'rotate(' + rotation_degree + ' ' + elem.attr('x') + ',' + elem.attr('y') + ')'; + }); + + } +} + +function zeroLine (args, axisArgs) { + var svg = mg_get_svg_child_of(args.target); + var ns = axisArgs.namespace; + var position = axisArgs.position; + var scale = args.scales[ns.toUpperCase()]; + var x1, x2, y1, y2; + if (position === 'left' || position === 'right') { + x1 = mg_get_plot_left(args); + x2 = mg_get_plot_right(args); + y1 = scale(0) + 1; + y2 = scale(0) + 1; + } + if (position === 'bottom' || position === 'top') { + y1 = mg_get_plot_top(args); + y2 = mg_get_plot_bottom(args); + x1 = scale(0) - 1; + x2 = scale(0) - 1; + } + + svg.append('line') + .attr('x1', x1) + .attr('x2', x2) + .attr('y1', y1) + .attr('y2', y2) + .attr('stroke', 'black'); +} + +var mgDrawAxis = {}; + +mgDrawAxis.categorical = function (args, axisArgs) { + var ns = axisArgs.namespace; + + categoricalLabels(args, axisArgs); + categoricalGuides(args, axisArgs); +}; + +mgDrawAxis.numerical = function (args, axisArgs) { + var namespace = axisArgs.namespace; + var axisName = namespace + '_axis'; + var axisClass = 'mg-' + namespace + '-axis'; + var svg = mg_get_svg_child_of(args.target); + + mg_selectAll_and_remove(svg, '.' + axisClass); + + if (!args[axisName]) { + return this; + } + + var g = mg_add_g(svg, axisClass); + + processScaleTicks(args, namespace); + initializeAxisRim(g, args, axisArgs); + addTickLines(g, args, axisArgs); + addNumericalLabels(g, args, axisArgs); + + // add label + if (args[namespace + '_label']) { + axisArgs.label(svg.select('.mg-' + namespace + '-axis'), args); + } + + // add rugs + if (args[namespace + '_rug']) { + rug(args, axisArgs); + } + + if (args.show_bar_zero) { + mg_bar_add_zero_line(args); + } + + return this; +}; + +function axisFactory (args) { + var axisArgs = {}; + axisArgs.type = 'numerical'; + + this.namespace = function (ns) { + // take the ns in the scale, and use it to + axisArgs.namespace = ns; + return this; + }; + + this.rug = function (tf) { + axisArgs.rug = tf; + return this; + }; + + this.label = function (tf) { + axisArgs.label = tf; + return this; + }; + + this.type = function (t) { + axisArgs.type = t; + return this; + }; + + this.position = function (pos) { + axisArgs.position = pos; + return this; + }; + + this.zeroLine = function (tf) { + axisArgs.zeroLine = tf; + return this; + }; + + this.draw = function () { + mgDrawAxis[axisArgs.type](args, axisArgs); + return this; + }; + + return this; + +} + +MG.axis_factory = axisFactory; + +/* ================================================================================ */ +/* ================================================================================ */ +/* ================================================================================ */ + +function y_rug (args) { + 'use strict'; + + if (!args.y_rug) { + return; + } + + args.rug_buffer_size = args.chart_type === 'point' + ? args.buffer / 2 + : args.buffer * 2 / 3; + + var rug = mg_make_rug(args, 'mg-y-rug'); + + rug.attr('x1', args.left + 1) + .attr('x2', args.left + args.rug_buffer_size) + .attr('y1', args.scalefns.yf) + .attr('y2', args.scalefns.yf); + + mg_add_color_accessor_to_rug(rug, args, 'mg-y-rug-mono'); +} + +MG.y_rug = y_rug; + +function mg_change_y_extents_for_bars (args, my) { + if (args.chart_type === 'bar') { + my.min = 0; + my.max = d3.max(args.data[0], function (d) { + var trio = []; + trio.push(d[args.y_accessor]); + + if (args.baseline_accessor !== null) { + trio.push(d[args.baseline_accessor]); + } + + if (args.predictor_accessor !== null) { + trio.push(d[args.predictor_accessor]); + } + + return Math.max.apply(null, trio); + }); + } + return my; +} + +function mg_compute_yax_format (args) { + var yax_format = args.yax_format; + if (!yax_format) { + let decimals = args.decimals; + if (args.format === 'count') { + // increase decimals if we have small values, useful for realtime data + if (args.processed.y_ticks.length > 1) { + // calculate the number of decimals between the difference of ticks + // based on approach in flot: https://github.com/flot/flot/blob/958e5fd43c6dff4bab3e1fd5cb6109df5c1e8003/jquery.flot.js#L1810 + decimals = Math.max(0, -Math.floor( + Math.log(Math.abs(args.processed.y_ticks[1] - args.processed.y_ticks[0])) / Math.LN10 + )); + } + + yax_format = function (d) { + var pf; + + if (decimals !== 0) { + // don't scale tiny values + pf = d3.format(',.' + decimals + 'f'); + } else if (d < 1000) { + pf = d3.format(',.0f'); + } else { + pf = d3.format(',.2s'); + } + + // are we adding units after the value or before? + if (args.yax_units_append) { + return pf(d) + args.yax_units; + } else { + return args.yax_units + pf(d); + } + }; + } else { // percentage + yax_format = function (d_) { + var n = d3.format('.0%'); + return n(d_); + }; + } + } + return yax_format; +} + +function mg_bar_add_zero_line (args) { + var svg = mg_get_svg_child_of(args.target); + var extents = args.scales.X.domain(); + if (0 >= extents[0] && extents[1] >= 0) { + var r = args.scales.Y.range(); + var g = args.categorical_groups.length + ? args.scales.YGROUP(args.categorical_groups[args.categorical_groups.length - 1]) + : args.scales.YGROUP(); + + svg.append('svg:line') + .attr('x1', args.scales.X(0)) + .attr('x2', args.scales.X(0)) + .attr('y1', r[0] + mg_get_plot_top(args)) + .attr('y2', r[r.length - 1] + g) + .attr('stroke', 'black') + .attr('opacity', 0.2); + } +} + +function mg_y_domain_range (args, scale) { + scale.domain([args.processed.min_y, args.processed.max_y]) + .range([mg_get_plot_bottom(args), args.top]); + return scale; +} + +function mg_define_y_scales (args) { + var scale = (mg_is_function(args.y_scale_type)) + ? args.y_scale_type() + : (args.y_scale_type === 'log') + ? d3.scaleLog() + : d3.scaleLinear(); + + if (args.y_scale_type === 'log') { + if (args.chart_type === 'histogram') { + // log histogram plots should start just below 1 + // so that bins with single counts are visible + args.processed.min_y = 0.2; + } else { + if (args.processed.min_y <= 0) { + args.processed.min_y = 1; + } + } + } + args.scales.Y = mg_y_domain_range(args, scale); + args.scales.Y.clamp(args.y_scale_type === 'log'); + + // used for ticks and such, and designed to be paired with log or linear + args.scales.Y_axis = mg_y_domain_range(args, d3.scaleLinear()); +} + +function mg_add_y_label (g, args) { + if (args.y_label) { + g.append('text') + .attr('class', 'label') + .attr('x', function () { + return -1 * (mg_get_plot_top(args) + + ((mg_get_plot_bottom(args)) - (mg_get_plot_top(args))) / 2); + }) + .attr('y', function () { + return args.left / 2; + }) + .attr('dy', '-1.2em') + .attr('text-anchor', 'middle') + .text(function (d) { + return args.y_label; + }) + .attr('transform', function (d) { + return 'rotate(-90)'; + }); + } +} + +function mg_add_y_axis_rim (g, args) { + var tick_length = args.processed.y_ticks.length; + if (!args.x_extended_ticks && !args.y_extended_ticks && tick_length) { + var y1scale, y2scale; + + if (args.axes_not_compact && args.chart_type !== 'bar') { + y1scale = args.height - args.bottom; + y2scale = args.top; + } else if (tick_length) { + y1scale = args.scales.Y(args.processed.y_ticks[0]).toFixed(2); + y2scale = args.scales.Y(args.processed.y_ticks[tick_length - 1]).toFixed(2); + } else { + y1scale = 0; + y2scale = 0; + } + + g.append('line') + .attr('x1', args.left) + .attr('x2', args.left) + .attr('y1', y1scale) + .attr('y2', y2scale); + } +} + +function mg_add_y_axis_tick_lines (g, args) { + g.selectAll('.mg-yax-ticks') + .data(args.processed.y_ticks).enter() + .append('line') + .classed('mg-extended-yax-ticks', args.y_extended_ticks) + .attr('x1', args.left) + .attr('x2', function () { + return (args.y_extended_ticks) ? args.width - args.right : args.left - args.yax_tick_length; + }) + .attr('y1', function (d) { + return args.scales.Y(d).toFixed(2); + }) + .attr('y2', function (d) { + return args.scales.Y(d).toFixed(2); + }); +} + +function mg_add_y_axis_tick_labels (g, args) { + var yax_format = mg_compute_yax_format(args); + g.selectAll('.mg-yax-labels') + .data(args.processed.y_ticks).enter() + .append('text') + .attr('x', args.left - args.yax_tick_length * 3 / 2) + .attr('dx', -3) + .attr('y', function (d) { + return args.scales.Y(d).toFixed(2); + }) + .attr('dy', '.35em') + .attr('text-anchor', 'end') + .text(function (d) { + var o = yax_format(d); + return o; + }); +} + +// TODO ought to be deprecated, only used by histogram +function y_axis (args) { + if (!args.processed) { + args.processed = {}; + } + + var svg = mg_get_svg_child_of(args.target); + MG.call_hook('y_axis.process_min_max', args, args.processed.min_y, args.processed.max_y); + mg_selectAll_and_remove(svg, '.mg-y-axis'); + + if (!args.y_axis) { + return this; + } + + var g = mg_add_g(svg, 'mg-y-axis'); + mg_add_y_label(g, args); + mg_process_scale_ticks(args, 'y'); + mg_add_y_axis_rim(g, args); + mg_add_y_axis_tick_lines(g, args); + mg_add_y_axis_tick_labels(g, args); + + if (args.y_rug) { + y_rug(args); + } + + return this; +} + +MG.y_axis = y_axis; + +function mg_add_categorical_labels (args) { + var svg = mg_get_svg_child_of(args.target); + mg_selectAll_and_remove(svg, '.mg-y-axis'); + var g = mg_add_g(svg, 'mg-y-axis'); + var group_g;(args.categorical_groups.length ? args.categorical_groups : ['1']).forEach(function (group) { + group_g = mg_add_g(g, 'mg-group-' + mg_normalize(group)); + + if (args.ygroup_accessor !== null) { + mg_add_group_label(group_g, group, args); + } else { + var labels = mg_add_graphic_labels(group_g, group, args); + mg_rotate_labels(labels, args.rotate_y_labels); + } + }); +} + +function mg_add_graphic_labels (g, group, args) { + return g.selectAll('text').data(args.scales.Y.domain()).enter().append('svg:text') + .attr('x', args.left - args.buffer) + .attr('y', function (d) { + return args.scales.YGROUP(group) + args.scales.Y(d) + args.scales.Y.bandwidth() / 2; + }) + .attr('dy', '.35em') + .attr('text-anchor', 'end') + .text(String); +} + +function mg_add_group_label (g, group, args) { + g.append('svg:text') + .classed('mg-barplot-group-label', true) + .attr('x', args.left - args.buffer) + .attr('y', args.scales.YGROUP(group) + args.scales.YGROUP.bandwidth() / 2) + .attr('dy', '.35em') + .attr('text-anchor', 'end') + .text(group); +} + +function mg_draw_group_lines (args) { + var svg = mg_get_svg_child_of(args.target); + var groups = args.scales.YGROUP.domain(); + var first = groups[0]; + var last = groups[groups.length - 1]; + + svg.select('.mg-category-guides').selectAll('mg-group-lines') + .data(groups) + .enter().append('line') + .attr('x1', mg_get_plot_left(args)) + .attr('x2', mg_get_plot_left(args)) + .attr('y1', function (d) { + return args.scales.YGROUP(d); + }) + .attr('y2', function (d) { + return args.scales.YGROUP(d) + args.ygroup_height; + }) + .attr('stroke-width', 1); +} + +function mg_y_categorical_show_guides (args) { + // for each group + // for each data point + var svg = mg_get_svg_child_of(args.target); + var alreadyPlotted = []; + args.data[0].forEach(function (d) { + if (alreadyPlotted.indexOf(d[args.y_accessor]) === -1) { + svg.select('.mg-category-guides').append('line') + .attr('x1', mg_get_plot_left(args)) + .attr('x2', mg_get_plot_right(args)) + .attr('y1', args.scalefns.yf(d) + args.scalefns.ygroupf(d)) + .attr('y2', args.scalefns.yf(d) + args.scalefns.ygroupf(d)) + .attr('stroke-dasharray', '2,1'); + } + }); +} + +function y_axis_categorical (args) { + if (!args.y_axis) { + return this; + } + + mg_add_categorical_labels(args); + // mg_draw_group_scaffold(args); + if (args.show_bar_zero) mg_bar_add_zero_line(args); + if (args.ygroup_accessor) mg_draw_group_lines(args); + if (args.y_categorical_show_guides) mg_y_categorical_show_guides(args); + return this; +} + +MG.y_axis_categorical = y_axis_categorical; diff --git a/priv/static/js/metricsgraphics/common/zoom.js b/priv/static/js/metricsgraphics/common/zoom.js new file mode 100644 index 0000000..eb877f2 --- /dev/null +++ b/priv/static/js/metricsgraphics/common/zoom.js @@ -0,0 +1,85 @@ +{ + +const filter_in_range_data = (args, range) => { + const is_data_in_range = (data, range) => { + return data > Math.min(range[0], range[1]) && data < Math.max(range[0], range[1]); + }; + // if range without this axis return true, else judge is data in range or not. + return d => ['x', 'y'].every(dim => !(dim in range) || is_data_in_range(d[args[`${dim}_accessor`]], range[dim])); +}; + +// the range here is the range of data +// range is an object with two optional attributes of x,y, respectively represent ranges on two axes +const zoom_to_data_domain = (args, range) => { + const raw_data = args.processed.raw_data || args.data; + // store raw data and raw domain to in order to zoom back to the initial state + if (!('raw_data' in args.processed)) { + args.processed.raw_domain = { + x: args.scales.X.domain(), + y: args.scales.Y.domain() + }; + args.processed.raw_data = raw_data; + } + if (['x', 'y'].some(dim => range[dim][0] === range[dim][1])) return; + // to avoid drawing outside the chart in the point chart, unnecessary in line chart. + if (args.chart_type === 'point') { + if (is_array_of_arrays(raw_data)) { + args.data = raw_data.map(function(d) { + return d.filter(filter_in_range_data(args, range)); + }); + } else { + args.data = raw_data.filter(filter_in_range_data(args, range)); + } + if (mg_flatten_array(args.data).length === 0) return; + } + ['x', 'y'].forEach(dim => { + if (dim in range) args.processed[`zoom_${dim}`] = range[dim]; + else delete args.processed[`zoom_${dim}`]; + }); + if (args.processed.subplot) { + if (range !== args.processed.raw_domain) { + MG.create_brushing_pattern(args.processed.subplot, convert_domain_to_range(args.processed.subplot, range)); + } else { + MG.remove_brushing_pattern(args.processed.subplot); + } + } + new MG.charts[args.chart_type || defaults.chart_type].descriptor(args); +}; + +const zoom_to_raw_range = args => { + if (!('raw_domain' in args.processed)) return; + zoom_to_data_domain(args, args.processed.raw_domain); + delete args.processed.raw_domain; + delete args.processed.raw_data; +}; + +// converts the range of selection into the range of data that we can use to +// zoom the chart to a particular region +const convert_range_to_domain = (args, range) => + ['x', 'y'].reduce((domain, dim) => { + if (!(dim in range)) return domain; + domain[dim] = range[dim].map(v => +args.scales[dim.toUpperCase()].invert(v)); + if (dim === 'y') domain[dim].reverse(); + return domain; + }, {}); + +const convert_domain_to_range = (args, domain) => + ['x', 'y'].reduce((range, dim) => { + if (!(dim in domain)) return range; + range[dim] = domain[dim].map(v => +args.scales[dim.toUpperCase()](v)); + if (dim === 'y') range[dim].reverse(); + return range; + }, {}); + +// the range here is the range of selection +const zoom_to_data_range = (args, range) => { + const domain = convert_range_to_domain(args, range); + zoom_to_data_domain(args, domain); +}; + +MG.convert_range_to_domain = convert_range_to_domain; +MG.zoom_to_data_domain = zoom_to_data_domain; +MG.zoom_to_data_range = zoom_to_data_range; +MG.zoom_to_raw_range = zoom_to_raw_range; + +} diff --git a/priv/static/js/metricsgraphics/layout/bootstrap_dropdown.js b/priv/static/js/metricsgraphics/layout/bootstrap_dropdown.js new file mode 100755 index 0000000..41dbfc5 --- /dev/null +++ b/priv/static/js/metricsgraphics/layout/bootstrap_dropdown.js @@ -0,0 +1,177 @@ +if (mg_jquery_exists()) { + /*! + * Bootstrap v3.3.1 (http://getbootstrap.com) + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + */ + + /*! + * Generated using the Bootstrap Customizer (http://getbootstrap.com/customize/?id=c3834cc5b59ef727da53) + * Config saved to config.json and https://gist.github.com/c3834cc5b59ef727da53 + */ + + /* ======================================================================== + * Bootstrap: dropdown.js v3.3.1 + * http://getbootstrap.com/javascript/#dropdowns + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + + +function ($) { + 'use strict'; + + if(typeof $().dropdown == 'function') + return true; + + // DROPDOWN CLASS DEFINITION + // ========================= + + var backdrop = '.dropdown-backdrop'; + var toggle = '[data-toggle="dropdown"]'; + var Dropdown = function (element) { + $(element).on('click.bs.dropdown', this.toggle); + }; + + Dropdown.VERSION = '3.3.1'; + + Dropdown.prototype.toggle = function (e) { + var $this = $(this); + + if ($this.is('.disabled, :disabled')) return; + + var $parent = getParent($this); + var isActive = $parent.hasClass('open'); + + clearMenus(); + + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we use a backdrop because click events don't delegate + $('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus); + } + + var relatedTarget = { relatedTarget: this }; + $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget)); + + if (e.isDefaultPrevented()) return; + + $this + .trigger('focus') + .attr('aria-expanded', 'true'); + + $parent + .toggleClass('open') + .trigger('shown.bs.dropdown', relatedTarget); + } + + return false; + }; + + Dropdown.prototype.keydown = function (e) { + if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return; + + var $this = $(this); + + e.preventDefault(); + e.stopPropagation(); + + if ($this.is('.disabled, :disabled')) return; + + var $parent = getParent($this); + var isActive = $parent.hasClass('open'); + + if ((!isActive && e.which != 27) || (isActive && e.which == 27)) { + if (e.which == 27) $parent.find(toggle).trigger('focus'); + return $this.trigger('click'); + } + + var desc = ' li:not(.divider):visible a'; + var $items = $parent.find('[role="menu"]' + desc + ', [role="listbox"]' + desc); + + if (!$items.length) return; + + var index = $items.index(e.target); + + if (e.which == 38 && index > 0) index--; // up + if (e.which == 40 && index < $items.length - 1) index++; // down + if (!~index) index = 0; + + $items.eq(index).trigger('focus'); + }; + + function clearMenus(e) { + if (e && e.which === 3) return; + $(backdrop).remove(); + $(toggle).each(function () { + var $this = $(this); + var $parent = getParent($this); + var relatedTarget = { relatedTarget: this }; + + if (!$parent.hasClass('open')) return; + + $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)); + + if (e.isDefaultPrevented()) return; + + $this.attr('aria-expanded', 'false'); + $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget); + }); + } + + function getParent($this) { + var selector = $this.attr('data-target'); + + if (!selector) { + selector = $this.attr('href'); + selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, ''); // strip for ie7 + } + + var $parent = selector && $(selector); + + return $parent && $parent.length ? $parent : $this.parent(); + } + + + // DROPDOWN PLUGIN DEFINITION + // ========================== + + function Plugin(option) { + return this.each(function () { + var $this = $(this); + var data = $this.data('bs.dropdown'); + + if (!data) $this.data('bs.dropdown', (data = new Dropdown(this))); + if (typeof option == 'string') data[option].call($this); + }); + } + + var old = $.fn.dropdown; + + $.fn.dropdown = Plugin; + $.fn.dropdown.Constructor = Dropdown; + + + // DROPDOWN NO CONFLICT + // ==================== + + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old; + return this; + }; + + + // APPLY TO STANDARD DROPDOWN ELEMENTS + // =================================== + + $(document) + .on('click.bs.dropdown.data-api', clearMenus) + .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation(); }) + .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle) + .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown) + .on('keydown.bs.dropdown.data-api', '[role="menu"]', Dropdown.prototype.keydown) + .on('keydown.bs.dropdown.data-api', '[role="listbox"]', Dropdown.prototype.keydown); + + }(jQuery); +} diff --git a/priv/static/js/metricsgraphics/layout/button.js b/priv/static/js/metricsgraphics/layout/button.js new file mode 100644 index 0000000..b122273 --- /dev/null +++ b/priv/static/js/metricsgraphics/layout/button.js @@ -0,0 +1,126 @@ +MG.button_layout = function(target) { + 'use strict'; + this.target = target; + this.feature_set = {}; + this.public_name = {}; + this.sorters = {}; + this.manual = []; + this.manual_map = {}; + this.manual_callback = {}; + + this._strip_punctuation = function(s) { + var punctuationless = s.replace(/[^a-zA-Z0-9 _]+/g, ''); + var finalString = punctuationless.replace(/ +?/g, ''); + return finalString; + }; + + this.data = function(data) { + this._data = data; + return this; + }; + + this.manual_button = function(feature, feature_set, callback) { + this.feature_set[feature] = feature_set; + this.manual_map[this._strip_punctuation(feature)] = feature; + this.manual_callback[feature] = callback; // the default is going to be the first feature. + return this; + }; + + this.button = function(feature) { + if (arguments.length > 1) { + this.public_name[feature] = arguments[1]; + } + + if (arguments.length > 2) { + this.sorters[feature] = arguments[2]; + } + + this.feature_set[feature] = []; + return this; + }; + + this.callback = function(callback) { + this._callback = callback; + return this; + }; + + this.display = function() { + var callback = this._callback; + var manual_callback = this.manual_callback; + var manual_map = this.manual_map; + + var d, f, features, feat; + features = Object.keys(this.feature_set); + + var mapDtoF = function(f) { + return d[f]; }; + + var i; + + // build out this.feature_set with this.data + for (i = 0; i < this._data.length; i++) { + d = this._data[i]; + f = features.map(mapDtoF); + for (var j = 0; j < features.length; j++) { + feat = features[j]; + if (this.feature_set[feat].indexOf(f[j]) === -1) { + this.feature_set[feat].push(f[j]); + } + } + } + + for (feat in this.feature_set) { + if (this.sorters.hasOwnProperty(feat)) { + this.feature_set[feat].sort(this.sorters[feat]); + } + } + + $(this.target).empty(); + + $(this.target).append("<div class='col-lg-12 segments text-center'></div>"); + + var dropdownLiAClick = function() { + var k = $(this).data('key'); + var feature = $(this).data('feature'); + var manual_feature; + $('.' + feature + '-btns button.btn span.title').html(k); + if (!manual_map.hasOwnProperty(feature)) { + callback(feature, k); + } else { + manual_feature = manual_map[feature]; + manual_callback[manual_feature](k); + } + + return false; + }; + + for (var feature in this.feature_set) { + features = this.feature_set[feature]; + $(this.target + ' div.segments').append( + '<div class="btn-group ' + this._strip_punctuation(feature) + '-btns text-left">' + // This never changes. + '<button type="button" class="btn btn-default btn-lg dropdown-toggle" data-toggle="dropdown">' + + "<span class='which-button'>" + (this.public_name.hasOwnProperty(feature) ? this.public_name[feature] : feature) + "</span>" + + "<span class='title'>" + (this.manual_callback.hasOwnProperty(feature) ? this.feature_set[feature][0] : 'all') + "</span>" + // if a manual button, don't default to all in label. + '<span class="caret"></span>' + + '</button>' + + '<ul class="dropdown-menu" role="menu">' + + (!this.manual_callback.hasOwnProperty(feature) ? '<li><a href="#" data-feature="' + feature + '" data-key="all">All</a></li>' : "") + + (!this.manual_callback.hasOwnProperty(feature) ? '<li class="divider"></li>' : "") + + '</ul>' + '</div>'); + + for (i = 0; i < features.length; i++) { + if (features[i] !== 'all' && features[i] !== undefined) { // strange bug with undefined being added to manual buttons. + $(this.target + ' div.' + this._strip_punctuation(feature) + '-btns ul.dropdown-menu').append( + '<li><a href="#" data-feature="' + this._strip_punctuation(feature) + '" data-key="' + features[i] + '">' + features[i] + '</a></li>' + ); + } + } + + $('.' + this._strip_punctuation(feature) + '-btns .dropdown-menu li a').on('click', dropdownLiAClick); + } + + return this; + }; + + return this; +}; diff --git a/priv/static/js/metricsgraphics/misc/error.js b/priv/static/js/metricsgraphics/misc/error.js new file mode 100644 index 0000000..cf2eee3 --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/error.js @@ -0,0 +1,16 @@ +// call this to add a warning icon to a graph and log an error to the console +function error(args) { + console.error('ERROR : ', args.target, ' : ', args.error); + + d3.select(args.target).select('.mg-chart-title') + .append('tspan') + .attr('class', 'fa fa-x fa-exclamation-circle mg-warning') + .attr('dx', '0.3em') + .text('\uf06a'); +} + +function internal_error(args) { + console.error('INTERNAL ERROR : ', args.target, ' : ', args.internal_error); +} + +MG.error = error; diff --git a/priv/static/js/metricsgraphics/misc/formatters.js b/priv/static/js/metricsgraphics/misc/formatters.js new file mode 100644 index 0000000..1533fd5 --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/formatters.js @@ -0,0 +1,147 @@ +function format_rollover_number(args) { + var num; + if (args.format === 'count') { + num = function(d) { + var is_float = d % 1 !== 0; + var pf; + + if (is_float) { + pf = d3.format(',.' + args.decimals + 'f'); + } else { + pf = d3.format(',.0f'); + } + + // are we adding units after the value or before? + if (args.yax_units_append) { + return pf(d) + args.yax_units; + } else { + return args.yax_units + pf(d); + } + }; + } else { + num = function(d_) { + var fmt_string = (isNumeric(args.decimals) ? '.' + args.decimals : '') + '%'; + var pf = d3.format(fmt_string); + return pf(d_); + }; + } + return num; +} + +var time_rollover_format = function(f, d, accessor, utc) { + var fd; + if (typeof f === 'string') { + fd = MG.time_format(utc, f)(d[accessor]); + } else if (typeof f === 'function') { + fd = f(d); + } else { + fd = d[accessor]; + } + return fd; +}; + +// define our rollover format for numbers +var number_rollover_format = function(f, d, accessor) { + var fd; + if (typeof f === 'string') { + fd = d3.format('s')(d[accessor]); + } else if (typeof f === 'function') { + fd = f(d); + } else { + fd = d[accessor]; + } + return fd; +}; + +function mg_format_y_rollover(args, num, d) { + var formatted_y; + if (args.y_mouseover !== null) { + if (args.aggregate_rollover) { + formatted_y = number_rollover_format(args.y_mouseover, d, args.y_accessor); + } else { + formatted_y = number_rollover_format(args.y_mouseover, d, args.y_accessor); + } + } else { + if (args.time_series) { + if (args.aggregate_rollover) { + formatted_y = num(d[args.y_accessor]); + } else { + formatted_y = args.yax_units + num(d[args.y_accessor]); + } + } else { + formatted_y = args.y_accessor + ': ' + args.yax_units + num(d[args.y_accessor]); + } + } + return formatted_y; +} + +function mg_format_x_rollover(args, fmt, d) { + var formatted_x; + if (args.x_mouseover !== null) { + if (args.time_series) { + if (args.aggregate_rollover) { + formatted_x = time_rollover_format(args.x_mouseover, d, 'key', args.utc); + } else { + formatted_x = time_rollover_format(args.x_mouseover, d, args.x_accessor, args.utc); + } + } else { + formatted_x = number_rollover_format(args.x_mouseover, d, args.x_accessor); + } + } else { + if (args.time_series) { + var date; + + if (args.aggregate_rollover && args.data.length > 1) { + date = new Date(d.key); + } else { + date = new Date(+d[args.x_accessor]); + date.setDate(date.getDate()); + } + + formatted_x = fmt(date) + ' '; + } else { + formatted_x = args.x_accessor + ': ' + d[args.x_accessor] + ' '; + } + } + return formatted_x; +} + +function mg_format_data_for_mouseover(args, d, mouseover_fcn, accessor, check_time) { + var formatted_data, formatter; + var time_fmt = mg_get_rollover_time_format(args); + if (typeof d[accessor] === 'string') { + formatter = function(d) { + return d; + }; + } else { + formatter = format_rollover_number(args); + } + + if (mouseover_fcn !== null) { + if (check_time) formatted_data = time_rollover_format(mouseover_fcn, d, accessor, args.utc); + else formatted_data = number_rollover_format(mouseover_fcn, d, accessor); + + } else { + if (check_time) formatted_data = time_fmt(new Date(+d[accessor])) + ' '; + else formatted_data = (args.time_series ? '' : accessor + ': ') + formatter(d[accessor]) + ' '; + } + return formatted_data; +} + +function mg_format_number_mouseover(args, d) { + return mg_format_data_for_mouseover(args, d, args.x_mouseover, args.x_accessor, false); +} + +function mg_format_x_mouseover(args, d) { + return mg_format_data_for_mouseover(args, d, args.x_mouseover, args.x_accessor, args.time_series); +} + +function mg_format_y_mouseover(args, d) { + return mg_format_data_for_mouseover(args, d, args.y_mouseover, args.y_accessor, false); +} + +function mg_format_x_aggregate_mouseover(args, d) { + return mg_format_data_for_mouseover(args, d, args.x_mouseover, 'key', args.time_series); +} + +MG.format_rollover_number = format_rollover_number; diff --git a/priv/static/js/metricsgraphics/misc/markup.js b/priv/static/js/metricsgraphics/misc/markup.js new file mode 100644 index 0000000..c49f12a --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/markup.js @@ -0,0 +1,66 @@ +// influenced by https://bl.ocks.org/tomgp/c99a699587b5c5465228 + +function render_markup_for_server(callback) { + var virtual_window = MG.virtual_window; + var virtual_d3 = d3.select(virtual_window.document); + var target = virtual_window.document.createElement('div'); + + var original_d3 = global.d3; + var original_window = global.window; + var original_document = global.document; + global.d3 = virtual_d3; + global.window = virtual_window; + global.document = virtual_window.document; + + var error; + try { + callback(target); + } catch(e) { + error = e; + } + + global.d3 = original_d3; + global.window = original_window; + global.document = original_document; + + if (error) { + throw error; + } + + /* for some reason d3.select parses jsdom elements incorrectly + * but it works if we wrap the element in a function. + */ + return virtual_d3.select(function targetFn() { + return target; + }).html(); +} + +function render_markup_for_client(callback) { + var target = document.createElement('div'); + callback(target); + return d3.select(target).html(); +} + +function render_markup(callback) { + switch(typeof window) { + case 'undefined': + return render_markup_for_server(callback); + default: + return render_markup_for_client(callback); + } +} + +function init_virtual_window(jsdom, force) { + if (MG.virtual_window && !force) { + return; + } + + var doc = jsdom.jsdom({ + html: '', + features: { QuerySelector: true } + }); + MG.virtual_window = doc.defaultView; +} + +MG.render_markup = render_markup; +MG.init_virtual_window = init_virtual_window; diff --git a/priv/static/js/metricsgraphics/misc/process.js b/priv/static/js/metricsgraphics/misc/process.js new file mode 100644 index 0000000..d0d312d --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/process.js @@ -0,0 +1,368 @@ +function mg_process_scale_ticks(args, axis) { + var accessor; + var scale_ticks; + var max; + + if (axis === 'x') { + accessor = args.x_accessor; + scale_ticks = args.scales.X.ticks(args.xax_count); + max = args.processed.max_x; + } else if (axis === 'y') { + accessor = args.y_accessor; + scale_ticks = args.scales.Y.ticks(args.yax_count); + max = args.processed.max_y; + } + + function log10(val) { + if (val === 1000) { + return 3; + } + if (val === 1000000) { + return 7; + } + return Math.log(val) / Math.LN10; + } + + if ((axis === 'x' && args.x_scale_type === 'log') || (axis === 'y' && args.y_scale_type === 'log')) { + // get out only whole logs + scale_ticks = scale_ticks.filter(function(d) { + return Math.abs(log10(d)) % 1 < 1e-6 || Math.abs(log10(d)) % 1 > 1 - 1e-6; + }); + } + + // filter out fraction ticks if our data is ints and if xmax > number of generated ticks + var number_of_ticks = scale_ticks.length; + + // is our data object all ints? + var data_is_int = true; + args.data.forEach(function(d, i) { + d.forEach(function(d, i) { + if (d[accessor] % 1 !== 0) { + data_is_int = false; + return false; + } + }); + }); + + if (data_is_int && number_of_ticks > max && args.format === 'count') { + // remove non-integer ticks + scale_ticks = scale_ticks.filter(function(d) { + return d % 1 === 0; + }); + } + + if (axis === 'x') { + args.processed.x_ticks = scale_ticks; + } else if (axis === 'y') { + args.processed.y_ticks = scale_ticks; + } +} + +function raw_data_transformation(args) { + 'use strict'; + + // dupe our data so we can modify it without adverse effect + args.data = MG.clone(args.data); + + // we need to account for a few data format cases: + // #0 {bar1:___, bar2:___} // single object (for, say, bar charts) + // #1 [{key:__, value:__}, ...] // unnested obj-arrays + // #2 [[{key:__, value:__}, ...], [{key:__, value:__}, ...]] // nested obj-arrays + // #3 [[4323, 2343],..] // unnested 2d array + // #4 [[[4323, 2343],..] , [[4323, 2343],..]] // nested 2d array + args.single_object = false; // for bar charts. + args.array_of_objects = false; + args.array_of_arrays = false; + args.nested_array_of_arrays = false; + args.nested_array_of_objects = false; + + // is the data object a nested array? + + if (is_array_of_arrays(args.data)) { + args.nested_array_of_objects = args.data.map(function(d) { + return is_array_of_objects_or_empty(d); + }); // Case #2 + args.nested_array_of_arrays = args.data.map(function(d) { + return is_array_of_arrays(d); + }); // Case #4 + } else { + args.array_of_objects = is_array_of_objects(args.data); // Case #1 + args.array_of_arrays = is_array_of_arrays(args.data); // Case #3 + } + + if (args.chart_type === 'line') { + if (args.array_of_objects || args.array_of_arrays) { + args.data = [args.data]; + } + } else { + if (!(mg_is_array(args.data[0]))) { + args.data = [args.data]; + } + } + // if the y_accessor is an array, break it up and store the result in args.data + mg_process_multiple_x_accessors(args); + mg_process_multiple_y_accessors(args); + + // if user supplies keyword in args.color, change to arg.colors. + // this is so that the API remains fairly sensible and legible. + if (args.color !== undefined) { + args.colors = args.color; + } + + // if user has supplied args.colors, and that value is a string, turn it into an array. + if (args.colors !== null && typeof args.colors === 'string') { + args.colors = [args.colors]; + } + + // sort x-axis data + if (args.chart_type === 'line' && args.x_sort === true) { + for (var i = 0; i < args.data.length; i++) { + args.data[i].sort(function(a, b) { + return a[args.x_accessor] - b[args.x_accessor]; + }); + } + } + + return this; +} + +function mg_process_multiple_accessors(args, which_accessor) { + // turns an array of accessors into ... + if (mg_is_array(args[which_accessor])) { + args.data = args.data.map(function(_d) { + return args[which_accessor].map(function(ya) { + return _d.map(function(di) { + di = MG.clone(di); + + if (di[ya] === undefined) { + return undefined; + } + + di['multiline_' + which_accessor] = di[ya]; + return di; + }).filter(function(di) { + return di !== undefined; + }); + }); + })[0]; + args[which_accessor] = 'multiline_' + which_accessor; + } +} + +function mg_process_multiple_x_accessors(args) { + mg_process_multiple_accessors(args, 'x_accessor'); +} + +function mg_process_multiple_y_accessors(args) { + mg_process_multiple_accessors(args, 'y_accessor'); +} + +MG.raw_data_transformation = raw_data_transformation; + +function process_line(args) { + 'use strict'; + + var time_frame; + + // do we have a time-series? + var is_time_series = d3.sum(args.data.map(function(series) { + return series.length > 0 && mg_is_date(series[0][args.x_accessor]); + })) > 0; + + // are we replacing missing y values with zeros? + if ((args.missing_is_zero || args.missing_is_hidden) && args.chart_type === 'line' && is_time_series) { + for (var i = 0; i < args.data.length; i++) { + // we need to have a dataset of length > 2, so if it's less than that, skip + if (args.data[i].length <= 1) { + continue; + } + + var first = args.data[i][0]; + var last = args.data[i][args.data[i].length - 1]; + + // initialize our new array for storing the processed data + var processed_data = []; + + // we'll be starting from the day after our first date + var start_date = MG.clone(first[args.x_accessor]).setDate(first[args.x_accessor].getDate() + 1); + + // if we've set a max_x, add data points up to there + var from = (args.min_x) ? args.min_x : start_date; + var upto = (args.max_x) ? args.max_x : last[args.x_accessor]; + + time_frame = mg_get_time_frame((upto - from) / 1000); + + if (['four-days', 'many-days', 'many-months', 'years', 'default'].indexOf(time_frame) !== -1 && args.missing_is_hidden_accessor === null) { + for (var d = new Date(from); d <= upto; d.setDate(d.getDate() + 1)) { + var o = {}; + d.setHours(0, 0, 0, 0); + + // add the first date item, we'll be starting from the day after our first date + if (Date.parse(d) === Date.parse(new Date(start_date))) { + processed_data.push(MG.clone(args.data[i][0])); + } + + // check to see if we already have this date in our data object + var existing_o = null; + args.data[i].forEach(function(val, i) { + if (Date.parse(val[args.x_accessor]) === Date.parse(new Date(d))) { + existing_o = val; + + return false; + } + }); + + // if we don't have this date in our data object, add it and set it to zero + if (!existing_o) { + o[args.x_accessor] = new Date(d); + o[args.y_accessor] = 0; + o['_missing'] = true; //we want to distinguish between zero-value and missing observations + processed_data.push(o); + } + + // if the data point has, say, a 'missing' attribute set or if its + // y-value is null identify it internally as missing + else if (existing_o[args.missing_is_hidden_accessor] || existing_o[args.y_accessor] === null) { + existing_o['_missing'] = true; + processed_data.push(existing_o); + } + + //otherwise, use the existing object for that date + else { + processed_data.push(existing_o); + } + } + } else { + for (var j = 0; j < args.data[i].length; j += 1) { + var obj = MG.clone(args.data[i][j]); + obj['_missing'] = args.data[i][j][args.missing_is_hidden_accessor]; + processed_data.push(obj); + } + } + + // update our date object + args.data[i] = processed_data; + } + } + + return this; +} + +MG.process_line = process_line; + +function process_histogram(args) { + 'use strict'; + + // if args.binned == false, then we need to bin the data appropriately. + // if args.binned == true, then we need to make sure to compute the relevant computed data. + // the outcome of either of these should be something in args.computed_data. + // the histogram plotting function will be looking there for the data to plot. + + // we need to compute an array of objects. + // each object has an x, y, and dx. + + // histogram data is always single dimension + var our_data = args.data[0]; + + var extracted_data; + if (args.binned === false) { + // use d3's built-in layout.histogram functionality to compute what you need. + + if (typeof(our_data[0]) === 'object') { + // we are dealing with an array of objects. Extract the data value of interest. + extracted_data = our_data + .map(function(d) { + return d[args.x_accessor]; + }); + } else if (typeof(our_data[0]) === 'number') { + // we are dealing with a simple array of numbers. No extraction needed. + extracted_data = our_data; + } else { + console.log('TypeError: expected an array of numbers, found ' + typeof(our_data[0])); + return; + } + + var hist = d3.histogram(); + if (args.bins) { + hist.thresholds(args.bins); + } + + var bins = hist(extracted_data); + args.processed_data = bins.map(function(d) { + return { 'x': d.x0, 'y': d.length }; + }); + } else { + // here, we just need to reconstruct the array of objects + // take the x accessor and y accessor. + // pull the data as x and y. y is count. + + args.processed_data = our_data.map(function(d) { + return { 'x': d[args.x_accessor], 'y': d[args.y_accessor] }; + }); + + var this_pt; + var next_pt; + + // we still need to compute the dx component for each data point + for (var i = 0; i < args.processed_data.length; i++) { + this_pt = args.processed_data[i]; + if (i === args.processed_data.length - 1) { + this_pt.dx = args.processed_data[i - 1].dx; + } else { + next_pt = args.processed_data[i + 1]; + this_pt.dx = next_pt.x - this_pt.x; + } + } + } + + // capture the original data and accessors before replacing args.data + if (!args.processed) { + args.processed = {}; + } + args.processed.original_data = args.data; + args.processed.original_x_accessor = args.x_accessor; + args.processed.original_y_accessor = args.y_accessor; + + args.data = [args.processed_data]; + args.x_accessor = args.processed_x_accessor; + args.y_accessor = args.processed_y_accessor; + + return this; +} + +MG.process_histogram = process_histogram; + +// for use with bar charts, etc. +function process_categorical_variables(args) { + 'use strict'; + + var extracted_data, processed_data = {}, + pd = []; + //var our_data = args.data[0]; + var label_accessor = args.bar_orientation === 'vertical' ? args.x_accessor : args.y_accessor; + var data_accessor = args.bar_orientation === 'vertical' ? args.y_accessor : args.x_accessor; + + return this; +} + +MG.process_categorical_variables = process_categorical_variables; + +function process_point(args) { + 'use strict'; + + var data = args.data[0]; + var x = data.map(function(d) { + return d[args.x_accessor]; + }); + var y = data.map(function(d) { + return d[args.y_accessor]; + }); + + if (args.least_squares) { + args.ls_line = least_squares(x, y); + } + + return this; +} + +MG.process_point = process_point; diff --git a/priv/static/js/metricsgraphics/misc/smoothers.js b/priv/static/js/metricsgraphics/misc/smoothers.js new file mode 100644 index 0000000..aab8a00 --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/smoothers.js @@ -0,0 +1,280 @@ +function add_ls(args) { + var svg = mg_get_svg_child_of(args.target); + var data = args.data[0]; + var min_x = d3.min(data, function(d) { + return d[args.x_accessor]; }); + var max_x = d3.max(data, function(d) { + return d[args.x_accessor]; }); + + d3.select(args.target).selectAll('.mg-least-squares-line').remove(); + + svg.append('svg:line') + .attr('x1', args.scales.X(min_x)) + .attr('x2', args.scales.X(max_x)) + .attr('y1', args.scales.Y(args.ls_line.fit(min_x))) + .attr('y2', args.scales.Y(args.ls_line.fit(max_x))) + .attr('class', 'mg-least-squares-line'); +} + +MG.add_ls = add_ls; + +function add_lowess(args) { + var svg = mg_get_svg_child_of(args.target); + var lowess = args.lowess_line; + + var line = d3.svg.line() + .x(function(d) { + return args.scales.X(d.x); }) + .y(function(d) { + return args.scales.Y(d.y); }) + .interpolate(args.interpolate); + + svg.append('path') + .attr('d', line(lowess)) + .attr('class', 'mg-lowess-line'); +} + +MG.add_lowess = add_lowess; + +function lowess_robust(x, y, alpha, inc) { + // Used http://www.unc.edu/courses/2007spring/biol/145/001/docs/lectures/Oct27.html + // for the clear explanation of robust lowess. + + // calculate the the first pass. + var _l; + var r = []; + var yhat = d3.mean(y); + var i; + for (i = 0; i < x.length; i += 1) { r.push(1); } + _l = _calculate_lowess_fit(x, y, alpha, inc, r); + var x_proto = _l.x; + var y_proto = _l.y; + + // Now, take the fit, recalculate the weights, and re-run LOWESS using r*w instead of w. + + for (i = 0; i < 100; i += 1) { + r = d3.zip(y_proto, y).map(function(yi) { + return Math.abs(yi[1] - yi[0]); + }); + + var q = d3.quantile(r.sort(), 0.5); + + r = r.map(function(ri) { + return _bisquare_weight(ri / (6 * q)); + }); + + _l = _calculate_lowess_fit(x, y, alpha, inc, r); + x_proto = _l.x; + y_proto = _l.y; + } + + return d3.zip(x_proto, y_proto).map(function(d) { + var p = {}; + p.x = d[0]; + p.y = d[1]; + return p; + }); +} + +MG.lowess_robust = lowess_robust; + +function lowess(x, y, alpha, inc) { + var r = []; + for (var i = 0; i < x.length; i += 1) { r.push(1); } + var _l = _calculate_lowess_fit(x, y, alpha, inc, r); +} + +MG.lowess = lowess; + +function least_squares(x_, y_) { + var x, y, xi, yi, + _x = 0, + _y = 0, + _xy = 0, + _xx = 0; + + var n = x_.length; + if (mg_is_date(x_[0])) { + x = x_.map(function(d) { + return d.getTime(); + }); + } else { + x = x_; + } + + if (mg_is_date(y_[0])) { + y = y_.map(function(d) { + return d.getTime(); + }); + } else { + y = y_; + } + + var xhat = d3.mean(x); + var yhat = d3.mean(y); + var numerator = 0, + denominator = 0; + + for (var i = 0; i < x.length; i++) { + xi = x[i]; + yi = y[i]; + numerator += (xi - xhat) * (yi - yhat); + denominator += (xi - xhat) * (xi - xhat); + } + + var beta = numerator / denominator; + var x0 = yhat - beta * xhat; + + return { + x0: x0, + beta: beta, + fit: function(x) { + return x0 + x * beta; + } + }; +} + +MG.least_squares = least_squares; + +function _pow_weight(u, w) { + if (u >= 0 && u <= 1) { + return Math.pow(1 - Math.pow(u, w), w); + } else { + return 0; + } +} + +function _bisquare_weight(u) { + return _pow_weight(u, 2); +} + +function _tricube_weight(u) { + return _pow_weight(u, 3); +} + +function _neighborhood_width(x0, xis) { + return Array.max(xis.map(function(xi) { + return Math.abs(x0 - xi); + })); +} + +function _manhattan(x1, x2) { + return Math.abs(x1 - x2); +} + +function _weighted_means(wxy) { + var wsum = d3.sum(wxy.map(function(wxyi) { + return wxyi.w; })); + + return { + xbar: d3.sum(wxy.map(function(wxyi) { + return wxyi.w * wxyi.x; + })) / wsum, + ybar: d3.sum(wxy.map(function(wxyi) { + return wxyi.w * wxyi.y; + })) / wsum + }; +} + +function _weighted_beta(wxy, xbar, ybar) { + var num = d3.sum(wxy.map(function(wxyi) { + return Math.pow(wxyi.w, 2) * (wxyi.x - xbar) * (wxyi.y - ybar); + })); + + var denom = d3.sum(wxy.map(function(wxyi) { + return Math.pow(wxyi.w, 2) * Math.pow(wxyi.x - xbar, 2); + })); + + return num / denom; +} + +function _weighted_least_squares(wxy) { + var ybar, xbar, beta_i, x0; + + var _wm = _weighted_means(wxy); + + xbar = _wm.xbar; + ybar = _wm.ybar; + + var beta = _weighted_beta(wxy, xbar, ybar); + + return { + beta: beta, + xbar: xbar, + ybar: ybar, + x0: ybar - beta * xbar + + }; +} + +function _calculate_lowess_fit(x, y, alpha, inc, residuals) { + // alpha - smoothing factor. 0 < alpha < 1/ + // + // + var k = Math.floor(x.length * alpha); + + var sorted_x = x.slice(); + + sorted_x.sort(function(a, b) { + if (a < b) { + return -1; } else if (a > b) { + return 1; } + + return 0; + }); + + var x_max = d3.quantile(sorted_x, 0.98); + var x_min = d3.quantile(sorted_x, 0.02); + + var xy = d3.zip(x, y, residuals).sort(); + + var size = Math.abs(x_max - x_min) / inc; + + var smallest = x_min; + var largest = x_max; + var x_proto = d3.range(smallest, largest, size); + + var xi_neighbors; + var x_i, beta_i, x0_i, delta_i, xbar, ybar; + + // for each prototype, find its fit. + var y_proto = []; + + for (var i = 0; i < x_proto.length; i += 1) { + x_i = x_proto[i]; + + // get k closest neighbors. + xi_neighbors = xy.map(function(xyi) { + return [ + Math.abs(xyi[0] - x_i), + xyi[0], + xyi[1], + xyi[2] + ]; + }).sort().slice(0, k); + + // Get the largest distance in the neighbor set. + delta_i = d3.max(xi_neighbors)[0]; + + // Prepare the weights for mean calculation and WLS. + + xi_neighbors = xi_neighbors.map(function(wxy) { + return { + w: _tricube_weight(wxy[0] / delta_i) * wxy[3], + x: wxy[1], + y: wxy[2] + }; + }); + + // Find the weighted least squares, obviously. + var _output = _weighted_least_squares(xi_neighbors); + + x0_i = _output.x0; + beta_i = _output.beta; + + // + y_proto.push(x0_i + beta_i * x_i); + } + + return { x: x_proto, y: y_proto }; +} diff --git a/priv/static/js/metricsgraphics/misc/transitions.js b/priv/static/js/metricsgraphics/misc/transitions.js new file mode 100644 index 0000000..da1e503 --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/transitions.js @@ -0,0 +1,31 @@ +// http://bl.ocks.org/mbostock/3916621 +function path_tween(d1, precision) { + return function() { + var path0 = this, + path1 = path0.cloneNode(), + n0 = path0.getTotalLength() || 0, + n1 = (path1.setAttribute("d", d1), path1).getTotalLength() || 0; + + // Uniform sampling of distance based on specified precision. + var distances = [0], + i = 0, + dt = precision / Math.max(n0, n1); + while ((i += dt) < 1) distances.push(i); + distances.push(1); + + // Compute point-interpolators at each distance. + var points = distances.map(function(t) { + var p0 = path0.getPointAtLength(t * n0), + p1 = path1.getPointAtLength(t * n1); + return d3.interpolate([p0.x, p0.y], [p1.x, p1.y]); + }); + + return function(t) { + return t < 1 ? "M" + points.map(function(p) { + return p(t); + }).join("L") : d1; + }; + }; +} + +MG.path_tween = path_tween; diff --git a/priv/static/js/metricsgraphics/misc/utility.js b/priv/static/js/metricsgraphics/misc/utility.js new file mode 100644 index 0000000..f68327b --- /dev/null +++ b/priv/static/js/metricsgraphics/misc/utility.js @@ -0,0 +1,619 @@ +//a set of helper functions, some that we've written, others that we've borrowed + +MG.convert = {}; + +MG.convert.date = function(data, accessor, time_format) { + time_format = (typeof time_format === "undefined") ? '%Y-%m-%d' : time_format; + var parse_time = d3.timeParse(time_format); + data = data.map(function(d) { + d[accessor] = parse_time(d[accessor].trim()); + return d; + }); + + return data; +}; + +MG.convert.number = function(data, accessor) { + data = data.map(function(d) { + d[accessor] = Number(d[accessor]); + return d; + }); + + return data; +}; + +MG.time_format = function(utc, specifier) { + return utc ? d3.utcFormat(specifier) : d3.timeFormat(specifier); +}; + +function mg_jquery_exists() { + if (typeof jQuery !== 'undefined' || typeof $ !== 'undefined') { + return true; + } else { + return false; + } +} + +function mg_get_rollover_time_format(args) { + // if a rollover time format is defined, use that + if (args.rollover_time_format) { + return MG.time_format(args.utc_time, args.rollover_time_format); + } + + switch (args.processed.x_time_frame) { + case 'millis': + return MG.time_format(args.utc_time, '%b %e, %Y %H:%M:%S.%L'); + case 'seconds': + return MG.time_format(args.utc_time, '%b %e, %Y %H:%M:%S'); + case 'less-than-a-day': + return MG.time_format(args.utc_time, '%b %e, %Y %I:%M%p'); + case 'four-days': + return MG.time_format(args.utc_time, '%b %e, %Y %I:%M%p'); + } + + // default + return MG.time_format(args.utc_time, '%b %e, %Y'); +} + +function mg_data_in_plot_bounds(datum, args) { + return datum[args.x_accessor] >= args.processed.min_x && + datum[args.x_accessor] <= args.processed.max_x && + datum[args.y_accessor] >= args.processed.min_y && + datum[args.y_accessor] <= args.processed.max_y; +} + +function is_array(thing) { + return Object.prototype.toString.call(thing) === '[object Array]'; +} + +function is_function(thing) { + return Object.prototype.toString.call(thing) === '[object Function]'; +} + +function is_empty_array(thing) { + return is_array(thing) && thing.length === 0; +} + +function is_object(thing) { + return Object.prototype.toString.call(thing) === '[object Object]'; +} + +function is_array_of_arrays(data) { + var all_elements = data.map(function(d) { + return is_array(d) === true && d.length > 0; + }); + + return d3.sum(all_elements) === data.length; +} + +function is_array_of_objects(data) { + // is every element of data an object? + var all_elements = data.map(function(d) { + return is_object(d) === true; + }); + + return d3.sum(all_elements) === data.length; +} + +function is_array_of_objects_or_empty(data) { + return is_empty_array(data) || is_array_of_objects(data); +} + +function pluck(arr, accessor) { + return arr.map(function(d) { + return d[accessor]; }); +} + +function count_array_elements(arr) { + return arr.reduce(function(a, b) { a[b] = a[b] + 1 || 1; + return a; }, {}); +} + +function mg_get_bottom(args) { + return args.height - args.bottom; +} + +function mg_get_plot_bottom(args) { + // returns the pixel location of the bottom side of the plot area. + return mg_get_bottom(args) - args.buffer; +} + +function mg_get_top(args) { + return args.top; +} + +function mg_get_plot_top(args) { + // returns the pixel location of the top side of the plot area. + return mg_get_top(args) + args.buffer; +} + +function mg_get_left(args) { + return args.left; +} + +function mg_get_plot_left(args) { + // returns the pixel location of the left side of the plot area. + return mg_get_left(args) + args.buffer; +} + +function mg_get_right(args) { + return args.width - args.right; +} + +function mg_get_plot_right(args) { + // returns the pixel location of the right side of the plot area. + return mg_get_right(args) - args.buffer; +} + +//////// adding elements, removing elements ///////////// + +function mg_exit_and_remove(elem) { + elem.exit().remove(); +} + +function mg_selectAll_and_remove(svg, cl) { + svg.selectAll(cl).remove(); +} + +function mg_add_g(svg, cl) { + return svg.append('g').classed(cl, true); +} + +function mg_remove_element(svg, elem) { + svg.select(elem).remove(); +} + +//////// axis helper functions //////////// + +function mg_make_rug(args, rug_class) { + var svg = mg_get_svg_child_of(args.target); + var all_data = mg_flatten_array(args.data); + var rug = svg.selectAll('line.' + rug_class).data(all_data); + + rug.enter() + .append('line') + .attr('class', rug_class) + .attr('opacity', 0.3); + + //remove rug elements that are no longer in use + mg_exit_and_remove(rug); + + //set coordinates of new rug elements + mg_exit_and_remove(rug); + return rug; +} + +function mg_add_color_accessor_to_rug(rug, args, rug_mono_class) { + if (args.color_accessor) { + rug.attr('stroke', args.scalefns.colorf); + rug.classed(rug_mono_class, false); + } else { + rug.attr('stroke', null); + rug.classed(rug_mono_class, true); + } +} + +function mg_rotate_labels(labels, rotation_degree) { + if (rotation_degree) { + labels.attr({ + dy: 0, + transform: function() { + var elem = d3.select(this); + return 'rotate(' + rotation_degree + ' ' + elem.attr('x') + ',' + elem.attr('y') + ')'; + } + }); + } +} + +////////////////////////////////////////////////// + +function mg_elements_are_overlapping(labels) { + labels = labels.node(); + if (!labels) { + return false; + } + + for (var i = 0; i < labels.length; i++) { + if (mg_is_horizontally_overlapping(labels[i], labels)) return true; + } + + return false; +} + +function mg_prevent_horizontal_overlap(labels, args) { + if (!labels || labels.length == 1) { + return; + } + + //see if each of our labels overlaps any of the other labels + for (var i = 0; i < labels.length; i++) { + //if so, nudge it up a bit, if the label it intersects hasn't already been nudged + if (mg_is_horizontally_overlapping(labels[i], labels)) { + var node = d3.select(labels[i]); + var newY = +node.attr('y'); + if (newY + 8 >= args.top) { + newY = args.top - 16; + } + node.attr('y', newY); + } + } +} + +function mg_prevent_vertical_overlap(labels, args) { + if (!labels || labels.length == 1) { + return; + } + + labels.sort(function(b, a) { + return d3.select(a).attr('y') - d3.select(b).attr('y'); + }); + + labels.reverse(); + + var overlap_amount, label_i, label_j; + + //see if each of our labels overlaps any of the other labels + for (var i = 0; i < labels.length; i++) { + //if so, nudge it up a bit, if the label it intersects hasn't already been nudged + label_i = d3.select(labels[i]).text(); + + for (var j = 0; j < labels.length; j++) { + label_j = d3.select(labels[j]).text(); + overlap_amount = mg_is_vertically_overlapping(labels[i], labels[j]); + + if (overlap_amount !== false && label_i !== label_j) { + var node = d3.select(labels[i]); + var newY = +node.attr('y'); + newY = newY + overlap_amount; + node.attr('y', newY); + } + } + } +} + +function mg_is_vertically_overlapping(element, sibling) { + var element_bbox = element.getBoundingClientRect(); + var sibling_bbox = sibling.getBoundingClientRect(); + + if (element_bbox.top <= sibling_bbox.bottom && element_bbox.top >= sibling_bbox.top) { + return sibling_bbox.bottom - element_bbox.top; + } + + return false; +} + +function mg_is_horiz_overlap(element, sibling) { + var element_bbox = element.getBoundingClientRect(); + var sibling_bbox = sibling.getBoundingClientRect(); + + if (element_bbox.right >= sibling_bbox.left || element_bbox.top >= sibling_bbox.top) { + return sibling_bbox.bottom - element_bbox.top; + } + return false; +} + +function mg_is_horizontally_overlapping(element, labels) { + var element_bbox = element.getBoundingClientRect(); + + for (var i = 0; i < labels.length; i++) { + if (labels[i] == element) { + continue; + } + + //check to see if this label overlaps with any of the other labels + var sibling_bbox = labels[i].getBoundingClientRect(); + if (element_bbox.top === sibling_bbox.top && + !(sibling_bbox.left > element_bbox.right || sibling_bbox.right < element_bbox.left) + ) { + return true; + } + } + + return false; +} + +function mg_infer_type(args, ns) { + // must return categorical or numerical. + var testPoint = mg_flatten_array(args.data); + + testPoint = testPoint[0][args[ns + '_accessor']]; + return typeof testPoint === 'string' ? 'categorical' : 'numerical'; + } + +function mg_get_svg_child_of(selector_or_node) { + return d3.select(selector_or_node).select('svg'); +} + +function mg_flatten_array(arr) { + var flat_data = []; + return flat_data.concat.apply(flat_data, arr); +} + +function mg_next_id() { + if (typeof MG._next_elem_id === 'undefined') { + MG._next_elem_id = 0; + } + + return 'mg-' + (MG._next_elem_id++); +} + +function mg_target_ref(target) { + if (typeof target === 'string') { + return mg_normalize(target); + + } else if (target instanceof window.HTMLElement) { + var target_ref = target.getAttribute('data-mg-uid'); + if (!target_ref) { + target_ref = mg_next_id(); + target.setAttribute('data-mg-uid', target_ref); + } + + return target_ref; + + } else { + console.warn('The specified target should be a string or an HTMLElement.', target); + return mg_normalize(target); + } +} + +function mg_normalize(string) { + return string + .replace(/[^a-zA-Z0-9 _-]+/g, '') + .replace(/ +?/g, ''); +} + +function get_pixel_dimension(target, dimension) { + return Number(d3.select(target).style(dimension).replace(/px/g, '')); +} + +function get_width(target) { + return get_pixel_dimension(target, 'width'); +} + +function get_height(target) { + return get_pixel_dimension(target, 'height'); +} + +function isNumeric(n) { + return !isNaN(parseFloat(n)) && isFinite(n); +} + +var each = function(obj, iterator, context) { + // yanked out of underscore + var breaker = {}; + if (obj === null) return obj; + if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, length = obj.length; i < length; i++) { + if (iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var k in obj) { + if (iterator.call(context, obj[k], k, obj) === breaker) return; + } + } + + return obj; +}; + +function merge_with_defaults(obj) { + // taken from underscore + each(Array.prototype.slice.call(arguments, 1), function(source) { + if (source) { + for (var prop in source) { + if (obj[prop] === void 0) obj[prop] = source[prop]; + } + } + }); + + return obj; +} + +MG.merge_with_defaults = merge_with_defaults; + +function options_to_defaults(obj) { + return Object.keys(obj).reduce((r, k) => { + r[k] = obj[k][0]; + return r; + }, {}); +} + +function compare_type(type, value) { + if (value == null) return true; // allow null or undefined + if (typeof type === 'string') { + if (type.substr(-2) === '[]') { + if (!is_array(value)) return false; + return value.every(i => compare_type(type.slice(0, -2), i)); + } + return typeof value === type + || value === type + || type.length === 0 + || type === 'array' && is_array(value); + } + if (typeof type === 'function') return value === type || value instanceof type; + return is_array(type) && !!~type.findIndex(i => compare_type(i, value)); +} + +function mg_validate_option(key, value) { + if (!is_array(MG.options[key])) return false; // non-existent option + const typeDef = MG.options[key][1]; + if (!typeDef) return true; // not restricted type + return compare_type(typeDef, value); +} + +function number_of_values(data, accessor, value) { + var values = data.filter(function(d) { + return d[accessor] === value; + }); + + return values.length; +} + +function has_values_below(data, accessor, value) { + var values = data.filter(function(d) { + return d[accessor] <= value; + }); + + return values.length > 0; +} + +function has_too_many_zeros(data, accessor, zero_count) { + return number_of_values(data, accessor, 0) >= zero_count; +} + +function mg_is_date(obj) { + return Object.prototype.toString.call(obj) === '[object Date]'; +} + +function mg_is_object(obj) { + return Object.prototype.toString.call(obj) === '[object Object]'; +} + +function mg_is_array(obj) { + if (Array.isArray) { + return Array.isArray(obj); + } + + return Object.prototype.toString.call(obj) === '[object Array]'; +} + +function mg_is_function(obj) { + return Object.prototype.toString.call(obj) === '[object Function]'; +} + +// deep copy +// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object +MG.clone = function(obj) { + var copy; + + // Handle the 3 simple types, and null or undefined + if (null === obj || "object" !== typeof obj) return obj; + + // Handle Date + if (mg_is_date(obj)) { + copy = new Date(); + copy.setTime(obj.getTime()); + return copy; + } + + // Handle Array + if (mg_is_array(obj)) { + copy = []; + for (var i = 0, len = obj.length; i < len; i++) { + copy[i] = MG.clone(obj[i]); + } + return copy; + } + + // Handle Object + if (mg_is_object(obj)) { + copy = {}; + for (var attr in obj) { + if (obj.hasOwnProperty(attr)) copy[attr] = MG.clone(obj[attr]); + } + return copy; + } + + throw new Error("Unable to copy obj! Its type isn't supported."); +}; + +// give us the difference of two int arrays +// http://radu.cotescu.com/javascript-diff-function/ +function arr_diff(a, b) { + var seen = [], + diff = [], + i; + for (i = 0; i < b.length; i++) + seen[b[i]] = true; + for (i = 0; i < a.length; i++) + if (!seen[a[i]]) + diff.push(a[i]); + return diff; +} + +MG.arr_diff = arr_diff; + +/** + Print warning message to the console when a feature has been scheduled for removal + + @author Dan de Havilland (github.com/dandehavilland) + @date 2014-12 +*/ +function warn_deprecation(message, untilVersion) { + console.warn('Deprecation: ' + message + (untilVersion ? '. This feature will be removed in ' + untilVersion + '.' : ' the near future.')); + console.trace(); +} + +MG.warn_deprecation = warn_deprecation; + +/** + Truncate a string to fit within an SVG text node + CSS text-overlow doesn't apply to SVG <= 1.2 + + @author Dan de Havilland (github.com/dandehavilland) + @date 2014-12-02 +*/ +function truncate_text(textObj, textString, width) { + var bbox, + position = 0; + + textObj.textContent = textString; + bbox = textObj.getBBox(); + + while (bbox.width > width) { + textObj.textContent = textString.slice(0, --position) + '...'; + bbox = textObj.getBBox(); + + if (textObj.textContent === '...') { + break; + } + } +} + +MG.truncate_text = truncate_text; + +/** + Wrap the contents of a text node to a specific width + + Adapted from bl.ocks.org/mbostock/7555321 + + @author Mike Bostock + @author Dan de Havilland + @date 2015-01-14 +*/ +function wrap_text(text, width, token, tspanAttrs) { + text.each(function() { + var text = d3.select(this), + words = text.text().split(token || /\s+/).reverse(), + word, + line = [], + lineNumber = 0, + lineHeight = 1.1, // ems + y = text.attr("y"), + dy = 0, + tspan = text.text(null) + .append("tspan") + .attr("x", 0) + .attr("y", dy + "em") + .attr(tspanAttrs || {}); + + while (!!(word = words.pop())) { + line.push(word); + tspan.text(line.join(" ")); + if (width === null || tspan.node().getComputedTextLength() > width) { + line.pop(); + tspan.text(line.join(" ")); + line = [word]; + tspan = text + .append("tspan") + .attr("x", 0) + .attr("y", ++lineNumber * lineHeight + dy + "em") + .attr(tspanAttrs || {}) + .text(word); + } + } + }); +} + +MG.wrap_text = wrap_text; |