www-thermferm/jqwidgets/jqxtreemap.js

changeset 511
2d1d43c3a2c2
parent 373
f6850e0b5d35
child 617
b216f9d4b917
equal deleted inserted replaced
510:2da3d3340403 511:2d1d43c3a2c2
1 /* 1 /*
2 jQWidgets v3.8.0 (2015-Apr) 2 jQWidgets v4.5.2 (2017-May)
3 Copyright (c) 2011-2015 jQWidgets. 3 Copyright (c) 2011-2017 jQWidgets.
4 License: http://jqwidgets.com/license/ 4 License: http://jqwidgets.com/license/
5 */ 5 */
6 !function(a){function b(a,b,c,d,e,f,g,h){this.label=a,this.value=b,this.parent=c,this.children=d,this.area=e||null,this.color=f,this.data=g,this.record=h}a.jqx.jqxWidget("jqxTreeMap","",{});var c={};c.default=function(){function a(b,c,d,e){this.height=e,this.width=d,this.xoffset=b,this.yoffset=c,this.shortestEdge=function(){return Math.min(this.height,this.width)},this.getCoordinates=function(a){var b=[],c=this.xoffset,d=this.yoffset,e=j(a)/this.height,f=j(a)/this.width;if(this.width>=this.height)for(var g=0;g<a.length;g+=1)b.push([c,d,c+e,d+a[g]/e]),d+=a[g]/e;else for(var g=0;g<a.length;g+=1)b.push([c,d,c+a[g]/f,d+f]),c+=a[g]/f;return b},this.cutArea=function(b){var c;if(this.width>=this.height){var d=b/this.height,e=this.width-d;c=new a(this.xoffset+d,this.yoffset,e,this.height)}else{var f=b/this.width,g=this.height-f;c=new a(this.xoffset,this.yoffset+f,this.width,g)}return c}}function b(a,b){for(var c=[],d=j(a),e=b/d,f=0;f<a.length;f+=1)c[f]=a[f]*e;return c}function c(a,b,e,f,g){f="undefined"==typeof f?0:f,g="undefined"==typeof g?0:g;var h,j=[],l=[];if(i(a[0])){for(var m=0;m<a.length;m+=1)j[m]=k(a[m]);h=d(j,b,e,f,g);for(var m=0;m<a.length;m+=1)l.push(c(a[m],h[m][2]-h[m][0],h[m][3]-h[m][1],h[m][0],h[m][1]))}else l=d(a,b,e,f,g);return l}function d(c,d,g,h,i){h="undefined"==typeof h?0:h,i="undefined"==typeof i?0:i;var j=f(b(c,d*g),[],new a(h,i,d,g),[]);return e(j)}function e(a){for(var b=[],c=0;c<a.length;c+=1)for(var d=0;d<a[c].length;d+=1)b.push(a[c][d]);return b}function f(a,b,c,d){var e,h,i;return 0===a.length?void d.push(c.getCoordinates(b)):(e=c.shortestEdge(),h=a[0],g(b,h,e)?(b.push(h),f(a.slice(1),b,c,d)):(i=c.cutArea(j(b),d),d.push(c.getCoordinates(b)),f(a,[],i,d)),d)}function g(a,b,c){var d;if(0===a.length)return!0;d=a.slice(),d.push(b);var e=h(a,c),f=h(d,c);return e>=f}function h(a,b){var c=Math.min.apply(Math,a),d=Math.max.apply(Math,a),e=j(a);return Math.max(Math.pow(b,2)*d/Math.pow(e,2),Math.pow(e,2)/(Math.pow(b,2)*c))}function i(a){return a&&a.constructor===Array}function j(a){for(var b=0,c=0;c<a.length;c+=1)b+=a[c];return b}function k(a){var b=0;if(i(a[0]))for(var c=0;c<a.length;c+=1)b+=k(a[c]);else b=j(a);return b}return c}();var d={HORIZONTAL:0,VERTICAL:1,BOTH:2};a.extend(a.jqx._jqxTreeMap.prototype,{defineInstance:function(){var b={width:600,height:600,renderCallbacks:{},legendScaleCallback:function(a){return a},hoverEnabled:!1,selectionEnabled:!0,singleSelection:!0,showLegend:!0,legendLabel:"Legend",headerHeight:25,colorRange:100,layout:"default",source:[],displayMember:null,valueMember:null,colorMode:"parent",baseColor:"#C2EEFF",legendPosition:{x:0,y:0},colorRanges:[{color:"#aa9988",min:0,max:10},{color:"#ccbbcc",min:11,max:50},{color:"#000",min:50,max:100}],_root:[]};return this===a.jqx._jqxTreeMap.prototype?b:(a.extend(!0,this,b),b)},createInstance:function(){this.render()},render:function(){this.host.addClass(this.toThemeProperty("jqx-widget")),this._destroy(),this._root=new b(void 0,0,null,[],this.host);var d=function(a,b){for(var d,e={},f=null,g=0;g<a.length;g+=1)if(a[g].items){f=!0;break}var h=new Array;if(f){var i=function(a,b){for(var c=0;c<a.length;c+=1){if(a[c].parent=b,a[c].data||(a[c].data=a[c].value),null==a[c].value&&(a[c].value=0),isNaN(parseFloat(a[c].value))){for(var d=a[c].value.toString(),e="",f=0;f<d.length;f++){var g=d.substring(f,f+1);null==g.match(/^[0-9]+$/)&&"."!=g||(e+=g)}a[c].value=new Number(e)}else a[c].value=parseFloat(a[c].value);h.push(a[c]),a[c].items&&i(a[c].items,a[c].label)}};i(a,null),a=h}for(var g=0;g<a.length;g+=1)d=a[g],d.value&&null!=d.parent&&(e[d.parent]||(e[d.parent]=0),e[d.parent]+=d.value);for(var g=0;g<a.length;g+=1)d=a[g],void 0!==e[d.label]&&(d.value=e[d.label]);b._buildTree(a,b._root),b._dataList=b._buildList(),b._setStyles();var j=c.default;"simple"===b.layout&&(j=c.simple),b._render(b._root,j),b._renderLegend()};return a.jqx.dataAdapter&&null!=this.source&&this.source._source?void this.dataBind(this.source,d):(d(this.source,this),void this._trigger("bindingComplete"))},dataBind:function(b,c){this.records=new Array;var d=!!b._source,e=new a.jqx.dataAdapter(b,{autoBind:!1});d&&(e=b,b=b._source);var f=function(a){void 0!=b.type&&(e._options.type=b.type),void 0!=b.formatdata&&(e._options.formatData=b.formatdata),void 0!=b.contenttype&&(e._options.contentType=b.contenttype),void 0!=b.async&&(e._options.async=b.async)},g=function(a,b){a.records=e.records;for(var d=new Array,f=0;f<a.records.length;f++){var g=a.records[f];a.displayMember&&(g.label=g[a.displayMember]),a.valueMember&&(g.value=g[a.valueMember]),g.record=g,d.push(g)}a._trigger("bindingComplete"),c(d,a)};f(this);var h=this;switch(b.datatype){case"local":case"array":default:null!=b.localdata&&(e.unbindBindingUpdate(this.element.id),e.dataBind(),g(this),e.bindBindingUpdate(this.element.id,function(a){g(h,a)}));break;case"json":case"jsonp":case"xml":case"xhtml":case"script":case"text":case"csv":case"tab":if(null!=b.localdata)return e.unbindBindingUpdate(this.element.id),e.dataBind(),g(this),void e.bindBindingUpdate(this.element.id,function(){g(h)});var i={};e._options.data?a.extend(e._options.data,i):(b.data&&a.extend(i,b.data),e._options.data=i);var j=function(){g(h)};e.unbindDownloadComplete(h.element.id),e.bindDownloadComplete(h.element.id,j),e.dataBind()}},_destroy:function(){this.host.children().remove()},destroy:function(){this.host.remove()},refresh:function(a){a||this._refresh()},_refresh:function(){this.render()},_setStyles:function(){this.host.css({position:"relative",width:this.width,height:this.height});var b=!1;null!=this.width&&this.width.toString().indexOf("%")!=-1&&(b=!0),null!=this.height&&this.height.toString().indexOf("%")!=-1&&(b=!0);var c=this;a.jqx.utilities.resize(this.host,function(){c.resizeTimer&&clearTimeout(c.resizeTimer),c.resizeTimer=setTimeout(function(){c.performLayout()},50)})},resize:function(a,b){this.width=a,this.height=b,this.performLayout()},performLayout:function(){var a=c.default;this.clearSelection(),this._layout(this._root,a)},_getValues:function(a){for(var b=[],c=0;c<a.length;c+=1)b.push(a[c].value);return b},_isColor:function(a){if(!a)return!1;var b=this._colorEvaluator;return!(!b._isRgb(a)&&!b._isHex(a))},_colorEvaluator:{_toRgb:function(a){var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return b?{r:parseInt(b[1],16),g:parseInt(b[2],16),b:parseInt(b[3],16)}:null},_toHex:function(a){var b=a.r.toString(16),c=a.g.toString(16),d=a.b.toString(16);return b=1===b.length?"0"+b:b,c=1===c.length?"0"+c:c,d=1===d.length?"0"+d:d,"#"+b+c+d},_isRgb:function(a){return/(rgb|rgba)\s*\(\s*\d+\s*(,\s*\d+\s*){2}(,\d+\.\d+)?\)(;?)/i.test(a)},_isHex:function(a){return/^(#([0-9A-F]{3})([0-9A-F]{3})?)$/i.test(a)},getColorByValue:function(a,b,c){var d,e,f,g,h,b,i=this._colorEvaluator;i._isRgb(c)&&(c=i._toHex(c)),c=i._toRgb(c),f=b.length,d=-(1/0);for(var j=0;j<f;j+=1)d<b[j].value&&(d=b[j].value);return e=a/d,g=Math.round(e*this.colorRange),h=i._toHex({r:Math.max(c.r-g,0),g:Math.max(c.g-g,0),b:Math.max(c.b-g,0)})},parent:function(a){var b=a.parent.color,c=this._colorEvaluator;return a.parent?(b||(b=this.baseColor),b=c.getColorByValue.call(this,a.value,a.parent.children,b),a.color=b,b):"#fff"},autoColors:function(a){var b=this.baseColor,c=this._colorEvaluator;return b=c.getColorByValue.call(this,a.value,this._dataList,b),a.color=b,b},rangeColors:function(a){for(var b,c=a.value,d=0;d<this.colorRanges.length;d+=1)if(b=this.colorRanges[d],b.min<c&&b.max>=c)return b.color;return"#fff"}},_getColor:function(a){var b=a.color,c=this.colorMode;if(this._isColor(b))return b;if("function"==typeof this._colorEvaluator[c])return this._colorEvaluator[c].call(this,a);throw"Invalid colorMode"},_renderRect:function(b,c){var d=a("<div/>"),e=b[2]-b[0],f=b[3]-b[1],g=this._getColor(c);d.css({position:"absolute",left:b[0]-1,top:b[1]-1,width:e,height:f,backgroundColor:g}),d.addClass(this.toThemeProperty("jqx-treemap-rectangle"));var h=this._colorEvaluator,i={data:c.data,label:c.label,value:c.value,parent:c.parent,record:c.record,color:g,rgb:h._toRgb(g)};if(c.parent==this._root&&(i.parent=null),"function"==typeof this.renderCallbacks["*"]){var j=this.renderCallbacks["*"](d,i);if(void 0!==j)return d}if("function"==typeof this.renderCallbacks[c.label])this.renderCallbacks[c.label](d,i);else{var e=d.width()-2;d.html('<span style="max-width:'+e+'px;" class="jqx-treemap-label">'+c.label+"</span>")}return d},_centerLabel:function(a,b){var c=a[0].firstChild;c.style.position="absolute",b!==d.HORIZONTAL&&b!==d.BOTH||(c.style.left=(a[0].offsetWidth-c.offsetWidth)/2+"px"),b!==d.VERTICAL&&b!==d.BOTH||(c.style.top=(a[0].offsetHeight-c.offsetHeight)/2+"px")},_trigger:function(b,c){var d=a.Event(b);return d.args=c,this.host.trigger(d)},_addHandlers:function(b,c){var d=this;b.on("mouseenter",function(a){d.hoverEnabled&&(d.host.find(".jqx-treemap-rectangle").removeClass("jqx-treemap-rectangle-hover"),b.addClass(d.toThemeProperty("jqx-treemap-rectangle-hover"))),d._trigger("mouseenterSector",c)}),b.on("mouseleave",function(a){d.hoverEnabled&&b.removeClass("jqx-treemap-rectangle-hover"),d._trigger("mouseleaveSector",c)}),b.on("click",function(c){if(d.selectionEnabled){var e=a.data(this,"jqx-treemap-selected")||!1;d.singleSelection&&d.host.find(".jqx-treemap-rectangle-hover").each(function(b,c){a.data(c,"jqx-treemap-selected",!1),a(c).removeClass("jqx-treemap-rectangle-hover")}),e?(b.removeClass("jqx-treemap-rectangle-hover"),e=!1):(b.addClass(d.toThemeProperty("jqx-treemap-rectangle-hover")),e=!0),a.data(this,"jqx-treemap-selected",e),c.stopImmediatePropagation()}})},clearSelection:function(){this.host.find(".jqx-treemap-rectangle-hover").removeClass(this.toThemeProperty("jqx-treemap-rectangle-hover")),a.data(this,"jqx-treemap-selected",!1)},_layoutArea:function(a,b){a.children.length&&a.children.length>0?(this._centerLabel(b,d.HORIZONTAL),b.addClass(this.toThemeProperty("jqx-treemap-rectangle-parent"))):this._centerLabel(b,d.BOTH)},_render:function(a,b){if(a.children.length){var c=0;a.value&&(c=this.headerHeight);for(var d,e,f=this._getValues(a.children),g=(a.area.offset(),b(f,a.area.width(),a.area.height()-c,0,c)),h=0;h<a.children.length;h+=1)d=a.children[h],e=this._renderRect(g[h],d),d.area=e,a.area.append(e),this._addHandlers(e,{label:d.label,value:d.value,color:d.color,sector:d.area,data:d.data}),this._layoutArea(d,e),this._render(d,b)}},_layout:function(b,c){if(b.children.length){var d=0;b.value&&(d=this.headerHeight);for(var e=this._getValues(b.children),f=(b.area.offset(),c(e,b.area.width(),b.area.height()-d,0,d)),g=0;g<b.children.length;g+=1){var h=b.children[g];this._layoutRect(f[g],h),this._layoutArea(h,h.area),this._layout(h,c)}this.showLegend&&(a(".jqx-treemap-legend").remove(),this._renderLegend())}},_layoutRect:function(a,b){var c=b.area,d=a[2]-a[0],e=a[3]-a[1];c.css({left:a[0]-1,top:a[1]-1,width:d,height:e});var f=this._colorEvaluator,g=this._getColor(b),h={data:b.data,label:b.label,value:b.value,parent:b.parent,record:b.record,color:g,rgb:f._toRgb(g)};if(b.parent==this._root&&(h.parent=null),"function"==typeof this.renderCallbacks["*"]){var i=this.renderCallbacks["*"](c,h);if(void 0!==i)return c}if("function"==typeof this.renderCallbacks[b.label])this.renderCallbacks[b.label](c,h);else{var d=c.width()-2;c.find(".jqx-treemap-label:first").css("max-width",d)}},_getBoundValues:function(){var a,b=this._root,c=[],d={},e={};for(d.value=b.value||1/0,e.value=b.value||-(1/0),c.push(b);c.length;){a=c.pop(),d.value>a.value&&(d=a),e.value<a.value&&(e=a);for(var f=0;f<a.children.length;f+=1)c.push(a.children[f])}return[d,e]},_getAutocolorRanges:function(){for(var a,b=this._getBoundValues(),c=5,d=b[1].value,e=b[0].value,f=(d-e)/c,g=[],h=e;h<d;h+=f)a=Math.round(h),g.push({min:a,max:h+f,color:this._colorEvaluator.getColorByValue.call(this,a,this._dataList,this.baseColor)});return g},_renderLegend:function(){if(/autoColors|rangeColors/.test(this.colorMode)&&this.showLegend){var a=this.colorRanges;"autoColors"===this.colorMode&&(a=this._getAutocolorRanges());var b=this._renderColorLegend(a);this._renderLegendLabel(b)}},_renderLegendLabel:function(b){var c=a('<tr><td colspan="'+b.find("td").length/2+'"/></tr>'),d=a('<div class="'+this.toThemeProperty("jqx-treemap-legend-label")+'" />');d.text(this.legendLabel),c.children().append(d),b.prepend(c)},_renderColorLegend:function(b){var c,d,e=a('<div class="'+this.toThemeProperty("jqx-treemap-legend")+'"/>'),f=function(a){return a};"function"==typeof this.legendScaleCallback&&(f=this.legendScaleCallback);var g=a('<table class="'+this.toThemeProperty("jqx-treemap-legend-table")+'"/>');e.append(g),g.append("<tr/>"),e.append("<div/>"),this.host.append(e),c=a(e.find("tr")[0]),d=a(e.find("div")[0]),d.addClass(this.toThemeProperty("jqx-treemap-legend-values"));var h=function(a,b){try{if(a.min<b.min)return-1;if(a.min>b.min)return 1}catch(a){}return 0};b.sort(h);for(var i=Math.round(e.width()/b.length),j=-2,k=0,l=0;l<b.length;l+=1){var m=a('<td class="'+this.toThemeProperty("jqx-treemap-legend-color")+'"/>');if(m.css("backgroundColor",b[l].color),c.append(m),0===l){var n=a('<span class="'+this.toThemeProperty("jqx-treemap-legend-max-value")+" "+this.toThemeProperty("jqx-treemap-legend-value")+'"/>');n.text(f(b[l].min)),d.append(n),g.css("margin-left",n.width()/2),j+=n.width()/2,k=j}var n=a('<span class="'+this.toThemeProperty("jqx-treemap-legend-max-value")+" "+this.toThemeProperty("jqx-treemap-legend-value")+'"/>');j+=i,n.text(f(b[l].max)),d.append(n),l==b.length-1&&(k+=n.width()/2,e.css("padding-right",k+5),j-=2),j-=n.width()/2,n.css("left",j),j+=n.width()/2}return e.css({position:"absolute",left:this.legendPosition.x,bottom:this.legendPosition.y,visibility:this.showLegend?"visible":"hidden"}),e},_buildTree:function(a,c){var d,e,f=null,g=[];for(g.push(c);g.length;){f=g.pop();for(var h=0;h<a.length;h+=1)if(e=a[h],e.parent===f.label||!e.parent&&!f.label){var i=f;d=new b(e.label,parseFloat(e.value,10),i,[],null,e.color,e.data,e.record),f.children.push(d),g.push(d)}}return c},_buildList:function(){var a,b=[],c=[];for(c.push(this._root);c.length;){a=c.pop(),a!==this._root&&b.push(a);for(var d=0;d<a.children.length;d+=1)c.push(a.children[d])}return b},propertyChangedHandler:function(a,b,c){"renderCallbacks"!==b&&(/hoverEnabled|selectionEnabled/.test(b)?c||this.host.find("jqx-treemap-rectangle-hover"):"showLegend"===b?this.host.find("jqx-treemap-legend").toggle():this._refresh())}})}(jqxBaseFramework);
6 7
7 (function(c){c.jqx.jqxWidget("jqxTreeMap","",{});var d={};d["default"]=(function(){function g(r,s,q,p){this.height=p;this.width=q;this.xoffset=r;this.yoffset=s;this.shortestEdge=function(){return Math.min(this.height,this.width)};this.getCoordinates=function(y){var x=[],v=this.xoffset,z=this.yoffset,w=j(y)/this.height,u=j(y)/this.width;if(this.width>=this.height){for(var t=0;t<y.length;t+=1){x.push([v,z,v+w,z+y[t]/w]);z=z+y[t]/w}}else{for(var t=0;t<y.length;t+=1){x.push([v,z,v+y[t]/u,z+u]);v=v+y[t]/u}}return x};this.cutArea=function(w){var y;if(this.width>=this.height){var x=w/this.height,t=this.width-x;y=new g(this.xoffset+x,this.yoffset,t,this.height)}else{var v=w/this.width,u=this.height-v;y=new g(this.xoffset,this.yoffset+v,this.width,u)}return y}}function o(t,r){var s=[],q=j(t),u=r/q;for(var p=0;p<t.length;p+=1){s[p]=t[p]*u}return s}function e(s,q,x,u,p){u=(typeof u==="undefined")?0:u;p=(typeof p==="undefined")?0:p;var v=[],w,t=[];if(h(s[0])){for(var r=0;r<s.length;r+=1){v[r]=i(s[r])}w=m(v,q,x,u,p);for(var r=0;r<s.length;r+=1){t.push(e(s[r],w[r][2]-w[r][0],w[r][3]-w[r][1],w[r][0],w[r][1]))}}else{t=m(s,q,x,u,p)}return t}function m(s,r,p,t,u){t=(typeof t==="undefined")?0:t;u=(typeof u==="undefined")?0:u;var q=f(o(s,r*p),[],new g(t,u,r,p),[]);return n(q)}function n(r){var s=[];for(var q=0;q<r.length;q+=1){for(var p=0;p<r[q].length;p+=1){s.push(r[q][p])}}return s}function f(u,t,q,p){var s,r,v;if(u.length===0){p.push(q.getCoordinates(t));return}s=q.shortestEdge();r=u[0];if(l(t,r,s)){t.push(r);f(u.slice(1),t,q,p)}else{v=q.cutArea(j(t),p);p.push(q.getCoordinates(t));f(u,[],v,p)}return p}function l(t,q,r){var s;if(t.length===0){return true}s=t.slice();s.push(q);var u=k(t,r),p=k(s,r);return u>=p}function k(t,s){var q=Math.min.apply(Math,t),p=Math.max.apply(Math,t),r=j(t);return Math.max(Math.pow(s,2)*p/Math.pow(r,2),Math.pow(r,2)/(Math.pow(s,2)*q))}function h(p){return p&&p.constructor===Array}function j(p){var r=0;for(var q=0;q<p.length;q+=1){r+=p[q]}return r}function i(p){var r=0;if(h(p[0])){for(var q=0;q<p.length;q+=1){r+=i(p[q])}}else{r=j(p)}return r}return e}());function b(g,l,i,h,j,f,k,e){this.label=g;this.value=l;this.parent=i;this.children=h;this.area=j||null;this.color=f;this.data=k;this.record=e}var a={HORIZONTAL:0,VERTICAL:1,BOTH:2};c.extend(c.jqx._jqxTreeMap.prototype,{defineInstance:function(){var e={width:600,height:600,renderCallbacks:{},legendScaleCallback:function(f){return f},hoverEnabled:false,selectionEnabled:true,singleSelection:true,showLegend:true,legendLabel:"Legend",headerHeight:25,colorRange:100,layout:"default",source:[],displayMember:null,valueMember:null,colorMode:"parent",baseColor:"#C2EEFF",legendPosition:{x:0,y:0},colorRanges:[{color:"#aa9988",min:0,max:10},{color:"#ccbbcc",min:11,max:50},{color:"#000",min:50,max:100}],_root:[]};c.extend(true,this,e);return e},createInstance:function(){this.render()},render:function(){this.host.addClass(this.toThemeProperty("jqx-widget"));this._destroy();this._root=new b(undefined,0,null,[],this.host);var e=function(h,k){var n={},l;var m=null;for(var j=0;j<h.length;j+=1){if(h[j].items){m=true;break}}var f=new Array();if(m){var g=function(v,s){for(var q=0;q<v.length;q+=1){v[q].parent=s;if(!v[q].data){v[q].data=v[q].value}if(v[q].value==null){v[q].value=0}if(isNaN(parseFloat(v[q].value))){var w=v[q].value.toString();var u="";for(var p=0;p<w.length;p++){var r=w.substring(p,p+1);if(r.match(/^[0-9]+$/)!=null||r=="."){u+=r}}v[q].value=new Number(u)}else{v[q].value=parseFloat(v[q].value)}f.push(v[q]);if(v[q].items){g(v[q].items,v[q].label)}}};g(h,null);h=f}for(var j=0;j<h.length;j+=1){l=h[j];if(l.value){if(l.parent!=null){if(!n[l.parent]){n[l.parent]=0}n[l.parent]+=l.value}}}for(var j=0;j<h.length;j+=1){l=h[j];if(n[l.label]!==undefined){l.value=n[l.label]}}k._buildTree(h,k._root);k._dataList=k._buildList();k._setStyles();var o=d["default"];if(k.layout==="simple"){o=d.simple}k._render(k._root,o);k._renderLegend()};if(c.jqx.dataAdapter&&this.source!=null&&this.source._source){this.dataBind(this.source,e);return}e(this.source,this);this._trigger("bindingComplete")},dataBind:function(e,m){this.records=new Array();var h=e._source?true:false;var f=new c.jqx.dataAdapter(e,{autoBind:false});if(h){f=e;e=e._source}var g=function(n){if(e.type!=undefined){f._options.type=e.type}if(e.formatdata!=undefined){f._options.formatData=e.formatdata}if(e.contenttype!=undefined){f._options.contentType=e.contenttype}if(e.async!=undefined){f._options.async=e.async}};var j=function(p,o){p.records=f.records;var q=new Array();for(var n=0;n<p.records.length;n++){var r=p.records[n];if(p.displayMember){r.label=r[p.displayMember]}if(p.valueMember){r.value=r[p.valueMember]}r.record=r;q.push(r)}p._trigger("bindingComplete");m(q,p)};g(this);var k=this;switch(e.datatype){case"local":case"array":default:if(e.localdata!=null){f.unbindBindingUpdate(this.element.id);f.dataBind();j(this);f.bindBindingUpdate(this.element.id,function(n){j(k,n)})}break;case"json":case"jsonp":case"xml":case"xhtml":case"script":case"text":case"csv":case"tab":if(e.localdata!=null){f.unbindBindingUpdate(this.element.id);f.dataBind();j(this);f.bindBindingUpdate(this.element.id,function(){j(k)});return}var l={};if(f._options.data){c.extend(f._options.data,l)}else{if(e.data){c.extend(l,e.data)}f._options.data=l}var i=function(){j(k)};f.unbindDownloadComplete(k.element.id);f.bindDownloadComplete(k.element.id,i);f.dataBind()}},_destroy:function(){this.host.children().remove()},destroy:function(){this.host.remove()},refresh:function(e){if(!e){this._refresh()}},_refresh:function(){this.render()},_setStyles:function(){this.host.css({position:"relative",width:this.width,height:this.height});var e=false;if(this.width!=null&&this.width.toString().indexOf("%")!=-1){e=true}if(this.height!=null&&this.height.toString().indexOf("%")!=-1){e=true}var f=this;c.jqx.utilities.resize(this.host,function(){if(f.resizeTimer){clearTimeout(f.resizeTimer)}f.resizeTimer=setTimeout(function(){f.performLayout()},50)})},resize:function(f,e){this.width=f;this.height=e;this.performLayout()},performLayout:function(){var e=d["default"];this.clearSelection();this._layout(this._root,e)},_getValues:function(g){var e=[];for(var f=0;f<g.length;f+=1){e.push(g[f].value)}return e},_isColor:function(e){if(!e){return false}var f=this._colorEvaluator;if(f._isRgb(e)||f._isHex(e)){return true}return false},_colorEvaluator:{_toRgb:function(f){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(f);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null},_toHex:function(f){var i=f.r.toString(16),h=f.g.toString(16),e=f.b.toString(16);i=i.length===1?"0"+i:i;h=h.length===1?"0"+h:h;e=e.length===1?"0"+e:e;return"#"+i+h+e},_isRgb:function(e){return(/(rgb|rgba)\s*\(\s*\d+\s*(,\s*\d+\s*){2}(,\d+\.\d+)?\)(;?)/i).test(e)},_isHex:function(e){return(/^(#([0-9A-F]{3})([0-9A-F]{3})?)$/i).test(e)},getColorByValue:function(n,j,k){var o=this._colorEvaluator,m,l,e,f,g,j;if(o._isRgb(k)){k=o._toHex(k)}k=o._toRgb(k);e=j.length;m=-Infinity;for(var h=0;h<e;h+=1){if(m<j[h].value){m=j[h].value}}l=n/m;f=Math.round(l*this.colorRange);g=o._toHex({r:Math.max(k.r-f,0),g:Math.max(k.g-f,0),b:Math.max(k.b-f,0)});return g},parent:function(g){var f=g.parent.color,e=this._colorEvaluator;if(!g.parent){return"#fff"}if(!f){f=this.baseColor}f=e.getColorByValue.call(this,g.value,g.parent.children,f);g.color=f;return f},autoColors:function(g){var f=this.baseColor,e=this._colorEvaluator;f=e.getColorByValue.call(this,g.value,this._dataList,f);g.color=f;return f},rangeColors:function(f){var h=f.value,g;for(var e=0;e<this.colorRanges.length;e+=1){g=this.colorRanges[e];if(g.min<h&&g.max>=h){return g.color}}return"#fff"}},_getColor:function(f){var e=f.color,g=this.colorMode;if(this._isColor(e)){return e}if(typeof this._colorEvaluator[g]==="function"){return this._colorEvaluator[g].call(this,f)}else{throw"Invalid colorMode"}},_renderRect:function(i,f){var j=c("<div/>"),e=i[2]-i[0],l=i[3]-i[1];var g=this._getColor(f);j.css({position:"absolute",left:i[0]-1,top:i[1]-1,width:e,height:l,backgroundColor:g});j.addClass(this.toThemeProperty("jqx-treemap-rectangle"));var k=this._colorEvaluator;var h={data:f.data,label:f.label,value:f.value,parent:f.parent,record:f.record,color:g,rgb:k._toRgb(g)};if(f.parent==this._root){h.parent=null}if(typeof this.renderCallbacks["*"]==="function"){var m=this.renderCallbacks["*"](j,h);if(m!==undefined){return j}}if(typeof this.renderCallbacks[f.label]==="function"){this.renderCallbacks[f.label](j,h)}else{var e=j.width()-2;j.html('<span style="max-width:'+e+'px;" class="jqx-treemap-label">'+f.label+"</span>")}return j},_centerLabel:function(g,f){var e=g[0].firstChild;e.style.position="absolute";if(f===a.HORIZONTAL||f===a.BOTH){e.style.left=(g[0].offsetWidth-e.offsetWidth)/2+"px"}if(f===a.VERTICAL||f===a.BOTH){e.style.top=(g[0].offsetHeight-e.offsetHeight)/2+"px"}},_trigger:function(g,f){var h=c.Event(g);h.args=f;return this.host.trigger(h)},_addHandlers:function(e,g){var f=this;e.bind("mouseenter",function(h){if(f.hoverEnabled){f.host.find(".jqx-treemap-rectangle").removeClass("jqx-treemap-rectangle-hover");e.addClass(f.toThemeProperty("jqx-treemap-rectangle-hover"))}f._trigger("mouseenterSector",g)});e.bind("mouseleave",function(h){if(f.hoverEnabled){e.removeClass("jqx-treemap-rectangle-hover")}f._trigger("mouseleaveSector",g)});e.bind("click",function(i){if(f.selectionEnabled){var h=c.data(this,"jqx-treemap-selected")||false;if(f.singleSelection){f.host.find(".jqx-treemap-rectangle-hover").each(function(j,k){c.data(k,"jqx-treemap-selected",false);c(k).removeClass("jqx-treemap-rectangle-hover")})}if(h){e.removeClass("jqx-treemap-rectangle-hover");h=false}else{e.addClass(f.toThemeProperty("jqx-treemap-rectangle-hover"));h=true}c.data(this,"jqx-treemap-selected",h);i.stopImmediatePropagation()}})},clearSelection:function(){this.host.find(".jqx-treemap-rectangle-hover").removeClass(this.toThemeProperty("jqx-treemap-rectangle-hover"));c.data(this,"jqx-treemap-selected",false)},_layoutArea:function(f,e){if(f.children.length&&f.children.length>0){this._centerLabel(e,a.HORIZONTAL);e.addClass(this.toThemeProperty("jqx-treemap-rectangle-parent"))}else{this._centerLabel(e,a.BOTH)}},_render:function(f,l){if(!f.children.length){return}var e=0;if(f.value){e=this.headerHeight}var n=this._getValues(f.children),g=f.area.offset(),j=l(n,f.area.width(),f.area.height()-e,0,e),k,m;for(var h=0;h<f.children.length;h+=1){k=f.children[h];m=this._renderRect(j[h],k);k.area=m;f.area.append(m);this._addHandlers(m,{label:k.label,value:k.value,color:k.color,sector:k.area,data:k.data});this._layoutArea(k,m);this._render(k,l)}},_layout:function(f,l){if(!f.children.length){return}var e=0;if(f.value){e=this.headerHeight}var n=this._getValues(f.children),g=f.area.offset(),h=l(n,f.area.width(),f.area.height()-e,0,e),m;for(var j=0;j<f.children.length;j+=1){var k=f.children[j];this._layoutRect(h[j],k);this._layoutArea(k,k.area);this._layout(k,l)}if(this.showLegend){c(".jqx-treemap-legend").remove();this._renderLegend()}},_layoutRect:function(i,f){var j=f.area,e=i[2]-i[0],l=i[3]-i[1];j.css({left:i[0]-1,top:i[1]-1,width:e,height:l});var k=this._colorEvaluator;var g=this._getColor(f);var h={data:f.data,label:f.label,value:f.value,parent:f.parent,record:f.record,color:g,rgb:k._toRgb(g)};if(f.parent==this._root){h.parent=null}if(typeof this.renderCallbacks["*"]==="function"){var m=this.renderCallbacks["*"](j,h);if(m!==undefined){return j}}if(typeof this.renderCallbacks[f.label]==="function"){this.renderCallbacks[f.label](j,h)}else{var e=j.width()-2;j.find(".jqx-treemap-label:first").css("max-width",e)}},_getBoundValues:function(){var g=this._root,f=[],k,j={},e={};j.value=g.value||Infinity;e.value=g.value||-Infinity;f.push(g);while(f.length){k=f.pop();if(j.value>k.value){j=k}if(e.value<k.value){e=k}for(var h=0;h<k.children.length;h+=1){f.push(k.children[h])}}return[j,e]},_getAutocolorRanges:function(){var l=this._getBoundValues(),g=5,e=l[1].value,j=l[0].value,f=(e-j)/g,m,k=[];for(var h=j;h<e;h+=f){m=Math.round(h);k.push({min:m,max:h+f,color:this._colorEvaluator.getColorByValue.call(this,m,this._dataList,this.baseColor)})}return k},_renderLegend:function(){if(!(/autoColors|rangeColors/).test(this.colorMode)||!this.showLegend){return}var e=this.colorRanges;if(this.colorMode==="autoColors"){e=this._getAutocolorRanges()}var f=this._renderColorLegend(e);this._renderLegendLabel(f)},_renderLegendLabel:function(f){var g=c('<tr><td colspan="'+f.find("td").length/2+'"/></tr>'),e=c('<div class="'+this.toThemeProperty("jqx-treemap-legend-label")+'" />');e.text(this.legendLabel);g.children().append(e);f.prepend(g)},_renderColorLegend:function(e){var o=c('<div class="'+this.toThemeProperty("jqx-treemap-legend")+'"/>'),q,n,r,p=function(i){return i};if(typeof this.legendScaleCallback==="function"){p=this.legendScaleCallback}var s=c('<table class="'+this.toThemeProperty("jqx-treemap-legend-table")+'"/>');o.append(s);s.append("<tr/>");o.append("<div/>");this.host.append(o);q=c(o.find("tr")[0]);n=c(o.find("div")[0]);n.addClass(this.toThemeProperty("jqx-treemap-legend-values"));var g=function(t,i){try{if(t.min<i.min){return -1}if(t.min>i.min){return 1}}catch(u){var v=u}return 0};e.sort(g);var f=Math.round(o.width()/e.length);var m=-2;var h=0;for(var k=0;k<e.length;k+=1){var j=c('<td class="'+this.toThemeProperty("jqx-treemap-legend-color")+'"/>');j.css("backgroundColor",e[k].color);q.append(j);if(k===0){var l=c('<span class="'+this.toThemeProperty("jqx-treemap-legend-max-value")+" "+this.toThemeProperty("jqx-treemap-legend-value")+'"/>');l.text(p(e[k].min));n.append(l);s.css("margin-left",l.width()/2);m+=l.width()/2;h=m}var l=c('<span class="'+this.toThemeProperty("jqx-treemap-legend-max-value")+" "+this.toThemeProperty("jqx-treemap-legend-value")+'"/>');m+=f;l.text(p(e[k].max));n.append(l);if(k==e.length-1){h+=l.width()/2;o.css("padding-right",h+5);m-=2}m-=l.width()/2;l.css("left",m);m+=l.width()/2}o.css({position:"absolute",left:this.legendPosition.x,bottom:this.legendPosition.y,visibility:(this.showLegend)?"visible":"hidden"});return o},_buildTree:function(k,f){var g=null,m,l,e=[];e.push(f);while(e.length){g=e.pop();for(var h=0;h<k.length;h+=1){l=k[h];if(l.parent===g.label||(!l.parent&&!g.label)){var j=g;m=new b(l.label,parseFloat(l.value,10),j,[],null,l.color,l.data,l.record);g.children.push(m);e.push(m)}}}return f},_buildList:function(){var f=[],e=[],h;e.push(this._root);while(e.length){h=e.pop();if(h!==this._root){f.push(h)}for(var g=0;g<h.children.length;g+=1){e.push(h.children[g])}}return f},propertyChangedHandler:function(g,e,h){if(e==="renderCallbacks"){return}if((/hoverEnabled|selectionEnabled/).test(e)){if(!h){this.host.find("jqx-treemap-rectangle-hover")}}else{if(e==="showLegend"){this.host.find("jqx-treemap-legend").toggle()}else{this._refresh()}}}})}(jqxBaseFramework));

mercurial