All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.jQuery.treemap-min.js Maven / Gradle / Ivy

(function(a){a.fn.treemap=function(c,f,e){e=a.extend({labelCell:0,dataCell:1,colorCell:2,headHeight:20,borderWidth:1,borderColor:"#000",getColor:b.getColor,sort:true,nested:false,legend:false},e);var d=e.target;return this.pushStack(a.map(this,function(h){var i;if(!e.getData){if(!a.nodeName(h,"table")){return}i=b.getDataFromTable(h,e)}else{i=e.getData(h)}i=i.concat();if(a.fn.treemap.caller!=b.layoutRow){e.minColorValue=Number.POSITIVE_INFINITY;e.maxColorValue=Number.NEGATIVE_INFINITY;if(!e.colorDiscreteVal){e.colorDiscreteVal={num:0}}b.normalizeValues(i,e);e.colorDiscrete=e.minColorValue==Number.POSITIVE_INFINITY;e.rangeColorValue=e.maxColorValue-e.minColorValue}if(e.sort){i.sort(function(k,j){var m=j[1],l=k[1];m=m.constructor==Array?b.getValue(m):m;l=l.constructor==Array?b.getValue(l):l;return m-l})}e.target=d||h;e.numSquare=0;b.render(i,f,c,e);if(a.fn.treemap.caller!=b.layoutRow&&e.legend){jQuery(e.target).append(b.legend(f,e))}if(e.target==h&&a.nodeName(h,"table")){var g=jQuery(h).find(">").insertBefore(h);a(h).remove();h=g.get()}return h}))};a.fn.treemapClone=function(){return this.pushStack(jQuery.map(this,function(c){return c.outerHTML?jQuery(c.outerHTML)[0]:c.cloneNode(true)}))};a.fn.treemapAppend=function(f){var e=this[0];for(var d=0,c=f.length;de.maxColorValue){e.maxColorValue=c}if(!e.colorDiscreteVal[c]){e.colorDiscreteVal[c]=e.colorDiscreteVal.num++}}}},getDataFromTable:function(d,c){var e=[];if(c.labelCell==undefined){c.labelCell=c.dataCell}a("tbody tr",d).each(function(){var f=a(">",this);var g=[f.eq(c.labelCell).html(),f.eq(c.dataCell).html(),f.eq(c.colorCell).html()];e.push(g)});return e},emptyView:a("
").addClass("treemapView"),render:function(g,f,c,d){d.height=f;d.width=c;var e=b.calculateArea(g);d.viewAreaCoeff=c*f/e;d.view=b.emptyView.clone().css({width:c,height:f});d.content=[];b.squarify(g,[],f,true,d);d.view.treemapAppend(d.content);a(d.target).empty().treemapAppend(d.view)},squarify:function(e,k,j,d,m){if(j<=0){return}var h=k,l,i,f;do{k=h;l=b.calculateArea(k);if(e.length==0){return b.layoutRow(k,j,d,l,m,true)}f=e.shift();h=k.concat();h.push(f);i=l+(f[1].constructor==Array?b.getValue(f[1]):f[1])}while(b.worst(k,j,l,m.viewAreaCoeff)>=b.worst(h,j,i,m.viewAreaCoeff));var g=b.layoutRow(k,j,d,l,m);e.unshift(f);if(!g){g=b.layoutRow([["",l]],j,d,l,m,true)}var c;if(d){m.width-=g;c=m.width}else{m.height-=g;c=m.height}b.squarify(e,[],c,!d,m)},worst:function(j,i,k,f){var g=j.length;if(!g){return Number.POSITIVE_INFINITY}var e=i*i,h=k*k*f;var d=(e*(j[0][1].constructor==Array?b.getValue(j[0][1]):j[0][1]))/h;var c=h/(e*(j[g-1][1].constructor==Array?b.getValue(j[g-1][1]):j[g-1][1]));return Math.max(d,c)},emptyCell:a("
").addClass("treemapCell").css({"float":"left",overflow:"hidden"}),emptySquare:a("
").addClass("treemapSquare").css("float","left"),layoutRow:function(p,u,f,y,j,t){var A=b.emptySquare.treemapClone();var m,H=y/u;if(f){m=t?j.width:Math.min(Math.round(H*j.viewAreaCoeff),j.width);A.css({width:m,height:u}).addClass("treemapV")}else{m=t?j.height:Math.min(Math.round(H*j.viewAreaCoeff),j.height);A.css({height:m,width:u}).addClass("treemapH")}var v=p.length-1,d=0,I=j.borderWidth,o=j.borderColor,D=I*2,k=[];for(var G=0;G<=v;G++){var E=p[G],x=E[1].constructor==Array,l=[],K=x?b.getValue(E[1]):E[1];var c=b.emptyCell.treemapClone();if(!x){c.append(E[0])}var F=G==v;var g=m,q=F?u-d:Math.round(K/H);if(q<=0){break}d+=q;var J={};if(I&&m>D&&q>D){if(jQuery.boxModel){g-=I*(2-(j.numSquare>=2||!j.numSquare&&j.nested?1:0)-(t&&j.nested?1:0));q-=I*(2-(!F||j.nested?1:0)-(j.numSquare>=1&&!G?1:0))}J.border=I+"px solid "+o;if(!F||j.nested){J["border"+(f?"Bottom":"Right")]="none"}if(j.numSquare>=2||!j.numSquare&&j.nested){J["border"+(f?"Left":"Top")]="none"}if(j.numSquare>=1&&!G){J["border"+(f?"Top":"Left")]="none"}if(t&&j.nested){J["border"+(f?"Right":"Bottom")]="none"}}var z=f?q:g,C=f?g:q;J.height=z+"px";J.width=C+"px";if(x){if(j.headHeight){l=a("
").css({width:C,height:j.headHeight,overflow:"hidden"}).html(E[0]);if(f){z=q-=j.headHeight}else{z=g-=j.headHeight}}if(z>0){var r={};for(var e in j){r[e]=j[e]}r.target=null;r=jQuery.extend(r,{getData:function(){return E[1].concat()},nested:true});c.treemap(C,z,r)}c.prepend(l)}else{if(E[2]){J.backgroundColor=j.getColor(E[2],j)}}if(E[3]){c.attr({id:E[3]})}var B=c[0].style;for(var e in J){B[e]=J[e]}k.push(c[0])}j.content.push(A.treemapAppend(k)[0]);j.numSquare++;return m},calculateArea:function(g){if(g.total){return g.total}var d=0,f=g.length;for(var c=0;c").css({position:"absolute",left:25,width:200}),legend:function(g,e){var c=a("
").css({position:"relative","float":"left",height:g-2});var j=a("
").css({width:20,height:g-2,border:"1px solid"});e.view.css({"float":"left",marginRight:20});if(e.colorDiscrete){a.each(e.colorDiscreteVal,function(l,q){if(l!="num"){l=e.descriptionCallback?e.descriptionCallback(l):l;var h=Math.round(q*g/e.colorDiscreteVal.num);var o=a("
").css({height:20,width:20,backgroundColor:b.getColor(l,e),position:"absolute",bottom:h});var p=b.emptyLegendDescr.clone().text(l).css("bottom",h);c.append(o).append(p)}})}else{for(var f=g-1;f>1;f--){var d=a("
").height(1).css("backgroundColor",b.getColorCode(f/g));j.append(d)}c.append(j);for(var f=0;f<10;f++){var m=f*e.rangeColorValue/10+e.minColorValue;m=e.descriptionCallback?e.descriptionCallback(m):m;var k=b.emptyLegendDescr.clone().text(m.toString()).css("bottom",Math.round(f*g/10));c.append(k)}}return c}}})(jQuery);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy