From a213c01d518cfe7f7b73245af69b4e5e4293f0c8 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 12 Jul 2021 10:17:06 -0400 Subject: [PATCH 1/6] remove minified bundle - not used in plotly.js - simplifies build --- .gitattributes | 1 - CONTRIBUTING.md | 2 +- d3.min.js | 4 ---- package.json | 4 ++-- test/arrays/min-test.js | 51 ----------------------------------------- 5 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 d3.min.js delete mode 100644 test/arrays/min-test.js diff --git a/.gitattributes b/.gitattributes index f19c7a9e9be6a5..eab783da7bee07 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ d3.js -diff merge=ours -d3.min.js -diff merge=ours diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ced343e04b265..89a33e2da0b926 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ To contribute new documentation or add examples to the gallery, just [edit the W 3. Create a new branch for your new feature. For example: `git checkout -b my-awesome-feature`. A dedicated branch for your pull request means you can develop multiple features at the same time, and ensures that your pull request is stable even if you later decide to develop an unrelated feature. -4. The `d3.js` and `d3.min.js` files are built from source files in the `src` directory. _Do not edit `d3.js` directly._ Instead, edit the source files, and then run `make` to build the generated files. +4. The `d3.js` file is built from source files in the `src` directory. _Do not edit `d3.js` directly._ Instead, edit the source files, and then run `make` to build the generated files. 5. Use `make test` to run tests and verify your changes. If you are adding a new feature, you should add new tests! If you are changing existing functionality, make sure the existing tests run, or update them as appropriate. diff --git a/d3.min.js b/d3.min.js deleted file mode 100644 index 8555bea1fa305c..00000000000000 --- a/d3.min.js +++ /dev/null @@ -1,4 +0,0 @@ -!function(){function n(n){return n&&(n.ownerDocument||n.document||n).documentElement}function t(n){return n&&(n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView)}function e(n,t){return t>n?-1:n>t?1:n>=t?0:NaN}function r(n){return null===n?NaN:+n}function u(n){return!isNaN(n)}function i(n){return{left:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)<0?r=i+1:u=i}return r},right:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)>0?u=i:r=i+1}return r}}}function o(n){return n.length}function a(n){for(var t=1;n*t%1;)t*=10;return t}function l(n,t){for(var e in t)Object.defineProperty(n.prototype,e,{value:t[e],enumerable:!1})}function c(){this._=Object.create(null)}function f(n){return(n+="")===ei||n[0]===ri?ri+n:n}function s(n){return(n+="")[0]===ri?n.slice(1):n}function h(n){return f(n)in this._}function g(n){return(n=f(n))in this._&&delete this._[n]}function p(){var n=[];for(var t in this._)n.push(s(t));return n}function d(){var n=0;for(var t in this._)++n;return n}function v(){for(var n in this._)return!1;return!0}function y(){this._=Object.create(null)}function m(n){return n}function x(n,t,e){return function(){var r=e.apply(t,arguments);return r===t?n:r}}function M(n,t){if(t in n)return t;t=t.charAt(0).toUpperCase()+t.slice(1);for(var e=0,r=ui.length;r>e;++e){var u=ui[e]+t;if(u in n)return u}}function _(){}function b(){}function w(n){function t(){for(var t,r=e,u=-1,i=r.length;++ue;e++)for(var u,i=n[e],o=0,a=i.length;a>o;o++)(u=i[o])&&t(u,o,e);return n}function Z(n){return oi(n,gi),n}function V(n){var t,e;return function(r,u,i){var o,a=n[i].update,l=a.length;for(i!=e&&(e=i,t=0),u>=t&&(t=u+1);!(o=a[t])&&++t0&&(n=n.slice(0,a));var c=pi.get(n);return c&&(n=c,l=B),a?t?u:r:t?_:i}function $(n,t){return function(e){var r=Iu.event;Iu.event=e,t[0]=this.__data__;try{n.apply(this,t)}finally{Iu.event=r}}}function B(n,t){var e=$(n,t);return function(n){var t=this,r=n.relatedTarget;r&&(r===t||8&r.compareDocumentPosition(t))||e.call(t,n)}}function W(e){var r=".dragsuppress-"+ ++vi,u="click"+r,i=Iu.select(t(e)).on("touchmove"+r,k).on("dragstart"+r,k).on("selectstart"+r,k);if(null==di&&(di="onselectstart"in e?!1:M(e.style,"userSelect")),di){var o=n(e).style,a=o[di];o[di]="none"}return function(n){if(i.on(r,null),di&&(o[di]=a),n){var t=function(){i.on(u,null)};i.on(u,function(){k(),t()},!0),setTimeout(t,0)}}}function J(n,e){e.changedTouches&&(e=e.changedTouches[0]);var r=n.ownerSVGElement||n;if(r.createSVGPoint){var u=r.createSVGPoint();if(0>yi){var i=t(n);if(i.scrollX||i.scrollY){r=Iu.select("body").append("svg").style({position:"absolute",top:0,left:0,margin:0,padding:0,border:"none"},"important");var o=r[0][0].getScreenCTM();yi=!(o.f||o.e),r.remove()}}return yi?(u.x=e.pageX,u.y=e.pageY):(u.x=e.clientX,u.y=e.clientY),u=u.matrixTransform(n.getScreenCTM().inverse()),[u.x,u.y]}var a=n.getBoundingClientRect();return[e.clientX-a.left-n.clientLeft,e.clientY-a.top-n.clientTop]}function G(){return Iu.event.changedTouches[0].identifier}function K(n,t,e){return(t[0]-n[0])*(e[1]-n[1])-(t[1]-n[1])*(e[0]-n[0])}function Q(n){return n>1?wi:-1>n?-wi:Math.asin(n)}function nn(n){return((n=Math.exp(n))-1/n)/2}function tn(n){return((n=Math.exp(n))+1/n)/2}function en(n){return((n=Math.exp(2*n))-1)/(n+1)}function rn(){}function un(n,t,e){return this instanceof un?(this.h=+n,this.s=+t,void(this.l=+e)):arguments.length<2?n instanceof un?new un(n.h,n.s,n.l):xn(""+n,Mn,un):new un(n,t,e)}function on(n,t,e){function r(n){return n>360?n-=360:0>n&&(n+=360),60>n?i+(o-i)*n/60:180>n?o:240>n?i+(o-i)*(240-n)/60:i}function u(n){return Math.round(255*r(n))}var i,o;return n=isNaN(n)?0:(n%=360)<0?n+360:n,t=isNaN(t)?0:0>t?0:t>1?1:t,e=0>e?0:e>1?1:e,o=.5>=e?e*(1+t):e+t-e*t,i=2*e-o,new dn(u(n+120),u(n),u(n-120))}function an(n,t,e){return this instanceof an?(this.h=+n,this.c=+t,void(this.l=+e)):arguments.length<2?n instanceof an?new an(n.h,n.c,n.l):n instanceof cn?sn(n.l,n.a,n.b):sn((n=_n((n=Iu.rgb(n)).r,n.g,n.b)).l,n.a,n.b):new an(n,t,e)}function ln(n,t,e){return isNaN(n)&&(n=0),isNaN(t)&&(t=0),new cn(e,Math.cos(n*=ki)*t,Math.sin(n)*t)}function cn(n,t,e){return this instanceof cn?(this.l=+n,this.a=+t,void(this.b=+e)):arguments.length<2?n instanceof cn?new cn(n.l,n.a,n.b):n instanceof an?ln(n.h,n.c,n.l):_n((n=dn(n)).r,n.g,n.b):new cn(n,t,e)}function fn(n,t,e){var r=(n+16)/116,u=r+t/500,i=r-e/200;return u=hn(u)*Ei,r=hn(r)*Ui,i=hn(i)*Pi,new dn(pn(3.2404542*u-1.5371385*r-.4985314*i),pn(-.969266*u+1.8760108*r+.041556*i),pn(.0556434*u-.2040259*r+1.0572252*i))}function sn(n,t,e){return n>0?new an(Math.atan2(e,t)*Ni,Math.sqrt(t*t+e*e),n):new an(NaN,NaN,n)}function hn(n){return n>.206893034?n*n*n:(n-4/29)/7.787037}function gn(n){return n>.008856?Math.pow(n,1/3):7.787037*n+4/29}function pn(n){return Math.round(255*(.00304>=n?12.92*n:1.055*Math.pow(n,1/2.4)-.055))}function dn(n,t,e){return this instanceof dn?(this.r=~~n,this.g=~~t,void(this.b=~~e)):arguments.length<2?n instanceof dn?new dn(n.r,n.g,n.b):xn(""+n,dn,on):new dn(n,t,e)}function vn(n){return new dn(n>>16,n>>8&255,255&n)}function yn(n){return vn(n)+""}function mn(n){return 16>n?"0"+Math.max(0,n).toString(16):Math.min(255,n).toString(16)}function xn(n,t,e){var r,u,i,o=0,a=0,l=0;if(r=/([a-z]+)\((.*)\)/.exec(n=n.toLowerCase()))switch(u=r[2].split(","),r[1]){case"hsl":return e(parseFloat(u[0]),parseFloat(u[1])/100,parseFloat(u[2])/100);case"rgb":return t(wn(u[0]),wn(u[1]),wn(u[2]))}return(i=Fi.get(n))?t(i.r,i.g,i.b):(null==n||"#"!==n.charAt(0)||isNaN(i=parseInt(n.slice(1),16))||(4===n.length?(o=(3840&i)>>4,o=o>>4|o,a=240&i,a=a>>4|a,l=15&i,l=l<<4|l):7===n.length&&(o=(16711680&i)>>16,a=(65280&i)>>8,l=255&i)),t(o,a,l))}function Mn(n,t,e){var r,u,i=Math.min(n/=255,t/=255,e/=255),o=Math.max(n,t,e),a=o-i,l=(o+i)/2;return a?(u=.5>l?a/(o+i):a/(2-o-i),r=n==o?(t-e)/a+(e>t?6:0):t==o?(e-n)/a+2:(n-t)/a+4,r*=60):(r=NaN,u=l>0&&1>l?0:r),new un(r,u,l)}function _n(n,t,e){n=bn(n),t=bn(t),e=bn(e);var r=gn((.4124564*n+.3575761*t+.1804375*e)/Ei),u=gn((.2126729*n+.7151522*t+.072175*e)/Ui),i=gn((.0193339*n+.119192*t+.9503041*e)/Pi);return cn(116*u-16,500*(r-u),200*(u-i))}function bn(n){return(n/=255)<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function wn(n){var t=parseFloat(n);return"%"===n.charAt(n.length-1)?Math.round(2.55*t):t}function kn(n){return"function"==typeof n?n:function(){return n}}function Nn(n){return function(t,e,r){return 2===arguments.length&&"function"==typeof e&&(r=e,e=null),An(t,e,n,r)}}function An(n,t,e,r){function u(){var n,t=l.status;if(!t&&zn(l)||t>=200&&300>t||304===t){try{n=e.call(i,l)}catch(r){return void o.error.call(i,r)}o.load.call(i,n)}else o.error.call(i,l)}var i={},o=Iu.dispatch("beforesend","progress","load","error"),a={},l=new XMLHttpRequest,c=null;return!self.XDomainRequest||"withCredentials"in l||!/^(http(s)?:)?\/\//.test(n)||(l=new XDomainRequest),"onload"in l?l.onload=l.onerror=u:l.onreadystatechange=function(){l.readyState>3&&u()},l.onprogress=function(n){var t=Iu.event;Iu.event=n;try{o.progress.call(i,l)}finally{Iu.event=t}},i.header=function(n,t){return n=(n+"").toLowerCase(),arguments.length<2?a[n]:(null==t?delete a[n]:a[n]=t+"",i)},i.mimeType=function(n){return arguments.length?(t=null==n?null:n+"",i):t},i.responseType=function(n){return arguments.length?(c=n,i):c},i.response=function(n){return e=n,i},["get","post"].forEach(function(n){i[n]=function(){return i.send.apply(i,[n].concat(Vu(arguments)))}}),i.send=function(e,r,u){if(2===arguments.length&&"function"==typeof r&&(u=r,r=null),l.open(e,n,!0),null==t||"accept"in a||(a.accept=t+",*/*"),l.setRequestHeader)for(var f in a)l.setRequestHeader(f,a[f]);return null!=t&&l.overrideMimeType&&l.overrideMimeType(t),null!=c&&(l.responseType=c),null!=u&&i.on("error",u).on("load",function(n){u(null,n)}),o.beforesend.call(i,l),l.send(null==r?null:r),i},i.abort=function(){return l.abort(),i},Iu.rebind(i,o,"on"),null==r?i:i.get(Cn(r))}function Cn(n){return 1===n.length?function(t,e){n(null==t?e:null)}:n}function zn(n){var t=n.responseType;return t&&"text"!==t?n.response:n.responseText}function Ln(n,t,e){var r=arguments.length;2>r&&(t=0),3>r&&(e=Date.now());var u=e+t,i={c:n,t:u,n:null};return Yi?Yi.n=i:Oi=i,Yi=i,Ii||(Zi=clearTimeout(Zi),Ii=1,Vi(Sn)),i}function Sn(){var n=Tn(),t=qn()-n;t>24?(isFinite(t)&&(clearTimeout(Zi),Zi=setTimeout(Sn,t)),Ii=0):(Ii=1,Vi(Sn))}function Tn(){for(var n=Date.now(),t=Oi;t;)n>=t.t&&t.c(n-t.t)&&(t.c=null),t=t.n;return n}function qn(){for(var n,t=Oi,e=1/0;t;)t.c?(t.t8?function(n){return n/e}:function(n){return n*e},symbol:n}}function En(n){var t=n.decimal,e=n.thousands,r=n.grouping,u=n.currency,i=r&&e?function(n,t){for(var u=n.length,i=[],o=0,a=r[0],l=0;u>0&&a>0&&(l+a+1>t&&(a=Math.max(1,t-l)),i.push(n.substring(u-=a,u+a)),!((l+=a+1)>t));)a=r[o=(o+1)%r.length];return i.reverse().join(e)}:m;return function(n){var e=$i.exec(n),r=e[1]||" ",o=e[2]||">",a=e[3]||"-",l=e[4]||"",c=e[5],f=+e[6],s=e[7],h=e[8],g=e[9],p=1,d="",v="",y=!1,m=!0;switch(h&&(h=+h.substring(1)),(c||"0"===r&&"="===o)&&(c=r="0",o="="),g){case"n":s=!0,g="g";break;case"%":p=100,v="%",g="f";break;case"p":p=100,v="%",g="r";break;case"b":case"o":case"x":case"X":"#"===l&&(d="0"+g.toLowerCase());case"c":m=!1;case"d":y=!0,h=0;break;case"s":p=-1,g="r"}"$"===l&&(d=u[0],v=u[1]),"r"!=g||h||(g="g"),null!=h&&("g"==g?h=Math.max(1,Math.min(21,h)):"e"!=g&&"f"!=g||(h=Math.max(0,Math.min(20,h)))),g=Bi.get(g)||Un;var x=c&&s;return function(n){var e=v;if(y&&n%1)return"";var u=0>n||0===n&&0>1/n?(n=-n,"-"):"-"===a?"":a;if(0>p){var l=Iu.formatPrefix(n,h);n=l.scale(n),e=l.symbol+v}else n*=p;n=g(n,h);var M,_,b=n.lastIndexOf(".");if(0>b){var w=m?n.lastIndexOf("e"):-1;0>w?(M=n,_=""):(M=n.substring(0,w),_=n.substring(w))}else M=n.substring(0,b),_=t+n.substring(b+1);!c&&s&&(M=i(M,1/0));var k=d.length+M.length+_.length+(x?0:u.length),N=f>k?new Array(k=f-k+1).join(r):"";return x&&(M=i(N+M,N.length?f-_.length:1/0)),u+=d,n=M+_,("<"===o?u+n+N:">"===o?N+u+n:"^"===o?N.substring(0,k>>=1)+u+n+N.substring(k):u+(x?n:N+n))+e}}}function Un(n){return n+""}function Pn(){this._=new Date(arguments.length>1?Date.UTC.apply(this,arguments):arguments[0])}function jn(n,t,e){function r(t){var e=n(t),r=i(e,1);return r-t>t-e?e:r}function u(e){return t(e=n(new Ji(e-1)),1),e}function i(n,e){return t(n=new Ji(+n),e),n}function o(n,r,i){var o=u(n),a=[];if(i>1)for(;r>o;)e(o)%i||a.push(new Date(+o)),t(o,1);else for(;r>o;)a.push(new Date(+o)),t(o,1);return a}function a(n,t,e){try{Ji=Pn;var r=new Pn;return r._=n,o(r,t,e)}finally{Ji=Date}}n.floor=n,n.round=r,n.ceil=u,n.offset=i,n.range=o;var l=n.utc=Hn(n);return l.floor=l,l.round=Hn(r),l.ceil=Hn(u),l.offset=Hn(i),l.range=a,n}function Hn(n){return function(t,e){try{Ji=Pn;var r=new Pn;return r._=t,n(r,e)._}finally{Ji=Date}}}function Fn(n){function t(n){function t(t){for(var e,u,i,o=[],a=-1,l=0;++aa;){if(r>=c)return-1;if(u=t.charCodeAt(a++),37===u){if(o=t.charAt(a++),i=L[o in Ki?t.charAt(a++):o],!i||(r=i(n,e,r))<0)return-1}else if(u!=e.charCodeAt(r++))return-1}return r}function r(n,t,e){b.lastIndex=0;var r=b.exec(t.slice(e));return r?(n.w=w.get(r[0].toLowerCase()),e+r[0].length):-1}function u(n,t,e){M.lastIndex=0;var r=M.exec(t.slice(e));return r?(n.w=_.get(r[0].toLowerCase()),e+r[0].length):-1}function i(n,t,e){A.lastIndex=0;var r=A.exec(t.slice(e));return r?(n.m=C.get(r[0].toLowerCase()),e+r[0].length):-1}function o(n,t,e){k.lastIndex=0;var r=k.exec(t.slice(e));return r?(n.m=N.get(r[0].toLowerCase()),e+r[0].length):-1}function a(n,t,r){return e(n,z.c.toString(),t,r)}function l(n,t,r){return e(n,z.x.toString(),t,r)}function c(n,t,r){return e(n,z.X.toString(),t,r)}function f(n,t,e){var r=x.get(t.slice(e,e+=2).toLowerCase());return null==r?-1:(n.p=r,e)}var s=n.dateTime,h=n.date,g=n.time,p=n.periods,d=n.days,v=n.shortDays,y=n.months,m=n.shortMonths;t.utc=function(n){function e(n){try{Ji=Pn;var t=new Ji;return t._=n,r(t)}finally{Ji=Date}}var r=t(n);return e.parse=function(n){try{Ji=Pn;var t=r.parse(n);return t&&t._}finally{Ji=Date}},e.toString=r.toString,e},t.multi=t.utc.multi=ot;var x=Iu.map(),M=Yn(d),_=In(d),b=Yn(v),w=In(v),k=Yn(y),N=In(y),A=Yn(m),C=In(m);p.forEach(function(n,t){x.set(n.toLowerCase(),t)});var z={a:function(n){return v[n.getDay()]},A:function(n){return d[n.getDay()]},b:function(n){return m[n.getMonth()]},B:function(n){return y[n.getMonth()]},c:t(s),d:function(n,t){return On(n.getDate(),t,2)},e:function(n,t){return On(n.getDate(),t,2)},H:function(n,t){return On(n.getHours(),t,2)},I:function(n,t){return On(n.getHours()%12||12,t,2)},j:function(n,t){return On(1+Wi.dayOfYear(n),t,3)},L:function(n,t){return On(n.getMilliseconds(),t,3)},m:function(n,t){return On(n.getMonth()+1,t,2)},M:function(n,t){return On(n.getMinutes(),t,2)},p:function(n){return p[+(n.getHours()>=12)]},S:function(n,t){return On(n.getSeconds(),t,2)},U:function(n,t){return On(Wi.sundayOfYear(n),t,2)},w:function(n){return n.getDay()},W:function(n,t){return On(Wi.mondayOfYear(n),t,2)},x:t(h),X:t(g),y:function(n,t){return On(n.getFullYear()%100,t,2)},Y:function(n,t){return On(n.getFullYear()%1e4,t,4)},Z:ut,"%":function(){return"%"}},L={a:r,A:u,b:i,B:o,c:a,d:Kn,e:Kn,H:nt,I:nt,j:Qn,L:rt,m:Gn,M:tt,p:f,S:et,U:Vn,w:Zn,W:Xn,x:l,X:c,y:Bn,Y:$n,Z:Wn,"%":it};return t}function On(n,t,e){var r=0>n?"-":"",u=(r?-n:n)+"",i=u.length;return r+(e>i?new Array(e-i+1).join(t)+u:u)}function Yn(n){return new RegExp("^(?:"+n.map(Iu.requote).join("|")+")","i")}function In(n){for(var t=new c,e=-1,r=n.length;++e68?1900:2e3)}function Gn(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+2));return r?(n.m=r[0]-1,e+r[0].length):-1}function Kn(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+2));return r?(n.d=+r[0],e+r[0].length):-1}function Qn(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+3));return r?(n.j=+r[0],e+r[0].length):-1}function nt(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+2));return r?(n.H=+r[0],e+r[0].length):-1}function tt(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+2));return r?(n.M=+r[0],e+r[0].length):-1}function et(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+2));return r?(n.S=+r[0],e+r[0].length):-1}function rt(n,t,e){Qi.lastIndex=0;var r=Qi.exec(t.slice(e,e+3));return r?(n.L=+r[0],e+r[0].length):-1}function ut(n){var t=n.getTimezoneOffset(),e=t>0?"-":"+",r=ti(t)/60|0,u=ti(t)%60;return e+On(r,"0",2)+On(u,"0",2)}function it(n,t,e){no.lastIndex=0;var r=no.exec(t.slice(e,e+1));return r?e+r[0].length:-1}function ot(n){for(var t=n.length,e=-1;++eu;u++){for(;r>1&&K(n[e[r-2]],n[e[r-1]],n[u])<=0;)--r;e[r++]=u}return e.slice(0,r)}function ft(n,t){return n[0]-t[0]||n[1]-t[1]}function st(n,t,e){return(e[0]-t[0])*(n[1]-t[1])<(e[1]-t[1])*(n[0]-t[0])}function ht(n,t,e,r){var u=n[0],i=e[0],o=t[0]-u,a=r[0]-i,l=n[1],c=e[1],f=t[1]-l,s=r[1]-c,h=(a*(l-c)-s*(u-i))/(s*o-a*f);return[u+h*o,l+h*f]}function gt(n){var t=n[0],e=n[n.length-1];return!(t[0]-e[0]||t[1]-e[1])}function pt(){Ut(this),this.edge=this.site=this.circle=null}function dt(n){var t=lo.pop()||new pt;return t.site=n,t}function vt(n){At(n),io.remove(n),lo.push(n),Ut(n)}function yt(n){var t=n.circle,e=t.x,r=t.cy,u={x:e,y:r},i=n.P,o=n.N,a=[n];vt(n);for(var l=i;l.circle&&ti(e-l.circle.x)f;++f)c=a[f],l=a[f-1],Dt(c.edge,l.site,c.site,u);l=a[0],c=a[s-1],c.edge=Tt(l.site,c.site,null,u),Nt(l),Nt(c)}function mt(n){for(var t,e,r,u,i=n.x,o=n.y,a=io._;a;)if(r=xt(a,o)-i,r>mi)a=a.L;else{if(u=i-Mt(a,o),!(u>mi)){r>-mi?(t=a.P,e=a):u>-mi?(t=a,e=a.N):t=e=a;break}if(!a.R){t=a;break}a=a.R}var l=dt(n);if(io.insert(t,l),t||e){if(t===e)return At(t),e=dt(t.site),io.insert(l,e),l.edge=e.edge=Tt(t.site,l.site),Nt(t),void Nt(e);if(!e)return void(l.edge=Tt(t.site,l.site));At(t),At(e);var c=t.site,f=c.x,s=c.y,h=n.x-f,g=n.y-s,p=e.site,d=p.x-f,v=p.y-s,y=2*(h*v-g*d),m=h*h+g*g,x=d*d+v*v,M={x:(v*m-g*x)/y+f,y:(h*x-d*m)/y+s};Dt(e.edge,c,p,M),l.edge=Tt(c,n,null,M),e.edge=Tt(n,p,null,M),Nt(t),Nt(e)}}function xt(n,t){var e=n.site,r=e.x,u=e.y,i=u-t;if(!i)return r;var o=n.P;if(!o)return-(1/0);e=o.site;var a=e.x,l=e.y,c=l-t;if(!c)return a;var f=a-r,s=1/i-1/c,h=f/c;return s?(-h+Math.sqrt(h*h-2*s*(f*f/(-2*c)-l+c/2+u-i/2)))/s+r:(r+a)/2}function Mt(n,t){var e=n.N;if(e)return xt(e,t);var r=n.site;return r.y===t?r.x:1/0}function _t(n){this.site=n,this.edges=[]}function bt(n){for(var t,e,r,u,i,o,a,l,c,f,s=n[0][0],h=n[1][0],g=n[0][1],p=n[1][1],d=uo,v=d.length;v--;)if(i=d[v],i&&i.prepare())for(a=i.edges,l=a.length,o=0;l>o;)f=a[o].end(),r=f.x,u=f.y,c=a[++o%l].start(),t=c.x,e=c.y,(ti(r-t)>mi||ti(u-e)>mi)&&(a.splice(o,0,new Rt(qt(i.site,f,ti(r-s)mi?{x:s,y:ti(t-s)mi?{x:ti(e-p)mi?{x:h,y:ti(t-h)mi?{x:ti(e-g)=-xi)){var g=l*l+c*c,p=f*f+s*s,d=(s*g-c*p)/h,v=(l*p-f*g)/h,s=v+a,y=co.pop()||new kt;y.arc=n,y.site=u,y.x=d+o,y.y=s+Math.sqrt(d*d+v*v),y.cy=s,n.circle=y;for(var m=null,x=ao._;x;)if(y.y0)){if(i/=p,0>p){if(h>i)return;g>i&&(g=i)}else if(p>0){if(i>g)return;i>h&&(h=i)}if(i=e-l,p||!(0>i)){if(i/=p,0>p){if(i>g)return;i>h&&(h=i)}else if(p>0){if(h>i)return;g>i&&(g=i)}if(i=t-c,d||!(i>0)){if(i/=d,0>d){if(h>i)return;g>i&&(g=i)}else if(d>0){if(i>g)return;i>h&&(h=i)}if(i=r-c,d||!(0>i)){if(i/=d,0>d){if(i>g)return;i>h&&(h=i)}else if(d>0){if(h>i)return;g>i&&(g=i)}return h>0&&(u.a={x:l+h*p,y:c+h*d}),1>g&&(u.b={x:l+g*p,y:c+g*d}),u}}}}}}function zt(n){for(var t,e=ro,r=Ct(n[0][0],n[0][1],n[1][0],n[1][1]),u=e.length;u--;)t=e[u],(!Lt(t,n)||!r(t)||ti(t.a.x-t.b.x)v||v>=a)return;if(h>p){if(i){if(i.y>=c)return}else i={x:v,y:l};e={x:v,y:c}}else{if(i){if(i.yr||r>1)if(h>p){if(i){if(i.y>=c)return}else i={x:(l-u)/r,y:l};e={x:(c-u)/r,y:c}}else{if(i){if(i.yg){if(i){if(i.x>=a)return}else i={x:o,y:r*o+u};e={x:a,y:r*a+u}}else{if(i){if(i.xi||s>o||r>h||u>g)){if(p=n.point){var p,d=t-n.x,v=e-n.y,y=d*d+v*v;if(l>y){var m=Math.sqrt(l=y);r=t-m,u=e-m,i=t+m,o=e+m,a=p}}for(var x=n.nodes,M=.5*(f+h),_=.5*(s+g),b=t>=M,w=e>=_,k=w<<1|b,N=k+4;N>k;++k)if(n=x[3&k])switch(3&k){case 0:c(n,f,s,M,_);break;case 1:c(n,M,s,h,_);break;case 2:c(n,f,_,M,g);break;case 3:c(n,M,_,h,g)}}}(n,r,u,i,o),a}function Bt(n,t){n=Iu.rgb(n),t=Iu.rgb(t);var e=n.r,r=n.g,u=n.b,i=t.r-e,o=t.g-r,a=t.b-u;return function(n){return"#"+mn(Math.round(e+i*n))+mn(Math.round(r+o*n))+mn(Math.round(u+a*n))}}function Wt(n,t){var e,r={},u={};for(e in n)e in t?r[e]=Kt(n[e],t[e]):u[e]=n[e];for(e in t)e in n||(u[e]=t[e]);return function(n){for(e in r)u[e]=r[e](n);return u}}function Jt(n,t){return n=+n,t=+t,function(e){return n*(1-e)+t*e}}function Gt(n,t){var e,r,u,i=so.lastIndex=ho.lastIndex=0,o=-1,a=[],l=[];for(n+="",t+="";(e=so.exec(n))&&(r=ho.exec(t));)(u=r.index)>i&&(u=t.slice(i,u),a[o]?a[o]+=u:a[++o]=u),(e=e[0])===(r=r[0])?a[o]?a[o]+=r:a[++o]=r:(a[++o]=null,l.push({i:o,x:Jt(e,r)})),i=ho.lastIndex;return ir;++r)a[(e=l[r]).i]=e.x(n);return a.join("")})}function Kt(n,t){for(var e,r=Iu.interpolators.length;--r>=0&&!(e=Iu.interpolators[r](n,t)););return e}function Qt(n,t){var e,r=[],u=[],i=n.length,o=t.length,a=Math.min(n.length,t.length);for(e=0;a>e;++e)r.push(Kt(n[e],t[e]));for(;i>e;++e)u[e]=n[e];for(;o>e;++e)u[e]=t[e];return function(n){for(e=0;a>e;++e)u[e]=r[e](n);return u}}function ne(n){return function(t){return 0>=t?0:t>=1?1:n(t)}}function te(n){return function(t){return 1-n(1-t)}}function ee(n){return function(t){return.5*(.5>t?n(2*t):2-n(2-2*t))}}function re(n){return n*n}function ue(n){return n*n*n}function ie(n){if(0>=n)return 0;if(n>=1)return 1;var t=n*n,e=t*n;return 4*(.5>n?e:3*(n-t)+e-.75)}function oe(n){return function(t){return Math.pow(t,n)}}function ae(n){return 1-Math.cos(n*wi)}function le(n){return Math.pow(2,10*(n-1))}function ce(n){return 1-Math.sqrt(1-n*n)}function fe(n,t){var e;return arguments.length<2&&(t=.45),arguments.length?e=t/_i*Math.asin(1/n):(n=1,e=t/4),function(r){return 1+n*Math.pow(2,-10*r)*Math.sin((r-e)*_i/t)}}function se(n){return n||(n=1.70158),function(t){return t*t*((n+1)*t-n)}}function he(n){return 1/2.75>n?7.5625*n*n:2/2.75>n?7.5625*(n-=1.5/2.75)*n+.75:2.5/2.75>n?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375}function ge(n,t){n=Iu.hcl(n),t=Iu.hcl(t);var e=n.h,r=n.c,u=n.l,i=t.h-e,o=t.c-r,a=t.l-u;return isNaN(o)&&(o=0,r=isNaN(r)?t.c:r),isNaN(i)?(i=0,e=isNaN(e)?t.h:e):i>180?i-=360:-180>i&&(i+=360),function(n){return ln(e+i*n,r+o*n,u+a*n)+""}}function pe(n,t){n=Iu.hsl(n),t=Iu.hsl(t);var e=n.h,r=n.s,u=n.l,i=t.h-e,o=t.s-r,a=t.l-u;return isNaN(o)&&(o=0,r=isNaN(r)?t.s:r),isNaN(i)?(i=0,e=isNaN(e)?t.h:e):i>180?i-=360:-180>i&&(i+=360),function(n){return on(e+i*n,r+o*n,u+a*n)+""}}function de(n,t){n=Iu.lab(n),t=Iu.lab(t);var e=n.l,r=n.a,u=n.b,i=t.l-e,o=t.a-r,a=t.b-u;return function(n){return fn(e+i*n,r+o*n,u+a*n)+""}}function ve(n,t){return t-=n,function(e){return Math.round(n+t*e)}}function ye(n){var t=[n.a,n.b],e=[n.c,n.d],r=xe(t),u=me(t,e),i=xe(Me(e,t,-u))||0;t[0]*e[1]180?t+=360:t-n>180&&(n+=360),r.push({i:e.push(_e(e)+"rotate(",null,")")-2,x:Jt(n,t)})):t&&e.push(_e(e)+"rotate("+t+")")}function ke(n,t,e,r){n!==t?r.push({i:e.push(_e(e)+"skewX(",null,")")-2,x:Jt(n,t)}):t&&e.push(_e(e)+"skewX("+t+")")}function Ne(n,t,e,r){if(n[0]!==t[0]||n[1]!==t[1]){var u=e.push(_e(e)+"scale(",null,",",null,")");r.push({i:u-4,x:Jt(n[0],t[0])},{i:u-2,x:Jt(n[1],t[1])})}else 1===t[0]&&1===t[1]||e.push(_e(e)+"scale("+t+")")}function Ae(n,t){var e=[],r=[];return n=Iu.transform(n),t=Iu.transform(t),be(n.translate,t.translate,e,r),we(n.rotate,t.rotate,e,r),ke(n.skew,t.skew,e,r),Ne(n.scale,t.scale,e,r),n=t=null,function(n){for(var t,u=-1,i=r.length;++u=0;)e.push(u[r])}function He(n,t){for(var e=[n],r=[];null!=(n=e.pop());)if(r.push(n),(i=n.children)&&(u=i.length))for(var u,i,o=-1;++oe;++e)(t=n[e][1])>u&&(r=e,u=t);return r}function Je(n){return n.reduce(Ge,0)}function Ge(n,t){return n+t[1]}function Ke(n,t){return Qe(n,Math.ceil(Math.log(t.length)/Math.LN2+1))}function Qe(n,t){for(var e=-1,r=+n[0],u=(n[1]-r)/t,i=[];++e<=t;)i[e]=u*e+r;return i}function nr(n){return[Iu.min(n),Iu.max(n)]}function tr(n,t){return n.value-t.value}function er(n,t){var e=n._pack_next;n._pack_next=t,t._pack_prev=n,t._pack_next=e,e._pack_prev=t}function rr(n,t){n._pack_next=t,t._pack_prev=n}function ur(n,t){var e=t.x-n.x,r=t.y-n.y,u=n.r+t.r;return.999*u*u>e*e+r*r}function ir(n){function t(n){f=Math.min(n.x-n.r,f),s=Math.max(n.x+n.r,s),h=Math.min(n.y-n.r,h),g=Math.max(n.y+n.r,g)}if((e=n.children)&&(c=e.length)){var e,r,u,i,o,a,l,c,f=1/0,s=-(1/0),h=1/0,g=-(1/0);if(e.forEach(or),r=e[0],r.x=-r.r,r.y=0,t(r),c>1&&(u=e[1],u.x=u.r,u.y=0,t(u),c>2))for(i=e[2],cr(r,u,i),t(i),er(r,i),r._pack_prev=i,er(i,u),u=r._pack_next,o=3;c>o;o++){cr(r,u,i=e[o]);var p=0,d=1,v=1;for(a=u._pack_next;a!==u;a=a._pack_next,d++)if(ur(a,i)){p=1;break}if(1==p)for(l=r._pack_prev;l!==a._pack_prev&&!ur(l,i);l=l._pack_prev,v++);p?(v>d||d==v&&u.ro;o++)i=e[o],i.x-=y,i.y-=m,x=Math.max(x,i.r+Math.sqrt(i.x*i.x+i.y*i.y));n.r=x,e.forEach(ar)}}function or(n){n._pack_next=n._pack_prev=n}function ar(n){delete n._pack_next,delete n._pack_prev}function lr(n,t,e,r){var u=n.children;if(n.x=t+=r*n.x,n.y=e+=r*n.y,n.r*=r,u)for(var i=-1,o=u.length;++i=0;)t=u[i],t.z+=e,t.m+=e,e+=t.s+(r+=t.c)}function dr(n,t,e){return n.a.parent===t.parent?n.a:e}function vr(n){return 1+Iu.max(n,function(n){return n.y})}function yr(n){return n.reduce(function(n,t){return n+t.x},0)/n.length}function mr(n){var t=n.children;return t&&t.length?mr(t[0]):n}function xr(n){var t,e=n.children;return e&&(t=e.length)?xr(e[t-1]):n}function Mr(n){return{x:n.x,y:n.y,dx:n.dx,dy:n.dy}}function _r(n,t){var e=n.x+t[3],r=n.y+t[0],u=n.dx-t[1]-t[3],i=n.dy-t[0]-t[2];return 0>u&&(e+=u/2,u=0),0>i&&(r+=i/2,i=0),{x:e,y:r,dx:u,dy:i}}function br(n){var t=n[0],e=n[n.length-1];return e>t?[t,e]:[e,t]}function wr(n){return n.rangeExtent?n.rangeExtent():br(n.range())}function kr(n,t,e,r){var u=e(n[0],n[1]),i=r(t[0],t[1]);return function(n){return i(u(n))}}function Nr(n,t){var e,r=0,u=n.length-1,i=n[r],o=n[u];return i>o&&(e=r,r=u,u=e,e=i,i=o,o=e),n[r]=t.floor(i),n[u]=t.ceil(o),n}function Ar(n){return n?{floor:function(t){return Math.floor(t/n)*n},ceil:function(t){return Math.ceil(t/n)*n}}:ko}function Cr(n,t,e,r){var u=[],i=[],o=0,a=Math.min(n.length,t.length)-1;for(n[a]2?Cr:kr,l=r?ze:Ce;return o=u(n,t,l,e),a=u(t,n,l,Kt),i}function i(n){return o(n)}var o,a;return i.invert=function(n){return a(n)},i.domain=function(t){return arguments.length?(n=t.map(Number),u()):n},i.range=function(n){return arguments.length?(t=n,u()):t},i.rangeRound=function(n){return i.range(n).interpolate(ve)},i.clamp=function(n){return arguments.length?(r=n,u()):r},i.interpolate=function(n){return arguments.length?(e=n,u()):e},i.ticks=function(t){return qr(n,t)},i.tickFormat=function(t,e){return Dr(n,t,e)},i.nice=function(t){return Sr(n,t),u()},i.copy=function(){return zr(n,t,e,r)},u()}function Lr(n,t){return Iu.rebind(n,t,"range","rangeRound","interpolate","clamp")}function Sr(n,t){return Nr(n,Ar(Tr(n,t)[2])),Nr(n,Ar(Tr(n,t)[2])),n}function Tr(n,t){null==t&&(t=10);var e=br(n),r=e[1]-e[0],u=Math.pow(10,Math.floor(Math.log(r/t)/Math.LN10)),i=t/r*u;return.15>=i?u*=10:.35>=i?u*=5:.75>=i&&(u*=2),e[0]=Math.ceil(e[0]/u)*u,e[1]=Math.floor(e[1]/u)*u+.5*u,e[2]=u,e}function qr(n,t){return Iu.range.apply(Iu,Tr(n,t))}function Dr(n,t,e){var r=Tr(n,t);if(e){var u=$i.exec(e);if(u.shift(),"s"===u[8]){var i=Iu.formatPrefix(Math.max(ti(r[0]),ti(r[1])));return u[7]||(u[7]="."+Rr(i.scale(r[2]))),u[8]="f",e=Iu.format(u.join("")),function(n){return e(i.scale(n))+i.symbol}}u[7]||(u[7]="."+Er(u[8],r)),e=u.join("")}else e=",."+Rr(r[2])+"f";return Iu.format(e)}function Rr(n){return-Math.floor(Math.log(n)/Math.LN10+.01)}function Er(n,t){var e=Rr(t[2]);return n in No?Math.abs(e-Rr(Math.max(ti(t[0]),ti(t[1]))))+ +("e"!==n):e-2*("%"===n)}function Ur(n,t,e,r){function u(n){return(e?Math.log(0>n?0:n):-Math.log(n>0?0:-n))/Math.log(t)}function i(n){return e?Math.pow(t,n):-Math.pow(t,-n)}function o(t){return n(u(t))}return o.invert=function(t){return i(n.invert(t))},o.domain=function(t){return arguments.length?(e=t[0]>=0,n.domain((r=t.map(Number)).map(u)),o):r},o.base=function(e){return arguments.length?(t=+e,n.domain(r.map(u)),o):t},o.nice=function(){var t=Nr(r.map(u),e?Math:Co);return n.domain(t),r=t.map(i),o},o.ticks=function(){var n=br(r),o=[],a=n[0],l=n[1],c=Math.floor(u(a)),f=Math.ceil(u(l)),s=t%1?2:t;if(isFinite(f-c)){if(e){for(;f>c;c++)for(var h=1;s>h;h++)o.push(i(c)*h);o.push(i(c))}else for(o.push(i(c));c++0;h--)o.push(i(c)*h);for(c=0;o[c]l;f--);o=o.slice(c,f)}return o},o.tickFormat=function(n,e){if(!arguments.length)return Ao;arguments.length<2?e=Ao:"function"!=typeof e&&(e=Iu.format(e));var r=Math.max(1,t*n/o.ticks().length);return function(n){var o=n/i(Math.round(u(n)));return t-.5>o*t&&(o*=t),r>=o?e(n):""}},o.copy=function(){return Ur(n.copy(),t,e,r)},Lr(o,n)}function Pr(n,t,e){function r(t){return n(u(t))}var u=jr(t),i=jr(1/t);return r.invert=function(t){return i(n.invert(t))},r.domain=function(t){return arguments.length?(n.domain((e=t.map(Number)).map(u)),r):e},r.ticks=function(n){return qr(e,n)},r.tickFormat=function(n,t){return Dr(e,n,t)},r.nice=function(n){return r.domain(Sr(e,n))},r.exponent=function(o){return arguments.length?(u=jr(t=o),i=jr(1/t),n.domain(e.map(u)),r):t},r.copy=function(){return Pr(n.copy(),t,e)},Lr(r,n)}function jr(n){return function(t){return 0>t?-Math.pow(-t,n):Math.pow(t,n)}}function Hr(n,t){function e(e){return i[((u.get(e)||("range"===t.t?u.set(e,n.push(e)):NaN))-1)%i.length]}function r(t,e){return Iu.range(n.length).map(function(n){return t+e*n})}var u,i,o;return e.domain=function(r){if(!arguments.length)return n;n=[],u=new c;for(var i,o=-1,a=r.length;++oe?[NaN,NaN]:[e>0?a[e-1]:n[0],et?NaN:t/i+n,[t,t+1/i]},r.copy=function(){return Or(n,t,e)},u()}function Yr(n,t){function e(e){return e>=e?t[Iu.bisect(n,e)]:void 0}return e.domain=function(t){return arguments.length?(n=t,e):n},e.range=function(n){return arguments.length?(t=n,e):t},e.invertExtent=function(e){return e=t.indexOf(e),[n[e-1],n[e]]},e.copy=function(){return Yr(n,t)},e}function Ir(n){function t(n){return+n}return t.invert=t,t.domain=t.range=function(e){return arguments.length?(n=e.map(t),t):n},t.ticks=function(t){return qr(n,t)},t.tickFormat=function(t,e){return Dr(n,t,e)},t.copy=function(){return Ir(n)},t}function Zr(){return 0}function Vr(n){return n.innerRadius}function Xr(n){return n.outerRadius}function $r(n){return n.startAngle}function Br(n){return n.endAngle}function Wr(n){return n&&n.padAngle}function Jr(n,t,e,r){return(n-e)*t-(t-r)*n>0?0:1}function Gr(n,t,e,r,u){var i=n[0]-t[0],o=n[1]-t[1],a=(u?r:-r)/Math.sqrt(i*i+o*o),l=a*o,c=-a*i,f=n[0]+l,s=n[1]+c,h=t[0]+l,g=t[1]+c,p=(f+h)/2,d=(s+g)/2,v=h-f,y=g-s,m=v*v+y*y,x=e-r,M=f*g-h*s,_=(0>y?-1:1)*Math.sqrt(Math.max(0,x*x*m-M*M)),b=(M*y-v*_)/m,w=(-M*v-y*_)/m,k=(M*y+v*_)/m,N=(-M*v+y*_)/m,A=b-p,C=w-d,z=k-p,L=N-d;return A*A+C*C>z*z+L*L&&(b=k,w=N),[[b-l,w-c],[b*e/x,w*e/x]]}function Kr(){return!0}function Qr(n){function t(t){function o(){c.push("M",i(n(f),a))}for(var l,c=[],f=[],s=-1,h=t.length,g=kn(e),p=kn(r);++s1?n.join("L"):n+"Z"}function tu(n){return n.join("L")+"Z"}function eu(n){for(var t=0,e=n.length,r=n[0],u=[r[0],",",r[1]];++t1&&u.push("H",r[0]),u.join("")}function ru(n){for(var t=0,e=n.length,r=n[0],u=[r[0],",",r[1]];++t1){a=t[1],i=n[l],l++,r+="C"+(u[0]+o[0])+","+(u[1]+o[1])+","+(i[0]-a[0])+","+(i[1]-a[1])+","+i[0]+","+i[1];for(var c=2;c9&&(u=3*t/Math.sqrt(u),o[a]=u*e,o[a+1]=u*r));for(a=-1;++a<=l;)u=(n[Math.min(l,a+1)][0]-n[Math.max(0,a-1)][0])/(6*(1+o[a]*o[a])),i.push([u||0,o[a]*u||0]);return i}function xu(n){return n.length<3?nu(n):n[0]+lu(n,mu(n))}function Mu(n){for(var t,e,r,u=-1,i=n.length;++u=t?o(n-t):void(f.c=o)}function o(e){var u=p.active,i=p[u];i&&(i.timer.c=null,i.timer.t=NaN,--p.count,delete p[u],i.event&&i.event.interrupt.call(n,n.__data__,i.index));for(var o in p)if(r>+o){var c=p[o];c.timer.c=null,c.timer.t=NaN,--p.count,delete p[o]}f.c=a,Ln(function(){return f.c&&a(e||1)&&(f.c=null,f.t=NaN),1},0,l),p.active=r,d.event&&d.event.start.call(n,n.__data__,t),g=[],d.tween.forEach(function(e,r){(r=r.call(n,n.__data__,t))&&g.push(r)}),h=d.ease,s=d.duration}function a(u){for(var i=u/s,o=h(i),a=g.length;a>0;)g[--a].call(n,o);return i>=1?(d.event&&d.event.end.call(n,n.__data__,t),--p.count?delete p[r]:delete n[e],1):void 0}var l,f,s,h,g,p=n[e]||(n[e]={active:0,count:0}),d=p[r];d||(l=u.time,f=Ln(i,0,l),d=p[r]={tween:new c,time:l,timer:f,delay:u.delay,duration:u.duration,ease:u.ease,index:t},u=null,++p.count)}function Uu(n,t,e){n.attr("transform",function(n){var r=t(n);return"translate("+(isFinite(r)?r:e(n))+",0)"})}function Pu(n,t,e){n.attr("transform",function(n){var r=t(n);return"translate(0,"+(isFinite(r)?r:e(n))+")"})}function ju(n){return n.toISOString()}function Hu(n,t,e){function r(t){return n(t)}function u(n,e){var r=n[1]-n[0],u=r/e,i=Iu.bisect(Ko,u);return i==Ko.length?[t.year,Tr(n.map(function(n){return n/31536e6}),e)[2]]:i?t[u/Ko[i-1]1?{floor:function(t){for(;e(t=n.floor(t));)t=Fu(t-1);return t},ceil:function(t){for(;e(t=n.ceil(t));)t=Fu(+t+1);return t}}:n))},r.ticks=function(n,t){var e=br(r.domain()),i=null==n?u(e,10):"number"==typeof n?u(e,n):!n.range&&[{range:n},t];return i&&(n=i[0],t=i[1]),n.range(e[0],Fu(+e[1]+1),1>t?1:t)},r.tickFormat=function(){return e},r.copy=function(){return Hu(n.copy(),t,e)},Lr(r,n)}function Fu(n){return new Date(n)}function Ou(n){return JSON.parse(n.responseText)}function Yu(n){var t=Xu.createRange();return t.selectNode(Xu.body),t.createContextualFragment(n.responseText)}var Iu={version:"3.7.0"},Zu=[].slice,Vu=function(n){return Zu.call(n)},Xu=this.document;if(Xu)try{Vu(Xu.documentElement.childNodes)[0].nodeType}catch($u){Vu=function(n){for(var t=n.length,e=new Array(t);t--;)e[t]=n[t];return e}}if(Date.now||(Date.now=function(){return+new Date}),Xu)try{Xu.createElement("DIV").style.setProperty("opacity",0,"")}catch(Bu){var Wu=this.Element.prototype,Ju=Wu.setAttribute,Gu=Wu.setAttributeNS,Ku=this.CSSStyleDeclaration.prototype,Qu=Ku.setProperty;Wu.setAttribute=function(n,t){Ju.call(this,n,t+"")},Wu.setAttributeNS=function(n,t,e){Gu.call(this,n,t,e+"")},Ku.setProperty=function(n,t,e){Qu.call(this,n,t+"",e)}}Iu.ascending=e,Iu.descending=function(n,t){return n>t?-1:t>n?1:t>=n?0:NaN},Iu.min=function(n,t){var e,r,u=-1,i=n.length;if(1===arguments.length){for(;++u=r){e=r;break}for(;++ur&&(e=r)}else{for(;++u=r){e=r;break}for(;++ur&&(e=r)}return e},Iu.max=function(n,t){var e,r,u=-1,i=n.length;if(1===arguments.length){for(;++u=r){e=r;break}for(;++ue&&(e=r)}else{for(;++u=r){e=r;break}for(;++ue&&(e=r)}return e},Iu.extent=function(n,t){var e,r,u,i=-1,o=n.length;if(1===arguments.length){for(;++i=r){e=u=r;break}for(;++ir&&(e=r),r>u&&(u=r))}else{for(;++i=r){e=u=r;break}for(;++ir&&(e=r),r>u&&(u=r))}return[e,u]},Iu.sum=function(n,t){var e,r=0,i=n.length,o=-1;if(1===arguments.length)for(;++o1?l/(f-1):void 0},Iu.deviation=function(){var n=Iu.variance.apply(this,arguments);return n?Math.sqrt(n):n};var ni=i(e);Iu.bisectLeft=ni.left,Iu.bisect=Iu.bisectRight=ni.right,Iu.bisector=function(n){return i(1===n.length?function(t,r){return e(n(t),r)}:n)},Iu.shuffle=function(n,t,e){(i=arguments.length)<3&&(e=n.length,2>i&&(t=0));for(var r,u,i=e-t;i;)u=Math.random()*i--|0,r=n[i+t],n[i+t]=n[u+t],n[u+t]=r;return n},Iu.permute=function(n,t){for(var e=t.length,r=new Array(e);e--;)r[e]=n[t[e]];return r},Iu.pairs=function(n){for(var t,e=0,r=n.length-1,u=n[0],i=new Array(0>r?0:r);r>e;)i[e]=[t=u,u=n[++e]];return i},Iu.transpose=function(n){if(!(u=n.length))return[];for(var t=-1,e=Iu.min(n,o),r=new Array(e);++t=0;)for(r=n[u],t=r.length;--t>=0;)e[--o]=r[t];return e};var ti=Math.abs;Iu.range=function(n,t,e){if(arguments.length<3&&(e=1,arguments.length<2&&(t=n,n=0)),(t-n)/e===1/0)throw new Error("infinite range");var r,u=[],i=a(ti(e)),o=-1;if(n*=i,t*=i,e*=i,0>e)for(;(r=n+e*++o)>t;)u.push(r/i);else for(;(r=n+e*++o)=i.length)return r?r.call(u,o):e?o.sort(e):o;for(var l,f,s,h,g=-1,p=o.length,d=i[a++],v=new c;++g=i.length)return n;var r=[],u=o[e++];return n.forEach(function(n,u){r.push({key:n,values:t(u,e)})}),u?r.sort(function(n,t){return u(n.key,t.key)}):r}var e,r,u={},i=[],o=[];return u.map=function(t,e){return n(e,t,0)},u.entries=function(e){return t(n(Iu.map,e,0),0)},u.key=function(n){return i.push(n),u},u.sortKeys=function(n){return o[i.length-1]=n,u},u.sortValues=function(n){return e=n,u},u.rollup=function(n){return r=n,u},u},Iu.set=function(n){var t=new y;if(n)for(var e=0,r=n.length;r>e;++e)t.add(n[e]);return t},l(y,{has:h,add:function(n){return this._[f(n+="")]=!0,n},remove:g,values:p,size:d,empty:v,forEach:function(n){for(var t in this._)n.call(this,s(t))}}),Iu.behavior={},Iu.rebind=function(n,t){for(var e,r=1,u=arguments.length;++r=0&&(r=n.slice(e+1),n=n.slice(0,e)),n)return arguments.length<2?this[n].on(r):this[n].on(r,t);if(2===arguments.length){if(null==t)for(n in this)this.hasOwnProperty(n)&&this[n].on(r,null);return this}},Iu.event=null,Iu.requote=function(n){return n.replace(ii,"\\$&")};var ii=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,oi={}.__proto__?function(n,t){n.__proto__=t}:function(n,t){for(var e in t)n[e]=t[e]},ai=function(n,t){return t.querySelector(n)},li=function(n,t){return t.querySelectorAll(n)},ci=function(n,t){var e=n.matches||n[M(n,"matchesSelector")];return(ci=function(n,t){return e.call(n,t)})(n,t)};"function"==typeof Sizzle&&(ai=function(n,t){return Sizzle(n,t)[0]||null},li=Sizzle,ci=Sizzle.matchesSelector),Iu.selection=function(){return Iu.select(Xu.documentElement)};var fi=Iu.selection.prototype=[];fi.select=function(n){var t,e,r,u,i=[];n=z(n);for(var o=-1,a=this.length;++o=0&&"xmlns"!==(e=n.slice(0,t))&&(n=n.slice(t+1)),hi.hasOwnProperty(e)?{space:hi[e],local:n}:n}},fi.attr=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node();return n=Iu.ns.qualify(n),n.local?e.getAttributeNS(n.space,n.local):e.getAttribute(n)}for(t in n)this.each(S(t,n[t]));return this}return this.each(S(n,t))},fi.classed=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node(),r=(n=D(n)).length,u=-1;if(t=e.classList){for(;++uu){if("string"!=typeof n){2>u&&(e="");for(r in n)this.each(U(r,n[r],e));return this}if(2>u){var i=this.node();return t(i).getComputedStyle(i,null).getPropertyValue(n)}r=""}return this.each(U(n,e,r))},fi.property=function(n,t){if(arguments.length<2){if("string"==typeof n)return this.node()[n];for(t in n)this.each(P(t,n[t]));return this}return this.each(P(n,t))},fi.text=function(n){return arguments.length?this.each("function"==typeof n?function(){var t=n.apply(this,arguments);this.textContent=null==t?"":t}:null==n?function(){this.textContent=""}:function(){this.textContent=n}):this.node().textContent},fi.html=function(n){return arguments.length?this.each("function"==typeof n?function(){var t=n.apply(this,arguments);this.innerHTML=null==t?"":t}:null==n?function(){this.innerHTML=""}:function(){this.innerHTML=n}):this.node().innerHTML},fi.append=function(n){return n=j(n),this.select(function(){return this.appendChild(n.apply(this,arguments))})},fi.insert=function(n,t){return n=j(n),t=z(t),this.select(function(){return this.insertBefore(n.apply(this,arguments),t.apply(this,arguments)||null)})},fi.remove=function(){return this.each(H)},fi.data=function(n,t){function e(n,e){var r,u,i,o=n.length,s=e.length,h=Math.min(o,s),g=new Array(s),p=new Array(s),d=new Array(o);if(t){var v,y=new c,m=new Array(o);for(r=-1;++rr;++r)p[r]=F(e[r]);for(;o>r;++r)d[r]=n[r]}p.update=g,p.parentNode=g.parentNode=d.parentNode=n.parentNode,a.push(p),l.push(g),f.push(d)}var r,u,i=-1,o=this.length;if(!arguments.length){for(n=new Array(o=(r=this[0]).length);++ii;i++){u.push(t=[]),t.parentNode=(e=this[i]).parentNode;for(var a=0,l=e.length;l>a;a++)(r=e[a])&&n.call(r,r.__data__,a,i)&&t.push(r)}return C(u)},fi.order=function(){for(var n=-1,t=this.length;++n=0;)(e=r[u])&&(i&&i!==e.nextSibling&&i.parentNode.insertBefore(e,i),i=e);return this},fi.sort=function(n){n=Y.apply(this,arguments);for(var t=-1,e=this.length;++tn;n++)for(var e=this[n],r=0,u=e.length;u>r;r++){var i=e[r];if(i)return i}return null},fi.size=function(){var n=0;return I(this,function(){++n}),n};var gi=[];Iu.selection.enter=Z,Iu.selection.enter.prototype=gi,gi.append=fi.append,gi.empty=fi.empty,gi.node=fi.node,gi.call=fi.call,gi.size=fi.size,gi.select=function(n){for(var t,e,r,u,i,o=[],a=-1,l=this.length;++ar){if("string"!=typeof n){2>r&&(t=!1);for(e in n)this.each(X(e,n[e],t));return this}if(2>r)return(r=this.node()["__on"+n])&&r._;e=!1}return this.each(X(n,t,e))};var pi=Iu.map({mouseenter:"mouseover",mouseleave:"mouseout"});Xu&&pi.forEach(function(n){"on"+n in Xu&&pi.remove(n)});var di,vi=0;Iu.mouse=function(n){return J(n,N())};var yi=this.navigator&&/WebKit/.test(this.navigator.userAgent)?-1:0;Iu.touch=function(n,t,e){if(arguments.length<3&&(e=t,t=N().changedTouches),t)for(var r,u=0,i=t.length;i>u;++u)if((r=t[u]).identifier===e)return J(n,r)},Iu.behavior.drag=function(){function n(){this.on("mousedown.drag",i).on("touchstart.drag",o)}function e(n,t,e,i,o){return function(){function a(){var n,e,r=t(h,d);r&&(n=r[0]-x[0],e=r[1]-x[1],p|=n|e,x=r,g({type:"drag",x:r[0]+c[0],y:r[1]+c[1],dx:n,dy:e}))}function l(){t(h,d)&&(y.on(i+v,null).on(o+v,null),m(p),g({type:"dragend"}))}var c,f=this,s=Iu.event.target.correspondingElement||Iu.event.target,h=f.parentNode,g=r.of(f,arguments),p=0,d=n(),v=".drag"+(null==d?"":"-"+d),y=Iu.select(e(s)).on(i+v,a).on(o+v,l),m=W(s),x=t(h,d);u?(c=u.apply(f,arguments),c=[c.x-x[0],c.y-x[1]]):c=[0,0],g({type:"dragstart"})}}var r=A(n,"drag","dragstart","dragend"),u=null,i=e(_,Iu.mouse,t,"mousemove","mouseup"),o=e(G,Iu.touch,m,"touchmove","touchend");return n.origin=function(t){return arguments.length?(u=t,n):u},Iu.rebind(n,r,"on")},Iu.touches=function(n,t){return arguments.length<2&&(t=N().touches),t?Vu(t).map(function(t){var e=J(n,t);return e.identifier=t.identifier, -e}):[]};var mi=1e-6,xi=mi*mi,Mi=Math.PI,_i=2*Mi,bi=_i-mi,wi=Mi/2,ki=Mi/180,Ni=180/Mi,Ai=Math.SQRT2,Ci=2,zi=4;Iu.interpolateZoom=function(n,t){var e,r,u=n[0],i=n[1],o=n[2],a=t[0],l=t[1],c=t[2],f=a-u,s=l-i,h=f*f+s*s;if(xi>h)r=Math.log(c/o)/Ai,e=function(n){return[u+n*f,i+n*s,o*Math.exp(Ai*n*r)]};else{var g=Math.sqrt(h),p=(c*c-o*o+zi*h)/(2*o*Ci*g),d=(c*c-o*o-zi*h)/(2*c*Ci*g),v=Math.log(Math.sqrt(p*p+1)-p),y=Math.log(Math.sqrt(d*d+1)-d);r=(y-v)/Ai,e=function(n){var t=n*r,e=tn(v),a=o/(Ci*g)*(e*en(Ai*t+v)-nn(v));return[u+a*f,i+a*s,o*e/tn(Ai*t+v)]}}return e.duration=1e3*r,e},Iu.behavior.zoom=function(){function n(n){n.on(T,s).on(Si+".zoom",g).on("dblclick.zoom",p).on(R,h)}function e(n){return[(n[0]-N.x)/N.k,(n[1]-N.y)/N.k]}function r(n){return[n[0]*N.k+N.x,n[1]*N.k+N.y]}function u(n){N.k=Math.max(z[0],Math.min(z[1],n))}function i(n,t){t=r(t),N.x+=n[0]-t[0],N.y+=n[1]-t[1]}function o(t,e,r,o){t.__chart__={x:N.x,y:N.y,k:N.k},u(Math.pow(2,o)),i(v=e,r),t=Iu.select(t),L>0&&(t=t.transition().duration(L)),t.call(n.event)}function a(){_&&_.domain(M.range().map(function(n){return(n-N.x)/N.k}).map(M.invert)),w&&w.domain(b.range().map(function(n){return(n-N.y)/N.k}).map(b.invert))}function l(n){S++||n({type:"zoomstart"})}function c(n){a(),n({type:"zoom",scale:N.k,translate:[N.x,N.y]})}function f(n){--S||(n({type:"zoomend"}),v=null)}function s(){function n(){a=1,i(Iu.mouse(u),h),c(o)}function r(){s.on(q,null).on(D,null),g(a),f(o)}var u=this,o=E.of(u,arguments),a=0,s=Iu.select(t(u)).on(q,n).on(D,r),h=e(Iu.mouse(u)),g=W(u);Yo.call(u),l(o)}function h(){function n(){var n=Iu.touches(p);return g=N.k,n.forEach(function(n){n.identifier in v&&(v[n.identifier]=e(n))}),n}function t(){var t=Iu.event.target;Iu.select(t).on(M,r).on(_,a),b.push(t);for(var e=Iu.event.changedTouches,u=0,i=e.length;i>u;++u)v[e[u].identifier]=null;var l=n(),c=Date.now();if(1===l.length){if(500>c-x){var f=l[0];o(p,f,v[f.identifier],Math.floor(Math.log(N.k)/Math.LN2)+1),k()}x=c}else if(l.length>1){var f=l[0],s=l[1],h=f[0]-s[0],g=f[1]-s[1];y=h*h+g*g}}function r(){var n,t,e,r,o=Iu.touches(p);Yo.call(p);for(var a=0,l=o.length;l>a;++a,r=null)if(e=o[a],r=v[e.identifier]){if(t)break;n=e,t=r}if(r){var f=(f=e[0]-n[0])*f+(f=e[1]-n[1])*f,s=y&&Math.sqrt(f/y);n=[(n[0]+e[0])/2,(n[1]+e[1])/2],t=[(t[0]+r[0])/2,(t[1]+r[1])/2],u(s*g)}x=null,i(n,t),c(d)}function a(){if(Iu.event.touches.length){for(var t=Iu.event.changedTouches,e=0,r=t.length;r>e;++e)delete v[t[e].identifier];for(var u in v)return void n()}Iu.selectAll(b).on(m,null),w.on(T,s).on(R,h),A(),f(d)}var g,p=this,d=E.of(p,arguments),v={},y=0,m=".zoom-"+Iu.event.changedTouches[0].identifier,M="touchmove"+m,_="touchend"+m,b=[],w=Iu.select(p),A=W(p);t(),l(d),w.on(T,null).on(R,t)}function g(){var n=E.of(this,arguments);m?clearTimeout(m):(Yo.call(this),d=e(v=y||Iu.mouse(this)),l(n)),m=setTimeout(function(){m=null,f(n)},50),k(),u(Math.pow(2,.002*Li())*N.k),i(v,d),c(n)}function p(){var n=Iu.mouse(this),t=Math.log(N.k)/Math.LN2;o(this,n,e(n),Iu.event.shiftKey?Math.ceil(t)-1:Math.floor(t)+1)}var d,v,y,m,x,M,_,b,w,N={x:0,y:0,k:1},C=[960,500],z=Ti,L=250,S=0,T="mousedown.zoom",q="mousemove.zoom",D="mouseup.zoom",R="touchstart.zoom",E=A(n,"zoomstart","zoom","zoomend");return Si||(Si="onwheel"in Xu?(Li=function(){return-Iu.event.deltaY*(Iu.event.deltaMode?120:1)},"wheel"):"onmousewheel"in Xu?(Li=function(){return Iu.event.wheelDelta},"mousewheel"):(Li=function(){return-Iu.event.detail},"MozMousePixelScroll")),n.event=function(n){n.each(function(){var n=E.of(this,arguments),t=N;Fo?Iu.select(this).transition().each("start.zoom",function(){N=this.__chart__||{x:0,y:0,k:1},l(n)}).tween("zoom:zoom",function(){var e=C[0],r=C[1],u=v?v[0]:e/2,i=v?v[1]:r/2,o=Iu.interpolateZoom([(u-N.x)/N.k,(i-N.y)/N.k,e/N.k],[(u-t.x)/t.k,(i-t.y)/t.k,e/t.k]);return function(t){var r=o(t),a=e/r[2];this.__chart__=N={x:u-r[0]*a,y:i-r[1]*a,k:a},c(n)}}).each("interrupt.zoom",function(){f(n)}).each("end.zoom",function(){f(n)}):(this.__chart__=N,l(n),c(n),f(n))})},n.translate=function(t){return arguments.length?(N={x:+t[0],y:+t[1],k:N.k},a(),n):[N.x,N.y]},n.scale=function(t){return arguments.length?(N={x:N.x,y:N.y,k:null},u(+t),a(),n):N.k},n.scaleExtent=function(t){return arguments.length?(z=null==t?Ti:[+t[0],+t[1]],n):z},n.center=function(t){return arguments.length?(y=t&&[+t[0],+t[1]],n):y},n.size=function(t){return arguments.length?(C=t&&[+t[0],+t[1]],n):C},n.duration=function(t){return arguments.length?(L=+t,n):L},n.x=function(t){return arguments.length?(_=t,M=t.copy(),N={x:0,y:0,k:1},n):_},n.y=function(t){return arguments.length?(w=t,b=t.copy(),N={x:0,y:0,k:1},n):w},Iu.rebind(n,E,"on")};var Li,Si,Ti=[0,1/0];Iu.color=rn,rn.prototype.toString=function(){return this.rgb()+""},Iu.hsl=un;var qi=un.prototype=new rn;qi.brighter=function(n){return n=Math.pow(.7,arguments.length?n:1),new un(this.h,this.s,this.l/n)},qi.darker=function(n){return n=Math.pow(.7,arguments.length?n:1),new un(this.h,this.s,n*this.l)},qi.rgb=function(){return on(this.h,this.s,this.l)},Iu.hcl=an;var Di=an.prototype=new rn;Di.brighter=function(n){return new an(this.h,this.c,Math.min(100,this.l+Ri*(arguments.length?n:1)))},Di.darker=function(n){return new an(this.h,this.c,Math.max(0,this.l-Ri*(arguments.length?n:1)))},Di.rgb=function(){return ln(this.h,this.c,this.l).rgb()},Iu.lab=cn;var Ri=18,Ei=.95047,Ui=1,Pi=1.08883,ji=cn.prototype=new rn;ji.brighter=function(n){return new cn(Math.min(100,this.l+Ri*(arguments.length?n:1)),this.a,this.b)},ji.darker=function(n){return new cn(Math.max(0,this.l-Ri*(arguments.length?n:1)),this.a,this.b)},ji.rgb=function(){return fn(this.l,this.a,this.b)},Iu.rgb=dn;var Hi=dn.prototype=new rn;Hi.brighter=function(n){n=Math.pow(.7,arguments.length?n:1);var t=this.r,e=this.g,r=this.b,u=30;return t||e||r?(t&&u>t&&(t=u),e&&u>e&&(e=u),r&&u>r&&(r=u),new dn(Math.min(255,t/n),Math.min(255,e/n),Math.min(255,r/n))):new dn(u,u,u)},Hi.darker=function(n){return n=Math.pow(.7,arguments.length?n:1),new dn(n*this.r,n*this.g,n*this.b)},Hi.hsl=function(){return Mn(this.r,this.g,this.b)},Hi.toString=function(){return"#"+mn(this.r)+mn(this.g)+mn(this.b)};var Fi=Iu.map({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});Fi.forEach(function(n,t){Fi.set(n,vn(t))}),Iu.functor=kn,Iu.xhr=Nn(m),Iu.dsv=function(n,t){function e(n,e,i){arguments.length<3&&(i=e,e=null);var o=An(n,t,null==e?r:u(e),i);return o.row=function(n){return arguments.length?o.response(null==(e=n)?r:u(n)):e},o}function r(n){return e.parse(n.responseText)}function u(n){return function(t){return e.parse(t.responseText,n)}}function i(t){return t.map(o).join(n)}function o(n){return a.test(n)?'"'+n.replace(/\"/g,'""')+'"':n}var a=new RegExp('["'+n+"\n]"),l=n.charCodeAt(0);return e.parse=function(n,t){var r;return e.parseRows(n,function(n,e){if(r)return r(n,e-1);var u=function(t){for(var e={},r=n.length,u=0;r>u;++u)e[n[u]]=t[u];return e};r=t?function(n,e){return t(u(n),e)}:u})},e.parseRows=function(n,t){function e(){if(f>=c)return o;if(u)return u=!1,i;var t=f;if(34===n.charCodeAt(t)){for(var e=t;e++f;){var r=n.charCodeAt(f++),a=1;if(10===r)u=!0;else if(13===r)u=!0,10===n.charCodeAt(f)&&(++f,++a);else if(r!==l)continue;return n.slice(t,f-a)}return n.slice(t)}for(var r,u,i={},o={},a=[],c=n.length,f=0,s=0;(r=e())!==o;){for(var h=[];r!==i&&r!==o;)h.push(r),r=e();t&&null==(h=t(h,s++))||a.push(h)}return a},e.format=function(t){if(Array.isArray(t[0]))return e.formatRows(t);var r=new y,u=[];return t.forEach(function(n){for(var t in n)r.has(t)||u.push(r.add(t))}),[u.map(o).join(n)].concat(t.map(function(t){return u.map(function(n){return o(t[n])}).join(n)})).join("\n")},e.formatRows=function(n){return n.map(i).join("\n")},e},Iu.csv=Iu.dsv(",","text/csv"),Iu.tsv=Iu.dsv(" ","text/tab-separated-values");var Oi,Yi,Ii,Zi,Vi=this[M(this,"requestAnimationFrame")]||function(n){setTimeout(n,17)};Iu.timer=function(){Ln.apply(this,arguments)},Iu.timer.flush=function(){Tn(),qn()},Iu.round=function(n,t){return t?Math.round(n*(t=Math.pow(10,t)))/t:Math.round(n)};var Xi=["y","z","a","f","p","n","\xb5","m","","k","M","G","T","P","E","Z","Y"].map(Rn);Iu.formatPrefix=function(n,t){var e=0;return(n=+n)&&(0>n&&(n*=-1),t&&(n=Iu.round(n,Dn(n,t))),e=1+Math.floor(1e-12+Math.log(n)/Math.LN10),e=Math.max(-24,Math.min(24,3*Math.floor((e-1)/3)))),Xi[8+e/3]};var $i=/(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i,Bi=Iu.map({b:function(n){return n.toString(2)},c:function(n){return String.fromCharCode(n)},o:function(n){return n.toString(8)},x:function(n){return n.toString(16)},X:function(n){return n.toString(16).toUpperCase()},g:function(n,t){return n.toPrecision(t)},e:function(n,t){return n.toExponential(t)},f:function(n,t){return n.toFixed(t)},r:function(n,t){return(n=Iu.round(n,Dn(n,t))).toFixed(Math.max(0,Math.min(20,Dn(n*(1+1e-15),t))))}}),Wi=Iu.time={},Ji=Date;Pn.prototype={getDate:function(){return this._.getUTCDate()},getDay:function(){return this._.getUTCDay()},getFullYear:function(){return this._.getUTCFullYear()},getHours:function(){return this._.getUTCHours()},getMilliseconds:function(){return this._.getUTCMilliseconds()},getMinutes:function(){return this._.getUTCMinutes()},getMonth:function(){return this._.getUTCMonth()},getSeconds:function(){return this._.getUTCSeconds()},getTime:function(){return this._.getTime()},getTimezoneOffset:function(){return 0},valueOf:function(){return this._.valueOf()},setDate:function(){Gi.setUTCDate.apply(this._,arguments)},setDay:function(){Gi.setUTCDay.apply(this._,arguments)},setFullYear:function(){Gi.setUTCFullYear.apply(this._,arguments)},setHours:function(){Gi.setUTCHours.apply(this._,arguments)},setMilliseconds:function(){Gi.setUTCMilliseconds.apply(this._,arguments)},setMinutes:function(){Gi.setUTCMinutes.apply(this._,arguments)},setMonth:function(){Gi.setUTCMonth.apply(this._,arguments)},setSeconds:function(){Gi.setUTCSeconds.apply(this._,arguments)},setTime:function(){Gi.setTime.apply(this._,arguments)}};var Gi=Date.prototype;Wi.year=jn(function(n){return n=Wi.day(n),n.setMonth(0,1),n},function(n,t){n.setFullYear(n.getFullYear()+t)},function(n){return n.getFullYear()}),Wi.years=Wi.year.range,Wi.years.utc=Wi.year.utc.range,Wi.day=jn(function(n){var t=new Ji(2e3,0);return t.setFullYear(n.getFullYear(),n.getMonth(),n.getDate()),t},function(n,t){n.setDate(n.getDate()+t)},function(n){return n.getDate()-1}),Wi.days=Wi.day.range,Wi.days.utc=Wi.day.utc.range,Wi.dayOfYear=function(n){var t=Wi.year(n);return Math.floor((n-t-6e4*(n.getTimezoneOffset()-t.getTimezoneOffset()))/864e5)},["sunday","monday","tuesday","wednesday","thursday","friday","saturday"].forEach(function(n,t){t=7-t;var e=Wi[n]=jn(function(n){return(n=Wi.day(n)).setDate(n.getDate()-(n.getDay()+t)%7),n},function(n,t){n.setDate(n.getDate()+7*Math.floor(t))},function(n){var e=Wi.year(n).getDay();return Math.floor((Wi.dayOfYear(n)+(e+t)%7)/7)-(e!==t)});Wi[n+"s"]=e.range,Wi[n+"s"].utc=e.utc.range,Wi[n+"OfYear"]=function(n){var e=Wi.year(n).getDay();return Math.floor((Wi.dayOfYear(n)+(e+t)%7)/7)}}),Wi.week=Wi.sunday,Wi.weeks=Wi.sunday.range,Wi.weeks.utc=Wi.sunday.utc.range,Wi.weekOfYear=Wi.sundayOfYear;var Ki={"-":"",_:" ",0:"0"},Qi=/^\s*\d+/,no=/^%/;Iu.locale=function(n){return{numberFormat:En(n),timeFormat:Fn(n)}};var to=Iu.locale({decimal:".",thousands:",",grouping:[3],currency:["$",""],dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",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"]});Iu.format=to.numberFormat,Iu.geom={},Iu.geom.hull=function(n){function t(n){if(n.length<3)return[];var t,u=kn(e),i=kn(r),o=n.length,a=[],l=[];for(t=0;o>t;t++)a.push([+u.call(this,n[t],t),+i.call(this,n[t],t),t]);for(a.sort(ft),t=0;o>t;t++)l.push([a[t][0],-a[t][1]]);var c=ct(a),f=ct(l),s=f[0]===c[0],h=f[f.length-1]===c[c.length-1],g=[];for(t=c.length-1;t>=0;--t)g.push(n[a[c[t]][2]]);for(t=+s;t=r&&c.x<=i&&c.y>=u&&c.y<=o?[[r,o],[i,o],[i,u],[r,u]]:[];f.point=n[a]}),t}function e(n){return n.map(function(n,t){return{x:Math.round(i(n,t)/mi)*mi,y:Math.round(o(n,t)/mi)*mi,i:t}})}var r=at,u=lt,i=r,o=u,a=fo;return n?t(n):(t.links=function(n){return Ft(e(n)).edges.filter(function(n){return n.l&&n.r}).map(function(t){return{source:n[t.l.i],target:n[t.r.i]}})},t.triangles=function(n){var t=[];return Ft(e(n)).cells.forEach(function(e,r){for(var u,i,o=e.site,a=e.edges.sort(wt),l=-1,c=a.length,f=a[c-1].edge,s=f.l===o?f.r:f.l;++l=c,h=r>=f,g=h<<1|s;n.leaf=!1,n=n.nodes[g]||(n.nodes[g]=Vt()),s?u=c:a=c,h?o=f:l=f,i(n,t,e,r,u,o,a,l)}var f,s,h,g,p,d,v,y,m,x=kn(a),M=kn(l);if(null!=t)d=t,v=e,y=r,m=u;else if(y=m=-(d=v=1/0),s=[],h=[],p=n.length,o)for(g=0;p>g;++g)f=n[g],f.xy&&(y=f.x),f.y>m&&(m=f.y),s.push(f.x),h.push(f.y);else for(g=0;p>g;++g){var _=+x(f=n[g],g),b=+M(f,g);d>_&&(d=_),v>b&&(v=b),_>y&&(y=_),b>m&&(m=b),s.push(_),h.push(b)}var w=y-d,k=m-v;w>k?m=v+w:y=d+k;var N=Vt();if(N.add=function(n){i(N,n,+x(n,++g),+M(n,g),d,v,y,m)},N.visit=function(n){Xt(n,N,d,v,y,m)},N.find=function(n){return $t(N,n[0],n[1],d,v,y,m)},g=-1,null==t){for(;++g=0?n.slice(0,t):n,r=t>=0?n.slice(t+1):"in";return e=po.get(e)||go,r=vo.get(r)||m,ne(r(e.apply(null,Zu.call(arguments,1))))},Iu.interpolateHcl=ge,Iu.interpolateHsl=pe,Iu.interpolateLab=de,Iu.interpolateRound=ve,Iu.transform=function(n){var t=Xu.createElementNS(Iu.ns.prefix.svg,"g");return(Iu.transform=function(n){if(null!=n){t.setAttribute("transform",n);var e=t.transform.baseVal.consolidate()}return new ye(e?e.matrix:yo)})(n)},ye.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var yo={a:1,b:0,c:0,d:1,e:0,f:0};Iu.interpolateTransform=Ae,Iu.layout={},Iu.layout.bundle=function(){return function(n){for(var t=[],e=-1,r=n.length;++ea*a/y){if(d>l){var c=t.charge/l;n.px-=i*c,n.py-=o*c}return!0}if(t.point&&l&&d>l){var c=t.pointCharge/l;n.px-=i*c,n.py-=o*c}}return!t.charge}}function t(n){n.px=Iu.event.x,n.py=Iu.event.y,l.resume()}var e,r,u,i,o,a,l={},c=Iu.dispatch("start","tick","end"),f=[1,1],s=.9,h=mo,g=xo,p=-30,d=Mo,v=.1,y=.64,x=[],M=[];return l.tick=function(){if((u*=.99)<.005)return e=null,c.end({type:"end",alpha:u=0}),!0;var t,r,l,h,g,d,y,m,_,b=x.length,w=M.length;for(r=0;w>r;++r)l=M[r],h=l.source,g=l.target,m=g.x-h.x,_=g.y-h.y,(d=m*m+_*_)&&(d=u*o[r]*((d=Math.sqrt(d))-i[r])/d,m*=d,_*=d,g.x-=m*(y=h.weight+g.weight?h.weight/(h.weight+g.weight):.5),g.y-=_*y,h.x+=m*(y=1-y),h.y+=_*y);if((y=u*v)&&(m=f[0]/2,_=f[1]/2,r=-1,y))for(;++r0?u=n:(e.c=null,e.t=NaN,e=null,c.end({type:"end",alpha:u=0})):n>0&&(c.start({type:"start",alpha:u=n}),e=Ln(l.tick)),l):u},l.start=function(){function n(n,r){if(!e){for(e=new Array(u),l=0;u>l;++l)e[l]=[];for(l=0;c>l;++l){var i=M[l];e[i.source.index].push(i.target),e[i.target.index].push(i.source)}}for(var o,a=e[t],l=-1,f=a.length;++lt;++t)(r=x[t]).index=t,r.weight=0;for(t=0;c>t;++t)r=M[t],"number"==typeof r.source&&(r.source=x[r.source]),"number"==typeof r.target&&(r.target=x[r.target]),++r.source.weight,++r.target.weight;for(t=0;u>t;++t)r=x[t],isNaN(r.x)&&(r.x=n("x",s)),isNaN(r.y)&&(r.y=n("y",d)),isNaN(r.px)&&(r.px=r.x),isNaN(r.py)&&(r.py=r.y);if(i=[],"function"==typeof h)for(t=0;c>t;++t)i[t]=+h.call(this,M[t],t);else for(t=0;c>t;++t)i[t]=h;if(o=[],"function"==typeof g)for(t=0;c>t;++t)o[t]=+g.call(this,M[t],t);else for(t=0;c>t;++t)o[t]=g;if(a=[],"function"==typeof p)for(t=0;u>t;++t)a[t]=+p.call(this,x[t],t);else for(t=0;u>t;++t)a[t]=p;return l.resume()},l.resume=function(){return l.alpha(.1)},l.stop=function(){return l.alpha(0)},l.drag=function(){return r||(r=Iu.behavior.drag().origin(m).on("dragstart.force",qe).on("drag.force",t).on("dragend.force",De)),arguments.length?void this.on("mouseover.force",Re).on("mouseout.force",Ee).call(r):r},Iu.rebind(l,c,"on")};var mo=20,xo=1,Mo=1/0;Iu.layout.hierarchy=function(){function n(u){var i,o=[u],a=[];for(u.depth=0;null!=(i=o.pop());)if(a.push(i),(c=e.call(n,i,i.depth))&&(l=c.length)){for(var l,c,f;--l>=0;)o.push(f=c[l]),f.parent=i,f.depth=i.depth+1;r&&(i.value=0),i.children=c}else r&&(i.value=+r.call(n,i,i.depth)||0),delete i.children;return He(u,function(n){var e,u;t&&(e=n.children)&&e.sort(t),r&&(u=n.parent)&&(u.value+=n.value)}),a}var t=Ye,e=Fe,r=Oe;return n.sort=function(e){return arguments.length?(t=e,n):t},n.children=function(t){return arguments.length?(e=t,n):e},n.value=function(t){return arguments.length?(r=t,n):r},n.revalue=function(t){return r&&(je(t,function(n){n.children&&(n.value=0)}),He(t,function(t){var e;t.children||(t.value=+r.call(n,t,t.depth)||0),(e=t.parent)&&(e.value+=t.value)})),t},n},Iu.layout.partition=function(){function n(t,e,r,u){var i=t.children;if(t.x=e,t.y=t.depth*u,t.dx=r,t.dy=u,i&&(o=i.length)){var o,a,l,c=-1;for(r=t.value?r/t.value:0;++cs?-1:1),p=Iu.sum(c),d=p?(s-l*g)/p:0,v=Iu.range(l),y=[];return null!=e&&v.sort(e===_o?function(n,t){return c[t]-c[n]}:function(n,t){return e(o[n],o[t])}),v.forEach(function(n){y[n]={data:o[n],value:a=c[n],startAngle:f,endAngle:f+=a*d+g,padAngle:h}}),y}var t=Number,e=_o,r=0,u=_i,i=0;return n.value=function(e){return arguments.length?(t=e,n):t},n.sort=function(t){return arguments.length?(e=t,n):e},n.startAngle=function(t){return arguments.length?(r=t,n):r},n.endAngle=function(t){return arguments.length?(u=t,n):u},n.padAngle=function(t){return arguments.length?(i=t,n):i},n};var _o={};Iu.layout.stack=function(){function n(a,l){if(!(h=a.length))return a;var c=a.map(function(e,r){return t.call(n,e,r)}),f=c.map(function(t){return t.map(function(t,e){return[i.call(n,t,e),o.call(n,t,e)]})}),s=e.call(n,f,l);c=Iu.permute(c,s),f=Iu.permute(f,s);var h,g,p,d,v=r.call(n,f,l),y=c[0].length;for(p=0;y>p;++p)for(u.call(n,c[0][p],d=v[p],f[0][p][1]),g=1;h>g;++g)u.call(n,c[g][p],d+=f[g-1][p][1],f[g][p][1]);return a}var t=m,e=$e,r=Be,u=Xe,i=Ze,o=Ve;return n.values=function(e){return arguments.length?(t=e,n):t},n.order=function(t){return arguments.length?(e="function"==typeof t?t:bo.get(t)||$e,n):e},n.offset=function(t){return arguments.length?(r="function"==typeof t?t:wo.get(t)||Be,n):r},n.x=function(t){return arguments.length?(i=t,n):i},n.y=function(t){return arguments.length?(o=t,n):o},n.out=function(t){return arguments.length?(u=t,n):u},n};var bo=Iu.map({"inside-out":function(n){var t,e,r=n.length,u=n.map(We),i=n.map(Je),o=Iu.range(r).sort(function(n,t){return u[n]-u[t]}),a=0,l=0,c=[],f=[];for(t=0;r>t;++t)e=o[t],l>a?(a+=i[e],c.push(e)):(l+=i[e],f.push(e));return f.reverse().concat(c)},reverse:function(n){return Iu.range(n.length).reverse()},"default":$e}),wo=Iu.map({silhouette:function(n){var t,e,r,u=n.length,i=n[0].length,o=[],a=0,l=[];for(e=0;i>e;++e){for(t=0,r=0;u>t;t++)r+=n[t][e][1];r>a&&(a=r),o.push(r)}for(e=0;i>e;++e)l[e]=(a-o[e])/2;return l},wiggle:function(n){var t,e,r,u,i,o,a,l,c,f=n.length,s=n[0],h=s.length,g=[];for(g[0]=l=c=0,e=1;h>e;++e){for(t=0,u=0;f>t;++t)u+=n[t][e][1];for(t=0,i=0,a=s[e][0]-s[e-1][0];f>t;++t){for(r=0,o=(n[t][e][1]-n[t][e-1][1])/(2*a);t>r;++r)o+=(n[r][e][1]-n[r][e-1][1])/a;i+=o*n[t][e][1]}g[e]=l-=u?i/u*a:0,c>l&&(c=l)}for(e=0;h>e;++e)g[e]-=c;return g},expand:function(n){var t,e,r,u=n.length,i=n[0].length,o=1/u,a=[];for(e=0;i>e;++e){for(t=0,r=0;u>t;t++)r+=n[t][e][1];if(r)for(t=0;u>t;t++)n[t][e][1]/=r;else for(t=0;u>t;t++)n[t][e][1]=o}for(e=0;i>e;++e)a[e]=0;return a},zero:Be});Iu.layout.histogram=function(){function n(n,i){for(var o,a,l=[],c=n.map(e,this),f=r.call(this,c,i),s=u.call(this,f,c,i),i=-1,h=c.length,g=s.length-1,p=t?1:1/h;++i0)for(i=-1;++i=f[0]&&a<=f[1]&&(o=l[Iu.bisect(s,a,1,g)-1],o.y+=p,o.push(n[i]));return l}var t=!0,e=Number,r=nr,u=Ke;return n.value=function(t){return arguments.length?(e=t,n):e},n.range=function(t){return arguments.length?(r=kn(t),n):r},n.bins=function(t){return arguments.length?(u="number"==typeof t?function(n){return Qe(n,t)}:kn(t),n):u},n.frequency=function(e){return arguments.length?(t=!!e,n):t},n},Iu.layout.pack=function(){function n(n,i){var o=e.call(this,n,i),a=o[0],l=u[0],c=u[1],f=null==t?Math.sqrt:"function"==typeof t?t:function(){return t};if(a.x=a.y=0,He(a,function(n){n.r=+f(n.value)}),He(a,ir),r){var s=r*(t?1:Math.max(2*a.r/l,2*a.r/c))/2;He(a,function(n){n.r+=s}),He(a,ir),He(a,function(n){n.r-=s})}return lr(a,l/2,c/2,t?1:1/Math.max(2*a.r/l,2*a.r/c)),o}var t,e=Iu.layout.hierarchy().sort(tr),r=0,u=[1,1];return n.size=function(t){return arguments.length?(u=t,n):u},n.radius=function(e){return arguments.length?(t=null==e||"function"==typeof e?e:+e,n):t},n.padding=function(t){return arguments.length?(r=+t,n):r},Pe(n,e)},Iu.layout.tree=function(){function n(n,u){var f=o.call(this,n,u),s=f[0],h=t(s);if(He(h,e),h.parent.m=-h.z,je(h,r),c)je(s,i);else{var g=s,p=s,d=s;je(s,function(n){n.xp.x&&(p=n),n.depth>d.depth&&(d=n)});var v=a(g,p)/2-g.x,y=l[0]/(p.x+a(p,g)/2+v),m=l[1]/(d.depth||1);je(s,function(n){n.x=(n.x+v)*y,n.y=n.depth*m})}return f}function t(n){for(var t,e={A:null,children:[n]},r=[e];null!=(t=r.pop());)for(var u,i=t.children,o=0,a=i.length;a>o;++o)r.push((i[o]=u={ -_:i[o],parent:t,children:(u=i[o].children)&&u.slice()||[],A:null,a:null,z:0,m:0,c:0,s:0,t:null,i:o}).a=u);return e.children[0]}function e(n){var t=n.children,e=n.parent.children,r=n.i?e[n.i-1]:null;if(t.length){pr(n);var i=(t[0].z+t[t.length-1].z)/2;r?(n.z=r.z+a(n._,r._),n.m=n.z-i):n.z=i}else r&&(n.z=r.z+a(n._,r._));n.parent.A=u(n,r,n.parent.A||e[0])}function r(n){n._.x=n.z+n.parent.m,n.m+=n.parent.m}function u(n,t,e){if(t){for(var r,u=n,i=n,o=t,l=u.parent.children[0],c=u.m,f=i.m,s=o.m,h=l.m;o=hr(o),u=sr(u),o&&u;)l=sr(l),i=hr(i),i.a=n,r=o.z+s-u.z-c+a(o._,u._),r>0&&(gr(dr(o,n,e),n,r),c+=r,f+=r),s+=o.m,c+=u.m,h+=l.m,f+=i.m;o&&!hr(i)&&(i.t=o,i.m+=s-f),u&&!sr(l)&&(l.t=u,l.m+=c-h,e=n)}return e}function i(n){n.x*=l[0],n.y=n.depth*l[1]}var o=Iu.layout.hierarchy().sort(null).value(null),a=fr,l=[1,1],c=null;return n.separation=function(t){return arguments.length?(a=t,n):a},n.size=function(t){return arguments.length?(c=null==(l=t)?i:null,n):c?null:l},n.nodeSize=function(t){return arguments.length?(c=null==(l=t)?null:i,n):c?l:null},Pe(n,o)},Iu.layout.cluster=function(){function n(n,i){var o,a=t.call(this,n,i),l=a[0],c=0;He(l,function(n){var t=n.children;t&&t.length?(n.x=yr(t),n.y=vr(t)):(n.x=o?c+=e(n,o):0,n.y=0,o=n)});var f=mr(l),s=xr(l),h=f.x-e(f,s)/2,g=s.x+e(s,f)/2;return He(l,u?function(n){n.x=(n.x-l.x)*r[0],n.y=(l.y-n.y)*r[1]}:function(n){n.x=(n.x-h)/(g-h)*r[0],n.y=(1-(l.y?n.y/l.y:1))*r[1]}),a}var t=Iu.layout.hierarchy().sort(null).value(null),e=fr,r=[1,1],u=!1;return n.separation=function(t){return arguments.length?(e=t,n):e},n.size=function(t){return arguments.length?(u=null==(r=t),n):u?null:r},n.nodeSize=function(t){return arguments.length?(u=null!=(r=t),n):u?r:null},Pe(n,t)},Iu.layout.treemap=function(){function n(n,t){for(var e,r,u=-1,i=n.length;++ut?0:t),e.area=isNaN(r)||0>=r?0:r}function t(e){var i=e.children;if(i&&i.length){var o,a,l,c=s(e),f=[],h=i.slice(),p=1/0,d="slice"===g?c.dx:"dice"===g?c.dy:"slice-dice"===g?1&e.depth?c.dy:c.dx:Math.min(c.dx,c.dy);for(n(h,c.dx*c.dy/e.value),f.area=0;(l=h.length)>0;)f.push(o=h[l-1]),f.area+=o.area,"squarify"!==g||(a=r(f,d))<=p?(h.pop(),p=a):(f.area-=f.pop().area,u(f,d,c,!1),d=Math.min(c.dx,c.dy),f.length=f.area=0,p=1/0);f.length&&(u(f,d,c,!0),f.length=f.area=0),i.forEach(t)}}function e(t){var r=t.children;if(r&&r.length){var i,o=s(t),a=r.slice(),l=[];for(n(a,o.dx*o.dy/t.value),l.area=0;i=a.pop();)l.push(i),l.area+=i.area,null!=i.z&&(u(l,i.z?o.dx:o.dy,o,!a.length),l.length=l.area=0);r.forEach(e)}}function r(n,t){for(var e,r=n.area,u=0,i=1/0,o=-1,a=n.length;++oe&&(i=e),e>u&&(u=e));return r*=r,t*=t,r?Math.max(t*u*p/r,r/(t*i*p)):1/0}function u(n,t,e,r){var u,i=-1,o=n.length,a=e.x,c=e.y,f=t?l(n.area/t):0;if(t==e.dx){for((r||f>e.dy)&&(f=e.dy);++ie.dx)&&(f=e.dx);++ie&&(t=1),1>e&&(n=0),function(){var e,r,u;do e=2*Math.random()-1,r=2*Math.random()-1,u=e*e+r*r;while(!u||u>1);return n+t*e*Math.sqrt(-2*Math.log(u)/u)}},logNormal:function(){var n=Iu.random.normal.apply(Iu,arguments);return function(){return Math.exp(n())}},bates:function(n){var t=Iu.random.irwinHall(n);return function(){return t()/n}},irwinHall:function(n){return function(){for(var t=0,e=0;n>e;e++)t+=Math.random();return t}}},Iu.scale={};var ko={floor:m,ceil:m};Iu.scale.linear=function(){return zr([0,1],[0,1],Kt,!1)};var No={s:1,g:1,p:1,r:1,e:1};Iu.scale.log=function(){return Ur(Iu.scale.linear().domain([0,1]),10,!0,[1,10])};var Ao=Iu.format(".0e"),Co={floor:function(n){return-Math.ceil(-n)},ceil:function(n){return-Math.floor(-n)}};Iu.scale.pow=function(){return Pr(Iu.scale.linear(),1,[0,1])},Iu.scale.sqrt=function(){return Iu.scale.pow().exponent(.5)},Iu.scale.ordinal=function(){return Hr([],{t:"range",a:[[]]})},Iu.scale.category10=function(){return Iu.scale.ordinal().range(zo)},Iu.scale.category20=function(){return Iu.scale.ordinal().range(Lo)},Iu.scale.category20b=function(){return Iu.scale.ordinal().range(So)},Iu.scale.category20c=function(){return Iu.scale.ordinal().range(To)};var zo=[2062260,16744206,2924588,14034728,9725885,9197131,14907330,8355711,12369186,1556175].map(yn),Lo=[2062260,11454440,16744206,16759672,2924588,10018698,14034728,16750742,9725885,12955861,9197131,12885140,14907330,16234194,8355711,13092807,12369186,14408589,1556175,10410725].map(yn),So=[3750777,5395619,7040719,10264286,6519097,9216594,11915115,13556636,9202993,12426809,15186514,15190932,8666169,11356490,14049643,15177372,8077683,10834324,13528509,14589654].map(yn),To=[3244733,7057110,10406625,13032431,15095053,16616764,16625259,16634018,3253076,7652470,10607003,13101504,7695281,10394312,12369372,14342891,6513507,9868950,12434877,14277081].map(yn);Iu.scale.quantile=function(){return Fr([],[])},Iu.scale.quantize=function(){return Or(0,1,[0,1])},Iu.scale.threshold=function(){return Yr([.5],[0,1])},Iu.scale.identity=function(){return Ir([0,1])},Iu.svg={},Iu.svg.arc=function(){function n(){var n=Math.max(0,+e.apply(this,arguments)),c=Math.max(0,+r.apply(this,arguments)),f=o.apply(this,arguments)-wi,s=a.apply(this,arguments)-wi,h=Math.abs(s-f),g=f>s?0:1;if(n>c&&(p=c,c=n,n=p),h>=bi)return t(c,g)+(n?t(n,1-g):"")+"Z";var p,d,v,y,m,x,M,_,b,w,k,N,A=0,C=0,z=[];if((y=(+l.apply(this,arguments)||0)/2)&&(v=i===qo?Math.sqrt(n*n+c*c):+i.apply(this,arguments),g||(C*=-1),c&&(C=Q(v/c*Math.sin(y))),n&&(A=Q(v/n*Math.sin(y)))),c){m=c*Math.cos(f+C),x=c*Math.sin(f+C),M=c*Math.cos(s-C),_=c*Math.sin(s-C);var L=Math.abs(s-f-2*C)<=Mi?0:1;if(C&&Jr(m,x,M,_)===g^L){var S=(f+s)/2;m=c*Math.cos(S),x=c*Math.sin(S),M=_=null}}else m=x=0;if(n){b=n*Math.cos(s-A),w=n*Math.sin(s-A),k=n*Math.cos(f+A),N=n*Math.sin(f+A);var T=Math.abs(f-s+2*A)<=Mi?0:1;if(A&&Jr(b,w,k,N)===1-g^T){var q=(f+s)/2;b=n*Math.cos(q),w=n*Math.sin(q),k=N=null}}else b=w=0;if(h>mi&&(p=Math.min(Math.abs(c-n)/2,+u.apply(this,arguments)))>.001){d=c>n^g?0:1;var D=p,R=p;if(Mi>h){var E=null==k?[b,w]:null==M?[m,x]:ht([m,x],[k,N],[M,_],[b,w]),U=m-E[0],P=x-E[1],j=M-E[0],H=_-E[1],F=1/Math.sin(Math.acos((U*j+P*H)/(Math.sqrt(U*U+P*P)*Math.sqrt(j*j+H*H)))/2),O=Math.sqrt(E[0]*E[0]+E[1]*E[1]);R=Math.min(p,(n-O)/(F-1)),D=Math.min(p,(c-O)/(F+1))}if(null!=M){var Y=Gr(null==k?[b,w]:[k,N],[m,x],c,D,g),I=Gr([M,_],[b,w],c,D,g);p===D?z.push("M",Y[0],"A",D,",",D," 0 0,",d," ",Y[1],"A",c,",",c," 0 ",1-g^Jr(Y[1][0],Y[1][1],I[1][0],I[1][1]),",",g," ",I[1],"A",D,",",D," 0 0,",d," ",I[0]):z.push("M",Y[0],"A",D,",",D," 0 1,",d," ",I[0])}else z.push("M",m,",",x);if(null!=k){var Z=Gr([m,x],[k,N],n,-R,g),V=Gr([b,w],null==M?[m,x]:[M,_],n,-R,g);p===R?z.push("L",V[0],"A",R,",",R," 0 0,",d," ",V[1],"A",n,",",n," 0 ",g^Jr(V[1][0],V[1][1],Z[1][0],Z[1][1]),",",1-g," ",Z[1],"A",R,",",R," 0 0,",d," ",Z[0]):z.push("L",V[0],"A",R,",",R," 0 0,",d," ",Z[0])}else z.push("L",b,",",w)}else z.push("M",m,",",x),null!=M&&z.push("A",c,",",c," 0 ",L,",",g," ",M,",",_),z.push("L",b,",",w),null!=k&&z.push("A",n,",",n," 0 ",T,",",1-g," ",k,",",N);return z.push("Z"),z.join("")}function t(n,t){return"M0,"+n+"A"+n+","+n+" 0 1,"+t+" 0,"+-n+"A"+n+","+n+" 0 1,"+t+" 0,"+n}var e=Vr,r=Xr,u=Zr,i=qo,o=$r,a=Br,l=Wr;return n.innerRadius=function(t){return arguments.length?(e=kn(t),n):e},n.outerRadius=function(t){return arguments.length?(r=kn(t),n):r},n.cornerRadius=function(t){return arguments.length?(u=kn(t),n):u},n.padRadius=function(t){return arguments.length?(i=t==qo?qo:kn(t),n):i},n.startAngle=function(t){return arguments.length?(o=kn(t),n):o},n.endAngle=function(t){return arguments.length?(a=kn(t),n):a},n.padAngle=function(t){return arguments.length?(l=kn(t),n):l},n.centroid=function(){var n=(+e.apply(this,arguments)+ +r.apply(this,arguments))/2,t=(+o.apply(this,arguments)+ +a.apply(this,arguments))/2-wi;return[Math.cos(t)*n,Math.sin(t)*n]},n};var qo="auto";Iu.svg.line=function(){return Qr(m)};var Do=Iu.map({linear:nu,"linear-closed":tu,step:eu,"step-before":ru,"step-after":uu,basis:fu,"basis-open":su,"basis-closed":hu,bundle:gu,cardinal:au,"cardinal-open":iu,"cardinal-closed":ou,monotone:xu});Do.forEach(function(n,t){t.key=n,t.closed=/-closed$/.test(n)});var Ro=[0,2/3,1/3,0],Eo=[0,1/3,2/3,0],Uo=[0,1/6,2/3,1/6];Iu.svg.line.radial=function(){var n=Qr(Mu);return n.radius=n.x,delete n.x,n.angle=n.y,delete n.y,n},ru.reverse=uu,uu.reverse=ru,Iu.svg.area=function(){return _u(m)},Iu.svg.area.radial=function(){var n=_u(Mu);return n.radius=n.x,delete n.x,n.innerRadius=n.x0,delete n.x0,n.outerRadius=n.x1,delete n.x1,n.angle=n.y,delete n.y,n.startAngle=n.y0,delete n.y0,n.endAngle=n.y1,delete n.y1,n},Iu.svg.chord=function(){function n(n,a){var l=t(this,i,n,a),c=t(this,o,n,a);return"M"+l.p0+r(l.r,l.p1,l.a1-l.a0)+(e(l,c)?u(l.r,l.p1,l.r,l.p0):u(l.r,l.p1,c.r,c.p0)+r(c.r,c.p1,c.a1-c.a0)+u(c.r,c.p1,l.r,l.p0))+"Z"}function t(n,t,e,r){var u=t.call(n,e,r),i=a.call(n,u,r),o=l.call(n,u,r)-wi,f=c.call(n,u,r)-wi;return{r:i,a0:o,a1:f,p0:[i*Math.cos(o),i*Math.sin(o)],p1:[i*Math.cos(f),i*Math.sin(f)]}}function e(n,t){return n.a0==t.a0&&n.a1==t.a1}function r(n,t,e){return"A"+n+","+n+" 0 "+ +(e>Mi)+",1 "+t}function u(n,t,e,r){return"Q 0,0 "+r}var i=bu,o=wu,a=ku,l=$r,c=Br;return n.radius=function(t){return arguments.length?(a=kn(t),n):a},n.source=function(t){return arguments.length?(i=kn(t),n):i},n.target=function(t){return arguments.length?(o=kn(t),n):o},n.startAngle=function(t){return arguments.length?(l=kn(t),n):l},n.endAngle=function(t){return arguments.length?(c=kn(t),n):c},n},Iu.svg.diagonal=function(){function n(n,u){var i=t.call(this,n,u),o=e.call(this,n,u),a=(i.y+o.y)/2,l=[i,{x:i.x,y:a},{x:o.x,y:a},o];return l=l.map(r),"M"+l[0]+"C"+l[1]+" "+l[2]+" "+l[3]}var t=bu,e=wu,r=Nu;return n.source=function(e){return arguments.length?(t=kn(e),n):t},n.target=function(t){return arguments.length?(e=kn(t),n):e},n.projection=function(t){return arguments.length?(r=t,n):r},n},Iu.svg.diagonal.radial=function(){var n=Iu.svg.diagonal(),t=Nu,e=n.projection;return n.projection=function(n){return arguments.length?e(Au(t=n)):t},n},Iu.svg.symbol=function(){function n(n,r){return(Po.get(t.call(this,n,r))||Lu)(e.call(this,n,r))}var t=zu,e=Cu;return n.type=function(e){return arguments.length?(t=kn(e),n):t},n.size=function(t){return arguments.length?(e=kn(t),n):e},n};var Po=Iu.map({circle:Lu,cross:function(n){var t=Math.sqrt(n/5)/2;return"M"+-3*t+","+-t+"H"+-t+"V"+-3*t+"H"+t+"V"+-t+"H"+3*t+"V"+t+"H"+t+"V"+3*t+"H"+-t+"V"+t+"H"+-3*t+"Z"},diamond:function(n){var t=Math.sqrt(n/(2*Ho)),e=t*Ho;return"M0,"+-t+"L"+e+",0 0,"+t+" "+-e+",0Z"},square:function(n){var t=Math.sqrt(n)/2;return"M"+-t+","+-t+"L"+t+","+-t+" "+t+","+t+" "+-t+","+t+"Z"},"triangle-down":function(n){var t=Math.sqrt(n/jo),e=t*jo/2;return"M0,"+e+"L"+t+","+-e+" "+-t+","+-e+"Z"},"triangle-up":function(n){var t=Math.sqrt(n/jo),e=t*jo/2;return"M0,"+-e+"L"+t+","+e+" "+-t+","+e+"Z"}});Iu.svg.symbolTypes=Po.keys();var jo=Math.sqrt(3),Ho=Math.tan(30*ki);fi.transition=function(n){for(var t,e,r=Fo||++Zo,u=Ru(n),i=[],o=Oo||{time:Date.now(),ease:ie,delay:0,duration:250},a=-1,l=this.length;++ai;i++){u.push(t=[]);for(var e=this[i],a=0,l=e.length;l>a;a++)(r=e[a])&&n.call(r,r.__data__,a,i)&&t.push(r)}return Tu(u,this.namespace,this.id)},Io.tween=function(n,t){var e=this.id,r=this.namespace;return arguments.length<2?this.node()[r][e].tween.get(n):I(this,null==t?function(t){t[r][e].tween.remove(n)}:function(u){u[r][e].tween.set(n,t)})},Io.attr=function(n,t){function e(){this.removeAttribute(a)}function r(){this.removeAttributeNS(a.space,a.local)}function u(n){return null==n?e:(n+="",function(){var t,e=this.getAttribute(a);return e!==n&&(t=o(e,n),function(n){this.setAttribute(a,t(n))})})}function i(n){return null==n?r:(n+="",function(){var t,e=this.getAttributeNS(a.space,a.local);return e!==n&&(t=o(e,n),function(n){this.setAttributeNS(a.space,a.local,t(n))})})}if(arguments.length<2){for(t in n)this.attr(t,n[t]);return this}var o="transform"==n?Ae:Kt,a=Iu.ns.qualify(n);return qu(this,"attr."+n,t,a.local?i:u)},Io.attrTween=function(n,t){function e(n,e){var r=t.call(this,n,e,this.getAttribute(u));return r&&function(n){this.setAttribute(u,r(n))}}function r(n,e){var r=t.call(this,n,e,this.getAttributeNS(u.space,u.local));return r&&function(n){this.setAttributeNS(u.space,u.local,r(n))}}var u=Iu.ns.qualify(n);return this.tween("attr."+n,u.local?r:e)},Io.style=function(n,e,r){function u(){this.style.removeProperty(n)}function i(e){return null==e?u:(e+="",function(){var u,i=t(this).getComputedStyle(this,null).getPropertyValue(n);return i!==e&&(u=Kt(i,e),function(t){this.style.setProperty(n,u(t),r)})})}var o=arguments.length;if(3>o){if("string"!=typeof n){2>o&&(e="");for(r in n)this.style(r,n[r],e);return this}r=""}return qu(this,"style."+n,e,i)},Io.styleTween=function(n,e,r){function u(u,i){var o=e.call(this,u,i,t(this).getComputedStyle(this,null).getPropertyValue(n));return o&&function(t){this.style.setProperty(n,o(t),r)}}return arguments.length<3&&(r=""),this.tween("style."+n,u)},Io.text=function(n){return qu(this,"text",n,Du)},Io.remove=function(){var n=this.namespace;return this.each("end.transition",function(){var t;this[n].count<2&&(t=this.parentNode)&&t.removeChild(this)})},Io.ease=function(n){var t=this.id,e=this.namespace;return arguments.length<1?this.node()[e][t].ease:("function"!=typeof n&&(n=Iu.ease.apply(Iu,arguments)),I(this,function(r){r[e][t].ease=n}))},Io.delay=function(n){var t=this.id,e=this.namespace;return arguments.length<1?this.node()[e][t].delay:I(this,"function"==typeof n?function(r,u,i){r[e][t].delay=+n.call(r,r.__data__,u,i)}:(n=+n,function(r){r[e][t].delay=n}))},Io.duration=function(n){var t=this.id,e=this.namespace;return arguments.length<1?this.node()[e][t].duration:I(this,"function"==typeof n?function(r,u,i){r[e][t].duration=Math.max(1,n.call(r,r.__data__,u,i))}:(n=Math.max(1,n),function(r){r[e][t].duration=n}))},Io.each=function(n,t){var e=this.id,r=this.namespace;if(arguments.length<2){var u=Oo,i=Fo;try{Fo=e,I(this,function(t,u,i){Oo=t[r][e],n.call(t,t.__data__,u,i)})}finally{Oo=u,Fo=i}}else I(this,function(u){var i=u[r][e];(i.event||(i.event=Iu.dispatch("start","end","interrupt"))).on(n,t)});return this},Io.transition=function(){for(var n,t,e,r,u=this.id,i=++Zo,o=this.namespace,a=[],l=0,c=this.length;c>l;l++){a.push(n=[]);for(var t=this[l],f=0,s=t.length;s>f;f++)(e=t[f])&&(r=e[o][u],Eu(e,f,o,i,{time:r.time,ease:r.ease,delay:r.delay+r.duration,duration:r.duration})),n.push(e)}return Tu(a,o,i)},Iu.svg.axis=function(){function n(n){n.each(function(){var n,c=Iu.select(this),f=this.__chart__||e,s=this.__chart__=e.copy(),h=null==l?s.ticks?s.ticks.apply(s,a):s.domain():l,g=null==t?s.tickFormat?s.tickFormat.apply(s,a):m:t,p=c.selectAll(".tick").data(h,s),d=p.enter().insert("g",".domain").attr("class","tick").style("opacity",mi),v=Iu.transition(p.exit()).style("opacity",mi).remove(),y=Iu.transition(p.order()).style("opacity",1),x=Math.max(u,0)+o,M=wr(s),_=c.selectAll(".domain").data([0]),b=(_.enter().append("path").attr("class","domain"),Iu.transition(_));d.append("line"),d.append("text");var w,k,N,A,C=d.select("line"),z=y.select("line"),L=p.select("text").text(g),S=d.select("text"),T=y.select("text"),q="top"===r||"left"===r?-1:1;if("bottom"===r||"top"===r?(n=Uu,w="x",N="y",k="x2",A="y2",L.attr("dy",0>q?"0em":".71em").style("text-anchor","middle"),b.attr("d","M"+M[0]+","+q*i+"V0H"+M[1]+"V"+q*i)):(n=Pu,w="y",N="x",k="y2",A="x2",L.attr("dy",".32em").style("text-anchor",0>q?"end":"start"),b.attr("d","M"+q*i+","+M[0]+"H0V"+M[1]+"H"+q*i)),C.attr(A,q*u),S.attr(N,q*x),z.attr(k,0).attr(A,q*u),T.attr(w,0).attr(N,q*x),s.rangeBand){var D=s,R=D.rangeBand()/2;f=s=function(n){return D(n)+R}}else f.rangeBand?f=s:v.call(n,s,f);d.call(n,f,s),y.call(n,s,s)})}var t,e=Iu.scale.linear(),r=Vo,u=6,i=6,o=3,a=[10],l=null;return n.scale=function(t){return arguments.length?(e=t,n):e},n.orient=function(t){return arguments.length?(r=t in Xo?t+"":Vo,n):r},n.ticks=function(){return arguments.length?(a=Vu(arguments),n):a},n.tickValues=function(t){return arguments.length?(l=t,n):l},n.tickFormat=function(e){return arguments.length?(t=e,n):t},n.tickSize=function(t){var e=arguments.length;return e?(u=+t,i=+arguments[e-1],n):u},n.innerTickSize=function(t){return arguments.length?(u=+t,n):u},n.outerTickSize=function(t){return arguments.length?(i=+t,n):i},n.tickPadding=function(t){return arguments.length?(o=+t,n):o},n.tickSubdivide=function(){return arguments.length&&n},n};var Vo="bottom",Xo={top:1,right:1,bottom:1,left:1};Iu.svg.brush=function(){function n(t){t.each(function(){var t=Iu.select(this).style("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush",i).on("touchstart.brush",i),o=t.selectAll(".background").data([0]);o.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),t.selectAll(".extent").data([0]).enter().append("rect").attr("class","extent").style("cursor","move");var a=t.selectAll(".resize").data(d,m);a.exit().remove(),a.enter().append("g").attr("class",function(n){return"resize "+n}).style("cursor",function(n){return $o[n]}).append("rect").attr("x",function(n){return/[ew]$/.test(n)?-3:null}).attr("y",function(n){return/^[ns]/.test(n)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),a.style("display",n.empty()?"none":null);var l,s=Iu.transition(t),h=Iu.transition(o);c&&(l=wr(c),h.attr("x",l[0]).attr("width",l[1]-l[0]),r(s)),f&&(l=wr(f),h.attr("y",l[0]).attr("height",l[1]-l[0]),u(s)),e(s)})}function e(n){n.selectAll(".resize").attr("transform",function(n){return"translate("+s[+/e$/.test(n)]+","+h[+/^s/.test(n)]+")"})}function r(n){n.select(".extent").attr("x",s[0]),n.selectAll(".extent,.n>rect,.s>rect").attr("width",s[1]-s[0])}function u(n){n.select(".extent").attr("y",h[0]),n.selectAll(".extent,.e>rect,.w>rect").attr("height",h[1]-h[0])}function i(){function i(){32==Iu.event.keyCode&&(L||(x=null,T[0]-=s[1],T[1]-=h[1],L=2),k())}function d(){32==Iu.event.keyCode&&2==L&&(T[0]+=s[1],T[1]+=h[1],L=0,k())}function v(){var n=Iu.mouse(_),t=!1;M&&(n[0]+=M[0],n[1]+=M[1]),L||(Iu.event.altKey?(x||(x=[(s[0]+s[1])/2,(h[0]+h[1])/2]),T[0]=s[+(n[0]f?(u=r,r=f):u=f),d[0]!=r||d[1]!=u?(e?a=null:o=null,d[0]=r,d[1]=u,!0):void 0}function m(){v(),N.style("pointer-events","all").selectAll(".resize").style("display",n.empty()?"none":null),Iu.select("body").style("cursor",null),q.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),S(),w({type:"brushend"})}var x,M,_=this,b=Iu.select(Iu.event.target),w=l.of(_,arguments),N=Iu.select(_),A=b.datum(),C=!/^(n|s)$/.test(A)&&c,z=!/^(e|w)$/.test(A)&&f,L=b.classed("extent"),S=W(_),T=Iu.mouse(_),q=Iu.select(t(_)).on("keydown.brush",i).on("keyup.brush",d);if(Iu.event.changedTouches?q.on("touchmove.brush",v).on("touchend.brush",m):q.on("mousemove.brush",v).on("mouseup.brush",m),N.interrupt().selectAll("*").interrupt(),L)T[0]=s[0]-T[0],T[1]=h[0]-T[1];else if(A){var D=+/w$/.test(A),R=+/^n/.test(A);M=[s[1-D]-T[0],h[1-R]-T[1]],T[0]=s[D],T[1]=h[R]}else Iu.event.altKey&&(x=T.slice());N.style("pointer-events","none").selectAll(".resize").style("display",null),Iu.select("body").style("cursor",b.style("cursor")),w({type:"brushstart"}),v()}var o,a,l=A(n,"brushstart","brush","brushend"),c=null,f=null,s=[0,0],h=[0,0],g=!0,p=!0,d=Bo[0];return n.event=function(n){n.each(function(){var n=l.of(this,arguments),t={x:s,y:h,i:o,j:a},e=this.__chart__||t;this.__chart__=t,Fo?Iu.select(this).transition().each("start.brush",function(){o=e.i,a=e.j,s=e.x,h=e.y,n({type:"brushstart"})}).tween("brush:brush",function(){var e=Qt(s,t.x),r=Qt(h,t.y);return o=a=null,function(u){s=t.x=e(u),h=t.y=r(u),n({type:"brush",mode:"resize"})}}).each("end.brush",function(){o=t.i,a=t.j,n({type:"brush",mode:"resize"}),n({type:"brushend"})}):(n({type:"brushstart"}),n({type:"brush",mode:"resize"}),n({type:"brushend"}))})},n.x=function(t){return arguments.length?(c=t,d=Bo[!c<<1|!f],n):c},n.y=function(t){return arguments.length?(f=t,d=Bo[!c<<1|!f],n):f},n.clamp=function(t){return arguments.length?(c&&f?(g=!!t[0],p=!!t[1]):c?g=!!t:f&&(p=!!t),n):c&&f?[g,p]:c?g:f?p:null},n.extent=function(t){var e,r,u,i,l;return arguments.length?(c&&(e=t[0],r=t[1],f&&(e=e[0],r=r[0]),o=[e,r],c.invert&&(e=c(e),r=c(r)),e>r&&(l=e,e=r,r=l),e==s[0]&&r==s[1]||(s=[e,r])),f&&(u=t[0],i=t[1],c&&(u=u[1],i=i[1]),a=[u,i],f.invert&&(u=f(u),i=f(i)),u>i&&(l=u,u=i,i=l),u==h[0]&&i==h[1]||(h=[u,i])),n):(c&&(o?(e=o[0],r=o[1]):(e=s[0],r=s[1],c.invert&&(e=c.invert(e),r=c.invert(r)),e>r&&(l=e,e=r,r=l))),f&&(a?(u=a[0],i=a[1]):(u=h[0],i=h[1],f.invert&&(u=f.invert(u),i=f.invert(i)),u>i&&(l=u,u=i,i=l))),c&&f?[[e,u],[r,i]]:c?[e,r]:f&&[u,i])},n.clear=function(){return n.empty()||(s=[0,0],h=[0,0],o=a=null),n},n.empty=function(){return!!c&&s[0]==s[1]||!!f&&h[0]==h[1]},Iu.rebind(n,l,"on")};var $o={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Bo=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]],Wo=Wi.format=to.timeFormat,Jo=Wo.utc,Go=Jo("%Y-%m-%dT%H:%M:%S.%LZ");Wo.iso=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?ju:Go,ju.parse=function(n){var t=new Date(n);return isNaN(t)?null:t},ju.toString=Go.toString,Wi.second=jn(function(n){return new Ji(1e3*Math.floor(n/1e3))},function(n,t){n.setTime(n.getTime()+1e3*Math.floor(t))},function(n){return n.getSeconds()}),Wi.seconds=Wi.second.range,Wi.seconds.utc=Wi.second.utc.range,Wi.minute=jn(function(n){return new Ji(6e4*Math.floor(n/6e4))},function(n,t){n.setTime(n.getTime()+6e4*Math.floor(t))},function(n){return n.getMinutes()}),Wi.minutes=Wi.minute.range,Wi.minutes.utc=Wi.minute.utc.range,Wi.hour=jn(function(n){var t=n.getTimezoneOffset()/60;return new Ji(36e5*(Math.floor(n/36e5-t)+t))},function(n,t){n.setTime(n.getTime()+36e5*Math.floor(t))},function(n){return n.getHours()}),Wi.hours=Wi.hour.range,Wi.hours.utc=Wi.hour.utc.range,Wi.month=jn(function(n){return n=Wi.day(n),n.setDate(1),n},function(n,t){n.setMonth(n.getMonth()+t)},function(n){return n.getMonth()}),Wi.months=Wi.month.range,Wi.months.utc=Wi.month.utc.range;var Ko=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],Qo=[[Wi.second,1],[Wi.second,5],[Wi.second,15],[Wi.second,30],[Wi.minute,1],[Wi.minute,5],[Wi.minute,15],[Wi.minute,30],[Wi.hour,1],[Wi.hour,3],[Wi.hour,6],[Wi.hour,12],[Wi.day,1],[Wi.day,2],[Wi.week,1],[Wi.month,1],[Wi.month,3],[Wi.year,1]],na=Wo.multi([[".%L",function(n){return n.getMilliseconds()}],[":%S",function(n){return n.getSeconds()}],["%I:%M",function(n){return n.getMinutes()}],["%I %p",function(n){return n.getHours()}],["%a %d",function(n){return n.getDay()&&1!=n.getDate()}],["%b %d",function(n){return 1!=n.getDate()}],["%B",function(n){return n.getMonth()}],["%Y",Kr]]),ta={range:function(n,t,e){return Iu.range(Math.ceil(n/e)*e,+t,e).map(Fu)},floor:m,ceil:m};Qo.year=Wi.year,Wi.scale=function(){return Hu(Iu.scale.linear(),Qo,na)};var ea=Qo.map(function(n){return[n[0].utc,n[1]]}),ra=Jo.multi([[".%L",function(n){return n.getUTCMilliseconds()}],[":%S",function(n){return n.getUTCSeconds()}],["%I:%M",function(n){return n.getUTCMinutes()}],["%I %p",function(n){return n.getUTCHours()}],["%a %d",function(n){return n.getUTCDay()&&1!=n.getUTCDate()}],["%b %d",function(n){return 1!=n.getUTCDate()}],["%B",function(n){return n.getUTCMonth()}],["%Y",Kr]]);ea.year=Wi.year.utc,Wi.scale.utc=function(){return Hu(Iu.scale.linear(),ea,ra)},Iu.text=Nn(function(n){return n.responseText}),Iu.json=function(n,t){return An(n,"application/json",Ou,t)},Iu.html=function(n,t){return An(n,"text/html",Yu,t)},Iu.xml=Nn(function(n){return n.responseXML}),"function"==typeof define&&define.amd?(this.d3=Iu,define(Iu)):"object"==typeof module&&module.exports?module.exports=Iu:this.d3=Iu}.apply(self); \ No newline at end of file diff --git a/package.json b/package.json index 3e6c224799f9ba..a731d7a6d4d612 100644 --- a/package.json +++ b/package.json @@ -59,8 +59,8 @@ }, "scripts": { "test": "vows && echo", - "prepublish": "npm test && rm -f package.js src/start.js d3.js d3.min.js d3.zip && bin/start > src/start.js && bin/meteor > package.js && smash src/d3.js | uglifyjs - -b indent-level=2 -o d3.js && bin/uglify d3.js > d3.min.js && chmod a-w d3.js d3.min.js package.js && zip d3.zip LICENSE d3.js d3.min.js", - "postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp -v README.md LICENSE d3.js d3.min.js ../d3-bower && cd ../d3-bower && git add README.md LICENSE d3.js d3.min.js && git commit -m \"Release $VERSION.\" && git tag -am \"Release $VERSION.\" v${VERSION} && git push && git push --tags && cd - && cp -v d3.js ../d3.github.com/d3.v3.js && cp -v d3.min.js ../d3.github.com/d3.v3.min.js && cd ../d3.github.com && git add d3.v3.js d3.v3.min.js && git commit -m \"d3 ${VERSION}\" && git push" + "prepublish": "npm test && rm -f package.js src/start.js d3.js d3.zip && bin/start > src/start.js && bin/meteor > package.js && smash src/d3.js | uglifyjs - -b indent-level=2 -o d3.js && chmod a-w d3.js package.js && zip d3.zip LICENSE d3.js", + "postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp -v README.md LICENSE d3.js ../d3-bower && cd ../d3-bower && git add README.md LICENSE d3.js && git commit -m \"Release $VERSION.\" && git tag -am \"Release $VERSION.\" v${VERSION} && git push && git push --tags && cd - && cp -v d3.js ../d3.github.com/d3.v3.js && cd ../d3.github.com && git add d3.v3.js && git commit -m \"d3 ${VERSION}\" && git push" }, "license": "BSD-3-Clause" } diff --git a/test/arrays/min-test.js b/test/arrays/min-test.js deleted file mode 100644 index 5fe331bb19c14d..00000000000000 --- a/test/arrays/min-test.js +++ /dev/null @@ -1,51 +0,0 @@ -var vows = require("vows"), - _ = require("../../"), - load = require("../load"), - assert = require("../assert"); - -var suite = vows.describe("d3.min"); - -suite.addBatch({ - "min": { - topic: load("arrays/min").expression("d3.min"), - "returns the least numeric value for numbers": function(min) { - assert.equal(min([1]), 1); - assert.equal(min([5, 1, 2, 3, 4]), 1); - assert.equal(min([20, 3]), 3); - assert.equal(min([3, 20]), 3); - }, - "returns the least lexicographic value for strings": function(min) { - assert.equal(min(["c", "a", "b"]), "a"); - assert.equal(min(["20", "3"]), "20"); - assert.equal(min(["3", "20"]), "20"); - }, - "ignores null, undefined and NaN": function(min) { - var o = {valueOf: function() { return NaN; }}; - assert.equal(min([NaN, 1, 2, 3, 4, 5]), 1); - assert.equal(min([o, 1, 2, 3, 4, 5]), 1); - assert.equal(min([1, 2, 3, 4, 5, NaN]), 1); - assert.equal(min([1, 2, 3, 4, 5, o]), 1); - assert.equal(min([10, null, 3, undefined, 5, NaN]), 3); - assert.equal(min([-1, null, -3, undefined, -5, NaN]), -5); - }, - "compares heterogenous types as numbers": function(min) { - assert.strictEqual(min([20, "3"]), "3"); - assert.strictEqual(min(["20", 3]), 3); - assert.strictEqual(min([3, "20"]), 3); - assert.strictEqual(min(["3", 20]), "3"); - }, - "returns undefined for empty array": function(min) { - assert.isUndefined(min([])); - assert.isUndefined(min([null])); - assert.isUndefined(min([undefined])); - assert.isUndefined(min([NaN])); - assert.isUndefined(min([NaN, NaN])); - }, - "applies the optional accessor function": function(min) { - assert.equal(min([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { return _.max(d); }), 5); - assert.equal(min([1, 2, 3, 4, 5], function(d, i) { return i; }), 0); - } - } -}); - -suite.export(module); From ddf0fe85f0d30887637bf73881f6a5ce37b4644e Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 12 Jul 2021 14:44:51 -0400 Subject: [PATCH 2/6] drop format but keep d3.requote, d3.round and d3.collapse --- d3.js | 6214 ++++++++--------- src/format/format.js | 3 - src/format/formatPrefix.js | 24 - src/format/index.js | 2 - src/format/precision.js | 3 - src/locale/ca-ES.js | 16 - src/locale/de-CH.js | 16 - src/locale/de-DE.js | 16 - src/locale/en-CA.js | 16 - src/locale/en-GB.js | 16 - src/locale/en-US.js | 16 - src/locale/es-ES.js | 16 - src/locale/fi-FI.js | 16 - src/locale/fr-CA.js | 16 - src/locale/fr-FR.js | 16 - src/locale/he-IL.js | 16 - src/locale/hu-HU.js | 16 - src/locale/it-IT.js | 16 - src/locale/ja-JP.js | 16 - src/locale/ko-KR.js | 16 - src/locale/locale.js | 9 - src/locale/mk-MK.js | 16 - src/locale/nl-NL.js | 16 - src/locale/number-format.js | 155 - src/locale/pl-PL.js | 16 - src/locale/pt-BR.js | 16 - src/locale/ru-RU.js | 16 - src/locale/sv-SE.js | 16 - src/locale/time-format.js | 370 - src/locale/time-scale.js | 0 src/locale/zh-CN.js | 16 - src/scale/linear.js | 23 - src/scale/log.js | 16 +- src/time/format-iso.js | 19 - src/time/format-utc.js | 3 - src/time/format.js | 4 - src/time/index.js | 5 - src/time/scale-utc.js | 25 - src/time/scale.js | 155 - test/format/format-test.js | 436 -- test/format/formatPrefix-test.js | 115 - test/format/requote-test.js | 49 - test/format/round-test.js | 66 - test/interpolate/interpolate-string-benchmark | 5 +- test/locale/locale-caes-test.js | 120 - test/locale/locale-fifi-test.js | 120 - test/locale/locale-huhu-test.js | 120 - test/locale/locale-ptbr-test.js | 120 - test/locale/locale-test.js | 120 - test/locale/locale-zhcn-test.js | 120 - test/math/transform-rotate-test.html | 32 +- test/scale/log-test.js | 41 - test/scale/pow-test.js | 12 - test/scale/sqrt-test.js | 30 - test/selection/data-benchmark.js | 7 +- test/svg/axis-test.js | 6 - test/time/format-iso-test.js | 33 - test/time/format-test.js | 366 - test/time/format-utc-test.js | 226 - test/time/scale-test.js | 684 -- 60 files changed, 3127 insertions(+), 7083 deletions(-) delete mode 100644 src/format/format.js delete mode 100644 src/format/formatPrefix.js delete mode 100644 src/format/precision.js delete mode 100644 src/locale/ca-ES.js delete mode 100644 src/locale/de-CH.js delete mode 100644 src/locale/de-DE.js delete mode 100644 src/locale/en-CA.js delete mode 100644 src/locale/en-GB.js delete mode 100644 src/locale/en-US.js delete mode 100644 src/locale/es-ES.js delete mode 100644 src/locale/fi-FI.js delete mode 100644 src/locale/fr-CA.js delete mode 100644 src/locale/fr-FR.js delete mode 100644 src/locale/he-IL.js delete mode 100644 src/locale/hu-HU.js delete mode 100644 src/locale/it-IT.js delete mode 100644 src/locale/ja-JP.js delete mode 100644 src/locale/ko-KR.js delete mode 100644 src/locale/locale.js delete mode 100644 src/locale/mk-MK.js delete mode 100644 src/locale/nl-NL.js delete mode 100644 src/locale/number-format.js delete mode 100644 src/locale/pl-PL.js delete mode 100644 src/locale/pt-BR.js delete mode 100644 src/locale/ru-RU.js delete mode 100644 src/locale/sv-SE.js delete mode 100644 src/locale/time-format.js delete mode 100644 src/locale/time-scale.js delete mode 100644 src/locale/zh-CN.js delete mode 100644 src/time/format-iso.js delete mode 100644 src/time/format-utc.js delete mode 100644 src/time/format.js delete mode 100644 src/time/scale-utc.js delete mode 100644 src/time/scale.js delete mode 100644 test/format/format-test.js delete mode 100644 test/format/formatPrefix-test.js delete mode 100644 test/format/requote-test.js delete mode 100644 test/format/round-test.js delete mode 100644 test/locale/locale-caes-test.js delete mode 100644 test/locale/locale-fifi-test.js delete mode 100644 test/locale/locale-huhu-test.js delete mode 100644 test/locale/locale-ptbr-test.js delete mode 100644 test/locale/locale-test.js delete mode 100644 test/locale/locale-zhcn-test.js delete mode 100644 test/time/format-iso-test.js delete mode 100644 test/time/format-test.js delete mode 100644 test/time/format-utc-test.js delete mode 100644 test/time/scale-test.js diff --git a/d3.js b/d3.js index 431d012417b6ca..12d0d676895f5f 100644 --- a/d3.js +++ b/d3.js @@ -2186,3394 +2186,3394 @@ d3_timer_queueTail = t0; return time; } - function d3_format_precision(x, p) { - return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1); + d3.geom = {}; + function d3_geom_pointX(d) { + return d[0]; } - d3.round = function(x, n) { - return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x); - }; - var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix); - d3.formatPrefix = function(value, precision) { - var i = 0; - if (value = +value) { - if (value < 0) value *= -1; - if (precision) value = d3.round(value, d3_format_precision(value, precision)); - i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10); - i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3)); - } - return d3_formatPrefixes[8 + i / 3]; - }; - function d3_formatPrefix(d, i) { - var k = Math.pow(10, abs(8 - i) * 3); - return { - scale: i > 8 ? function(d) { - return d / k; - } : function(d) { - return d * k; - }, - symbol: d - }; + function d3_geom_pointY(d) { + return d[1]; } - function d3_locale_numberFormat(locale) { - var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) { - var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0; - while (i > 0 && g > 0) { - if (length + g + 1 > width) g = Math.max(1, width - length); - t.push(value.substring(i -= g, i + g)); - if ((length += g + 1) > width) break; - g = locale_grouping[j = (j + 1) % locale_grouping.length]; - } - return t.reverse().join(locale_thousands); - } : d3_identity; - return function(specifier) { - var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true; - if (precision) precision = +precision.substring(1); - if (zfill || fill === "0" && align === "=") { - zfill = fill = "0"; - align = "="; - } - switch (type) { - case "n": - comma = true; - type = "g"; - break; - - case "%": - scale = 100; - suffix = "%"; - type = "f"; - break; - - case "p": - scale = 100; - suffix = "%"; - type = "r"; - break; - - case "b": - case "o": - case "x": - case "X": - if (symbol === "#") prefix = "0" + type.toLowerCase(); - - case "c": - exponent = false; - - case "d": - integer = true; - precision = 0; - break; - - case "s": - scale = -1; - type = "r"; - break; - } - if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1]; - if (type == "r" && !precision) type = "g"; - if (precision != null) { - if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision)); + d3.geom.hull = function(vertices) { + var x = d3_geom_pointX, y = d3_geom_pointY; + if (arguments.length) return hull(vertices); + function hull(data) { + if (data.length < 3) return []; + var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = []; + for (i = 0; i < n; i++) { + points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]); } - type = d3_format_types.get(type) || d3_format_typeDefault; - var zcomma = zfill && comma; - return function(value) { - var fullSuffix = suffix; - if (integer && value % 1) return ""; - var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign; - if (scale < 0) { - var unit = d3.formatPrefix(value, precision); - value = unit.scale(value); - fullSuffix = unit.symbol + suffix; - } else { - value *= scale; - } - value = type(value, precision); - var i = value.lastIndexOf("."), before, after; - if (i < 0) { - var j = exponent ? value.lastIndexOf("e") : -1; - if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j); - } else { - before = value.substring(0, i); - after = locale_decimal + value.substring(i + 1); - } - if (!zfill && comma) before = formatGroup(before, Infinity); - var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : ""; - if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity); - negative += prefix; - value = before + after; - return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix; - }; + points.sort(d3_geom_hullOrder); + for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]); + var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints); + var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = []; + for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]); + for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]); + return polygon; + } + hull.x = function(_) { + return arguments.length ? (x = _, hull) : x; }; - } - var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i; - var d3_format_types = d3.map({ - b: function(x) { - return x.toString(2); - }, - c: function(x) { - return String.fromCharCode(x); - }, - o: function(x) { - return x.toString(8); - }, - x: function(x) { - return x.toString(16); - }, - X: function(x) { - return x.toString(16).toUpperCase(); - }, - g: function(x, p) { - return x.toPrecision(p); - }, - e: function(x, p) { - return x.toExponential(p); - }, - f: function(x, p) { - return x.toFixed(p); - }, - r: function(x, p) { - return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p)))); + hull.y = function(_) { + return arguments.length ? (y = _, hull) : y; + }; + return hull; + }; + function d3_geom_hullUpper(points) { + var n = points.length, hull = [ 0, 1 ], hs = 2; + for (var i = 2; i < n; i++) { + while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs; + hull[hs++] = i; } - }); - function d3_format_typeDefault(x) { - return x + ""; + return hull.slice(0, hs); } - var d3_time = d3.time = {}, d3_date = Date; - function d3_date_utc() { - this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]); + function d3_geom_hullOrder(a, b) { + return a[0] - b[0] || a[1] - b[1]; } - d3_date_utc.prototype = { - getDate: function() { - return this._.getUTCDate(); - }, - getDay: function() { - return this._.getUTCDay(); - }, - getFullYear: function() { - return this._.getUTCFullYear(); - }, - getHours: function() { - return this._.getUTCHours(); - }, - getMilliseconds: function() { - return this._.getUTCMilliseconds(); - }, - getMinutes: function() { - return this._.getUTCMinutes(); - }, - getMonth: function() { - return this._.getUTCMonth(); - }, - getSeconds: function() { - return this._.getUTCSeconds(); - }, - getTime: function() { - return this._.getTime(); - }, - getTimezoneOffset: function() { - return 0; - }, - valueOf: function() { - return this._.valueOf(); - }, - setDate: function() { - d3_time_prototype.setUTCDate.apply(this._, arguments); - }, - setDay: function() { - d3_time_prototype.setUTCDay.apply(this._, arguments); - }, - setFullYear: function() { - d3_time_prototype.setUTCFullYear.apply(this._, arguments); - }, - setHours: function() { - d3_time_prototype.setUTCHours.apply(this._, arguments); - }, - setMilliseconds: function() { - d3_time_prototype.setUTCMilliseconds.apply(this._, arguments); - }, - setMinutes: function() { - d3_time_prototype.setUTCMinutes.apply(this._, arguments); - }, - setMonth: function() { - d3_time_prototype.setUTCMonth.apply(this._, arguments); - }, - setSeconds: function() { - d3_time_prototype.setUTCSeconds.apply(this._, arguments); - }, - setTime: function() { - d3_time_prototype.setTime.apply(this._, arguments); - } + d3.geom.polygon = function(coordinates) { + d3_subclass(coordinates, d3_geom_polygonPrototype); + return coordinates; }; - var d3_time_prototype = Date.prototype; - function d3_time_interval(local, step, number) { - function round(date) { - var d0 = local(date), d1 = offset(d0, 1); - return date - d0 < d1 - date ? d0 : d1; - } - function ceil(date) { - step(date = local(new d3_date(date - 1)), 1); - return date; + var d3_geom_polygonPrototype = d3.geom.polygon.prototype = []; + d3_geom_polygonPrototype.area = function() { + var i = -1, n = this.length, a, b = this[n - 1], area = 0; + while (++i < n) { + a = b; + b = this[i]; + area += a[1] * b[0] - a[0] * b[1]; } - function offset(date, k) { - step(date = new d3_date(+date), k); - return date; + return area * .5; + }; + d3_geom_polygonPrototype.centroid = function(k) { + var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c; + if (!arguments.length) k = -1 / (6 * this.area()); + while (++i < n) { + a = b; + b = this[i]; + c = a[0] * b[1] - b[0] * a[1]; + x += (a[0] + b[0]) * c; + y += (a[1] + b[1]) * c; } - function range(t0, t1, dt) { - var time = ceil(t0), times = []; - if (dt > 1) { - while (time < t1) { - if (!(number(time) % dt)) times.push(new Date(+time)); - step(time, 1); + return [ x * k, y * k ]; + }; + d3_geom_polygonPrototype.clip = function(subject) { + var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d; + while (++i < n) { + input = subject.slice(); + subject.length = 0; + b = this[i]; + c = input[(m = input.length - closed) - 1]; + j = -1; + while (++j < m) { + d = input[j]; + if (d3_geom_polygonInside(d, a, b)) { + if (!d3_geom_polygonInside(c, a, b)) { + subject.push(d3_geom_polygonIntersect(c, d, a, b)); + } + subject.push(d); + } else if (d3_geom_polygonInside(c, a, b)) { + subject.push(d3_geom_polygonIntersect(c, d, a, b)); } - } else { - while (time < t1) times.push(new Date(+time)), step(time, 1); + c = d; } - return times; + if (closed) subject.push(subject[0]); + a = b; } - function range_utc(t0, t1, dt) { - try { - d3_date = d3_date_utc; - var utc = new d3_date_utc(); - utc._ = t0; - return range(utc, t1, dt); - } finally { - d3_date = Date; - } + return subject; + }; + function d3_geom_polygonInside(p, a, b) { + return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]); + } + function d3_geom_polygonIntersect(c, d, a, b) { + var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21); + return [ x1 + ua * x21, y1 + ua * y21 ]; + } + function d3_geom_polygonClosed(coordinates) { + var a = coordinates[0], b = coordinates[coordinates.length - 1]; + return !(a[0] - b[0] || a[1] - b[1]); + } + var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = []; + function d3_geom_voronoiBeach() { + d3_geom_voronoiRedBlackNode(this); + this.edge = this.site = this.circle = null; + } + function d3_geom_voronoiCreateBeach(site) { + var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach(); + beach.site = site; + return beach; + } + function d3_geom_voronoiDetachBeach(beach) { + d3_geom_voronoiDetachCircle(beach); + d3_geom_voronoiBeaches.remove(beach); + d3_geom_voronoiBeachPool.push(beach); + d3_geom_voronoiRedBlackNode(beach); + } + function d3_geom_voronoiRemoveBeach(beach) { + var circle = beach.circle, x = circle.x, y = circle.cy, vertex = { + x: x, + y: y + }, previous = beach.P, next = beach.N, disappearing = [ beach ]; + d3_geom_voronoiDetachBeach(beach); + var lArc = previous; + while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) { + previous = lArc.P; + disappearing.unshift(lArc); + d3_geom_voronoiDetachBeach(lArc); + lArc = previous; } - local.floor = local; - local.round = round; - local.ceil = ceil; - local.offset = offset; - local.range = range; - var utc = local.utc = d3_time_interval_utc(local); - utc.floor = utc; - utc.round = d3_time_interval_utc(round); - utc.ceil = d3_time_interval_utc(ceil); - utc.offset = d3_time_interval_utc(offset); - utc.range = range_utc; - return local; + disappearing.unshift(lArc); + d3_geom_voronoiDetachCircle(lArc); + var rArc = next; + while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) { + next = rArc.N; + disappearing.push(rArc); + d3_geom_voronoiDetachBeach(rArc); + rArc = next; + } + disappearing.push(rArc); + d3_geom_voronoiDetachCircle(rArc); + var nArcs = disappearing.length, iArc; + for (iArc = 1; iArc < nArcs; ++iArc) { + rArc = disappearing[iArc]; + lArc = disappearing[iArc - 1]; + d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex); + } + lArc = disappearing[0]; + rArc = disappearing[nArcs - 1]; + rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex); + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); } - function d3_time_interval_utc(method) { - return function(date, k) { - try { - d3_date = d3_date_utc; - var utc = new d3_date_utc(); - utc._ = date; - return method(utc, k)._; - } finally { - d3_date = Date; + function d3_geom_voronoiAddBeach(site) { + var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._; + while (node) { + dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x; + if (dxl > ε) node = node.L; else { + dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix); + if (dxr > ε) { + if (!node.R) { + lArc = node; + break; + } + node = node.R; + } else { + if (dxl > -ε) { + lArc = node.P; + rArc = node; + } else if (dxr > -ε) { + lArc = node; + rArc = node.N; + } else { + lArc = rArc = node; + } + break; + } } + } + var newArc = d3_geom_voronoiCreateBeach(site); + d3_geom_voronoiBeaches.insert(lArc, newArc); + if (!lArc && !rArc) return; + if (lArc === rArc) { + d3_geom_voronoiDetachCircle(lArc); + rArc = d3_geom_voronoiCreateBeach(lArc.site); + d3_geom_voronoiBeaches.insert(newArc, rArc); + newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); + return; + } + if (!rArc) { + newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); + return; + } + d3_geom_voronoiDetachCircle(lArc); + d3_geom_voronoiDetachCircle(rArc); + var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = { + x: (cy * hb - by * hc) / d + ax, + y: (bx * hc - cx * hb) / d + ay }; + d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex); + newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex); + rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex); + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); } - d3_time.year = d3_time_interval(function(date) { - date = d3_time.day(date); - date.setMonth(0, 1); - return date; - }, function(date, offset) { - date.setFullYear(date.getFullYear() + offset); - }, function(date) { - return date.getFullYear(); - }); - d3_time.years = d3_time.year.range; - d3_time.years.utc = d3_time.year.utc.range; - d3_time.day = d3_time_interval(function(date) { - var day = new d3_date(2e3, 0); - day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate()); - return day; - }, function(date, offset) { - date.setDate(date.getDate() + offset); - }, function(date) { - return date.getDate() - 1; - }); - d3_time.days = d3_time.day.range; - d3_time.days.utc = d3_time.day.utc.range; - d3_time.dayOfYear = function(date) { - var year = d3_time.year(date); - return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5); + function d3_geom_voronoiLeftBreakPoint(arc, directrix) { + var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix; + if (!pby2) return rfocx; + var lArc = arc.P; + if (!lArc) return -Infinity; + site = lArc.site; + var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix; + if (!plby2) return lfocx; + var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2; + if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx; + return (rfocx + lfocx) / 2; + } + function d3_geom_voronoiRightBreakPoint(arc, directrix) { + var rArc = arc.N; + if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix); + var site = arc.site; + return site.y === directrix ? site.x : Infinity; + } + function d3_geom_voronoiCell(site) { + this.site = site; + this.edges = []; + } + d3_geom_voronoiCell.prototype.prepare = function() { + var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge; + while (iHalfEdge--) { + edge = halfEdges[iHalfEdge].edge; + if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1); + } + halfEdges.sort(d3_geom_voronoiHalfEdgeOrder); + return halfEdges.length; }; - [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) { - i = 7 - i; - var interval = d3_time[day] = d3_time_interval(function(date) { - (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7); - return date; - }, function(date, offset) { - date.setDate(date.getDate() + Math.floor(offset) * 7); - }, function(date) { - var day = d3_time.year(date).getDay(); - return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i); - }); - d3_time[day + "s"] = interval.range; - d3_time[day + "s"].utc = interval.utc.range; - d3_time[day + "OfYear"] = function(date) { - var day = d3_time.year(date).getDay(); - return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7); - }; - }); - d3_time.week = d3_time.sunday; - d3_time.weeks = d3_time.sunday.range; - d3_time.weeks.utc = d3_time.sunday.utc.range; - d3_time.weekOfYear = d3_time.sundayOfYear; - function d3_locale_timeFormat(locale) { - var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths; - function d3_time_format(template) { - var n = template.length; - function format(date) { - var string = [], i = -1, j = 0, c, p, f; - while (++i < n) { - if (template.charCodeAt(i) === 37) { - string.push(template.slice(j, i)); - if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i); - if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p); - string.push(c); - j = i + 1; - } + function d3_geom_voronoiCloseCells(extent) { + var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end; + while (iCell--) { + cell = cells[iCell]; + if (!cell || !cell.prepare()) continue; + halfEdges = cell.edges; + nHalfEdges = halfEdges.length; + iHalfEdge = 0; + while (iHalfEdge < nHalfEdges) { + end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y; + start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y; + if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) { + halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? { + x: x0, + y: abs(x2 - x0) < ε ? y2 : y1 + } : abs(y3 - y1) < ε && x1 - x3 > ε ? { + x: abs(y2 - y1) < ε ? x2 : x1, + y: y1 + } : abs(x3 - x1) < ε && y3 - y0 > ε ? { + x: x1, + y: abs(x2 - x1) < ε ? y2 : y0 + } : abs(y3 - y0) < ε && x3 - x0 > ε ? { + x: abs(y2 - y0) < ε ? x2 : x0, + y: y0 + } : null), cell.site, null)); + ++nHalfEdges; } - string.push(template.slice(j, i)); - return string.join(""); } - format.parse = function(string) { - var d = { - y: 1900, - m: 0, - d: 1, - H: 0, - M: 0, - S: 0, - L: 0, - Z: null - }, i = d3_time_parse(d, template, string, 0); - if (i != string.length) return null; - if ("p" in d) d.H = d.H % 12 + d.p * 12; - var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)(); - if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) { - if (!("w" in d)) d.w = "W" in d ? 1 : 0; - date.setFullYear(d.y, 0, 1); - date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7); - } else date.setFullYear(d.y, d.m, d.d); - date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L); - return localZ ? date._ : date; - }; - format.toString = function() { - return template; - }; - return format; } - function d3_time_parse(date, template, string, j) { - var c, p, t, i = 0, n = template.length, m = string.length; - while (i < n) { - if (j >= m) return -1; - c = template.charCodeAt(i++); - if (c === 37) { - t = template.charAt(i++); - p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t]; - if (!p || (j = p(date, string, j)) < 0) return -1; - } else if (c != string.charCodeAt(j++)) { - return -1; + } + function d3_geom_voronoiHalfEdgeOrder(a, b) { + return b.angle - a.angle; + } + function d3_geom_voronoiCircle() { + d3_geom_voronoiRedBlackNode(this); + this.x = this.y = this.arc = this.site = this.cy = null; + } + function d3_geom_voronoiAttachCircle(arc) { + var lArc = arc.P, rArc = arc.N; + if (!lArc || !rArc) return; + var lSite = lArc.site, cSite = arc.site, rSite = rArc.site; + if (lSite === rSite) return; + var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by; + var d = 2 * (ax * cy - ay * cx); + if (d >= -ε2) return; + var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by; + var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle(); + circle.arc = arc; + circle.site = cSite; + circle.x = x + bx; + circle.y = cy + Math.sqrt(x * x + y * y); + circle.cy = cy; + arc.circle = circle; + var before = null, node = d3_geom_voronoiCircles._; + while (node) { + if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) { + if (node.L) node = node.L; else { + before = node.P; + break; + } + } else { + if (node.R) node = node.R; else { + before = node; + break; } } - return j; } - d3_time_format.utc = function(template) { - var local = d3_time_format(template); - function format(date) { - try { - d3_date = d3_date_utc; - var utc = new d3_date(); - utc._ = date; - return local(utc); - } finally { - d3_date = Date; - } + d3_geom_voronoiCircles.insert(before, circle); + if (!before) d3_geom_voronoiFirstCircle = circle; + } + function d3_geom_voronoiDetachCircle(arc) { + var circle = arc.circle; + if (circle) { + if (!circle.P) d3_geom_voronoiFirstCircle = circle.N; + d3_geom_voronoiCircles.remove(circle); + d3_geom_voronoiCirclePool.push(circle); + d3_geom_voronoiRedBlackNode(circle); + arc.circle = null; + } + } + function d3_geom_clipLine(x0, y0, x1, y1) { + return function(line) { + var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r; + r = x0 - ax; + if (!dx && r > 0) return; + r /= dx; + if (dx < 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } else if (dx > 0) { + if (r > t1) return; + if (r > t0) t0 = r; } - format.parse = function(string) { - try { - d3_date = d3_date_utc; - var date = local.parse(string); - return date && date._; - } finally { - d3_date = Date; - } + r = x1 - ax; + if (!dx && r < 0) return; + r /= dx; + if (dx < 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } else if (dx > 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } + r = y0 - ay; + if (!dy && r > 0) return; + r /= dy; + if (dy < 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } else if (dy > 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } + r = y1 - ay; + if (!dy && r < 0) return; + r /= dy; + if (dy < 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } else if (dy > 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } + if (t0 > 0) line.a = { + x: ax + t0 * dx, + y: ay + t0 * dy }; - format.toString = local.toString; - return format; + if (t1 < 1) line.b = { + x: ax + t1 * dx, + y: ay + t1 * dy + }; + return line; }; - d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti; - var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths); - locale_periods.forEach(function(p, i) { - d3_time_periodLookup.set(p.toLowerCase(), i); - }); - var d3_time_formats = { - a: function(d) { - return locale_shortDays[d.getDay()]; - }, - A: function(d) { - return locale_days[d.getDay()]; - }, - b: function(d) { - return locale_shortMonths[d.getMonth()]; - }, - B: function(d) { - return locale_months[d.getMonth()]; - }, - c: d3_time_format(locale_dateTime), - d: function(d, p) { - return d3_time_formatPad(d.getDate(), p, 2); - }, - e: function(d, p) { - return d3_time_formatPad(d.getDate(), p, 2); - }, - H: function(d, p) { - return d3_time_formatPad(d.getHours(), p, 2); - }, - I: function(d, p) { - return d3_time_formatPad(d.getHours() % 12 || 12, p, 2); - }, - j: function(d, p) { - return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3); - }, - L: function(d, p) { - return d3_time_formatPad(d.getMilliseconds(), p, 3); - }, - m: function(d, p) { - return d3_time_formatPad(d.getMonth() + 1, p, 2); - }, - M: function(d, p) { - return d3_time_formatPad(d.getMinutes(), p, 2); - }, - p: function(d) { - return locale_periods[+(d.getHours() >= 12)]; - }, - S: function(d, p) { - return d3_time_formatPad(d.getSeconds(), p, 2); - }, - U: function(d, p) { - return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2); - }, - w: function(d) { - return d.getDay(); - }, - W: function(d, p) { - return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2); - }, - x: d3_time_format(locale_date), - X: d3_time_format(locale_time), - y: function(d, p) { - return d3_time_formatPad(d.getFullYear() % 100, p, 2); - }, - Y: function(d, p) { - return d3_time_formatPad(d.getFullYear() % 1e4, p, 4); - }, - Z: d3_time_zone, - "%": function() { - return "%"; + } + function d3_geom_voronoiClipEdges(extent) { + var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e; + while (i--) { + e = edges[i]; + if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) { + e.a = e.b = null; + edges.splice(i, 1); } - }; - var d3_time_parsers = { - a: d3_time_parseWeekdayAbbrev, - A: d3_time_parseWeekday, - b: d3_time_parseMonthAbbrev, - B: d3_time_parseMonth, - c: d3_time_parseLocaleFull, - d: d3_time_parseDay, - e: d3_time_parseDay, - H: d3_time_parseHour24, - I: d3_time_parseHour24, - j: d3_time_parseDayOfYear, - L: d3_time_parseMilliseconds, - m: d3_time_parseMonthNumber, - M: d3_time_parseMinutes, - p: d3_time_parseAmPm, - S: d3_time_parseSeconds, - U: d3_time_parseWeekNumberSunday, - w: d3_time_parseWeekdayNumber, - W: d3_time_parseWeekNumberMonday, - x: d3_time_parseLocaleDate, - X: d3_time_parseLocaleTime, - y: d3_time_parseYear, - Y: d3_time_parseFullYear, - Z: d3_time_parseZone, - "%": d3_time_parseLiteralPercent - }; - function d3_time_parseWeekdayAbbrev(date, string, i) { - d3_time_dayAbbrevRe.lastIndex = 0; - var n = d3_time_dayAbbrevRe.exec(string.slice(i)); - return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - function d3_time_parseWeekday(date, string, i) { - d3_time_dayRe.lastIndex = 0; - var n = d3_time_dayRe.exec(string.slice(i)); - return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - function d3_time_parseMonthAbbrev(date, string, i) { - d3_time_monthAbbrevRe.lastIndex = 0; - var n = d3_time_monthAbbrevRe.exec(string.slice(i)); - return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - function d3_time_parseMonth(date, string, i) { - d3_time_monthRe.lastIndex = 0; - var n = d3_time_monthRe.exec(string.slice(i)); - return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - function d3_time_parseLocaleFull(date, string, i) { - return d3_time_parse(date, d3_time_formats.c.toString(), string, i); - } - function d3_time_parseLocaleDate(date, string, i) { - return d3_time_parse(date, d3_time_formats.x.toString(), string, i); - } - function d3_time_parseLocaleTime(date, string, i) { - return d3_time_parse(date, d3_time_formats.X.toString(), string, i); - } - function d3_time_parseAmPm(date, string, i) { - var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase()); - return n == null ? -1 : (date.p = n, i); } - return d3_time_format; - } - var d3_time_formatPads = { - "-": "", - _: " ", - "0": "0" - }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/; - function d3_time_formatPad(value, fill, width) { - var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length; - return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); } - function d3_time_formatRe(names) { - return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i"); + function d3_geom_voronoiConnectEdge(edge, extent) { + var vb = edge.b; + if (vb) return true; + var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb; + if (ry === ly) { + if (fx < x0 || fx >= x1) return; + if (lx > rx) { + if (!va) va = { + x: fx, + y: y0 + }; else if (va.y >= y1) return; + vb = { + x: fx, + y: y1 + }; + } else { + if (!va) va = { + x: fx, + y: y1 + }; else if (va.y < y0) return; + vb = { + x: fx, + y: y0 + }; + } + } else { + fm = (lx - rx) / (ry - ly); + fb = fy - fm * fx; + if (fm < -1 || fm > 1) { + if (lx > rx) { + if (!va) va = { + x: (y0 - fb) / fm, + y: y0 + }; else if (va.y >= y1) return; + vb = { + x: (y1 - fb) / fm, + y: y1 + }; + } else { + if (!va) va = { + x: (y1 - fb) / fm, + y: y1 + }; else if (va.y < y0) return; + vb = { + x: (y0 - fb) / fm, + y: y0 + }; + } + } else { + if (ly < ry) { + if (!va) va = { + x: x0, + y: fm * x0 + fb + }; else if (va.x >= x1) return; + vb = { + x: x1, + y: fm * x1 + fb + }; + } else { + if (!va) va = { + x: x1, + y: fm * x1 + fb + }; else if (va.x < x0) return; + vb = { + x: x0, + y: fm * x0 + fb + }; + } + } + } + edge.a = va; + edge.b = vb; + return true; } - function d3_time_formatLookup(names) { - var map = new d3_Map(), i = -1, n = names.length; - while (++i < n) map.set(names[i].toLowerCase(), i); - return map; + function d3_geom_voronoiEdge(lSite, rSite) { + this.l = lSite; + this.r = rSite; + this.a = this.b = null; } - function d3_time_parseWeekdayNumber(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 1)); - return n ? (date.w = +n[0], i + n[0].length) : -1; + function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) { + var edge = new d3_geom_voronoiEdge(lSite, rSite); + d3_geom_voronoiEdges.push(edge); + if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va); + if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb); + d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite)); + d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite)); + return edge; } - function d3_time_parseWeekNumberSunday(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i)); - return n ? (date.U = +n[0], i + n[0].length) : -1; + function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) { + var edge = new d3_geom_voronoiEdge(lSite, null); + edge.a = va; + edge.b = vb; + d3_geom_voronoiEdges.push(edge); + return edge; } - function d3_time_parseWeekNumberMonday(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i)); - return n ? (date.W = +n[0], i + n[0].length) : -1; + function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) { + if (!edge.a && !edge.b) { + edge.a = vertex; + edge.l = lSite; + edge.r = rSite; + } else if (edge.l === rSite) { + edge.b = vertex; + } else { + edge.a = vertex; + } } - function d3_time_parseFullYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 4)); - return n ? (date.y = +n[0], i + n[0].length) : -1; + function d3_geom_voronoiHalfEdge(edge, lSite, rSite) { + var va = edge.a, vb = edge.b; + this.edge = edge; + this.site = lSite; + this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y); } - function d3_time_parseYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1; + d3_geom_voronoiHalfEdge.prototype = { + start: function() { + return this.edge.l === this.site ? this.edge.a : this.edge.b; + }, + end: function() { + return this.edge.l === this.site ? this.edge.b : this.edge.a; + } + }; + function d3_geom_voronoiRedBlackTree() { + this._ = null; } - function d3_time_parseZone(date, string, i) { - return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string, - i + 5) : -1; + function d3_geom_voronoiRedBlackNode(node) { + node.U = node.C = node.L = node.R = node.P = node.N = null; } - function d3_time_expandYear(d) { - return d + (d > 68 ? 1900 : 2e3); - } - function d3_time_parseMonthNumber(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.m = n[0] - 1, i + n[0].length) : -1; - } - function d3_time_parseDay(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.d = +n[0], i + n[0].length) : -1; - } - function d3_time_parseDayOfYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 3)); - return n ? (date.j = +n[0], i + n[0].length) : -1; - } - function d3_time_parseHour24(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.H = +n[0], i + n[0].length) : -1; - } - function d3_time_parseMinutes(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.M = +n[0], i + n[0].length) : -1; - } - function d3_time_parseSeconds(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.S = +n[0], i + n[0].length) : -1; - } - function d3_time_parseMilliseconds(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 3)); - return n ? (date.L = +n[0], i + n[0].length) : -1; - } - function d3_time_zone(d) { - var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60; - return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2); + d3_geom_voronoiRedBlackTree.prototype = { + insert: function(after, node) { + var parent, grandpa, uncle; + if (after) { + node.P = after; + node.N = after.N; + if (after.N) after.N.P = node; + after.N = node; + if (after.R) { + after = after.R; + while (after.L) after = after.L; + after.L = node; + } else { + after.R = node; + } + parent = after; + } else if (this._) { + after = d3_geom_voronoiRedBlackFirst(this._); + node.P = null; + node.N = after; + after.P = after.L = node; + parent = after; + } else { + node.P = node.N = null; + this._ = node; + parent = null; + } + node.L = node.R = null; + node.U = parent; + node.C = true; + after = node; + while (parent && parent.C) { + grandpa = parent.U; + if (parent === grandpa.L) { + uncle = grandpa.R; + if (uncle && uncle.C) { + parent.C = uncle.C = false; + grandpa.C = true; + after = grandpa; + } else { + if (after === parent.R) { + d3_geom_voronoiRedBlackRotateLeft(this, parent); + after = parent; + parent = after.U; + } + parent.C = false; + grandpa.C = true; + d3_geom_voronoiRedBlackRotateRight(this, grandpa); + } + } else { + uncle = grandpa.L; + if (uncle && uncle.C) { + parent.C = uncle.C = false; + grandpa.C = true; + after = grandpa; + } else { + if (after === parent.L) { + d3_geom_voronoiRedBlackRotateRight(this, parent); + after = parent; + parent = after.U; + } + parent.C = false; + grandpa.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, grandpa); + } + } + parent = after.U; + } + this._.C = false; + }, + remove: function(node) { + if (node.N) node.N.P = node.P; + if (node.P) node.P.N = node.N; + node.N = node.P = null; + var parent = node.U, sibling, left = node.L, right = node.R, next, red; + if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right); + if (parent) { + if (parent.L === node) parent.L = next; else parent.R = next; + } else { + this._ = next; + } + if (left && right) { + red = next.C; + next.C = node.C; + next.L = left; + left.U = next; + if (next !== right) { + parent = next.U; + next.U = node.U; + node = next.R; + parent.L = node; + next.R = right; + right.U = next; + } else { + next.U = parent; + parent = next; + node = next.R; + } + } else { + red = node.C; + node = next; + } + if (node) node.U = parent; + if (red) return; + if (node && node.C) { + node.C = false; + return; + } + do { + if (node === this._) break; + if (node === parent.L) { + sibling = parent.R; + if (sibling.C) { + sibling.C = false; + parent.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, parent); + sibling = parent.R; + } + if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { + if (!sibling.R || !sibling.R.C) { + sibling.L.C = false; + sibling.C = true; + d3_geom_voronoiRedBlackRotateRight(this, sibling); + sibling = parent.R; + } + sibling.C = parent.C; + parent.C = sibling.R.C = false; + d3_geom_voronoiRedBlackRotateLeft(this, parent); + node = this._; + break; + } + } else { + sibling = parent.L; + if (sibling.C) { + sibling.C = false; + parent.C = true; + d3_geom_voronoiRedBlackRotateRight(this, parent); + sibling = parent.L; + } + if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { + if (!sibling.L || !sibling.L.C) { + sibling.R.C = false; + sibling.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, sibling); + sibling = parent.L; + } + sibling.C = parent.C; + parent.C = sibling.L.C = false; + d3_geom_voronoiRedBlackRotateRight(this, parent); + node = this._; + break; + } + } + sibling.C = true; + node = parent; + parent = parent.U; + } while (!node.C); + if (node) node.C = false; + } + }; + function d3_geom_voronoiRedBlackRotateLeft(tree, node) { + var p = node, q = node.R, parent = p.U; + if (parent) { + if (parent.L === p) parent.L = q; else parent.R = q; + } else { + tree._ = q; + } + q.U = parent; + p.U = q; + p.R = q.L; + if (p.R) p.R.U = p; + q.L = p; } - function d3_time_parseLiteralPercent(date, string, i) { - d3_time_percentRe.lastIndex = 0; - var n = d3_time_percentRe.exec(string.slice(i, i + 1)); - return n ? i + n[0].length : -1; + function d3_geom_voronoiRedBlackRotateRight(tree, node) { + var p = node, q = node.L, parent = p.U; + if (parent) { + if (parent.L === p) parent.L = q; else parent.R = q; + } else { + tree._ = q; + } + q.U = parent; + p.U = q; + p.L = q.R; + if (p.L) p.L.U = p; + q.R = p; } - function d3_time_formatMulti(formats) { - var n = formats.length, i = -1; - while (++i < n) formats[i][0] = this(formats[i][0]); - return function(date) { - var i = 0, f = formats[i]; - while (!f[1](date)) f = formats[++i]; - return f[0](date); - }; + function d3_geom_voronoiRedBlackFirst(node) { + while (node.L) node = node.L; + return node; } - d3.locale = function(locale) { - return { - numberFormat: d3_locale_numberFormat(locale), - timeFormat: d3_locale_timeFormat(locale) + function d3_geom_voronoi(sites, bbox) { + var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle; + d3_geom_voronoiEdges = []; + d3_geom_voronoiCells = new Array(sites.length); + d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree(); + d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree(); + while (true) { + circle = d3_geom_voronoiFirstCircle; + if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) { + if (site.x !== x0 || site.y !== y0) { + d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site); + d3_geom_voronoiAddBeach(site); + x0 = site.x, y0 = site.y; + } + site = sites.pop(); + } else if (circle) { + d3_geom_voronoiRemoveBeach(circle.arc); + } else { + break; + } + } + if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox); + var diagram = { + cells: d3_geom_voronoiCells, + edges: d3_geom_voronoiEdges }; - }; - var d3_locale_enUS = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [ 3 ], - currency: [ "$", "" ], - dateTime: "%a %b %e %X %Y", - date: "%m/%d/%Y", - time: "%H:%M:%S", - 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" ] - }); - d3.format = d3_locale_enUS.numberFormat; - d3.geom = {}; - function d3_geom_pointX(d) { - return d[0]; + d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null; + return diagram; } - function d3_geom_pointY(d) { - return d[1]; + function d3_geom_voronoiVertexOrder(a, b) { + return b.y - a.y || b.x - a.x; } - d3.geom.hull = function(vertices) { - var x = d3_geom_pointX, y = d3_geom_pointY; - if (arguments.length) return hull(vertices); - function hull(data) { - if (data.length < 3) return []; - var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = []; - for (i = 0; i < n; i++) { - points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]); - } - points.sort(d3_geom_hullOrder); - for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]); - var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints); - var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = []; - for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]); - for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]); - return polygon; + d3.geom.voronoi = function(points) { + var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent; + if (points) return voronoi(points); + function voronoi(data) { + var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1]; + d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) { + var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) { + var s = e.start(); + return [ s.x, s.y ]; + }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : []; + polygon.point = data[i]; + }); + return polygons; + } + function sites(data) { + return data.map(function(d, i) { + return { + x: Math.round(fx(d, i) / ε) * ε, + y: Math.round(fy(d, i) / ε) * ε, + i: i + }; + }); } - hull.x = function(_) { - return arguments.length ? (x = _, hull) : x; + voronoi.links = function(data) { + return d3_geom_voronoi(sites(data)).edges.filter(function(edge) { + return edge.l && edge.r; + }).map(function(edge) { + return { + source: data[edge.l.i], + target: data[edge.r.i] + }; + }); }; - hull.y = function(_) { - return arguments.length ? (y = _, hull) : y; + voronoi.triangles = function(data) { + var triangles = []; + d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) { + var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l; + while (++j < m) { + e0 = e1; + s0 = s1; + e1 = edges[j].edge; + s1 = e1.l === site ? e1.r : e1.l; + if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) { + triangles.push([ data[i], data[s0.i], data[s1.i] ]); + } + } + }); + return triangles; }; - return hull; + voronoi.x = function(_) { + return arguments.length ? (fx = d3_functor(x = _), voronoi) : x; + }; + voronoi.y = function(_) { + return arguments.length ? (fy = d3_functor(y = _), voronoi) : y; + }; + voronoi.clipExtent = function(_) { + if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent; + clipExtent = _ == null ? d3_geom_voronoiClipExtent : _; + return voronoi; + }; + voronoi.size = function(_) { + if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1]; + return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]); + }; + return voronoi; }; - function d3_geom_hullUpper(points) { - var n = points.length, hull = [ 0, 1 ], hs = 2; - for (var i = 2; i < n; i++) { - while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs; - hull[hs++] = i; - } - return hull.slice(0, hs); - } - function d3_geom_hullOrder(a, b) { - return a[0] - b[0] || a[1] - b[1]; + var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ]; + function d3_geom_voronoiTriangleArea(a, b, c) { + return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y); } - d3.geom.polygon = function(coordinates) { - d3_subclass(coordinates, d3_geom_polygonPrototype); - return coordinates; - }; - var d3_geom_polygonPrototype = d3.geom.polygon.prototype = []; - d3_geom_polygonPrototype.area = function() { - var i = -1, n = this.length, a, b = this[n - 1], area = 0; - while (++i < n) { - a = b; - b = this[i]; - area += a[1] * b[0] - a[0] * b[1]; - } - return area * .5; + d3.geom.delaunay = function(vertices) { + return d3.geom.voronoi().triangles(vertices); }; - d3_geom_polygonPrototype.centroid = function(k) { - var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c; - if (!arguments.length) k = -1 / (6 * this.area()); - while (++i < n) { - a = b; - b = this[i]; - c = a[0] * b[1] - b[0] * a[1]; - x += (a[0] + b[0]) * c; - y += (a[1] + b[1]) * c; + d3.geom.quadtree = function(points, x1, y1, x2, y2) { + var x = d3_geom_pointX, y = d3_geom_pointY, compat; + if (compat = arguments.length) { + x = d3_geom_quadtreeCompatX; + y = d3_geom_quadtreeCompatY; + if (compat === 3) { + y2 = y1; + x2 = x1; + y1 = x1 = 0; + } + return quadtree(points); } - return [ x * k, y * k ]; - }; - d3_geom_polygonPrototype.clip = function(subject) { - var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d; - while (++i < n) { - input = subject.slice(); - subject.length = 0; - b = this[i]; - c = input[(m = input.length - closed) - 1]; - j = -1; - while (++j < m) { - d = input[j]; - if (d3_geom_polygonInside(d, a, b)) { - if (!d3_geom_polygonInside(c, a, b)) { - subject.push(d3_geom_polygonIntersect(c, d, a, b)); - } - subject.push(d); - } else if (d3_geom_polygonInside(c, a, b)) { - subject.push(d3_geom_polygonIntersect(c, d, a, b)); + function quadtree(data) { + var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_; + if (x1 != null) { + x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2; + } else { + x2_ = y2_ = -(x1_ = y1_ = Infinity); + xs = [], ys = []; + n = data.length; + if (compat) for (i = 0; i < n; ++i) { + d = data[i]; + if (d.x < x1_) x1_ = d.x; + if (d.y < y1_) y1_ = d.y; + if (d.x > x2_) x2_ = d.x; + if (d.y > y2_) y2_ = d.y; + xs.push(d.x); + ys.push(d.y); + } else for (i = 0; i < n; ++i) { + var x_ = +fx(d = data[i], i), y_ = +fy(d, i); + if (x_ < x1_) x1_ = x_; + if (y_ < y1_) y1_ = y_; + if (x_ > x2_) x2_ = x_; + if (y_ > y2_) y2_ = y_; + xs.push(x_); + ys.push(y_); } - c = d; } - if (closed) subject.push(subject[0]); - a = b; - } - return subject; - }; - function d3_geom_polygonInside(p, a, b) { - return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]); - } - function d3_geom_polygonIntersect(c, d, a, b) { - var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21); - return [ x1 + ua * x21, y1 + ua * y21 ]; - } - function d3_geom_polygonClosed(coordinates) { - var a = coordinates[0], b = coordinates[coordinates.length - 1]; - return !(a[0] - b[0] || a[1] - b[1]); - } - var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = []; - function d3_geom_voronoiBeach() { - d3_geom_voronoiRedBlackNode(this); - this.edge = this.site = this.circle = null; - } - function d3_geom_voronoiCreateBeach(site) { - var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach(); - beach.site = site; - return beach; - } - function d3_geom_voronoiDetachBeach(beach) { - d3_geom_voronoiDetachCircle(beach); - d3_geom_voronoiBeaches.remove(beach); - d3_geom_voronoiBeachPool.push(beach); - d3_geom_voronoiRedBlackNode(beach); - } - function d3_geom_voronoiRemoveBeach(beach) { - var circle = beach.circle, x = circle.x, y = circle.cy, vertex = { - x: x, - y: y - }, previous = beach.P, next = beach.N, disappearing = [ beach ]; - d3_geom_voronoiDetachBeach(beach); - var lArc = previous; - while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) { - previous = lArc.P; - disappearing.unshift(lArc); - d3_geom_voronoiDetachBeach(lArc); - lArc = previous; - } - disappearing.unshift(lArc); - d3_geom_voronoiDetachCircle(lArc); - var rArc = next; - while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) { - next = rArc.N; - disappearing.push(rArc); - d3_geom_voronoiDetachBeach(rArc); - rArc = next; - } - disappearing.push(rArc); - d3_geom_voronoiDetachCircle(rArc); - var nArcs = disappearing.length, iArc; - for (iArc = 1; iArc < nArcs; ++iArc) { - rArc = disappearing[iArc]; - lArc = disappearing[iArc - 1]; - d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex); - } - lArc = disappearing[0]; - rArc = disappearing[nArcs - 1]; - rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex); - d3_geom_voronoiAttachCircle(lArc); - d3_geom_voronoiAttachCircle(rArc); - } - function d3_geom_voronoiAddBeach(site) { - var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._; - while (node) { - dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x; - if (dxl > ε) node = node.L; else { - dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix); - if (dxr > ε) { - if (!node.R) { - lArc = node; - break; - } - node = node.R; - } else { - if (dxl > -ε) { - lArc = node.P; - rArc = node; - } else if (dxr > -ε) { - lArc = node; - rArc = node.N; + var dx = x2_ - x1_, dy = y2_ - y1_; + if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy; + function insert(n, d, x, y, x1, y1, x2, y2) { + if (isNaN(x) || isNaN(y)) return; + if (n.leaf) { + var nx = n.x, ny = n.y; + if (nx != null) { + if (abs(nx - x) + abs(ny - y) < .01) { + insertChild(n, d, x, y, x1, y1, x2, y2); + } else { + var nPoint = n.point; + n.x = n.y = n.point = null; + insertChild(n, nPoint, nx, ny, x1, y1, x2, y2); + insertChild(n, d, x, y, x1, y1, x2, y2); + } } else { - lArc = rArc = node; + n.x = x, n.y = y, n.point = d; } - break; + } else { + insertChild(n, d, x, y, x1, y1, x2, y2); } } + function insertChild(n, d, x, y, x1, y1, x2, y2) { + var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right; + n.leaf = false; + n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode()); + if (right) x1 = xm; else x2 = xm; + if (below) y1 = ym; else y2 = ym; + insert(n, d, x, y, x1, y1, x2, y2); + } + var root = d3_geom_quadtreeNode(); + root.add = function(d) { + insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_); + }; + root.visit = function(f) { + d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_); + }; + root.find = function(point) { + return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_); + }; + i = -1; + if (x1 == null) { + while (++i < n) { + insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_); + } + --i; + } else data.forEach(root.add); + xs = ys = data = d = null; + return root; } - var newArc = d3_geom_voronoiCreateBeach(site); - d3_geom_voronoiBeaches.insert(lArc, newArc); - if (!lArc && !rArc) return; - if (lArc === rArc) { - d3_geom_voronoiDetachCircle(lArc); - rArc = d3_geom_voronoiCreateBeach(lArc.site); - d3_geom_voronoiBeaches.insert(newArc, rArc); - newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); - d3_geom_voronoiAttachCircle(lArc); - d3_geom_voronoiAttachCircle(rArc); - return; - } - if (!rArc) { - newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); - return; - } - d3_geom_voronoiDetachCircle(lArc); - d3_geom_voronoiDetachCircle(rArc); - var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = { - x: (cy * hb - by * hc) / d + ax, - y: (bx * hc - cx * hb) / d + ay + quadtree.x = function(_) { + return arguments.length ? (x = _, quadtree) : x; }; - d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex); - newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex); - rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex); - d3_geom_voronoiAttachCircle(lArc); - d3_geom_voronoiAttachCircle(rArc); - } - function d3_geom_voronoiLeftBreakPoint(arc, directrix) { - var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix; - if (!pby2) return rfocx; - var lArc = arc.P; - if (!lArc) return -Infinity; - site = lArc.site; - var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix; - if (!plby2) return lfocx; - var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2; - if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx; - return (rfocx + lfocx) / 2; + quadtree.y = function(_) { + return arguments.length ? (y = _, quadtree) : y; + }; + quadtree.extent = function(_) { + if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ]; + if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], + y2 = +_[1][1]; + return quadtree; + }; + quadtree.size = function(_) { + if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ]; + if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1]; + return quadtree; + }; + return quadtree; + }; + function d3_geom_quadtreeCompatX(d) { + return d.x; } - function d3_geom_voronoiRightBreakPoint(arc, directrix) { - var rArc = arc.N; - if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix); - var site = arc.site; - return site.y === directrix ? site.x : Infinity; + function d3_geom_quadtreeCompatY(d) { + return d.y; } - function d3_geom_voronoiCell(site) { - this.site = site; - this.edges = []; + function d3_geom_quadtreeNode() { + return { + leaf: true, + nodes: [], + point: null, + x: null, + y: null + }; } - d3_geom_voronoiCell.prototype.prepare = function() { - var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge; - while (iHalfEdge--) { - edge = halfEdges[iHalfEdge].edge; - if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1); + function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) { + if (!f(node, x1, y1, x2, y2)) { + var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes; + if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy); + if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy); + if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2); + if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2); } - halfEdges.sort(d3_geom_voronoiHalfEdgeOrder); - return halfEdges.length; - }; - function d3_geom_voronoiCloseCells(extent) { - var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end; - while (iCell--) { - cell = cells[iCell]; - if (!cell || !cell.prepare()) continue; - halfEdges = cell.edges; - nHalfEdges = halfEdges.length; - iHalfEdge = 0; - while (iHalfEdge < nHalfEdges) { - end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y; - start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y; - if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) { - halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? { - x: x0, - y: abs(x2 - x0) < ε ? y2 : y1 - } : abs(y3 - y1) < ε && x1 - x3 > ε ? { - x: abs(y2 - y1) < ε ? x2 : x1, - y: y1 - } : abs(x3 - x1) < ε && y3 - y0 > ε ? { - x: x1, - y: abs(x2 - x1) < ε ? y2 : y0 - } : abs(y3 - y0) < ε && x3 - x0 > ε ? { - x: abs(y2 - y0) < ε ? x2 : x0, - y: y0 - } : null), cell.site, null)); - ++nHalfEdges; + } + function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) { + var minDistance2 = Infinity, closestPoint; + (function find(node, x1, y1, x2, y2) { + if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return; + if (point = node.point) { + var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy; + if (distance2 < minDistance2) { + var distance = Math.sqrt(minDistance2 = distance2); + x0 = x - distance, y0 = y - distance; + x3 = x + distance, y3 = y + distance; + closestPoint = point; } } - } - } - function d3_geom_voronoiHalfEdgeOrder(a, b) { - return b.angle - a.angle; - } - function d3_geom_voronoiCircle() { - d3_geom_voronoiRedBlackNode(this); - this.x = this.y = this.arc = this.site = this.cy = null; - } - function d3_geom_voronoiAttachCircle(arc) { - var lArc = arc.P, rArc = arc.N; - if (!lArc || !rArc) return; - var lSite = lArc.site, cSite = arc.site, rSite = rArc.site; - if (lSite === rSite) return; - var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by; - var d = 2 * (ax * cy - ay * cx); - if (d >= -ε2) return; - var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by; - var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle(); - circle.arc = arc; - circle.site = cSite; - circle.x = x + bx; - circle.y = cy + Math.sqrt(x * x + y * y); - circle.cy = cy; - arc.circle = circle; - var before = null, node = d3_geom_voronoiCircles._; - while (node) { - if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) { - if (node.L) node = node.L; else { - before = node.P; + var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym; + for (var i = below << 1 | right, j = i + 4; i < j; ++i) { + if (node = children[i & 3]) switch (i & 3) { + case 0: + find(node, x1, y1, xm, ym); break; - } - } else { - if (node.R) node = node.R; else { - before = node; + + case 1: + find(node, xm, y1, x2, ym); + break; + + case 2: + find(node, x1, ym, xm, y2); + break; + + case 3: + find(node, xm, ym, x2, y2); break; } } - } - d3_geom_voronoiCircles.insert(before, circle); - if (!before) d3_geom_voronoiFirstCircle = circle; - } - function d3_geom_voronoiDetachCircle(arc) { - var circle = arc.circle; - if (circle) { - if (!circle.P) d3_geom_voronoiFirstCircle = circle.N; - d3_geom_voronoiCircles.remove(circle); - d3_geom_voronoiCirclePool.push(circle); - d3_geom_voronoiRedBlackNode(circle); - arc.circle = null; - } - } - function d3_geom_clipLine(x0, y0, x1, y1) { - return function(line) { - var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r; - r = x0 - ax; - if (!dx && r > 0) return; - r /= dx; - if (dx < 0) { - if (r < t0) return; - if (r < t1) t1 = r; - } else if (dx > 0) { - if (r > t1) return; - if (r > t0) t0 = r; - } - r = x1 - ax; - if (!dx && r < 0) return; - r /= dx; - if (dx < 0) { - if (r > t1) return; - if (r > t0) t0 = r; - } else if (dx > 0) { - if (r < t0) return; - if (r < t1) t1 = r; - } - r = y0 - ay; - if (!dy && r > 0) return; - r /= dy; - if (dy < 0) { - if (r < t0) return; - if (r < t1) t1 = r; - } else if (dy > 0) { - if (r > t1) return; - if (r > t0) t0 = r; - } - r = y1 - ay; - if (!dy && r < 0) return; - r /= dy; - if (dy < 0) { - if (r > t1) return; - if (r > t0) t0 = r; - } else if (dy > 0) { - if (r < t0) return; - if (r < t1) t1 = r; - } - if (t0 > 0) line.a = { - x: ax + t0 * dx, - y: ay + t0 * dy - }; - if (t1 < 1) line.b = { - x: ax + t1 * dx, - y: ay + t1 * dy - }; - return line; + })(root, x0, y0, x3, y3); + return closestPoint; + } + d3.interpolateRgb = d3_interpolateRgb; + function d3_interpolateRgb(a, b) { + a = d3.rgb(a); + b = d3.rgb(b); + var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab; + return function(t) { + return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t)); }; } - function d3_geom_voronoiClipEdges(extent) { - var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e; - while (i--) { - e = edges[i]; - if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) { - e.a = e.b = null; - edges.splice(i, 1); + d3.interpolateObject = d3_interpolateObject; + function d3_interpolateObject(a, b) { + var i = {}, c = {}, k; + for (k in a) { + if (k in b) { + i[k] = d3_interpolate(a[k], b[k]); + } else { + c[k] = a[k]; + } + } + for (k in b) { + if (!(k in a)) { + c[k] = b[k]; } } + return function(t) { + for (k in i) c[k] = i[k](t); + return c; + }; } - function d3_geom_voronoiConnectEdge(edge, extent) { - var vb = edge.b; - if (vb) return true; - var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb; - if (ry === ly) { - if (fx < x0 || fx >= x1) return; - if (lx > rx) { - if (!va) va = { - x: fx, - y: y0 - }; else if (va.y >= y1) return; - vb = { - x: fx, - y: y1 - }; - } else { - if (!va) va = { - x: fx, - y: y1 - }; else if (va.y < y0) return; - vb = { - x: fx, - y: y0 - }; + d3.interpolateNumber = d3_interpolateNumber; + function d3_interpolateNumber(a, b) { + a = +a, b = +b; + return function(t) { + return a * (1 - t) + b * t; + }; + } + d3.interpolateString = d3_interpolateString; + function d3_interpolateString(a, b) { + var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = []; + a = a + "", b = b + ""; + while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) { + if ((bs = bm.index) > bi) { + bs = b.slice(bi, bs); + if (s[i]) s[i] += bs; else s[++i] = bs; } - } else { - fm = (lx - rx) / (ry - ly); - fb = fy - fm * fx; - if (fm < -1 || fm > 1) { - if (lx > rx) { - if (!va) va = { - x: (y0 - fb) / fm, - y: y0 - }; else if (va.y >= y1) return; - vb = { - x: (y1 - fb) / fm, - y: y1 - }; - } else { - if (!va) va = { - x: (y1 - fb) / fm, - y: y1 - }; else if (va.y < y0) return; - vb = { - x: (y0 - fb) / fm, - y: y0 - }; - } + if ((am = am[0]) === (bm = bm[0])) { + if (s[i]) s[i] += bm; else s[++i] = bm; } else { - if (ly < ry) { - if (!va) va = { - x: x0, - y: fm * x0 + fb - }; else if (va.x >= x1) return; - vb = { - x: x1, - y: fm * x1 + fb - }; - } else { - if (!va) va = { - x: x1, - y: fm * x1 + fb - }; else if (va.x < x0) return; - vb = { - x: x0, - y: fm * x0 + fb - }; - } + s[++i] = null; + q.push({ + i: i, + x: d3_interpolateNumber(am, bm) + }); } + bi = d3_interpolate_numberB.lastIndex; } - edge.a = va; - edge.b = vb; - return true; + if (bi < b.length) { + bs = b.slice(bi); + if (s[i]) s[i] += bs; else s[++i] = bs; + } + return s.length < 2 ? q[0] ? (b = q[0].x, function(t) { + return b(t) + ""; + }) : function() { + return b; + } : (b = q.length, function(t) { + for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); + return s.join(""); + }); } - function d3_geom_voronoiEdge(lSite, rSite) { - this.l = lSite; - this.r = rSite; - this.a = this.b = null; + var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g"); + d3.interpolate = d3_interpolate; + function d3_interpolate(a, b) { + var i = d3.interpolators.length, f; + while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ; + return f; + } + d3.interpolators = [ function(a, b) { + var t = typeof b; + return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b); + } ]; + d3.interpolateArray = d3_interpolateArray; + function d3_interpolateArray(a, b) { + var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i; + for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i])); + for (;i < na; ++i) c[i] = a[i]; + for (;i < nb; ++i) c[i] = b[i]; + return function(t) { + for (i = 0; i < n0; ++i) c[i] = x[i](t); + return c; + }; + } + var d3_ease_default = function() { + return d3_identity; + }; + var d3_ease = d3.map({ + linear: d3_ease_default, + poly: d3_ease_poly, + quad: function() { + return d3_ease_quad; + }, + cubic: function() { + return d3_ease_cubic; + }, + sin: function() { + return d3_ease_sin; + }, + exp: function() { + return d3_ease_exp; + }, + circle: function() { + return d3_ease_circle; + }, + elastic: d3_ease_elastic, + back: d3_ease_back, + bounce: function() { + return d3_ease_bounce; + } + }); + var d3_ease_mode = d3.map({ + "in": d3_identity, + out: d3_ease_reverse, + "in-out": d3_ease_reflect, + "out-in": function(f) { + return d3_ease_reflect(d3_ease_reverse(f)); + } + }); + d3.ease = function(name) { + var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in"; + t = d3_ease.get(t) || d3_ease_default; + m = d3_ease_mode.get(m) || d3_identity; + return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1)))); + }; + function d3_ease_clamp(f) { + return function(t) { + return t <= 0 ? 0 : t >= 1 ? 1 : f(t); + }; + } + function d3_ease_reverse(f) { + return function(t) { + return 1 - f(1 - t); + }; + } + function d3_ease_reflect(f) { + return function(t) { + return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t)); + }; + } + function d3_ease_quad(t) { + return t * t; + } + function d3_ease_cubic(t) { + return t * t * t; + } + function d3_ease_cubicInOut(t) { + if (t <= 0) return 0; + if (t >= 1) return 1; + var t2 = t * t, t3 = t2 * t; + return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75); + } + function d3_ease_poly(e) { + return function(t) { + return Math.pow(t, e); + }; + } + function d3_ease_sin(t) { + return 1 - Math.cos(t * halfπ); + } + function d3_ease_exp(t) { + return Math.pow(2, 10 * (t - 1)); + } + function d3_ease_circle(t) { + return 1 - Math.sqrt(1 - t * t); + } + function d3_ease_elastic(a, p) { + var s; + if (arguments.length < 2) p = .45; + if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4; + return function(t) { + return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p); + }; } - function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) { - var edge = new d3_geom_voronoiEdge(lSite, rSite); - d3_geom_voronoiEdges.push(edge); - if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va); - if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb); - d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite)); - d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite)); - return edge; + function d3_ease_back(s) { + if (!s) s = 1.70158; + return function(t) { + return t * t * ((s + 1) * t - s); + }; } - function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) { - var edge = new d3_geom_voronoiEdge(lSite, null); - edge.a = va; - edge.b = vb; - d3_geom_voronoiEdges.push(edge); - return edge; + function d3_ease_bounce(t) { + return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375; } - function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) { - if (!edge.a && !edge.b) { - edge.a = vertex; - edge.l = lSite; - edge.r = rSite; - } else if (edge.l === rSite) { - edge.b = vertex; - } else { - edge.a = vertex; - } + d3.interpolateHcl = d3_interpolateHcl; + function d3_interpolateHcl(a, b) { + a = d3.hcl(a); + b = d3.hcl(b); + var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al; + if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac; + if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; + return function(t) { + return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + ""; + }; } - function d3_geom_voronoiHalfEdge(edge, lSite, rSite) { - var va = edge.a, vb = edge.b; - this.edge = edge; - this.site = lSite; - this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y); + d3.interpolateHsl = d3_interpolateHsl; + function d3_interpolateHsl(a, b) { + a = d3.hsl(a); + b = d3.hsl(b); + var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al; + if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as; + if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; + return function(t) { + return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + ""; + }; } - d3_geom_voronoiHalfEdge.prototype = { - start: function() { - return this.edge.l === this.site ? this.edge.a : this.edge.b; - }, - end: function() { - return this.edge.l === this.site ? this.edge.b : this.edge.a; - } - }; - function d3_geom_voronoiRedBlackTree() { - this._ = null; + d3.interpolateLab = d3_interpolateLab; + function d3_interpolateLab(a, b) { + a = d3.lab(a); + b = d3.lab(b); + var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab; + return function(t) { + return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + ""; + }; } - function d3_geom_voronoiRedBlackNode(node) { - node.U = node.C = node.L = node.R = node.P = node.N = null; + d3.interpolateRound = d3_interpolateRound; + function d3_interpolateRound(a, b) { + b -= a; + return function(t) { + return Math.round(a + b * t); + }; } - d3_geom_voronoiRedBlackTree.prototype = { - insert: function(after, node) { - var parent, grandpa, uncle; - if (after) { - node.P = after; - node.N = after.N; - if (after.N) after.N.P = node; - after.N = node; - if (after.R) { - after = after.R; - while (after.L) after = after.L; - after.L = node; - } else { - after.R = node; - } - parent = after; - } else if (this._) { - after = d3_geom_voronoiRedBlackFirst(this._); - node.P = null; - node.N = after; - after.P = after.L = node; - parent = after; - } else { - node.P = node.N = null; - this._ = node; - parent = null; - } - node.L = node.R = null; - node.U = parent; - node.C = true; - after = node; - while (parent && parent.C) { - grandpa = parent.U; - if (parent === grandpa.L) { - uncle = grandpa.R; - if (uncle && uncle.C) { - parent.C = uncle.C = false; - grandpa.C = true; - after = grandpa; - } else { - if (after === parent.R) { - d3_geom_voronoiRedBlackRotateLeft(this, parent); - after = parent; - parent = after.U; - } - parent.C = false; - grandpa.C = true; - d3_geom_voronoiRedBlackRotateRight(this, grandpa); - } - } else { - uncle = grandpa.L; - if (uncle && uncle.C) { - parent.C = uncle.C = false; - grandpa.C = true; - after = grandpa; - } else { - if (after === parent.L) { - d3_geom_voronoiRedBlackRotateRight(this, parent); - after = parent; - parent = after.U; - } - parent.C = false; - grandpa.C = true; - d3_geom_voronoiRedBlackRotateLeft(this, grandpa); - } - } - parent = after.U; - } - this._.C = false; - }, - remove: function(node) { - if (node.N) node.N.P = node.P; - if (node.P) node.P.N = node.N; - node.N = node.P = null; - var parent = node.U, sibling, left = node.L, right = node.R, next, red; - if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right); - if (parent) { - if (parent.L === node) parent.L = next; else parent.R = next; - } else { - this._ = next; - } - if (left && right) { - red = next.C; - next.C = node.C; - next.L = left; - left.U = next; - if (next !== right) { - parent = next.U; - next.U = node.U; - node = next.R; - parent.L = node; - next.R = right; - right.U = next; - } else { - next.U = parent; - parent = next; - node = next.R; - } - } else { - red = node.C; - node = next; - } - if (node) node.U = parent; - if (red) return; - if (node && node.C) { - node.C = false; - return; + d3.transform = function(string) { + var g = d3_document.createElementNS(d3.ns.prefix.svg, "g"); + return (d3.transform = function(string) { + if (string != null) { + g.setAttribute("transform", string); + var t = g.transform.baseVal.consolidate(); } - do { - if (node === this._) break; - if (node === parent.L) { - sibling = parent.R; - if (sibling.C) { - sibling.C = false; - parent.C = true; - d3_geom_voronoiRedBlackRotateLeft(this, parent); - sibling = parent.R; - } - if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { - if (!sibling.R || !sibling.R.C) { - sibling.L.C = false; - sibling.C = true; - d3_geom_voronoiRedBlackRotateRight(this, sibling); - sibling = parent.R; - } - sibling.C = parent.C; - parent.C = sibling.R.C = false; - d3_geom_voronoiRedBlackRotateLeft(this, parent); - node = this._; - break; - } - } else { - sibling = parent.L; - if (sibling.C) { - sibling.C = false; - parent.C = true; - d3_geom_voronoiRedBlackRotateRight(this, parent); - sibling = parent.L; - } - if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) { - if (!sibling.L || !sibling.L.C) { - sibling.R.C = false; - sibling.C = true; - d3_geom_voronoiRedBlackRotateLeft(this, sibling); - sibling = parent.L; - } - sibling.C = parent.C; - parent.C = sibling.L.C = false; - d3_geom_voronoiRedBlackRotateRight(this, parent); - node = this._; - break; - } - } - sibling.C = true; - node = parent; - parent = parent.U; - } while (!node.C); - if (node) node.C = false; + return new d3_transform(t ? t.matrix : d3_transformIdentity); + })(string); + }; + function d3_transform(m) { + var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0; + if (r0[0] * r1[1] < r1[0] * r0[1]) { + r0[0] *= -1; + r0[1] *= -1; + kx *= -1; + kz *= -1; } + this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees; + this.translate = [ m.e, m.f ]; + this.scale = [ kx, ky ]; + this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0; + } + d3_transform.prototype.toString = function() { + return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")"; }; - function d3_geom_voronoiRedBlackRotateLeft(tree, node) { - var p = node, q = node.R, parent = p.U; - if (parent) { - if (parent.L === p) parent.L = q; else parent.R = q; - } else { - tree._ = q; + function d3_transformDot(a, b) { + return a[0] * b[0] + a[1] * b[1]; + } + function d3_transformNormalize(a) { + var k = Math.sqrt(d3_transformDot(a, a)); + if (k) { + a[0] /= k; + a[1] /= k; } - q.U = parent; - p.U = q; - p.R = q.L; - if (p.R) p.R.U = p; - q.L = p; + return k; } - function d3_geom_voronoiRedBlackRotateRight(tree, node) { - var p = node, q = node.L, parent = p.U; - if (parent) { - if (parent.L === p) parent.L = q; else parent.R = q; - } else { - tree._ = q; + function d3_transformCombine(a, b, k) { + a[0] += k * b[0]; + a[1] += k * b[1]; + return a; + } + var d3_transformIdentity = { + a: 1, + b: 0, + c: 0, + d: 1, + e: 0, + f: 0 + }; + d3.interpolateTransform = d3_interpolateTransform; + function d3_interpolateTransformPop(s) { + return s.length ? s.pop() + "," : ""; + } + function d3_interpolateTranslate(ta, tb, s, q) { + if (ta[0] !== tb[0] || ta[1] !== tb[1]) { + var i = s.push("translate(", null, ",", null, ")"); + q.push({ + i: i - 4, + x: d3_interpolateNumber(ta[0], tb[0]) + }, { + i: i - 2, + x: d3_interpolateNumber(ta[1], tb[1]) + }); + } else if (tb[0] || tb[1]) { + s.push("translate(" + tb + ")"); } - q.U = parent; - p.U = q; - p.L = q.R; - if (p.L) p.L.U = p; - q.R = p; } - function d3_geom_voronoiRedBlackFirst(node) { - while (node.L) node = node.L; - return node; + function d3_interpolateRotate(ra, rb, s, q) { + if (ra !== rb) { + if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; + q.push({ + i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2, + x: d3_interpolateNumber(ra, rb) + }); + } else if (rb) { + s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")"); + } } - function d3_geom_voronoi(sites, bbox) { - var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle; - d3_geom_voronoiEdges = []; - d3_geom_voronoiCells = new Array(sites.length); - d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree(); - d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree(); - while (true) { - circle = d3_geom_voronoiFirstCircle; - if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) { - if (site.x !== x0 || site.y !== y0) { - d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site); - d3_geom_voronoiAddBeach(site); - x0 = site.x, y0 = site.y; + function d3_interpolateSkew(wa, wb, s, q) { + if (wa !== wb) { + q.push({ + i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2, + x: d3_interpolateNumber(wa, wb) + }); + } else if (wb) { + s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")"); + } + } + function d3_interpolateScale(ka, kb, s, q) { + if (ka[0] !== kb[0] || ka[1] !== kb[1]) { + var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")"); + q.push({ + i: i - 4, + x: d3_interpolateNumber(ka[0], kb[0]) + }, { + i: i - 2, + x: d3_interpolateNumber(ka[1], kb[1]) + }); + } else if (kb[0] !== 1 || kb[1] !== 1) { + s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")"); + } + } + function d3_interpolateTransform(a, b) { + var s = [], q = []; + a = d3.transform(a), b = d3.transform(b); + d3_interpolateTranslate(a.translate, b.translate, s, q); + d3_interpolateRotate(a.rotate, b.rotate, s, q); + d3_interpolateSkew(a.skew, b.skew, s, q); + d3_interpolateScale(a.scale, b.scale, s, q); + a = b = null; + return function(t) { + var i = -1, n = q.length, o; + while (++i < n) s[(o = q[i]).i] = o.x(t); + return s.join(""); + }; + } + function d3_uninterpolateNumber(a, b) { + b = (b -= a = +a) || 1 / b; + return function(x) { + return (x - a) / b; + }; + } + function d3_uninterpolateClamp(a, b) { + b = (b -= a = +a) || 1 / b; + return function(x) { + return Math.max(0, Math.min(1, (x - a) / b)); + }; + } + d3.layout = {}; + d3.layout.bundle = function() { + return function(links) { + var paths = [], i = -1, n = links.length; + while (++i < n) paths.push(d3_layout_bundlePath(links[i])); + return paths; + }; + }; + function d3_layout_bundlePath(link) { + var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ]; + while (start !== lca) { + start = start.parent; + points.push(start); + } + var k = points.length; + while (end !== lca) { + points.splice(k, 0, end); + end = end.parent; + } + return points; + } + function d3_layout_bundleAncestors(node) { + var ancestors = [], parent = node.parent; + while (parent != null) { + ancestors.push(node); + node = parent; + parent = parent.parent; + } + ancestors.push(node); + return ancestors; + } + function d3_layout_bundleLeastCommonAncestor(a, b) { + if (a === b) return a; + var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null; + while (aNode === bNode) { + sharedNode = aNode; + aNode = aNodes.pop(); + bNode = bNodes.pop(); + } + return sharedNode; + } + d3.layout.chord = function() { + var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords; + function relayout() { + var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j; + chords = []; + groups = []; + k = 0, i = -1; + while (++i < n) { + x = 0, j = -1; + while (++j < n) { + x += matrix[i][j]; + } + groupSums.push(x); + subgroupIndex.push(d3.range(n)); + k += x; + } + if (sortGroups) { + groupIndex.sort(function(a, b) { + return sortGroups(groupSums[a], groupSums[b]); + }); + } + if (sortSubgroups) { + subgroupIndex.forEach(function(d, i) { + d.sort(function(a, b) { + return sortSubgroups(matrix[i][a], matrix[i][b]); + }); + }); + } + k = (τ - padding * n) / k; + x = 0, i = -1; + while (++i < n) { + x0 = x, j = -1; + while (++j < n) { + var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k; + subgroups[di + "-" + dj] = { + index: di, + subindex: dj, + startAngle: a0, + endAngle: a1, + value: v + }; + } + groups[di] = { + index: di, + startAngle: x0, + endAngle: x, + value: groupSums[di] + }; + x += padding; + } + i = -1; + while (++i < n) { + j = i - 1; + while (++j < n) { + var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i]; + if (source.value || target.value) { + chords.push(source.value < target.value ? { + source: target, + target: source + } : { + source: source, + target: target + }); + } } - site = sites.pop(); - } else if (circle) { - d3_geom_voronoiRemoveBeach(circle.arc); - } else { - break; } + if (sortChords) resort(); } - if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox); - var diagram = { - cells: d3_geom_voronoiCells, - edges: d3_geom_voronoiEdges - }; - d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null; - return diagram; - } - function d3_geom_voronoiVertexOrder(a, b) { - return b.y - a.y || b.x - a.x; - } - d3.geom.voronoi = function(points) { - var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent; - if (points) return voronoi(points); - function voronoi(data) { - var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1]; - d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) { - var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) { - var s = e.start(); - return [ s.x, s.y ]; - }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : []; - polygon.point = data[i]; - }); - return polygons; - } - function sites(data) { - return data.map(function(d, i) { - return { - x: Math.round(fx(d, i) / ε) * ε, - y: Math.round(fy(d, i) / ε) * ε, - i: i - }; + function resort() { + chords.sort(function(a, b) { + return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2); }); } - voronoi.links = function(data) { - return d3_geom_voronoi(sites(data)).edges.filter(function(edge) { - return edge.l && edge.r; - }).map(function(edge) { - return { - source: data[edge.l.i], - target: data[edge.r.i] - }; - }); + chord.matrix = function(x) { + if (!arguments.length) return matrix; + n = (matrix = x) && matrix.length; + chords = groups = null; + return chord; }; - voronoi.triangles = function(data) { - var triangles = []; - d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) { - var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l; - while (++j < m) { - e0 = e1; - s0 = s1; - e1 = edges[j].edge; - s1 = e1.l === site ? e1.r : e1.l; - if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) { - triangles.push([ data[i], data[s0.i], data[s1.i] ]); - } - } - }); - return triangles; + chord.padding = function(x) { + if (!arguments.length) return padding; + padding = x; + chords = groups = null; + return chord; }; - voronoi.x = function(_) { - return arguments.length ? (fx = d3_functor(x = _), voronoi) : x; + chord.sortGroups = function(x) { + if (!arguments.length) return sortGroups; + sortGroups = x; + chords = groups = null; + return chord; }; - voronoi.y = function(_) { - return arguments.length ? (fy = d3_functor(y = _), voronoi) : y; + chord.sortSubgroups = function(x) { + if (!arguments.length) return sortSubgroups; + sortSubgroups = x; + chords = null; + return chord; }; - voronoi.clipExtent = function(_) { - if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent; - clipExtent = _ == null ? d3_geom_voronoiClipExtent : _; - return voronoi; + chord.sortChords = function(x) { + if (!arguments.length) return sortChords; + sortChords = x; + if (chords) resort(); + return chord; }; - voronoi.size = function(_) { - if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1]; - return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]); + chord.chords = function() { + if (!chords) relayout(); + return chords; }; - return voronoi; - }; - var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ]; - function d3_geom_voronoiTriangleArea(a, b, c) { - return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y); - } - d3.geom.delaunay = function(vertices) { - return d3.geom.voronoi().triangles(vertices); + chord.groups = function() { + if (!groups) relayout(); + return groups; + }; + return chord; }; - d3.geom.quadtree = function(points, x1, y1, x2, y2) { - var x = d3_geom_pointX, y = d3_geom_pointY, compat; - if (compat = arguments.length) { - x = d3_geom_quadtreeCompatX; - y = d3_geom_quadtreeCompatY; - if (compat === 3) { - y2 = y1; - x2 = x1; - y1 = x1 = 0; - } - return quadtree(points); + d3.layout.force = function() { + var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges; + function repulse(node) { + return function(quad, x1, _, x2) { + if (quad.point !== node) { + var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy; + if (dw * dw / theta2 < dn) { + if (dn < chargeDistance2) { + var k = quad.charge / dn; + node.px -= dx * k; + node.py -= dy * k; + } + return true; + } + if (quad.point && dn && dn < chargeDistance2) { + var k = quad.pointCharge / dn; + node.px -= dx * k; + node.py -= dy * k; + } + } + return !quad.charge; + }; } - function quadtree(data) { - var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_; - if (x1 != null) { - x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2; - } else { - x2_ = y2_ = -(x1_ = y1_ = Infinity); - xs = [], ys = []; - n = data.length; - if (compat) for (i = 0; i < n; ++i) { - d = data[i]; - if (d.x < x1_) x1_ = d.x; - if (d.y < y1_) y1_ = d.y; - if (d.x > x2_) x2_ = d.x; - if (d.y > y2_) y2_ = d.y; - xs.push(d.x); - ys.push(d.y); - } else for (i = 0; i < n; ++i) { - var x_ = +fx(d = data[i], i), y_ = +fy(d, i); - if (x_ < x1_) x1_ = x_; - if (y_ < y1_) y1_ = y_; - if (x_ > x2_) x2_ = x_; - if (y_ > y2_) y2_ = y_; - xs.push(x_); - ys.push(y_); + force.tick = function() { + if ((alpha *= .99) < .005) { + timer = null; + event.end({ + type: "end", + alpha: alpha = 0 + }); + return true; + } + var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y; + for (i = 0; i < m; ++i) { + o = links[i]; + s = o.source; + t = o.target; + x = t.x - s.x; + y = t.y - s.y; + if (l = x * x + y * y) { + l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l; + x *= l; + y *= l; + t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5); + t.y -= y * k; + s.x += x * (k = 1 - k); + s.y += y * k; } } - var dx = x2_ - x1_, dy = y2_ - y1_; - if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy; - function insert(n, d, x, y, x1, y1, x2, y2) { - if (isNaN(x) || isNaN(y)) return; - if (n.leaf) { - var nx = n.x, ny = n.y; - if (nx != null) { - if (abs(nx - x) + abs(ny - y) < .01) { - insertChild(n, d, x, y, x1, y1, x2, y2); - } else { - var nPoint = n.point; - n.x = n.y = n.point = null; - insertChild(n, nPoint, nx, ny, x1, y1, x2, y2); - insertChild(n, d, x, y, x1, y1, x2, y2); - } - } else { - n.x = x, n.y = y, n.point = d; - } - } else { - insertChild(n, d, x, y, x1, y1, x2, y2); + if (k = alpha * gravity) { + x = size[0] / 2; + y = size[1] / 2; + i = -1; + if (k) while (++i < n) { + o = nodes[i]; + o.x += (x - o.x) * k; + o.y += (y - o.y) * k; } } - function insertChild(n, d, x, y, x1, y1, x2, y2) { - var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right; - n.leaf = false; - n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode()); - if (right) x1 = xm; else x2 = xm; - if (below) y1 = ym; else y2 = ym; - insert(n, d, x, y, x1, y1, x2, y2); + if (charge) { + d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges); + i = -1; + while (++i < n) { + if (!(o = nodes[i]).fixed) { + q.visit(repulse(o)); + } + } } - var root = d3_geom_quadtreeNode(); - root.add = function(d) { - insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_); - }; - root.visit = function(f) { - d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_); - }; - root.find = function(point) { - return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_); - }; i = -1; - if (x1 == null) { - while (++i < n) { - insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_); + while (++i < n) { + o = nodes[i]; + if (o.fixed) { + o.x = o.px; + o.y = o.py; + } else { + o.x -= (o.px - (o.px = o.x)) * friction; + o.y -= (o.py - (o.py = o.y)) * friction; } - --i; - } else data.forEach(root.add); - xs = ys = data = d = null; - return root; - } - quadtree.x = function(_) { - return arguments.length ? (x = _, quadtree) : x; + } + event.tick({ + type: "tick", + alpha: alpha + }); }; - quadtree.y = function(_) { - return arguments.length ? (y = _, quadtree) : y; + force.nodes = function(x) { + if (!arguments.length) return nodes; + nodes = x; + return force; }; - quadtree.extent = function(_) { - if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ]; - if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], - y2 = +_[1][1]; - return quadtree; + force.links = function(x) { + if (!arguments.length) return links; + links = x; + return force; }; - quadtree.size = function(_) { - if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ]; - if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1]; - return quadtree; + force.size = function(x) { + if (!arguments.length) return size; + size = x; + return force; }; - return quadtree; - }; - function d3_geom_quadtreeCompatX(d) { - return d.x; - } - function d3_geom_quadtreeCompatY(d) { - return d.y; - } - function d3_geom_quadtreeNode() { - return { - leaf: true, - nodes: [], - point: null, - x: null, - y: null + force.linkDistance = function(x) { + if (!arguments.length) return linkDistance; + linkDistance = typeof x === "function" ? x : +x; + return force; }; - } - function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) { - if (!f(node, x1, y1, x2, y2)) { - var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes; - if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy); - if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy); - if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2); - if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2); - } - } - function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) { - var minDistance2 = Infinity, closestPoint; - (function find(node, x1, y1, x2, y2) { - if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return; - if (point = node.point) { - var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy; - if (distance2 < minDistance2) { - var distance = Math.sqrt(minDistance2 = distance2); - x0 = x - distance, y0 = y - distance; - x3 = x + distance, y3 = y + distance; - closestPoint = point; - } - } - var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym; - for (var i = below << 1 | right, j = i + 4; i < j; ++i) { - if (node = children[i & 3]) switch (i & 3) { - case 0: - find(node, x1, y1, xm, ym); - break; - - case 1: - find(node, xm, y1, x2, ym); - break; - - case 2: - find(node, x1, ym, xm, y2); - break; - - case 3: - find(node, xm, ym, x2, y2); - break; - } - } - })(root, x0, y0, x3, y3); - return closestPoint; - } - d3.interpolateRgb = d3_interpolateRgb; - function d3_interpolateRgb(a, b) { - a = d3.rgb(a); - b = d3.rgb(b); - var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab; - return function(t) { - return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t)); + force.distance = force.linkDistance; + force.linkStrength = function(x) { + if (!arguments.length) return linkStrength; + linkStrength = typeof x === "function" ? x : +x; + return force; }; - } - d3.interpolateObject = d3_interpolateObject; - function d3_interpolateObject(a, b) { - var i = {}, c = {}, k; - for (k in a) { - if (k in b) { - i[k] = d3_interpolate(a[k], b[k]); - } else { - c[k] = a[k]; - } - } - for (k in b) { - if (!(k in a)) { - c[k] = b[k]; - } - } - return function(t) { - for (k in i) c[k] = i[k](t); - return c; + force.friction = function(x) { + if (!arguments.length) return friction; + friction = +x; + return force; }; - } - d3.interpolateNumber = d3_interpolateNumber; - function d3_interpolateNumber(a, b) { - a = +a, b = +b; - return function(t) { - return a * (1 - t) + b * t; + force.charge = function(x) { + if (!arguments.length) return charge; + charge = typeof x === "function" ? x : +x; + return force; }; - } - d3.interpolateString = d3_interpolateString; - function d3_interpolateString(a, b) { - var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = []; - a = a + "", b = b + ""; - while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) { - if ((bs = bm.index) > bi) { - bs = b.slice(bi, bs); - if (s[i]) s[i] += bs; else s[++i] = bs; - } - if ((am = am[0]) === (bm = bm[0])) { - if (s[i]) s[i] += bm; else s[++i] = bm; - } else { - s[++i] = null; - q.push({ - i: i, - x: d3_interpolateNumber(am, bm) - }); - } - bi = d3_interpolate_numberB.lastIndex; - } - if (bi < b.length) { - bs = b.slice(bi); - if (s[i]) s[i] += bs; else s[++i] = bs; - } - return s.length < 2 ? q[0] ? (b = q[0].x, function(t) { - return b(t) + ""; - }) : function() { - return b; - } : (b = q.length, function(t) { - for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); - return s.join(""); - }); - } - var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g"); - d3.interpolate = d3_interpolate; - function d3_interpolate(a, b) { - var i = d3.interpolators.length, f; - while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ; - return f; - } - d3.interpolators = [ function(a, b) { - var t = typeof b; - return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b); - } ]; - d3.interpolateArray = d3_interpolateArray; - function d3_interpolateArray(a, b) { - var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i; - for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i])); - for (;i < na; ++i) c[i] = a[i]; - for (;i < nb; ++i) c[i] = b[i]; - return function(t) { - for (i = 0; i < n0; ++i) c[i] = x[i](t); - return c; + force.chargeDistance = function(x) { + if (!arguments.length) return Math.sqrt(chargeDistance2); + chargeDistance2 = x * x; + return force; }; - } - var d3_ease_default = function() { - return d3_identity; - }; - var d3_ease = d3.map({ - linear: d3_ease_default, - poly: d3_ease_poly, - quad: function() { - return d3_ease_quad; - }, - cubic: function() { - return d3_ease_cubic; - }, - sin: function() { - return d3_ease_sin; - }, - exp: function() { - return d3_ease_exp; - }, - circle: function() { - return d3_ease_circle; - }, - elastic: d3_ease_elastic, - back: d3_ease_back, - bounce: function() { - return d3_ease_bounce; - } - }); - var d3_ease_mode = d3.map({ - "in": d3_identity, - out: d3_ease_reverse, - "in-out": d3_ease_reflect, - "out-in": function(f) { - return d3_ease_reflect(d3_ease_reverse(f)); - } - }); - d3.ease = function(name) { - var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in"; - t = d3_ease.get(t) || d3_ease_default; - m = d3_ease_mode.get(m) || d3_identity; - return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1)))); - }; - function d3_ease_clamp(f) { - return function(t) { - return t <= 0 ? 0 : t >= 1 ? 1 : f(t); + force.gravity = function(x) { + if (!arguments.length) return gravity; + gravity = +x; + return force; + }; + force.theta = function(x) { + if (!arguments.length) return Math.sqrt(theta2); + theta2 = x * x; + return force; }; - } - function d3_ease_reverse(f) { - return function(t) { - return 1 - f(1 - t); + force.alpha = function(x) { + if (!arguments.length) return alpha; + x = +x; + if (alpha) { + if (x > 0) { + alpha = x; + } else { + timer.c = null, timer.t = NaN, timer = null; + event.end({ + type: "end", + alpha: alpha = 0 + }); + } + } else if (x > 0) { + event.start({ + type: "start", + alpha: alpha = x + }); + timer = d3_timer(force.tick); + } + return force; }; - } - function d3_ease_reflect(f) { - return function(t) { - return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t)); + force.start = function() { + var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o; + for (i = 0; i < n; ++i) { + (o = nodes[i]).index = i; + o.weight = 0; + } + for (i = 0; i < m; ++i) { + o = links[i]; + if (typeof o.source == "number") o.source = nodes[o.source]; + if (typeof o.target == "number") o.target = nodes[o.target]; + ++o.source.weight; + ++o.target.weight; + } + for (i = 0; i < n; ++i) { + o = nodes[i]; + if (isNaN(o.x)) o.x = position("x", w); + if (isNaN(o.y)) o.y = position("y", h); + if (isNaN(o.px)) o.px = o.x; + if (isNaN(o.py)) o.py = o.y; + } + distances = []; + if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance; + strengths = []; + if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength; + charges = []; + if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge; + function position(dimension, size) { + if (!neighbors) { + neighbors = new Array(n); + for (j = 0; j < n; ++j) { + neighbors[j] = []; + } + for (j = 0; j < m; ++j) { + var o = links[j]; + neighbors[o.source.index].push(o.target); + neighbors[o.target.index].push(o.source); + } + } + var candidates = neighbors[i], j = -1, l = candidates.length, x; + while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x; + return Math.random() * size; + } + return force.resume(); }; - } - function d3_ease_quad(t) { - return t * t; - } - function d3_ease_cubic(t) { - return t * t * t; - } - function d3_ease_cubicInOut(t) { - if (t <= 0) return 0; - if (t >= 1) return 1; - var t2 = t * t, t3 = t2 * t; - return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75); - } - function d3_ease_poly(e) { - return function(t) { - return Math.pow(t, e); + force.resume = function() { + return force.alpha(.1); }; + force.stop = function() { + return force.alpha(0); + }; + force.drag = function() { + if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend); + if (!arguments.length) return drag; + this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag); + }; + function dragmove(d) { + d.px = d3.event.x, d.py = d3.event.y; + force.resume(); + } + return d3.rebind(force, event, "on"); + }; + function d3_layout_forceDragstart(d) { + d.fixed |= 2; } - function d3_ease_sin(t) { - return 1 - Math.cos(t * halfπ); - } - function d3_ease_exp(t) { - return Math.pow(2, 10 * (t - 1)); - } - function d3_ease_circle(t) { - return 1 - Math.sqrt(1 - t * t); + function d3_layout_forceDragend(d) { + d.fixed &= ~6; } - function d3_ease_elastic(a, p) { - var s; - if (arguments.length < 2) p = .45; - if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4; - return function(t) { - return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p); - }; + function d3_layout_forceMouseover(d) { + d.fixed |= 4; + d.px = d.x, d.py = d.y; } - function d3_ease_back(s) { - if (!s) s = 1.70158; - return function(t) { - return t * t * ((s + 1) * t - s); - }; + function d3_layout_forceMouseout(d) { + d.fixed &= ~4; } - function d3_ease_bounce(t) { - return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375; + function d3_layout_forceAccumulate(quad, alpha, charges) { + var cx = 0, cy = 0; + quad.charge = 0; + if (!quad.leaf) { + var nodes = quad.nodes, n = nodes.length, i = -1, c; + while (++i < n) { + c = nodes[i]; + if (c == null) continue; + d3_layout_forceAccumulate(c, alpha, charges); + quad.charge += c.charge; + cx += c.charge * c.cx; + cy += c.charge * c.cy; + } + } + if (quad.point) { + if (!quad.leaf) { + quad.point.x += Math.random() - .5; + quad.point.y += Math.random() - .5; + } + var k = alpha * charges[quad.point.index]; + quad.charge += quad.pointCharge = k; + cx += k * quad.point.x; + cy += k * quad.point.y; + } + quad.cx = cx / quad.charge; + quad.cy = cy / quad.charge; } - d3.interpolateHcl = d3_interpolateHcl; - function d3_interpolateHcl(a, b) { - a = d3.hcl(a); - b = d3.hcl(b); - var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al; - if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac; - if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; - return function(t) { - return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + ""; + var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity; + d3.layout.hierarchy = function() { + var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue; + function hierarchy(root) { + var stack = [ root ], nodes = [], node; + root.depth = 0; + while ((node = stack.pop()) != null) { + nodes.push(node); + if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) { + var n, childs, child; + while (--n >= 0) { + stack.push(child = childs[n]); + child.parent = node; + child.depth = node.depth + 1; + } + if (value) node.value = 0; + node.children = childs; + } else { + if (value) node.value = +value.call(hierarchy, node, node.depth) || 0; + delete node.children; + } + } + d3_layout_hierarchyVisitAfter(root, function(node) { + var childs, parent; + if (sort && (childs = node.children)) childs.sort(sort); + if (value && (parent = node.parent)) parent.value += node.value; + }); + return nodes; + } + hierarchy.sort = function(x) { + if (!arguments.length) return sort; + sort = x; + return hierarchy; }; - } - d3.interpolateHsl = d3_interpolateHsl; - function d3_interpolateHsl(a, b) { - a = d3.hsl(a); - b = d3.hsl(b); - var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al; - if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as; - if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; - return function(t) { - return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + ""; + hierarchy.children = function(x) { + if (!arguments.length) return children; + children = x; + return hierarchy; }; - } - d3.interpolateLab = d3_interpolateLab; - function d3_interpolateLab(a, b) { - a = d3.lab(a); - b = d3.lab(b); - var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab; - return function(t) { - return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + ""; + hierarchy.value = function(x) { + if (!arguments.length) return value; + value = x; + return hierarchy; }; - } - d3.interpolateRound = d3_interpolateRound; - function d3_interpolateRound(a, b) { - b -= a; - return function(t) { - return Math.round(a + b * t); + hierarchy.revalue = function(root) { + if (value) { + d3_layout_hierarchyVisitBefore(root, function(node) { + if (node.children) node.value = 0; + }); + d3_layout_hierarchyVisitAfter(root, function(node) { + var parent; + if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0; + if (parent = node.parent) parent.value += node.value; + }); + } + return root; }; + return hierarchy; + }; + function d3_layout_hierarchyRebind(object, hierarchy) { + d3.rebind(object, hierarchy, "sort", "children", "value"); + object.nodes = object; + object.links = d3_layout_hierarchyLinks; + return object; } - d3.transform = function(string) { - var g = d3_document.createElementNS(d3.ns.prefix.svg, "g"); - return (d3.transform = function(string) { - if (string != null) { - g.setAttribute("transform", string); - var t = g.transform.baseVal.consolidate(); + function d3_layout_hierarchyVisitBefore(node, callback) { + var nodes = [ node ]; + while ((node = nodes.pop()) != null) { + callback(node); + if ((children = node.children) && (n = children.length)) { + var n, children; + while (--n >= 0) nodes.push(children[n]); } - return new d3_transform(t ? t.matrix : d3_transformIdentity); - })(string); - }; - function d3_transform(m) { - var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0; - if (r0[0] * r1[1] < r1[0] * r0[1]) { - r0[0] *= -1; - r0[1] *= -1; - kx *= -1; - kz *= -1; } - this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees; - this.translate = [ m.e, m.f ]; - this.scale = [ kx, ky ]; - this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0; - } - d3_transform.prototype.toString = function() { - return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")"; - }; - function d3_transformDot(a, b) { - return a[0] * b[0] + a[1] * b[1]; } - function d3_transformNormalize(a) { - var k = Math.sqrt(d3_transformDot(a, a)); - if (k) { - a[0] /= k; - a[1] /= k; + function d3_layout_hierarchyVisitAfter(node, callback) { + var nodes = [ node ], nodes2 = []; + while ((node = nodes.pop()) != null) { + nodes2.push(node); + if ((children = node.children) && (n = children.length)) { + var i = -1, n, children; + while (++i < n) nodes.push(children[i]); + } + } + while ((node = nodes2.pop()) != null) { + callback(node); } - return k; } - function d3_transformCombine(a, b, k) { - a[0] += k * b[0]; - a[1] += k * b[1]; - return a; + function d3_layout_hierarchyChildren(d) { + return d.children; } - var d3_transformIdentity = { - a: 1, - b: 0, - c: 0, - d: 1, - e: 0, - f: 0 - }; - d3.interpolateTransform = d3_interpolateTransform; - function d3_interpolateTransformPop(s) { - return s.length ? s.pop() + "," : ""; + function d3_layout_hierarchyValue(d) { + return d.value; } - function d3_interpolateTranslate(ta, tb, s, q) { - if (ta[0] !== tb[0] || ta[1] !== tb[1]) { - var i = s.push("translate(", null, ",", null, ")"); - q.push({ - i: i - 4, - x: d3_interpolateNumber(ta[0], tb[0]) - }, { - i: i - 2, - x: d3_interpolateNumber(ta[1], tb[1]) - }); - } else if (tb[0] || tb[1]) { - s.push("translate(" + tb + ")"); - } + function d3_layout_hierarchySort(a, b) { + return b.value - a.value; } - function d3_interpolateRotate(ra, rb, s, q) { - if (ra !== rb) { - if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; - q.push({ - i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2, - x: d3_interpolateNumber(ra, rb) + function d3_layout_hierarchyLinks(nodes) { + return d3.merge(nodes.map(function(parent) { + return (parent.children || []).map(function(child) { + return { + source: parent, + target: child + }; }); - } else if (rb) { - s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")"); - } + })); } - function d3_interpolateSkew(wa, wb, s, q) { - if (wa !== wb) { - q.push({ - i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2, - x: d3_interpolateNumber(wa, wb) + d3.layout.partition = function() { + var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ]; + function position(node, x, dx, dy) { + var children = node.children; + node.x = x; + node.y = node.depth * dy; + node.dx = dx; + node.dy = dy; + if (children && (n = children.length)) { + var i = -1, n, c, d; + dx = node.value ? dx / node.value : 0; + while (++i < n) { + position(c = children[i], x, d = c.value * dx, dy); + x += d; + } + } + } + function depth(node) { + var children = node.children, d = 0; + if (children && (n = children.length)) { + var i = -1, n; + while (++i < n) d = Math.max(d, depth(children[i])); + } + return 1 + d; + } + function partition(d, i) { + var nodes = hierarchy.call(this, d, i); + position(nodes[0], 0, size[0], size[1] / depth(nodes[0])); + return nodes; + } + partition.size = function(x) { + if (!arguments.length) return size; + size = x; + return partition; + }; + return d3_layout_hierarchyRebind(partition, hierarchy); + }; + d3.layout.pie = function() { + var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0; + function pie(data) { + var n = data.length, values = data.map(function(d, i) { + return +value.call(pie, d, i); + }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v; + if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) { + return values[j] - values[i]; + } : function(i, j) { + return sort(data[i], data[j]); }); - } else if (wb) { - s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")"); + index.forEach(function(i) { + arcs[i] = { + data: data[i], + value: v = values[i], + startAngle: a, + endAngle: a += v * k + pa, + padAngle: p + }; + }); + return arcs; } - } - function d3_interpolateScale(ka, kb, s, q) { - if (ka[0] !== kb[0] || ka[1] !== kb[1]) { - var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")"); - q.push({ - i: i - 4, - x: d3_interpolateNumber(ka[0], kb[0]) - }, { - i: i - 2, - x: d3_interpolateNumber(ka[1], kb[1]) + pie.value = function(_) { + if (!arguments.length) return value; + value = _; + return pie; + }; + pie.sort = function(_) { + if (!arguments.length) return sort; + sort = _; + return pie; + }; + pie.startAngle = function(_) { + if (!arguments.length) return startAngle; + startAngle = _; + return pie; + }; + pie.endAngle = function(_) { + if (!arguments.length) return endAngle; + endAngle = _; + return pie; + }; + pie.padAngle = function(_) { + if (!arguments.length) return padAngle; + padAngle = _; + return pie; + }; + return pie; + }; + var d3_layout_pieSortByValue = {}; + d3.layout.stack = function() { + var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY; + function stack(data, index) { + if (!(n = data.length)) return data; + var series = data.map(function(d, i) { + return values.call(stack, d, i); }); - } else if (kb[0] !== 1 || kb[1] !== 1) { - s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")"); + var points = series.map(function(d) { + return d.map(function(v, i) { + return [ x.call(stack, v, i), y.call(stack, v, i) ]; + }); + }); + var orders = order.call(stack, points, index); + series = d3.permute(series, orders); + points = d3.permute(points, orders); + var offsets = offset.call(stack, points, index); + var m = series[0].length, n, i, j, o; + for (j = 0; j < m; ++j) { + out.call(stack, series[0][j], o = offsets[j], points[0][j][1]); + for (i = 1; i < n; ++i) { + out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]); + } + } + return data; } - } - function d3_interpolateTransform(a, b) { - var s = [], q = []; - a = d3.transform(a), b = d3.transform(b); - d3_interpolateTranslate(a.translate, b.translate, s, q); - d3_interpolateRotate(a.rotate, b.rotate, s, q); - d3_interpolateSkew(a.skew, b.skew, s, q); - d3_interpolateScale(a.scale, b.scale, s, q); - a = b = null; - return function(t) { - var i = -1, n = q.length, o; - while (++i < n) s[(o = q[i]).i] = o.x(t); - return s.join(""); + stack.values = function(x) { + if (!arguments.length) return values; + values = x; + return stack; + }; + stack.order = function(x) { + if (!arguments.length) return order; + order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault; + return stack; + }; + stack.offset = function(x) { + if (!arguments.length) return offset; + offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero; + return stack; }; - } - function d3_uninterpolateNumber(a, b) { - b = (b -= a = +a) || 1 / b; - return function(x) { - return (x - a) / b; + stack.x = function(z) { + if (!arguments.length) return x; + x = z; + return stack; }; - } - function d3_uninterpolateClamp(a, b) { - b = (b -= a = +a) || 1 / b; - return function(x) { - return Math.max(0, Math.min(1, (x - a) / b)); + stack.y = function(z) { + if (!arguments.length) return y; + y = z; + return stack; }; - } - d3.layout = {}; - d3.layout.bundle = function() { - return function(links) { - var paths = [], i = -1, n = links.length; - while (++i < n) paths.push(d3_layout_bundlePath(links[i])); - return paths; + stack.out = function(z) { + if (!arguments.length) return out; + out = z; + return stack; }; + return stack; }; - function d3_layout_bundlePath(link) { - var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ]; - while (start !== lca) { - start = start.parent; - points.push(start); - } - var k = points.length; - while (end !== lca) { - points.splice(k, 0, end); - end = end.parent; - } - return points; + function d3_layout_stackX(d) { + return d.x; } - function d3_layout_bundleAncestors(node) { - var ancestors = [], parent = node.parent; - while (parent != null) { - ancestors.push(node); - node = parent; - parent = parent.parent; - } - ancestors.push(node); - return ancestors; + function d3_layout_stackY(d) { + return d.y; } - function d3_layout_bundleLeastCommonAncestor(a, b) { - if (a === b) return a; - var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null; - while (aNode === bNode) { - sharedNode = aNode; - aNode = aNodes.pop(); - bNode = bNodes.pop(); - } - return sharedNode; + function d3_layout_stackOut(d, y0, y) { + d.y0 = y0; + d.y = y; } - d3.layout.chord = function() { - var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords; - function relayout() { - var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j; - chords = []; - groups = []; - k = 0, i = -1; - while (++i < n) { - x = 0, j = -1; - while (++j < n) { - x += matrix[i][j]; + var d3_layout_stackOrders = d3.map({ + "inside-out": function(data) { + var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) { + return max[a] - max[b]; + }), top = 0, bottom = 0, tops = [], bottoms = []; + for (i = 0; i < n; ++i) { + j = index[i]; + if (top < bottom) { + top += sums[j]; + tops.push(j); + } else { + bottom += sums[j]; + bottoms.push(j); } - groupSums.push(x); - subgroupIndex.push(d3.range(n)); - k += x; } - if (sortGroups) { - groupIndex.sort(function(a, b) { - return sortGroups(groupSums[a], groupSums[b]); - }); + return bottoms.reverse().concat(tops); + }, + reverse: function(data) { + return d3.range(data.length).reverse(); + }, + "default": d3_layout_stackOrderDefault + }); + var d3_layout_stackOffsets = d3.map({ + silhouette: function(data) { + var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = []; + for (j = 0; j < m; ++j) { + for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; + if (o > max) max = o; + sums.push(o); } - if (sortSubgroups) { - subgroupIndex.forEach(function(d, i) { - d.sort(function(a, b) { - return sortSubgroups(matrix[i][a], matrix[i][b]); - }); - }); + for (j = 0; j < m; ++j) { + y0[j] = (max - sums[j]) / 2; } - k = (τ - padding * n) / k; - x = 0, i = -1; - while (++i < n) { - x0 = x, j = -1; - while (++j < n) { - var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k; - subgroups[di + "-" + dj] = { - index: di, - subindex: dj, - startAngle: a0, - endAngle: a1, - value: v - }; + return y0; + }, + wiggle: function(data) { + var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = []; + y0[0] = o = o0 = 0; + for (j = 1; j < m; ++j) { + for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1]; + for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) { + for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) { + s3 += (data[k][j][1] - data[k][j - 1][1]) / dx; + } + s2 += s3 * data[i][j][1]; } - groups[di] = { - index: di, - startAngle: x0, - endAngle: x, - value: groupSums[di] - }; - x += padding; + y0[j] = o -= s1 ? s2 / s1 * dx : 0; + if (o < o0) o0 = o; } - i = -1; - while (++i < n) { - j = i - 1; - while (++j < n) { - var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i]; - if (source.value || target.value) { - chords.push(source.value < target.value ? { - source: target, - target: source - } : { - source: source, - target: target - }); + for (j = 0; j < m; ++j) y0[j] -= o0; + return y0; + }, + expand: function(data) { + var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = []; + for (j = 0; j < m; ++j) { + for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; + if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k; + } + for (j = 0; j < m; ++j) y0[j] = 0; + return y0; + }, + zero: d3_layout_stackOffsetZero + }); + function d3_layout_stackOrderDefault(data) { + return d3.range(data.length); + } + function d3_layout_stackOffsetZero(data) { + var j = -1, m = data[0].length, y0 = []; + while (++j < m) y0[j] = 0; + return y0; + } + function d3_layout_stackMaxIndex(array) { + var i = 1, j = 0, v = array[0][1], k, n = array.length; + for (;i < n; ++i) { + if ((k = array[i][1]) > v) { + j = i; + v = k; + } + } + return j; + } + function d3_layout_stackReduceSum(d) { + return d.reduce(d3_layout_stackSum, 0); + } + function d3_layout_stackSum(p, d) { + return p + d[1]; + } + d3.layout.histogram = function() { + var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges; + function histogram(data, i) { + var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x; + while (++i < m) { + bin = bins[i] = []; + bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]); + bin.y = 0; + } + if (m > 0) { + i = -1; + while (++i < n) { + x = values[i]; + if (x >= range[0] && x <= range[1]) { + bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; + bin.y += k; + bin.push(data[i]); } } } - if (sortChords) resort(); - } - function resort() { - chords.sort(function(a, b) { - return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2); - }); + return bins; } - chord.matrix = function(x) { - if (!arguments.length) return matrix; - n = (matrix = x) && matrix.length; - chords = groups = null; - return chord; + histogram.value = function(x) { + if (!arguments.length) return valuer; + valuer = x; + return histogram; }; - chord.padding = function(x) { - if (!arguments.length) return padding; - padding = x; - chords = groups = null; - return chord; + histogram.range = function(x) { + if (!arguments.length) return ranger; + ranger = d3_functor(x); + return histogram; }; - chord.sortGroups = function(x) { - if (!arguments.length) return sortGroups; - sortGroups = x; - chords = groups = null; - return chord; + histogram.bins = function(x) { + if (!arguments.length) return binner; + binner = typeof x === "number" ? function(range) { + return d3_layout_histogramBinFixed(range, x); + } : d3_functor(x); + return histogram; }; - chord.sortSubgroups = function(x) { - if (!arguments.length) return sortSubgroups; - sortSubgroups = x; - chords = null; - return chord; + histogram.frequency = function(x) { + if (!arguments.length) return frequency; + frequency = !!x; + return histogram; }; - chord.sortChords = function(x) { - if (!arguments.length) return sortChords; - sortChords = x; - if (chords) resort(); - return chord; + return histogram; + }; + function d3_layout_histogramBinSturges(range, values) { + return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1)); + } + function d3_layout_histogramBinFixed(range, n) { + var x = -1, b = +range[0], m = (range[1] - b) / n, f = []; + while (++x <= n) f[x] = m * x + b; + return f; + } + function d3_layout_histogramRange(values) { + return [ d3.min(values), d3.max(values) ]; + } + d3.layout.pack = function() { + var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius; + function pack(d, i) { + var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() { + return radius; + }; + root.x = root.y = 0; + d3_layout_hierarchyVisitAfter(root, function(d) { + d.r = +r(d.value); + }); + d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); + if (padding) { + var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2; + d3_layout_hierarchyVisitAfter(root, function(d) { + d.r += dr; + }); + d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); + d3_layout_hierarchyVisitAfter(root, function(d) { + d.r -= dr; + }); + } + d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h)); + return nodes; + } + pack.size = function(_) { + if (!arguments.length) return size; + size = _; + return pack; }; - chord.chords = function() { - if (!chords) relayout(); - return chords; + pack.radius = function(_) { + if (!arguments.length) return radius; + radius = _ == null || typeof _ === "function" ? _ : +_; + return pack; }; - chord.groups = function() { - if (!groups) relayout(); - return groups; + pack.padding = function(_) { + if (!arguments.length) return padding; + padding = +_; + return pack; }; - return chord; + return d3_layout_hierarchyRebind(pack, hierarchy); }; - d3.layout.force = function() { - var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges; - function repulse(node) { - return function(quad, x1, _, x2) { - if (quad.point !== node) { - var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy; - if (dw * dw / theta2 < dn) { - if (dn < chargeDistance2) { - var k = quad.charge / dn; - node.px -= dx * k; - node.py -= dy * k; + function d3_layout_packSort(a, b) { + return a.value - b.value; + } + function d3_layout_packInsert(a, b) { + var c = a._pack_next; + a._pack_next = b; + b._pack_prev = a; + b._pack_next = c; + c._pack_prev = b; + } + function d3_layout_packSplice(a, b) { + a._pack_next = b; + b._pack_prev = a; + } + function d3_layout_packIntersects(a, b) { + var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r; + return .999 * dr * dr > dx * dx + dy * dy; + } + function d3_layout_packSiblings(node) { + if (!(nodes = node.children) || !(n = nodes.length)) return; + var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n; + function bound(node) { + xMin = Math.min(node.x - node.r, xMin); + xMax = Math.max(node.x + node.r, xMax); + yMin = Math.min(node.y - node.r, yMin); + yMax = Math.max(node.y + node.r, yMax); + } + nodes.forEach(d3_layout_packLink); + a = nodes[0]; + a.x = -a.r; + a.y = 0; + bound(a); + if (n > 1) { + b = nodes[1]; + b.x = b.r; + b.y = 0; + bound(b); + if (n > 2) { + c = nodes[2]; + d3_layout_packPlace(a, b, c); + bound(c); + d3_layout_packInsert(a, c); + a._pack_prev = c; + d3_layout_packInsert(c, b); + b = a._pack_next; + for (i = 3; i < n; i++) { + d3_layout_packPlace(a, b, c = nodes[i]); + var isect = 0, s1 = 1, s2 = 1; + for (j = b._pack_next; j !== b; j = j._pack_next, s1++) { + if (d3_layout_packIntersects(j, c)) { + isect = 1; + break; } - return true; } - if (quad.point && dn && dn < chargeDistance2) { - var k = quad.pointCharge / dn; - node.px -= dx * k; - node.py -= dy * k; + if (isect == 1) { + for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) { + if (d3_layout_packIntersects(k, c)) { + break; + } + } + } + if (isect) { + if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b); + i--; + } else { + d3_layout_packInsert(a, c); + b = c; + bound(c); } } - return !quad.charge; - }; + } } - force.tick = function() { - if ((alpha *= .99) < .005) { - timer = null; - event.end({ - type: "end", - alpha: alpha = 0 + var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0; + for (i = 0; i < n; i++) { + c = nodes[i]; + c.x -= cx; + c.y -= cy; + cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y)); + } + node.r = cr; + nodes.forEach(d3_layout_packUnlink); + } + function d3_layout_packLink(node) { + node._pack_next = node._pack_prev = node; + } + function d3_layout_packUnlink(node) { + delete node._pack_next; + delete node._pack_prev; + } + function d3_layout_packTransform(node, x, y, k) { + var children = node.children; + node.x = x += k * node.x; + node.y = y += k * node.y; + node.r *= k; + if (children) { + var i = -1, n = children.length; + while (++i < n) d3_layout_packTransform(children[i], x, y, k); + } + } + function d3_layout_packPlace(a, b, c) { + var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y; + if (db && (dx || dy)) { + var da = b.r + c.r, dc = dx * dx + dy * dy; + da *= da; + db *= db; + var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc); + c.x = a.x + x * dx + y * dy; + c.y = a.y + x * dy - y * dx; + } else { + c.x = a.x + db; + c.y = a.y; + } + } + d3.layout.tree = function() { + var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null; + function tree(d, i) { + var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0); + d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z; + d3_layout_hierarchyVisitBefore(root1, secondWalk); + if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else { + var left = root0, right = root0, bottom = root0; + d3_layout_hierarchyVisitBefore(root0, function(node) { + if (node.x < left.x) left = node; + if (node.x > right.x) right = node; + if (node.depth > bottom.depth) bottom = node; + }); + var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1); + d3_layout_hierarchyVisitBefore(root0, function(node) { + node.x = (node.x + tx) * kx; + node.y = node.depth * ky; }); - return true; } - var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y; - for (i = 0; i < m; ++i) { - o = links[i]; - s = o.source; - t = o.target; - x = t.x - s.x; - y = t.y - s.y; - if (l = x * x + y * y) { - l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l; - x *= l; - y *= l; - t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5); - t.y -= y * k; - s.x += x * (k = 1 - k); - s.y += y * k; + return nodes; + } + function wrapTree(root0) { + var root1 = { + A: null, + children: [ root0 ] + }, queue = [ root1 ], node1; + while ((node1 = queue.pop()) != null) { + for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) { + queue.push((children[i] = child = { + _: children[i], + parent: node1, + children: (child = children[i].children) && child.slice() || [], + A: null, + a: null, + z: 0, + m: 0, + c: 0, + s: 0, + t: null, + i: i + }).a = child); } } - if (k = alpha * gravity) { - x = size[0] / 2; - y = size[1] / 2; - i = -1; - if (k) while (++i < n) { - o = nodes[i]; - o.x += (x - o.x) * k; - o.y += (y - o.y) * k; + return root1.children[0]; + } + function firstWalk(v) { + var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null; + if (children.length) { + d3_layout_treeShift(v); + var midpoint = (children[0].z + children[children.length - 1].z) / 2; + if (w) { + v.z = w.z + separation(v._, w._); + v.m = v.z - midpoint; + } else { + v.z = midpoint; } + } else if (w) { + v.z = w.z + separation(v._, w._); } - if (charge) { - d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges); - i = -1; - while (++i < n) { - if (!(o = nodes[i]).fixed) { - q.visit(repulse(o)); + v.parent.A = apportion(v, w, v.parent.A || siblings[0]); + } + function secondWalk(v) { + v._.x = v.z + v.parent.m; + v.m += v.parent.m; + } + function apportion(v, w, ancestor) { + if (w) { + var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift; + while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) { + vom = d3_layout_treeLeft(vom); + vop = d3_layout_treeRight(vop); + vop.a = v; + shift = vim.z + sim - vip.z - sip + separation(vim._, vip._); + if (shift > 0) { + d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift); + sip += shift; + sop += shift; } + sim += vim.m; + sip += vip.m; + som += vom.m; + sop += vop.m; } - } - i = -1; - while (++i < n) { - o = nodes[i]; - if (o.fixed) { - o.x = o.px; - o.y = o.py; - } else { - o.x -= (o.px - (o.px = o.x)) * friction; - o.y -= (o.py - (o.py = o.y)) * friction; + if (vim && !d3_layout_treeRight(vop)) { + vop.t = vim; + vop.m += sim - sop; + } + if (vip && !d3_layout_treeLeft(vom)) { + vom.t = vip; + vom.m += sip - som; + ancestor = v; } } - event.tick({ - type: "tick", - alpha: alpha - }); - }; - force.nodes = function(x) { - if (!arguments.length) return nodes; - nodes = x; - return force; - }; - force.links = function(x) { - if (!arguments.length) return links; - links = x; - return force; - }; - force.size = function(x) { - if (!arguments.length) return size; - size = x; - return force; - }; - force.linkDistance = function(x) { - if (!arguments.length) return linkDistance; - linkDistance = typeof x === "function" ? x : +x; - return force; - }; - force.distance = force.linkDistance; - force.linkStrength = function(x) { - if (!arguments.length) return linkStrength; - linkStrength = typeof x === "function" ? x : +x; - return force; - }; - force.friction = function(x) { - if (!arguments.length) return friction; - friction = +x; - return force; - }; - force.charge = function(x) { - if (!arguments.length) return charge; - charge = typeof x === "function" ? x : +x; - return force; - }; - force.chargeDistance = function(x) { - if (!arguments.length) return Math.sqrt(chargeDistance2); - chargeDistance2 = x * x; - return force; + return ancestor; + } + function sizeNode(node) { + node.x *= size[0]; + node.y = node.depth * size[1]; + } + tree.separation = function(x) { + if (!arguments.length) return separation; + separation = x; + return tree; }; - force.gravity = function(x) { - if (!arguments.length) return gravity; - gravity = +x; - return force; + tree.size = function(x) { + if (!arguments.length) return nodeSize ? null : size; + nodeSize = (size = x) == null ? sizeNode : null; + return tree; }; - force.theta = function(x) { - if (!arguments.length) return Math.sqrt(theta2); - theta2 = x * x; - return force; + tree.nodeSize = function(x) { + if (!arguments.length) return nodeSize ? size : null; + nodeSize = (size = x) == null ? null : sizeNode; + return tree; }; - force.alpha = function(x) { - if (!arguments.length) return alpha; - x = +x; - if (alpha) { - if (x > 0) { - alpha = x; + return d3_layout_hierarchyRebind(tree, hierarchy); + }; + function d3_layout_treeSeparation(a, b) { + return a.parent == b.parent ? 1 : 2; + } + function d3_layout_treeLeft(v) { + var children = v.children; + return children.length ? children[0] : v.t; + } + function d3_layout_treeRight(v) { + var children = v.children, n; + return (n = children.length) ? children[n - 1] : v.t; + } + function d3_layout_treeMove(wm, wp, shift) { + var change = shift / (wp.i - wm.i); + wp.c -= change; + wp.s += shift; + wm.c += change; + wp.z += shift; + wp.m += shift; + } + function d3_layout_treeShift(v) { + var shift = 0, change = 0, children = v.children, i = children.length, w; + while (--i >= 0) { + w = children[i]; + w.z += shift; + w.m += shift; + shift += w.s + (change += w.c); + } + } + function d3_layout_treeAncestor(vim, v, ancestor) { + return vim.a.parent === v.parent ? vim.a : ancestor; + } + d3.layout.cluster = function() { + var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false; + function cluster(d, i) { + var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0; + d3_layout_hierarchyVisitAfter(root, function(node) { + var children = node.children; + if (children && children.length) { + node.x = d3_layout_clusterX(children); + node.y = d3_layout_clusterY(children); } else { - timer.c = null, timer.t = NaN, timer = null; - event.end({ - type: "end", - alpha: alpha = 0 - }); - } - } else if (x > 0) { - event.start({ - type: "start", - alpha: alpha = x - }); - timer = d3_timer(force.tick); - } - return force; - }; - force.start = function() { - var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o; - for (i = 0; i < n; ++i) { - (o = nodes[i]).index = i; - o.weight = 0; - } - for (i = 0; i < m; ++i) { - o = links[i]; - if (typeof o.source == "number") o.source = nodes[o.source]; - if (typeof o.target == "number") o.target = nodes[o.target]; - ++o.source.weight; - ++o.target.weight; - } - for (i = 0; i < n; ++i) { - o = nodes[i]; - if (isNaN(o.x)) o.x = position("x", w); - if (isNaN(o.y)) o.y = position("y", h); - if (isNaN(o.px)) o.px = o.x; - if (isNaN(o.py)) o.py = o.y; - } - distances = []; - if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance; - strengths = []; - if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength; - charges = []; - if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge; - function position(dimension, size) { - if (!neighbors) { - neighbors = new Array(n); - for (j = 0; j < n; ++j) { - neighbors[j] = []; - } - for (j = 0; j < m; ++j) { - var o = links[j]; - neighbors[o.source.index].push(o.target); - neighbors[o.target.index].push(o.source); - } + node.x = previousNode ? x += separation(node, previousNode) : 0; + node.y = 0; + previousNode = node; } - var candidates = neighbors[i], j = -1, l = candidates.length, x; - while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x; - return Math.random() * size; - } - return force.resume(); - }; - force.resume = function() { - return force.alpha(.1); + }); + var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2; + d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) { + node.x = (node.x - root.x) * size[0]; + node.y = (root.y - node.y) * size[1]; + } : function(node) { + node.x = (node.x - x0) / (x1 - x0) * size[0]; + node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1]; + }); + return nodes; + } + cluster.separation = function(x) { + if (!arguments.length) return separation; + separation = x; + return cluster; }; - force.stop = function() { - return force.alpha(0); + cluster.size = function(x) { + if (!arguments.length) return nodeSize ? null : size; + nodeSize = (size = x) == null; + return cluster; }; - force.drag = function() { - if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend); - if (!arguments.length) return drag; - this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag); + cluster.nodeSize = function(x) { + if (!arguments.length) return nodeSize ? size : null; + nodeSize = (size = x) != null; + return cluster; }; - function dragmove(d) { - d.px = d3.event.x, d.py = d3.event.y; - force.resume(); - } - return d3.rebind(force, event, "on"); + return d3_layout_hierarchyRebind(cluster, hierarchy); }; - function d3_layout_forceDragstart(d) { - d.fixed |= 2; + function d3_layout_clusterY(children) { + return 1 + d3.max(children, function(child) { + return child.y; + }); } - function d3_layout_forceDragend(d) { - d.fixed &= ~6; + function d3_layout_clusterX(children) { + return children.reduce(function(x, child) { + return x + child.x; + }, 0) / children.length; } - function d3_layout_forceMouseover(d) { - d.fixed |= 4; - d.px = d.x, d.py = d.y; + function d3_layout_clusterLeft(node) { + var children = node.children; + return children && children.length ? d3_layout_clusterLeft(children[0]) : node; } - function d3_layout_forceMouseout(d) { - d.fixed &= ~4; + function d3_layout_clusterRight(node) { + var children = node.children, n; + return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node; } - function d3_layout_forceAccumulate(quad, alpha, charges) { - var cx = 0, cy = 0; - quad.charge = 0; - if (!quad.leaf) { - var nodes = quad.nodes, n = nodes.length, i = -1, c; + d3.layout.treemap = function() { + var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5)); + function scale(children, k) { + var i = -1, n = children.length, child, area; while (++i < n) { - c = nodes[i]; - if (c == null) continue; - d3_layout_forceAccumulate(c, alpha, charges); - quad.charge += c.charge; - cx += c.charge * c.cx; - cy += c.charge * c.cy; - } - } - if (quad.point) { - if (!quad.leaf) { - quad.point.x += Math.random() - .5; - quad.point.y += Math.random() - .5; + area = (child = children[i]).value * (k < 0 ? 0 : k); + child.area = isNaN(area) || area <= 0 ? 0 : area; } - var k = alpha * charges[quad.point.index]; - quad.charge += quad.pointCharge = k; - cx += k * quad.point.x; - cy += k * quad.point.y; } - quad.cx = cx / quad.charge; - quad.cy = cy / quad.charge; - } - var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity; - d3.layout.hierarchy = function() { - var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue; - function hierarchy(root) { - var stack = [ root ], nodes = [], node; - root.depth = 0; - while ((node = stack.pop()) != null) { - nodes.push(node); - if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) { - var n, childs, child; - while (--n >= 0) { - stack.push(child = childs[n]); - child.parent = node; - child.depth = node.depth + 1; + function squarify(node) { + var children = node.children; + if (children && children.length) { + var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n; + scale(remaining, rect.dx * rect.dy / node.value); + row.area = 0; + while ((n = remaining.length) > 0) { + row.push(child = remaining[n - 1]); + row.area += child.area; + if (mode !== "squarify" || (score = worst(row, u)) <= best) { + remaining.pop(); + best = score; + } else { + row.area -= row.pop().area; + position(row, u, rect, false); + u = Math.min(rect.dx, rect.dy); + row.length = row.area = 0; + best = Infinity; } - if (value) node.value = 0; - node.children = childs; - } else { - if (value) node.value = +value.call(hierarchy, node, node.depth) || 0; - delete node.children; } + if (row.length) { + position(row, u, rect, true); + row.length = row.area = 0; + } + children.forEach(squarify); } - d3_layout_hierarchyVisitAfter(root, function(node) { - var childs, parent; - if (sort && (childs = node.children)) childs.sort(sort); - if (value && (parent = node.parent)) parent.value += node.value; - }); - return nodes; } - hierarchy.sort = function(x) { - if (!arguments.length) return sort; - sort = x; - return hierarchy; - }; - hierarchy.children = function(x) { - if (!arguments.length) return children; - children = x; - return hierarchy; - }; - hierarchy.value = function(x) { - if (!arguments.length) return value; - value = x; - return hierarchy; - }; - hierarchy.revalue = function(root) { - if (value) { - d3_layout_hierarchyVisitBefore(root, function(node) { - if (node.children) node.value = 0; - }); - d3_layout_hierarchyVisitAfter(root, function(node) { - var parent; - if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0; - if (parent = node.parent) parent.value += node.value; - }); - } - return root; - }; - return hierarchy; - }; - function d3_layout_hierarchyRebind(object, hierarchy) { - d3.rebind(object, hierarchy, "sort", "children", "value"); - object.nodes = object; - object.links = d3_layout_hierarchyLinks; - return object; - } - function d3_layout_hierarchyVisitBefore(node, callback) { - var nodes = [ node ]; - while ((node = nodes.pop()) != null) { - callback(node); - if ((children = node.children) && (n = children.length)) { - var n, children; - while (--n >= 0) nodes.push(children[n]); + function stickify(node) { + var children = node.children; + if (children && children.length) { + var rect = pad(node), remaining = children.slice(), child, row = []; + scale(remaining, rect.dx * rect.dy / node.value); + row.area = 0; + while (child = remaining.pop()) { + row.push(child); + row.area += child.area; + if (child.z != null) { + position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length); + row.length = row.area = 0; + } + } + children.forEach(stickify); } } - } - function d3_layout_hierarchyVisitAfter(node, callback) { - var nodes = [ node ], nodes2 = []; - while ((node = nodes.pop()) != null) { - nodes2.push(node); - if ((children = node.children) && (n = children.length)) { - var i = -1, n, children; - while (++i < n) nodes.push(children[i]); + function worst(row, u) { + var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length; + while (++i < n) { + if (!(r = row[i].area)) continue; + if (r < rmin) rmin = r; + if (r > rmax) rmax = r; } + s *= s; + u *= u; + return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity; } - while ((node = nodes2.pop()) != null) { - callback(node); - } - } - function d3_layout_hierarchyChildren(d) { - return d.children; - } - function d3_layout_hierarchyValue(d) { - return d.value; - } - function d3_layout_hierarchySort(a, b) { - return b.value - a.value; - } - function d3_layout_hierarchyLinks(nodes) { - return d3.merge(nodes.map(function(parent) { - return (parent.children || []).map(function(child) { - return { - source: parent, - target: child - }; - }); - })); - } - d3.layout.partition = function() { - var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ]; - function position(node, x, dx, dy) { - var children = node.children; - node.x = x; - node.y = node.depth * dy; - node.dx = dx; - node.dy = dy; - if (children && (n = children.length)) { - var i = -1, n, c, d; - dx = node.value ? dx / node.value : 0; + function position(row, u, rect, flush) { + var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o; + if (u == rect.dx) { + if (flush || v > rect.dy) v = rect.dy; + while (++i < n) { + o = row[i]; + o.x = x; + o.y = y; + o.dy = v; + x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0); + } + o.z = true; + o.dx += rect.x + rect.dx - x; + rect.y += v; + rect.dy -= v; + } else { + if (flush || v > rect.dx) v = rect.dx; while (++i < n) { - position(c = children[i], x, d = c.value * dx, dy); - x += d; + o = row[i]; + o.x = x; + o.y = y; + o.dx = v; + y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0); } + o.z = false; + o.dy += rect.y + rect.dy - y; + rect.x += v; + rect.dx -= v; } } - function depth(node) { - var children = node.children, d = 0; - if (children && (n = children.length)) { - var i = -1, n; - while (++i < n) d = Math.max(d, depth(children[i])); - } - return 1 + d; - } - function partition(d, i) { - var nodes = hierarchy.call(this, d, i); - position(nodes[0], 0, size[0], size[1] / depth(nodes[0])); + function treemap(d) { + var nodes = stickies || hierarchy(d), root = nodes[0]; + root.x = root.y = 0; + if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0; + if (stickies) hierarchy.revalue(root); + scale([ root ], root.dx * root.dy / root.value); + (stickies ? stickify : squarify)(root); + if (sticky) stickies = nodes; return nodes; } - partition.size = function(x) { + treemap.size = function(x) { if (!arguments.length) return size; size = x; - return partition; + return treemap; }; - return d3_layout_hierarchyRebind(partition, hierarchy); - }; - d3.layout.pie = function() { - var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0; - function pie(data) { - var n = data.length, values = data.map(function(d, i) { - return +value.call(pie, d, i); - }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v; - if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) { - return values[j] - values[i]; - } : function(i, j) { - return sort(data[i], data[j]); - }); - index.forEach(function(i) { - arcs[i] = { - data: data[i], - value: v = values[i], - startAngle: a, - endAngle: a += v * k + pa, - padAngle: p - }; - }); - return arcs; - } - pie.value = function(_) { - if (!arguments.length) return value; - value = _; - return pie; + treemap.padding = function(x) { + if (!arguments.length) return padding; + function padFunction(node) { + var p = x.call(treemap, node, node.depth); + return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p); + } + function padConstant(node) { + return d3_layout_treemapPad(node, x); + } + var type; + pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], + padConstant) : padConstant; + return treemap; }; - pie.sort = function(_) { - if (!arguments.length) return sort; - sort = _; - return pie; + treemap.round = function(x) { + if (!arguments.length) return round != Number; + round = x ? Math.round : Number; + return treemap; }; - pie.startAngle = function(_) { - if (!arguments.length) return startAngle; - startAngle = _; - return pie; + treemap.sticky = function(x) { + if (!arguments.length) return sticky; + sticky = x; + stickies = null; + return treemap; }; - pie.endAngle = function(_) { - if (!arguments.length) return endAngle; - endAngle = _; - return pie; + treemap.ratio = function(x) { + if (!arguments.length) return ratio; + ratio = x; + return treemap; }; - pie.padAngle = function(_) { - if (!arguments.length) return padAngle; - padAngle = _; - return pie; + treemap.mode = function(x) { + if (!arguments.length) return mode; + mode = x + ""; + return treemap; }; - return pie; + return d3_layout_hierarchyRebind(treemap, hierarchy); }; - var d3_layout_pieSortByValue = {}; - d3.layout.stack = function() { - var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY; - function stack(data, index) { - if (!(n = data.length)) return data; - var series = data.map(function(d, i) { - return values.call(stack, d, i); - }); - var points = series.map(function(d) { - return d.map(function(v, i) { - return [ x.call(stack, v, i), y.call(stack, v, i) ]; - }); - }); - var orders = order.call(stack, points, index); - series = d3.permute(series, orders); - points = d3.permute(points, orders); - var offsets = offset.call(stack, points, index); - var m = series[0].length, n, i, j, o; - for (j = 0; j < m; ++j) { - out.call(stack, series[0][j], o = offsets[j], points[0][j][1]); - for (i = 1; i < n; ++i) { - out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]); - } - } - return data; - } - stack.values = function(x) { - if (!arguments.length) return values; - values = x; - return stack; - }; - stack.order = function(x) { - if (!arguments.length) return order; - order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault; - return stack; - }; - stack.offset = function(x) { - if (!arguments.length) return offset; - offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero; - return stack; - }; - stack.x = function(z) { - if (!arguments.length) return x; - x = z; - return stack; + function d3_layout_treemapPadNull(node) { + return { + x: node.x, + y: node.y, + dx: node.dx, + dy: node.dy }; - stack.y = function(z) { - if (!arguments.length) return y; - y = z; - return stack; + } + function d3_layout_treemapPad(node, padding) { + var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2]; + if (dx < 0) { + x += dx / 2; + dx = 0; + } + if (dy < 0) { + y += dy / 2; + dy = 0; + } + return { + x: x, + y: y, + dx: dx, + dy: dy }; - stack.out = function(z) { - if (!arguments.length) return out; - out = z; - return stack; + } + d3.random = { + normal: function(µ, σ) { + var n = arguments.length; + if (n < 2) σ = 1; + if (n < 1) µ = 0; + return function() { + var x, y, r; + do { + x = Math.random() * 2 - 1; + y = Math.random() * 2 - 1; + r = x * x + y * y; + } while (!r || r > 1); + return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r); + }; + }, + logNormal: function() { + var random = d3.random.normal.apply(d3, arguments); + return function() { + return Math.exp(random()); + }; + }, + bates: function(m) { + var random = d3.random.irwinHall(m); + return function() { + return random() / m; + }; + }, + irwinHall: function(m) { + return function() { + for (var s = 0, j = 0; j < m; j++) s += Math.random(); + return s; + }; + } + }; + d3.scale = {}; + function d3_scaleExtent(domain) { + var start = domain[0], stop = domain[domain.length - 1]; + return start < stop ? [ start, stop ] : [ stop, start ]; + } + function d3_scaleRange(scale) { + return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range()); + } + function d3_format_precision(x, p) { + return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1); + } + d3.round = function(x, n) { + return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x); + }; + var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix); + d3.formatPrefix = function(value, precision) { + var i = 0; + if (value = +value) { + if (value < 0) value *= -1; + if (precision) value = d3.round(value, d3_format_precision(value, precision)); + i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10); + i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3)); + } + return d3_formatPrefixes[8 + i / 3]; + }; + function d3_formatPrefix(d, i) { + var k = Math.pow(10, abs(8 - i) * 3); + return { + scale: i > 8 ? function(d) { + return d / k; + } : function(d) { + return d * k; + }, + symbol: d }; - return stack; - }; - function d3_layout_stackX(d) { - return d.x; - } - function d3_layout_stackY(d) { - return d.y; - } - function d3_layout_stackOut(d, y0, y) { - d.y0 = y0; - d.y = y; } - var d3_layout_stackOrders = d3.map({ - "inside-out": function(data) { - var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) { - return max[a] - max[b]; - }), top = 0, bottom = 0, tops = [], bottoms = []; - for (i = 0; i < n; ++i) { - j = index[i]; - if (top < bottom) { - top += sums[j]; - tops.push(j); + function d3_locale_numberFormat(locale) { + var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) { + var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0; + while (i > 0 && g > 0) { + if (length + g + 1 > width) g = Math.max(1, width - length); + t.push(value.substring(i -= g, i + g)); + if ((length += g + 1) > width) break; + g = locale_grouping[j = (j + 1) % locale_grouping.length]; + } + return t.reverse().join(locale_thousands); + } : d3_identity; + return function(specifier) { + var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true; + if (precision) precision = +precision.substring(1); + if (zfill || fill === "0" && align === "=") { + zfill = fill = "0"; + align = "="; + } + switch (type) { + case "n": + comma = true; + type = "g"; + break; + + case "%": + scale = 100; + suffix = "%"; + type = "f"; + break; + + case "p": + scale = 100; + suffix = "%"; + type = "r"; + break; + + case "b": + case "o": + case "x": + case "X": + if (symbol === "#") prefix = "0" + type.toLowerCase(); + + case "c": + exponent = false; + + case "d": + integer = true; + precision = 0; + break; + + case "s": + scale = -1; + type = "r"; + break; + } + if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1]; + if (type == "r" && !precision) type = "g"; + if (precision != null) { + if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision)); + } + type = d3_format_types.get(type) || d3_format_typeDefault; + var zcomma = zfill && comma; + return function(value) { + var fullSuffix = suffix; + if (integer && value % 1) return ""; + var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign; + if (scale < 0) { + var unit = d3.formatPrefix(value, precision); + value = unit.scale(value); + fullSuffix = unit.symbol + suffix; } else { - bottom += sums[j]; - bottoms.push(j); + value *= scale; } - } - return bottoms.reverse().concat(tops); + value = type(value, precision); + var i = value.lastIndexOf("."), before, after; + if (i < 0) { + var j = exponent ? value.lastIndexOf("e") : -1; + if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j); + } else { + before = value.substring(0, i); + after = locale_decimal + value.substring(i + 1); + } + if (!zfill && comma) before = formatGroup(before, Infinity); + var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : ""; + if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity); + negative += prefix; + value = before + after; + return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix; + }; + }; + } + var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i; + var d3_format_types = d3.map({ + b: function(x) { + return x.toString(2); }, - reverse: function(data) { - return d3.range(data.length).reverse(); + c: function(x) { + return String.fromCharCode(x); }, - "default": d3_layout_stackOrderDefault - }); - var d3_layout_stackOffsets = d3.map({ - silhouette: function(data) { - var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = []; - for (j = 0; j < m; ++j) { - for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; - if (o > max) max = o; - sums.push(o); - } - for (j = 0; j < m; ++j) { - y0[j] = (max - sums[j]) / 2; - } - return y0; + o: function(x) { + return x.toString(8); }, - wiggle: function(data) { - var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = []; - y0[0] = o = o0 = 0; - for (j = 1; j < m; ++j) { - for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1]; - for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) { - for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) { - s3 += (data[k][j][1] - data[k][j - 1][1]) / dx; - } - s2 += s3 * data[i][j][1]; - } - y0[j] = o -= s1 ? s2 / s1 * dx : 0; - if (o < o0) o0 = o; - } - for (j = 0; j < m; ++j) y0[j] -= o0; - return y0; + x: function(x) { + return x.toString(16); }, - expand: function(data) { - var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = []; - for (j = 0; j < m; ++j) { - for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; - if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k; - } - for (j = 0; j < m; ++j) y0[j] = 0; - return y0; + X: function(x) { + return x.toString(16).toUpperCase(); }, - zero: d3_layout_stackOffsetZero + g: function(x, p) { + return x.toPrecision(p); + }, + e: function(x, p) { + return x.toExponential(p); + }, + f: function(x, p) { + return x.toFixed(p); + }, + r: function(x, p) { + return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p)))); + } }); - function d3_layout_stackOrderDefault(data) { - return d3.range(data.length); + function d3_format_typeDefault(x) { + return x + ""; } - function d3_layout_stackOffsetZero(data) { - var j = -1, m = data[0].length, y0 = []; - while (++j < m) y0[j] = 0; - return y0; + var d3_time = d3.time = {}, d3_date = Date; + function d3_date_utc() { + this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]); } - function d3_layout_stackMaxIndex(array) { - var i = 1, j = 0, v = array[0][1], k, n = array.length; - for (;i < n; ++i) { - if ((k = array[i][1]) > v) { - j = i; - v = k; - } + d3_date_utc.prototype = { + getDate: function() { + return this._.getUTCDate(); + }, + getDay: function() { + return this._.getUTCDay(); + }, + getFullYear: function() { + return this._.getUTCFullYear(); + }, + getHours: function() { + return this._.getUTCHours(); + }, + getMilliseconds: function() { + return this._.getUTCMilliseconds(); + }, + getMinutes: function() { + return this._.getUTCMinutes(); + }, + getMonth: function() { + return this._.getUTCMonth(); + }, + getSeconds: function() { + return this._.getUTCSeconds(); + }, + getTime: function() { + return this._.getTime(); + }, + getTimezoneOffset: function() { + return 0; + }, + valueOf: function() { + return this._.valueOf(); + }, + setDate: function() { + d3_time_prototype.setUTCDate.apply(this._, arguments); + }, + setDay: function() { + d3_time_prototype.setUTCDay.apply(this._, arguments); + }, + setFullYear: function() { + d3_time_prototype.setUTCFullYear.apply(this._, arguments); + }, + setHours: function() { + d3_time_prototype.setUTCHours.apply(this._, arguments); + }, + setMilliseconds: function() { + d3_time_prototype.setUTCMilliseconds.apply(this._, arguments); + }, + setMinutes: function() { + d3_time_prototype.setUTCMinutes.apply(this._, arguments); + }, + setMonth: function() { + d3_time_prototype.setUTCMonth.apply(this._, arguments); + }, + setSeconds: function() { + d3_time_prototype.setUTCSeconds.apply(this._, arguments); + }, + setTime: function() { + d3_time_prototype.setTime.apply(this._, arguments); } - return j; - } - function d3_layout_stackReduceSum(d) { - return d.reduce(d3_layout_stackSum, 0); - } - function d3_layout_stackSum(p, d) { - return p + d[1]; - } - d3.layout.histogram = function() { - var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges; - function histogram(data, i) { - var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x; - while (++i < m) { - bin = bins[i] = []; - bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]); - bin.y = 0; - } - if (m > 0) { - i = -1; - while (++i < n) { - x = values[i]; - if (x >= range[0] && x <= range[1]) { - bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; - bin.y += k; - bin.push(data[i]); - } + }; + var d3_time_prototype = Date.prototype; + function d3_time_interval(local, step, number) { + function round(date) { + var d0 = local(date), d1 = offset(d0, 1); + return date - d0 < d1 - date ? d0 : d1; + } + function ceil(date) { + step(date = local(new d3_date(date - 1)), 1); + return date; + } + function offset(date, k) { + step(date = new d3_date(+date), k); + return date; + } + function range(t0, t1, dt) { + var time = ceil(t0), times = []; + if (dt > 1) { + while (time < t1) { + if (!(number(time) % dt)) times.push(new Date(+time)); + step(time, 1); } + } else { + while (time < t1) times.push(new Date(+time)), step(time, 1); } - return bins; + return times; } - histogram.value = function(x) { - if (!arguments.length) return valuer; - valuer = x; - return histogram; - }; - histogram.range = function(x) { - if (!arguments.length) return ranger; - ranger = d3_functor(x); - return histogram; - }; - histogram.bins = function(x) { - if (!arguments.length) return binner; - binner = typeof x === "number" ? function(range) { - return d3_layout_histogramBinFixed(range, x); - } : d3_functor(x); - return histogram; - }; - histogram.frequency = function(x) { - if (!arguments.length) return frequency; - frequency = !!x; - return histogram; - }; - return histogram; - }; - function d3_layout_histogramBinSturges(range, values) { - return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1)); - } - function d3_layout_histogramBinFixed(range, n) { - var x = -1, b = +range[0], m = (range[1] - b) / n, f = []; - while (++x <= n) f[x] = m * x + b; - return f; - } - function d3_layout_histogramRange(values) { - return [ d3.min(values), d3.max(values) ]; - } - d3.layout.pack = function() { - var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius; - function pack(d, i) { - var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() { - return radius; - }; - root.x = root.y = 0; - d3_layout_hierarchyVisitAfter(root, function(d) { - d.r = +r(d.value); - }); - d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); - if (padding) { - var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2; - d3_layout_hierarchyVisitAfter(root, function(d) { - d.r += dr; - }); - d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); - d3_layout_hierarchyVisitAfter(root, function(d) { - d.r -= dr; - }); + function range_utc(t0, t1, dt) { + try { + d3_date = d3_date_utc; + var utc = new d3_date_utc(); + utc._ = t0; + return range(utc, t1, dt); + } finally { + d3_date = Date; } - d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h)); - return nodes; } - pack.size = function(_) { - if (!arguments.length) return size; - size = _; - return pack; - }; - pack.radius = function(_) { - if (!arguments.length) return radius; - radius = _ == null || typeof _ === "function" ? _ : +_; - return pack; - }; - pack.padding = function(_) { - if (!arguments.length) return padding; - padding = +_; - return pack; - }; - return d3_layout_hierarchyRebind(pack, hierarchy); - }; - function d3_layout_packSort(a, b) { - return a.value - b.value; - } - function d3_layout_packInsert(a, b) { - var c = a._pack_next; - a._pack_next = b; - b._pack_prev = a; - b._pack_next = c; - c._pack_prev = b; - } - function d3_layout_packSplice(a, b) { - a._pack_next = b; - b._pack_prev = a; + local.floor = local; + local.round = round; + local.ceil = ceil; + local.offset = offset; + local.range = range; + var utc = local.utc = d3_time_interval_utc(local); + utc.floor = utc; + utc.round = d3_time_interval_utc(round); + utc.ceil = d3_time_interval_utc(ceil); + utc.offset = d3_time_interval_utc(offset); + utc.range = range_utc; + return local; } - function d3_layout_packIntersects(a, b) { - var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r; - return .999 * dr * dr > dx * dx + dy * dy; + function d3_time_interval_utc(method) { + return function(date, k) { + try { + d3_date = d3_date_utc; + var utc = new d3_date_utc(); + utc._ = date; + return method(utc, k)._; + } finally { + d3_date = Date; + } + }; } - function d3_layout_packSiblings(node) { - if (!(nodes = node.children) || !(n = nodes.length)) return; - var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n; - function bound(node) { - xMin = Math.min(node.x - node.r, xMin); - xMax = Math.max(node.x + node.r, xMax); - yMin = Math.min(node.y - node.r, yMin); - yMax = Math.max(node.y + node.r, yMax); - } - nodes.forEach(d3_layout_packLink); - a = nodes[0]; - a.x = -a.r; - a.y = 0; - bound(a); - if (n > 1) { - b = nodes[1]; - b.x = b.r; - b.y = 0; - bound(b); - if (n > 2) { - c = nodes[2]; - d3_layout_packPlace(a, b, c); - bound(c); - d3_layout_packInsert(a, c); - a._pack_prev = c; - d3_layout_packInsert(c, b); - b = a._pack_next; - for (i = 3; i < n; i++) { - d3_layout_packPlace(a, b, c = nodes[i]); - var isect = 0, s1 = 1, s2 = 1; - for (j = b._pack_next; j !== b; j = j._pack_next, s1++) { - if (d3_layout_packIntersects(j, c)) { - isect = 1; - break; - } - } - if (isect == 1) { - for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) { - if (d3_layout_packIntersects(k, c)) { - break; - } - } - } - if (isect) { - if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b); - i--; - } else { - d3_layout_packInsert(a, c); - b = c; - bound(c); + d3_time.year = d3_time_interval(function(date) { + date = d3_time.day(date); + date.setMonth(0, 1); + return date; + }, function(date, offset) { + date.setFullYear(date.getFullYear() + offset); + }, function(date) { + return date.getFullYear(); + }); + d3_time.years = d3_time.year.range; + d3_time.years.utc = d3_time.year.utc.range; + d3_time.day = d3_time_interval(function(date) { + var day = new d3_date(2e3, 0); + day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate()); + return day; + }, function(date, offset) { + date.setDate(date.getDate() + offset); + }, function(date) { + return date.getDate() - 1; + }); + d3_time.days = d3_time.day.range; + d3_time.days.utc = d3_time.day.utc.range; + d3_time.dayOfYear = function(date) { + var year = d3_time.year(date); + return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5); + }; + [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) { + i = 7 - i; + var interval = d3_time[day] = d3_time_interval(function(date) { + (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7); + return date; + }, function(date, offset) { + date.setDate(date.getDate() + Math.floor(offset) * 7); + }, function(date) { + var day = d3_time.year(date).getDay(); + return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i); + }); + d3_time[day + "s"] = interval.range; + d3_time[day + "s"].utc = interval.utc.range; + d3_time[day + "OfYear"] = function(date) { + var day = d3_time.year(date).getDay(); + return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7); + }; + }); + d3_time.week = d3_time.sunday; + d3_time.weeks = d3_time.sunday.range; + d3_time.weeks.utc = d3_time.sunday.utc.range; + d3_time.weekOfYear = d3_time.sundayOfYear; + function d3_locale_timeFormat(locale) { + var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths; + function d3_time_format(template) { + var n = template.length; + function format(date) { + var string = [], i = -1, j = 0, c, p, f; + while (++i < n) { + if (template.charCodeAt(i) === 37) { + string.push(template.slice(j, i)); + if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i); + if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p); + string.push(c); + j = i + 1; } } + string.push(template.slice(j, i)); + return string.join(""); } + format.parse = function(string) { + var d = { + y: 1900, + m: 0, + d: 1, + H: 0, + M: 0, + S: 0, + L: 0, + Z: null + }, i = d3_time_parse(d, template, string, 0); + if (i != string.length) return null; + if ("p" in d) d.H = d.H % 12 + d.p * 12; + var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)(); + if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) { + if (!("w" in d)) d.w = "W" in d ? 1 : 0; + date.setFullYear(d.y, 0, 1); + date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7); + } else date.setFullYear(d.y, d.m, d.d); + date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L); + return localZ ? date._ : date; + }; + format.toString = function() { + return template; + }; + return format; } - var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0; - for (i = 0; i < n; i++) { - c = nodes[i]; - c.x -= cx; - c.y -= cy; - cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y)); - } - node.r = cr; - nodes.forEach(d3_layout_packUnlink); - } - function d3_layout_packLink(node) { - node._pack_next = node._pack_prev = node; - } - function d3_layout_packUnlink(node) { - delete node._pack_next; - delete node._pack_prev; - } - function d3_layout_packTransform(node, x, y, k) { - var children = node.children; - node.x = x += k * node.x; - node.y = y += k * node.y; - node.r *= k; - if (children) { - var i = -1, n = children.length; - while (++i < n) d3_layout_packTransform(children[i], x, y, k); - } - } - function d3_layout_packPlace(a, b, c) { - var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y; - if (db && (dx || dy)) { - var da = b.r + c.r, dc = dx * dx + dy * dy; - da *= da; - db *= db; - var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc); - c.x = a.x + x * dx + y * dy; - c.y = a.y + x * dy - y * dx; - } else { - c.x = a.x + db; - c.y = a.y; + function d3_time_parse(date, template, string, j) { + var c, p, t, i = 0, n = template.length, m = string.length; + while (i < n) { + if (j >= m) return -1; + c = template.charCodeAt(i++); + if (c === 37) { + t = template.charAt(i++); + p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t]; + if (!p || (j = p(date, string, j)) < 0) return -1; + } else if (c != string.charCodeAt(j++)) { + return -1; + } + } + return j; } - } - d3.layout.tree = function() { - var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null; - function tree(d, i) { - var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0); - d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z; - d3_layout_hierarchyVisitBefore(root1, secondWalk); - if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else { - var left = root0, right = root0, bottom = root0; - d3_layout_hierarchyVisitBefore(root0, function(node) { - if (node.x < left.x) left = node; - if (node.x > right.x) right = node; - if (node.depth > bottom.depth) bottom = node; - }); - var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1); - d3_layout_hierarchyVisitBefore(root0, function(node) { - node.x = (node.x + tx) * kx; - node.y = node.depth * ky; - }); + d3_time_format.utc = function(template) { + var local = d3_time_format(template); + function format(date) { + try { + d3_date = d3_date_utc; + var utc = new d3_date(); + utc._ = date; + return local(utc); + } finally { + d3_date = Date; + } } - return nodes; + format.parse = function(string) { + try { + d3_date = d3_date_utc; + var date = local.parse(string); + return date && date._; + } finally { + d3_date = Date; + } + }; + format.toString = local.toString; + return format; + }; + d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti; + var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths); + locale_periods.forEach(function(p, i) { + d3_time_periodLookup.set(p.toLowerCase(), i); + }); + var d3_time_formats = { + a: function(d) { + return locale_shortDays[d.getDay()]; + }, + A: function(d) { + return locale_days[d.getDay()]; + }, + b: function(d) { + return locale_shortMonths[d.getMonth()]; + }, + B: function(d) { + return locale_months[d.getMonth()]; + }, + c: d3_time_format(locale_dateTime), + d: function(d, p) { + return d3_time_formatPad(d.getDate(), p, 2); + }, + e: function(d, p) { + return d3_time_formatPad(d.getDate(), p, 2); + }, + H: function(d, p) { + return d3_time_formatPad(d.getHours(), p, 2); + }, + I: function(d, p) { + return d3_time_formatPad(d.getHours() % 12 || 12, p, 2); + }, + j: function(d, p) { + return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3); + }, + L: function(d, p) { + return d3_time_formatPad(d.getMilliseconds(), p, 3); + }, + m: function(d, p) { + return d3_time_formatPad(d.getMonth() + 1, p, 2); + }, + M: function(d, p) { + return d3_time_formatPad(d.getMinutes(), p, 2); + }, + p: function(d) { + return locale_periods[+(d.getHours() >= 12)]; + }, + S: function(d, p) { + return d3_time_formatPad(d.getSeconds(), p, 2); + }, + U: function(d, p) { + return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2); + }, + w: function(d) { + return d.getDay(); + }, + W: function(d, p) { + return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2); + }, + x: d3_time_format(locale_date), + X: d3_time_format(locale_time), + y: function(d, p) { + return d3_time_formatPad(d.getFullYear() % 100, p, 2); + }, + Y: function(d, p) { + return d3_time_formatPad(d.getFullYear() % 1e4, p, 4); + }, + Z: d3_time_zone, + "%": function() { + return "%"; + } + }; + var d3_time_parsers = { + a: d3_time_parseWeekdayAbbrev, + A: d3_time_parseWeekday, + b: d3_time_parseMonthAbbrev, + B: d3_time_parseMonth, + c: d3_time_parseLocaleFull, + d: d3_time_parseDay, + e: d3_time_parseDay, + H: d3_time_parseHour24, + I: d3_time_parseHour24, + j: d3_time_parseDayOfYear, + L: d3_time_parseMilliseconds, + m: d3_time_parseMonthNumber, + M: d3_time_parseMinutes, + p: d3_time_parseAmPm, + S: d3_time_parseSeconds, + U: d3_time_parseWeekNumberSunday, + w: d3_time_parseWeekdayNumber, + W: d3_time_parseWeekNumberMonday, + x: d3_time_parseLocaleDate, + X: d3_time_parseLocaleTime, + y: d3_time_parseYear, + Y: d3_time_parseFullYear, + Z: d3_time_parseZone, + "%": d3_time_parseLiteralPercent + }; + function d3_time_parseWeekdayAbbrev(date, string, i) { + d3_time_dayAbbrevRe.lastIndex = 0; + var n = d3_time_dayAbbrevRe.exec(string.slice(i)); + return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; } - function wrapTree(root0) { - var root1 = { - A: null, - children: [ root0 ] - }, queue = [ root1 ], node1; - while ((node1 = queue.pop()) != null) { - for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) { - queue.push((children[i] = child = { - _: children[i], - parent: node1, - children: (child = children[i].children) && child.slice() || [], - A: null, - a: null, - z: 0, - m: 0, - c: 0, - s: 0, - t: null, - i: i - }).a = child); - } - } - return root1.children[0]; + function d3_time_parseWeekday(date, string, i) { + d3_time_dayRe.lastIndex = 0; + var n = d3_time_dayRe.exec(string.slice(i)); + return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; } - function firstWalk(v) { - var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null; - if (children.length) { - d3_layout_treeShift(v); - var midpoint = (children[0].z + children[children.length - 1].z) / 2; - if (w) { - v.z = w.z + separation(v._, w._); - v.m = v.z - midpoint; - } else { - v.z = midpoint; - } - } else if (w) { - v.z = w.z + separation(v._, w._); - } - v.parent.A = apportion(v, w, v.parent.A || siblings[0]); + function d3_time_parseMonthAbbrev(date, string, i) { + d3_time_monthAbbrevRe.lastIndex = 0; + var n = d3_time_monthAbbrevRe.exec(string.slice(i)); + return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; } - function secondWalk(v) { - v._.x = v.z + v.parent.m; - v.m += v.parent.m; + function d3_time_parseMonth(date, string, i) { + d3_time_monthRe.lastIndex = 0; + var n = d3_time_monthRe.exec(string.slice(i)); + return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; } - function apportion(v, w, ancestor) { - if (w) { - var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift; - while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) { - vom = d3_layout_treeLeft(vom); - vop = d3_layout_treeRight(vop); - vop.a = v; - shift = vim.z + sim - vip.z - sip + separation(vim._, vip._); - if (shift > 0) { - d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift); - sip += shift; - sop += shift; - } - sim += vim.m; - sip += vip.m; - som += vom.m; - sop += vop.m; - } - if (vim && !d3_layout_treeRight(vop)) { - vop.t = vim; - vop.m += sim - sop; - } - if (vip && !d3_layout_treeLeft(vom)) { - vom.t = vip; - vom.m += sip - som; - ancestor = v; - } - } - return ancestor; + function d3_time_parseLocaleFull(date, string, i) { + return d3_time_parse(date, d3_time_formats.c.toString(), string, i); } - function sizeNode(node) { - node.x *= size[0]; - node.y = node.depth * size[1]; + function d3_time_parseLocaleDate(date, string, i) { + return d3_time_parse(date, d3_time_formats.x.toString(), string, i); } - tree.separation = function(x) { - if (!arguments.length) return separation; - separation = x; - return tree; - }; - tree.size = function(x) { - if (!arguments.length) return nodeSize ? null : size; - nodeSize = (size = x) == null ? sizeNode : null; - return tree; - }; - tree.nodeSize = function(x) { - if (!arguments.length) return nodeSize ? size : null; - nodeSize = (size = x) == null ? null : sizeNode; - return tree; - }; - return d3_layout_hierarchyRebind(tree, hierarchy); - }; - function d3_layout_treeSeparation(a, b) { - return a.parent == b.parent ? 1 : 2; + function d3_time_parseLocaleTime(date, string, i) { + return d3_time_parse(date, d3_time_formats.X.toString(), string, i); + } + function d3_time_parseAmPm(date, string, i) { + var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase()); + return n == null ? -1 : (date.p = n, i); + } + return d3_time_format; } - function d3_layout_treeLeft(v) { - var children = v.children; - return children.length ? children[0] : v.t; + var d3_time_formatPads = { + "-": "", + _: " ", + "0": "0" + }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/; + function d3_time_formatPad(value, fill, width) { + var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length; + return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); } - function d3_layout_treeRight(v) { - var children = v.children, n; - return (n = children.length) ? children[n - 1] : v.t; + function d3_time_formatRe(names) { + return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i"); } - function d3_layout_treeMove(wm, wp, shift) { - var change = shift / (wp.i - wm.i); - wp.c -= change; - wp.s += shift; - wm.c += change; - wp.z += shift; - wp.m += shift; + function d3_time_formatLookup(names) { + var map = new d3_Map(), i = -1, n = names.length; + while (++i < n) map.set(names[i].toLowerCase(), i); + return map; } - function d3_layout_treeShift(v) { - var shift = 0, change = 0, children = v.children, i = children.length, w; - while (--i >= 0) { - w = children[i]; - w.z += shift; - w.m += shift; - shift += w.s + (change += w.c); - } + function d3_time_parseWeekdayNumber(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 1)); + return n ? (date.w = +n[0], i + n[0].length) : -1; } - function d3_layout_treeAncestor(vim, v, ancestor) { - return vim.a.parent === v.parent ? vim.a : ancestor; + function d3_time_parseWeekNumberSunday(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i)); + return n ? (date.U = +n[0], i + n[0].length) : -1; } - d3.layout.cluster = function() { - var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false; - function cluster(d, i) { - var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0; - d3_layout_hierarchyVisitAfter(root, function(node) { - var children = node.children; - if (children && children.length) { - node.x = d3_layout_clusterX(children); - node.y = d3_layout_clusterY(children); - } else { - node.x = previousNode ? x += separation(node, previousNode) : 0; - node.y = 0; - previousNode = node; - } - }); - var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2; - d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) { - node.x = (node.x - root.x) * size[0]; - node.y = (root.y - node.y) * size[1]; - } : function(node) { - node.x = (node.x - x0) / (x1 - x0) * size[0]; - node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1]; - }); - return nodes; - } - cluster.separation = function(x) { - if (!arguments.length) return separation; - separation = x; - return cluster; - }; - cluster.size = function(x) { - if (!arguments.length) return nodeSize ? null : size; - nodeSize = (size = x) == null; - return cluster; - }; - cluster.nodeSize = function(x) { - if (!arguments.length) return nodeSize ? size : null; - nodeSize = (size = x) != null; - return cluster; - }; - return d3_layout_hierarchyRebind(cluster, hierarchy); - }; - function d3_layout_clusterY(children) { - return 1 + d3.max(children, function(child) { - return child.y; - }); + function d3_time_parseWeekNumberMonday(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i)); + return n ? (date.W = +n[0], i + n[0].length) : -1; + } + function d3_time_parseFullYear(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 4)); + return n ? (date.y = +n[0], i + n[0].length) : -1; + } + function d3_time_parseYear(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1; + } + function d3_time_parseZone(date, string, i) { + return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string, + i + 5) : -1; + } + function d3_time_expandYear(d) { + return d + (d > 68 ? 1900 : 2e3); + } + function d3_time_parseMonthNumber(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.m = n[0] - 1, i + n[0].length) : -1; + } + function d3_time_parseDay(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.d = +n[0], i + n[0].length) : -1; + } + function d3_time_parseDayOfYear(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 3)); + return n ? (date.j = +n[0], i + n[0].length) : -1; + } + function d3_time_parseHour24(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.H = +n[0], i + n[0].length) : -1; + } + function d3_time_parseMinutes(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.M = +n[0], i + n[0].length) : -1; + } + function d3_time_parseSeconds(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 2)); + return n ? (date.S = +n[0], i + n[0].length) : -1; } - function d3_layout_clusterX(children) { - return children.reduce(function(x, child) { - return x + child.x; - }, 0) / children.length; + function d3_time_parseMilliseconds(date, string, i) { + d3_time_numberRe.lastIndex = 0; + var n = d3_time_numberRe.exec(string.slice(i, i + 3)); + return n ? (date.L = +n[0], i + n[0].length) : -1; } - function d3_layout_clusterLeft(node) { - var children = node.children; - return children && children.length ? d3_layout_clusterLeft(children[0]) : node; + function d3_time_zone(d) { + var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60; + return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2); } - function d3_layout_clusterRight(node) { - var children = node.children, n; - return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node; + function d3_time_parseLiteralPercent(date, string, i) { + d3_time_percentRe.lastIndex = 0; + var n = d3_time_percentRe.exec(string.slice(i, i + 1)); + return n ? i + n[0].length : -1; } - d3.layout.treemap = function() { - var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5)); - function scale(children, k) { - var i = -1, n = children.length, child, area; - while (++i < n) { - area = (child = children[i]).value * (k < 0 ? 0 : k); - child.area = isNaN(area) || area <= 0 ? 0 : area; - } - } - function squarify(node) { - var children = node.children; - if (children && children.length) { - var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n; - scale(remaining, rect.dx * rect.dy / node.value); - row.area = 0; - while ((n = remaining.length) > 0) { - row.push(child = remaining[n - 1]); - row.area += child.area; - if (mode !== "squarify" || (score = worst(row, u)) <= best) { - remaining.pop(); - best = score; - } else { - row.area -= row.pop().area; - position(row, u, rect, false); - u = Math.min(rect.dx, rect.dy); - row.length = row.area = 0; - best = Infinity; - } - } - if (row.length) { - position(row, u, rect, true); - row.length = row.area = 0; - } - children.forEach(squarify); - } - } - function stickify(node) { - var children = node.children; - if (children && children.length) { - var rect = pad(node), remaining = children.slice(), child, row = []; - scale(remaining, rect.dx * rect.dy / node.value); - row.area = 0; - while (child = remaining.pop()) { - row.push(child); - row.area += child.area; - if (child.z != null) { - position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length); - row.length = row.area = 0; - } - } - children.forEach(stickify); - } - } - function worst(row, u) { - var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length; - while (++i < n) { - if (!(r = row[i].area)) continue; - if (r < rmin) rmin = r; - if (r > rmax) rmax = r; - } - s *= s; - u *= u; - return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity; - } - function position(row, u, rect, flush) { - var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o; - if (u == rect.dx) { - if (flush || v > rect.dy) v = rect.dy; - while (++i < n) { - o = row[i]; - o.x = x; - o.y = y; - o.dy = v; - x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0); - } - o.z = true; - o.dx += rect.x + rect.dx - x; - rect.y += v; - rect.dy -= v; - } else { - if (flush || v > rect.dx) v = rect.dx; - while (++i < n) { - o = row[i]; - o.x = x; - o.y = y; - o.dx = v; - y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0); - } - o.z = false; - o.dy += rect.y + rect.dy - y; - rect.x += v; - rect.dx -= v; - } - } - function treemap(d) { - var nodes = stickies || hierarchy(d), root = nodes[0]; - root.x = root.y = 0; - if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0; - if (stickies) hierarchy.revalue(root); - scale([ root ], root.dx * root.dy / root.value); - (stickies ? stickify : squarify)(root); - if (sticky) stickies = nodes; - return nodes; - } - treemap.size = function(x) { - if (!arguments.length) return size; - size = x; - return treemap; - }; - treemap.padding = function(x) { - if (!arguments.length) return padding; - function padFunction(node) { - var p = x.call(treemap, node, node.depth); - return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p); - } - function padConstant(node) { - return d3_layout_treemapPad(node, x); - } - var type; - pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ], - padConstant) : padConstant; - return treemap; - }; - treemap.round = function(x) { - if (!arguments.length) return round != Number; - round = x ? Math.round : Number; - return treemap; - }; - treemap.sticky = function(x) { - if (!arguments.length) return sticky; - sticky = x; - stickies = null; - return treemap; - }; - treemap.ratio = function(x) { - if (!arguments.length) return ratio; - ratio = x; - return treemap; - }; - treemap.mode = function(x) { - if (!arguments.length) return mode; - mode = x + ""; - return treemap; - }; - return d3_layout_hierarchyRebind(treemap, hierarchy); - }; - function d3_layout_treemapPadNull(node) { - return { - x: node.x, - y: node.y, - dx: node.dx, - dy: node.dy + function d3_time_formatMulti(formats) { + var n = formats.length, i = -1; + while (++i < n) formats[i][0] = this(formats[i][0]); + return function(date) { + var i = 0, f = formats[i]; + while (!f[1](date)) f = formats[++i]; + return f[0](date); }; } - function d3_layout_treemapPad(node, padding) { - var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2]; - if (dx < 0) { - x += dx / 2; - dx = 0; - } - if (dy < 0) { - y += dy / 2; - dy = 0; - } + d3.locale = function(locale) { return { - x: x, - y: y, - dx: dx, - dy: dy + numberFormat: d3_locale_numberFormat(locale), + timeFormat: d3_locale_timeFormat(locale) }; - } - d3.random = { - normal: function(µ, σ) { - var n = arguments.length; - if (n < 2) σ = 1; - if (n < 1) µ = 0; - return function() { - var x, y, r; - do { - x = Math.random() * 2 - 1; - y = Math.random() * 2 - 1; - r = x * x + y * y; - } while (!r || r > 1); - return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r); - }; - }, - logNormal: function() { - var random = d3.random.normal.apply(d3, arguments); - return function() { - return Math.exp(random()); - }; - }, - bates: function(m) { - var random = d3.random.irwinHall(m); - return function() { - return random() / m; - }; - }, - irwinHall: function(m) { - return function() { - for (var s = 0, j = 0; j < m; j++) s += Math.random(); - return s; - }; - } }; - d3.scale = {}; - function d3_scaleExtent(domain) { - var start = domain[0], stop = domain[domain.length - 1]; - return start < stop ? [ start, stop ] : [ stop, start ]; - } - function d3_scaleRange(scale) { - return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range()); - } + var d3_locale_enUS = d3.locale({ + decimal: ".", + thousands: ",", + grouping: [ 3 ], + currency: [ "$", "" ], + dateTime: "%a %b %e %X %Y", + date: "%m/%d/%Y", + time: "%H:%M:%S", + 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" ] + }); + d3.format = d3_locale_enUS.numberFormat; function d3_scale_bilinear(domain, range, uninterpolate, interpolate) { var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]); return function(x) { diff --git a/src/format/format.js b/src/format/format.js deleted file mode 100644 index bf740dbde10f14..00000000000000 --- a/src/format/format.js +++ /dev/null @@ -1,3 +0,0 @@ -import "../locale/en-US"; - -d3.format = d3_locale_enUS.numberFormat; diff --git a/src/format/formatPrefix.js b/src/format/formatPrefix.js deleted file mode 100644 index b5a8bab1e026a2..00000000000000 --- a/src/format/formatPrefix.js +++ /dev/null @@ -1,24 +0,0 @@ -import "precision"; -import "round"; -import "../math/abs"; - -var d3_formatPrefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"].map(d3_formatPrefix); - -d3.formatPrefix = function(value, precision) { - var i = 0; - if (value = +value) { - if (value < 0) value *= -1; - if (precision) value = d3.round(value, d3_format_precision(value, precision)); - i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10); - i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3)); - } - return d3_formatPrefixes[8 + i / 3]; -}; - -function d3_formatPrefix(d, i) { - var k = Math.pow(10, abs(8 - i) * 3); - return { - scale: i > 8 ? function(d) { return d / k; } : function(d) { return d * k; }, - symbol: d - }; -} diff --git a/src/format/index.js b/src/format/index.js index 21d7e9de2b5804..688fa052daf4f5 100644 --- a/src/format/index.js +++ b/src/format/index.js @@ -1,4 +1,2 @@ -import "format"; -import "formatPrefix"; import "requote"; import "round"; diff --git a/src/format/precision.js b/src/format/precision.js deleted file mode 100644 index 24e32a1e6d006a..00000000000000 --- a/src/format/precision.js +++ /dev/null @@ -1,3 +0,0 @@ -function d3_format_precision(x, p) { - return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1); -} diff --git a/src/locale/ca-ES.js b/src/locale/ca-ES.js deleted file mode 100644 index 73be711a2db736..00000000000000 --- a/src/locale/ca-ES.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_caES = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", " €"], - dateTime: "%A, %e de %B de %Y, %X", - date: "%d/%m/%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["diumenge", "dilluns", "dimarts", "dimecres", "dijous", "divendres", "dissabte"], - shortDays: ["dg.", "dl.", "dt.", "dc.", "dj.", "dv.", "ds."], - months: ["gener", "febrer", "març", "abril", "maig", "juny", "juliol", "agost", "setembre", "octubre", "novembre", "desembre"], - shortMonths: ["gen.", "febr.", "març", "abr.", "maig", "juny", "jul.", "ag.", "set.", "oct.", "nov.", "des."] -}); diff --git a/src/locale/de-CH.js b/src/locale/de-CH.js deleted file mode 100644 index 8d760ceb135181..00000000000000 --- a/src/locale/de-CH.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_deCH = d3.locale({ - decimal: ",", - thousands: "'", - grouping: [3], - currency: ["", " CHF"], - dateTime: "%A, der %e. %B %Y, %X", - date: "%d.%m.%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"], - shortDays: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"], - months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"], - shortMonths: ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"] -}); diff --git a/src/locale/de-DE.js b/src/locale/de-DE.js deleted file mode 100644 index a497ac48a7fae8..00000000000000 --- a/src/locale/de-DE.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_deDE = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", " €"], - dateTime: "%A, der %e. %B %Y, %X", - date: "%d.%m.%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"], - shortDays: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"], - months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"], - shortMonths: ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"] -}); diff --git a/src/locale/en-CA.js b/src/locale/en-CA.js deleted file mode 100644 index 64853cfe04b55b..00000000000000 --- a/src/locale/en-CA.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_enCA = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["$", ""], - dateTime: "%a %b %e %X %Y", - date: "%Y-%m-%d", - time: "%H:%M:%S", - 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"] -}); diff --git a/src/locale/en-GB.js b/src/locale/en-GB.js deleted file mode 100644 index 10414bbd790e2c..00000000000000 --- a/src/locale/en-GB.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_enGB = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["£", ""], - dateTime: "%a %e %b %X %Y", - date: "%d/%m/%Y", - time: "%H:%M:%S", - 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"] -}); diff --git a/src/locale/en-US.js b/src/locale/en-US.js deleted file mode 100644 index 4fa8547bfde13f..00000000000000 --- a/src/locale/en-US.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_enUS = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["$", ""], - dateTime: "%a %b %e %X %Y", - date: "%m/%d/%Y", - time: "%H:%M:%S", - 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"] -}); diff --git a/src/locale/es-ES.js b/src/locale/es-ES.js deleted file mode 100644 index 839b2a69a3c572..00000000000000 --- a/src/locale/es-ES.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_esES = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", " €"], - dateTime: "%A, %e de %B de %Y, %X", - date: "%d/%m/%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"], - shortDays: ["dom", "lun", "mar", "mié", "jue", "vie", "sáb"], - months: ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"], - shortMonths: ["ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic"] -}); diff --git a/src/locale/fi-FI.js b/src/locale/fi-FI.js deleted file mode 100644 index 05e5eeb98e9c3b..00000000000000 --- a/src/locale/fi-FI.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_fiFI = d3.locale({ - decimal: ",", - thousands: "\xa0", - grouping: [3], - currency: ["", "\xa0€"], - dateTime: "%A, %-d. %Bta %Y klo %X", - date: "%-d.%-m.%Y", - time: "%H:%M:%S", - periods: ["a.m.", "p.m."], - days: ["sunnuntai", "maanantai", "tiistai", "keskiviikko", "torstai", "perjantai", "lauantai"], - shortDays: ["Su", "Ma", "Ti", "Ke", "To", "Pe", "La"], - months: ["tammikuu", "helmikuu", "maaliskuu", "huhtikuu", "toukokuu", "kesäkuu", "heinäkuu", "elokuu", "syyskuu", "lokakuu", "marraskuu", "joulukuu"], - shortMonths: ["Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu"] -}); diff --git a/src/locale/fr-CA.js b/src/locale/fr-CA.js deleted file mode 100644 index a18c39f9ab6a7b..00000000000000 --- a/src/locale/fr-CA.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_frCA = d3.locale({ - decimal: ",", - thousands: "\xa0", - grouping: [3], - currency: ["", "$"], - dateTime: "%a %e %b %Y %X", - date: "%Y-%m-%d", - time: "%H:%M:%S", - periods: ["", ""], - days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"], - shortDays: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"], - months: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"], - shortMonths: ["jan", "fév", "mar", "avr", "mai", "jui", "jul", "aoû", "sep", "oct", "nov", "déc"] -}); diff --git a/src/locale/fr-FR.js b/src/locale/fr-FR.js deleted file mode 100644 index 1afd400850ea6f..00000000000000 --- a/src/locale/fr-FR.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_frFR = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", " €"], - dateTime: "%A, le %e %B %Y, %X", - date: "%d/%m/%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"], - shortDays: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."], - months: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"], - shortMonths: ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."] -}); diff --git a/src/locale/he-IL.js b/src/locale/he-IL.js deleted file mode 100644 index c840cc843a57d2..00000000000000 --- a/src/locale/he-IL.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_heIL = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["₪", ""], - dateTime: "%A, %e ב%B %Y %X", - date: "%d.%m.%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["ראשון", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת"], - shortDays: ["א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"], - months: ["ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"], - shortMonths: ["ינו׳", "פבר׳", "מרץ", "אפר׳", "מאי", "יוני", "יולי", "אוג׳", "ספט׳", "אוק׳", "נוב׳", "דצמ׳"] -}); diff --git a/src/locale/hu-HU.js b/src/locale/hu-HU.js deleted file mode 100644 index 4bfff72274372b..00000000000000 --- a/src/locale/hu-HU.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_huHU = d3.locale({ - decimal: ",", - thousands: "\xa0", - grouping: [3], - currency: ["", "\xa0Ft"], - dateTime: "%Y. %B %-e., %A %X", - date: "%Y. %m. %d.", - time: "%H:%M:%S", - periods: ["de.", "du."], // unused - days: ["vasárnap", "hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat"], - shortDays: ["V", "H", "K", "Sze", "Cs", "P", "Szo"], - months: ["január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december"], - shortMonths: ["jan.", "feb.", "már.", "ápr.", "máj.", "jún.", "júl.", "aug.", "szept.", "okt.", "nov.", "dec."] -}); diff --git a/src/locale/it-IT.js b/src/locale/it-IT.js deleted file mode 100644 index aec9202ef631a2..00000000000000 --- a/src/locale/it-IT.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_itIT = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["€", ""], - dateTime: "%A %e %B %Y, %X", - date: "%d/%m/%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"], - shortDays: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"], - months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"], - shortMonths: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"] -}); diff --git a/src/locale/ja-JP.js b/src/locale/ja-JP.js deleted file mode 100644 index 45efb48fbf2fb9..00000000000000 --- a/src/locale/ja-JP.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_jaJP = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["", "円"], - dateTime: "%Y %b %e %a %X", - date: "%Y/%m/%d", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"], - shortDays: ["日", "月", "火", "水", "木", "金", "土"], - months: ["睦月", "如月", "弥生", "卯月", "皐月", "水無月", "文月", "葉月", "長月", "神無月", "霜月", "師走"], - shortMonths: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"] -}); \ No newline at end of file diff --git a/src/locale/ko-KR.js b/src/locale/ko-KR.js deleted file mode 100644 index 3638bb3fad7697..00000000000000 --- a/src/locale/ko-KR.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_koKR = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["₩", ""], - dateTime: "%Y/%m/%d %a %X", - date: "%Y/%m/%d", - time: "%H:%M:%S", - periods: ["오전", "오후"], - days: ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"], - shortDays: ["일", "월", "화", "수", "목", "금", "토"], - months: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"], - shortMonths: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"] -}); diff --git a/src/locale/locale.js b/src/locale/locale.js deleted file mode 100644 index b3b9950e29d224..00000000000000 --- a/src/locale/locale.js +++ /dev/null @@ -1,9 +0,0 @@ -import "number-format"; -import "time-format"; - -d3.locale = function(locale) { - return { - numberFormat: d3_locale_numberFormat(locale), - timeFormat: d3_locale_timeFormat(locale) - }; -}; diff --git a/src/locale/mk-MK.js b/src/locale/mk-MK.js deleted file mode 100644 index 7b618c44163195..00000000000000 --- a/src/locale/mk-MK.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_mkMK = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", " ден."], - dateTime: "%A, %e %B %Y г. %X", - date: "%d.%m.%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["недела", "понеделник", "вторник", "среда", "четврток", "петок", "сабота"], - shortDays: ["нед", "пон", "вто", "сре", "чет", "пет", "саб"], - months: ["јануари", "февруари", "март", "април", "мај", "јуни", "јули", "август", "септември", "октомври", "ноември", "декември"], - shortMonths: ["јан", "фев", "мар", "апр", "мај", "јун", "јул", "авг", "сеп", "окт", "ное", "дек"] -}); diff --git a/src/locale/nl-NL.js b/src/locale/nl-NL.js deleted file mode 100644 index 667f92475a2afc..00000000000000 --- a/src/locale/nl-NL.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_nlNL = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["€ ", ""], - dateTime: "%a %e %B %Y %T", - date: "%d-%m-%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"], - shortDays: ["zo", "ma", "di", "wo", "do", "vr", "za"], - months: ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"], - shortMonths: ["jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec"] -}); diff --git a/src/locale/number-format.js b/src/locale/number-format.js deleted file mode 100644 index e62f7b4e8b448e..00000000000000 --- a/src/locale/number-format.js +++ /dev/null @@ -1,155 +0,0 @@ -import "../arrays/map"; -import "../core/identity"; -import "../format/formatPrefix"; -import "../format/precision"; -import "../format/round"; - -function d3_locale_numberFormat(locale) { - var locale_decimal = locale.decimal, - locale_thousands = locale.thousands, - locale_grouping = locale.grouping, - locale_currency = locale.currency, - formatGroup = locale_grouping && locale_thousands ? function(value, width) { - var i = value.length, - t = [], - j = 0, - g = locale_grouping[0], - length = 0; - while (i > 0 && g > 0) { - if (length + g + 1 > width) g = Math.max(1, width - length); - t.push(value.substring(i -= g, i + g)); - if ((length += g + 1) > width) break; - g = locale_grouping[j = (j + 1) % locale_grouping.length]; - } - return t.reverse().join(locale_thousands); - } : d3_identity; - - return function(specifier) { - var match = d3_format_re.exec(specifier), - fill = match[1] || " ", - align = match[2] || ">", - sign = match[3] || "-", - symbol = match[4] || "", - zfill = match[5], - width = +match[6], - comma = match[7], - precision = match[8], - type = match[9], - scale = 1, - prefix = "", - suffix = "", - integer = false, - exponent = true; - - if (precision) precision = +precision.substring(1); - - if (zfill || fill === "0" && align === "=") { - zfill = fill = "0"; - align = "="; - } - - switch (type) { - case "n": comma = true; type = "g"; break; - case "%": scale = 100; suffix = "%"; type = "f"; break; - case "p": scale = 100; suffix = "%"; type = "r"; break; - case "b": - case "o": - case "x": - case "X": if (symbol === "#") prefix = "0" + type.toLowerCase(); - case "c": exponent = false; - case "d": integer = true; precision = 0; break; - case "s": scale = -1; type = "r"; break; - } - - if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1]; - - // If no precision is specified for r, fallback to general notation. - if (type == "r" && !precision) type = "g"; - - // Ensure that the requested precision is in the supported range. - if (precision != null) { - if (type == "g") precision = Math.max(1, Math.min(21, precision)); - else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision)); - } - - type = d3_format_types.get(type) || d3_format_typeDefault; - - var zcomma = zfill && comma; - - return function(value) { - var fullSuffix = suffix; - - // Return the empty string for floats formatted as ints. - if (integer && (value % 1)) return ""; - - // Convert negative to positive, and record the sign prefix. - var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign; - - // Apply the scale, computing it from the value's exponent for si format. - // Preserve the existing suffix, if any, such as the currency symbol. - if (scale < 0) { - var unit = d3.formatPrefix(value, precision); - value = unit.scale(value); - fullSuffix = unit.symbol + suffix; - } else { - value *= scale; - } - - // Convert to the desired precision. - value = type(value, precision); - - // Break the value into the integer part (before) and decimal part (after). - var i = value.lastIndexOf("."), - before, - after; - if (i < 0) { - // If there is no decimal, break on "e" where appropriate. - var j = exponent ? value.lastIndexOf("e") : -1; - if (j < 0) before = value, after = ""; - else before = value.substring(0, j), after = value.substring(j); - } else { - before = value.substring(0, i); - after = locale_decimal + value.substring(i + 1); - } - - // If the fill character is not "0", grouping is applied before padding. - if (!zfill && comma) before = formatGroup(before, Infinity); - - var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), - padding = length < width ? new Array(length = width - length + 1).join(fill) : ""; - - // If the fill character is "0", grouping is applied after padding. - if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity); - - // Apply prefix. - negative += prefix; - - // Rejoin integer and decimal parts. - value = before + after; - - return (align === "<" ? negative + value + padding - : align === ">" ? padding + negative + value - : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) - : negative + (zcomma ? value : padding + value)) + fullSuffix; - }; - }; -} - -// [[fill]align][sign][symbol][0][width][,][.precision][type] -var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i; - -var d3_format_types = d3.map({ - b: function(x) { return x.toString(2); }, - c: function(x) { return String.fromCharCode(x); }, - o: function(x) { return x.toString(8); }, - x: function(x) { return x.toString(16); }, - X: function(x) { return x.toString(16).toUpperCase(); }, - g: function(x, p) { return x.toPrecision(p); }, - e: function(x, p) { return x.toExponential(p); }, - f: function(x, p) { return x.toFixed(p); }, - r: function(x, p) { return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p)))); } -}); - -function d3_format_typeDefault(x) { - return x + ""; -} diff --git a/src/locale/pl-PL.js b/src/locale/pl-PL.js deleted file mode 100644 index 4f6b5876fe1fb3..00000000000000 --- a/src/locale/pl-PL.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_plPL = d3.locale({ - decimal: ",", - thousands: ".", - grouping: [3], - currency: ["", "zł"], - dateTime: "%A, %e %B %Y, %X", - date: "%d/%m/%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], // unused - days: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"], - shortDays: ["Niedz.", "Pon.", "Wt.", "Śr.", "Czw.", "Pt.", "Sob."], - months: ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"], - shortMonths: ["Stycz.", "Luty", "Marz.", "Kwie.", "Maj", "Czerw.", "Lipc.", "Sierp.", "Wrz.", "Paźdz.", "Listop.", "Grudz."]/* In Polish language abbraviated months are not commonly used so there is a dispute about the proper abbraviations. */ -}); diff --git a/src/locale/pt-BR.js b/src/locale/pt-BR.js deleted file mode 100644 index e80a3af307be60..00000000000000 --- a/src/locale/pt-BR.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_ptBR = d3.locale({ - decimal: ',', - thousands: '.', - grouping: [3], - currency: ['R$', ''], - dateTime: '%A, %e de %B de %Y. %X', - date: '%d/%m/%Y', - time: '%H:%M:%S', - periods: ['AM', 'PM'], - days: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'], - shortDays: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], - months: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], - shortMonths: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'] -}); diff --git a/src/locale/ru-RU.js b/src/locale/ru-RU.js deleted file mode 100644 index 2d3896257690ce..00000000000000 --- a/src/locale/ru-RU.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_ruRU = d3.locale({ - decimal: ",", - thousands: "\xa0", - grouping: [3], - currency: ["", " руб."], - dateTime: "%A, %e %B %Y г. %X", - date: "%d.%m.%Y", - time: "%H:%M:%S", - periods: ["AM", "PM"], - days: ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"], - shortDays: ["вс", "пн", "вт", "ср", "чт", "пт", "сб"], - months: ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"], - shortMonths: ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"] -}); diff --git a/src/locale/sv-SE.js b/src/locale/sv-SE.js deleted file mode 100644 index b83dfbea0620c6..00000000000000 --- a/src/locale/sv-SE.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_svSE = d3.locale({ - decimal: ",", - thousands: "\xa0", - grouping: [3], - currency: ["", "SEK"], - dateTime: "%A den %d %B %Y %X", - date: "%Y-%m-%d", - time: "%H:%M:%S", - periods: ["fm", "em"], - days: ["Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag"], - shortDays: ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"], - months: ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"], - shortMonths: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"] -}); diff --git a/src/locale/time-format.js b/src/locale/time-format.js deleted file mode 100644 index ccff6f19840762..00000000000000 --- a/src/locale/time-format.js +++ /dev/null @@ -1,370 +0,0 @@ -import "../arrays/map"; -import "../format/requote"; -import "../math/abs"; -import "../time/day"; -import "../time/time"; -import "../time/week"; -import "../time/interval"; - -function d3_locale_timeFormat(locale) { - var locale_dateTime = locale.dateTime, - locale_date = locale.date, - locale_time = locale.time, - locale_periods = locale.periods, - locale_days = locale.days, - locale_shortDays = locale.shortDays, - locale_months = locale.months, - locale_shortMonths = locale.shortMonths; - - function d3_time_format(template) { - var n = template.length; - - function format(date) { - var string = [], - i = -1, - j = 0, - c, - p, - f; - while (++i < n) { - if (template.charCodeAt(i) === 37) { - string.push(template.slice(j, i)); - if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i); - if (f = d3_time_formats[c]) c = f(date, p == null ? (c === "e" ? " " : "0") : p); - string.push(c); - j = i + 1; - } - } - string.push(template.slice(j, i)); - return string.join(""); - } - - format.parse = function(string) { - var d = {y: 1900, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0, Z: null}, - i = d3_time_parse(d, template, string, 0); - if (i != string.length) return null; - - // The am-pm flag is 0 for AM, and 1 for PM. - if ("p" in d) d.H = d.H % 12 + d.p * 12; - - // If a time zone is specified, it is always relative to UTC; - // we need to use d3_date_utc if we aren’t already. - var localZ = d.Z != null && d3_date !== d3_date_utc, - date = new (localZ ? d3_date_utc : d3_date); - - // Set year, month, date. - if ("j" in d) date.setFullYear(d.y, 0, d.j); - else if ("W" in d || "U" in d) { - if (!("w" in d)) d.w = "W" in d ? 1 : 0; - date.setFullYear(d.y, 0, 1); - date.setFullYear(d.y, 0, "W" in d - ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 - : d.w + d.U * 7 - (date.getDay() + 6) % 7); - } else date.setFullYear(d.y, d.m, d.d); - - // Set hours, minutes, seconds and milliseconds. - date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L); - - return localZ ? date._ : date; - }; - - format.toString = function() { - return template; - }; - - return format; - } - - function d3_time_parse(date, template, string, j) { - var c, - p, - t, - i = 0, - n = template.length, - m = string.length; - while (i < n) { - if (j >= m) return -1; - c = template.charCodeAt(i++); - if (c === 37) { - t = template.charAt(i++); - p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t]; - if (!p || ((j = p(date, string, j)) < 0)) return -1; - } else if (c != string.charCodeAt(j++)) { - return -1; - } - } - return j; - } - - d3_time_format.utc = function(template) { - var local = d3_time_format(template); - - function format(date) { - try { - d3_date = d3_date_utc; - var utc = new d3_date(); - utc._ = date; - return local(utc); - } finally { - d3_date = Date; - } - } - - format.parse = function(string) { - try { - d3_date = d3_date_utc; - var date = local.parse(string); - return date && date._; - } finally { - d3_date = Date; - } - }; - - format.toString = local.toString; - - return format; - }; - - d3_time_format.multi = - d3_time_format.utc.multi = d3_time_formatMulti; - - var d3_time_periodLookup = d3.map(), - d3_time_dayRe = d3_time_formatRe(locale_days), - d3_time_dayLookup = d3_time_formatLookup(locale_days), - d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), - d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), - d3_time_monthRe = d3_time_formatRe(locale_months), - d3_time_monthLookup = d3_time_formatLookup(locale_months), - d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), - d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths); - - locale_periods.forEach(function(p, i) { - d3_time_periodLookup.set(p.toLowerCase(), i); - }); - - var d3_time_formats = { - a: function(d) { return locale_shortDays[d.getDay()]; }, - A: function(d) { return locale_days[d.getDay()]; }, - b: function(d) { return locale_shortMonths[d.getMonth()]; }, - B: function(d) { return locale_months[d.getMonth()]; }, - c: d3_time_format(locale_dateTime), - d: function(d, p) { return d3_time_formatPad(d.getDate(), p, 2); }, - e: function(d, p) { return d3_time_formatPad(d.getDate(), p, 2); }, - H: function(d, p) { return d3_time_formatPad(d.getHours(), p, 2); }, - I: function(d, p) { return d3_time_formatPad(d.getHours() % 12 || 12, p, 2); }, - j: function(d, p) { return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3); }, - L: function(d, p) { return d3_time_formatPad(d.getMilliseconds(), p, 3); }, - m: function(d, p) { return d3_time_formatPad(d.getMonth() + 1, p, 2); }, - M: function(d, p) { return d3_time_formatPad(d.getMinutes(), p, 2); }, - p: function(d) { return locale_periods[+(d.getHours() >= 12)]; }, - S: function(d, p) { return d3_time_formatPad(d.getSeconds(), p, 2); }, - U: function(d, p) { return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2); }, - w: function(d) { return d.getDay(); }, - W: function(d, p) { return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2); }, - x: d3_time_format(locale_date), - X: d3_time_format(locale_time), - y: function(d, p) { return d3_time_formatPad(d.getFullYear() % 100, p, 2); }, - Y: function(d, p) { return d3_time_formatPad(d.getFullYear() % 10000, p, 4); }, - Z: d3_time_zone, - "%": function() { return "%"; } - }; - - var d3_time_parsers = { - a: d3_time_parseWeekdayAbbrev, - A: d3_time_parseWeekday, - b: d3_time_parseMonthAbbrev, - B: d3_time_parseMonth, - c: d3_time_parseLocaleFull, - d: d3_time_parseDay, - e: d3_time_parseDay, - H: d3_time_parseHour24, - I: d3_time_parseHour24, - j: d3_time_parseDayOfYear, - L: d3_time_parseMilliseconds, - m: d3_time_parseMonthNumber, - M: d3_time_parseMinutes, - p: d3_time_parseAmPm, - S: d3_time_parseSeconds, - U: d3_time_parseWeekNumberSunday, - w: d3_time_parseWeekdayNumber, - W: d3_time_parseWeekNumberMonday, - x: d3_time_parseLocaleDate, - X: d3_time_parseLocaleTime, - y: d3_time_parseYear, - Y: d3_time_parseFullYear, - Z: d3_time_parseZone, - "%": d3_time_parseLiteralPercent - }; - - function d3_time_parseWeekdayAbbrev(date, string, i) { - d3_time_dayAbbrevRe.lastIndex = 0; - var n = d3_time_dayAbbrevRe.exec(string.slice(i)); - return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - - function d3_time_parseWeekday(date, string, i) { - d3_time_dayRe.lastIndex = 0; - var n = d3_time_dayRe.exec(string.slice(i)); - return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - - function d3_time_parseMonthAbbrev(date, string, i) { - d3_time_monthAbbrevRe.lastIndex = 0; - var n = d3_time_monthAbbrevRe.exec(string.slice(i)); - return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - - function d3_time_parseMonth(date, string, i) { - d3_time_monthRe.lastIndex = 0; - var n = d3_time_monthRe.exec(string.slice(i)); - return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; - } - - function d3_time_parseLocaleFull(date, string, i) { - return d3_time_parse(date, d3_time_formats.c.toString(), string, i); - } - - function d3_time_parseLocaleDate(date, string, i) { - return d3_time_parse(date, d3_time_formats.x.toString(), string, i); - } - - function d3_time_parseLocaleTime(date, string, i) { - return d3_time_parse(date, d3_time_formats.X.toString(), string, i); - } - - function d3_time_parseAmPm(date, string, i) { - var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase()); - return n == null ? -1 : (date.p = n, i); - } - - return d3_time_format; -} - -var d3_time_formatPads = {"-": "", "_": " ", "0": "0"}, - d3_time_numberRe = /^\s*\d+/, // note: ignores next directive - d3_time_percentRe = /^%/; - -function d3_time_formatPad(value, fill, width) { - var sign = value < 0 ? "-" : "", - string = (sign ? -value : value) + "", - length = string.length; - return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); -} - -function d3_time_formatRe(names) { - return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i"); -} - -function d3_time_formatLookup(names) { - var map = new d3_Map, i = -1, n = names.length; - while (++i < n) map.set(names[i].toLowerCase(), i); - return map; -} - -function d3_time_parseWeekdayNumber(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 1)); - return n ? (date.w = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseWeekNumberSunday(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i)); - return n ? (date.U = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseWeekNumberMonday(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i)); - return n ? (date.W = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseFullYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 4)); - return n ? (date.y = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1; -} - -function d3_time_parseZone(date, string, i) { - return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) - ? (date.Z = -string, i + 5) // sign differs from getTimezoneOffset! - : -1; -} - -function d3_time_expandYear(d) { - return d + (d > 68 ? 1900 : 2000); -} - -function d3_time_parseMonthNumber(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.m = n[0] - 1, i + n[0].length) : -1; -} - -function d3_time_parseDay(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.d = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseDayOfYear(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 3)); - return n ? (date.j = +n[0], i + n[0].length) : -1; -} - -// Note: we don't validate that the hour is in the range [0,23] or [1,12]. -function d3_time_parseHour24(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.H = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseMinutes(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.M = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseSeconds(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 2)); - return n ? (date.S = +n[0], i + n[0].length) : -1; -} - -function d3_time_parseMilliseconds(date, string, i) { - d3_time_numberRe.lastIndex = 0; - var n = d3_time_numberRe.exec(string.slice(i, i + 3)); - return n ? (date.L = +n[0], i + n[0].length) : -1; -} - -// TODO table of time zone offset names? -function d3_time_zone(d) { - var z = d.getTimezoneOffset(), - zs = z > 0 ? "-" : "+", - zh = abs(z) / 60 | 0, - zm = abs(z) % 60; - return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2); -} - -function d3_time_parseLiteralPercent(date, string, i) { - d3_time_percentRe.lastIndex = 0; - var n = d3_time_percentRe.exec(string.slice(i, i + 1)); - return n ? i + n[0].length : -1; -} - -function d3_time_formatMulti(formats) { - var n = formats.length, i = -1; - while (++i < n) formats[i][0] = this(formats[i][0]); - return function(date) { - var i = 0, f = formats[i]; - while (!f[1](date)) f = formats[++i]; - return f[0](date); - }; -} diff --git a/src/locale/time-scale.js b/src/locale/time-scale.js deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/src/locale/zh-CN.js b/src/locale/zh-CN.js deleted file mode 100644 index 417a5ff6df7ab3..00000000000000 --- a/src/locale/zh-CN.js +++ /dev/null @@ -1,16 +0,0 @@ -import "locale"; - -var d3_locale_zhCN = d3.locale({ - decimal: ".", - thousands: ",", - grouping: [3], - currency: ["¥", ""], - dateTime: "%x %A %X", - date: "%Y年%-m月%-d日", - time: "%H:%M:%S", - periods: ["上午", "下午"], - days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"], - shortDays: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"], - months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], - shortMonths: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"] -}); diff --git a/src/scale/linear.js b/src/scale/linear.js index 0dc1426fa78add..1b60a2c650bdd4 100644 --- a/src/scale/linear.js +++ b/src/scale/linear.js @@ -3,7 +3,6 @@ import "../core/rebind"; import "../interpolate/interpolate"; import "../interpolate/round"; import "../interpolate/uninterpolate"; -import "../format/format"; import "../math/abs"; import "bilinear"; import "nice"; @@ -117,28 +116,6 @@ function d3_scale_linearTicks(domain, m) { return d3.range.apply(d3, d3_scale_linearTickRange(domain, m)); } -function d3_scale_linearTickFormat(domain, m, format) { - var range = d3_scale_linearTickRange(domain, m); - if (format) { - var match = d3_format_re.exec(format); - match.shift(); - if (match[8] === "s") { - var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1]))); - if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2])); - match[8] = "f"; - format = d3.format(match.join("")); - return function(d) { - return format(prefix.scale(d)) + prefix.symbol; - }; - } - if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range); - format = match.join(""); - } else { - format = ",." + d3_scale_linearPrecision(range[2]) + "f"; - } - return d3.format(format); -} - var d3_scale_linearFormatSignificant = {s: 1, g: 1, p: 1, r: 1, e: 1}; // Returns the number of significant digits after the decimal point. diff --git a/src/scale/log.js b/src/scale/log.js index fe264fa41598c8..9ba4289dcdea50 100644 --- a/src/scale/log.js +++ b/src/scale/log.js @@ -1,4 +1,3 @@ -import "../format/format"; import "linear"; import "nice"; import "scale"; @@ -69,18 +68,6 @@ function d3_scale_log(linear, base, positive, domain) { return ticks; }; - scale.tickFormat = function(n, format) { - if (!arguments.length) return d3_scale_logFormat; - if (arguments.length < 2) format = d3_scale_logFormat; - else if (typeof format !== "function") format = d3.format(format); - var k = Math.max(1, base * n / scale.ticks().length); - return function(d) { - var i = d / pow(Math.round(log(d))); - if (i * base < base - 0.5) i *= base; - return i <= k ? format(d) : ""; - }; - }; - scale.copy = function() { return d3_scale_log(linear.copy(), base, positive, domain); }; @@ -88,5 +75,4 @@ function d3_scale_log(linear, base, positive, domain) { return d3_scale_linearRebind(scale, linear); } -var d3_scale_logFormat = d3.format(".0e"), - d3_scale_logNiceNegative = {floor: function(x) { return -Math.ceil(-x); }, ceil: function(x) { return -Math.floor(-x); }}; +var d3_scale_logNiceNegative = {floor: function(x) { return -Math.ceil(-x); }, ceil: function(x) { return -Math.floor(-x); }}; diff --git a/src/time/format-iso.js b/src/time/format-iso.js deleted file mode 100644 index 1bcd860ce0ec74..00000000000000 --- a/src/time/format-iso.js +++ /dev/null @@ -1,19 +0,0 @@ -import "format"; -import "format-utc"; - -var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ"); - -d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") - ? d3_time_formatIsoNative - : d3_time_formatIso; - -function d3_time_formatIsoNative(date) { - return date.toISOString(); -} - -d3_time_formatIsoNative.parse = function(string) { - var date = new Date(string); - return isNaN(date) ? null : date; -}; - -d3_time_formatIsoNative.toString = d3_time_formatIso.toString; diff --git a/src/time/format-utc.js b/src/time/format-utc.js deleted file mode 100644 index f5b4808c088d2d..00000000000000 --- a/src/time/format-utc.js +++ /dev/null @@ -1,3 +0,0 @@ -import "format"; - -var d3_time_formatUtc = d3_time_format.utc; diff --git a/src/time/format.js b/src/time/format.js deleted file mode 100644 index 3ad7f5f6dee04b..00000000000000 --- a/src/time/format.js +++ /dev/null @@ -1,4 +0,0 @@ -import "../locale/en-US"; -import "time"; - -var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat; diff --git a/src/time/index.js b/src/time/index.js index b041fc6dd32c1d..2ba704d10c68c8 100644 --- a/src/time/index.js +++ b/src/time/index.js @@ -1,7 +1,4 @@ import "time"; -import "format"; -import "format-utc"; -import "format-iso"; import "interval"; import "second"; import "minute"; @@ -10,5 +7,3 @@ import "day"; import "week"; import "month"; import "year"; -import "scale"; -import "scale-utc"; diff --git a/src/time/scale-utc.js b/src/time/scale-utc.js deleted file mode 100644 index 1c6e30fe6e7676..00000000000000 --- a/src/time/scale-utc.js +++ /dev/null @@ -1,25 +0,0 @@ -import "../core/true"; -import "../scale/linear"; -import "scale"; -import "format-utc"; - -var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) { - return [m[0].utc, m[1]]; -}); - -var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ - [".%L", function(d) { return d.getUTCMilliseconds(); }], - [":%S", function(d) { return d.getUTCSeconds(); }], - ["%I:%M", function(d) { return d.getUTCMinutes(); }], - ["%I %p", function(d) { return d.getUTCHours(); }], - ["%a %d", function(d) { return d.getUTCDay() && d.getUTCDate() != 1; }], - ["%b %d", function(d) { return d.getUTCDate() != 1; }], - ["%B", function(d) { return d.getUTCMonth(); }], - ["%Y", d3_true] -]); - -d3_time_scaleUtcMethods.year = d3_time.year.utc; - -d3_time.scale.utc = function() { - return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat); -}; diff --git a/src/time/scale.js b/src/time/scale.js deleted file mode 100644 index 90a23df9ea7dbf..00000000000000 --- a/src/time/scale.js +++ /dev/null @@ -1,155 +0,0 @@ -import "../arrays/bisect"; -import "../arrays/range"; -import "../core/identity"; -import "../core/true"; -import "../scale/linear"; -import "../scale/nice"; -import "format"; -import "day"; -import "hour"; -import "minute"; -import "month"; -import "second"; -import "time"; -import "week"; -import "year"; - -function d3_time_scale(linear, methods, format) { - - function scale(x) { - return linear(x); - } - - scale.invert = function(x) { - return d3_time_scaleDate(linear.invert(x)); - }; - - scale.domain = function(x) { - if (!arguments.length) return linear.domain().map(d3_time_scaleDate); - linear.domain(x); - return scale; - }; - - function tickMethod(extent, count) { - var span = extent[1] - extent[0], - target = span / count, - i = d3.bisect(d3_time_scaleSteps, target); - return i == d3_time_scaleSteps.length ? [methods.year, d3_scale_linearTickRange(extent.map(function(d) { return d / 31536e6; }), count)[2]] - : !i ? [d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2]] - : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i]; - } - - scale.nice = function(interval, skip) { - var domain = scale.domain(), - extent = d3_scaleExtent(domain), - method = interval == null ? tickMethod(extent, 10) - : typeof interval === "number" && tickMethod(extent, interval); - - if (method) interval = method[0], skip = method[1]; - - function skipped(date) { - return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length; - } - - return scale.domain(d3_scale_nice(domain, skip > 1 ? { - floor: function(date) { - while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1); - return date; - }, - ceil: function(date) { - while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1); - return date; - } - } : interval)); - }; - - scale.ticks = function(interval, skip) { - var extent = d3_scaleExtent(scale.domain()), - method = interval == null ? tickMethod(extent, 10) - : typeof interval === "number" ? tickMethod(extent, interval) - : !interval.range && [{range: interval}, skip]; // assume deprecated range function - - if (method) interval = method[0], skip = method[1]; - - return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip); // inclusive upper bound - }; - - scale.tickFormat = function() { - return format; - }; - - scale.copy = function() { - return d3_time_scale(linear.copy(), methods, format); - }; - - return d3_scale_linearRebind(scale, linear); -} - -function d3_time_scaleDate(t) { - return new Date(t); -} - -var d3_time_scaleSteps = [ - 1e3, // 1-second - 5e3, // 5-second - 15e3, // 15-second - 3e4, // 30-second - 6e4, // 1-minute - 3e5, // 5-minute - 9e5, // 15-minute - 18e5, // 30-minute - 36e5, // 1-hour - 108e5, // 3-hour - 216e5, // 6-hour - 432e5, // 12-hour - 864e5, // 1-day - 1728e5, // 2-day - 6048e5, // 1-week - 2592e6, // 1-month - 7776e6, // 3-month - 31536e6 // 1-year -]; - -var d3_time_scaleLocalMethods = [ - [d3_time.second, 1], - [d3_time.second, 5], - [d3_time.second, 15], - [d3_time.second, 30], - [d3_time.minute, 1], - [d3_time.minute, 5], - [d3_time.minute, 15], - [d3_time.minute, 30], - [d3_time.hour, 1], - [d3_time.hour, 3], - [d3_time.hour, 6], - [d3_time.hour, 12], - [d3_time.day, 1], - [d3_time.day, 2], - [d3_time.week, 1], - [d3_time.month, 1], - [d3_time.month, 3], - [d3_time.year, 1] -]; - -var d3_time_scaleLocalFormat = d3_time_format.multi([ - [".%L", function(d) { return d.getMilliseconds(); }], - [":%S", function(d) { return d.getSeconds(); }], - ["%I:%M", function(d) { return d.getMinutes(); }], - ["%I %p", function(d) { return d.getHours(); }], - ["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }], - ["%b %d", function(d) { return d.getDate() != 1; }], - ["%B", function(d) { return d.getMonth(); }], - ["%Y", d3_true] -]); - -var d3_time_scaleMilliseconds = { - range: function(start, stop, step) { return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate); }, - floor: d3_identity, - ceil: d3_identity -}; - -d3_time_scaleLocalMethods.year = d3_time.year; - -d3_time.scale = function() { - return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat); -}; diff --git a/test/format/format-test.js b/test/format/format-test.js deleted file mode 100644 index b81704bcea7250..00000000000000 --- a/test/format/format-test.js +++ /dev/null @@ -1,436 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"); - -var suite = vows.describe("d3.format"); - -suite.addBatch({ - "format": { - topic: load("format/format").expression("d3.format"), - "returns a string": function(format) { - assert.isString(format("d")(0)); - }, - "can zero fill": function(format) { - var f = format("08d"); - assert.strictEqual(f(0), "00000000"); - assert.strictEqual(f(42), "00000042"); - assert.strictEqual(f(42000000), "42000000"); - assert.strictEqual(f(420000000), "420000000"); - assert.strictEqual(f(-4), "-0000004"); - assert.strictEqual(f(-42), "-0000042"); - assert.strictEqual(f(-4200000), "-4200000"); - assert.strictEqual(f(-42000000), "-42000000"); - }, - "can space fill": function(format) { - var f = format("8d"); - assert.strictEqual(f(0), " 0"); - assert.strictEqual(f(42), " 42"); - assert.strictEqual(f(42000000), "42000000"); - assert.strictEqual(f(420000000), "420000000"); - assert.strictEqual(f(-4), " -4"); - assert.strictEqual(f(-42), " -42"); - assert.strictEqual(f(-4200000), "-4200000"); - assert.strictEqual(f(-42000000), "-42000000"); - }, - "can output fixed-point notation": function(format) { - assert.strictEqual(format(".1f")(0.49), "0.5"); - assert.strictEqual(format(".2f")(0.449), "0.45"); - assert.strictEqual(format(".3f")(0.4449), "0.445"); - assert.strictEqual(format(".5f")(0.444449), "0.44445"); - assert.strictEqual(format(".1f")(100), "100.0"); - assert.strictEqual(format(".2f")(100), "100.00"); - assert.strictEqual(format(".3f")(100), "100.000"); - assert.strictEqual(format(".5f")(100), "100.00000"); - }, - "can output general notation": function(format) { - assert.strictEqual(format(".1g")(0.049), "0.05"); - assert.strictEqual(format(".1g")(0.49), "0.5"); - assert.strictEqual(format(".2g")(0.449), "0.45"); - assert.strictEqual(format(".3g")(0.4449), "0.445"); - assert.strictEqual(format(".5g")(0.444449), "0.44445"); - assert.strictEqual(format(".1g")(100), "1e+2"); - assert.strictEqual(format(".2g")(100), "1.0e+2"); - assert.strictEqual(format(".3g")(100), "100"); - assert.strictEqual(format(".5g")(100), "100.00"); - assert.strictEqual(format(".5g")(100.2), "100.20"); - assert.strictEqual(format(".2g")(0.002), "0.0020"); - }, - "can output exponent notation ": function(format) { - var f = format("e"); - assert.strictEqual(f(0), "0e+0"); - assert.strictEqual(f(42), "4.2e+1"); - assert.strictEqual(f(42000000), "4.2e+7"); - assert.strictEqual(f(420000000), "4.2e+8"); - assert.strictEqual(f(-4), "-4e+0"); - assert.strictEqual(f(-42), "-4.2e+1"); - assert.strictEqual(f(-4200000), "-4.2e+6"); - assert.strictEqual(f(-42000000), "-4.2e+7"); - assert.strictEqual(format(".0e")(42), "4e+1") - assert.strictEqual(format(".3e")(42), "4.200e+1") - }, - "can output SI prefix notation": function(format) { - var f = format("s"); - assert.strictEqual(f(0), "0"); - assert.strictEqual(f(1), "1"); - assert.strictEqual(f(10), "10"); - assert.strictEqual(f(100), "100"); - assert.strictEqual(f(999.5), "999.5"); - assert.strictEqual(f(999500), "999.5k"); - assert.strictEqual(f(1000), "1k"); - assert.strictEqual(f(1400), "1.4k"); - assert.strictEqual(f(1500.5), "1.5005k"); - assert.strictEqual(f(0.000001), "1µ"); - }, - "can output SI prefix notation with appropriate rounding": function(format) { - var f = format(".3s"); - assert.strictEqual(f(0), "0.00"); - assert.strictEqual(f(1), "1.00"); - assert.strictEqual(f(10), "10.0"); - assert.strictEqual(f(100), "100"); - assert.strictEqual(f(999.5), "1.00k"); - assert.strictEqual(f(999500), "1.00M"); - assert.strictEqual(f(1000), "1.00k"); - assert.strictEqual(f(1500.5), "1.50k"); - assert.strictEqual(f(145500000), "146M"); - assert.strictEqual(f(145999999.999999347), "146M"); - assert.strictEqual(f(1e26), "100Y"); - assert.strictEqual(f(0.000001), "1.00µ"); - assert.strictEqual(f(0.009995), "10.0m"); - var f = format(".4s"); - assert.strictEqual(f(999.5), "999.5"); - assert.strictEqual(f(999500), "999.5k"); - assert.strictEqual(f(0.009995), "9.995m"); - }, - "can output SI prefix notation with appropriate rounding and currency symbol": function(format) { - var f = format("$.3s"); - assert.strictEqual(f(0), "$0.00"); - assert.strictEqual(f(1), "$1.00"); - assert.strictEqual(f(10), "$10.0"); - assert.strictEqual(f(100), "$100"); - assert.strictEqual(f(999.5), "$1.00k"); - assert.strictEqual(f(999500), "$1.00M"); - assert.strictEqual(f(1000), "$1.00k"); - assert.strictEqual(f(1500.5), "$1.50k"); - assert.strictEqual(f(145500000), "$146M"); - assert.strictEqual(f(145999999.999999347), "$146M"); - assert.strictEqual(f(1e26), "$100Y"); - assert.strictEqual(f(0.000001), "$1.00µ"); - assert.strictEqual(f(0.009995), "$10.0m"); - var f = format("$.4s"); - assert.strictEqual(f(999.5), "$999.5"); - assert.strictEqual(f(999500), "$999.5k"); - assert.strictEqual(f(0.009995), "$9.995m"); - }, - "SI prefix notation precision is consistent for small and large numbers": function(format) { - assert.deepEqual( - [ 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0, 1e1, 1e2, 1e3, 1e4, 1e5].map(format("s")), - [ '10µ', '100µ', '1m', '10m', '100m', '1', '10', '100', '1k', '10k', '100k']); - assert.deepEqual( - [ 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0, 1e1, 1e2, 1e3, 1e4, 1e5].map(format(".4s")), - ['10.00µ', '100.0µ', '1.000m', '10.00m', '100.0m', '1.000', '10.00', '100.0', '1.000k', '10.00k', '100.0k']); - }, - "can output a currency": function(format) { - var f = format("$"); - assert.strictEqual(f(0), "$0"); - assert.strictEqual(f(0.042), "$0.042"); - assert.strictEqual(f(0.42), "$0.42"); - assert.strictEqual(f(4.2), "$4.2"); - assert.strictEqual(f(-0.042), "-$0.042"); - assert.strictEqual(f(-0.42), "-$0.42"); - assert.strictEqual(f(-4.2), "-$4.2"); - }, - "can output a currency with comma-grouping and sign": function(format) { - var f = format("+$,.2f"); - assert.strictEqual(f(0), "+$0.00"); - assert.strictEqual(f(0.429), "+$0.43"); - assert.strictEqual(f(-0.429), "-$0.43"); - assert.strictEqual(f(-1), "-$1.00"); - assert.strictEqual(f(1e4), "+$10,000.00"); - }, - "can output a currency with si-prefix notation": function(format) { - var f = format("$.2s"); - assert.strictEqual(f(0), "$0.0"); - assert.strictEqual(f(2.5e5), "$250k"); - assert.strictEqual(f(-2.5e8), "-$250M"); - assert.strictEqual(f(2.5e11), "$250G"); - }, - "can output a percentage": function(format) { - var f = format("%"); - assert.strictEqual(f(0), "0%"); - assert.strictEqual(f(0.042), "4%"); - assert.strictEqual(f(0.42), "42%"); - assert.strictEqual(f(4.2), "420%"); - assert.strictEqual(f(-0.042), "-4%"); - assert.strictEqual(f(-0.42), "-42%"); - assert.strictEqual(f(-4.2), "-420%"); - }, - "can output a percentage with rounding and sign": function(format) { - var f = format("+.2p"); - assert.strictEqual(f(0.00123), "+0.12%"); - assert.strictEqual(f(0.0123), "+1.2%"); - assert.strictEqual(f(0.123), "+12%"); - assert.strictEqual(f(1.23), "+120%"); - assert.strictEqual(f(-0.00123), "-0.12%"); - assert.strictEqual(f(-0.0123), "-1.2%"); - assert.strictEqual(f(-0.123), "-12%"); - assert.strictEqual(f(-1.23), "-120%"); - }, - "can round to significant digits": function(format) { - assert.strictEqual(format(".2r")(0), "0.0"); - assert.strictEqual(format(".1r")(0.049), "0.05"); - assert.strictEqual(format(".1r")(-0.049), "-0.05"); - assert.strictEqual(format(".1r")(0.49), "0.5"); - assert.strictEqual(format(".1r")(-0.49), "-0.5"); - assert.strictEqual(format(".2r")(0.449), "0.45"); - assert.strictEqual(format(".3r")(0.4449), "0.445"); - assert.strictEqual(format(".3r")(1.00), "1.00"); - assert.strictEqual(format(".3r")(0.9995), "1.00"); - assert.strictEqual(format(".5r")(0.444449), "0.44445"); - assert.strictEqual(format("r")(123.45), "123.45"); - assert.strictEqual(format(".1r")(123.45), "100"); - assert.strictEqual(format(".2r")(123.45), "120"); - assert.strictEqual(format(".3r")(123.45), "123"); - assert.strictEqual(format(".4r")(123.45), "123.5"); - assert.strictEqual(format(".5r")(123.45), "123.45"); - assert.strictEqual(format(".6r")(123.45), "123.450"); - assert.strictEqual(format(".1r")(0.9), "0.9"); - assert.strictEqual(format(".1r")(0.09), "0.09"); - assert.strictEqual(format(".1r")(0.949), "0.9"); - assert.strictEqual(format(".1r")(0.0949), "0.09"); - assert.strictEqual(format(".10r")(0.9999999999), "0.9999999999"); - assert.strictEqual(format(".15r")(0.999999999999999), "0.999999999999999"); - }, - "can round very small numbers": function(format) { - var f = format(".2r"); - assert.strictEqual(f(1e-22), "0.00000000000000000000"); - }, - "can group thousands": function(format) { - var f = format(",d"); - assert.strictEqual(f(0), "0"); - assert.strictEqual(f(42), "42"); - assert.strictEqual(f(42000000), "42,000,000"); - assert.strictEqual(f(420000000), "420,000,000"); - assert.strictEqual(f(-4), "-4"); - assert.strictEqual(f(-42), "-42"); - assert.strictEqual(f(-4200000), "-4,200,000"); - assert.strictEqual(f(-42000000), "-42,000,000"); - assert.strictEqual(f(1e21), "1e+21"); - }, - "can group thousands and zero fill": function(format) { - assert.strictEqual(format("01,d")(0), "0"); - assert.strictEqual(format("01,d")(0), "0"); - assert.strictEqual(format("02,d")(0), "00"); - assert.strictEqual(format("03,d")(0), "000"); - assert.strictEqual(format("04,d")(0), "0,000"); - assert.strictEqual(format("05,d")(0), "0,000"); - assert.strictEqual(format("06,d")(0), "00,000"); - assert.strictEqual(format("08,d")(0), "0,000,000"); - assert.strictEqual(format("013,d")(0), "0,000,000,000"); - assert.strictEqual(format("021,d")(0), "0,000,000,000,000,000"); - assert.strictEqual(format("013,d")(-42000000), "-0,042,000,000"); - assert.strictEqual(format("012,d")(1e21), "0,000,001e+21"); - assert.strictEqual(format("013,d")(1e21), "0,000,001e+21"); - assert.strictEqual(format("014,d")(1e21), "00,000,001e+21"); - assert.strictEqual(format("015,d")(1e21), "000,000,001e+21"); - }, - "can group thousands and zero fill with overflow": function(format) { - assert.strictEqual(format("01,d")(1), "1"); - assert.strictEqual(format("01,d")(1), "1"); - assert.strictEqual(format("02,d")(12), "12"); - assert.strictEqual(format("03,d")(123), "123"); - assert.strictEqual(format("05,d")(12345), "12,345"); - assert.strictEqual(format("08,d")(12345678), "12,345,678"); - assert.strictEqual(format("013,d")(1234567890123), "1,234,567,890,123"); - }, - "can group thousands and space fill": function(format) { - assert.strictEqual(format("1,d")(0), "0"); - assert.strictEqual(format("1,d")(0), "0"); - assert.strictEqual(format("2,d")(0), " 0"); - assert.strictEqual(format("3,d")(0), " 0"); - assert.strictEqual(format("5,d")(0), " 0"); - assert.strictEqual(format("8,d")(0), " 0"); - assert.strictEqual(format("13,d")(0), " 0"); - assert.strictEqual(format("21,d")(0), " 0"); - }, - "can group thousands and space fill with overflow": function(format) { - assert.strictEqual(format("1,d")(1), "1"); - assert.strictEqual(format("1,d")(1), "1"); - assert.strictEqual(format("2,d")(12), "12"); - assert.strictEqual(format("3,d")(123), "123"); - assert.strictEqual(format("5,d")(12345), "12,345"); - assert.strictEqual(format("8,d")(12345678), "12,345,678"); - assert.strictEqual(format("13,d")(1234567890123), "1,234,567,890,123"); - }, - "can group thousands with general notation": function(format) { - var f = format(",g"); - assert.strictEqual(f(0), "0"); - assert.strictEqual(f(42), "42"); - assert.strictEqual(f(42000000), "42,000,000"); - assert.strictEqual(f(420000000), "420,000,000"); - assert.strictEqual(f(-4), "-4"); - assert.strictEqual(f(-42), "-42"); - assert.strictEqual(f(-4200000), "-4,200,000"); - assert.strictEqual(f(-42000000), "-42,000,000"); - }, - "can group thousands, space fill, and round to significant digits": function(format) { - assert.strictEqual(format("10,.1f")(123456.49), " 123,456.5"); - assert.strictEqual(format("10,.2f")(1234567.449), "1,234,567.45"); - assert.strictEqual(format("10,.3f")(12345678.4449), "12,345,678.445"); - assert.strictEqual(format("10,.5f")(123456789.444449), "123,456,789.44445"); - assert.strictEqual(format("10,.1f")(123456), " 123,456.0"); - assert.strictEqual(format("10,.2f")(1234567), "1,234,567.00"); - assert.strictEqual(format("10,.3f")(12345678), "12,345,678.000"); - assert.strictEqual(format("10,.5f")(123456789), "123,456,789.00000"); - }, - "can display integers in fixed-point notation": function(format) { - assert.strictEqual(format("f")(42), "42"); - }, - "will not display non-integers in integer format": function(format) { - assert.strictEqual(format("d")(4.2), ""); - }, - "unicode character": function(format) { - assert.strictEqual(format("c")(9731), "☃"); - }, - "binary": function(format) { - assert.strictEqual(format("b")(10), "1010"); - }, - "binary with prefix": function(format) { - assert.strictEqual(format("#b")(10), "0b1010"); - }, - "octal": function(format) { - assert.strictEqual(format("o")(10), "12"); - }, - "octal with prefix": function(format) { - assert.strictEqual(format("#o")(10), "0o12"); - }, - "hexadecimal (lowercase)": function(format) { - assert.strictEqual(format("x")(3735928559), "deadbeef"); - }, - "hexadecimal (lowercase) with prefix": function(format) { - assert.strictEqual(format("#x")(3735928559), "0xdeadbeef"); - }, - "hexadecimal (uppercase)": function(format) { - assert.strictEqual(format("X")(3735928559), "DEADBEEF"); - }, - "hexadecimal (uppercase) with prefix": function(format) { - assert.strictEqual(format("#X")(3735928559), "0xDEADBEEF"); - }, - "fill respects prefix": function(format) { - assert.strictEqual(format("#20x")(3735928559), " 0xdeadbeef"); - }, - "align left": function(format) { - assert.strictEqual(format("<1,d")(0), "0"); - assert.strictEqual(format("<1,d")(0), "0"); - assert.strictEqual(format("<2,d")(0), "0 "); - assert.strictEqual(format("<3,d")(0), "0 "); - assert.strictEqual(format("<5,d")(0), "0 "); - assert.strictEqual(format("<8,d")(0), "0 "); - assert.strictEqual(format("<13,d")(0), "0 "); - assert.strictEqual(format("<21,d")(0), "0 "); - }, - "align right": function(format) { - assert.strictEqual(format(">1,d")(0), "0"); - assert.strictEqual(format(">1,d")(0), "0"); - assert.strictEqual(format(">2,d")(0), " 0"); - assert.strictEqual(format(">3,d")(0), " 0"); - assert.strictEqual(format(">5,d")(0), " 0"); - assert.strictEqual(format(">8,d")(0), " 0"); - assert.strictEqual(format(">13,d")(0), " 0"); - assert.strictEqual(format(">21,d")(0), " 0"); - assert.strictEqual(format(">21,d")(1000), " 1,000"); - assert.strictEqual(format(">21,d")(1e21), " 1e+21"); - }, - "align center": function(format) { - assert.strictEqual(format("^1,d")(0), "0"); - assert.strictEqual(format("^1,d")(0), "0"); - assert.strictEqual(format("^2,d")(0), " 0"); - assert.strictEqual(format("^3,d")(0), " 0 "); - assert.strictEqual(format("^5,d")(0), " 0 "); - assert.strictEqual(format("^8,d")(0), " 0 "); - assert.strictEqual(format("^13,d")(0), " 0 "); - assert.strictEqual(format("^21,d")(0), " 0 "); - assert.strictEqual(format("^21,d")(1000), " 1,000 "); - assert.strictEqual(format("^21,d")(1e21), " 1e+21 "); - }, - "pad after sign": function(format) { - assert.strictEqual(format("=+1,d")(0), "+0"); - assert.strictEqual(format("=+1,d")(0), "+0"); - assert.strictEqual(format("=+2,d")(0), "+0"); - assert.strictEqual(format("=+3,d")(0), "+ 0"); - assert.strictEqual(format("=+5,d")(0), "+ 0"); - assert.strictEqual(format("=+8,d")(0), "+ 0"); - assert.strictEqual(format("=+13,d")(0), "+ 0"); - assert.strictEqual(format("=+21,d")(0), "+ 0"); - assert.strictEqual(format("=+21,d")(1e21), "+ 1e+21"); - }, - "pad after sign with currency": function(format) { - assert.strictEqual(format("=+$1,d")(0), "+$0"); - assert.strictEqual(format("=+$1,d")(0), "+$0"); - assert.strictEqual(format("=+$2,d")(0), "+$0"); - assert.strictEqual(format("=+$3,d")(0), "+$0"); - assert.strictEqual(format("=+$5,d")(0), "+$ 0"); - assert.strictEqual(format("=+$8,d")(0), "+$ 0"); - assert.strictEqual(format("=+$13,d")(0), "+$ 0"); - assert.strictEqual(format("=+$21,d")(0), "+$ 0"); - assert.strictEqual(format("=+$21,d")(1e21), "+$ 1e+21"); - }, - "a space can denote positive numbers": function(format) { - assert.strictEqual(format(" 1,d")(-1), "-1"); - assert.strictEqual(format(" 1,d")(0), " 0"); - assert.strictEqual(format(" 2,d")(0), " 0"); - assert.strictEqual(format(" 3,d")(0), " 0"); - assert.strictEqual(format(" 5,d")(0), " 0"); - assert.strictEqual(format(" 8,d")(0), " 0"); - assert.strictEqual(format(" 13,d")(0), " 0"); - assert.strictEqual(format(" 21,d")(0), " 0"); - assert.strictEqual(format(" 21,d")(1e21), " 1e+21"); - }, - "explicitly only use a sign for negative numbers": function(format) { - assert.strictEqual(format("-1,d")(-1), "-1"); - assert.strictEqual(format("-1,d")(0), "0"); - assert.strictEqual(format("-2,d")(0), " 0"); - assert.strictEqual(format("-3,d")(0), " 0"); - assert.strictEqual(format("-5,d")(0), " 0"); - assert.strictEqual(format("-8,d")(0), " 0"); - assert.strictEqual(format("-13,d")(0), " 0"); - assert.strictEqual(format("-21,d")(0), " 0"); - }, - "can format negative zero": function(format) { - assert.strictEqual(format("1d")(-0), "-0"); - assert.strictEqual(format("1f")(-0), "-0"); - }, - "supports \"n\" as an alias for \",g\"": function(format) { - var f = format("n"); - assert.strictEqual(f(0.0042), "0.0042"); - assert.strictEqual(f(0.42), "0.42"); - assert.strictEqual(f(0), "0"); - assert.strictEqual(f(42), "42"); - assert.strictEqual(f(42000000), "42,000,000"); - assert.strictEqual(f(420000000), "420,000,000"); - assert.strictEqual(f(-4), "-4"); - assert.strictEqual(f(-42), "-42"); - assert.strictEqual(f(-4200000), "-4,200,000"); - assert.strictEqual(f(-42000000), "-42,000,000"); - assert.strictEqual(f(1e21), "1e+21"); - }, - "\"n\" with zero padding": function(format) { - assert.strictEqual(format("01n")(0), "0"); - assert.strictEqual(format("01n")(0), "0"); - assert.strictEqual(format("02n")(0), "00"); - assert.strictEqual(format("03n")(0), "000"); - assert.strictEqual(format("05n")(0), "0,000"); - assert.strictEqual(format("08n")(0), "0,000,000"); - assert.strictEqual(format("013n")(0), "0,000,000,000"); - assert.strictEqual(format("021n")(0), "0,000,000,000,000,000"); - assert.strictEqual(format("013n")(-42000000), "-0,042,000,000"); - }, - "unreasonable precision values are clamped to reasonable values": function(format) { - assert.strictEqual(format(".30f")(0), "0.00000000000000000000"); - assert.strictEqual(format(".0g")(1), "1"); - assert.strictEqual(format(",.-1f")(12345), "12,345"); - assert.strictEqual(format("+,.-1%")(123.45), "+12,345%"); - } - } -}); - -suite.export(module); diff --git a/test/format/formatPrefix-test.js b/test/format/formatPrefix-test.js deleted file mode 100644 index dd9e37a7507bde..00000000000000 --- a/test/format/formatPrefix-test.js +++ /dev/null @@ -1,115 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"); - -var suite = vows.describe("d3.formatPrefix"); - -suite.addBatch({ - "formatPrefix": { - topic: load("format/formatPrefix").expression("d3.formatPrefix"), - "determines the appropriate prefix for small numbers": function(prefix) { - assert.equal(prefix(0).symbol, ""); - assert.equal(prefix(1e-00).symbol, ""); - assert.equal(prefix(1e-01).symbol, "m"); - assert.equal(prefix(1e-02).symbol, "m"); - assert.equal(prefix(1e-03).symbol, "m"); - assert.equal(prefix(1e-04).symbol, "µ"); - assert.equal(prefix(1e-05).symbol, "µ"); - assert.equal(prefix(1e-06).symbol, "µ"); - assert.equal(prefix(1e-07).symbol, "n"); - assert.equal(prefix(1e-08).symbol, "n"); - assert.equal(prefix(1e-09).symbol, "n"); - assert.equal(prefix(1e-10).symbol, "p"); - assert.equal(prefix(1e-11).symbol, "p"); - assert.equal(prefix(1e-12).symbol, "p"); - assert.equal(prefix(1e-13).symbol, "f"); - assert.equal(prefix(1e-14).symbol, "f"); - assert.equal(prefix(1e-15).symbol, "f"); - assert.equal(prefix(1e-16).symbol, "a"); - assert.equal(prefix(1e-17).symbol, "a"); - assert.equal(prefix(1e-18).symbol, "a"); - assert.equal(prefix(1e-19).symbol, "z"); - assert.equal(prefix(1e-20).symbol, "z"); - assert.equal(prefix(1e-21).symbol, "z"); - assert.equal(prefix(1e-22).symbol, "y"); - assert.equal(prefix(1e-23).symbol, "y"); - assert.equal(prefix(1e-24).symbol, "y"); - assert.equal(prefix(1e-25).symbol, "y"); - assert.equal(prefix(1e-26).symbol, "y"); - assert.equal(prefix(1e-27).symbol, "y"); - }, - "determines the appropriate prefix for large numbers": function(prefix) { - assert.equal(prefix(0).symbol, ""); - assert.equal(prefix(1e00).symbol, ""); - assert.equal(prefix(1e01).symbol, ""); - assert.equal(prefix(1e02).symbol, ""); - assert.equal(prefix(1e03).symbol, "k"); - assert.equal(prefix(1e04).symbol, "k"); - assert.equal(prefix(1e05).symbol, "k"); - assert.equal(prefix(1e06).symbol, "M"); - assert.equal(prefix(1e07).symbol, "M"); - assert.equal(prefix(1e08).symbol, "M"); - assert.equal(prefix(1e09).symbol, "G"); - assert.equal(prefix(1e10).symbol, "G"); - assert.equal(prefix(1e11).symbol, "G"); - assert.equal(prefix(1e12).symbol, "T"); - assert.equal(prefix(1e13).symbol, "T"); - assert.equal(prefix(1e14).symbol, "T"); - assert.equal(prefix(1e15).symbol, "P"); - assert.equal(prefix(1e16).symbol, "P"); - assert.equal(prefix(1e17).symbol, "P"); - assert.equal(prefix(1e18).symbol, "E"); - assert.equal(prefix(1e19).symbol, "E"); - assert.equal(prefix(1e20).symbol, "E"); - assert.equal(prefix(1e21).symbol, "Z"); - assert.equal(prefix(1e22).symbol, "Z"); - assert.equal(prefix(1e23).symbol, "Z"); - assert.equal(prefix(1e24).symbol, "Y"); - assert.equal(prefix(1e25).symbol, "Y"); - assert.equal(prefix(1e26).symbol, "Y"); - assert.equal(prefix(1e27).symbol, "Y"); - }, - "determines the appropriate prefix for negative numbers": function(prefix) { - assert.equal(prefix(-0).symbol, ""); - assert.equal(prefix(-1e-00).symbol, ""); - assert.equal(prefix(-1e-03).symbol, "m"); - assert.equal(prefix(-1e-06).symbol, "µ"); - assert.equal(prefix(-1e-09).symbol, "n"); - assert.equal(prefix(-1e-12).symbol, "p"); - assert.equal(prefix(-1e-15).symbol, "f"); - assert.equal(prefix(-1e-18).symbol, "a"); - assert.equal(prefix(-1e-21).symbol, "z"); - assert.equal(prefix(-1e-24).symbol, "y"); - assert.equal(prefix(-1e-27).symbol, "y"); - assert.equal(prefix(-1e00).symbol, ""); - assert.equal(prefix(-1e03).symbol, "k"); - assert.equal(prefix(-1e06).symbol, "M"); - assert.equal(prefix(-1e09).symbol, "G"); - assert.equal(prefix(-1e12).symbol, "T"); - assert.equal(prefix(-1e15).symbol, "P"); - assert.equal(prefix(-1e18).symbol, "E"); - assert.equal(prefix(-1e21).symbol, "Z"); - assert.equal(prefix(-1e24).symbol, "Y"); - assert.equal(prefix(-1e27).symbol, "Y"); - }, - "considers the effect of rounding based on precision": function(prefix) { - assert.equal(prefix(999.50000, 4).symbol, ""); - assert.equal(prefix(999.50000, 3).symbol, "k"); - assert.equal(prefix(995.00000, 3).symbol, ""); - assert.equal(prefix(995.00000, 2).symbol, "k"); - assert.equal(prefix(950.00000, 2).symbol, ""); - assert.equal(prefix(950.00000, 1).symbol, "k"); - assert.equal(prefix(0.0009995, 4).symbol, "µ"); - assert.equal(prefix(0.0009995, 3).symbol, "m"); - assert.equal(prefix(0.0009950, 3).symbol, "µ"); - assert.equal(prefix(0.0009950, 2).symbol, "m"); - assert.equal(prefix(0.0009500, 2).symbol, "µ"); - assert.equal(prefix(0.0009500, 1).symbol, "m"); - }, - "coerces input to a string": function(prefix) { - assert.equal(prefix("0").symbol, ""); - } - } -}); - -suite.export(module); diff --git a/test/format/requote-test.js b/test/format/requote-test.js deleted file mode 100644 index 4c727f98c54c4d..00000000000000 --- a/test/format/requote-test.js +++ /dev/null @@ -1,49 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"); - -var suite = vows.describe("d3.requote"); - -suite.addBatch({ - "requote": { - topic: load("format/requote").expression("d3.requote"), - "quotes backslashes": function(requote) { - assert.equal(requote("\\"), "\\\\"); - }, - "quotes carets": function(requote) { - assert.equal(requote("^"), "\\^"); - }, - "quotes dollar signs": function(requote) { - assert.equal(requote("$"), "\\$"); - }, - "quotes stars": function(requote) { - assert.equal(requote("*"), "\\*"); - }, - "quotes plusses": function(requote) { - assert.equal(requote("+"), "\\+"); - }, - "quotes question marks": function(requote) { - assert.equal(requote("?"), "\\?"); - }, - "quotes periods": function(requote) { - assert.equal(requote("."), "\\."); - }, - "quotes parentheses": function(requote) { - assert.equal(requote("("), "\\("); - assert.equal(requote(")"), "\\)"); - }, - "quotes pipes": function(requote) { - assert.equal(requote("|"), "\\|"); - }, - "quotes curly braces": function(requote) { - assert.equal(requote("{"), "\\{"); - assert.equal(requote("}"), "\\}"); - }, - "quotes square brackets": function(requote) { - assert.equal(requote("["), "\\["); - assert.equal(requote("]"), "\\]"); - } - } -}); - -suite.export(module); diff --git a/test/format/round-test.js b/test/format/round-test.js deleted file mode 100644 index 0f70c48d0a23cf..00000000000000 --- a/test/format/round-test.js +++ /dev/null @@ -1,66 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"); - -var suite = vows.describe("d3.round"); - -suite.addBatch({ - "round": { - topic: load("format/round").expression("d3.round"), - "returns a number": function(round) { - assert.isNumber(round(42)); - }, - "returns zero for zero": function(round) { - assert.equal(round(0), 0); - }, - "ignores degenerate input": function(round) { - assert.isNaN(round(NaN)); - assert.equal(round(Infinity), Infinity); - assert.equal(round(-Infinity), -Infinity); - }, - "returns integers by default": function(round) { - assert.equal(round(10.6), 11); - assert.equal(round(10.4), 10); - assert.equal(round(0.6), 1); - assert.equal(round(0.4), 0); - assert.equal(round(-0.6), -1); - assert.equal(round(-0.4), 0); - assert.equal(round(-10.6), -11); - assert.equal(round(-10.4), -10); - }, - "rounds to the specified decimal place": function(round) { - assert.inDelta(round(10.56, 1), 10.6, 1e-6); - assert.inDelta(round(10.54, 1), 10.5, 1e-6); - assert.inDelta(round(0.56, 1), 0.6, 1e-6); - assert.inDelta(round(0.54, 1), 0.5, 1e-6); - assert.inDelta(round(-0.56, 1), -0.6, 1e-6); - assert.inDelta(round(-0.54, 1), -0.5, 1e-6); - assert.inDelta(round(-10.56, 1), -10.6, 1e-6); - assert.inDelta(round(-10.54, 1), -10.5, 1e-6); - assert.inDelta(round(10.556, 2), 10.56, 1e-6); - assert.inDelta(round(10.554, 2), 10.55, 1e-6); - assert.inDelta(round(0.556, 2), 0.56, 1e-6); - assert.inDelta(round(0.554, 2), 0.55, 1e-6); - assert.inDelta(round(-0.556, 2), -0.56, 1e-6); - assert.inDelta(round(-0.554, 2), -0.55, 1e-6); - assert.inDelta(round(-10.556, 2), -10.56, 1e-6); - assert.inDelta(round(-10.554, 2), -10.55, 1e-6); - }, - "rounds to the specified significant digits": function(round) { - assert.equal(round(123.45, -1), 120); - assert.equal(round(345.67, -1), 350); - assert.equal(round(-123.45, -1), -120); - assert.equal(round(-345.67, -1), -350); - assert.equal(round(123.45, -2), 100); - assert.equal(round(456.78, -2), 500); - assert.equal(round(-123.45, -2), -100); - assert.equal(round(-456.78, -2), -500); - assert.equal(round(123.45, -3), 0); - assert.equal(round(567.89, -3), 1000); - assert.equal(round(-123.45, -3), 0); - assert.equal(round(-567.89, -3), -1000); - } - } -}); - -suite.export(module); diff --git a/test/interpolate/interpolate-string-benchmark b/test/interpolate/interpolate-string-benchmark index e8babf9b943342..7540e30c8851b1 100755 --- a/test/interpolate/interpolate-string-benchmark +++ b/test/interpolate/interpolate-string-benchmark @@ -6,9 +6,6 @@ var n = +process.argv[2], p = +process.argv[3], k = +process.argv[4]; -var formatTime = d3.format(".3s"), - formatNumber = d3.format(",.0f"); - // Returns the time required to construct a string interpolator // for two strings with n numbers, separated by commas, // with probability p that the corresponding numbers in a & b are different. @@ -28,4 +25,4 @@ function observeConstruction(n, p, k) { return sum / k; } -console.log(formatTime(observeConstruction(n, p, k)) + "s\tn=" + formatNumber(n) + "\tp=" + p); +console.log(observeConstruction(n, p, k) + "s\tn=" + n + "\tp=" + p); diff --git a/test/locale/locale-caes-test.js b/test/locale/locale-caes-test.js deleted file mode 100644 index db5901eb44defb..00000000000000 --- a/test/locale/locale-caes-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/ca-ES").expression("d3_locale_caES"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12.345,67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "12.345,67 €"); - }, - "formats currencies with SI-prefix notation and currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "12,35k €"); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "dilluns, 1 de gener de 1990, 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "01/01/1990"); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "dl."); - assert.equal(f(local(1990, 0, 2)), "dt."); - assert.equal(f(local(1990, 0, 3)), "dc."); - assert.equal(f(local(1990, 0, 4)), "dj."); - assert.equal(f(local(1990, 0, 5)), "dv."); - assert.equal(f(local(1990, 0, 6)), "ds."); - assert.equal(f(local(1990, 0, 7)), "dg."); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "dilluns"); - assert.equal(f(local(1990, 0, 2)), "dimarts"); - assert.equal(f(local(1990, 0, 3)), "dimecres"); - assert.equal(f(local(1990, 0, 4)), "dijous"); - assert.equal(f(local(1990, 0, 5)), "divendres"); - assert.equal(f(local(1990, 0, 6)), "dissabte"); - assert.equal(f(local(1990, 0, 7)), "diumenge"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "gen."); - assert.equal(f(local(1990, 1, 1)), "febr."); - assert.equal(f(local(1990, 2, 1)), "març"); - assert.equal(f(local(1990, 3, 1)), "abr."); - assert.equal(f(local(1990, 4, 1)), "maig"); - assert.equal(f(local(1990, 5, 1)), "juny"); - assert.equal(f(local(1990, 6, 1)), "jul."); - assert.equal(f(local(1990, 7, 1)), "ag."); - assert.equal(f(local(1990, 8, 1)), "set."); - assert.equal(f(local(1990, 9, 1)), "oct."); - assert.equal(f(local(1990, 10, 1)), "nov."); - assert.equal(f(local(1990, 11, 1)), "des."); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "gener"); - assert.equal(f(local(1990, 1, 1)), "febrer"); - assert.equal(f(local(1990, 2, 1)), "març"); - assert.equal(f(local(1990, 3, 1)), "abril"); - assert.equal(f(local(1990, 4, 1)), "maig"); - assert.equal(f(local(1990, 5, 1)), "juny"); - assert.equal(f(local(1990, 6, 1)), "juliol"); - assert.equal(f(local(1990, 7, 1)), "agost"); - assert.equal(f(local(1990, 8, 1)), "setembre"); - assert.equal(f(local(1990, 9, 1)), "octubre"); - assert.equal(f(local(1990, 10, 1)), "novembre"); - assert.equal(f(local(1990, 11, 1)), "desembre"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "AM"); - assert.equal(f(local(1990, 0, 1, 13)), "PM"); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("dilluns, 1 de gener de 1990, 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("01/01/1990"), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/locale/locale-fifi-test.js b/test/locale/locale-fifi-test.js deleted file mode 100644 index 5a64ac46d28e19..00000000000000 --- a/test/locale/locale-fifi-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/fi-FI").expression("d3_locale_fiFI"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12\xa0345,67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "12\xa0345,67\xa0€"); - }, - "formats currencies with SI-prefix notation and currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "12,35k\xa0€"); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "maanantai, 1. tammikuuta 1990 klo 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "1.1.1990"); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "Ma"); - assert.equal(f(local(1990, 0, 2)), "Ti"); - assert.equal(f(local(1990, 0, 3)), "Ke"); - assert.equal(f(local(1990, 0, 4)), "To"); - assert.equal(f(local(1990, 0, 5)), "Pe"); - assert.equal(f(local(1990, 0, 6)), "La"); - assert.equal(f(local(1990, 0, 7)), "Su"); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "maanantai"); - assert.equal(f(local(1990, 0, 2)), "tiistai"); - assert.equal(f(local(1990, 0, 3)), "keskiviikko"); - assert.equal(f(local(1990, 0, 4)), "torstai"); - assert.equal(f(local(1990, 0, 5)), "perjantai"); - assert.equal(f(local(1990, 0, 6)), "lauantai"); - assert.equal(f(local(1990, 0, 7)), "sunnuntai"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "Tammi"); - assert.equal(f(local(1990, 1, 1)), "Helmi"); - assert.equal(f(local(1990, 2, 1)), "Maalis"); - assert.equal(f(local(1990, 3, 1)), "Huhti"); - assert.equal(f(local(1990, 4, 1)), "Touko"); - assert.equal(f(local(1990, 5, 1)), "Kesä"); - assert.equal(f(local(1990, 6, 1)), "Heinä"); - assert.equal(f(local(1990, 7, 1)), "Elo"); - assert.equal(f(local(1990, 8, 1)), "Syys"); - assert.equal(f(local(1990, 9, 1)), "Loka"); - assert.equal(f(local(1990, 10, 1)), "Marras"); - assert.equal(f(local(1990, 11, 1)), "Joulu"); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "tammikuu"); - assert.equal(f(local(1990, 1, 1)), "helmikuu"); - assert.equal(f(local(1990, 2, 1)), "maaliskuu"); - assert.equal(f(local(1990, 3, 1)), "huhtikuu"); - assert.equal(f(local(1990, 4, 1)), "toukokuu"); - assert.equal(f(local(1990, 5, 1)), "kesäkuu"); - assert.equal(f(local(1990, 6, 1)), "heinäkuu"); - assert.equal(f(local(1990, 7, 1)), "elokuu"); - assert.equal(f(local(1990, 8, 1)), "syyskuu"); - assert.equal(f(local(1990, 9, 1)), "lokakuu"); - assert.equal(f(local(1990, 10, 1)), "marraskuu"); - assert.equal(f(local(1990, 11, 1)), "joulukuu"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "a.m."); - assert.equal(f(local(1990, 0, 1, 13)), "p.m."); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("maanantai, 1. tammikuuta 1990 klo 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("1.1.1990"), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/locale/locale-huhu-test.js b/test/locale/locale-huhu-test.js deleted file mode 100644 index 80a62192c22546..00000000000000 --- a/test/locale/locale-huhu-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/hu-HU").expression("d3_locale_huHU"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12\xa0345,67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "12\xa0345,67\xa0Ft"); - }, - "formats currencies with currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "12,35k\xa0Ft"); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "1990. január 1., hétfő 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "1990. 01. 01."); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "H"); - assert.equal(f(local(1990, 0, 2)), "K"); - assert.equal(f(local(1990, 0, 3)), "Sze"); - assert.equal(f(local(1990, 0, 4)), "Cs"); - assert.equal(f(local(1990, 0, 5)), "P"); - assert.equal(f(local(1990, 0, 6)), "Szo"); - assert.equal(f(local(1990, 0, 7)), "V"); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "hétfő"); - assert.equal(f(local(1990, 0, 2)), "kedd"); - assert.equal(f(local(1990, 0, 3)), "szerda"); - assert.equal(f(local(1990, 0, 4)), "csütörtök"); - assert.equal(f(local(1990, 0, 5)), "péntek"); - assert.equal(f(local(1990, 0, 6)), "szombat"); - assert.equal(f(local(1990, 0, 7)), "vasárnap"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "jan."); - assert.equal(f(local(1990, 1, 1)), "feb."); - assert.equal(f(local(1990, 2, 1)), "már."); - assert.equal(f(local(1990, 3, 1)), "ápr."); - assert.equal(f(local(1990, 4, 1)), "máj."); - assert.equal(f(local(1990, 5, 1)), "jún."); - assert.equal(f(local(1990, 6, 1)), "júl."); - assert.equal(f(local(1990, 7, 1)), "aug."); - assert.equal(f(local(1990, 8, 1)), "szept."); - assert.equal(f(local(1990, 9, 1)), "okt."); - assert.equal(f(local(1990, 10, 1)), "nov."); - assert.equal(f(local(1990, 11, 1)), "dec."); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "január"); - assert.equal(f(local(1990, 1, 1)), "február"); - assert.equal(f(local(1990, 2, 1)), "március"); - assert.equal(f(local(1990, 3, 1)), "április"); - assert.equal(f(local(1990, 4, 1)), "május"); - assert.equal(f(local(1990, 5, 1)), "június"); - assert.equal(f(local(1990, 6, 1)), "július"); - assert.equal(f(local(1990, 7, 1)), "augusztus"); - assert.equal(f(local(1990, 8, 1)), "szeptember"); - assert.equal(f(local(1990, 9, 1)), "október"); - assert.equal(f(local(1990, 10, 1)), "november"); - assert.equal(f(local(1990, 11, 1)), "december"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "de."); - assert.equal(f(local(1990, 0, 1, 13)), "du."); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("1990. január 1., hétfő 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("1990. 01. 01."), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/locale/locale-ptbr-test.js b/test/locale/locale-ptbr-test.js deleted file mode 100644 index 93a222ccb7a0fc..00000000000000 --- a/test/locale/locale-ptbr-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/pt-BR").expression("d3_locale_ptBR"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12.345,67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "R$12.345,67"); - }, - "formats currencies with SI-prefix notation and currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "R$12,35k"); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "Segunda, 1 de Janeiro de 1990. 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "01/01/1990"); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "Seg"); - assert.equal(f(local(1990, 0, 2)), "Ter"); - assert.equal(f(local(1990, 0, 3)), "Qua"); - assert.equal(f(local(1990, 0, 4)), "Qui"); - assert.equal(f(local(1990, 0, 5)), "Sex"); - assert.equal(f(local(1990, 0, 6)), "Sáb"); - assert.equal(f(local(1990, 0, 7)), "Dom"); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "Segunda"); - assert.equal(f(local(1990, 0, 2)), "Terça"); - assert.equal(f(local(1990, 0, 3)), "Quarta"); - assert.equal(f(local(1990, 0, 4)), "Quinta"); - assert.equal(f(local(1990, 0, 5)), "Sexta"); - assert.equal(f(local(1990, 0, 6)), "Sábado"); - assert.equal(f(local(1990, 0, 7)), "Domingo"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "Jan"); - assert.equal(f(local(1990, 1, 1)), "Fev"); - assert.equal(f(local(1990, 2, 1)), "Mar"); - assert.equal(f(local(1990, 3, 1)), "Abr"); - assert.equal(f(local(1990, 4, 1)), "Mai"); - assert.equal(f(local(1990, 5, 1)), "Jun"); - assert.equal(f(local(1990, 6, 1)), "Jul"); - assert.equal(f(local(1990, 7, 1)), "Ago"); - assert.equal(f(local(1990, 8, 1)), "Set"); - assert.equal(f(local(1990, 9, 1)), "Out"); - assert.equal(f(local(1990, 10, 1)), "Nov"); - assert.equal(f(local(1990, 11, 1)), "Dez"); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "Janeiro"); - assert.equal(f(local(1990, 1, 1)), "Fevereiro"); - assert.equal(f(local(1990, 2, 1)), "Março"); - assert.equal(f(local(1990, 3, 1)), "Abril"); - assert.equal(f(local(1990, 4, 1)), "Maio"); - assert.equal(f(local(1990, 5, 1)), "Junho"); - assert.equal(f(local(1990, 6, 1)), "Julho"); - assert.equal(f(local(1990, 7, 1)), "Agosto"); - assert.equal(f(local(1990, 8, 1)), "Setembro"); - assert.equal(f(local(1990, 9, 1)), "Outubro"); - assert.equal(f(local(1990, 10, 1)), "Novembro"); - assert.equal(f(local(1990, 11, 1)), "Dezembro"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "AM"); - assert.equal(f(local(1990, 0, 1, 13)), "PM"); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("Segunda, 1 de Janeiro de 1990. 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("01/01/1990"), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/locale/locale-test.js b/test/locale/locale-test.js deleted file mode 100644 index e7ed5f38f1caf9..00000000000000 --- a/test/locale/locale-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/ru-RU").expression("d3_locale_ruRU"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12 345,67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "12 345,67 руб."); - }, - "formats currencies with SI-prefix notation and currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "12,35k руб."); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "понедельник, 1 января 1990 г. 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "01.01.1990"); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "пн"); - assert.equal(f(local(1990, 0, 2)), "вт"); - assert.equal(f(local(1990, 0, 3)), "ср"); - assert.equal(f(local(1990, 0, 4)), "чт"); - assert.equal(f(local(1990, 0, 5)), "пт"); - assert.equal(f(local(1990, 0, 6)), "сб"); - assert.equal(f(local(1990, 0, 7)), "вс"); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "понедельник"); - assert.equal(f(local(1990, 0, 2)), "вторник"); - assert.equal(f(local(1990, 0, 3)), "среда"); - assert.equal(f(local(1990, 0, 4)), "четверг"); - assert.equal(f(local(1990, 0, 5)), "пятница"); - assert.equal(f(local(1990, 0, 6)), "суббота"); - assert.equal(f(local(1990, 0, 7)), "воскресенье"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "янв"); - assert.equal(f(local(1990, 1, 1)), "фев"); - assert.equal(f(local(1990, 2, 1)), "мар"); - assert.equal(f(local(1990, 3, 1)), "апр"); - assert.equal(f(local(1990, 4, 1)), "май"); - assert.equal(f(local(1990, 5, 1)), "июн"); - assert.equal(f(local(1990, 6, 1)), "июл"); - assert.equal(f(local(1990, 7, 1)), "авг"); - assert.equal(f(local(1990, 8, 1)), "сен"); - assert.equal(f(local(1990, 9, 1)), "окт"); - assert.equal(f(local(1990, 10, 1)), "ноя"); - assert.equal(f(local(1990, 11, 1)), "дек"); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "января"); - assert.equal(f(local(1990, 1, 1)), "февраля"); - assert.equal(f(local(1990, 2, 1)), "марта"); - assert.equal(f(local(1990, 3, 1)), "апреля"); - assert.equal(f(local(1990, 4, 1)), "мая"); - assert.equal(f(local(1990, 5, 1)), "июня"); - assert.equal(f(local(1990, 6, 1)), "июля"); - assert.equal(f(local(1990, 7, 1)), "августа"); - assert.equal(f(local(1990, 8, 1)), "сентября"); - assert.equal(f(local(1990, 9, 1)), "октября"); - assert.equal(f(local(1990, 10, 1)), "ноября"); - assert.equal(f(local(1990, 11, 1)), "декабря"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "AM"); - assert.equal(f(local(1990, 0, 1, 13)), "PM"); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("понедельник, 1 января 1990 г. 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("01.01.1990"), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/locale/locale-zhcn-test.js b/test/locale/locale-zhcn-test.js deleted file mode 100644 index 256f1efef749f4..00000000000000 --- a/test/locale/locale-zhcn-test.js +++ /dev/null @@ -1,120 +0,0 @@ -var vows = require("vows"), - load = require("../load"), - assert = require("../assert"), - time = require("../time/time"), - local = time.local; - -var suite = vows.describe("d3.locale"); - -suite.addBatch({ - "locale": { - topic: load("locale/zh-CN").expression("d3_locale_zhCN"), - - "numberFormat": { - topic: function(locale) { - return locale.numberFormat; - }, - "formats numbers": function(format) { - var f = format(",.2f"); - assert.equal(f(12345.67), "12,345.67"); - }, - "formats currencies": function(format) { - var f = format("$,.2f"); - assert.equal(f(12345.67), "¥12,345.67"); - }, - "formats currencies with SI-prefix notation and currency suffix": function(format) { - var f = format("$,.4s"); - assert.equal(f(12345.67), "¥12.35k"); - } - }, - - "timeFormat": { - topic: function(locale) { - return locale.timeFormat; - }, - - "format": { - "formats locale date and time": function(format) { - var f = format("%c"); - assert.equal(f(local(1990, 0, 1)), "1990年1月1日 星期一 00:00:00"); - }, - "formats locale date": function(format) { - var f = format("%x"); - assert.equal(f(local(1990, 0, 1)), "1990年1月1日"); - }, - "formats locale time": function(format) { - var f = format("%X"); - assert.equal(f(local(1990, 0, 1)), "00:00:00"); - }, - "formats abbreviated weekday": function(format) { - var f = format("%a"); - assert.equal(f(local(1990, 0, 1)), "周一"); - assert.equal(f(local(1990, 0, 2)), "周二"); - assert.equal(f(local(1990, 0, 3)), "周三"); - assert.equal(f(local(1990, 0, 4)), "周四"); - assert.equal(f(local(1990, 0, 5)), "周五"); - assert.equal(f(local(1990, 0, 6)), "周六"); - assert.equal(f(local(1990, 0, 7)), "周日"); - }, - "formats weekday": function(format) { - var f = format("%A"); - assert.equal(f(local(1990, 0, 1)), "星期一"); - assert.equal(f(local(1990, 0, 2)), "星期二"); - assert.equal(f(local(1990, 0, 3)), "星期三"); - assert.equal(f(local(1990, 0, 4)), "星期四"); - assert.equal(f(local(1990, 0, 5)), "星期五"); - assert.equal(f(local(1990, 0, 6)), "星期六"); - assert.equal(f(local(1990, 0, 7)), "星期日"); - }, - "formats abbreviated month": function(format) { - var f = format("%b"); - assert.equal(f(local(1990, 0, 1)), "一月"); - assert.equal(f(local(1990, 1, 1)), "二月"); - assert.equal(f(local(1990, 2, 1)), "三月"); - assert.equal(f(local(1990, 3, 1)), "四月"); - assert.equal(f(local(1990, 4, 1)), "五月"); - assert.equal(f(local(1990, 5, 1)), "六月"); - assert.equal(f(local(1990, 6, 1)), "七月"); - assert.equal(f(local(1990, 7, 1)), "八月"); - assert.equal(f(local(1990, 8, 1)), "九月"); - assert.equal(f(local(1990, 9, 1)), "十月"); - assert.equal(f(local(1990, 10, 1)), "十一月"); - assert.equal(f(local(1990, 11, 1)), "十二月"); - }, - "formats month": function(format) { - var f = format("%B"); - assert.equal(f(local(1990, 0, 1)), "一月"); - assert.equal(f(local(1990, 1, 1)), "二月"); - assert.equal(f(local(1990, 2, 1)), "三月"); - assert.equal(f(local(1990, 3, 1)), "四月"); - assert.equal(f(local(1990, 4, 1)), "五月"); - assert.equal(f(local(1990, 5, 1)), "六月"); - assert.equal(f(local(1990, 6, 1)), "七月"); - assert.equal(f(local(1990, 7, 1)), "八月"); - assert.equal(f(local(1990, 8, 1)), "九月"); - assert.equal(f(local(1990, 9, 1)), "十月"); - assert.equal(f(local(1990, 10, 1)), "十一月"); - assert.equal(f(local(1990, 11, 1)), "十二月"); - }, - "formats AM or PM": function(format) { - var f = format("%p"); - assert.equal(f(local(1990, 0, 1, 0)), "上午"); - assert.equal(f(local(1990, 0, 1, 13)), "下午"); - } - }, - - "parse": { - "parses locale date and time": function(format) { - var p = format("%c").parse; - assert.deepEqual(p("1990年1月1日 星期一 00:00:00"), local(1990, 0, 1)); - }, - "parses locale date": function(format) { - var p = format("%x").parse; - assert.deepEqual(p("1990年1月1日"), local(1990, 0, 1)); - } - } - } - } -}); - -suite.export(module); diff --git a/test/math/transform-rotate-test.html b/test/math/transform-rotate-test.html index bf5eb55951fb64..f30cbe9b439513 100644 --- a/test/math/transform-rotate-test.html +++ b/test/math/transform-rotate-test.html @@ -44,21 +44,19 @@