Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expose d3.layout.hierarchy.sort.

Also, add nifty transitions to the sunburst example.
  • Loading branch information...
commit 52bf6c978a1388d4f2fd3f4e0bad0fd51e86bcd6 1 parent 2443389
@mbostock authored
View
2  d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.6.1"}; // semver
+(function(){d3 = {version: "1.6+1.1"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
View
16 d3.layout.js
@@ -350,7 +350,7 @@ d3.layout.partition = function() {
node.dy = dy;
if (children) {
var i = -1,
- n = (children = children.slice().sort(d3_layout_hierarchySort)).length,
+ n = children.length,
c,
d;
dx /= node.value;
@@ -378,6 +378,7 @@ d3.layout.partition = function() {
return nodes;
}
+ partition.sort = d3.rebind(partition, hierarchy.sort);
partition.children = d3.rebind(partition, hierarchy.children);
partition.value = d3.rebind(partition, hierarchy.value);
@@ -647,7 +648,8 @@ function d3_layout_stackSum(p, d) {
return p + d.y;
}
d3.layout.hierarchy = function() {
- var children = d3_layout_hierarchyChildren,
+ var sort = d3_layout_hierarchySort,
+ children = d3_layout_hierarchyChildren,
value = d3_layout_hierarchyValue;
// Recursively compute the node depth and value.
@@ -670,6 +672,7 @@ d3.layout.hierarchy = function() {
d.parent = node;
}
}
+ if (sort) c.sort(sort);
node.value = v;
} else {
node.value = value.call(hierarchy, data, depth);
@@ -683,6 +686,12 @@ d3.layout.hierarchy = function() {
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;
@@ -732,7 +741,7 @@ d3.layout.treemap = function() {
if (!node.children) return;
var rect = {x: node.x, y: node.y, dx: node.dx, dy: node.dy},
row = [],
- children = node.children.slice().sort(d3_layout_hierarchySort),
+ children = node.children.slice(), // copy-on-write
child,
best = Infinity, // the best row score so far
score, // the current row score
@@ -825,6 +834,7 @@ d3.layout.treemap = function() {
return nodes;
}
+ treemap.sort = d3.rebind(treemap, hierarchy.sort);
treemap.children = d3.rebind(treemap, hierarchy.children);
treemap.value = d3.rebind(treemap, hierarchy.value);
View
32 d3.layout.min.js
@@ -1,16 +1,16 @@
-(function(){function B(e){return e.reduce(C,0)}function D(e){for(var j=1,l=0,i=e[0].y,m,c=e.length;j<c;++j)if((m=e[j].y)>i){l=j;i=m}return l}function C(e,j){return e+j.y}function E(e){return e.children}function F(e){return e.value}function z(e,j){return j.value-e.value}d3.layout={};d3.layout.chord=function(){function e(){var f={},n=[],r=d3.range(g),q=[],o,p,u,s,t;i=[];m=[];o=0;for(s=-1;++s<g;){p=0;for(t=-1;++t<g;)p+=c[s][t];n.push(p);q.push(d3.range(g));o+=p}k&&r.sort(function(x,v){return k(n[x],
-n[v])});a&&q.forEach(function(x,v){x.sort(function(G,H){return a(c[v][G],c[v][H])})});o=(2*Math.PI-h*g)/o;p=0;for(s=-1;++s<g;){u=p;for(t=-1;++t<g;){var w=r[s],y=q[s][t],A=c[w][y];f[w+"-"+y]={index:w,subindex:y,startAngle:p,endAngle:p+=A*o,value:A}}m.push({index:w,startAngle:u,endAngle:p,value:(p-u)/o});p+=h}for(s=-1;++s<g;)for(t=s-1;++t<g;){r=f[s+"-"+t];q=f[t+"-"+s];if(r.value||q.value)i.push({source:r,target:q})}b&&j()}function j(){i.sort(function(f,n){f=Math.min(f.source.value,f.target.value);n=
-Math.min(n.source.value,n.target.value);return b(f,n)})}var l={},i,m,c,g,h=0,k,a,b;l.matrix=function(f){if(!arguments.length)return c;g=(c=f)&&c.length;i=m=null;return l};l.padding=function(f){if(!arguments.length)return h;h=f;i=m=null;return l};l.sortGroups=function(f){if(!arguments.length)return k;k=f;i=m=null;return l};l.sortSubgroups=function(f){if(!arguments.length)return a;a=f;i=null;return l};l.sortChords=function(f){if(!arguments.length)return b;b=f;i&&j();return l};l.chords=function(){i||
-e();return i};l.groups=function(){m||e();return m};return l};d3.layout.force=function(){function e(){var a=k.length,b,f,n,r,q,o,p;for(b=0;b<a;++b){f=k[b];n=f.source;r=f.target;o=r.x-n.x;p=r.y-n.y;if(q=Math.sqrt(o*o+p*p)){q=m/(f.distance*f.distance)*(q-c*f.distance)/q;o*=q;p*=q;if(!r.fixed){r.x-=o;r.y-=p}if(!n.fixed){n.x+=o;n.y+=p}}}l.tick.dispatch({type:"tick"});return(m*=0.99)<0.0050}var j={},l=d3.dispatch("tick"),i=[1,1],m=0.5,c=30,g,h,k;j.on=function(a,b){l[a].add(b);return j};j.nodes=function(a){if(!arguments.length)return g;
-g=a;return j};j.links=function(a){if(!arguments.length)return h;h=a;return j};j.size=function(a){if(!arguments.length)return i;i=a;return j};j.distance=function(a){if(!arguments.length)return c;c=a;return j};j.start=function(){var a,b,f,n=g.length;f=h.length;var r=i[0],q=i[1],o=[];for(a=0;a<n;++a){b=g[a];b.x=b.x||Math.random()*r;b.y=b.y||Math.random()*q;b.fixed=0;o[a]=[];for(b=0;b<n;++b)o[a][b]=Infinity;o[a][a]=0}for(a=0;a<f;++a){b=h[a];o[b.source][b.target]=1;o[b.target][b.source]=1;b.source=g[b.source];
-b.target=g[b.target]}for(f=0;f<n;++f)for(a=0;a<n;++a)for(b=0;b<n;++b)o[a][b]=Math.min(o[a][b],o[a][f]+o[f][b]);k=[];for(a=0;a<n;++a)for(b=a+1;b<n;++b)k.push({source:g[a],target:g[b],distance:o[a][b]*o[a][b]});k.sort(function(p,u){return p.distance-u.distance});d3.timer(e);return j};j.resume=function(){m=0.1;d3.timer(e);return j};j.stop=function(){m=0;return j};j.drag=function(){function a(){if(b){var n=d3.svg.mouse(f);b.x=n[0];b.y=n[1];j.resume()}}var b,f;this.on("mouseover",function(n){n.fixed=true}).on("mouseout",
-function(n){if(n!=b)n.fixed=false}).on("mousedown",function(n){(b=n).fixed=true;f=this;d3.event.preventDefault()});d3.select(window).on("mousemove",a).on("mouseup",function(){if(b){a();b.fixed=false;b=f=null}});return j};return j};d3.layout.partition=function(){function e(c,g,h,k){var a=c.children;c.x=g;c.y=c.depth*k;c.dx=h;c.dy=k;if(a){var b=-1,f=(a=a.slice().sort(z)).length,n;for(h/=c.value;++b<f;){e(n=a[b],g,c=n.value*h,k);g+=c}}}function j(c){c=c.children;var g=0;if(c)for(var h=-1,k=c.length;++h<
-k;)g=Math.max(g,j(c[h]));return 1+g}function l(c,g){var h=i.call(this,c,g);e(h[0],0,m[0],m[1]/j(h[0]));return h}var i=d3.layout.hierarchy(),m=[1,1];l.children=d3.rebind(l,i.children);l.value=d3.rebind(l,i.value);l.size=function(c){if(!arguments.length)return m;m=c;return l};return l};d3.layout.pie=function(){function e(c){var g=+(typeof i=="function"?i.apply(this,arguments):i),h=(typeof m=="function"?m.apply(this,arguments):m)-i,k=d3.range(c.length);l!=null&&k.sort(function(f,n){return l(c[f],c[n])});
-var a=c.map(j);h/=a.reduce(function(f,n){return f+n},0);var b=k.map(function(f){return{value:d=a[f],startAngle:g,endAngle:g+=d*h}});return c.map(function(f,n){return b[k[n]]})}var j=Number,l=null,i=0,m=2*Math.PI;e.value=function(c){if(!arguments.length)return j;j=c;return e};e.sort=function(c){if(!arguments.length)return l;l=c;return e};e.startAngle=function(c){if(!arguments.length)return i;i=c;return e};e.endAngle=function(c){if(!arguments.length)return m;m=c;return e};return e};d3.layout.stack=
-function(){function e(i){var m=i.length,c=i[0].length,g,h,k,a=I[j](i);J[l](i,a);for(h=0;h<c;++h){g=1;for(k=i[a[0]][h].y0;g<m;++g)i[a[g]][h].y0=k+=i[a[g-1]][h].y}return i}var j="default",l="zero";e.order=function(i){if(!arguments.length)return j;j=i;return e};e.offset=function(i){if(!arguments.length)return l;l=i;return e};return e};var I={"inside-out":function(e){var j=e.length,l,i=e.map(D),m=e.map(B),c=d3.range(j).sort(function(b,f){return i[b]-i[f]}),g=0,h=0,k=[],a=[];for(e=0;e<j;e++){l=c[e];if(g<
-h){g+=m[l];k.push(l)}else{h+=m[l];a.push(l)}}return a.reverse().concat(k)},reverse:function(e){return d3.range(e.length).reverse()},"default":function(e){return d3.range(e.length)}},J={silhouette:function(e,j){var l=e.length,i=e[0].length,m=[],c=0,g,h,k;for(h=0;h<i;++h){for(k=g=0;g<l;g++)k+=e[g][h].y;if(k>c)c=k;m.push(k)}h=0;for(g=j[0];h<i;++h)e[g][h].y0=(c-m[h])/2},wiggle:function(e,j){var l=e.length,i=e[0],m=i.length,c,g,h,k,a,b=j[0],f,n,r,q,o,p;e[b][0].y0=o=p=0;for(g=1;g<m;++g){for(f=c=0;c<l;++c)f+=
-e[c][g].y;n=c=0;for(q=i[g].x-i[g-1].x;c<l;++c){h=0;k=j[c];for(r=(e[k][g].y-e[k][g-1].y)/(2*q);h<c;++h)r+=(e[a=j[h]][g].y-e[a][g-1].y)/q;n+=r*e[k][g].y}e[b][g].y0=o-=f?n/f*q:0;if(o<p)p=o}for(g=0;g<m;++g)e[b][g].y0-=p},zero:function(e,j){for(var l=0,i=e[0].length,m=j[0];l<i;++l)e[m][l].y0=0}};d3.layout.hierarchy=function(){function e(m,c,g){var h=l.call(j,m,c),k={depth:c,data:m};g.push(k);if(h){m=-1;var a=h.length,b=k.children=[],f=0;for(c+=1;++m<a;){d=e(h[m],c,g);if(d.value>0){b.push(d);f+=d.value;
-d.parent=k}}k.value=f}else k.value=i.call(j,m,c);return k}function j(m){var c=[];e(m,0,c);return c}var l=E,i=F;j.children=function(m){if(!arguments.length)return l;l=m;return j};j.value=function(m){if(!arguments.length)return i;i=m;return j};return j};d3.layout.treemap=function(){function e(h,k){var a=h.children;h.area=h.value*k;if(a)for(var b=-1,f=a.length;++b<f;)e(a[b],k)}function j(h){if(h.children){var k={x:h.x,y:h.y,dx:h.dx,dy:h.dy},a=[],b=h.children.slice().sort(z),f,n=Infinity,r=Math.min(k.dx,
-k.dy);for(a.area=0;(f=b.length)>0;){a.push(f=b[f-1]);a.area+=f.area;f=r;for(var q=a.area,o=void 0,p=0,u=Infinity,s=-1,t=a.length;++s<t;){o=a[s].area;if(o<u)u=o;if(o>p)p=o}q*=q;f*=f;if((f=Math.max(f*p/q,q/(f*u)))<=n){b.pop();n=f}else{a.area-=a.pop().area;l(a,r,k,false);r=Math.min(k.dx,k.dy);a.length=a.area=0;n=Infinity}}if(a.length){l(a,r,k,true);a.length=a.area=0}h.children.forEach(j)}}function l(h,k,a,b){var f=-1,n=h.length,r=a.x,q=a.y,o=k?c(h.area/k):0,p;if(k==a.dx){if(b||o>a.dy)o=a.dy;for(;++f<
-n;){p=h[f];p.x=r;p.y=q;p.dy=o;r+=p.dx=c(p.area/o)}p.dx+=a.x+a.dx-r;a.y+=o;a.dy-=o}else{if(b||o>a.dx)o=a.dx;for(;++f<n;){p=h[f];p.x=r;p.y=q;p.dx=o;q+=p.dy=c(p.area/o)}p.dy+=a.y+a.dy-q;a.x+=o;a.dx-=o}}function i(h,k){var a=m.call(this,h,k),b=a[0];b.x=0;b.y=0;b.dx=g[0];b.dy=g[1];e(b,g[0]*g[1]/b.value);j(b);return a}var m=d3.layout.hierarchy(),c=Math.round,g=[1,1];i.children=d3.rebind(i,m.children);i.value=d3.rebind(i,m.value);i.size=function(h){if(!arguments.length)return g;g=h;return i};i.round=function(h){if(!arguments.length)return c!=
-Number;c=h?Math.round:Number;return i};return i}})();
+(function(){function A(f){return f.reduce(B,0)}function C(f){for(var j=1,k=0,i=f[0].y,o,b=f.length;j<b;++j)if((o=f[j].y)>i){k=j;i=o}return k}function B(f,j){return f+j.y}function D(f){return f.children}function E(f){return f.value}function F(f,j){return j.value-f.value}d3.layout={};d3.layout.chord=function(){function f(){var g={},m=[],r=d3.range(e),q=[],n,p,u,s,t;i=[];o=[];n=0;for(s=-1;++s<e;){p=0;for(t=-1;++t<e;)p+=b[s][t];m.push(p);q.push(d3.range(e));n+=p}l&&r.sort(function(x,v){return l(m[x],
+m[v])});a&&q.forEach(function(x,v){x.sort(function(G,H){return a(b[v][G],b[v][H])})});n=(2*Math.PI-h*e)/n;p=0;for(s=-1;++s<e;){u=p;for(t=-1;++t<e;){var w=r[s],y=q[s][t],z=b[w][y];g[w+"-"+y]={index:w,subindex:y,startAngle:p,endAngle:p+=z*n,value:z}}o.push({index:w,startAngle:u,endAngle:p,value:(p-u)/n});p+=h}for(s=-1;++s<e;)for(t=s-1;++t<e;){r=g[s+"-"+t];q=g[t+"-"+s];if(r.value||q.value)i.push({source:r,target:q})}c&&j()}function j(){i.sort(function(g,m){g=Math.min(g.source.value,g.target.value);m=
+Math.min(m.source.value,m.target.value);return c(g,m)})}var k={},i,o,b,e,h=0,l,a,c;k.matrix=function(g){if(!arguments.length)return b;e=(b=g)&&b.length;i=o=null;return k};k.padding=function(g){if(!arguments.length)return h;h=g;i=o=null;return k};k.sortGroups=function(g){if(!arguments.length)return l;l=g;i=o=null;return k};k.sortSubgroups=function(g){if(!arguments.length)return a;a=g;i=null;return k};k.sortChords=function(g){if(!arguments.length)return c;c=g;i&&j();return k};k.chords=function(){i||
+f();return i};k.groups=function(){o||f();return o};return k};d3.layout.force=function(){function f(){var a=l.length,c,g,m,r,q,n,p;for(c=0;c<a;++c){g=l[c];m=g.source;r=g.target;n=r.x-m.x;p=r.y-m.y;if(q=Math.sqrt(n*n+p*p)){q=o/(g.distance*g.distance)*(q-b*g.distance)/q;n*=q;p*=q;if(!r.fixed){r.x-=n;r.y-=p}if(!m.fixed){m.x+=n;m.y+=p}}}k.tick.dispatch({type:"tick"});return(o*=0.99)<0.0050}var j={},k=d3.dispatch("tick"),i=[1,1],o=0.5,b=30,e,h,l;j.on=function(a,c){k[a].add(c);return j};j.nodes=function(a){if(!arguments.length)return e;
+e=a;return j};j.links=function(a){if(!arguments.length)return h;h=a;return j};j.size=function(a){if(!arguments.length)return i;i=a;return j};j.distance=function(a){if(!arguments.length)return b;b=a;return j};j.start=function(){var a,c,g,m=e.length;g=h.length;var r=i[0],q=i[1],n=[];for(a=0;a<m;++a){c=e[a];c.x=c.x||Math.random()*r;c.y=c.y||Math.random()*q;c.fixed=0;n[a]=[];for(c=0;c<m;++c)n[a][c]=Infinity;n[a][a]=0}for(a=0;a<g;++a){c=h[a];n[c.source][c.target]=1;n[c.target][c.source]=1;c.source=e[c.source];
+c.target=e[c.target]}for(g=0;g<m;++g)for(a=0;a<m;++a)for(c=0;c<m;++c)n[a][c]=Math.min(n[a][c],n[a][g]+n[g][c]);l=[];for(a=0;a<m;++a)for(c=a+1;c<m;++c)l.push({source:e[a],target:e[c],distance:n[a][c]*n[a][c]});l.sort(function(p,u){return p.distance-u.distance});d3.timer(f);return j};j.resume=function(){o=0.1;d3.timer(f);return j};j.stop=function(){o=0;return j};j.drag=function(){function a(){if(c){var m=d3.svg.mouse(g);c.x=m[0];c.y=m[1];j.resume()}}var c,g;this.on("mouseover",function(m){m.fixed=true}).on("mouseout",
+function(m){if(m!=c)m.fixed=false}).on("mousedown",function(m){(c=m).fixed=true;g=this;d3.event.preventDefault()});d3.select(window).on("mousemove",a).on("mouseup",function(){if(c){a();c.fixed=false;c=g=null}});return j};return j};d3.layout.partition=function(){function f(b,e,h,l){var a=b.children;b.x=e;b.y=b.depth*l;b.dx=h;b.dy=l;if(a){var c=-1,g=a.length,m;for(h/=b.value;++c<g;){f(m=a[c],e,b=m.value*h,l);e+=b}}}function j(b){b=b.children;var e=0;if(b)for(var h=-1,l=b.length;++h<l;)e=Math.max(e,
+j(b[h]));return 1+e}function k(b,e){var h=i.call(this,b,e);f(h[0],0,o[0],o[1]/j(h[0]));return h}var i=d3.layout.hierarchy(),o=[1,1];k.sort=d3.rebind(k,i.sort);k.children=d3.rebind(k,i.children);k.value=d3.rebind(k,i.value);k.size=function(b){if(!arguments.length)return o;o=b;return k};return k};d3.layout.pie=function(){function f(b){var e=+(typeof i=="function"?i.apply(this,arguments):i),h=(typeof o=="function"?o.apply(this,arguments):o)-i,l=d3.range(b.length);k!=null&&l.sort(function(g,m){return k(b[g],
+b[m])});var a=b.map(j);h/=a.reduce(function(g,m){return g+m},0);var c=l.map(function(g){return{value:d=a[g],startAngle:e,endAngle:e+=d*h}});return b.map(function(g,m){return c[l[m]]})}var j=Number,k=null,i=0,o=2*Math.PI;f.value=function(b){if(!arguments.length)return j;j=b;return f};f.sort=function(b){if(!arguments.length)return k;k=b;return f};f.startAngle=function(b){if(!arguments.length)return i;i=b;return f};f.endAngle=function(b){if(!arguments.length)return o;o=b;return f};return f};d3.layout.stack=
+function(){function f(i){var o=i.length,b=i[0].length,e,h,l,a=I[j](i);J[k](i,a);for(h=0;h<b;++h){e=1;for(l=i[a[0]][h].y0;e<o;++e)i[a[e]][h].y0=l+=i[a[e-1]][h].y}return i}var j="default",k="zero";f.order=function(i){if(!arguments.length)return j;j=i;return f};f.offset=function(i){if(!arguments.length)return k;k=i;return f};return f};var I={"inside-out":function(f){var j=f.length,k,i=f.map(C),o=f.map(A),b=d3.range(j).sort(function(c,g){return i[c]-i[g]}),e=0,h=0,l=[],a=[];for(f=0;f<j;f++){k=b[f];if(e<
+h){e+=o[k];l.push(k)}else{h+=o[k];a.push(k)}}return a.reverse().concat(l)},reverse:function(f){return d3.range(f.length).reverse()},"default":function(f){return d3.range(f.length)}},J={silhouette:function(f,j){var k=f.length,i=f[0].length,o=[],b=0,e,h,l;for(h=0;h<i;++h){for(l=e=0;e<k;e++)l+=f[e][h].y;if(l>b)b=l;o.push(l)}h=0;for(e=j[0];h<i;++h)f[e][h].y0=(b-o[h])/2},wiggle:function(f,j){var k=f.length,i=f[0],o=i.length,b,e,h,l,a,c=j[0],g,m,r,q,n,p;f[c][0].y0=n=p=0;for(e=1;e<o;++e){for(g=b=0;b<k;++b)g+=
+f[b][e].y;m=b=0;for(q=i[e].x-i[e-1].x;b<k;++b){h=0;l=j[b];for(r=(f[l][e].y-f[l][e-1].y)/(2*q);h<b;++h)r+=(f[a=j[h]][e].y-f[a][e-1].y)/q;m+=r*f[l][e].y}f[c][e].y0=n-=g?m/g*q:0;if(n<p)p=n}for(e=0;e<o;++e)f[c][e].y0-=p},zero:function(f,j){for(var k=0,i=f[0].length,o=j[0];k<i;++k)f[o][k].y0=0}};d3.layout.hierarchy=function(){function f(b,e,h){var l=i.call(j,b,e),a={depth:e,data:b};h.push(a);if(l){b=-1;var c=l.length,g=a.children=[],m=0;for(e+=1;++b<c;){d=f(l[b],e,h);if(d.value>0){g.push(d);m+=d.value;
+d.parent=a}}k&&g.sort(k);a.value=m}else a.value=o.call(j,b,e);return a}function j(b){var e=[];f(b,0,e);return e}var k=F,i=D,o=E;j.sort=function(b){if(!arguments.length)return k;k=b;return j};j.children=function(b){if(!arguments.length)return i;i=b;return j};j.value=function(b){if(!arguments.length)return o;o=b;return j};return j};d3.layout.treemap=function(){function f(h,l){var a=h.children;h.area=h.value*l;if(a)for(var c=-1,g=a.length;++c<g;)f(a[c],l)}function j(h){if(h.children){var l={x:h.x,y:h.y,
+dx:h.dx,dy:h.dy},a=[],c=h.children.slice(),g,m=Infinity,r=Math.min(l.dx,l.dy);for(a.area=0;(g=c.length)>0;){a.push(g=c[g-1]);a.area+=g.area;g=r;for(var q=a.area,n=void 0,p=0,u=Infinity,s=-1,t=a.length;++s<t;){n=a[s].area;if(n<u)u=n;if(n>p)p=n}q*=q;g*=g;if((g=Math.max(g*p/q,q/(g*u)))<=m){c.pop();m=g}else{a.area-=a.pop().area;k(a,r,l,false);r=Math.min(l.dx,l.dy);a.length=a.area=0;m=Infinity}}if(a.length){k(a,r,l,true);a.length=a.area=0}h.children.forEach(j)}}function k(h,l,a,c){var g=-1,m=h.length,
+r=a.x,q=a.y,n=l?b(h.area/l):0,p;if(l==a.dx){if(c||n>a.dy)n=a.dy;for(;++g<m;){p=h[g];p.x=r;p.y=q;p.dy=n;r+=p.dx=b(p.area/n)}p.dx+=a.x+a.dx-r;a.y+=n;a.dy-=n}else{if(c||n>a.dx)n=a.dx;for(;++g<m;){p=h[g];p.x=r;p.y=q;p.dx=n;q+=p.dy=b(p.area/n)}p.dy+=a.y+a.dy-q;a.x+=n;a.dx-=n}}function i(h,l){var a=o.call(this,h,l),c=a[0];c.x=0;c.y=0;c.dx=e[0];c.dy=e[1];f(c,e[0]*e[1]/c.value);j(c);return a}var o=d3.layout.hierarchy(),b=Math.round,e=[1,1];i.sort=d3.rebind(i,o.sort);i.children=d3.rebind(i,o.children);i.value=
+d3.rebind(i,o.value);i.size=function(h){if(!arguments.length)return e;e=h;return i};i.round=function(h){if(!arguments.length)return b!=Number;b=h?Math.round:Number;return i};return i}})();
View
2  d3.min.js
@@ -25,7 +25,7 @@ a)})}function ia(a,b){var d=Date.now(),g=false,e=d+b,c=E;if(isFinite(b)){for(;c;
a)}}function Ma(a){return function(b){return-Math.pow(-b,a)}}function Na(a){return a.innerRadius}function Oa(a){return a.outerRadius}function ma(a){return a.startAngle}function na(a){return a.endAngle}function Z(a,b,d,g){var e=[],c=-1,f=b.length,h=typeof d=="function",i=typeof g=="function",k;if(h&&i)for(;++c<f;)e.push([d.call(a,k=b[c],c),g.call(a,k,c)]);else if(h)for(;++c<f;)e.push([d.call(a,b[c],c),g]);else if(i)for(;++c<f;)e.push([d,g.call(a,b[c],c)]);else for(;++c<f;)e.push([d,g]);return e}function oa(a){return a[0]}
function pa(a){return a[1]}function G(a){var b=[],d=0,g=a.length,e=a[0];for(b.push(e[0],",",e[1]);++d<g;)b.push("L",(e=a[d])[0],",",e[1]);return b.join("")}function qa(a,b){if(b.length<1||a.length!=b.length&&a.length!=b.length+2)return G(a);var d=a.length!=b.length,g="",e=a[0],c=a[1],f=b[0],h=f,i=1;if(d){g+="Q"+(c[0]-f[0]*2/3)+","+(c[1]-f[1]*2/3)+","+c[0]+","+c[1];e=a[1];i=2}if(b.length>1){h=b[1];c=a[i];i++;g+="C"+(e[0]+f[0])+","+(e[1]+f[1])+","+(c[0]-h[0])+","+(c[1]-h[1])+","+c[0]+","+c[1];for(e=
2;e<b.length;e++,i++){c=a[i];h=b[e];g+="S"+(c[0]-h[0])+","+(c[1]-h[1])+","+c[0]+","+c[1]}}if(d){d=a[i];g+="Q"+(c[0]+h[0]*2/3)+","+(c[1]+h[1]*2/3)+","+d[0]+","+d[1]}return g}function ra(a,b){for(var d=[],g=(1-b)/2,e=a[0],c=a[1],f=a[2],h=2,i=a.length;++h<i;){d.push([g*(f[0]-e[0]),g*(f[1]-e[1])]);e=c;c=f;f=a[h]}d.push([g*(f[0]-e[0]),g*(f[1]-e[1])]);return d}function B(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]}function K(a,b,d){a.push("C",B(sa,b),",",B(sa,d),",",B(ta,b),",",B(ta,d),",",B(L,
-b),",",B(L,d))}function Pa(){return 0}function Qa(a){return a.source}function Ra(a){return a.target}function Sa(a){return a.radius}function Ta(){return 64}function Ua(){return"circle"}d3={version:"1.6.1"};if(!Date.now)Date.now=function(){return+new Date};if(!Object.create)Object.create=function(a){function b(){}b.prototype=a;return new b};var M=function(a){return Array.prototype.slice.call(a)};try{M(document.documentElement.childNodes)}catch(gb){M=wa}d3.rebind=function(a,b){return function(){var d=
+b),",",B(L,d))}function Pa(){return 0}function Qa(a){return a.source}function Ra(a){return a.target}function Sa(a){return a.radius}function Ta(){return 64}function Ua(){return"circle"}d3={version:"1.6+1.1"};if(!Date.now)Date.now=function(){return+new Date};if(!Object.create)Object.create=function(a){function b(){}b.prototype=a;return new b};var M=function(a){return Array.prototype.slice.call(a)};try{M(document.documentElement.childNodes)}catch(gb){M=wa}d3.rebind=function(a,b){return function(){var d=
b.apply(a,arguments);return arguments.length?a:d}};d3.ascending=function(a,b){return a<b?-1:a>b?1:0};d3.descending=function(a,b){return b<a?-1:b>a?1:0};d3.min=function(a,b){var d=0,g=a.length,e=a[0],c;if(arguments.length==1)for(;++d<g;){if(e>(c=a[d]))e=c}else for(e=b(a[0]);++d<g;)if(e>(c=b(a[d])))e=c;return e};d3.max=function(a,b){var d=0,g=a.length,e=a[0],c;if(arguments.length==1)for(;++d<g;){if(e<(c=a[d]))e=c}else for(e=b(e);++d<g;)if(e<(c=b(a[d])))e=c;return e};d3.nest=function(){function a(h,
i){if(i>=g.length)return f?f.call(d,h):c?h.sort(c):h;for(var k=-1,j=h.length,o=g[i++],p,m,n={};++k<j;)if((p=o(m=h[k]))in n)n[p].push(m);else n[p]=[m];for(p in n)n[p]=a(n[p],i);return n}function b(h,i){if(i>=g.length)return h;var k=[],j=e[i++],o;for(o in h)k.push({key:o,values:b(h[o],i)});j&&k.sort(function(p,m){return j(p.key,m.key)});return k}var d={},g=[],e=[],c,f;d.map=function(h){return a(h,0)};d.entries=function(h){return b(a(h,0),0)};d.key=function(h){g.push(h);return d};d.sortKeys=function(h){e[g.length-
1]=h;return d};d.sortValues=function(h){c=h;return d};d.rollup=function(h){f=h;return d};return d};d3.keys=function(a){var b=[],d;for(d in a)b.push(d);return b};d3.values=function(a){var b=[],d;for(d in a)b.push(a[d]);return b};d3.entries=function(a){var b=[],d;for(d in a)b.push({key:d,value:a[d]});return b};d3.merge=function(a){return Array.prototype.concat.apply([],a)};d3.split=function(a,b){var d=[],g=[],e,c=-1,f=a.length;if(arguments.length<2)b=xa;for(;++c<f;)if(b.call(g,e=a[c],c))g=[];else{g.length||
View
3  examples/stream/button.css → examples/button.css
@@ -2,7 +2,8 @@ button {
font: 14px Helvetica Neue;
background-color: #222;
background-image: -moz-linear-gradient(top, rgba(255,255,255,.25), rgba(255,255,255,.11));
- background-image: -webkit-linear-gradient(top, rgba(255,255,255,.25), rgba(255,255,255,.11));
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgba(255,255,255,.25)),color-stop(1, rgba(255,255,255,.11)));
+ background-image: -webkit-linear-gradient(rgba(255,255,255,.25), rgba(255,255,255,.11));
color: #fff;
text-rendering: optimizeLegibility;
text-shadow: 0 -1px 1px #222;
View
82 examples/partition/partition-sunburst.html
@@ -5,40 +5,98 @@
<title>Partition - Icicle</title>
<script type="text/javascript" src="../../d3.js"></script>
<script type="text/javascript" src="../../d3.layout.js"></script>
+ <link type="text/css" rel="stylesheet" href="../button.css"/>
</head>
<body>
- <div id="chart"></div>
+ <div id="chart">
+ <button id="size" class="first">
+ Size
+ </button
+ ><button id="count" class="active last">
+ Count
+ </button><p>
+ </div>
<script type="text/javascript">
-var r = 960 / 2,
+var w = 960,
+ h = 700,
+ r = Math.min(w, h) / 2,
color = d3.scale.category20c();
var vis = d3.select("#chart").append("svg:svg")
- .attr("width", r * 2)
- .attr("height", r * 2)
+ .attr("width", w)
+ .attr("height", h)
.append("svg:g")
- .attr("transform", "translate(" + r + "," + r + ")");
+ .attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
var partition = d3.layout.partition()
+ .sort(null)
.size([2 * Math.PI, r * r])
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; })
- .value(function(d) { return d.value; });
+ .value(function(d) { return 1; });
+
+var arc = d3.svg.arc()
+ .startAngle(function(d) { return d.x; })
+ .endAngle(function(d) { return d.x + d.dx; })
+ .innerRadius(function(d) { return Math.sqrt(d.y); })
+ .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
d3.json("../treemap/flare.json", function(json) {
vis.data(d3.entries(json)).selectAll("path")
.data(partition)
.enter().append("svg:path")
- .filter(function(d) { return d.depth; }) // hide inner ring
- .attr("d", d3.svg.arc()
- .startAngle(function(d) { return d.x; })
- .endAngle(function(d) { return d.x + d.dx; })
- .innerRadius(function(d) { return Math.sqrt(d.y); })
- .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); }))
+ .attr("display", function(d) { return d.depth ? null : "none"; }) // hide inner ring
+ .attr("d", arc)
.attr("stroke", "#fff")
.attr("fill", function(d) { return color((d.children ? d : d.parent).data.key); })
.attr("fill-rule", "evenodd");
+
+ d3.select("#size").on("click", function() {
+ vis.selectAll("path")
+ .data(repartition(function(d) { return d.value; }))
+ .transition()
+ .duration(1500)
+ .attrTween("d", arcTween);
+
+ d3.select("#size").classed("active", true);
+ d3.select("#count").classed("active", false);
+ });
+
+ d3.select("#count").on("click", function() {
+ vis.selectAll("path")
+ .data(repartition(function(d) { return 1; }))
+ .transition()
+ .duration(1500)
+ .attrTween("d", arcTween);
+
+ d3.select("#size").classed("active", false);
+ d3.select("#count").classed("active", true);
+ });
});
+// Compute a new partition, stashing the old value for transition.
+function repartition(value) {
+ return function(d) {
+ var olds = partition(d),
+ news = partition.value(value)(d);
+ news.forEach(function(d, i) {
+ d.prev = olds[i];
+ });
+ return news;
+ };
+}
+
+// Interpolate the arcs in data space.
+function arcTween(a) {
+ var i = d3.interpolate(
+ {x: a.prev.x, dx: a.prev.dx},
+ {x: a.x, dx: a.dx, y: a.y, dy: a.dy}
+ );
+ return function(t) {
+ return arc(i(t));
+ };
+}
+
</script>
</body>
</html>
View
2  examples/stream/stack.html
@@ -5,7 +5,7 @@
<script type="text/javascript" src="../../d3.js"></script>
<script type="text/javascript" src="../../d3.layout.js"></script>
<script type="text/javascript" src="stream_layers.js"></script>
- <link type="text/css" rel="stylesheet" href="button.css"/>
+ <link type="text/css" rel="stylesheet" href="../button.css"/>
<link type="text/css" rel="stylesheet" href="stack.css"/>
</head>
<body>
View
2  examples/stream/stream.html
@@ -5,7 +5,7 @@
<script type="text/javascript" src="../../d3.js"></script>
<script type="text/javascript" src="../../d3.layout.js"></script>
<script type="text/javascript" src="stream_layers.js"></script>
- <link type="text/css" rel="stylesheet" href="button.css"/>
+ <link type="text/css" rel="stylesheet" href="../button.css"/>
<link type="text/css" rel="stylesheet" href="stream.css"/>
</head>
<body>
View
2  examples/treemap/treemap.html
@@ -5,7 +5,7 @@
<title>Treemap</title>
<script type="text/javascript" src="../../d3.js"></script>
<script type="text/javascript" src="../../d3.layout.js"></script>
- <link type="text/css" rel="stylesheet" href="treemap.css"></script>
+ <link type="text/css" rel="stylesheet" href="treemap.css"/>
</head>
<body>
<div id="chart"></div>
View
2  src/core/core.js
@@ -1 +1 @@
-d3 = {version: "1.6.1"}; // semver
+d3 = {version: "1.6+1.1"}; // semver
View
10 src/layout/hierarchy.js
@@ -1,5 +1,6 @@
d3.layout.hierarchy = function() {
- var children = d3_layout_hierarchyChildren,
+ var sort = d3_layout_hierarchySort,
+ children = d3_layout_hierarchyChildren,
value = d3_layout_hierarchyValue;
// Recursively compute the node depth and value.
@@ -22,6 +23,7 @@ d3.layout.hierarchy = function() {
d.parent = node;
}
}
+ if (sort) c.sort(sort);
node.value = v;
} else {
node.value = value.call(hierarchy, data, depth);
@@ -35,6 +37,12 @@ d3.layout.hierarchy = function() {
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;
View
3  src/layout/partition.js
@@ -10,7 +10,7 @@ d3.layout.partition = function() {
node.dy = dy;
if (children) {
var i = -1,
- n = (children = children.slice().sort(d3_layout_hierarchySort)).length,
+ n = children.length,
c,
d;
dx /= node.value;
@@ -38,6 +38,7 @@ d3.layout.partition = function() {
return nodes;
}
+ partition.sort = d3.rebind(partition, hierarchy.sort);
partition.children = d3.rebind(partition, hierarchy.children);
partition.value = d3.rebind(partition, hierarchy.value);
View
3  src/layout/treemap.js
@@ -21,7 +21,7 @@ d3.layout.treemap = function() {
if (!node.children) return;
var rect = {x: node.x, y: node.y, dx: node.dx, dy: node.dy},
row = [],
- children = node.children.slice().sort(d3_layout_hierarchySort),
+ children = node.children.slice(), // copy-on-write
child,
best = Infinity, // the best row score so far
score, // the current row score
@@ -114,6 +114,7 @@ d3.layout.treemap = function() {
return nodes;
}
+ treemap.sort = d3.rebind(treemap, hierarchy.sort);
treemap.children = d3.rebind(treemap, hierarchy.children);
treemap.value = d3.rebind(treemap, hierarchy.value);
Please sign in to comment.
Something went wrong with that request. Please try again.