/*
    *
    * Wijmo Library 5.20182.500
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
import*as wjcChart from"wijmo/wijmo.chart";import*as wjcCore from"wijmo/wijmo";import*as wjcSelfRef from"wijmo/wijmo.chart.hierarchical";var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.hierarchical=wjcSelf;export class Sunburst extends wjcChart.FlexPie{constructor(t,e){super(t,e),this._selectionIndex=0,this.applyTemplate("wj-sunburst",null,null),this.initialize(e),this.refresh()}get bindingName(){return this._bindName}set bindingName(t){t!=this._bindName&&(wjcCore.assert(null==t||wjcCore.isArray(t)||wjcCore.isString(t),"bindingName should be an array or a string."),this._bindName=t,this._bindChart())}get childItemsPath(){return this._childItemsPath}set childItemsPath(t){t!=this._childItemsPath&&(wjcCore.assert(null==t||wjcCore.isArray(t)||wjcCore.isString(t),"childItemsPath should be an array or a string."),this._childItemsPath=t,this._bindChart())}_initData(){super._initData(),this._processedData=[],this._level=1,this._legendLabels=[],this._processedItem=[]}_performBind(){var t;this._initData(),this._cv&&(t=this._cv.items,this._cv.groups&&this._cv.groups.length?this._processedData=HierarchicalUtil.parseDataToHierarchical(this._cv,this.binding,this.bindingName,this.childItemsPath):t&&(this._processedData=HierarchicalUtil.parseDataToHierarchical(t,this.binding,this.bindingName,this.childItemsPath)),this._processedData&&this._processedData.length&&(this._sum=this._calculateValueAndLevel(this._processedData,1),this._processedData.forEach(t=>{this._legendLabels.push(t.name)})))}_calculateValueAndLevel(t,e){var i=0,r=this._values,a=this._labels;return this._level<e&&(this._level=e),t.forEach(t=>{var s;t.items?(s=this._calculateValueAndLevel(t.items,e+1),t.value=s,r.push(s),a.push(t.name)):(s=this._getBindData(t,r,a,"value","name"),t.value=s),i+=s}),i}_renderPie(t,e,i,r,a){var s=this._getCenter();this._sliceIndex=0,this._parentRef={},this._renderHierarchicalSlices(t,s.x,s.y,this._processedData,this._sum,e,i,r,2*Math.PI,a,1)}_renderHierarchicalSlices(t,e,i,r,a,s,l,h,o,n,c){var _,d,m,u,p,C,w,g,v,f,I=r.length,j=h,T=1==this.reversed;m=(s-l)/this._level,_=s-(this._level-c)*m,d=l+(c-1)*m;for(var x=0;x<I;x++){if(g=e,v=i,w=t.startGroup("wj-slice slice-level"+c),1===c&&(t.fill=this._getColorLight(x),t.stroke=this._getColor(x)),p=r[x],C=Math.abs(p.value),u=Math.abs(C-a)<1e-10?o:o*C/a,f=T?j-.5*u:j+.5*u,n>0&&u<o&&(g+=n*Math.cos(f),v+=n*Math.sin(f)),p.items){let e=this._sliceIndex;for(this._renderHierarchicalSlices(t,g,v,p.items,C,s,l,j,u,0,c+1);e<this._sliceIndex;e++)null==this._parentRef[e]&&(this._parentRef[e]=this._sliceIndex)}this._renderSlice(t,g,v,f,this._sliceIndex,_,d,j,u,o),this._processedItem.push(p.item),this._sliceIndex++,T?j-=u:j+=u,t.endGroup(),this._pels.push(w)}}_getLabelsForLegend(){return this._legendLabels||[]}_highlightCurrent(){this.selectionMode!=wjcChart.SelectionMode.None&&this._highlight(!0,this._selectionIndex)}hitTest(t,e){var i=super.hitTest(t,e),r=this._toControl(t,e);if(wjcChart.FlexChart._contains(this._rectChart,r)){var a=i.pointIndex,s=this._processedItem[a],l=new wjcChart._DataPoint(null,a,null,null);l.item=s,i._setDataPoint(l)}return i}_getSelectedItemOffset(t,e){var i=0,r=0,a=0;if(this.selectedItemOffset>0)if(t==this.selectedIndex)a=this.selectedItemOffset;else{let i=this._getSelectedParentIndex(t);if(null!=i){let t=this._areas[i];this.dataLabel.position;a=this.selectedItemOffset,e=((e=t.langle+this._rotationAngle)%360+360)%360,e*=Math.PI/180}}return a>0&&(i=Math.cos(e)*a*this._radius,r=Math.sin(e)*a*this._radius),{x:i,y:r}}_getSelectedParentIndex(t){let e=this._parentRef[t];return null!=e?e===this.selectedIndex?e:this._getSelectedParentIndex(e):null}};export var TreeMapType;!function(t){t[t.Squarified=0]="Squarified",t[t.Horizontal=1]="Horizontal",t[t.Vertical=2]="Vertical"}(TreeMapType||(TreeMapType={}));export class TreeMap extends wjcChart.FlexChartBase{constructor(t,e){super(t,null,!0),this._values=[],this._labels=[],this._areas=[],this._sum=0,this._keywords=new wjcChart._KeyWords,this._processedData=[],this._depth=1,this._itemIndex=0,this._processedItem=[],this._maxDepth=-1,this._tmItems=[],this._colRowLens=[],this._defPalette=[{titleColor:"#033884",maxColor:"#1450a7",minColor:"#83b3f9"},{titleColor:"#a83100",maxColor:"#dc4a0d",minColor:"#ffb190"},{titleColor:"#006658",maxColor:"#008d7a",minColor:"#7deddf"},{titleColor:"#a10046",maxColor:"#df0061",minColor:"#ff8cbe"},{titleColor:"#784d08",maxColor:"#99681a",minColor:"#efc989"},{titleColor:"#54156f",maxColor:"#722a90",minColor:"#cf95e7"},{titleColor:"#998605",maxColor:"#c2ac19",minColor:"#ffef8b"},{titleColor:"#9a0005",maxColor:"#c80c14",minColor:"#ff888d"}],this.applyTemplate("wj-control wj-flexchart wj-treemap",null,null),this._currentRenderEngine=new wjcChart._SvgRenderEngine(this.hostElement),this._legend=new wjcChart.Legend(this),this._legend.position=wjcChart.Position.None,this._tooltip=new wjcChart.ChartTooltip,this._tooltip.content="<b>{name}</b><br/>{value}",this._tooltip.showDelay=0,this._lbl=new wjcChart.DataLabel,this._lbl.position=wjcChart.LabelPosition.Center,this._lbl._chart=this,this.hostElement.addEventListener("mousemove",t=>{this.isTouching||this._toogleTooltip(t)}),this.hostElement.addEventListener("click",t=>{var e=!0;if(this.maxDepth>0){var i=this.hitTest(t),r=wjcChart.FlexChart._SELECTION_THRESHOLD;if(this.tooltip&&this.tooltip.threshold&&(r=this.tooltip.threshold),i.distance<=r&&i.pointIndex>=-1&&i.pointIndex<this._areas.length){var a=this._areas[i.pointIndex];this._currentItem!=a.item&&(this._currentItem=a.item,this._refreshChart(),e=!1)}}e&&this.isTouching&&this._toogleTooltip(t)}),this.hostElement.addEventListener("contextmenu",t=>{if(this.maxDepth>0){var e=this.hitTest(t),i=wjcChart.FlexChart._SELECTION_THRESHOLD;this.tooltip&&this.tooltip.threshold&&(i=this.tooltip.threshold),e.distance<=i&&this._rollUp()}return t.preventDefault(),!1}),this.hostElement.addEventListener("mouseleave",()=>{this._hideToolTip()}),this.initialize(e),this.refresh()}_rollUp(){this._currentItem=this._currentItem&&this._currentItem.parent?this._currentItem.parent:null,this._refreshChart()}_toogleTooltip(t){var e=this._tooltip;if(e.content){var i=this.hitTest(t);if(i.distance<=e.threshold){var r=this._getLabelContent(i,this.tooltip.content);this._showToolTip(r,new wjcCore.Rect(t.clientX,t.clientY,5,5))}else this._hideToolTip()}}get selectionMode(){return wjcChart.SelectionMode.None}set selectionMode(t){}get _treeMapItems(){return this._tmItems}get tooltip(){return this._tooltip}get binding(){return this._binding}set binding(t){t!=this._binding&&(this._binding=wjcCore.asString(t,!0),this._bindChart())}get type(){return null==this._type?TreeMapType.Squarified:this._type}set type(t){(t=wjcCore.asEnum(t,TreeMapType))!=this._type&&(this._type=t,this.invalidate())}get bindingName(){return this._bindingName}set bindingName(t){t!=this._bindingName&&(wjcCore.assert(null==t||wjcCore.isArray(t)||wjcCore.isString(t),"bindingName should be an array or a string."),this._bindingName=t,this._bindChart())}get dataLabel(){return this._lbl}set dataLabel(t){t!=this._lbl&&(this._lbl=t,this._lbl&&(this._lbl._chart=this))}get childItemsPath(){return this._childItemsPath}set childItemsPath(t){t!=this._childItemsPath&&(wjcCore.assert(null==t||wjcCore.isArray(t)||wjcCore.isString(t),"childItemsPath should be an array or a string."),this._childItemsPath=t,this._bindChart())}get maxDepth(){return this._maxDepth}set maxDepth(t){t!=this._maxDepth&&(this._maxDepth=wjcCore.asNumber(t,!0),this.invalidate())}get palette(){return this._palette}set palette(t){t!=this._palette&&(this._palette=wjcCore.asArray(t),this._tmItems&&this._tmItems.length>0&&this._calculateColorForItems(this._tmItems),this.invalidate())}_initData(){this._sum=0,this._tmItems=[],this._currentItem=null,this._values=[],this._labels=[],this._processedData=[],this._depth=1,this._processedItem=[]}_performBind(){var t;this._initData(),this._cv&&(t=this._cv.items,this._cv.groups&&this._cv.groups.length?this._processedData=HierarchicalUtil.parseDataToHierarchical(this._cv,this.binding,this.bindingName,this.childItemsPath):t&&(this._processedData=HierarchicalUtil.parseDataToHierarchical(t,this.binding,this.bindingName,this.childItemsPath)),this._processedData&&this._processedData.length&&(this._sum=this._calculateValueAndDepth(this._processedData,1),this._sortData(this._processedData),this._values=[],this._getTMItemsAndLabelsAndValues(this._processedData,this._tmItems,1,null),this._calculateColorForItems(this._tmItems)))}_sortData(t){t.forEach(t=>{t.items&&this._sortData(t.items)}),t.sort((t,e)=>e.value-t.value)}_getTMItemsAndLabelsAndValues(t,e,i,r,a){t&&t.length>0&&t.forEach((t,a)=>{var s,l=new _TreeMapItem;l.items=[],l.parent=r,l.depth=i,t.items&&this._getTMItemsAndLabelsAndValues(t.items,l.items,i+1,l),s=t.name?t.name:t.value.toString(),l.label=s,l.value=t.value,null!=r&&(t.value>r.maxValue&&(r.maxValue=t.value),t.value<r.minValue&&(r.minValue=t.value)),e.push(l),this._labels.push(s),this._values.push(t.value)})}_calculateColorForItems(t,e,i){var r=i;t.forEach((t,i)=>{var a=e;1===t.depth&&(a=this._getColor(i)),t.palette=a;var s=t.palette;if(wjcCore.isString(s)){var l=s,h=this._getLightColor(l);t.titleFill=l,t.titleStroke=l,t.fill=h,t.stroke=l}else if(s.maxColor&&s.minColor&&s.titleColor)if(t.titleFill=s.titleColor,t.titleStroke=s.titleColor,null==t.parent)t.fill=s.maxColor,t.stroke=s.maxColor;else{null==r&&(r=new _ColorConverter(s.minColor,t.minValue,s.maxColor,t.maxValue));let e=r._calculateColorByVal(t.value,!0).toString();t.fill=e,t.stroke=e}if(t.items&&t.items.length>0){var o=new _ColorConverter(s.minColor,t.minValue,s.maxColor,t.maxValue);this._calculateColorForItems(t.items,a,o)}})}_getBindData(t,e,i){var r,a=0;i&&(r=t[i]);a=0;return wjcCore.isNumber(r)?a=wjcCore.asNumber(r):r&&(a=parseFloat(r.toString())),!isNaN(a)&&isFinite(a)?e.push(a):(a=0,e.push(a)),a}_calculateValueAndDepth(t,e){var i=0,r=this._values;return this._depth<e&&(this._depth=e),t.forEach(t=>{var a;t.items?(a=this._calculateValueAndDepth(t.items,e+1),t.value=a,r.push(a)):(a=this._getBindData(t,r,"value"),t.value=a),i+=a}),i}_prepareRender(){this._areas=[]}_renderChart(t,e,i){var r,a,s,l=this._rectChart.clone();new wjcCore.Size(l.width,l.height);this.onRendering(new wjcChart.RenderEventArgs(t));var h=e.width,o=e.height;this._tmGroup=t.startGroup(null,null,!0);var n=this._parseMargin(this.plotMargin);this.dataLabel;isNaN(n.left)&&(n.left=TreeMap._MARGIN),isNaN(n.right)&&(n.right=TreeMap._MARGIN),isNaN(n.top)&&(n.top=TreeMap._MARGIN),isNaN(n.bottom)&&(n.bottom=TreeMap._MARGIN),e.top+=n.top;o=e.height-(n.top+n.bottom);e.height=o>0?o:24,e.left+=n.left;h=e.width-(n.left+n.right);e.width=h>0?h:24,this._plotRect=e,r=this._currentItem?[this._currentItem]:this._tmItems,a=null==this._currentItem||this.maxDepth<1?this.maxDepth:this._currentItem&&this._currentItem.items&&this._currentItem.items.length&&this.maxDepth>1?this.maxDepth:this.maxDepth+1,s=this._currentItem?this._currentItem.value:this._sum,this._renderTreeMap(t,e,this._tmGroup,r,s,a),t.endGroup(),this.dataLabel.content&&this.dataLabel.position!=wjcChart.LabelPosition.None&&this._renderLabels(t),this.onRendered(new wjcChart.RenderEventArgs(t))}_renderTreeMap(t,e,i,r,a,s){a>0&&(this._itemIndex=0,this._resetItemRects(this._tmItems),this._calculateItemRects(e,r,a,1,s),this._renderHierarchicalTreeMapItems(t,i,e,this._tmItems,a,1,s))}_resetItemRects(t){t.forEach(t=>{t.rect=new wjcCore.Rect(0,0,0,0),t.isTitle=!1,t.type=this.type,t.items&&t.items.length&&this._resetItemRects(t.items)})}_calculateItemRects(t,e,i,r,a){switch(this.type){case TreeMapType.Horizontal:_TreeMapUtils.horizontal(e,t,i);break;case TreeMapType.Vertical:_TreeMapUtils.vertical(e,t,i);break;case TreeMapType.Squarified:_TreeMapUtils.squarified(e,t,i)}e.forEach((t,e)=>{t.rect.clone();t.items&&t.items.length&&(r===a||r>a&&a>=1||(t.isTitle=!0,this._calculateItemRects(t.itemsRect,t.items,t.value,r+1,a)))})}_renderHierarchicalTreeMapItems(t,e,i,r,a,s,l){var h,o,n,c,_,d=r.length;this.type;if(0!==d)for(var m=0;m<d;m++)h=t.startGroup(TreeMap._CSS_ITEMDEPTH+s),o=r[m],n=Math.abs(o.value),c=o.rect,o.draw(t),_=new wjcChart._RectArea(c),o.items&&this._renderHierarchicalTreeMapItems(t,h,o.itemsRect,o.items,n,s+1,l),_.tag=this._itemIndex,_.name=o.label,_.value=n,_.item=o,this._areas.push(_),this._itemIndex++,t.endGroup()}_renderLabels(t){var e,i=this._areas.length,r=this.dataLabel,a=r.position,s=r.connectingLine,l=r.border,h=r.offset||0;t.stroke="null",t.fill="transparent",t.strokeWidth=1,t.startGroup("wj-data-labels");for(var o=0;o<i;o++){var n=this._areas[o];if(n){var c=n.rect,_=new wjcChart.HitTestInfo(this,e);_._setData(null,o);var d=this._getLabelContent(_,r.content);if(e=new wjcCore.Point(c.left+c.width/2,c.top+c.height/2),d&&c.width>0&&c.height>0){var m=new wjcChart.DataLabelRenderEventArgs(t,_,e,d);r.onRendering(m)&&(d=m.text,e=m.point,this._renderLabelAndBorder(t,n,c,d,a,h,e,s,2,l))}}}t.endGroup()}_renderLabelAndBorder(t,e,i,r,a,s,l,h,o,n){var c,_="wj-data-label",d="wj-data-label-line";switch(a){case wjcChart.LabelPosition.Top:h&&t.drawLine(l.x,l.y,l.x,l.y-s,d),l.y-=o+s,c=this._renderText(t,e,i,r,l,1,2,_);break;case wjcChart.LabelPosition.Bottom:h&&t.drawLine(l.x,l.y,l.x,l.y+s,d),l.y+=o+s,c=this._renderText(t,e,i,r,l,1,0,_);break;case wjcChart.LabelPosition.Left:h&&t.drawLine(l.x,l.y,l.x-s,l.y,d),l.x-=o+s,c=this._renderText(t,e,i,r,l,2,1,_);break;case wjcChart.LabelPosition.Right:h&&t.drawLine(l.x,l.y,l.x+s,l.y,d),l.x+=o+s,c=this._renderText(t,e,i,r,l,0,1,_);break;case wjcChart.LabelPosition.Center:c=this._renderText(t,e,i,r,l,1,1,_)}return n&&c&&t.drawRect(c.left-o,c.top-o,c.width+2*o,c.height+2*o,"wj-data-label-border"),c}_renderText(t,e,i,r,a,s,l,h){var o,n=r,c=e.item;return o=t.measureString(r,h),this.type===TreeMapType.Horizontal&&c.isTitle?(o.width>i.height&&(n=this._cutText(r,o.width,i.height)),wjcChart.FlexChart._renderRotatedText(t,n,a,s,l,a,-90,h),null):(o.width>i.width&&(n=this._cutText(r,o.width,i.width)),wjcChart.FlexChart._renderText(t,n,a,s,l,h))}_cutText(t,e,i){var r="",a=t.length,s=Math.floor((1-(e-i)/e)*a);return t.length>0&&(r=t[0]+(s>1?t.substring(1,s-1)+"..":"")),r}_measureLegendItem(t,e){var i=new wjcCore.Size;if(i.width=wjcChart.Series._LEGEND_ITEM_WIDTH,i.height=wjcChart.Series._LEGEND_ITEM_HEIGHT,e){var r=t.measureString(e,wjcChart.FlexChart._CSS_LABEL,wjcChart.FlexChart._CSS_LEGEND);i.width+=r.width,i.height<r.height&&(i.height=r.height)}return i.width+=3*wjcChart.Series._LEGEND_ITEM_MARGIN,i.height+=2*wjcChart.Series._LEGEND_ITEM_MARGIN,i}_getDesiredLegendSize(t,e,i,r){var a=new wjcCore.Size,s=new wjcCore.Size(i,r),l=this._tmItems.length,h=0,o=0;this._colRowLens=[];for(var n=0;n<l;n++){var c=this._measureLegendItem(t,this._tmItems[n].label);e?(o+c.height>r&&(a.height=r,this._colRowLens.push(h),h=0,o=0),h<c.width&&(h=c.width),o+=c.height):(h+c.width>i&&(a.width=i,this._colRowLens.push(o),o=0,h=0),o<c.height&&(o=c.height),h+=c.width)}return e?(a.height<o&&(a.height=o),this._colRowLens.push(h),a.width=this._colRowLens.reduce((t,e)=>t+e,0),a.width>s.width/2&&(a.width=s.width/2)):(a.width<h&&(a.width=h),this._colRowLens.push(o),a.height=this._colRowLens.reduce((t,e)=>t+e,0),a.height>s.height/2&&(a.height=s.height/2)),a}_renderLegend(t,e,i,r,a,s){for(var l,h=this._rectLegend,o=this._tmItems.length,n=0,c=e.clone(),_=0;_<o;_++){l=this._tmItems[_].label;var d=this._measureLegendItem(t,l);r?c.y+d.height>h.top+h.height+1&&(c.x+=this._colRowLens[n],n++,c.y=e.y):c.x+d.width>h.left+h.width+1&&(c.y+=this._colRowLens[n],n++,c.x=e.x);var m=new wjcCore.Rect(c.x,c.y,d.width,d.height);this._drawLegendItem(t,m,_,l),i.push(m),r?c.y+=d.height:c.x+=d.width}}_drawLegendItem(t,e,i,r){t.strokeWidth=1;var a=wjcChart.Series._LEGEND_ITEM_MARGIN,s=this._getColor(i),l=s&&s.maxColor?s.maxColor:s,h=this._getLightColor(l);t.fill=l,t.stroke=h;var o=e.top+.5*e.height,n=wjcChart.Series._LEGEND_ITEM_WIDTH,c=wjcChart.Series._LEGEND_ITEM_HEIGHT;t.drawRect(e.left+a,o-.5*c,n,c,null),r&&wjcChart.FlexChart._renderText(t,r,new wjcCore.Point(e.left+c+2*a,o),0,1,wjcChart.FlexChart._CSS_LABEL)}_getLabelContent(t,e){return wjcCore.isString(e)?this._keywords.replace(e,t):wjcCore.isFunction(e)?e(t):null}hitTest(t,e){var i=this._toControl(t,e),r=new wjcChart.HitTestInfo(this,i),a=null;if(wjcChart.FlexChart._contains(this._rectHeader,i))r._chartElement=wjcChart.ChartElement.Header;else if(wjcChart.FlexChart._contains(this._rectFooter,i))r._chartElement=wjcChart.ChartElement.Footer;else if(wjcChart.FlexChart._contains(this._rectLegend,i))r._chartElement=wjcChart.ChartElement.Legend,null!==(a=this.legend._hitTest(i))&&a>=0&&a<this._areas.length&&r._setData(null,a);else if(wjcChart.FlexChart._contains(this._rectChart,i)){for(var s,l=this._areas.length,h=NaN,o=0;o<l;o++){var n=i.clone(),c=this._areas[o];c.contains(n)&&(r._setData(null,c.tag),r._dist=0);var _=c.distance(n);void 0!==_&&(isNaN(h)||_<h)&&(h=_,s=c)}0!==r._dist&&null!=s&&(r._setData(null,s.tag),r._dist=h),r._chartElement=wjcChart.ChartElement.ChartArea}else r._chartElement=wjcChart.ChartElement.None;return r}_getHitTestItem(t){var e=null,i=null;return(e=null!=this._cv?this._cv.items:this.itemsSource)&&t<e.length&&(i=e[t]),i}_getHitTestValue(t){return this._values[t]}_getHitTestLabel(t){return this._labels[t]}};TreeMap._CSS_ITEMDEPTH="wj-treemap-item-depth",TreeMap._MARGIN=0;class _TreeMapItem{constructor(){this.items=[],this.maxValue=Number.MIN_VALUE,this.minValue=Number.MAX_VALUE}draw(t){var e=this.rect;t.strokeWidth=0,this.isTitle?(t.fill=this.titleFill,t.stroke=this.titleStroke):(t.fill=this.fill,t.stroke=this.stroke),t.drawRect(e.left,e.top,e.width,e.height,_TreeMapItem._CLASSNAME)}get itemsRect(){var t=this.rect,e=this._rect,i=1===this.depth?2:.5;return this.isTitle?this.type===TreeMapType.Horizontal?new wjcCore.Rect(t.left+t.width+1,t.top,e.width-t.width-2*i,t.height+1):new wjcCore.Rect(t.left,t.top+t.height+1,t.width+1,e.height-t.height-2*i):new wjcCore.Rect(0,0,0,0)}get rect(){var t=this._rect,e=1===this.depth?2:.5,i=t.width,r=t.height,a=t.left,s=t.top;return this.isTitle?(this.type===TreeMapType.Horizontal?(i=t.width>20?20:i,i=Math.max(20,i-2*e),r=r>2*e?r-2*e:0):(r=t.height>20?20:r,r=Math.max(20,r-2*e),i=i>2*e?i-2*e:0),a+=e,s+=e):(i=i>2*e?i-2*e:0,r=r>2*e?r-2*e:0),new wjcCore.Rect(a,s,i,r)}set rect(t){t!=this._rect&&(this._rect=t)}get isTitle(){return this._isTitle}set isTitle(t){var e=wjcCore.asBoolean(t,!0);e!==this._isTitle&&(this._isTitle=e)}}_TreeMapItem._CLASSNAME="wj-treemap-item";class _ColorConverter{constructor(t,e,i,r,a,s){this.minColor=new wjcCore.Color(t),this.minColorValue=e,this.maxColor=new wjcCore.Color(i),this.maxColorValue=r,this.midColorValue=this.originalMidColorValue=s,this._calculateMidColorValue(),this.midColor=this.originalMidColor=new wjcCore.Color(a),this._calculateMidColor()}_resetminColor(t){this.minColor=new wjcCore.Color(t),this._calculateMidColor()}_resetmidColor(t){this.midColor=this.originalMidColor=new wjcCore.Color(t),this._calculateMidColor()}_resetmaxColor(t){this.maxColor=new wjcCore.Color(t),this._calculateMidColor()}_resetminColorValue(t){this.minColorValue=t,this._calculateMidColorValue()}_resetmidColorValue(t){this.midColorValue=this.originalMidColorValue=t,this._calculateMidColorValue()}_resetmaxColorValue(t){this.maxColorValue=t,this._calculateMidColorValue()}_calculateMidColorValue(){null==this.originalMidColorValue&&(this.midColorValue=(this.maxColorValue+this.minColorValue)/2)}_calculateMidColor(){null==this.originalMidColor&&(this.midColor=this._calculateColorByVal(this.midColorValue,!0))}_calculateColorByVal(t,e=!1){var i=this.maxColor,r=this.minColor,a=this.maxColorValue,s=this.minColorValue;if(t>=this.maxColorValue)return new wjcCore.Color(i.toString());if(t<=this.minColorValue)return new wjcCore.Color(r.toString());if(!e){if(t===this.midColorValue)return new wjcCore.Color(this.midColor.toString());t<this.midColorValue?(i=this.midColor,a=this.midColorValue):(r=this.midColor,s=this.midColorValue)}return this._getColor(t,i,a,r,s)}_getColor(t,e,i,r,a){return wjcCore.Color.fromRgba(this._getValueByRatio(t,e.r,i,r.r,a),this._getValueByRatio(t,e.g,i,r.g,a),this._getValueByRatio(t,e.b,i,r.b,a),this._getValueByRatio(t,e.a,i,r.a,a))}_getValueByRatio(t,e,i,r,a){return Math.abs(r+Math.round((t-a)*(e-r)/(i-a)))}}class _TreeMapUtils{static squarified(t,e,i){var r=t.slice(),a=e.clone(),s=a.width*a.height/i;do{var l=_TreeMapUtils.getRowedItems(r,a,s);_TreeMapUtils.layoutRowedItems(e,l,a,a.width>a.height)}while(r.length)}static horizontal(t,e,i){var r=e.clone();t.forEach(t=>{var a=[{item:t,val:t.value*e.width*e.height/i}];_TreeMapUtils.layoutRowedItems(e,a,r,!1)})}static vertical(t,e,i){var r=e.clone();t.forEach(t=>{var a=[{item:t,val:t.value*e.width*e.height/i}];_TreeMapUtils.layoutRowedItems(e,a,r,!0)})}static getNarrowLen(t){return Math.min(t.width,t.height)}static getRowedItem(t,e,i){return{item:t,val:i*t.value}}static getRowedItems(t,e,i){var r=t.shift(),a=[],s=[],l=_TreeMapUtils.getNarrowLen(e),h=_TreeMapUtils.getRowedItem(r,e,i);if(a.push(h),s.push(h),t.length>0)do{if(s.push(_TreeMapUtils.getRowedItem(t[0],e,i)),!(_TreeMapUtils.worst(a,l)>_TreeMapUtils.worst(s,l)))break;a=s.slice(),t.shift()}while(t.length);return a}static layoutRowedItems(t,e,i,r){var a,s=i.left,l=i.top,h=s+i.width,o=l+i.height,n=_TreeMapUtils.sumRowedArray(e);r?(a=0===i.height?0:n/i.height,s+a>=h&&(a=h-s),e.forEach((t,i)=>{var r=0===a?0:t.val/a;(l+r>o||i===e.length-1)&&(r=o-l);var h=new wjcCore.Rect(s,l,a,r);t.item.rect=h,l+=r}),i.left+=a,i.width-=a):(a=0===i.width?0:n/i.width,l+a>=o&&(a=o-l),e.forEach((t,i)=>{var r=0===a?0:t.val/a;(s+r>h||i===e.length-1)&&(r=h-s);var o=new wjcCore.Rect(s,l,r,a);t.item.rect=o,s+=r}),i.top+=a,i.height-=a)}static sumRowedArray(t){for(var e=0,i=t.length,r=0;r<i;r++)e+=t[r].val;return e}static worst(t,e){var i,r,a=_TreeMapUtils.sumRowedArray(t),s=a*a,l=e*e;return i=r=t[0].val,t.forEach((t,e)=>{t.val>i?i=t.val:t.val<r&&(r=t.val)}),Math.max(l*i/s,s/(l*r))}}export class HierarchicalUtil{static parseDataToHierarchical(t,e,i,r){var a,s=[];return t instanceof wjcCore.CollectionView&&t.groups.length>0?s=HierarchicalUtil.parseGroupCV(t,e):t.length>0&&(wjcCore.isString(i)&&i.indexOf(",")>-1&&(i=i.split(",")),r?s=HierarchicalUtil.parseItems(t,e,i,r):(a=HierarchicalUtil.convertFlatData(t,e,i),s=HierarchicalUtil.parseItems(a,"value",i,"items"))),s}static parseGroupCV(t,e){for(var i=[],r=0,a=t.groups.length;r<a;r++){var s=this.parseGroups(t.groups[r],e);i.push(s)}return i}static parseGroups(t,e){var i={};if(i.name=t.name,i.nameField=t.groupDescription.propertyName,i.item=t.items,t.groups&&t.groups.length){i.items=[];for(var r=0,a=t.groups.length;r<a;r++){var s=this.parseGroups(t.groups[r],e);i.items.push(s)}}else t.isBottomLevel&&(i.value=t.getAggregate(wjcCore.Aggregate.Sum,e));return i}static parseItems(t,e,i,r){var a,s=[],l=t.length;for(a=0;a<l;a++)s.push(HierarchicalUtil.parseItem(t[a],e,i,r));return s}static isFlatItem(t,e){return!wjcCore.isArray(t[e])}static convertFlatData(t,e,i){var r,a,s=[],l={},h=t.length;for(r=0;r<h;r++)a=t[r],HierarchicalUtil.convertFlatItem(l,a,e,wjcCore.isArray(i)?i:[i]);return HierarchicalUtil.convertFlatToHierarchical(s,l),s}static convertFlatToHierarchical(t,e){var i=e.flatDataOrder;i&&i.forEach(i=>{var r,a={},s=e[i];a[e.field]=i,s.flatDataOrder?(r=[],HierarchicalUtil.convertFlatToHierarchical(r,s),a.items=r):a.value=s,t.push(a)})}static convertFlatItem(t,e,i,r){var a,s,l,h;return a=r.slice(),s=a.shift(),s=wjcCore.isString(s)?s.trim():s,null!=(l=null==s?i:e[s])&&(0===a.length?(t[l]=e[i]||0,t.flatDataOrder?t.flatDataOrder.push(l):t.flatDataOrder=[l],t.field=s):(null==t[l]&&(t[l]={},t.flatDataOrder?t.flatDataOrder.push(l):t.flatDataOrder=[l],t.field=s),h=t[l],HierarchicalUtil.convertFlatItem(h,e,i,a)||(t[l]=e[i])),!0)}static parseItem(t,e,i,r){var a,s,l,h,o,n={};return wjcCore.isArray(r)?h=(o=r.slice()).length?o.shift().trim():"":(o=r,h=r),wjcCore.isArray(i)?(s=null==(s=(a=i.slice()).shift())?s:s.trim(),n.nameField=null==s?e:s,n.name=null==s?t[e]:t[s],l=t[h],0===a.length?n.value=t[e]:l&&wjcCore.isArray(l)&&l.length>0?n.items=HierarchicalUtil.parseItems(l,e,a,o):n.value=t[e]||0):(n.nameField=null==i?e:i,n.name=null==i?t[e]:t[i],null!=(l=t[h])&&wjcCore.isArray(l)&&l.length>0?n.items=HierarchicalUtil.parseItems(l,e,i,o):n.value=t[e]),n.item=t,n}static parseFlatItem(t,e,i,r){t.items||(t.items=[])}};