EOS/Scripts/kendo/2015.3.1111/kendo.dataviz.treemap.min.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

9 lines
11 KiB
JavaScript

/*
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
* Copyright 2015 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
!function(e,define){define(["./kendo.data.min","./kendo.userevents.min","./kendo.dataviz.themes.min"],e)}(function(){return function(e,t){function n(e,t){if(null===t)return t;var n=x(e,!0);return n(t)}function i(e){return typeof e!==E}function o(e,t,n){var i,o,l=a(e),c=a(t),h=u(e)-u(t)<0,d=[];for(d.push(e),i=0;n>i;i++)o={r:r(l.r,c.r,i,n,h),g:r(l.g,c.g,i,n,h),b:r(l.b,c.b,i,n,h)},d.push(s(o));return d.push(t),d}function r(e,t,n,i,o){var r,s=f.min(f.abs(e),f.abs(t)),a=f.max(f.abs(e),f.abs(t)),l=(a-s)/(i+1),c=l*(n+1);return r=o?s+c:a-c}function s(e){return"#"+l(e.r)+l(e.g)+l(e.b)}function a(e){e=e.replace("#","");var t=c(e);return{r:h(t.r),g:h(t.g),b:h(t.b)}}function l(e){var t=f.round(e).toString(16).toUpperCase();return 1===t.length&&(t="0"+t),t}function c(e){var t=e.length,n={};return 3===t?(n.r=e[0],n.g=e[1],n.b=e[2]):(n.r=e.substring(0,2),n.g=e.substring(2,4),n.b=e.substring(4,6)),n}function h(e){return parseInt(e.toString(16),16)}function u(e){var t=0;return e&&(e=a(e),t=f.sqrt(.241*e.r*e.r+.691*e.g*e.g+.068*e.b*e.b)),t}function d(e){var t=f.pow(10,4);return f.round(e*t)/t}var f=Math,p=e.proxy,g=e.isArray,m=window.kendo,v=m.Class,_=m.ui.Widget,w=m.template,y=m.deepExtend,b=m.data.HierarchicalDataSource,x=m.getter,k=m.dataviz,C=".kendoTreeMap",S="change",T="dataBound",A="itemCreated",D=Number.MAX_VALUE,M="mouseover"+C,P="mouseleave"+C,E="undefined",I=_.extend({init:function(t,n){m.destroy(t),e(t).empty(),_.fn.init.call(this,t,n),this.wrapper=this.element,this._initTheme(this.options),this.element.addClass("k-widget k-treemap"),this._setLayout(),this._originalOptions=y({},this.options),this._initDataSource(),this._attachEvents(),m.notify(this,k.ui)},options:{name:"TreeMap",theme:"default",autoBind:!0,textField:"text",valueField:"value",colorField:"color"},events:[T,A],_initTheme:function(e){var t=this,n=k.ui.themes||{},i=((e||{}).theme||"").toLowerCase(),o=(n[i]||{}).treeMap;t.options=y({},o,e)},_attachEvents:function(){this.element.on(M,p(this._mouseover,this)).on(P,p(this._mouseleave,this))},_setLayout:function(){"horizontal"===this.options.type?(this._layout=new z(!1),this._view=new L(this,this.options)):"vertical"===this.options.type?(this._layout=new z(!0),this._view=new L(this,this.options)):(this._layout=new B,this._view=new R(this,this.options))},_initDataSource:function(){var e=this,t=e.options,n=t.dataSource;e._dataChangeHandler=p(e._onDataChange,e),e.dataSource=b.create(n).bind(S,e._dataChangeHandler),n&&e.options.autoBind&&e.dataSource.fetch()},setDataSource:function(e){var t=this;t.dataSource.unbind(S,t._dataChangeHandler),t.dataSource=e.bind(S,t._dataChangeHandler),e&&t.options.autoBind&&t.dataSource.fetch()},_onDataChange:function(e){var t,n,i,o,r=e.node,s=e.items,a=this.options;if(r){if(s.length){for(i=this._getByUid(r.uid),i.children=[],s=new m.data.Query(s)._sortForGrouping(a.valueField,"desc"),n=0;s.length>n;n++)t=s[n],i.children.push(this._wrapItem(t));o=this._view.htmlSize(i),this._layout.compute(i.children,i.coord,o),this._setColors(i.children),this._view.render(i)}}else this.element.empty(),t=this._wrapItem(s[0]),this._layout.createRoot(t,this.element.outerWidth(),this.element.outerHeight(),"vertical"===this.options.type),this._view.createRoot(t),this._root=t,this._colorIdx=0;for(n=0;s.length>n;n++)s[n].load();r&&this.trigger(T,{node:r})},_setColors:function(e){var t,n,r,s,a=this.options.colors,l=this._colorIdx,c=a[l%a.length];for(g(c)&&(t=o(c[0],c[1],e.length)),r=!1,s=0;e.length>s;s++)n=e[s],i(n.color)||(n.color=t?t[s]:c),n.dataItem.hasChildren||(r=!0);r&&this._colorIdx++},_contentSize:function(e){this.view.renderHeight(e)},_wrapItem:function(e){var t={};return i(this.options.valueField)&&(t.value=n(this.options.valueField,e)),i(this.options.colorField)&&(t.color=n(this.options.colorField,e)),i(this.options.textField)&&(t.text=n(this.options.textField,e)),t.level=e.level(),t.dataItem=e,t},_getByUid:function(e){for(var t,n=[this._root];n.length;){if(t=n.pop(),t.dataItem.uid===e)return t;t.children&&(n=n.concat(t.children))}},dataItem:function(t){var n=e(t).attr(m.attr("uid")),i=this.dataSource;return i&&i.getByUid(n)},findByUid:function(e){return this.element.find(".k-treemap-tile["+m.attr("uid")+"='"+e+"']")},_mouseover:function(t){var n=e(t.target);n.hasClass("k-leaf")&&(this._removeActiveState(),n.removeClass("k-state-hover").addClass("k-state-hover"))},_removeActiveState:function(){this.element.find(".k-state-hover").removeClass("k-state-hover")},_mouseleave:function(){this._removeActiveState()},destroy:function(){_.fn.destroy.call(this),this.element.off(C),this.dataSource&&this.dataSource.unbind(S,this._dataChangeHandler),this._root=null,m.destroy(this.element)},items:function(){return e()},getSize:function(){return m.dimensions(this.element)},_resize:function(){this.dataSource.fetch()},setOptions:function(e){var n=e.dataSource;e.dataSource=t,this._originalOptions=y(this._originalOptions,e),this.options=y({},this._originalOptions),this._setLayout(),this._initTheme(this.options),_.fn._setEvents.call(this,e),n&&this.setDataSource(b.create(n)),this.options.autoBind&&this.dataSource.fetch()}}),B=v.extend({createRoot:function(e,t,n){e.coord={width:t,height:n,top:0,left:0}},leaf:function(e){return!e.children},layoutChildren:function(e,t){var n,i,o,r,s=t.width*t.height,a=0,l=[];for(n=0;e.length>n;n++)l[n]=parseFloat(e[n].value),a+=l[n];for(n=0;l.length>n;n++)e[n].area=s*l[n]/a;i=this.layoutHorizontal()?t.height:t.width,o=[e[0]],r=e.slice(1),this.squarify(r,o,i,t)},squarify:function(e,t,n,i){this.computeDim(e,t,n,i)},computeDim:function(e,n,i,o){var r,s,a;return e.length+n.length==1?(r=1==e.length?e:n,this.layoutLast(r,i,o),t):(e.length>=2&&0===n.length&&(n=[e[0]],e=e.slice(1)),0===e.length?(n.length>0&&this.layoutRow(n,i,o),t):(s=e[0],this.worstAspectRatio(n,i)>=this.worstAspectRatio([s].concat(n),i)?this.computeDim(e.slice(1),n.concat([s]),i,o):(a=this.layoutRow(n,i,o),this.computeDim(e,[],a.dim,a)),t))},layoutLast:function(e,t,n){e[0].coord=n},layoutRow:function(e,t,n){return this.layoutHorizontal()?this.layoutV(e,t,n):this.layoutH(e,t,n)},orientation:"h",layoutVertical:function(){return"v"===this.orientation},layoutHorizontal:function(){return"h"===this.orientation},layoutChange:function(){this.orientation=this.layoutVertical()?"h":"v"},worstAspectRatio:function(e,t){var n,i,o,r,s;if(!e||0===e.length)return D;for(n=0,i=0,o=D,r=0;e.length>r;r++)s=e[r].area,n+=s,o=s>o?o:s,i=i>s?i:s;return f.max(t*t*i/(n*n),n*n/(t*t*o))},compute:function(e,t,n){if(t.width>=t.height&&this.layoutHorizontal()||this.layoutChange(),e&&e.length>0){var i={width:t.width,height:t.height-n.text,top:0,left:0};this.layoutChildren(e,i)}},layoutV:function(e,t,n){var i,o,r,s=this._totalArea(e),a=0;for(t=d(s/t),i=0;e.length>i;i++)o=d(e[i].area/t),e[i].coord={height:o,width:t,top:n.top+a,left:n.left},a+=o;return r={height:n.height,width:n.width-t,top:n.top,left:n.left+t},r.dim=f.min(r.width,r.height),r.dim!=r.height&&this.layoutChange(),r},layoutH:function(e,t,n){var i,o,r=this._totalArea(e),s=d(r/t),a=n.top,l=0;for(i=0;e.length>i;i++)e[i].coord={height:s,width:d(e[i].area/s),top:a,left:n.left+l},l+=e[i].coord.width;return o={height:n.height-s,width:n.width,top:n.top+s,left:n.left},o.dim=f.min(o.width,o.height),o.dim!=o.width&&this.layoutChange(),o},_totalArea:function(e){var t,n=0;for(t=0;e.length>t;t++)n+=e[t].area;return n}}),R=v.extend({init:function(t,n){this.options=y({},this.options,n),this.treeMap=t,this.element=e(t.element),this.offset=0},htmlSize:function(e){var t,n,i=this._getByUid(e.dataItem.uid),o={text:0};return e.children&&(this._clean(i),t=this._getText(e),t&&(n=this._createTitle(e),i.append(n),o.text=n.height()),i.append(this._createWrap()),this.offset=(i.outerWidth()-i.innerWidth())/2),o},_getByUid:function(e){return this.element.find(".k-treemap-tile["+m.attr("uid")+"='"+e+"']")},render:function(e){var t,n,i,o,r=this._getByUid(e.dataItem.uid),s=e.children;if(s)for(t=r.find(".k-treemap-wrap"),n=0;s.length>n;n++)i=s[n],o=this._createLeaf(i),t.append(o),this.treeMap.trigger(A,{element:o})},createRoot:function(e){var t=this._createLeaf(e);this.element.append(t),this.treeMap.trigger(A,{element:t})},_clean:function(e){e.css("background-color",""),e.removeClass("k-leaf"),e.removeClass("k-inverse"),e.empty()},_createLeaf:function(t){return this._createTile(t).css("background-color",t.color).addClass("k-leaf").toggleClass("k-inverse",this._tileColorBrightness(t)>180).append(e("<div></div>").html(this._getText(t)))},_createTile:function(t){var n,o={width:t.coord.width,height:t.coord.height,left:t.coord.left,top:t.coord.top};return o.width+=o.left&&this.offset?2*this.offset:this.offset,o.height+=o.top?2*this.offset:this.offset,n=e("<div class='k-treemap-tile'></div>").css({width:o.width,height:o.height,left:o.left,top:o.top}),i(t.dataItem)&&i(t.dataItem.uid)&&n.attr(m.attr("uid"),t.dataItem.uid),n},_getText:function(e){var t=e.text;return this.options.template&&(t=this._renderTemplate(e)),t},_renderTemplate:function(e){var t=w(this.options.template);return t({dataItem:e.dataItem,text:e.text})},_createTitle:function(t){return e("<div class='k-treemap-title'></div>").append(e("<div></div>").html(this._getText(t)))},_createWrap:function(){return e("<div class='k-treemap-wrap'></div>")},_tileColorBrightness:function(e){return u(e.color)}}),z=v.extend({createRoot:function(e,t,n,i){e.coord={width:t,height:n,top:0,left:0},e.vertical=i},init:function(e){this.vertical=e,this.quotient=e?1:0},compute:function(e,t,n){var i,o,r;e.length>0&&(i=t.width,o=t.height,this.vertical?o-=n.text:i-=n.text,r={width:i,height:o,top:0,left:0},this.layoutChildren(e,r))},layoutChildren:function(e,t){var n,i,o=t.width*t.height,r=0,s=[];for(n=0;e.length>n;n++)i=e[n],s[n]=parseFloat(e[n].value),r+=s[n],i.vertical=this.vertical;for(n=0;s.length>n;n++)e[n].area=o*s[n]/r;this.sliceAndDice(e,t)},sliceAndDice:function(e,t){var n=this._totalArea(e);e[0].level%2===this.quotient?this.layoutHorizontal(e,t,n):this.layoutVertical(e,t,n)},layoutHorizontal:function(e,t,n){var i,o,r,s=0;for(i=0;e.length>i;i++)o=e[i],r=o.area/(n/t.width),o.coord={height:t.height,width:r,top:t.top,left:t.left+s},s+=r},layoutVertical:function(e,t,n){var i,o,r,s=0;for(i=0;e.length>i;i++)o=e[i],r=o.area/(n/t.height),o.coord={height:r,width:t.width,top:t.top+s,left:t.left},s+=r},_totalArea:function(e){var t,n=0;for(t=0;e.length>t;t++)n+=e[t].area;return n}}),L=R.extend({htmlSize:function(e){var t,n,i=this._getByUid(e.dataItem.uid),o={text:0,offset:0};return e.children&&(this._clean(i),t=this._getText(e),t&&(n=this._createTitle(e),i.append(n),o.text=e.vertical?n.height():n.width()),i.append(this._createWrap()),this.offset=(i.outerWidth()-i.innerWidth())/2),o},_createTitle:function(t){var n;return n=e(t.vertical?"<div class='k-treemap-title'></div>":"<div class='k-treemap-title-vertical'></div>"),n.append(e("<div></div>").html(this._getText(t)))}});k.ui.plugin(I)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});