highcharts
Version:
JavaScript charting framework
11 lines • 29.3 kB
JavaScript
/**
* Highcharts JS v13.0.1 (2026-08-17)
* @module highcharts/modules/treemap
* @requires highcharts
*
* (c) 2014-2026 Highsoft AS
* Authors: Jon Arild Nygård / Øystein Moseng
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as t from"../highcharts.js";let e={};e.n=t=>{let i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},e.d=(t,i)=>{if(Array.isArray(i))for(var s=0;s<i.length;){var o=i[s++],r=i[s++];e.o(t,o)?0===r&&s++:0===r?Object.defineProperty(t,o,{enumerable:!0,value:i[s++]}):Object.defineProperty(t,o,{enumerable:!0,get:r})}else for(var o in i)e.o(i,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:i[o]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var s,o,r=e.n(i);let l={mainBreadcrumb:"Main"},a=t.default.Templating,{format:n}=e.n(a)(),{composed:h}=r();function d(){if(this.breadcrumbs){let t=this.resetZoomButton&&this.resetZoomButton.getBBox(),e=this.breadcrumbs.options;t&&"right"===e.position.align&&"plotBox"===e.relativeTo&&this.breadcrumbs.alignBreadcrumbsGroup(-t.width-e.buttonSpacing)}}function p(){this.breadcrumbs&&(this.breadcrumbs.destroy(),this.breadcrumbs=void 0)}function u(){let t=this.breadcrumbs;if(t&&!t.options.floating&&t.level){let e=t.options,i=e.buttonTheme,s=(i.height||0)+2*(i.padding||0)+e.buttonSpacing,o=e.position.verticalAlign;"bottom"===o?(this.marginBottom=(this.marginBottom||0)+s,t.yOffset=s):"middle"!==o?(this.plotTop+=s,t.yOffset=-s):t.yOffset=void 0}}function c(){this.breadcrumbs&&this.breadcrumbs.redraw()}function g(t){!0===t.resetSelection&&this.breadcrumbs&&this.breadcrumbs.alignBreadcrumbsGroup()}class v{static compose(t,e){(0,i.pushUnique)(h,"Breadcrumbs")&&((0,i.addEvent)(t,"destroy",p),(0,i.addEvent)(t,"afterShowResetZoom",d),(0,i.addEvent)(t,"getMargins",u),(0,i.addEvent)(t,"redraw",c),(0,i.addEvent)(t,"selection",g),(0,i.extend)(e.lang,l))}constructor(t,e){this.elementList={},this.isDirty=!0,this.level=0,this.list=[];let s=(0,i.merge)(t.options.drilldown&&t.options.drilldown.drillUpButton,v.defaultOptions,t.options.navigation&&t.options.navigation.breadcrumbs,e);this.chart=t,this.options=s||{}}updateProperties(t){this.setList(t),this.setLevel(),this.isDirty=!0}setList(t){this.list=t}setLevel(){this.level=this.list.length&&this.list.length-1}getLevel(){return this.level}getButtonText(t){let e=this.chart,s=this.options,o=e.options.lang,r=(0,i.pick)(s.format,s.showFullPath?"{level.name}":"← {level.name}"),l=o&&(0,i.pick)(o.drillUpText,o.mainBreadcrumb),a=s.formatter&&s.formatter(t)||n(r,{level:t.levelOptions},e)||"";return((0,i.isString)(a)&&!a.length||"← "===a)&&(0,i.defined)(l)&&(a=s.showFullPath?l:"← "+l),a}redraw(){this.isDirty&&this.render(),this.group&&this.group.align(),this.isDirty=!1}render(){let t=this.chart,e=this.options;!this.group&&e&&(this.group=t.renderer.g("breadcrumbs-group").addClass("highcharts-no-tooltip highcharts-breadcrumbs").attr({zIndex:e.zIndex}).add()),e.showFullPath?this.renderFullPathButtons():this.renderSingleButton(),this.alignBreadcrumbsGroup()}renderFullPathButtons(){this.destroySingleButton(),this.resetElementListState(),this.updateListElements(),this.destroyListElements()}renderSingleButton(){let t=this.chart,e=this.list,i=this.options.buttonSpacing;this.destroyListElements();let s=this.group?this.group.getBBox().width:i,o=e[e.length-2];!t.drillUpButton&&this.level>0?t.drillUpButton=this.renderButton(o,s,i):t.drillUpButton&&(this.level>0?this.updateSingleButton():this.destroySingleButton())}alignBreadcrumbsGroup(t){if(this.group){let e=this.options,s=e.buttonTheme,o=e.position,r="chart"===e.relativeTo||"spacingBox"===e.relativeTo?void 0:"plotBox",l=this.group.getBBox(),a=2*(s.padding||0)+e.buttonSpacing;o.width=l.width+a,o.height=l.height+a;let n=(0,i.merge)(o);t&&(n.x+=t),this.options.rtl&&(n.x+=o.width),n.y=(0,i.pick)(n.y,this.yOffset,0),this.group.align(n,!0,r)}}renderButton(t,e,s){let o=this,r=this.chart,l=o.options,a=(0,i.merge)(l.buttonTheme),n=r.renderer.button(o.getButtonText(t),e,s,function(e){let s,r=l.events&&l.events.click;r&&(s=r.call(o,e,t,o)),!1!==s&&(l.showFullPath?e.newLevel=t.level:e.newLevel=o.level-1,(0,i.fireEvent)(o,"up",e))},a).addClass("highcharts-breadcrumbs-button").add(o.group);return r.styledMode||n.attr(l.style),n}renderSeparator(t,e){let i=this.chart,s=this.options.separator,o=i.renderer.label(s.text,t,e,void 0,void 0,void 0,!1).addClass("highcharts-breadcrumbs-separator").add(this.group);return i.styledMode||o.css(s.style),o}update(t){(0,i.merge)(!0,this.options,t),this.destroy(),this.isDirty=!0}updateSingleButton(){let t=this.chart,e=this.list[this.level-1];t.drillUpButton&&t.drillUpButton.attr({text:this.getButtonText(e)})}destroy(){this.destroySingleButton(),this.destroyListElements(!0),this.group&&this.group.destroy(),this.group=void 0}destroyListElements(t){let e=this.elementList;(0,i.objectEach)(e,(i,s)=>{(t||!e[s].updated)&&((i=e[s]).button&&i.button.destroy(),i.separator&&i.separator.destroy(),delete i.button,delete i.separator,delete e[s])}),t&&(this.elementList={})}destroySingleButton(){this.chart.drillUpButton&&(this.chart.drillUpButton.destroy(),this.chart.drillUpButton=void 0)}resetElementListState(){(0,i.objectEach)(this.elementList,t=>{t.updated=!1})}updateListElements(){let t=this.elementList,e=this.options.buttonSpacing,i=this.list,s=this.options.rtl,o=s?-1:1,r=function(t,e){return o*t.getBBox().width+o*e},l=function(t,e,i){t.translate(e-t.getBBox().width,i)},a=this.group?r(this.group,e):e,n,h;for(let d=0,p=i.length;d<p;++d){let u,c,g=d===p-1;t[(h=i[d]).level]?(u=(n=t[h.level]).button,n.separator||g?n.separator&&g&&(n.separator.destroy(),delete n.separator):(a+=o*e,n.separator=this.renderSeparator(a,e),s&&l(n.separator,a,e),a+=r(n.separator,e)),t[h.level].updated=!0):(u=this.renderButton(h,a,e),s&&l(u,a,e),a+=r(u,e),g||(c=this.renderSeparator(a,e),s&&l(c,a,e),a+=r(c,e)),t[h.level]={button:u,separator:c,updated:!0}),u&&u.setState(2*!!g)}}}v.defaultOptions={buttonSpacing:5,buttonTheme:{fill:"none",height:18,padding:2,"stroke-width":0,zIndex:7,states:{select:{fill:"none"}},style:{color:"var(--highcharts-highlight-color-80)"}},floating:!1,format:void 0,relativeTo:"plotBox",rtl:!1,position:{align:"left",verticalAlign:"top",x:0,y:void 0},separator:{text:"/",style:{color:"var(--highcharts-neutral-color-60)",fontSize:"0.8em"}},showFullPath:!0,style:{},useHTML:!1,zIndex:7};let m=t.default.Color;var b=e.n(m);let f=t.default.SeriesRegistry;var y=e.n(f);let x=t.default.SVGElement;var T=e.n(x);let{column:{prototype:w}}=y().seriesTypes;var L=s||(s={});function A(t){let e=this.series,i=e.chart.renderer;this.moveToTopOnHover&&this.graphic&&(e.stateMarkerGraphic||(e.stateMarkerGraphic=new(T())(i,"use").css({pointerEvents:"none"}).add(this.graphic.parentGroup)),t?.state==="hover"?(this.graphic.attr({id:this.id}),e.stateMarkerGraphic.attr({href:`${i.url}#${this.id}`,visibility:"visible"})):e.stateMarkerGraphic.attr({href:""}))}L.pointMembers={dataLabelOnNull:!0,moveToTopOnHover:!0,isValid:function(){return null!==this.value&&this.value!==1/0&&this.value!==-1/0&&(void 0===this.value||!isNaN(this.value))}},L.seriesMembers={colorKey:"value",axisTypes:["xAxis","yAxis","colorAxis"],parallelArrays:["x","y","value"],pointArrayMap:["value"],trackerGroups:["group","markerGroup","dataLabelsGroup"],colorAttribs:function(t){let e={};return(0,i.defined)(t.color)&&(!t.state||"normal"===t.state)&&(e[this.colorProp||"fill"]=t.color),e},pointAttribs:w.pointAttribs},L.compose=function(t){let e=t.prototype.pointClass;return(0,i.addEvent)(e,"afterSetState",A),t};let B=s,O=t.default.Series;var P=e.n(O);let S=class{constructor(t,e,i,s){this.height=t,this.width=e,this.plot=s,this.direction=i,this.startDirection=i,this.total=0,this.nW=0,this.lW=0,this.nH=0,this.lH=0,this.elArr=[],this.lP={total:0,lH:0,nH:0,lW:0,nW:0,nR:0,lR:0,aspectRatio:function(t,e){return Math.max(t/e,e/t)}}}addElement(t){this.lP.total=this.elArr[this.elArr.length-1],this.total=this.total+t,0===this.direction?(this.lW=this.nW,this.lP.lH=this.lP.total/this.lW,this.lP.lR=this.lP.aspectRatio(this.lW,this.lP.lH),this.nW=this.total/this.height,this.lP.nH=this.lP.total/this.nW,this.lP.nR=this.lP.aspectRatio(this.nW,this.lP.nH)):(this.lH=this.nH,this.lP.lW=this.lP.total/this.lH,this.lP.lR=this.lP.aspectRatio(this.lP.lW,this.lH),this.nH=this.total/this.width,this.lP.nW=this.lP.total/this.nH,this.lP.nR=this.lP.aspectRatio(this.lP.nW,this.nH)),this.elArr.push(t)}reset(){this.nW=0,this.lW=0,this.elArr=[],this.total=0}},N=function(t,e){let{animatableAttribs:i,onComplete:s,css:o,renderer:r}=e,l=t.series&&t.series.chart.hasRendered?void 0:t.series&&t.series.options.animation,a=t.graphic;if(e.attribs={...e.attribs,class:t.getClassName()},t.shouldDraw())a||(t.graphic=a="text"===e.shapeType?r.text():"image"===e.shapeType?r.image(e.imageUrl||"").attr(e.shapeArgs||{}):r[e.shapeType](e.shapeArgs||{}),a.add(e.group)),o&&a.css(o),a.attr(e.attribs).animate(i,!e.isNew&&l,s);else if(a){let e=()=>{t.graphic=a=a&&a.destroy(),"function"==typeof s&&s()};Object.keys(i).length?a.animate(i,void 0,()=>e()):e()}},{pie:{prototype:{pointClass:C}},scatter:{prototype:{pointClass:M}}}=y().seriesTypes;class k extends M{constructor(){super(...arguments),this.groupedPointsAmount=0,this.shapeType="rect"}draw(t){N(this,t)}getClassName(){let t=this.series,e=t.options,s=super.getClassName();return this.node.level<=t.nodeMap[t.rootNode].level&&this.node.children.length?s+=" highcharts-above-level":this.node.isGroup||this.node.isLeaf||t.nodeMap[t.rootNode].isGroup||(0,i.pick)(e.interactByLeaf,!e.allowTraversingTree)?this.node.isGroup||this.node.isLeaf||t.nodeMap[t.rootNode].isGroup||(s+=" highcharts-internal-node"):s+=" highcharts-internal-node-interactive",s}isValid(){return!!(this.id||(0,i.isNumber)(this.value))}setState(t){super.setState.apply(this,arguments),this.graphic&&this.graphic.attr({zIndex:+("hover"===t)})}shouldDraw(){return(0,i.isNumber)(this.plotY)&&null!==this.y}}(0,i.extend)(k.prototype,{setVisible:C.prototype.setVisible});let D={allowTraversingTree:!1,animationLimit:250,borderRadius:0,showInLegend:!1,marker:void 0,colorByPoint:!1,dataLabels:{enabled:!0,formatter:function(){let t=this&&this.point?this.point:{};return(0,i.isString)(t.name)?t.name:""},headers:!1,inside:!0,padding:2,verticalAlign:"middle",style:{textOverflow:"ellipsis"}},tooltip:{headerFormat:"",pointFormat:"<b>{point.name}</b>: {point.value}<br/>",clusterFormat:"+ {point.groupedPointsAmount} more...<br/>"},ignoreHiddenPoint:!0,layoutAlgorithm:"sliceAndDice",layoutStartingDirection:"vertical",alternateStartingDirection:!1,levelIsConstant:!0,traverseUpButton:{position:{align:"right",x:-10,y:10}},borderColor:"var(--highcharts-neutral-color-10)",borderWidth:1,colorKey:"colorValue",opacity:.15,states:{hover:{borderColor:"var(--highcharts-neutral-color-40)",brightness:.1*!y().seriesTypes.heatmap,halo:!1,opacity:.75,shadow:!1}},legendSymbol:"rectangle",traverseToLeaf:!1,cluster:{className:void 0,color:void 0,enabled:!1,pixelWidth:void 0,pixelHeight:void 0,name:void 0,reductionFactor:void 0,minimumClusterSize:5,layoutAlgorithm:{distance:0,gridSize:0,kmeansThreshold:0},marker:{lineWidth:0,radius:0}}};(o||(o={})).recursive=function t(e,i,s){let o=i.call(s||this,e);!1!==o&&t(o,i,s)};let I=o,{parse:E}=b(),{composed:R,noop:G}=r(),{column:U,scatter:V}=y().seriesTypes,{getColor:W,getLevelOptions:H,updateRootId:F}={getColor:function(t,e){let s,o,r,l,a,n,h=e.index,d=e.mapOptionsToLevel,p=e.parentColor,u=e.parentColorIndex,c=e.series,g=e.colors,v=e.siblings,m=c.points,f=c.chart.options.chart;if(t){let y;s=m[t.i],o=d[t.level]||{},s&&o.colorByPoint&&(l=s.index%(g?g.length:f.colorCount),r=g&&g[l]),c.chart.styledMode||(a=(0,i.pick)(s&&s.options.color,o&&o.color,r,p&&((y=o&&o.colorVariation)&&"brightness"===y.key&&h&&v?b().parse(p).brighten(y.to*(h/v)).get():p),c.color)),n=(0,i.pick)(s&&s.options.colorIndex,o&&o.colorIndex,l,u,e.colorIndex)}return{color:a,colorIndex:n}},getLevelOptions:function(t){let e,s,o,r,l,a,n={};if((0,i.isObject)(t))for(r=(0,i.isNumber)(t.from)?t.from:1,a=t.levels,s={},e=(0,i.isObject)(t.defaults)?t.defaults:{},(0,i.isArray)(a)&&(s=a.reduce((t,s)=>{let o,l,a;return(0,i.isObject)(s)&&(0,i.isNumber)(s.level)&&(a=(0,i.merge)({},s),l=(0,i.pick)(a.levelIsConstant,e.levelIsConstant),delete a.levelIsConstant,delete a.level,o=s.level+(l?0:r-1),(0,i.isObject)(t[o])?(0,i.merge)(!0,t[o],a):t[o]=a),t},{})),l=(0,i.isNumber)(t.to)?t.to:1,o=0;o<=l;o++)n[o]=(0,i.merge)({},e,(0,i.isObject)(s[o])?s[o]:{});return n},getNodeWidth:function(t,e){let{chart:s,options:o}=t,{nodeDistance:r=0,nodeWidth:l=0}=o,{plotSizeX:a=1}=s;if("auto"===l){if("string"==typeof r&&/%$/.test(r))return a/(e+parseFloat(r)/100*(e-1));let t=Number(r);return(a+t)/(e||1)-t}return(0,i.relativeLength)(l,a)},setTreeValues:function t(e,s){let o=s.before,r=s.idRoot,l=s.mapIdToNode[r],a=!1!==s.levelIsConstant,n=s.points[e.i],h=n&&n.options||{},d=[],p=0;e.levelDynamic=e.level-(a?0:l.level),e.name=(0,i.pick)(n&&n.name,""),e.visible=r===e.id||!0===s.visible,"function"==typeof o&&(e=o(e,s)),e.children.forEach((o,r)=>{let l=(0,i.extend)({},s);(0,i.extend)(l,{index:r,siblings:e.children.length,visible:e.visible}),o=t(o,l),d.push(o),o.visible&&(p+=o.val)});let u=(0,i.pick)(h.value,p);return e.visible=u>=0&&(p>0||e.visible),e.children=d,e.childrenTotal=p,e.isLeaf=e.visible&&!p,e.val=u,e},updateRootId:function(t){let e,s;return(0,i.isObject)(t)&&(s=(0,i.isObject)(t.options)?t.options:{},e=(0,i.pick)(t.rootNode,s.rootId,""),(0,i.isObject)(t.userOptions)&&(t.userOptions.rootId=e),t.rootNode=e),e}};P().keepProps.push("simulation","hadOutsideDataLabels");let j=!1;function z(){let t=this.xAxis,e=this.yAxis;if(t&&e)if(this.is("treemap")){let s={endOnTick:!1,startOnTick:!1,visible:!1};this.is("treegraph")||(s.min=0,s.max=100,s.tickPositions=[]),(0,i.merge)(!0,t.options,s,t.userOptions),(0,i.merge)(!0,e.options,s,e.userOptions),t.visible=t.options.visible,e.visible=e.options.visible,this.is("treegraph")&&(this.isCartesian=t.visible),j=!0}else j&&(e.setOptions(e.userOptions),t.setOptions(t.userOptions),j=!1)}class $ extends V{constructor(){super(...arguments),this.simulation=0}static compose(t){(0,i.pushUnique)(R,"TreemapSeries")&&(0,i.addEvent)(t,"afterBindAxes",z)}algorithmCalcPoints(t,e,s,o){let r=s.plot,l=s.elArr.length-1,a,n,h,d,p=s.lW,u=s.lH,c,g=0;for(let t of(e?(p=s.nW,u=s.nH):c=s.elArr[l],s.elArr))(e||g<l)&&(0===s.direction?(a=r.x,n=r.y,d=t/(h=p)):(a=r.x,n=r.y,h=t/(d=u)),o.push({x:a,y:n,width:h,height:(0,i.correctFloat)(d)}),0===s.direction?r.y=r.y+d:r.x=r.x+h),g+=1;s.reset(),0===s.direction?s.width=s.width-p:s.height=s.height-u,r.y=r.parent.y+(r.parent.height-s.height),r.x=r.parent.x+(r.parent.width-s.width),t&&(s.direction=1-s.direction),e||s.addElement(c)}algorithmFill(t,e,i){let s=[],o,r=e.direction,l=e.x,a=e.y,n=e.width,h=e.height,d,p,u,c;for(let g of i)o=e.width*e.height*(g.val/e.val),d=l,p=a,0===r?(n-=u=o/(c=h),l+=u):(h-=c=o/(u=n),a+=c),s.push({x:d,y:p,width:u,height:c,direction:0,val:0}),t&&(r=1-r);return s}algorithmLowAspectRatio(t,e,i){let s=[],o={x:e.x,y:e.y,parent:e},r=e.direction,l=i.length-1,a=new S(e.height,e.width,r,o),n,h=0;for(let r of i)n=e.width*e.height*(r.val/e.val),a.addElement(n),a.lP.nR>a.lP.lR&&this.algorithmCalcPoints(t,!1,a,s,o),h===l&&this.algorithmCalcPoints(t,!0,a,s,o),++h;return s}alignDataLabel(t,e,i){U.prototype.alignDataLabel.apply(this,arguments),t.dataLabel&&t.dataLabel.attr({zIndex:(t.node.zIndex||0)+1})}applyTreeGrouping(){let t=this,e=t.parentList||{},{cluster:s}=t.options,o=s?.minimumClusterSize||5;if(s?.enabled){let r={},l=t=>{if(t?.point?.shapeArgs){let{width:e=0,height:o=0}=t.point.shapeArgs,{pixelWidth:l=0,pixelHeight:a=0}=s,n=(0,i.defined)(a),h=a?l*a:l*l;(e<l||o<(n?a:l)||e*o<h)&&!t.isGroup&&(0,i.defined)(t.parent)&&(r[t.parent]||(r[t.parent]=[]),r[t.parent].push(t))}t?.children.forEach(t=>{l(t)})};for(let a in l(t.tree),r)r[a]&&r[a].length>o&&r[a].forEach(o=>{let r=e[a].indexOf(o.i);if(-1!==r){e[a].splice(r,1);let l=`highcharts-grouped-treemap-points-${o.parent||"root"}`,n=t.points.find(t=>t.id===l);if(!n){let o=t.pointClass,r=t.points.length;n=new o(t,{className:s.className,color:s.color,id:l,index:r,isGroup:!0,value:0}),(0,i.extend)(n,{formatPrefix:"cluster"}),t.points.push(n),e[a].push(r),e[l]=[]}let h=n.groupedPointsAmount+1,d=t.points[n.index].options.value||0,p=s.name||`+ ${h}`;t.points[n.index].groupedPointsAmount=h,t.points[n.index].options.value=d+(o.point.value||0),t.points[n.index].name=p,e[l].push(o.point.index)}});t.nodeMap={},t.nodeList=[],t.parentList=e;let a=t.buildTree("",-1,0,t.parentList);t.translate(a)}}calculateChildrenAreas(t,e){let s=this.options,o=this.mapOptionsToLevel[t.level+1],r=(0,i.pick)(o?.layoutAlgorithm&&this[o?.layoutAlgorithm]&&o.layoutAlgorithm,s.layoutAlgorithm),l=s.alternateStartingDirection,a=t.children.filter(e=>t.isGroup||!e.ignore),n=o?.groupPadding??s.groupPadding??0,h=this.nodeMap[this.rootNode];if(!r)return;let d=[],p=h.pointValues?.width||0,u=h.pointValues?.height||0;o?.layoutStartingDirection&&(e.direction=+("vertical"!==o.layoutStartingDirection)),d=this[r](e,a);let c=-1;for(let t of a){let s=d[++c];t===h&&(p=p||s.width,u=s.height);let o=n/(this.xAxis.len/u),r=n/(this.yAxis.len/u);if(t.values=(0,i.merge)(s,{val:t.childrenTotal,direction:l?1-e.direction:e.direction}),t.children.length&&t.point.dataLabels?.length){let e=(0,i.arrayMax)(t.point.dataLabels.map(t=>t.options?.headers&&t.height||0))/(this.yAxis.len/u);e<t.values.height/2&&(t.values.y+=e,t.values.height-=e)}if(n){let e=Math.min(o,t.values.width/4),i=Math.min(r,t.values.height/4);t.values.x+=e,t.values.width-=2*e,t.values.y+=i,t.values.height-=2*i}t.pointValues=(0,i.merge)(s,{x:s.x/this.axisRatio,y:100-s.y-s.height,width:s.width/this.axisRatio}),t.children.length&&this.calculateChildrenAreas(t,t.values)}let g=(t,e=[],i=!0)=>(t.children.forEach(t=>{i&&t.isLeaf?e.push(t.point):i||t.isLeaf||e.push(t.point),t.children.length&&g(t,e,i)}),e);if("leaf"===s.nodeSizeBy&&t===h&&this.hasOutsideDataLabels&&!g(h,void 0,!1).some(t=>(0,i.isNumber)(t.options.value))&&!(0,i.isNumber)(h.point?.options.value)){let s=g(h),o=s.map(t=>t.options.value||0),r=s.map(({node:{pointValues:t}})=>t?t.width*t.height:0),l=o.reduce((t,e)=>t+e,0),a=r.reduce((t,e)=>t+e,0)/l,n=0,d=0;s.forEach((t,e)=>{let s=o[e]?r[e]/o[e]:1,l=(0,i.clamp)(s/a,.8,1.4),h=1-l;t.value&&(r[e]<20&&(h*=r[e]/20),h>d&&(d=h),h<n&&(n=h),t.simulatedValue=(t.simulatedValue||t.value)/l)}),(n<-.05||d>.05)&&this.simulation<10?(this.simulation++,this.setTreeValues(t),e.val=t.val,this.calculateChildrenAreas(t,e)):(s.forEach(t=>{delete t.simulatedValue}),this.setTreeValues(t),this.simulation=0)}}createList(t){let e=this.chart,i=e.breadcrumbs,s=[];if(i){let i=0;s.push({level:i,levelOptions:e.series[0]});let o=t.target.nodeMap[t.newRootId],r=[];for(;o.parent||""===o.parent;)r.push(o),o=t.target.nodeMap[o.parent];for(let t of r.reverse())s.push({level:++i,levelOptions:t});s.length<=1&&(s.length=0)}return s}drawDataLabels(){let t=this.mapOptionsToLevel,e=this.points.filter(function(t){return t.node.visible||(0,i.defined)(t.dataLabel)}),s=(0,i.splat)(this.options.dataLabels||{})[0]?.padding,o=e.some(t=>(0,i.isNumber)(t.plotY));for(let r of e){let e={},l={style:e},a=t[r.node.level];if((!r.node.isLeaf&&!r.node.isGroup||r.node.isGroup&&r.node.level<=this.nodeMap[this.rootNode].level)&&(l.enabled=!1),a?.dataLabels&&((0,i.merge)(!0,l,(0,i.splat)(a.dataLabels)[0]),this.hasDataLabels=()=>!0),r.node.isLeaf?l.inside=!0:l.headers&&(l.verticalAlign="top"),r.shapeArgs&&o){let{height:t=0,width:o=0}=r.shapeArgs;if(o>32&&t>16&&r.shouldDraw()){let a=o-2*((0,i.splat)(l.padding)[0]||(0,i.splat)(s)[0]||0);e.width=`${a}px`,e.lineClamp??(e.lineClamp=Math.floor(t/16)),this.options.allowTraversingTree&&(e.visibility="inherit"),r.dataLabel?.attr({width:l.headers?a:void 0})}else e.width=`${o}px`,e.visibility="hidden"}r.dlOptions=(0,i.merge)(l,r.options.dataLabels,{zIndex:void 0}),delete r.dlOptions.zIndex}super.drawDataLabels(e)}drawPoints(t=this.points){let e=this.chart,s=e.renderer,o=e.styledMode,r=this.options,l=o?{}:r.shadow,a=r.borderRadius,n=e.pointCount<r.animationLimit,h=r.allowTraversingTree;for(let e of t){let t={},d={},p={},u="level-group-"+e.node.level,c=!!e.graphic,g=n&&c,v=e.shapeArgs;e.shouldDraw()&&(e.isInside=!0,a&&(d.r=a),(0,i.merge)(!0,g?t:d,c?v:{},o?{}:this.pointAttribs(e,e.selected?"select":void 0)),this.colorAttribs&&o&&(0,i.extend)(p,this.colorAttribs(e)),this[u]||(this[u]=s.g(u).attr({zIndex:-(e.node.level||0)}).add(this.group),this[u].survive=!0)),e.draw({animatableAttribs:t,attribs:d,css:p,group:this[u],imageUrl:e.imageUrl,renderer:s,shadow:l,shapeArgs:v,shapeType:e.shapeType}),h&&e.graphic&&(e.drillId=r.interactByLeaf?this.drillToByLeaf(e):this.drillToByGroup(e))}}drillToByGroup(t){return(!t.node.isLeaf||!!t.node.isGroup)&&t.id}drillToByLeaf(t){let{traverseToLeaf:e}=t.series.options,i=!1,s;if(t.node.parent!==this.rootNode&&t.node.isLeaf)if(e)i=t.id;else for(s=t.node;!i;)void 0!==s.parent&&(s=this.nodeMap[s.parent]),s.parent===this.rootNode&&(i=s.id);return i}drillToNode(t,e){(0,i.error)(32,!1,void 0,{"treemap.drillToNode":"use treemap.setRootNode"}),this.setRootNode(t,e)}drillUp(){let t=this.nodeMap[this.rootNode];t&&(0,i.isString)(t.parent)&&this.setRootNode(t.parent,!0,{trigger:"traverseUpButton"})}getExtremes(){let{dataMin:t,dataMax:e}=super.getExtremes(this.colorValueData);return this.valueMin=t,this.valueMax=e,super.getExtremes()}getListOfParents(t,e){let s=(0,i.isArray)(t)?t:[],o=(0,i.isArray)(e)?e:[],r=s.reduce(function(t,e,s){let o=(0,i.pick)(e.parent,"");return void 0===t[o]&&(t[o]=[]),t[o].push(s),t},{"":[]});for(let t of Object.keys(r)){let e=r[t];if(""!==t&&-1===o.indexOf(t)){for(let t of e)r[""].push(t);delete r[t]}}return r}getTree(){let t=this.data.map(function(t){return t.id});return this.parentList=this.getListOfParents(this.data,t),this.nodeMap={},this.nodeList=[],this.buildTree("",-1,0,this.parentList||{})}buildTree(t,e,s,o,r){let l=[],a=this.points[e],n=0,h;for(let e of o[t]||[])n=Math.max((h=this.buildTree(this.points[e].id,e,s+1,o,t)).height+1,n),l.push(h),this.is("treegraph")&&(h.visible=!0);let d=new this.NodeClass().init(t,e,l,n,s,this,r);for(let t of l)t.parentNode=d;return this.nodeMap[d.id]=d,this.nodeList.push(d),a&&(a.node=d,d.point=a,(0,i.defined)(a.options.x)||(a.x=s)),d}hasData(){return!!this.dataTable.rowCount}init(t,e){let s=this,o=(0,i.merge)(e.drillUpButton,e.breadcrumbs),r=(0,i.addEvent)(s,"setOptions",t=>{let e=t.userOptions;(0,i.defined)(e.allowDrillToNode)&&!(0,i.defined)(e.allowTraversingTree)&&(e.allowTraversingTree=e.allowDrillToNode,delete e.allowDrillToNode),(0,i.defined)(e.drillUpButton)&&!(0,i.defined)(e.traverseUpButton)&&(e.traverseUpButton=e.drillUpButton,delete e.drillUpButton);let s=(0,i.splat)(e.dataLabels||{});e.levels?.forEach(t=>{s.push.apply(s,(0,i.splat)(t.dataLabels||{}))}),this.hasOutsideDataLabels=s.some(t=>t.headers)});super.init(t,e),delete s.opacity,s.eventsToUnbind.push(r),s.options.allowTraversingTree&&(s.eventsToUnbind.push((0,i.addEvent)(s,"click",s.onClickDrillToNode)),s.eventsToUnbind.push((0,i.addEvent)(s,"setRootNode",function(t){let e=s.chart;e.breadcrumbs&&e.breadcrumbs.updateProperties(s.createList(t))})),s.eventsToUnbind.push((0,i.addEvent)(s,"update",function(t,e){let i=this.chart.breadcrumbs;i&&t.options.breadcrumbs&&i.update(t.options.breadcrumbs),this.hadOutsideDataLabels=this.hasOutsideDataLabels})),s.eventsToUnbind.push((0,i.addEvent)(s,"destroy",function(t){let e=this.chart;e.breadcrumbs&&!t.keepEventsForUpdate&&(e.breadcrumbs.destroy(),e.breadcrumbs=void 0)}))),t.breadcrumbs||(t.breadcrumbs=new v(t,o)),s.eventsToUnbind.push((0,i.addEvent)(t.breadcrumbs,"up",function(t){let e=this.level-t.newLevel;for(let t=0;t<e;t++)s.drillUp()}))}onClickDrillToNode(t){let e=t.point,s=e?.drillId;(0,i.isString)(s)&&(e.setState(""),this.setRootNode(s,!0,{trigger:"click"}))}pointAttribs(t,e){let s=(0,i.isObject)(this.mapOptionsToLevel)?this.mapOptionsToLevel:{},o=t?.node&&s[t.node.level]||{},r=this.options,l=e&&r.states&&r.states[e]||{},a=t?.node&&t.getClassName()||"",n={stroke:t&&t.borderColor||o.borderColor||l.borderColor||r.borderColor,"stroke-width":(0,i.pick)(t&&t.borderWidth,o.borderWidth,l.borderWidth,r.borderWidth),dashstyle:t?.borderDashStyle||o.borderDashStyle||l.borderDashStyle||r.borderDashStyle,fill:t?.color||this.color};return -1!==a.indexOf("highcharts-above-level")?(n.fill="none",n["stroke-width"]=0):-1!==a.indexOf("highcharts-internal-node-interactive")?(n["fill-opacity"]=l.opacity??r.opacity??1,n.cursor="pointer"):-1!==a.indexOf("highcharts-internal-node")?n.fill="none":e&&l.brightness&&(n.fill=E(n.fill).brighten(l.brightness).get()),n}setColorRecursive(t,e,i,s,o){let r=this?.chart,l=r?.options?.colors;if(t){let r=W(t,{colors:l,index:s,mapOptionsToLevel:this.mapOptionsToLevel,parentColor:e,parentColorIndex:i,series:this,siblings:o}),a=this.points[t.i];a&&(a.color=r.color,a.colorIndex=r.colorIndex);let n=-1;for(let e of t.children||[])this.setColorRecursive(e,r.color,r.colorIndex,++n,t.children.length)}}setPointValues(){let t=this,{points:e,xAxis:s,yAxis:o}=t,r=t.chart.styledMode,l=e=>r?0:t.pointAttribs(e)["stroke-width"]||0;for(let t of e){let{pointValues:e,visible:r}=t.node;if(e&&r){let{height:r,width:a,x:n,y:h}=e,d=l(t),p=s.toPixels(n,!0),u=s.toPixels(n+a,!0),c=o.toPixels(h,!0),g=o.toPixels(h+r,!0),v=0===p?d/2:(0,i.crisp)(s.toPixels(n,!0),d,!0),m=u===s.len?s.len-d/2:(0,i.crisp)(s.toPixels(n+a,!0),d,!0),b=c===o.len?o.len-d/2:(0,i.crisp)(o.toPixels(h,!0),d,!0),f=0===g?d/2:(0,i.crisp)(o.toPixels(h+r,!0),d,!0),y={x:Math.min(v,m),y:Math.min(b,f),width:Math.abs(m-v),height:Math.abs(f-b)};t.plotX=y.x+y.width/2,t.plotY=y.y+y.height/2,t.shapeArgs=y}else delete t.plotX,delete t.plotY}}setRootNode(t,e,s){let o=(0,i.extend)({newRootId:t,previousRootId:this.rootNode,redraw:(0,i.pick)(e,!0),series:this},s);(0,i.fireEvent)(this,"setRootNode",o,function(t){let e=t.series;e.idPreviousRoot=t.previousRootId,e.rootNode=t.newRootId,e.isDirty=!0,t.redraw&&e.chart.redraw()})}setState(t){this.options.inactiveOtherPoints=!0,super.setState(t,!1),this.options.inactiveOtherPoints=!1}setTreeValues(t){let e=this.options,s=this.rootNode,o=this.nodeMap[s],r="boolean"!=typeof e.levelIsConstant||e.levelIsConstant,l=[],a=this.points[t.i],n=0;for(let e of t.children)e=this.setTreeValues(e),l.push(e),e.ignore||(n+=e.val);(0,i.stableSort)(l,(t,e)=>(t.sortIndex||0)-(e.sortIndex||0));let h=(0,i.pick)(a?.simulatedValue,a?.options.value,n);return a&&(a.value=h),a?.isGroup&&e.cluster?.reductionFactor&&(h/=e.cluster.reductionFactor),t.parentNode?.point?.isGroup&&this.rootNode!==t.parent&&(t.visible=!1),(0,i.extend)(t,{children:l,childrenTotal:n,ignore:!((0,i.pick)(a?.visible,!0)&&h>0),isLeaf:t.visible&&!("treegraph"===this.type?l.length>0:n),isGroup:a?.isGroup,levelDynamic:t.level-(r?0:o.level),name:(0,i.pick)(a?.name,""),sortIndex:(0,i.pick)(a?.sortIndex,-h),val:h}),t}sliceAndDice(t,e){return this.algorithmFill(!0,t,e)}squarified(t,e){return this.algorithmLowAspectRatio(!0,t,e)}strip(t,e){return this.algorithmLowAspectRatio(!1,t,e)}stripes(t,e){return this.algorithmFill(!1,t,e)}translate(t){let e=this,s=e.options,o=!t,r=F(e),l,a,n,h;t||r.startsWith("highcharts-grouped-treemap-points-")||((this.points||[]).forEach(t=>{t.isGroup&&t.destroy()}),super.translate(),t=e.getTree()),e.tree=t=t||e.tree,l=e.nodeMap[r],""===r||l||(e.setRootNode("",!1),r=e.rootNode,l=e.nodeMap[r]),l.point?.isGroup||(e.mapOptionsToLevel=H({from:l.level+1,levels:s.levels,to:t.height,defaults:{levelIsConstant:e.options.levelIsConstant,colorByPoint:s.colorByPoint}})),I.recursive(e.nodeMap[e.rootNode],t=>{let i=t.parent,s=!1;return t.visible=!0,(i||""===i)&&(s=e.nodeMap[i]),s}),I.recursive(e.nodeMap[e.rootNode].children,t=>{let e=!1;for(let i of t)i.visible=!0,i.children.length&&(e=(e||[]).concat(i.children));return e}),e.setTreeValues(t),e.axisRatio=e.xAxis.len/e.yAxis.len,e.nodeMap[""].pointValues=a={x:0,y:0,width:100,height:100},e.nodeMap[""].values=n=(0,i.merge)(a,{width:a.width*e.axisRatio,direction:+("vertical"!==s.layoutStartingDirection),val:t.val}),(this.hasOutsideDataLabels||this.hadOutsideDataLabels)&&this.drawDataLabels(),e.calculateChildrenAreas(t,n),e.colorAxis||s.colorByPoint||e.setColorRecursive(e.tree),s.allowTraversingTree&&l.pointValues&&(h=l.pointValues,e.xAxis.setExtremes(h.x,h.x+h.width,!1),e.yAxis.setExtremes(h.y,h.y+h.height,!1),e.xAxis.setScale(),e.yAxis.setScale()),e.setPointValues(),o&&e.applyTreeGrouping()}}$.defaultOptions=(0,i.merge)(V.defaultOptions,D),(0,i.extend)($.prototype,{buildKDTree:G,colorAttribs:B.seriesMembers.colorAttribs,colorKey:"colorValue",directTouch:!0,getExtremesFromAll:!0,getSymbol:G,optionalAxis:"colorAxis",parallelArrays:["x","y","value","colorValue"],pointArrayMap:["value","colorValue"],pointClass:k,NodeClass:class{constructor(){this.childrenTotal=0,this.visible=!1}init(t,e,i,s,o,r,l){return this.id=t,this.i=e,this.children=i,this.height=s,this.level=o,this.series=r,this.parent=l,this}},trackerGroups:["group","dataLabelsGroup"],utils:I}),B.compose($),y().registerSeriesType("treemap",$);let K=r();K.Breadcrumbs=K.Breadcrumbs||v,K.Breadcrumbs.compose(K.Chart,K.defaultOptions),$.compose(K.Series);let Y=r();export{Y as default};