realchart
Version:
Wooritech charting library
8 lines (6 loc) • 9.22 kB
JavaScript
/**
* RealChart Treemap v1.4.12
* Copyright (C) 2023-2026 WooriTech Inc.
* All Rights Reserved.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("realchart")):"function"==typeof define&&define.amd?define(["exports","realchart"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RealChartTreemap={},t.RealChart)}(this,(function(t,e){"use strict";function i(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,r.get?r:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var r,o=i(e),n=(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),h=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return n(i,t),i.prototype._assignTo=function(i){return e.assignObj(t.prototype._assignTo.call(this,i),{id:this.id,group:this.group})},i.prototype._readArray=function(t,i){if(i.length<=2)this.isNull=!0;else{var r=i.length>3?1:0;r>0&&(this.x=i[e.pickNum(t.options.xField,0)]),this.y=i[e.pickNum(t.options.yField,0+r)],this.id=e.toStr(i[e.pickNum(t.options.idField,1+r)]),this.group=e.toStr(i[e.pickNum(t.options.groupField,2+r)])}},i.prototype._readObject=function(i,r){t.prototype._readObject.call(this,i,r),this.id=e.toStr(r[i.options.idField]),this.group=e.toStr(r[i.options.groupField])},i}(e.DataPoint),s=function(t){function i(e){var i=t.call(this,e.chart)||this;return i.level=e,i.floating=!0,i}return n(i,t),i.defaults=e.extend(e.ChartItem.defaults,{visible:!1}),i}(e.ChartItem);!function(t){function e(e,i){var r=t.call(this,e.chart)||this;return r.series=e,r.level=i,r.head=new s(r),r}n(e,t)}(e.ChartItem);var u=function(){function t(t){this.point=t}return t.prototype.level=function(){return this.parent?this.parent.level()+1:0},t.prototype.getArea=function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},t.prototype.setArea=function(t,e,i,r){this.x=t,this.y=e,this.width=i,this.height=r},t.prototype.getTotal=function(){return this.children.reduce((function(t,e){return t+e.value}),0)},t}(),a=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e._map={},e._levels=1,e}return n(i,t),i.prototype.buildMap=function(t,i){function r(t){if(t.children){var i=0;t.children.forEach((function(t,e){r(t),i+=t.value})),t.value=i,t.children=t.children.sort((function(t,e){return e.value-t.value})),t.children.forEach((function(t,e){t.index=e})),h=e.maxv(h,t.level()+1+1)}else n.push(t),t.value=t.point?t.point.yValue:0}var o="vertical"===this._op.startDir||i>t,n=this._leafs=[],h=1;return this._roots.forEach((function(t,e){r(t)})),this._roots=this._roots.sort((function(t,e){return e.value-t.value})),this._roots.forEach((function(t,e){t.index=e})),(this[this._op.algorithm]||this.squarify).call(this,this._roots,t,i,o),this._levels=h,{roots:this._roots,leafs:this._leafs}},i.prototype.needAxes=function(){return!1},i.prototype.canMixWith=function(t){return!1},i.prototype._createPoint=function(t){return new h(t)},i.prototype._getLabeledPoints=function(){return this._leafs.map((function(t){return t.point}))},i.prototype._doPrepareRender=function(){t.prototype._doPrepareRender.call(this),this._roots=this.$_buildTree(this._runPoints)},i.prototype.$_buildTree=function(t){var e=[],i=[],r=this._map;t.forEach((function(t){if(t.id||!t.isNull){var o=new u(t);t.id&&(r[t.id]=o),t.group?i.push(o):e.push(o)}}));for(var o=i.length-1;o>=0;o--){var n=i[o],h=r[n.point.group];(n.parent=h)?(h.children||(h.children=[]),h.children.push(n),n.children&&i.splice(o,1)):(e.push(n),i.splice(o,1))}return e},i.prototype.$_squarifyRow=function(t,i,r,o){var n=i.width*i.height,h=i.width,s=i.height,u=i.x,a=i.y,l=Number.MAX_VALUE,c=0,p=[];if(2===t.length)return(1===r?h>s:h>=s)?t.forEach((function(t){t.setArea(u,a,h*t.value/o,s),u+=t.width})):t.forEach((function(t){t.setArea(u,a,h,s*t.value/o),a+=t.height})),0;for(var f=function(){var f,d,y,_,g=void 0;return f=t.shift(),g=(c+=f.value)*n/o,1===r?(d=g/s,y=s*f.value/c):(y=g/h,d=h*f.value/c),_=e.maxv(d/y,y/d),t.length>0&&_>l?(t.unshift(f),c-=f.value,g=n*c/o,1===r?d=g/(y=s):y=g/(d=h),p.forEach((function(t){1===r?(t.setArea(u,a,d,s*t.value/c),a+=t.height):(t.setArea(u,a,h*t.value/c,y),u+=t.width)})),1===r?(i.x+=d,i.width-=d):(i.y+=y,i.height-=y),{value:o-c}):0===t.length?(g=n*c/o,1===r?d=g/(y=s):y=g/(d=h),p.push(f),p.forEach((function(t){1===r?(t.setArea(u,a,d,s*t.value/c),a+=t.height):(t.setArea(u,a,h*t.value/c,y),u+=t.width)})),{value:0}):(l=_,void p.push(f))};t.length>0;){var d=f();if("object"==typeof d)return d.value}},i.prototype.$_squarify=function(t,e,i,r){var o=this,n=t.slice(0),h=i?1:0,s=t.reduce((function(t,e){return t+e.value}),0);do{s=this.$_squarifyRow(n,e,h,s),r&&(h=1-h)}while(s>0);t.forEach((function(t){t.children&&o.$_squarify(t.children,t.getArea(),!i,!0)}))},i.prototype.squarify=function(t,e,i,r){this.$_squarify(t,{x:0,y:0,width:e,height:i},r,!0)},i.prototype.strip=function(t,e,i,r){this.$_squarify(t,{x:0,y:0,width:e,height:i},r,!1)},i.prototype.$_sliceNext=function(t,e,i,r){if(t.x=e.x,t.y=e.y,1===i){var o=e.height*t.value/r;t.width=e.width,t.height=o,e.y+=o,e.height-=o}else{var n=e.width*t.value/r;t.height=e.height,t.width=n,e.x+=n,e.width-=n}t.children&&this.$_slice(t.children,t.getArea(),0===i,!0)},i.prototype.$_slice=function(t,e,i,r){var o=this,n=t.reduce((function(t,e){return t+e.value}),0),h=i?1:0;t.forEach((function(t){o.$_sliceNext(t,e,h,n),n-=t.value,r&&(h=1-h)}))},i.prototype.slice=function(t,e,i,r){this.$_slice(t,{x:0,y:0,width:e,height:i},r,!1)},i.prototype.sliceDice=function(t,e,i,r){this.$_slice(t,{x:0,y:0,width:e,height:i},r,!0)},i.type=e.TreemapSeriesType,i.defaults=e.extend(e.Series.defaults,{idField:"id",groupField:"group",algorithm:"squarify",alternate:!0,groupMode:!0}),i}(e.Series),l=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}(),c=function(t){function i(i){return t.call(this,i,e.SeriesView.POINT_CLASS)||this}return l(i,t),Object.defineProperty(i.prototype,"point",{get:function(){return this.node.point},enumerable:!1,configurable:!0}),i.prototype.render=function(t){if(1!==t){var e=Object.assign({},this.node);e.width*=t,e.height*=t,e.x+=(this.node.width-e.width)/2,e.y+=(this.node.height-e.height)/2,this.setRect(e)}else this.setRect(this.node)},i}(e.RectElement);!function(t){function e(){return null!==t&&t.apply(this,arguments)||this}l(e,t)}(c);var p=function(t){function i(i){var r=t.call(this,i,"rct-treemap-series")||this;return r._nodeViews=new e.ElementPool(r._pointContainer,c),r}return l(i,t),i.prototype._lazyPrepareLabels=function(){return!0},i.prototype._getPointPool=function(){return this._nodeViews},i.prototype._prepareSeries=function(t,e){},i.prototype._renderSeries=function(t,e){this._pointContainer.invert(this._inverted,e),this._rootView?this.$_renderGroups(t,e):this.$_renderLeafs(t,e)},i.prototype._runShowEffect=function(t){t&&e.SeriesAnimation.grow(this)},i.prototype._doViewRateChanged=function(t){this._rootView?this.$_renderGroups(this.width,this.height):this.$_renderLeafs(this.width,this.height)},i.prototype.$_renderLeafs=function(t,i){var r=this,o=this.model,n=o._xAxisObj,h=o._yAxisObj,s=this._inverted;o.pointLabel;var u=this._getGrowRate(),a=this._labelViews(),l=s?t:i,c=s?i:t,p=o.buildMap(c,l);p.roots;var f,d=p.leafs,y=new e.Color(o._calcedColor),_=[{fill:""}];null==a||a.prepare(this.doc,this);var g=this._labelContainer._textAlign;this._nodeViews.prepare(d.length,(function(t,i,p){var v=d[i],w=v.point,x=v.parent,b=y;x&&(!x._color&&x.point.color?b=x._color=new e.Color(x.point.color):x._color&&(b=x._color)),t.node=v,_[0].fill=b.brighten(v.index/p).toString(),r._setPointStyle(t,o,w,_),n.options.reversed&&(v.x=c-v.x-v.width),h.options.reversed&&(v.y=l-v.y-v.height),s&&(v.y=v.y-l),t.render(u);var m=v.x+v.width/2,O=v.y+v.height/2;if(w.xPos=s?-v.y-v.height/2:m,w.yPos=s?c-v.x-v.width/2:O,a&&(f=a.get(w,0))){f.setContrast(t.dom).layout(g);var S=f.getBBox();f.setVis(v.width>=S.height&&v.height>=S.height)&&(s?(m=-v.y-v.height/2-S.width/2,O=c-v.x-(v.width+S.height)/2):(m-=S.width/2,O-=S.height/2),f.trans(m,O),r._layoutLabelRotation(f))}}))},i.prototype.$_renderGroups=function(t,e){},i}(e.SeriesView);function f(t){(function(t){return t.Series&&t.SeriesView})(t)&&(t.Series.register(a),t.SeriesView.register([a,p]))}f(o),t.TreemapSeries=a,t.default=f,Object.defineProperty(t,"__esModule",{value:!0})}));