treemap.src.js 97 KB

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