treemap.src.js 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * (c) 2014-2021 Highsoft AS
  5. * Authors: Jon Arild Nygard / Oystein Moseng
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. 'use strict';
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. factory['default'] = factory;
  13. module.exports = factory;
  14. } else if (typeof define === 'function' && define.amd) {
  15. define('highcharts/modules/treemap', ['highcharts'], function (Highcharts) {
  16. factory(Highcharts);
  17. factory.Highcharts = Highcharts;
  18. return factory;
  19. });
  20. } else {
  21. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  22. }
  23. }(function (Highcharts) {
  24. var _modules = Highcharts ? Highcharts._modules : {};
  25. function _registerModule(obj, path, args, fn) {
  26. if (!obj.hasOwnProperty(path)) {
  27. obj[path] = fn.apply(null, args);
  28. }
  29. }
  30. _registerModule(_modules, 'Mixins/ColorMapSeries.js', [_modules['Core/Globals.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, Point, U) {
  31. /* *
  32. *
  33. * (c) 2010-2021 Torstein Honsi
  34. *
  35. * License: www.highcharts.com/license
  36. *
  37. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  38. *
  39. * */
  40. var defined = U.defined,
  41. addEvent = U.addEvent;
  42. var noop = H.noop,
  43. seriesTypes = H.seriesTypes;
  44. // Move points to the top of the z-index order when hovered
  45. addEvent(Point, 'afterSetState', function (e) {
  46. var point = this; // eslint-disable-line no-invalid-this
  47. if (point.moveToTopOnHover && point.graphic) {
  48. point.graphic.attr({
  49. zIndex: e && e.state === 'hover' ? 1 : 0
  50. });
  51. }
  52. });
  53. /**
  54. * Mixin for maps and heatmaps
  55. *
  56. * @private
  57. * @mixin Highcharts.colorMapPointMixin
  58. */
  59. var colorMapPointMixin = {
  60. dataLabelOnNull: true,
  61. moveToTopOnHover: true,
  62. /* eslint-disable valid-jsdoc */
  63. /**
  64. * Color points have a value option that determines whether or not it is
  65. * a null point
  66. * @private
  67. */
  68. isValid: function () {
  69. // undefined is allowed
  70. return (this.value !== null &&
  71. this.value !== Infinity &&
  72. this.value !== -Infinity);
  73. }
  74. /* eslint-enable valid-jsdoc */
  75. };
  76. /**
  77. * @private
  78. * @mixin Highcharts.colorMapSeriesMixin
  79. */
  80. var colorMapSeriesMixin = {
  81. pointArrayMap: ['value'],
  82. axisTypes: ['xAxis', 'yAxis', 'colorAxis'],
  83. trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
  84. getSymbol: noop,
  85. parallelArrays: ['x', 'y', 'value'],
  86. colorKey: 'value',
  87. pointAttribs: seriesTypes.column.prototype.pointAttribs,
  88. /* eslint-disable valid-jsdoc */
  89. /**
  90. * Get the color attibutes to apply on the graphic
  91. * @private
  92. * @function Highcharts.colorMapSeriesMixin.colorAttribs
  93. * @param {Highcharts.Point} point
  94. * @return {Highcharts.SVGAttributes}
  95. */
  96. colorAttribs: function (point) {
  97. var ret = {};
  98. if (defined(point.color) &&
  99. (!point.state || point.state === 'normal') // #15746
  100. ) {
  101. ret[this.colorProp || 'fill'] = point.color;
  102. }
  103. return ret;
  104. }
  105. };
  106. var exports = {
  107. colorMapPointMixin: colorMapPointMixin,
  108. colorMapSeriesMixin: colorMapSeriesMixin
  109. };
  110. return exports;
  111. });
  112. _registerModule(_modules, 'Series/Treemap/TreemapAlgorithmGroup.js', [], function () {
  113. /* *
  114. *
  115. * (c) 2014-2021 Highsoft AS
  116. *
  117. * Authors: Jon Arild Nygard / Oystein Moseng
  118. *
  119. * License: www.highcharts.com/license
  120. *
  121. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  122. *
  123. * */
  124. /* *
  125. *
  126. * Class
  127. *
  128. * */
  129. var TreemapAlgorithmGroup = /** @class */ (function () {
  130. /* *
  131. *
  132. * Constructor
  133. *
  134. * */
  135. function TreemapAlgorithmGroup(h, w, d, p) {
  136. this.height = h;
  137. this.width = w;
  138. this.plot = p;
  139. this.direction = d;
  140. this.startDirection = d;
  141. this.total = 0;
  142. this.nW = 0;
  143. this.lW = 0;
  144. this.nH = 0;
  145. this.lH = 0;
  146. this.elArr = [];
  147. this.lP = {
  148. total: 0,
  149. lH: 0,
  150. nH: 0,
  151. lW: 0,
  152. nW: 0,
  153. nR: 0,
  154. lR: 0,
  155. aspectRatio: function (w, h) {
  156. return Math.max((w / h), (h / w));
  157. }
  158. };
  159. }
  160. /* *
  161. *
  162. * Functions
  163. *
  164. * */
  165. /* eslint-disable valid-jsdoc */
  166. TreemapAlgorithmGroup.prototype.addElement = function (el) {
  167. this.lP.total = this.elArr[this.elArr.length - 1];
  168. this.total = this.total + el;
  169. if (this.direction === 0) {
  170. // Calculate last point old aspect ratio
  171. this.lW = this.nW;
  172. this.lP.lH = this.lP.total / this.lW;
  173. this.lP.lR = this.lP.aspectRatio(this.lW, this.lP.lH);
  174. // Calculate last point new aspect ratio
  175. this.nW = this.total / this.height;
  176. this.lP.nH = this.lP.total / this.nW;
  177. this.lP.nR = this.lP.aspectRatio(this.nW, this.lP.nH);
  178. }
  179. else {
  180. // Calculate last point old aspect ratio
  181. this.lH = this.nH;
  182. this.lP.lW = this.lP.total / this.lH;
  183. this.lP.lR = this.lP.aspectRatio(this.lP.lW, this.lH);
  184. // Calculate last point new aspect ratio
  185. this.nH = this.total / this.width;
  186. this.lP.nW = this.lP.total / this.nH;
  187. this.lP.nR = this.lP.aspectRatio(this.lP.nW, this.nH);
  188. }
  189. this.elArr.push(el);
  190. };
  191. TreemapAlgorithmGroup.prototype.reset = function () {
  192. this.nW = 0;
  193. this.lW = 0;
  194. this.elArr = [];
  195. this.total = 0;
  196. };
  197. return TreemapAlgorithmGroup;
  198. }());
  199. /* *
  200. *
  201. * Default Export
  202. *
  203. * */
  204. return TreemapAlgorithmGroup;
  205. });
  206. _registerModule(_modules, 'Mixins/DrawPoint.js', [], function () {
  207. /* *
  208. *
  209. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  210. *
  211. * */
  212. var isFn = function (x) {
  213. return typeof x === 'function';
  214. };
  215. /* eslint-disable no-invalid-this, valid-jsdoc */
  216. /**
  217. * Handles the drawing of a component.
  218. * Can be used for any type of component that reserves the graphic property, and
  219. * provides a shouldDraw on its context.
  220. *
  221. * @private
  222. * @function draw
  223. * @param {DrawPointParams} params
  224. * Parameters.
  225. *
  226. * @todo add type checking.
  227. * @todo export this function to enable usage
  228. */
  229. var draw = function draw(params) {
  230. var _this = this;
  231. var animatableAttribs = params.animatableAttribs,
  232. onComplete = params.onComplete,
  233. css = params.css,
  234. renderer = params.renderer;
  235. var animation = (this.series && this.series.chart.hasRendered) ?
  236. // Chart-level animation on updates
  237. void 0 :
  238. // Series-level animation on new points
  239. (this.series &&
  240. this.series.options.animation);
  241. var graphic = this.graphic;
  242. if (this.shouldDraw()) {
  243. if (!graphic) {
  244. this.graphic = graphic =
  245. renderer[params.shapeType](params.shapeArgs)
  246. .add(params.group);
  247. }
  248. graphic
  249. .css(css)
  250. .attr(params.attribs)
  251. .animate(animatableAttribs, params.isNew ? false : animation, onComplete);
  252. }
  253. else if (graphic) {
  254. var destroy_1 = function () {
  255. _this.graphic = graphic = (graphic && graphic.destroy());
  256. if (isFn(onComplete)) {
  257. onComplete();
  258. }
  259. };
  260. // animate only runs complete callback if something was animated.
  261. if (Object.keys(animatableAttribs).length) {
  262. graphic.animate(animatableAttribs, void 0, function () {
  263. destroy_1();
  264. });
  265. }
  266. else {
  267. destroy_1();
  268. }
  269. }
  270. };
  271. /**
  272. * An extended version of draw customized for points.
  273. * It calls additional methods that is expected when rendering a point.
  274. * @private
  275. * @param {Highcharts.Dictionary<any>} params Parameters
  276. */
  277. var drawPoint = function drawPoint(params) {
  278. var point = this,
  279. attribs = params.attribs = params.attribs || {};
  280. // Assigning class in dot notation does go well in IE8
  281. // eslint-disable-next-line dot-notation
  282. attribs['class'] = point.getClassName();
  283. // Call draw to render component
  284. draw.call(point, params);
  285. };
  286. var drawPointModule = {
  287. draw: draw,
  288. drawPoint: drawPoint,
  289. isFn: isFn
  290. };
  291. return drawPointModule;
  292. });
  293. _registerModule(_modules, 'Series/Treemap/TreemapPoint.js', [_modules['Mixins/DrawPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (DrawPointMixin, SeriesRegistry, U) {
  294. /* *
  295. *
  296. * (c) 2014-2021 Highsoft AS
  297. *
  298. * Authors: Jon Arild Nygard / Oystein Moseng
  299. *
  300. * License: www.highcharts.com/license
  301. *
  302. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  303. *
  304. * */
  305. var __extends = (this && this.__extends) || (function () {
  306. var extendStatics = function (d,
  307. b) {
  308. extendStatics = Object.setPrototypeOf ||
  309. ({ __proto__: [] } instanceof Array && function (d,
  310. b) { d.__proto__ = b; }) ||
  311. function (d,
  312. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  313. return extendStatics(d, b);
  314. };
  315. return function (d, b) {
  316. extendStatics(d, b);
  317. function __() { this.constructor = d; }
  318. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  319. };
  320. })();
  321. var Point = SeriesRegistry.series.prototype.pointClass,
  322. _a = SeriesRegistry.seriesTypes,
  323. PiePoint = _a.pie.prototype.pointClass,
  324. ScatterPoint = _a.scatter.prototype.pointClass;
  325. var extend = U.extend,
  326. isNumber = U.isNumber,
  327. pick = U.pick;
  328. /* *
  329. *
  330. * Class
  331. *
  332. * */
  333. var TreemapPoint = /** @class */ (function (_super) {
  334. __extends(TreemapPoint, _super);
  335. function TreemapPoint() {
  336. /* *
  337. *
  338. * Properties
  339. *
  340. * */
  341. var _this = _super !== null && _super.apply(this,
  342. arguments) || this;
  343. _this.name = void 0;
  344. _this.node = void 0;
  345. _this.options = void 0;
  346. _this.series = void 0;
  347. _this.value = void 0;
  348. return _this;
  349. /* eslint-enable valid-jsdoc */
  350. }
  351. /* *
  352. *
  353. * Functions
  354. *
  355. * */
  356. /* eslint-disable valid-jsdoc */
  357. TreemapPoint.prototype.getClassName = function () {
  358. var className = Point.prototype.getClassName.call(this),
  359. series = this.series,
  360. options = series.options;
  361. // Above the current level
  362. if (this.node.level <= series.nodeMap[series.rootNode].level) {
  363. className += ' highcharts-above-level';
  364. }
  365. else if (!this.node.isLeaf &&
  366. !pick(options.interactByLeaf, !options.allowTraversingTree)) {
  367. className += ' highcharts-internal-node-interactive';
  368. }
  369. else if (!this.node.isLeaf) {
  370. className += ' highcharts-internal-node';
  371. }
  372. return className;
  373. };
  374. /**
  375. * A tree point is valid if it has han id too, assume it may be a parent
  376. * item.
  377. *
  378. * @private
  379. * @function Highcharts.Point#isValid
  380. */
  381. TreemapPoint.prototype.isValid = function () {
  382. return Boolean(this.id || isNumber(this.value));
  383. };
  384. TreemapPoint.prototype.setState = function (state) {
  385. Point.prototype.setState.call(this, state);
  386. // Graphic does not exist when point is not visible.
  387. if (this.graphic) {
  388. this.graphic.attr({
  389. zIndex: state === 'hover' ? 1 : 0
  390. });
  391. }
  392. };
  393. TreemapPoint.prototype.shouldDraw = function () {
  394. return isNumber(this.plotY) && this.y !== null;
  395. };
  396. return TreemapPoint;
  397. }(ScatterPoint));
  398. extend(TreemapPoint.prototype, {
  399. draw: DrawPointMixin.drawPoint,
  400. setVisible: PiePoint.prototype.setVisible
  401. });
  402. /* *
  403. *
  404. * Default Export
  405. *
  406. * */
  407. return TreemapPoint;
  408. });
  409. _registerModule(_modules, 'Series/Treemap/TreemapUtilities.js', [_modules['Core/Utilities.js']], function (U) {
  410. /* *
  411. *
  412. * (c) 2014-2021 Highsoft AS
  413. *
  414. * Authors: Jon Arild Nygard / Oystein Moseng
  415. *
  416. * License: www.highcharts.com/license
  417. *
  418. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  419. *
  420. * */
  421. /* *
  422. *
  423. * Imports
  424. *
  425. * */
  426. var objectEach = U.objectEach;
  427. /* *
  428. *
  429. * Namespace
  430. *
  431. * */
  432. var TreemapUtilities;
  433. (function (TreemapUtilities) {
  434. TreemapUtilities.AXIS_MAX = 100;
  435. /* eslint-disable no-invalid-this, valid-jsdoc */
  436. /**
  437. * @todo Similar to eachObject, this function is likely redundant
  438. */
  439. function isBoolean(x) {
  440. return typeof x === 'boolean';
  441. }
  442. TreemapUtilities.isBoolean = isBoolean;
  443. /**
  444. * @todo Similar to recursive, this function is likely redundant
  445. */
  446. function eachObject(list, func, context) {
  447. context = context || this;
  448. objectEach(list, function (val, key) {
  449. func.call(context, val, key, list);
  450. });
  451. }
  452. TreemapUtilities.eachObject = eachObject;
  453. /**
  454. * @todo find correct name for this function.
  455. * @todo Similar to reduce, this function is likely redundant
  456. */
  457. function recursive(item, func, context) {
  458. if (context === void 0) { context = this; }
  459. var next;
  460. next = func.call(context, item);
  461. if (next !== false) {
  462. recursive(next, func, context);
  463. }
  464. }
  465. TreemapUtilities.recursive = recursive;
  466. })(TreemapUtilities || (TreemapUtilities = {}));
  467. /* *
  468. *
  469. * Default Export
  470. *
  471. * */
  472. return TreemapUtilities;
  473. });
  474. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  475. /* *
  476. *
  477. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  478. *
  479. * */
  480. var extend = U.extend,
  481. isArray = U.isArray,
  482. isNumber = U.isNumber,
  483. isObject = U.isObject,
  484. merge = U.merge,
  485. pick = U.pick;
  486. var isBoolean = function (x) {
  487. return typeof x === 'boolean';
  488. }, isFn = function (x) {
  489. return typeof x === 'function';
  490. };
  491. /* eslint-disable valid-jsdoc */
  492. /**
  493. * @todo Combine buildTree and buildNode with setTreeValues
  494. * @todo Remove logic from Treemap and make it utilize this mixin.
  495. * @private
  496. */
  497. var setTreeValues = function setTreeValues(tree,
  498. options) {
  499. var before = options.before,
  500. idRoot = options.idRoot,
  501. mapIdToNode = options.mapIdToNode,
  502. nodeRoot = mapIdToNode[idRoot],
  503. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  504. options.levelIsConstant :
  505. true),
  506. points = options.points,
  507. point = points[tree.i],
  508. optionsPoint = point && point.options || {},
  509. childrenTotal = 0,
  510. children = [],
  511. value;
  512. tree.levelDynamic = tree.level - (levelIsConstant ? 0 : nodeRoot.level);
  513. tree.name = pick(point && point.name, '');
  514. tree.visible = (idRoot === tree.id ||
  515. (isBoolean(options.visible) ? options.visible : false));
  516. if (isFn(before)) {
  517. tree = before(tree, options);
  518. }
  519. // First give the children some values
  520. tree.children.forEach(function (child, i) {
  521. var newOptions = extend({},
  522. options);
  523. extend(newOptions, {
  524. index: i,
  525. siblings: tree.children.length,
  526. visible: tree.visible
  527. });
  528. child = setTreeValues(child, newOptions);
  529. children.push(child);
  530. if (child.visible) {
  531. childrenTotal += child.val;
  532. }
  533. });
  534. tree.visible = childrenTotal > 0 || tree.visible;
  535. // Set the values
  536. value = pick(optionsPoint.value, childrenTotal);
  537. tree.children = children;
  538. tree.childrenTotal = childrenTotal;
  539. tree.isLeaf = tree.visible && !childrenTotal;
  540. tree.val = value;
  541. return tree;
  542. };
  543. /**
  544. * @private
  545. */
  546. var getColor = function getColor(node,
  547. options) {
  548. var index = options.index,
  549. mapOptionsToLevel = options.mapOptionsToLevel,
  550. parentColor = options.parentColor,
  551. parentColorIndex = options.parentColorIndex,
  552. series = options.series,
  553. colors = options.colors,
  554. siblings = options.siblings,
  555. points = series.points,
  556. getColorByPoint,
  557. chartOptionsChart = series.chart.options.chart,
  558. point,
  559. level,
  560. colorByPoint,
  561. colorIndexByPoint,
  562. color,
  563. colorIndex;
  564. /**
  565. * @private
  566. */
  567. function variation(color) {
  568. var colorVariation = level && level.colorVariation;
  569. if (colorVariation) {
  570. if (colorVariation.key === 'brightness') {
  571. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  572. }
  573. }
  574. return color;
  575. }
  576. if (node) {
  577. point = points[node.i];
  578. level = mapOptionsToLevel[node.level] || {};
  579. getColorByPoint = point && level.colorByPoint;
  580. if (getColorByPoint) {
  581. colorIndexByPoint = point.index % (colors ?
  582. colors.length :
  583. chartOptionsChart.colorCount);
  584. colorByPoint = colors && colors[colorIndexByPoint];
  585. }
  586. // Select either point color, level color or inherited color.
  587. if (!series.chart.styledMode) {
  588. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  589. }
  590. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  591. }
  592. return {
  593. color: color,
  594. colorIndex: colorIndex
  595. };
  596. };
  597. /**
  598. * Creates a map from level number to its given options.
  599. *
  600. * @private
  601. * @function getLevelOptions
  602. * @param {object} params
  603. * Object containing parameters.
  604. * - `defaults` Object containing default options. The default options
  605. * are merged with the userOptions to get the final options for a
  606. * specific level.
  607. * - `from` The lowest level number.
  608. * - `levels` User options from series.levels.
  609. * - `to` The highest level number.
  610. * @return {Highcharts.Dictionary<object>|null}
  611. * Returns a map from level number to its given options.
  612. */
  613. var getLevelOptions = function getLevelOptions(params) {
  614. var result = null,
  615. defaults,
  616. converted,
  617. i,
  618. from,
  619. to,
  620. levels;
  621. if (isObject(params)) {
  622. result = {};
  623. from = isNumber(params.from) ? params.from : 1;
  624. levels = params.levels;
  625. converted = {};
  626. defaults = isObject(params.defaults) ? params.defaults : {};
  627. if (isArray(levels)) {
  628. converted = levels.reduce(function (obj, item) {
  629. var level,
  630. levelIsConstant,
  631. options;
  632. if (isObject(item) && isNumber(item.level)) {
  633. options = merge({}, item);
  634. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  635. options.levelIsConstant :
  636. defaults.levelIsConstant);
  637. // Delete redundant properties.
  638. delete options.levelIsConstant;
  639. delete options.level;
  640. // Calculate which level these options apply to.
  641. level = item.level + (levelIsConstant ? 0 : from - 1);
  642. if (isObject(obj[level])) {
  643. extend(obj[level], options);
  644. }
  645. else {
  646. obj[level] = options;
  647. }
  648. }
  649. return obj;
  650. }, {});
  651. }
  652. to = isNumber(params.to) ? params.to : 1;
  653. for (i = 0; i <= to; i++) {
  654. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  655. }
  656. }
  657. return result;
  658. };
  659. /**
  660. * Update the rootId property on the series. Also makes sure that it is
  661. * accessible to exporting.
  662. *
  663. * @private
  664. * @function updateRootId
  665. *
  666. * @param {object} series
  667. * The series to operate on.
  668. *
  669. * @return {string}
  670. * Returns the resulting rootId after update.
  671. */
  672. var updateRootId = function (series) {
  673. var rootId,
  674. options;
  675. if (isObject(series)) {
  676. // Get the series options.
  677. options = isObject(series.options) ? series.options : {};
  678. // Calculate the rootId.
  679. rootId = pick(series.rootNode, options.rootId, '');
  680. // Set rootId on series.userOptions to pick it up in exporting.
  681. if (isObject(series.userOptions)) {
  682. series.userOptions.rootId = rootId;
  683. }
  684. // Set rootId on series to pick it up on next update.
  685. series.rootNode = rootId;
  686. }
  687. return rootId;
  688. };
  689. var result = {
  690. getColor: getColor,
  691. getLevelOptions: getLevelOptions,
  692. setTreeValues: setTreeValues,
  693. updateRootId: updateRootId
  694. };
  695. return result;
  696. });
  697. _registerModule(_modules, 'Series/Treemap/TreemapComposition.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Series/Treemap/TreemapUtilities.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, TreemapUtilities, U) {
  698. /* *
  699. *
  700. * (c) 2014-2021 Highsoft AS
  701. *
  702. * Authors: Jon Arild Nygard / Oystein Moseng
  703. *
  704. * License: www.highcharts.com/license
  705. *
  706. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  707. *
  708. * */
  709. /* *
  710. *
  711. * Imports
  712. *
  713. * */
  714. var Series = SeriesRegistry.series;
  715. var addEvent = U.addEvent,
  716. extend = U.extend;
  717. /* *
  718. *
  719. * Composition
  720. *
  721. * */
  722. var treemapAxisDefaultValues = false;
  723. addEvent(Series, 'afterBindAxes', function () {
  724. // eslint-disable-next-line no-invalid-this
  725. var series = this,
  726. xAxis = series.xAxis,
  727. yAxis = series.yAxis,
  728. treeAxis;
  729. if (xAxis && yAxis) {
  730. if (series.is('treemap')) {
  731. treeAxis = {
  732. endOnTick: false,
  733. gridLineWidth: 0,
  734. lineWidth: 0,
  735. min: 0,
  736. // dataMin: 0,
  737. minPadding: 0,
  738. max: TreemapUtilities.AXIS_MAX,
  739. // dataMax: TreemapUtilities.AXIS_MAX,
  740. maxPadding: 0,
  741. startOnTick: false,
  742. title: void 0,
  743. tickPositions: []
  744. };
  745. extend(yAxis.options, treeAxis);
  746. extend(xAxis.options, treeAxis);
  747. treemapAxisDefaultValues = true;
  748. }
  749. else if (treemapAxisDefaultValues) {
  750. yAxis.setOptions(yAxis.userOptions);
  751. xAxis.setOptions(xAxis.userOptions);
  752. treemapAxisDefaultValues = false;
  753. }
  754. }
  755. });
  756. });
  757. _registerModule(_modules, 'Series/Treemap/TreemapSeries.js', [_modules['Core/Color/Color.js'], _modules['Mixins/ColorMapSeries.js'], _modules['Core/Globals.js'], _modules['Mixins/LegendSymbol.js'], _modules['Core/Color/Palette.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Series/Treemap/TreemapAlgorithmGroup.js'], _modules['Series/Treemap/TreemapPoint.js'], _modules['Series/Treemap/TreemapUtilities.js'], _modules['Mixins/TreeSeries.js'], _modules['Core/Utilities.js']], function (Color, ColorMapMixin, H, LegendSymbolMixin, palette, SeriesRegistry, TreemapAlgorithmGroup, TreemapPoint, TreemapUtilities, TreeSeriesMixin, U) {
  758. /* *
  759. *
  760. * (c) 2014-2021 Highsoft AS
  761. *
  762. * Authors: Jon Arild Nygard / Oystein Moseng
  763. *
  764. * License: www.highcharts.com/license
  765. *
  766. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  767. *
  768. * */
  769. var __extends = (this && this.__extends) || (function () {
  770. var extendStatics = function (d,
  771. b) {
  772. extendStatics = Object.setPrototypeOf ||
  773. ({ __proto__: [] } instanceof Array && function (d,
  774. b) { d.__proto__ = b; }) ||
  775. function (d,
  776. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  777. return extendStatics(d, b);
  778. };
  779. return function (d, b) {
  780. extendStatics(d, b);
  781. function __() { this.constructor = d; }
  782. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  783. };
  784. })();
  785. var color = Color.parse;
  786. var colorMapSeriesMixin = ColorMapMixin.colorMapSeriesMixin;
  787. var noop = H.noop;
  788. var Series = SeriesRegistry.series,
  789. _a = SeriesRegistry.seriesTypes,
  790. ColumnSeries = _a.column,
  791. HeatmapSeries = _a.heatmap,
  792. ScatterSeries = _a.scatter;
  793. var getColor = TreeSeriesMixin.getColor,
  794. getLevelOptions = TreeSeriesMixin.getLevelOptions,
  795. updateRootId = TreeSeriesMixin.updateRootId;
  796. var addEvent = U.addEvent,
  797. correctFloat = U.correctFloat,
  798. defined = U.defined,
  799. error = U.error,
  800. extend = U.extend,
  801. fireEvent = U.fireEvent,
  802. isArray = U.isArray,
  803. isObject = U.isObject,
  804. isString = U.isString,
  805. merge = U.merge,
  806. pick = U.pick,
  807. stableSort = U.stableSort;
  808. /* *
  809. *
  810. * Class
  811. *
  812. * */
  813. /**
  814. * @private
  815. * @class
  816. * @name Highcharts.seriesTypes.treemap
  817. *
  818. * @augments Highcharts.Series
  819. */
  820. var TreemapSeries = /** @class */ (function (_super) {
  821. __extends(TreemapSeries, _super);
  822. function TreemapSeries() {
  823. /* *
  824. *
  825. * Static Properties
  826. *
  827. * */
  828. var _this = _super !== null && _super.apply(this,
  829. arguments) || this;
  830. /* *
  831. *
  832. * Properties
  833. *
  834. * */
  835. _this.axisRatio = void 0;
  836. _this.data = void 0;
  837. _this.mapOptionsToLevel = void 0;
  838. _this.nodeMap = void 0;
  839. _this.options = void 0;
  840. _this.points = void 0;
  841. _this.rootNode = void 0;
  842. _this.tree = void 0;
  843. return _this;
  844. /* eslint-enable valid-jsdoc */
  845. }
  846. /* *
  847. *
  848. * Function
  849. *
  850. * */
  851. /* eslint-disable valid-jsdoc */
  852. TreemapSeries.prototype.algorithmCalcPoints = function (directionChange, last, group, childrenArea) {
  853. var pX,
  854. pY,
  855. pW,
  856. pH,
  857. gW = group.lW,
  858. gH = group.lH,
  859. plot = group.plot,
  860. keep,
  861. i = 0,
  862. end = group.elArr.length - 1;
  863. if (last) {
  864. gW = group.nW;
  865. gH = group.nH;
  866. }
  867. else {
  868. keep = group.elArr[group.elArr.length - 1];
  869. }
  870. group.elArr.forEach(function (p) {
  871. if (last || (i < end)) {
  872. if (group.direction === 0) {
  873. pX = plot.x;
  874. pY = plot.y;
  875. pW = gW;
  876. pH = p / pW;
  877. }
  878. else {
  879. pX = plot.x;
  880. pY = plot.y;
  881. pH = gH;
  882. pW = p / pH;
  883. }
  884. childrenArea.push({
  885. x: pX,
  886. y: pY,
  887. width: pW,
  888. height: correctFloat(pH)
  889. });
  890. if (group.direction === 0) {
  891. plot.y = plot.y + pH;
  892. }
  893. else {
  894. plot.x = plot.x + pW;
  895. }
  896. }
  897. i = i + 1;
  898. });
  899. // Reset variables
  900. group.reset();
  901. if (group.direction === 0) {
  902. group.width = group.width - gW;
  903. }
  904. else {
  905. group.height = group.height - gH;
  906. }
  907. plot.y = plot.parent.y + (plot.parent.height - group.height);
  908. plot.x = plot.parent.x + (plot.parent.width - group.width);
  909. if (directionChange) {
  910. group.direction = 1 - group.direction;
  911. }
  912. // If not last, then add uncalculated element
  913. if (!last) {
  914. group.addElement(keep);
  915. }
  916. };
  917. TreemapSeries.prototype.algorithmFill = function (directionChange, parent, children) {
  918. var childrenArea = [],
  919. pTot,
  920. direction = parent.direction,
  921. x = parent.x,
  922. y = parent.y,
  923. width = parent.width,
  924. height = parent.height,
  925. pX,
  926. pY,
  927. pW,
  928. pH;
  929. children.forEach(function (child) {
  930. pTot =
  931. (parent.width * parent.height) * (child.val / parent.val);
  932. pX = x;
  933. pY = y;
  934. if (direction === 0) {
  935. pH = height;
  936. pW = pTot / pH;
  937. width = width - pW;
  938. x = x + pW;
  939. }
  940. else {
  941. pW = width;
  942. pH = pTot / pW;
  943. height = height - pH;
  944. y = y + pH;
  945. }
  946. childrenArea.push({
  947. x: pX,
  948. y: pY,
  949. width: pW,
  950. height: pH
  951. });
  952. if (directionChange) {
  953. direction = 1 - direction;
  954. }
  955. });
  956. return childrenArea;
  957. };
  958. TreemapSeries.prototype.algorithmLowAspectRatio = function (directionChange, parent, children) {
  959. var childrenArea = [],
  960. series = this,
  961. pTot,
  962. plot = {
  963. x: parent.x,
  964. y: parent.y,
  965. parent: parent
  966. },
  967. direction = parent.direction,
  968. i = 0,
  969. end = children.length - 1,
  970. group = new TreemapAlgorithmGroup(parent.height,
  971. parent.width,
  972. direction,
  973. plot);
  974. // Loop through and calculate all areas
  975. children.forEach(function (child) {
  976. pTot =
  977. (parent.width * parent.height) * (child.val / parent.val);
  978. group.addElement(pTot);
  979. if (group.lP.nR > group.lP.lR) {
  980. series.algorithmCalcPoints(directionChange, false, group, childrenArea, plot // @todo no supported
  981. );
  982. }
  983. // If last child, then calculate all remaining areas
  984. if (i === end) {
  985. series.algorithmCalcPoints(directionChange, true, group, childrenArea, plot // @todo not supported
  986. );
  987. }
  988. i = i + 1;
  989. });
  990. return childrenArea;
  991. };
  992. /**
  993. * Over the alignment method by setting z index.
  994. * @private
  995. */
  996. TreemapSeries.prototype.alignDataLabel = function (point, dataLabel, labelOptions) {
  997. var style = labelOptions.style;
  998. // #8160: Prevent the label from exceeding the point's
  999. // boundaries in treemaps by applying ellipsis overflow.
  1000. // The issue was happening when datalabel's text contained a
  1001. // long sequence of characters without a whitespace.
  1002. if (style &&
  1003. !defined(style.textOverflow) &&
  1004. dataLabel.text &&
  1005. dataLabel.getBBox().width > dataLabel.text.textWidth) {
  1006. dataLabel.css({
  1007. textOverflow: 'ellipsis',
  1008. // unit (px) is required when useHTML is true
  1009. width: style.width += 'px'
  1010. });
  1011. }
  1012. ColumnSeries.prototype.alignDataLabel.apply(this, arguments);
  1013. if (point.dataLabel) {
  1014. // point.node.zIndex could be undefined (#6956)
  1015. point.dataLabel.attr({ zIndex: (point.node.zIndex || 0) + 1 });
  1016. }
  1017. };
  1018. TreemapSeries.prototype.buildNode = function (id, i, level, list, parent) {
  1019. var series = this,
  1020. children = [],
  1021. point = series.points[i],
  1022. height = 0,
  1023. node,
  1024. child;
  1025. // Actions
  1026. ((list[id] || [])).forEach(function (i) {
  1027. child = series.buildNode(series.points[i].id, i, (level + 1), list, id);
  1028. height = Math.max(child.height + 1, height);
  1029. children.push(child);
  1030. });
  1031. node = {
  1032. id: id,
  1033. i: i,
  1034. children: children,
  1035. height: height,
  1036. level: level,
  1037. parent: parent,
  1038. visible: false // @todo move this to better location
  1039. };
  1040. series.nodeMap[node.id] = node;
  1041. if (point) {
  1042. point.node = node;
  1043. }
  1044. return node;
  1045. };
  1046. /**
  1047. * Recursive function which calculates the area for all children of a
  1048. * node.
  1049. *
  1050. * @private
  1051. * @function Highcharts.Series#calculateChildrenAreas
  1052. *
  1053. * @param {object} node
  1054. * The node which is parent to the children.
  1055. *
  1056. * @param {object} area
  1057. * The rectangular area of the parent.
  1058. */
  1059. TreemapSeries.prototype.calculateChildrenAreas = function (parent, area) {
  1060. var series = this,
  1061. options = series.options,
  1062. mapOptionsToLevel = series.mapOptionsToLevel,
  1063. level = mapOptionsToLevel[parent.level + 1],
  1064. algorithm = pick((series[(level && level.layoutAlgorithm)] &&
  1065. level.layoutAlgorithm),
  1066. options.layoutAlgorithm),
  1067. alternate = options.alternateStartingDirection,
  1068. childrenValues = [],
  1069. children;
  1070. // Collect all children which should be included
  1071. children = parent.children.filter(function (n) {
  1072. return !n.ignore;
  1073. });
  1074. if (level && level.layoutStartingDirection) {
  1075. area.direction = level.layoutStartingDirection === 'vertical' ?
  1076. 0 :
  1077. 1;
  1078. }
  1079. childrenValues = series[algorithm](area, children);
  1080. children.forEach(function (child, index) {
  1081. var values = childrenValues[index];
  1082. child.values = merge(values, {
  1083. val: child.childrenTotal,
  1084. direction: (alternate ? 1 - area.direction : area.direction)
  1085. });
  1086. child.pointValues = merge(values, {
  1087. x: (values.x / series.axisRatio),
  1088. // Flip y-values to avoid visual regression with csvCoord in
  1089. // Axis.translate at setPointValues. #12488
  1090. y: TreemapUtilities.AXIS_MAX - values.y - values.height,
  1091. width: (values.width / series.axisRatio)
  1092. });
  1093. // If node has children, then call method recursively
  1094. if (child.children.length) {
  1095. series.calculateChildrenAreas(child, child.values);
  1096. }
  1097. });
  1098. };
  1099. /**
  1100. * Extend drawDataLabels with logic to handle custom options related to
  1101. * the treemap series:
  1102. *
  1103. * - Points which is not a leaf node, has dataLabels disabled by
  1104. * default.
  1105. *
  1106. * - Options set on series.levels is merged in.
  1107. *
  1108. * - Width of the dataLabel is set to match the width of the point
  1109. * shape.
  1110. *
  1111. * @private
  1112. */
  1113. TreemapSeries.prototype.drawDataLabels = function () {
  1114. var series = this,
  1115. mapOptionsToLevel = series.mapOptionsToLevel,
  1116. points = series.points.filter(function (n) {
  1117. return n.node.visible;
  1118. }), options, level;
  1119. points.forEach(function (point) {
  1120. level = mapOptionsToLevel[point.node.level];
  1121. // Set options to new object to avoid problems with scope
  1122. options = { style: {} };
  1123. // If not a leaf, then label should be disabled as default
  1124. if (!point.node.isLeaf) {
  1125. options.enabled = false;
  1126. }
  1127. // If options for level exists, include them as well
  1128. if (level && level.dataLabels) {
  1129. options = merge(options, level.dataLabels);
  1130. series._hasPointLabels = true;
  1131. }
  1132. // Set dataLabel width to the width of the point shape.
  1133. if (point.shapeArgs) {
  1134. options.style.width = point.shapeArgs.width;
  1135. if (point.dataLabel) {
  1136. point.dataLabel.css({
  1137. width: point.shapeArgs.width + 'px'
  1138. });
  1139. }
  1140. }
  1141. // Merge custom options with point options
  1142. point.dlOptions = merge(options, point.options.dataLabels);
  1143. });
  1144. Series.prototype.drawDataLabels.call(this);
  1145. };
  1146. /**
  1147. * Override drawPoints
  1148. * @private
  1149. */
  1150. TreemapSeries.prototype.drawPoints = function () {
  1151. var series = this,
  1152. chart = series.chart,
  1153. renderer = chart.renderer,
  1154. points = series.points,
  1155. styledMode = chart.styledMode,
  1156. options = series.options,
  1157. shadow = styledMode ? {} : options.shadow,
  1158. borderRadius = options.borderRadius,
  1159. withinAnimationLimit = chart.pointCount < options.animationLimit,
  1160. allowTraversingTree = options.allowTraversingTree;
  1161. points.forEach(function (point) {
  1162. var levelDynamic = point.node.levelDynamic,
  1163. animatableAttribs = {},
  1164. attribs = {},
  1165. css = {},
  1166. groupKey = 'level-group-' + point.node.level,
  1167. hasGraphic = !!point.graphic,
  1168. shouldAnimate = withinAnimationLimit && hasGraphic,
  1169. shapeArgs = point.shapeArgs;
  1170. // Don't bother with calculate styling if the point is not drawn
  1171. if (point.shouldDraw()) {
  1172. point.isInside = true;
  1173. if (borderRadius) {
  1174. attribs.r = borderRadius;
  1175. }
  1176. merge(true, // Extend object
  1177. // Which object to extend
  1178. shouldAnimate ? animatableAttribs : attribs,
  1179. // Add shapeArgs to animate/attr if graphic exists
  1180. hasGraphic ? shapeArgs : {},
  1181. // Add style attribs if !styleMode
  1182. styledMode ?
  1183. {} :
  1184. series.pointAttribs(point, point.selected ? 'select' : void 0));
  1185. // In styled mode apply point.color. Use CSS, otherwise the
  1186. // fill used in the style sheet will take precedence over
  1187. // the fill attribute.
  1188. if (series.colorAttribs && styledMode) {
  1189. // Heatmap is loaded
  1190. extend(css, series.colorAttribs(point));
  1191. }
  1192. if (!series[groupKey]) {
  1193. series[groupKey] = renderer.g(groupKey)
  1194. .attr({
  1195. // @todo Set the zIndex based upon the number of
  1196. // levels, instead of using 1000
  1197. zIndex: 1000 - (levelDynamic || 0)
  1198. })
  1199. .add(series.group);
  1200. series[groupKey].survive = true;
  1201. }
  1202. }
  1203. // Draw the point
  1204. point.draw({
  1205. animatableAttribs: animatableAttribs,
  1206. attribs: attribs,
  1207. css: css,
  1208. group: series[groupKey],
  1209. renderer: renderer,
  1210. shadow: shadow,
  1211. shapeArgs: shapeArgs,
  1212. shapeType: 'rect'
  1213. });
  1214. // If setRootNode is allowed, set a point cursor on clickables &
  1215. // add drillId to point
  1216. if (allowTraversingTree && point.graphic) {
  1217. point.drillId = options.interactByLeaf ?
  1218. series.drillToByLeaf(point) :
  1219. series.drillToByGroup(point);
  1220. }
  1221. });
  1222. };
  1223. /**
  1224. * Finds the drill id for a parent node. Returns false if point should
  1225. * not have a click event.
  1226. * @private
  1227. */
  1228. TreemapSeries.prototype.drillToByGroup = function (point) {
  1229. var series = this,
  1230. drillId = false;
  1231. if ((point.node.level - series.nodeMap[series.rootNode].level) ===
  1232. 1 &&
  1233. !point.node.isLeaf) {
  1234. drillId = point.id;
  1235. }
  1236. return drillId;
  1237. };
  1238. /**
  1239. * Finds the drill id for a leaf node. Returns false if point should not
  1240. * have a click event
  1241. * @private
  1242. */
  1243. TreemapSeries.prototype.drillToByLeaf = function (point) {
  1244. var series = this,
  1245. drillId = false,
  1246. nodeParent;
  1247. if ((point.node.parent !== series.rootNode) &&
  1248. point.node.isLeaf) {
  1249. nodeParent = point.node;
  1250. while (!drillId) {
  1251. nodeParent = series.nodeMap[nodeParent.parent];
  1252. if (nodeParent.parent === series.rootNode) {
  1253. drillId = nodeParent.id;
  1254. }
  1255. }
  1256. }
  1257. return drillId;
  1258. };
  1259. /**
  1260. * @todo remove this function at a suitable version.
  1261. * @private
  1262. */
  1263. TreemapSeries.prototype.drillToNode = function (id, redraw) {
  1264. error(32, false, void 0, { 'treemap.drillToNode': 'use treemap.setRootNode' });
  1265. this.setRootNode(id, redraw);
  1266. };
  1267. TreemapSeries.prototype.drillUp = function () {
  1268. var series = this,
  1269. node = series.nodeMap[series.rootNode];
  1270. if (node && isString(node.parent)) {
  1271. series.setRootNode(node.parent, true, { trigger: 'traverseUpButton' });
  1272. }
  1273. };
  1274. TreemapSeries.prototype.getExtremes = function () {
  1275. // Get the extremes from the value data
  1276. var _a = Series.prototype.getExtremes
  1277. .call(this,
  1278. this.colorValueData),
  1279. dataMin = _a.dataMin,
  1280. dataMax = _a.dataMax;
  1281. this.valueMin = dataMin;
  1282. this.valueMax = dataMax;
  1283. // Get the extremes from the y data
  1284. return Series.prototype.getExtremes.call(this);
  1285. };
  1286. /**
  1287. * Creates an object map from parent id to childrens index.
  1288. *
  1289. * @private
  1290. * @function Highcharts.Series#getListOfParents
  1291. *
  1292. * @param {Highcharts.SeriesTreemapDataOptions} [data]
  1293. * List of points set in options.
  1294. *
  1295. * @param {Array<string>} [existingIds]
  1296. * List of all point ids.
  1297. *
  1298. * @return {object}
  1299. * Map from parent id to children index in data.
  1300. */
  1301. TreemapSeries.prototype.getListOfParents = function (data, existingIds) {
  1302. var arr = isArray(data) ? data : [],
  1303. ids = isArray(existingIds) ? existingIds : [],
  1304. listOfParents = arr.reduce(function (prev,
  1305. curr,
  1306. i) {
  1307. var parent = pick(curr.parent, '');
  1308. if (typeof prev[parent] === 'undefined') {
  1309. prev[parent] = [];
  1310. }
  1311. prev[parent].push(i);
  1312. return prev;
  1313. }, {
  1314. '': [] // Root of tree
  1315. });
  1316. // If parent does not exist, hoist parent to root of tree.
  1317. TreemapUtilities.eachObject(listOfParents, function (children, parent, list) {
  1318. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  1319. children.forEach(function (child) {
  1320. list[''].push(child);
  1321. });
  1322. delete list[parent];
  1323. }
  1324. });
  1325. return listOfParents;
  1326. };
  1327. /**
  1328. * Creates a tree structured object from the series points.
  1329. * @private
  1330. */
  1331. TreemapSeries.prototype.getTree = function () {
  1332. var series = this,
  1333. allIds = this.data.map(function (d) {
  1334. return d.id;
  1335. }), parentList = series.getListOfParents(this.data, allIds);
  1336. series.nodeMap = {};
  1337. return series.buildNode('', -1, 0, parentList);
  1338. };
  1339. /**
  1340. * Define hasData function for non-cartesian series. Returns true if the
  1341. * series has points at all.
  1342. * @private
  1343. */
  1344. TreemapSeries.prototype.hasData = function () {
  1345. return !!this.processedXData.length; // != 0
  1346. };
  1347. TreemapSeries.prototype.init = function (chart, options) {
  1348. var series = this,
  1349. setOptionsEvent;
  1350. // If color series logic is loaded, add some properties
  1351. if (colorMapSeriesMixin) {
  1352. this.colorAttribs = colorMapSeriesMixin.colorAttribs;
  1353. }
  1354. setOptionsEvent = addEvent(series, 'setOptions', function (event) {
  1355. var options = event.userOptions;
  1356. if (defined(options.allowDrillToNode) &&
  1357. !defined(options.allowTraversingTree)) {
  1358. options.allowTraversingTree = options.allowDrillToNode;
  1359. delete options.allowDrillToNode;
  1360. }
  1361. if (defined(options.drillUpButton) &&
  1362. !defined(options.traverseUpButton)) {
  1363. options.traverseUpButton = options.drillUpButton;
  1364. delete options.drillUpButton;
  1365. }
  1366. });
  1367. Series.prototype.init.call(series, chart, options);
  1368. // Treemap's opacity is a different option from other series
  1369. delete series.opacity;
  1370. // Handle deprecated options.
  1371. series.eventsToUnbind.push(setOptionsEvent);
  1372. if (series.options.allowTraversingTree) {
  1373. series.eventsToUnbind.push(addEvent(series, 'click', series.onClickDrillToNode));
  1374. }
  1375. };
  1376. /**
  1377. * Add drilling on the suitable points.
  1378. * @private
  1379. */
  1380. TreemapSeries.prototype.onClickDrillToNode = function (event) {
  1381. var series = this,
  1382. point = event.point,
  1383. drillId = point && point.drillId;
  1384. // If a drill id is returned, add click event and cursor.
  1385. if (isString(drillId)) {
  1386. point.setState(''); // Remove hover
  1387. series.setRootNode(drillId, true, { trigger: 'click' });
  1388. }
  1389. };
  1390. /**
  1391. * Get presentational attributes
  1392. * @private
  1393. */
  1394. TreemapSeries.prototype.pointAttribs = function (point, state) {
  1395. var series = this,
  1396. mapOptionsToLevel = (isObject(series.mapOptionsToLevel) ?
  1397. series.mapOptionsToLevel :
  1398. {}),
  1399. level = point && mapOptionsToLevel[point.node.level] || {},
  1400. options = this.options,
  1401. attr,
  1402. stateOptions = (state && options.states[state]) || {},
  1403. className = (point && point.getClassName()) || '',
  1404. opacity;
  1405. // Set attributes by precedence. Point trumps level trumps series.
  1406. // Stroke width uses pick because it can be 0.
  1407. attr = {
  1408. 'stroke': (point && point.borderColor) ||
  1409. level.borderColor ||
  1410. stateOptions.borderColor ||
  1411. options.borderColor,
  1412. 'stroke-width': pick(point && point.borderWidth, level.borderWidth, stateOptions.borderWidth, options.borderWidth),
  1413. 'dashstyle': (point && point.borderDashStyle) ||
  1414. level.borderDashStyle ||
  1415. stateOptions.borderDashStyle ||
  1416. options.borderDashStyle,
  1417. 'fill': (point && point.color) || this.color
  1418. };
  1419. // Hide levels above the current view
  1420. if (className.indexOf('highcharts-above-level') !== -1) {
  1421. attr.fill = 'none';
  1422. attr['stroke-width'] = 0;
  1423. // Nodes with children that accept interaction
  1424. }
  1425. else if (className.indexOf('highcharts-internal-node-interactive') !== -1) {
  1426. opacity = pick(stateOptions.opacity, options.opacity);
  1427. attr.fill = color(attr.fill).setOpacity(opacity).get();
  1428. attr.cursor = 'pointer';
  1429. // Hide nodes that have children
  1430. }
  1431. else if (className.indexOf('highcharts-internal-node') !== -1) {
  1432. attr.fill = 'none';
  1433. }
  1434. else if (state) {
  1435. // Brighten and hoist the hover nodes
  1436. attr.fill = color(attr.fill)
  1437. .brighten(stateOptions.brightness)
  1438. .get();
  1439. }
  1440. return attr;
  1441. };
  1442. TreemapSeries.prototype.renderTraverseUpButton = function (rootId) {
  1443. var series = this,
  1444. nodeMap = series.nodeMap,
  1445. node = nodeMap[rootId],
  1446. name = node.name,
  1447. buttonOptions = series.options.traverseUpButton,
  1448. backText = pick(buttonOptions.text,
  1449. name, '◁ Back'),
  1450. attr,
  1451. states;
  1452. if (rootId === '' || (series.is('sunburst') &&
  1453. series.tree.children.length === 1 &&
  1454. rootId === series.tree.children[0].id)) {
  1455. if (series.drillUpButton) {
  1456. series.drillUpButton = series.drillUpButton.destroy();
  1457. }
  1458. }
  1459. else if (!this.drillUpButton) {
  1460. attr = buttonOptions.theme;
  1461. states = attr && attr.states;
  1462. this.drillUpButton = this.chart.renderer
  1463. .button(backText, 0, 0, function () {
  1464. series.drillUp();
  1465. }, attr, states && states.hover, states && states.select)
  1466. .addClass('highcharts-drillup-button')
  1467. .attr({
  1468. align: buttonOptions.position.align,
  1469. zIndex: 7
  1470. })
  1471. .add()
  1472. .align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
  1473. }
  1474. else {
  1475. this.drillUpButton.placed = false;
  1476. this.drillUpButton.attr({
  1477. text: backText
  1478. })
  1479. .align();
  1480. }
  1481. };
  1482. /**
  1483. * Set the node's color recursively, from the parent down.
  1484. * @private
  1485. */
  1486. TreemapSeries.prototype.setColorRecursive = function (node, parentColor, colorIndex, index, siblings) {
  1487. var series = this,
  1488. chart = series && series.chart,
  1489. colors = chart && chart.options && chart.options.colors,
  1490. colorInfo,
  1491. point;
  1492. if (node) {
  1493. colorInfo = getColor(node, {
  1494. colors: colors,
  1495. index: index,
  1496. mapOptionsToLevel: series.mapOptionsToLevel,
  1497. parentColor: parentColor,
  1498. parentColorIndex: colorIndex,
  1499. series: series,
  1500. siblings: siblings
  1501. });
  1502. point = series.points[node.i];
  1503. if (point) {
  1504. point.color = colorInfo.color;
  1505. point.colorIndex = colorInfo.colorIndex;
  1506. }
  1507. // Do it all again with the children
  1508. (node.children || []).forEach(function (child, i) {
  1509. series.setColorRecursive(child, colorInfo.color, colorInfo.colorIndex, i, node.children.length);
  1510. });
  1511. }
  1512. };
  1513. TreemapSeries.prototype.setPointValues = function () {
  1514. var series = this;
  1515. var points = series.points,
  1516. xAxis = series.xAxis,
  1517. yAxis = series.yAxis;
  1518. var styledMode = series.chart.styledMode;
  1519. // Get the crisp correction in classic mode. For this to work in
  1520. // styled mode, we would need to first add the shape (without x,
  1521. // y, width and height), then read the rendered stroke width
  1522. // using point.graphic.strokeWidth(), then modify and apply the
  1523. // shapeArgs. This applies also to column series, but the
  1524. // downside is performance and code complexity.
  1525. var getCrispCorrection = function (point) { return (styledMode ?
  1526. 0 :
  1527. ((series.pointAttribs(point)['stroke-width'] || 0) % 2) / 2); };
  1528. points.forEach(function (point) {
  1529. var _a = point.node,
  1530. values = _a.pointValues,
  1531. visible = _a.visible;
  1532. // Points which is ignored, have no values.
  1533. if (values && visible) {
  1534. var height = values.height,
  1535. width = values.width,
  1536. x = values.x,
  1537. y = values.y;
  1538. var crispCorr = getCrispCorrection(point);
  1539. var x1 = Math.round(xAxis.toPixels(x,
  1540. true)) - crispCorr;
  1541. var x2 = Math.round(xAxis.toPixels(x + width,
  1542. true)) - crispCorr;
  1543. var y1 = Math.round(yAxis.toPixels(y,
  1544. true)) - crispCorr;
  1545. var y2 = Math.round(yAxis.toPixels(y + height,
  1546. true)) - crispCorr;
  1547. // Set point values
  1548. var shapeArgs = {
  1549. x: Math.min(x1,
  1550. x2),
  1551. y: Math.min(y1,
  1552. y2),
  1553. width: Math.abs(x2 - x1),
  1554. height: Math.abs(y2 - y1)
  1555. };
  1556. point.plotX = shapeArgs.x + (shapeArgs.width / 2);
  1557. point.plotY = shapeArgs.y + (shapeArgs.height / 2);
  1558. point.shapeArgs = shapeArgs;
  1559. }
  1560. else {
  1561. // Reset visibility
  1562. delete point.plotX;
  1563. delete point.plotY;
  1564. }
  1565. });
  1566. };
  1567. /**
  1568. * Sets a new root node for the series.
  1569. *
  1570. * @private
  1571. * @function Highcharts.Series#setRootNode
  1572. *
  1573. * @param {string} id
  1574. * The id of the new root node.
  1575. *
  1576. * @param {boolean} [redraw=true]
  1577. * Wether to redraw the chart or not.
  1578. *
  1579. * @param {object} [eventArguments]
  1580. * Arguments to be accessed in event handler.
  1581. *
  1582. * @param {string} [eventArguments.newRootId]
  1583. * Id of the new root.
  1584. *
  1585. * @param {string} [eventArguments.previousRootId]
  1586. * Id of the previous root.
  1587. *
  1588. * @param {boolean} [eventArguments.redraw]
  1589. * Wether to redraw the chart after.
  1590. *
  1591. * @param {object} [eventArguments.series]
  1592. * The series to update the root of.
  1593. *
  1594. * @param {string} [eventArguments.trigger]
  1595. * The action which triggered the event. Undefined if the setRootNode is
  1596. * called directly.
  1597. *
  1598. * @fires Highcharts.Series#event:setRootNode
  1599. */
  1600. TreemapSeries.prototype.setRootNode = function (id, redraw, eventArguments) {
  1601. var series = this,
  1602. eventArgs = extend({
  1603. newRootId: id,
  1604. previousRootId: series.rootNode,
  1605. redraw: pick(redraw,
  1606. true),
  1607. series: series
  1608. },
  1609. eventArguments);
  1610. /**
  1611. * The default functionality of the setRootNode event.
  1612. *
  1613. * @private
  1614. * @param {object} args The event arguments.
  1615. * @param {string} args.newRootId Id of the new root.
  1616. * @param {string} args.previousRootId Id of the previous root.
  1617. * @param {boolean} args.redraw Wether to redraw the chart after.
  1618. * @param {object} args.series The series to update the root of.
  1619. * @param {string} [args.trigger=undefined] The action which
  1620. * triggered the event. Undefined if the setRootNode is called
  1621. * directly.
  1622. * @return {void}
  1623. */
  1624. var defaultFn = function (args) {
  1625. var series = args.series;
  1626. // Store previous and new root ids on the series.
  1627. series.idPreviousRoot = args.previousRootId;
  1628. series.rootNode = args.newRootId;
  1629. // Redraw the chart
  1630. series.isDirty = true; // Force redraw
  1631. if (args.redraw) {
  1632. series.chart.redraw();
  1633. }
  1634. };
  1635. // Fire setRootNode event.
  1636. fireEvent(series, 'setRootNode', eventArgs, defaultFn);
  1637. };
  1638. /**
  1639. * Workaround for `inactive` state. Since `series.opacity` option is
  1640. * already reserved, don't use that state at all by disabling
  1641. * `inactiveOtherPoints` and not inheriting states by points.
  1642. * @private
  1643. */
  1644. TreemapSeries.prototype.setState = function (state) {
  1645. this.options.inactiveOtherPoints = true;
  1646. Series.prototype.setState.call(this, state, false);
  1647. this.options.inactiveOtherPoints = false;
  1648. };
  1649. TreemapSeries.prototype.setTreeValues = function (tree) {
  1650. var series = this,
  1651. options = series.options,
  1652. idRoot = series.rootNode,
  1653. mapIdToNode = series.nodeMap,
  1654. nodeRoot = mapIdToNode[idRoot],
  1655. levelIsConstant = (TreemapUtilities.isBoolean(options.levelIsConstant) ?
  1656. options.levelIsConstant :
  1657. true),
  1658. childrenTotal = 0,
  1659. children = [],
  1660. val,
  1661. point = series.points[tree.i];
  1662. // First give the children some values
  1663. tree.children.forEach(function (child) {
  1664. child = series.setTreeValues(child);
  1665. children.push(child);
  1666. if (!child.ignore) {
  1667. childrenTotal += child.val;
  1668. }
  1669. });
  1670. // Sort the children
  1671. stableSort(children, function (a, b) {
  1672. return (a.sortIndex || 0) - (b.sortIndex || 0);
  1673. });
  1674. // Set the values
  1675. val = pick(point && point.options.value, childrenTotal);
  1676. if (point) {
  1677. point.value = val;
  1678. }
  1679. extend(tree, {
  1680. children: children,
  1681. childrenTotal: childrenTotal,
  1682. // Ignore this node if point is not visible
  1683. ignore: !(pick(point && point.visible, true) && (val > 0)),
  1684. isLeaf: tree.visible && !childrenTotal,
  1685. levelDynamic: (tree.level - (levelIsConstant ? 0 : nodeRoot.level)),
  1686. name: pick(point && point.name, ''),
  1687. sortIndex: pick(point && point.sortIndex, -val),
  1688. val: val
  1689. });
  1690. return tree;
  1691. };
  1692. TreemapSeries.prototype.sliceAndDice = function (parent, children) {
  1693. return this.algorithmFill(true, parent, children);
  1694. };
  1695. TreemapSeries.prototype.squarified = function (parent, children) {
  1696. return this.algorithmLowAspectRatio(true, parent, children);
  1697. };
  1698. TreemapSeries.prototype.strip = function (parent, children) {
  1699. return this.algorithmLowAspectRatio(false, parent, children);
  1700. };
  1701. TreemapSeries.prototype.stripes = function (parent, children) {
  1702. return this.algorithmFill(false, parent, children);
  1703. };
  1704. TreemapSeries.prototype.translate = function () {
  1705. var series = this,
  1706. options = series.options,
  1707. // NOTE: updateRootId modifies series.
  1708. rootId = updateRootId(series),
  1709. rootNode,
  1710. pointValues,
  1711. seriesArea,
  1712. tree,
  1713. val;
  1714. // Call prototype function
  1715. Series.prototype.translate.call(series);
  1716. // @todo Only if series.isDirtyData is true
  1717. tree = series.tree = series.getTree();
  1718. rootNode = series.nodeMap[rootId];
  1719. if (rootId !== '' &&
  1720. (!rootNode || !rootNode.children.length)) {
  1721. series.setRootNode('', false);
  1722. rootId = series.rootNode;
  1723. rootNode = series.nodeMap[rootId];
  1724. }
  1725. series.renderTraverseUpButton(rootId);
  1726. series.mapOptionsToLevel = getLevelOptions({
  1727. from: rootNode.level + 1,
  1728. levels: options.levels,
  1729. to: tree.height,
  1730. defaults: {
  1731. levelIsConstant: series.options.levelIsConstant,
  1732. colorByPoint: options.colorByPoint
  1733. }
  1734. });
  1735. // Parents of the root node is by default visible
  1736. TreemapUtilities.recursive(series.nodeMap[series.rootNode], function (node) {
  1737. var next = false,
  1738. p = node.parent;
  1739. node.visible = true;
  1740. if (p || p === '') {
  1741. next = series.nodeMap[p];
  1742. }
  1743. return next;
  1744. });
  1745. // Children of the root node is by default visible
  1746. TreemapUtilities.recursive(series.nodeMap[series.rootNode].children, function (children) {
  1747. var next = false;
  1748. children.forEach(function (child) {
  1749. child.visible = true;
  1750. if (child.children.length) {
  1751. next = (next || []).concat(child.children);
  1752. }
  1753. });
  1754. return next;
  1755. });
  1756. series.setTreeValues(tree);
  1757. // Calculate plotting values.
  1758. series.axisRatio = (series.xAxis.len / series.yAxis.len);
  1759. series.nodeMap[''].pointValues = pointValues = {
  1760. x: 0,
  1761. y: 0,
  1762. width: TreemapUtilities.AXIS_MAX,
  1763. height: TreemapUtilities.AXIS_MAX
  1764. };
  1765. series.nodeMap[''].values = seriesArea = merge(pointValues, {
  1766. width: (pointValues.width * series.axisRatio),
  1767. direction: (options.layoutStartingDirection === 'vertical' ? 0 : 1),
  1768. val: tree.val
  1769. });
  1770. series.calculateChildrenAreas(tree, seriesArea);
  1771. // Logic for point colors
  1772. if (!series.colorAxis &&
  1773. !options.colorByPoint) {
  1774. series.setColorRecursive(series.tree);
  1775. }
  1776. // Update axis extremes according to the root node.
  1777. if (options.allowTraversingTree) {
  1778. val = rootNode.pointValues;
  1779. series.xAxis.setExtremes(val.x, val.x + val.width, false);
  1780. series.yAxis.setExtremes(val.y, val.y + val.height, false);
  1781. series.xAxis.setScale();
  1782. series.yAxis.setScale();
  1783. }
  1784. // Assign values to points.
  1785. series.setPointValues();
  1786. };
  1787. /**
  1788. * A treemap displays hierarchical data using nested rectangles. The data
  1789. * can be laid out in varying ways depending on options.
  1790. *
  1791. * @sample highcharts/demo/treemap-large-dataset/
  1792. * Treemap
  1793. *
  1794. * @extends plotOptions.scatter
  1795. * @excluding dragDrop, marker, jitter, dataSorting
  1796. * @product highcharts
  1797. * @requires modules/treemap
  1798. * @optionparent plotOptions.treemap
  1799. */
  1800. TreemapSeries.defaultOptions = merge(ScatterSeries.defaultOptions, {
  1801. /**
  1802. * When enabled the user can click on a point which is a parent and
  1803. * zoom in on its children. Deprecated and replaced by
  1804. * [allowTraversingTree](#plotOptions.treemap.allowTraversingTree).
  1805. *
  1806. * @sample {highcharts} highcharts/plotoptions/treemap-allowdrilltonode/
  1807. * Enabled
  1808. *
  1809. * @deprecated
  1810. * @type {boolean}
  1811. * @default false
  1812. * @since 4.1.0
  1813. * @product highcharts
  1814. * @apioption plotOptions.treemap.allowDrillToNode
  1815. */
  1816. /**
  1817. * When enabled the user can click on a point which is a parent and
  1818. * zoom in on its children.
  1819. *
  1820. * @sample {highcharts} highcharts/plotoptions/treemap-allowtraversingtree/
  1821. * Enabled
  1822. *
  1823. * @since 7.0.3
  1824. * @product highcharts
  1825. */
  1826. allowTraversingTree: false,
  1827. animationLimit: 250,
  1828. /**
  1829. * The border radius for each treemap item.
  1830. */
  1831. borderRadius: 0,
  1832. /**
  1833. * When the series contains less points than the crop threshold, all
  1834. * points are drawn, event if the points fall outside the visible plot
  1835. * area at the current zoom. The advantage of drawing all points
  1836. * (including markers and columns), is that animation is performed on
  1837. * updates. On the other hand, when the series contains more points than
  1838. * the crop threshold, the series data is cropped to only contain points
  1839. * that fall within the plot area. The advantage of cropping away
  1840. * invisible points is to increase performance on large series.
  1841. *
  1842. * @type {number}
  1843. * @default 300
  1844. * @since 4.1.0
  1845. * @product highcharts
  1846. * @apioption plotOptions.treemap.cropThreshold
  1847. */
  1848. /**
  1849. * Fires on a request for change of root node for the tree, before the
  1850. * update is made. An event object is passed to the function, containing
  1851. * additional properties `newRootId`, `previousRootId`, `redraw` and
  1852. * `trigger`.
  1853. *
  1854. * @type {function}
  1855. * @default undefined
  1856. * @sample {highcharts} highcharts/plotoptions/treemap-events-setrootnode/
  1857. * Alert update information on setRootNode event.
  1858. * @since 7.0.3
  1859. * @product highcharts
  1860. * @apioption plotOptions.treemap.events.setRootNode
  1861. */
  1862. /**
  1863. * This option decides if the user can interact with the parent nodes
  1864. * or just the leaf nodes. When this option is undefined, it will be
  1865. * true by default. However when allowTraversingTree is true, then it
  1866. * will be false by default.
  1867. *
  1868. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-false/
  1869. * False
  1870. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-true-and-allowtraversingtree/
  1871. * InteractByLeaf and allowTraversingTree is true
  1872. *
  1873. * @type {boolean}
  1874. * @since 4.1.2
  1875. * @product highcharts
  1876. * @apioption plotOptions.treemap.interactByLeaf
  1877. */
  1878. /**
  1879. * The sort index of the point inside the treemap level.
  1880. *
  1881. * @sample {highcharts} highcharts/plotoptions/treemap-sortindex/
  1882. * Sort by years
  1883. *
  1884. * @type {number}
  1885. * @since 4.1.10
  1886. * @product highcharts
  1887. * @apioption plotOptions.treemap.sortIndex
  1888. */
  1889. /**
  1890. * A series specific or series type specific color set to apply instead
  1891. * of the global [colors](#colors) when
  1892. * [colorByPoint](#plotOptions.treemap.colorByPoint) is true.
  1893. *
  1894. * @type {Array<Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject>}
  1895. * @since 3.0
  1896. * @product highcharts
  1897. * @apioption plotOptions.treemap.colors
  1898. */
  1899. /**
  1900. * Whether to display this series type or specific series item in the
  1901. * legend.
  1902. */
  1903. showInLegend: false,
  1904. /**
  1905. * @ignore-option
  1906. */
  1907. marker: void 0,
  1908. /**
  1909. * When using automatic point colors pulled from the `options.colors`
  1910. * collection, this option determines whether the chart should receive
  1911. * one color per series or one color per point.
  1912. *
  1913. * @see [series colors](#plotOptions.treemap.colors)
  1914. *
  1915. * @since 2.0
  1916. * @product highcharts
  1917. * @apioption plotOptions.treemap.colorByPoint
  1918. */
  1919. colorByPoint: false,
  1920. /**
  1921. * @since 4.1.0
  1922. */
  1923. dataLabels: {
  1924. defer: false,
  1925. enabled: true,
  1926. formatter: function () {
  1927. var point = this && this.point ?
  1928. this.point :
  1929. {},
  1930. name = isString(point.name) ? point.name : '';
  1931. return name;
  1932. },
  1933. inside: true,
  1934. verticalAlign: 'middle'
  1935. },
  1936. tooltip: {
  1937. headerFormat: '',
  1938. pointFormat: '<b>{point.name}</b>: {point.value}<br/>'
  1939. },
  1940. /**
  1941. * Whether to ignore hidden points when the layout algorithm runs.
  1942. * If `false`, hidden points will leave open spaces.
  1943. *
  1944. * @since 5.0.8
  1945. */
  1946. ignoreHiddenPoint: true,
  1947. /**
  1948. * This option decides which algorithm is used for setting position
  1949. * and dimensions of the points.
  1950. *
  1951. * @see [How to write your own algorithm](https://www.highcharts.com/docs/chart-and-series-types/treemap)
  1952. *
  1953. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-sliceanddice/
  1954. * SliceAndDice by default
  1955. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-stripes/
  1956. * Stripes
  1957. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-squarified/
  1958. * Squarified
  1959. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-strip/
  1960. * Strip
  1961. *
  1962. * @since 4.1.0
  1963. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  1964. */
  1965. layoutAlgorithm: 'sliceAndDice',
  1966. /**
  1967. * Defines which direction the layout algorithm will start drawing.
  1968. *
  1969. * @since 4.1.0
  1970. * @validvalue ["vertical", "horizontal"]
  1971. */
  1972. layoutStartingDirection: 'vertical',
  1973. /**
  1974. * Enabling this option will make the treemap alternate the drawing
  1975. * direction between vertical and horizontal. The next levels starting
  1976. * direction will always be the opposite of the previous.
  1977. *
  1978. * @sample {highcharts} highcharts/plotoptions/treemap-alternatestartingdirection-true/
  1979. * Enabled
  1980. *
  1981. * @since 4.1.0
  1982. */
  1983. alternateStartingDirection: false,
  1984. /**
  1985. * Used together with the levels and allowTraversingTree options. When
  1986. * set to false the first level visible to be level one, which is
  1987. * dynamic when traversing the tree. Otherwise the level will be the
  1988. * same as the tree structure.
  1989. *
  1990. * @since 4.1.0
  1991. */
  1992. levelIsConstant: true,
  1993. /**
  1994. * Options for the button appearing when drilling down in a treemap.
  1995. * Deprecated and replaced by
  1996. * [traverseUpButton](#plotOptions.treemap.traverseUpButton).
  1997. *
  1998. * @deprecated
  1999. */
  2000. drillUpButton: {
  2001. /**
  2002. * The position of the button.
  2003. *
  2004. * @deprecated
  2005. */
  2006. position: {
  2007. /**
  2008. * Vertical alignment of the button.
  2009. *
  2010. * @deprecated
  2011. * @type {Highcharts.VerticalAlignValue}
  2012. * @default top
  2013. * @product highcharts
  2014. * @apioption plotOptions.treemap.drillUpButton.position.verticalAlign
  2015. */
  2016. /**
  2017. * Horizontal alignment of the button.
  2018. *
  2019. * @deprecated
  2020. * @type {Highcharts.AlignValue}
  2021. */
  2022. align: 'right',
  2023. /**
  2024. * Horizontal offset of the button.
  2025. *
  2026. * @deprecated
  2027. */
  2028. x: -10,
  2029. /**
  2030. * Vertical offset of the button.
  2031. *
  2032. * @deprecated
  2033. */
  2034. y: 10
  2035. }
  2036. },
  2037. /**
  2038. * Options for the button appearing when traversing down in a treemap.
  2039. */
  2040. traverseUpButton: {
  2041. /**
  2042. * The position of the button.
  2043. */
  2044. position: {
  2045. /**
  2046. * Vertical alignment of the button.
  2047. *
  2048. * @type {Highcharts.VerticalAlignValue}
  2049. * @default top
  2050. * @product highcharts
  2051. * @apioption plotOptions.treemap.traverseUpButton.position.verticalAlign
  2052. */
  2053. /**
  2054. * Horizontal alignment of the button.
  2055. *
  2056. * @type {Highcharts.AlignValue}
  2057. */
  2058. align: 'right',
  2059. /**
  2060. * Horizontal offset of the button.
  2061. */
  2062. x: -10,
  2063. /**
  2064. * Vertical offset of the button.
  2065. */
  2066. y: 10
  2067. }
  2068. },
  2069. /**
  2070. * Set options on specific levels. Takes precedence over series options,
  2071. * but not point options.
  2072. *
  2073. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  2074. * Styling dataLabels and borders
  2075. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  2076. * Different layoutAlgorithm
  2077. *
  2078. * @type {Array<*>}
  2079. * @since 4.1.0
  2080. * @product highcharts
  2081. * @apioption plotOptions.treemap.levels
  2082. */
  2083. /**
  2084. * Can set a `borderColor` on all points which lies on the same level.
  2085. *
  2086. * @type {Highcharts.ColorString}
  2087. * @since 4.1.0
  2088. * @product highcharts
  2089. * @apioption plotOptions.treemap.levels.borderColor
  2090. */
  2091. /**
  2092. * Set the dash style of the border of all the point which lies on the
  2093. * level. See
  2094. * [plotOptions.scatter.dashStyle](#plotoptions.scatter.dashstyle)
  2095. * for possible options.
  2096. *
  2097. * @type {Highcharts.DashStyleValue}
  2098. * @since 4.1.0
  2099. * @product highcharts
  2100. * @apioption plotOptions.treemap.levels.borderDashStyle
  2101. */
  2102. /**
  2103. * Can set the borderWidth on all points which lies on the same level.
  2104. *
  2105. * @type {number}
  2106. * @since 4.1.0
  2107. * @product highcharts
  2108. * @apioption plotOptions.treemap.levels.borderWidth
  2109. */
  2110. /**
  2111. * Can set a color on all points which lies on the same level.
  2112. *
  2113. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2114. * @since 4.1.0
  2115. * @product highcharts
  2116. * @apioption plotOptions.treemap.levels.color
  2117. */
  2118. /**
  2119. * A configuration object to define how the color of a child varies from
  2120. * the parent's color. The variation is distributed among the children
  2121. * of node. For example when setting brightness, the brightness change
  2122. * will range from the parent's original brightness on the first child,
  2123. * to the amount set in the `to` setting on the last node. This allows a
  2124. * gradient-like color scheme that sets children out from each other
  2125. * while highlighting the grouping on treemaps and sectors on sunburst
  2126. * charts.
  2127. *
  2128. * @sample highcharts/demo/sunburst/
  2129. * Sunburst with color variation
  2130. *
  2131. * @since 6.0.0
  2132. * @product highcharts
  2133. * @apioption plotOptions.treemap.levels.colorVariation
  2134. */
  2135. /**
  2136. * The key of a color variation. Currently supports `brightness` only.
  2137. *
  2138. * @type {string}
  2139. * @since 6.0.0
  2140. * @product highcharts
  2141. * @validvalue ["brightness"]
  2142. * @apioption plotOptions.treemap.levels.colorVariation.key
  2143. */
  2144. /**
  2145. * The ending value of a color variation. The last sibling will receive
  2146. * this value.
  2147. *
  2148. * @type {number}
  2149. * @since 6.0.0
  2150. * @product highcharts
  2151. * @apioption plotOptions.treemap.levels.colorVariation.to
  2152. */
  2153. /**
  2154. * Can set the options of dataLabels on each point which lies on the
  2155. * level.
  2156. * [plotOptions.treemap.dataLabels](#plotOptions.treemap.dataLabels) for
  2157. * possible values.
  2158. *
  2159. * @extends plotOptions.treemap.dataLabels
  2160. * @since 4.1.0
  2161. * @product highcharts
  2162. * @apioption plotOptions.treemap.levels.dataLabels
  2163. */
  2164. /**
  2165. * Can set the layoutAlgorithm option on a specific level.
  2166. *
  2167. * @type {string}
  2168. * @since 4.1.0
  2169. * @product highcharts
  2170. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  2171. * @apioption plotOptions.treemap.levels.layoutAlgorithm
  2172. */
  2173. /**
  2174. * Can set the layoutStartingDirection option on a specific level.
  2175. *
  2176. * @type {string}
  2177. * @since 4.1.0
  2178. * @product highcharts
  2179. * @validvalue ["vertical", "horizontal"]
  2180. * @apioption plotOptions.treemap.levels.layoutStartingDirection
  2181. */
  2182. /**
  2183. * Decides which level takes effect from the options set in the levels
  2184. * object.
  2185. *
  2186. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  2187. * Styling of both levels
  2188. *
  2189. * @type {number}
  2190. * @since 4.1.0
  2191. * @product highcharts
  2192. * @apioption plotOptions.treemap.levels.level
  2193. */
  2194. // Presentational options
  2195. /**
  2196. * The color of the border surrounding each tree map item.
  2197. *
  2198. * @type {Highcharts.ColorString}
  2199. */
  2200. borderColor: palette.neutralColor10,
  2201. /**
  2202. * The width of the border surrounding each tree map item.
  2203. */
  2204. borderWidth: 1,
  2205. colorKey: 'colorValue',
  2206. /**
  2207. * The opacity of a point in treemap. When a point has children, the
  2208. * visibility of the children is determined by the opacity.
  2209. *
  2210. * @since 4.2.4
  2211. */
  2212. opacity: 0.15,
  2213. /**
  2214. * A wrapper object for all the series options in specific states.
  2215. *
  2216. * @extends plotOptions.heatmap.states
  2217. */
  2218. states: {
  2219. /**
  2220. * Options for the hovered series
  2221. *
  2222. * @extends plotOptions.heatmap.states.hover
  2223. * @excluding halo
  2224. */
  2225. hover: {
  2226. /**
  2227. * The border color for the hovered state.
  2228. */
  2229. borderColor: palette.neutralColor40,
  2230. /**
  2231. * Brightness for the hovered point. Defaults to 0 if the
  2232. * heatmap series is loaded first, otherwise 0.1.
  2233. *
  2234. * @type {number}
  2235. * @default undefined
  2236. */
  2237. brightness: HeatmapSeries ? 0 : 0.1,
  2238. /**
  2239. * @extends plotOptions.heatmap.states.hover.halo
  2240. */
  2241. halo: false,
  2242. /**
  2243. * The opacity of a point in treemap. When a point has children,
  2244. * the visibility of the children is determined by the opacity.
  2245. *
  2246. * @since 4.2.4
  2247. */
  2248. opacity: 0.75,
  2249. /**
  2250. * The shadow option for hovered state.
  2251. */
  2252. shadow: false
  2253. }
  2254. }
  2255. });
  2256. return TreemapSeries;
  2257. }(ScatterSeries));
  2258. extend(TreemapSeries.prototype, {
  2259. buildKDTree: noop,
  2260. colorKey: 'colorValue',
  2261. directTouch: true,
  2262. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  2263. getExtremesFromAll: true,
  2264. getSymbol: noop,
  2265. optionalAxis: 'colorAxis',
  2266. parallelArrays: ['x', 'y', 'value', 'colorValue'],
  2267. pointArrayMap: ['value'],
  2268. pointClass: TreemapPoint,
  2269. trackerGroups: ['group', 'dataLabelsGroup'],
  2270. utils: {
  2271. recursive: TreemapUtilities.recursive
  2272. }
  2273. });
  2274. SeriesRegistry.registerSeriesType('treemap', TreemapSeries);
  2275. /* *
  2276. *
  2277. * Default Export
  2278. *
  2279. * */
  2280. /* *
  2281. *
  2282. * API Options
  2283. *
  2284. * */
  2285. /**
  2286. * A `treemap` series. If the [type](#series.treemap.type) option is
  2287. * not specified, it is inherited from [chart.type](#chart.type).
  2288. *
  2289. * @extends series,plotOptions.treemap
  2290. * @excluding dataParser, dataURL, stack, dataSorting
  2291. * @product highcharts
  2292. * @requires modules/treemap
  2293. * @apioption series.treemap
  2294. */
  2295. /**
  2296. * An array of data points for the series. For the `treemap` series
  2297. * type, points can be given in the following ways:
  2298. *
  2299. * 1. An array of numerical values. In this case, the numerical values will be
  2300. * interpreted as `value` options. Example:
  2301. * ```js
  2302. * data: [0, 5, 3, 5]
  2303. * ```
  2304. *
  2305. * 2. An array of objects with named values. The following snippet shows only a
  2306. * few settings, see the complete options set below. If the total number of
  2307. * data points exceeds the series'
  2308. * [turboThreshold](#series.treemap.turboThreshold),
  2309. * this option is not available.
  2310. * ```js
  2311. * data: [{
  2312. * value: 9,
  2313. * name: "Point2",
  2314. * color: "#00FF00"
  2315. * }, {
  2316. * value: 6,
  2317. * name: "Point1",
  2318. * color: "#FF00FF"
  2319. * }]
  2320. * ```
  2321. *
  2322. * @sample {highcharts} highcharts/chart/reflow-true/
  2323. * Numerical values
  2324. * @sample {highcharts} highcharts/series/data-array-of-objects/
  2325. * Config objects
  2326. *
  2327. * @type {Array<number|null|*>}
  2328. * @extends series.heatmap.data
  2329. * @excluding x, y
  2330. * @product highcharts
  2331. * @apioption series.treemap.data
  2332. */
  2333. /**
  2334. * The value of the point, resulting in a relative area of the point
  2335. * in the treemap.
  2336. *
  2337. * @type {number|null}
  2338. * @product highcharts
  2339. * @apioption series.treemap.data.value
  2340. */
  2341. /**
  2342. * Serves a purpose only if a `colorAxis` object is defined in the chart
  2343. * options. This value will decide which color the point gets from the
  2344. * scale of the colorAxis.
  2345. *
  2346. * @type {number}
  2347. * @since 4.1.0
  2348. * @product highcharts
  2349. * @apioption series.treemap.data.colorValue
  2350. */
  2351. /**
  2352. * Only for treemap. Use this option to build a tree structure. The
  2353. * value should be the id of the point which is the parent. If no points
  2354. * has a matching id, or this option is undefined, then the parent will
  2355. * be set to the root.
  2356. *
  2357. * @sample {highcharts} highcharts/point/parent/
  2358. * Point parent
  2359. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  2360. * Example where parent id is not matching
  2361. *
  2362. * @type {string}
  2363. * @since 4.1.0
  2364. * @product highcharts
  2365. * @apioption series.treemap.data.parent
  2366. */
  2367. ''; // adds doclets above to transpiled file
  2368. return TreemapSeries;
  2369. });
  2370. _registerModule(_modules, 'masters/modules/treemap.src.js', [], function () {
  2371. });
  2372. }));