//>>built
define("dojox/treemap/_utils",["dojo/_base/array"],function(n){var p={group:function(c,g,d){var e={children:[]},k=function(b,a){b.__treeValue||(b.__treeValue=0);b.__treeValue+=d(a);return b};n.forEach(c,function(b){var a=e;n.forEach(g,function(c,d){var f=c(b),e=p.find(a.children,function(a){return a.__treeName==f});e||a.children.push(e={__treeName:f,__treeID:f+Math.random(),children:[]});e=k(e,b);d!=g.length-1?a=e:e.children.push(b)});a=k(a,b)});return e},find:function(c,g){for(var d=c.length,e=0;e<
d;++e)if(g.call(null,c[e]))return c[e];return null},solve:function(c,g,d,e,k){var b=p.initElements(c,e);e=b.total;var b=b.elements,a=e;if(0==e){if(0==b.length)return{items:c,rects:[],total:0};n.forEach(b,function(a){a.size=a.sizeTmp=100});e=100*b.length}b.sort(function(a,b){return b.size-a.size});p._compute(g,d,b,e);b.sort(function(a,b){return a.index-b.index});c={};c.elements=b;c.size=a;rects=n.map(b,function(a){return{x:k?g-a.x-a.width:a.x,y:a.y,w:a.width,h:a.height}});c.rectangles=rects;return c},
initElements:function(c,g){var d=0;return{elements:n.map(c,function(c,k){var b=null!=g?g(c):0;if(0>b)throw Error("item size dimension must be positive");d+=b;return{index:k,size:b,sizeTmp:b}}),total:d}},_compute:function(c,g,d,e){var k=c*g/e/100;n.forEach(d,function(a){a.sizeTmp*=k});for(var b=e=0,a=2147483647,f,l=0,h=0,m=c,r=g,q=m>r;b!=d.length;)if(f=p._trySolution(d,e,b,q,m,r),f>a||1>f){m=f=0;for(a=e;a<b;a++)d[a].x=l+f,d[a].y=h+m,q?m+=d[a].height:f+=d[a].width;q?l+=d[e].width:h+=d[e].height;m=c-
l;r=g-h;q=m>r;b=e=b;a=2147483647}else{for(a=e;a<=b;a++)d[a].width=d[a].widthTmp,d[a].height=d[a].heightTmp;a=f;b++}g=c=0;for(a=e;a<b;a++)d[a].x=l+c,d[a].y=h+g,q?g+=d[a].height:c+=d[a].width},_trySolution:function(c,g,d,e,k,b){for(var a=0,f=0,l=f=0,h=g;h<=d;h++)a+=c[h].sizeTmp;e?0==b?f=l=0:(f=a/b*100,l=b):0==k?f=l=0:(l=a/k*100,f=k);for(h=g;h<=d;h++)e?(c[h].widthTmp=f,c[h].heightTmp=0==a?0:l*c[h].sizeTmp/a):(c[h].widthTmp=0==a?0:f*c[h].sizeTmp/a,c[h].heightTmp=l);f=Math.max(c[d].heightTmp/c[d].widthTmp,
c[d].widthTmp/c[d].heightTmp);return void 0==f?1:f}};return p});