treemap.js
12.5 KB
/*
Highcharts JS v6.2.0 (2018-10-17)
(c) 2014 Highsoft AS
Authors: Jon Arild Nygard / Oystein Moseng
License: www.highcharts.com/license
*/
(function(v){"object"===typeof module&&module.exports?module.exports=v:"function"===typeof define&&define.amd?define(function(){return v}):v(Highcharts)})(function(v){var E=function(b){var v=b.each,y=b.extend,w=b.isArray,p=b.isObject,q=b.isNumber,A=b.merge,z=b.pick,r=b.reduce;return{getColor:function(b,t){var g=t.mapOptionsToLevel,f=t.parentColorIndex,r=t.series,B=t.colors,m=r.points,h,p;b&&(m=m[b.i],g=g[b.level]||{},(b=m&&g.colorByPoint)&&(h=m.index%(B?B.length:r.chart.options.chart.colorCount)),
p=z(m&&m.options.colorIndex,g&&g.colorIndex,h,f,t.colorIndex));return{color:void 0,colorIndex:p}},getLevelOptions:function(b){var t=null,g,f,C,x;if(p(b))for(t={},C=q(b.from)?b.from:1,x=b.levels,f={},g=p(b.defaults)?b.defaults:{},w(x)&&(f=r(x,function(b,h){var t,f;p(h)&&q(h.level)&&(f=A({},h),t="boolean"===typeof f.levelIsConstant?f.levelIsConstant:g.levelIsConstant,delete f.levelIsConstant,delete f.level,h=h.level+(t?0:C-1),p(b[h])?y(b[h],f):b[h]=f);return b},{})),x=q(b.to)?b.to:1,b=0;b<=x;b++)t[b]=
A({},g,p(f[b])?f[b]:{});return t},setTreeValues:function t(b,f){var g=f.before,r=f.idRoot,m=f.mapIdToNode[r],h=f.points[b.i],p=h&&h.options||{},q=0,w=[];y(b,{levelDynamic:b.level-(("boolean"===typeof f.levelIsConstant?f.levelIsConstant:1)?0:m.level),name:z(h&&h.name,""),visible:r===b.id||("boolean"===typeof f.visible?f.visible:!1)});"function"===typeof g&&(b=g(b,f));v(b.children,function(g,h){var a=y({},f);y(a,{index:h,siblings:b.children.length,visible:b.visible});g=t(g,a);w.push(g);g.visible&&(q+=
g.val)});b.visible=0<q||b.visible;g=z(p.value,q);y(b,{children:w,childrenTotal:q,isLeaf:b.visible&&!q,val:g});return b},updateRootId:function(b){var g;p(b)&&(g=p(b.options)?b.options:{},g=z(b.rootNode,g.rootId,""),p(b.userOptions)&&(b.userOptions.rootId=g),b.rootNode=g);return g}}}(v);(function(b,v){var y=b.seriesType,w=b.seriesTypes,p=b.map,q=b.merge,A=b.extend,z=b.noop,r=b.each,B=v.getColor,t=v.getLevelOptions,g=b.grep,f=b.isArray,C=b.isNumber,x=b.isString,m=b.pick,h=b.Series,E=b.stableSort,G=function(a,
d,c){c=c||this;b.objectEach(a,function(b,e){d.call(c,b,e,a)})},F=b.reduce,D=function(a,d,c){c=c||this;a=d.call(c,a);!1!==a&&D(a,d,c)},H=v.updateRootId;y("treemap","scatter",{showInLegend:!1,marker:!1,colorByPoint:!1,dataLabels:{enabled:!0,defer:!1,verticalAlign:"middle",formatter:function(){return this.point.name||this.point.id},inside:!0},tooltip:{headerFormat:"",pointFormat:"\x3cb\x3e{point.name}\x3c/b\x3e: {point.value}\x3cbr/\x3e"},ignoreHiddenPoint:!0,layoutAlgorithm:"sliceAndDice",layoutStartingDirection:"vertical",
alternateStartingDirection:!1,levelIsConstant:!0,drillUpButton:{position:{align:"right",x:-10,y:10}}},{pointArrayMap:["value"],directTouch:!0,optionalAxis:"colorAxis",getSymbol:z,parallelArrays:["x","y","value","colorValue"],colorKey:"colorValue",trackerGroups:["group","dataLabelsGroup"],getListOfParents:function(a,d){a=f(a)?a:[];var c=f(d)?d:[];d=F(a,function(a,c,d){c=m(c.parent,"");void 0===a[c]&&(a[c]=[]);a[c].push(d);return a},{"":[]});G(d,function(a,d,k){""!==d&&-1===b.inArray(d,c)&&(r(a,function(a){k[""].push(a)}),
delete k[d])});return d},getTree:function(){var a=p(this.data,function(a){return a.id}),a=this.getListOfParents(this.data,a);this.nodeMap=[];return this.buildNode("",-1,0,a,null)},init:function(a,d){var c=b.colorSeriesMixin;b.colorSeriesMixin&&(this.translateColors=c.translateColors,this.colorAttribs=c.colorAttribs,this.axisTypes=c.axisTypes);h.prototype.init.call(this,a,d);this.options.allowDrillToNode&&b.addEvent(this,"click",this.onClickDrillToNode)},buildNode:function(a,d,c,b,e){var k=this,u=
[],l=k.points[d],g=0,f;r(b[a]||[],function(d){f=k.buildNode(k.points[d].id,d,c+1,b,a);g=Math.max(f.height+1,g);u.push(f)});d={id:a,i:d,children:u,height:g,level:c,parent:e,visible:!1};k.nodeMap[d.id]=d;l&&(l.node=d);return d},setTreeValues:function(a){var d=this,c=d.options,b=d.nodeMap[d.rootNode],c="boolean"===typeof c.levelIsConstant?c.levelIsConstant:!0,e=0,k=[],n,l=d.points[a.i];r(a.children,function(a){a=d.setTreeValues(a);k.push(a);a.ignore||(e+=a.val)});E(k,function(a,c){return a.sortIndex-
c.sortIndex});n=m(l&&l.options.value,e);l&&(l.value=n);A(a,{children:k,childrenTotal:e,ignore:!(m(l&&l.visible,!0)&&0<n),isLeaf:a.visible&&!e,levelDynamic:a.level-(c?0:b.level),name:m(l&&l.name,""),sortIndex:m(l&&l.sortIndex,-n),val:n});return a},calculateChildrenAreas:function(a,d){var c=this,b=c.options,e=c.mapOptionsToLevel[a.level+1],k=m(c[e&&e.layoutAlgorithm]&&e.layoutAlgorithm,b.layoutAlgorithm),n=b.alternateStartingDirection,l=[];a=g(a.children,function(a){return!a.ignore});e&&e.layoutStartingDirection&&
(d.direction="vertical"===e.layoutStartingDirection?0:1);l=c[k](d,a);r(a,function(a,b){b=l[b];a.values=q(b,{val:a.childrenTotal,direction:n?1-d.direction:d.direction});a.pointValues=q(b,{x:b.x/c.axisRatio,width:b.width/c.axisRatio});a.children.length&&c.calculateChildrenAreas(a,a.values)})},setPointValues:function(){var a=this.xAxis,d=this.yAxis;r(this.points,function(c){var b=c.node,e=b.pointValues,k,n;e&&b.visible?(b=Math.round(a.translate(e.x,0,0,0,1))-0,k=Math.round(a.translate(e.x+e.width,0,
0,0,1))-0,n=Math.round(d.translate(e.y,0,0,0,1))-0,e=Math.round(d.translate(e.y+e.height,0,0,0,1))-0,c.shapeType="rect",c.shapeArgs={x:Math.min(b,k),y:Math.min(n,e),width:Math.abs(k-b),height:Math.abs(e-n)},c.plotX=c.shapeArgs.x+c.shapeArgs.width/2,c.plotY=c.shapeArgs.y+c.shapeArgs.height/2):(delete c.plotX,delete c.plotY)})},setColorRecursive:function(a,d,c,b,e){var k=this,n=k&&k.chart,n=n&&n.options&&n.options.colors,l;if(a){l=B(a,{colors:n,index:b,mapOptionsToLevel:k.mapOptionsToLevel,parentColor:d,
parentColorIndex:c,series:k,siblings:e});if(d=k.points[a.i])d.color=l.color,d.colorIndex=l.colorIndex;r(a.children||[],function(c,d){k.setColorRecursive(c,l.color,l.colorIndex,d,a.children.length)})}},algorithmGroup:function(a,d,c,b){this.height=a;this.width=d;this.plot=b;this.startDirection=this.direction=c;this.lH=this.nH=this.lW=this.nW=this.total=0;this.elArr=[];this.lP={total:0,lH:0,nH:0,lW:0,nW:0,nR:0,lR:0,aspectRatio:function(a,c){return Math.max(a/c,c/a)}};this.addElement=function(a){this.lP.total=
this.elArr[this.elArr.length-1];this.total+=a;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(a)};
this.reset=function(){this.lW=this.nW=0;this.elArr=[];this.total=0}},algorithmCalcPoints:function(a,d,c,b){var e,k,n,l,g=c.lW,f=c.lH,u=c.plot,h,m=0,t=c.elArr.length-1;d?(g=c.nW,f=c.nH):h=c.elArr[c.elArr.length-1];r(c.elArr,function(a){if(d||m<t)0===c.direction?(e=u.x,k=u.y,n=g,l=a/n):(e=u.x,k=u.y,l=f,n=a/l),b.push({x:e,y:k,width:n,height:l}),0===c.direction?u.y+=l:u.x+=n;m+=1});c.reset();0===c.direction?c.width-=g:c.height-=f;u.y=u.parent.y+(u.parent.height-c.height);u.x=u.parent.x+(u.parent.width-
c.width);a&&(c.direction=1-c.direction);d||c.addElement(h)},algorithmLowAspectRatio:function(a,d,c){var b=[],e=this,k,g={x:d.x,y:d.y,parent:d},l=0,f=c.length-1,h=new this.algorithmGroup(d.height,d.width,d.direction,g);r(c,function(c){k=c.val/d.val*d.height*d.width;h.addElement(k);h.lP.nR>h.lP.lR&&e.algorithmCalcPoints(a,!1,h,b,g);l===f&&e.algorithmCalcPoints(a,!0,h,b,g);l+=1});return b},algorithmFill:function(a,d,c){var b=[],e,k=d.direction,g=d.x,l=d.y,f=d.width,h=d.height,m,t,p,q;r(c,function(c){e=
c.val/d.val*d.height*d.width;m=g;t=l;0===k?(q=h,p=e/q,f-=p,g+=p):(p=f,q=e/p,h-=q,l+=q);b.push({x:m,y:t,width:p,height:q});a&&(k=1-k)});return b},strip:function(a,d){return this.algorithmLowAspectRatio(!1,a,d)},squarified:function(a,d){return this.algorithmLowAspectRatio(!0,a,d)},sliceAndDice:function(a,d){return this.algorithmFill(!0,a,d)},stripes:function(a,d){return this.algorithmFill(!1,a,d)},translate:function(){var a=this,d=a.options,c=H(a),b,e;h.prototype.translate.call(a);e=a.tree=a.getTree();
b=a.nodeMap[c];a.mapOptionsToLevel=t({from:b.level+1,levels:d.levels,to:e.height,defaults:{levelIsConstant:a.options.levelIsConstant,colorByPoint:d.colorByPoint}});""===c||b&&b.children.length||(a.drillToNode("",!1),c=a.rootNode,b=a.nodeMap[c]);D(a.nodeMap[a.rootNode],function(c){var b=!1,d=c.parent;c.visible=!0;if(d||""===d)b=a.nodeMap[d];return b});D(a.nodeMap[a.rootNode].children,function(a){var c=!1;r(a,function(a){a.visible=!0;a.children.length&&(c=(c||[]).concat(a.children))});return c});a.setTreeValues(e);
a.axisRatio=a.xAxis.len/a.yAxis.len;a.nodeMap[""].pointValues=c={x:0,y:0,width:100,height:100};a.nodeMap[""].values=c=q(c,{width:c.width*a.axisRatio,direction:"vertical"===d.layoutStartingDirection?0:1,val:e.val});a.calculateChildrenAreas(e,c);a.colorAxis?a.translateColors():d.colorByPoint||a.setColorRecursive(a.tree);d.allowDrillToNode&&(d=b.pointValues,a.xAxis.setExtremes(d.x,d.x+d.width,!1),a.yAxis.setExtremes(d.y,d.y+d.height,!1),a.xAxis.setScale(),a.yAxis.setScale());a.setPointValues()},drawDataLabels:function(){var a=
this,b=a.mapOptionsToLevel,c=g(a.points,function(a){return a.node.visible}),f,e;r(c,function(c){e=b[c.node.level];f={style:{}};c.node.isLeaf||(f.enabled=!1);e&&e.dataLabels&&(f=q(f,e.dataLabels),a._hasPointLabels=!0);c.shapeArgs&&(f.style.width=c.shapeArgs.width,c.dataLabel&&c.dataLabel.css({width:c.shapeArgs.width+"px"}));c.dlOptions=q(f,c.options.dataLabels)});h.prototype.drawDataLabels.call(this)},alignDataLabel:function(a){w.column.prototype.alignDataLabel.apply(this,arguments);a.dataLabel&&a.dataLabel.attr({zIndex:(a.node.zIndex||
0)+1})},drawPoints:function(){var a=this,b=g(a.points,function(a){return a.node.visible});r(b,function(c){var b="level-group-"+c.node.levelDynamic;a[b]||(a[b]=a.chart.renderer.g(b).attr({zIndex:1E3-c.node.levelDynamic}).add(a.group));c.group=a[b]});w.column.prototype.drawPoints.call(this);this.colorAttribs&&r(this.points,function(a){a.graphic&&a.graphic.css(this.colorAttribs(a))},this);a.options.allowDrillToNode&&r(b,function(c){c.graphic&&(c.drillId=a.options.interactByLeaf?a.drillToByLeaf(c):a.drillToByGroup(c))})},
onClickDrillToNode:function(a){var b=(a=a.point)&&a.drillId;x(b)&&(a.setState(""),this.drillToNode(b))},drillToByGroup:function(a){var b=!1;1!==a.node.level-this.nodeMap[this.rootNode].level||a.node.isLeaf||(b=a.id);return b},drillToByLeaf:function(a){var b=!1;if(a.node.parent!==this.rootNode&&a.node.isLeaf)for(a=a.node;!b;)a=this.nodeMap[a.parent],a.parent===this.rootNode&&(b=a.id);return b},drillUp:function(){var a=this.nodeMap[this.rootNode];a&&x(a.parent)&&this.drillToNode(a.parent)},drillToNode:function(a,
b){var c=this.nodeMap[a];this.idPreviousRoot=this.rootNode;this.rootNode=a;""===a?this.drillUpButton=this.drillUpButton.destroy():this.showDrillUpButton(c&&c.name||a);this.isDirty=!0;m(b,!0)&&this.chart.redraw()},showDrillUpButton:function(a){var b=this;a=a||"\x3c Back";var c=b.options.drillUpButton,f,e;c.text&&(a=c.text);this.drillUpButton?(this.drillUpButton.placed=!1,this.drillUpButton.attr({text:a}).align()):(e=(f=c.theme)&&f.states,this.drillUpButton=this.chart.renderer.button(a,null,null,function(){b.drillUp()},
f,e&&e.hover,e&&e.select).addClass("highcharts-drillup-button").attr({align:c.position.align,zIndex:7}).add().align(c.position,!1,c.relativeTo||"plotBox"))},buildKDTree:z,drawLegendSymbol:b.LegendSymbolMixin.drawRectangle,getExtremes:function(){h.prototype.getExtremes.call(this,this.colorValueData);this.valueMin=this.dataMin;this.valueMax=this.dataMax;h.prototype.getExtremes.call(this)},getExtremesFromAll:!0,bindAxes:function(){var a={endOnTick:!1,gridLineWidth:0,lineWidth:0,min:0,dataMin:0,minPadding:0,
max:100,dataMax:100,maxPadding:0,startOnTick:!1,title:null,tickPositions:[]};h.prototype.bindAxes.call(this);b.extend(this.yAxis.options,a);b.extend(this.xAxis.options,a)},utils:{recursive:D,reduce:F}},{getClassName:function(){var a=b.Point.prototype.getClassName.call(this),d=this.series,c=d.options;this.node.level<=d.nodeMap[d.rootNode].level?a+=" highcharts-above-level":this.node.isLeaf||m(c.interactByLeaf,!c.allowDrillToNode)?this.node.isLeaf||(a+=" highcharts-internal-node"):a+=" highcharts-internal-node-interactive";
return a},isValid:function(){return this.id||C(this.value)},setState:function(a){b.Point.prototype.setState.call(this,a);this.graphic&&this.graphic.attr({zIndex:"hover"===a?1:0})},setVisible:w.pie.prototype.pointClass.prototype.setVisible})})(v,E)});
//# sourceMappingURL=treemap.js.map