treemap.src.js 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  1. /**
  2. * @license Highcharts JS v9.1.0 (2021-05-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. 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 _this = this;
  229. var animatableAttribs = params.animatableAttribs,
  230. onComplete = params.onComplete,
  231. css = params.css,
  232. renderer = params.renderer;
  233. var animation = (this.series && this.series.chart.hasRendered) ?
  234. // Chart-level animation on updates
  235. void 0 :
  236. // Series-level animation on new points
  237. (this.series &&
  238. this.series.options.animation);
  239. var graphic = this.graphic;
  240. if (this.shouldDraw()) {
  241. if (!graphic) {
  242. this.graphic = graphic =
  243. renderer[params.shapeType](params.shapeArgs)
  244. .add(params.group);
  245. }
  246. graphic
  247. .css(css)
  248. .attr(params.attribs)
  249. .animate(animatableAttribs, params.isNew ? false : animation, onComplete);
  250. }
  251. else if (graphic) {
  252. var destroy_1 = function () {
  253. _this.graphic = graphic = (graphic && graphic.destroy());
  254. if (isFn(onComplete)) {
  255. onComplete();
  256. }
  257. };
  258. // animate only runs complete callback if something was animated.
  259. if (Object.keys(animatableAttribs).length) {
  260. graphic.animate(animatableAttribs, void 0, function () {
  261. destroy_1();
  262. });
  263. }
  264. else {
  265. destroy_1();
  266. }
  267. }
  268. };
  269. /**
  270. * An extended version of draw customized for points.
  271. * It calls additional methods that is expected when rendering a point.
  272. * @private
  273. * @param {Highcharts.Dictionary<any>} params Parameters
  274. */
  275. var drawPoint = function drawPoint(params) {
  276. var point = this,
  277. attribs = params.attribs = params.attribs || {};
  278. // Assigning class in dot notation does go well in IE8
  279. // eslint-disable-next-line dot-notation
  280. attribs['class'] = point.getClassName();
  281. // Call draw to render component
  282. draw.call(point, params);
  283. };
  284. var drawPointModule = {
  285. draw: draw,
  286. drawPoint: drawPoint,
  287. isFn: isFn
  288. };
  289. return drawPointModule;
  290. });
  291. _registerModule(_modules, 'Series/Treemap/TreemapPoint.js', [_modules['Mixins/DrawPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (DrawPointMixin, SeriesRegistry, U) {
  292. /* *
  293. *
  294. * (c) 2014-2021 Highsoft AS
  295. *
  296. * Authors: Jon Arild Nygard / Oystein Moseng
  297. *
  298. * License: www.highcharts.com/license
  299. *
  300. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  301. *
  302. * */
  303. var __extends = (this && this.__extends) || (function () {
  304. var extendStatics = function (d,
  305. b) {
  306. extendStatics = Object.setPrototypeOf ||
  307. ({ __proto__: [] } instanceof Array && function (d,
  308. b) { d.__proto__ = b; }) ||
  309. function (d,
  310. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  311. return extendStatics(d, b);
  312. };
  313. return function (d, b) {
  314. extendStatics(d, b);
  315. function __() { this.constructor = d; }
  316. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  317. };
  318. })();
  319. var Point = SeriesRegistry.series.prototype.pointClass,
  320. _a = SeriesRegistry.seriesTypes,
  321. PiePoint = _a.pie.prototype.pointClass,
  322. ScatterPoint = _a.scatter.prototype.pointClass;
  323. var extend = U.extend,
  324. isNumber = U.isNumber,
  325. pick = U.pick;
  326. /* *
  327. *
  328. * Class
  329. *
  330. * */
  331. var TreemapPoint = /** @class */ (function (_super) {
  332. __extends(TreemapPoint, _super);
  333. function TreemapPoint() {
  334. /* *
  335. *
  336. * Properties
  337. *
  338. * */
  339. var _this = _super !== null && _super.apply(this,
  340. arguments) || this;
  341. _this.name = void 0;
  342. _this.node = void 0;
  343. _this.options = void 0;
  344. _this.series = void 0;
  345. _this.value = void 0;
  346. return _this;
  347. /* eslint-enable valid-jsdoc */
  348. }
  349. /* *
  350. *
  351. * Functions
  352. *
  353. * */
  354. /* eslint-disable valid-jsdoc */
  355. TreemapPoint.prototype.getClassName = function () {
  356. var className = Point.prototype.getClassName.call(this),
  357. series = this.series,
  358. options = series.options;
  359. // Above the current level
  360. if (this.node.level <= series.nodeMap[series.rootNode].level) {
  361. className += ' highcharts-above-level';
  362. }
  363. else if (!this.node.isLeaf &&
  364. !pick(options.interactByLeaf, !options.allowTraversingTree)) {
  365. className += ' highcharts-internal-node-interactive';
  366. }
  367. else if (!this.node.isLeaf) {
  368. className += ' highcharts-internal-node';
  369. }
  370. return className;
  371. };
  372. /**
  373. * A tree point is valid if it has han id too, assume it may be a parent
  374. * item.
  375. *
  376. * @private
  377. * @function Highcharts.Point#isValid
  378. */
  379. TreemapPoint.prototype.isValid = function () {
  380. return Boolean(this.id || isNumber(this.value));
  381. };
  382. TreemapPoint.prototype.setState = function (state) {
  383. Point.prototype.setState.call(this, state);
  384. // Graphic does not exist when point is not visible.
  385. if (this.graphic) {
  386. this.graphic.attr({
  387. zIndex: state === 'hover' ? 1 : 0
  388. });
  389. }
  390. };
  391. TreemapPoint.prototype.shouldDraw = function () {
  392. return isNumber(this.plotY) && this.y !== null;
  393. };
  394. return TreemapPoint;
  395. }(ScatterPoint));
  396. extend(TreemapPoint.prototype, {
  397. draw: DrawPointMixin.drawPoint,
  398. setVisible: PiePoint.prototype.setVisible
  399. });
  400. /* *
  401. *
  402. * Default Export
  403. *
  404. * */
  405. return TreemapPoint;
  406. });
  407. _registerModule(_modules, 'Series/Treemap/TreemapUtilities.js', [_modules['Core/Utilities.js']], function (U) {
  408. /* *
  409. *
  410. * (c) 2014-2021 Highsoft AS
  411. *
  412. * Authors: Jon Arild Nygard / Oystein Moseng
  413. *
  414. * License: www.highcharts.com/license
  415. *
  416. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  417. *
  418. * */
  419. /* *
  420. *
  421. * Imports
  422. *
  423. * */
  424. var objectEach = U.objectEach;
  425. /* *
  426. *
  427. * Namespace
  428. *
  429. * */
  430. var TreemapUtilities;
  431. (function (TreemapUtilities) {
  432. TreemapUtilities.AXIS_MAX = 100;
  433. /* eslint-disable no-invalid-this, valid-jsdoc */
  434. /**
  435. * @todo Similar to eachObject, this function is likely redundant
  436. */
  437. function isBoolean(x) {
  438. return typeof x === 'boolean';
  439. }
  440. TreemapUtilities.isBoolean = isBoolean;
  441. /**
  442. * @todo Similar to recursive, this function is likely redundant
  443. */
  444. function eachObject(list, func, context) {
  445. context = context || this;
  446. objectEach(list, function (val, key) {
  447. func.call(context, val, key, list);
  448. });
  449. }
  450. TreemapUtilities.eachObject = eachObject;
  451. /**
  452. * @todo find correct name for this function.
  453. * @todo Similar to reduce, this function is likely redundant
  454. */
  455. function recursive(item, func, context) {
  456. if (context === void 0) { context = this; }
  457. var next;
  458. next = func.call(context, item);
  459. if (next !== false) {
  460. recursive(next, func, context);
  461. }
  462. }
  463. TreemapUtilities.recursive = recursive;
  464. })(TreemapUtilities || (TreemapUtilities = {}));
  465. /* *
  466. *
  467. * Default Export
  468. *
  469. * */
  470. return TreemapUtilities;
  471. });
  472. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  473. /* *
  474. *
  475. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  476. *
  477. * */
  478. var extend = U.extend,
  479. isArray = U.isArray,
  480. isNumber = U.isNumber,
  481. isObject = U.isObject,
  482. merge = U.merge,
  483. pick = U.pick;
  484. var isBoolean = function (x) {
  485. return typeof x === 'boolean';
  486. }, isFn = function (x) {
  487. return typeof x === 'function';
  488. };
  489. /* eslint-disable valid-jsdoc */
  490. /**
  491. * @todo Combine buildTree and buildNode with setTreeValues
  492. * @todo Remove logic from Treemap and make it utilize this mixin.
  493. * @private
  494. */
  495. var setTreeValues = function setTreeValues(tree,
  496. options) {
  497. var before = options.before,
  498. idRoot = options.idRoot,
  499. mapIdToNode = options.mapIdToNode,
  500. nodeRoot = mapIdToNode[idRoot],
  501. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  502. options.levelIsConstant :
  503. true),
  504. points = options.points,
  505. point = points[tree.i],
  506. optionsPoint = point && point.options || {},
  507. childrenTotal = 0,
  508. children = [],
  509. value;
  510. tree.levelDynamic = tree.level - (levelIsConstant ? 0 : nodeRoot.level);
  511. tree.name = pick(point && point.name, '');
  512. tree.visible = (idRoot === tree.id ||
  513. (isBoolean(options.visible) ? options.visible : false));
  514. if (isFn(before)) {
  515. tree = before(tree, options);
  516. }
  517. // First give the children some values
  518. tree.children.forEach(function (child, i) {
  519. var newOptions = extend({},
  520. options);
  521. extend(newOptions, {
  522. index: i,
  523. siblings: tree.children.length,
  524. visible: tree.visible
  525. });
  526. child = setTreeValues(child, newOptions);
  527. children.push(child);
  528. if (child.visible) {
  529. childrenTotal += child.val;
  530. }
  531. });
  532. tree.visible = childrenTotal > 0 || tree.visible;
  533. // Set the values
  534. value = pick(optionsPoint.value, childrenTotal);
  535. tree.children = children;
  536. tree.childrenTotal = childrenTotal;
  537. tree.isLeaf = tree.visible && !childrenTotal;
  538. tree.val = value;
  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: void 0,
  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 (style &&
  1001. !defined(style.textOverflow) &&
  1002. dataLabel.text &&
  1003. dataLabel.getBBox().width > dataLabel.text.textWidth) {
  1004. dataLabel.css({
  1005. textOverflow: 'ellipsis',
  1006. // unit (px) is required when useHTML is true
  1007. width: style.width += 'px'
  1008. });
  1009. }
  1010. ColumnSeries.prototype.alignDataLabel.apply(this, arguments);
  1011. if (point.dataLabel) {
  1012. // point.node.zIndex could be undefined (#6956)
  1013. point.dataLabel.attr({ zIndex: (point.node.zIndex || 0) + 1 });
  1014. }
  1015. };
  1016. TreemapSeries.prototype.buildNode = function (id, i, level, list, parent) {
  1017. var series = this,
  1018. children = [],
  1019. point = series.points[i],
  1020. height = 0,
  1021. node,
  1022. child;
  1023. // Actions
  1024. ((list[id] || [])).forEach(function (i) {
  1025. child = series.buildNode(series.points[i].id, i, (level + 1), list, id);
  1026. height = Math.max(child.height + 1, height);
  1027. children.push(child);
  1028. });
  1029. node = {
  1030. id: id,
  1031. i: i,
  1032. children: children,
  1033. height: height,
  1034. level: level,
  1035. parent: parent,
  1036. visible: false // @todo move this to better location
  1037. };
  1038. series.nodeMap[node.id] = node;
  1039. if (point) {
  1040. point.node = node;
  1041. }
  1042. return node;
  1043. };
  1044. /**
  1045. * Recursive function which calculates the area for all children of a
  1046. * node.
  1047. *
  1048. * @private
  1049. * @function Highcharts.Series#calculateChildrenAreas
  1050. *
  1051. * @param {object} node
  1052. * The node which is parent to the children.
  1053. *
  1054. * @param {object} area
  1055. * The rectangular area of the parent.
  1056. */
  1057. TreemapSeries.prototype.calculateChildrenAreas = function (parent, area) {
  1058. var series = this,
  1059. options = series.options,
  1060. mapOptionsToLevel = series.mapOptionsToLevel,
  1061. level = mapOptionsToLevel[parent.level + 1],
  1062. algorithm = pick((series[(level && level.layoutAlgorithm)] &&
  1063. level.layoutAlgorithm),
  1064. options.layoutAlgorithm),
  1065. alternate = options.alternateStartingDirection,
  1066. childrenValues = [],
  1067. children;
  1068. // Collect all children which should be included
  1069. children = parent.children.filter(function (n) {
  1070. return !n.ignore;
  1071. });
  1072. if (level && level.layoutStartingDirection) {
  1073. area.direction = level.layoutStartingDirection === 'vertical' ?
  1074. 0 :
  1075. 1;
  1076. }
  1077. childrenValues = series[algorithm](area, children);
  1078. children.forEach(function (child, index) {
  1079. var values = childrenValues[index];
  1080. child.values = merge(values, {
  1081. val: child.childrenTotal,
  1082. direction: (alternate ? 1 - area.direction : area.direction)
  1083. });
  1084. child.pointValues = merge(values, {
  1085. x: (values.x / series.axisRatio),
  1086. // Flip y-values to avoid visual regression with csvCoord in
  1087. // Axis.translate at setPointValues. #12488
  1088. y: TreemapUtilities.AXIS_MAX - values.y - values.height,
  1089. width: (values.width / series.axisRatio)
  1090. });
  1091. // If node has children, then call method recursively
  1092. if (child.children.length) {
  1093. series.calculateChildrenAreas(child, child.values);
  1094. }
  1095. });
  1096. };
  1097. /**
  1098. * Extend drawDataLabels with logic to handle custom options related to
  1099. * the treemap series:
  1100. *
  1101. * - Points which is not a leaf node, has dataLabels disabled by
  1102. * default.
  1103. *
  1104. * - Options set on series.levels is merged in.
  1105. *
  1106. * - Width of the dataLabel is set to match the width of the point
  1107. * shape.
  1108. *
  1109. * @private
  1110. */
  1111. TreemapSeries.prototype.drawDataLabels = function () {
  1112. var series = this,
  1113. mapOptionsToLevel = series.mapOptionsToLevel,
  1114. points = series.points.filter(function (n) {
  1115. return n.node.visible;
  1116. }), options, level;
  1117. points.forEach(function (point) {
  1118. level = mapOptionsToLevel[point.node.level];
  1119. // Set options to new object to avoid problems with scope
  1120. options = { style: {} };
  1121. // If not a leaf, then label should be disabled as default
  1122. if (!point.node.isLeaf) {
  1123. options.enabled = false;
  1124. }
  1125. // If options for level exists, include them as well
  1126. if (level && level.dataLabels) {
  1127. options = merge(options, level.dataLabels);
  1128. series._hasPointLabels = true;
  1129. }
  1130. // Set dataLabel width to the width of the point shape.
  1131. if (point.shapeArgs) {
  1132. options.style.width = point.shapeArgs.width;
  1133. if (point.dataLabel) {
  1134. point.dataLabel.css({
  1135. width: point.shapeArgs.width + 'px'
  1136. });
  1137. }
  1138. }
  1139. // Merge custom options with point options
  1140. point.dlOptions = merge(options, point.options.dataLabels);
  1141. });
  1142. Series.prototype.drawDataLabels.call(this);
  1143. };
  1144. /**
  1145. * Override drawPoints
  1146. * @private
  1147. */
  1148. TreemapSeries.prototype.drawPoints = function () {
  1149. var series = this,
  1150. chart = series.chart,
  1151. renderer = chart.renderer,
  1152. points = series.points,
  1153. styledMode = chart.styledMode,
  1154. options = series.options,
  1155. shadow = styledMode ? {} : options.shadow,
  1156. borderRadius = options.borderRadius,
  1157. withinAnimationLimit = chart.pointCount < options.animationLimit,
  1158. allowTraversingTree = options.allowTraversingTree;
  1159. points.forEach(function (point) {
  1160. var levelDynamic = point.node.levelDynamic,
  1161. animatableAttribs = {},
  1162. attribs = {},
  1163. css = {},
  1164. groupKey = 'level-group-' + point.node.level,
  1165. hasGraphic = !!point.graphic,
  1166. shouldAnimate = withinAnimationLimit && hasGraphic,
  1167. shapeArgs = point.shapeArgs;
  1168. // Don't bother with calculate styling if the point is not drawn
  1169. if (point.shouldDraw()) {
  1170. point.isInside = true;
  1171. if (borderRadius) {
  1172. attribs.r = borderRadius;
  1173. }
  1174. merge(true, // Extend object
  1175. // Which object to extend
  1176. shouldAnimate ? animatableAttribs : attribs,
  1177. // Add shapeArgs to animate/attr if graphic exists
  1178. hasGraphic ? shapeArgs : {},
  1179. // Add style attribs if !styleMode
  1180. styledMode ?
  1181. {} :
  1182. series.pointAttribs(point, point.selected ? 'select' : void 0));
  1183. // In styled mode apply point.color. Use CSS, otherwise the
  1184. // fill used in the style sheet will take precedence over
  1185. // the fill attribute.
  1186. if (series.colorAttribs && styledMode) {
  1187. // Heatmap is loaded
  1188. extend(css, series.colorAttribs(point));
  1189. }
  1190. if (!series[groupKey]) {
  1191. series[groupKey] = renderer.g(groupKey)
  1192. .attr({
  1193. // @todo Set the zIndex based upon the number of
  1194. // levels, instead of using 1000
  1195. zIndex: 1000 - (levelDynamic || 0)
  1196. })
  1197. .add(series.group);
  1198. series[groupKey].survive = true;
  1199. }
  1200. }
  1201. // Draw the point
  1202. point.draw({
  1203. animatableAttribs: animatableAttribs,
  1204. attribs: attribs,
  1205. css: css,
  1206. group: series[groupKey],
  1207. renderer: renderer,
  1208. shadow: shadow,
  1209. shapeArgs: shapeArgs,
  1210. shapeType: 'rect'
  1211. });
  1212. // If setRootNode is allowed, set a point cursor on clickables &
  1213. // add drillId to point
  1214. if (allowTraversingTree && point.graphic) {
  1215. point.drillId = options.interactByLeaf ?
  1216. series.drillToByLeaf(point) :
  1217. series.drillToByGroup(point);
  1218. }
  1219. });
  1220. };
  1221. /**
  1222. * Finds the drill id for a parent node. Returns false if point should
  1223. * not have a click event.
  1224. * @private
  1225. */
  1226. TreemapSeries.prototype.drillToByGroup = function (point) {
  1227. var series = this,
  1228. drillId = false;
  1229. if ((point.node.level - series.nodeMap[series.rootNode].level) ===
  1230. 1 &&
  1231. !point.node.isLeaf) {
  1232. drillId = point.id;
  1233. }
  1234. return drillId;
  1235. };
  1236. /**
  1237. * Finds the drill id for a leaf node. Returns false if point should not
  1238. * have a click event
  1239. * @private
  1240. */
  1241. TreemapSeries.prototype.drillToByLeaf = function (point) {
  1242. var series = this,
  1243. drillId = false,
  1244. nodeParent;
  1245. if ((point.node.parent !== series.rootNode) &&
  1246. point.node.isLeaf) {
  1247. nodeParent = point.node;
  1248. while (!drillId) {
  1249. nodeParent = series.nodeMap[nodeParent.parent];
  1250. if (nodeParent.parent === series.rootNode) {
  1251. drillId = nodeParent.id;
  1252. }
  1253. }
  1254. }
  1255. return drillId;
  1256. };
  1257. /**
  1258. * @todo remove this function at a suitable version.
  1259. * @private
  1260. */
  1261. TreemapSeries.prototype.drillToNode = function (id, redraw) {
  1262. error(32, false, void 0, { 'treemap.drillToNode': 'use treemap.setRootNode' });
  1263. this.setRootNode(id, redraw);
  1264. };
  1265. TreemapSeries.prototype.drillUp = function () {
  1266. var series = this,
  1267. node = series.nodeMap[series.rootNode];
  1268. if (node && isString(node.parent)) {
  1269. series.setRootNode(node.parent, true, { trigger: 'traverseUpButton' });
  1270. }
  1271. };
  1272. TreemapSeries.prototype.getExtremes = function () {
  1273. // Get the extremes from the value data
  1274. var _a = Series.prototype.getExtremes
  1275. .call(this,
  1276. this.colorValueData),
  1277. dataMin = _a.dataMin,
  1278. dataMax = _a.dataMax;
  1279. this.valueMin = dataMin;
  1280. this.valueMax = dataMax;
  1281. // Get the extremes from the y data
  1282. return Series.prototype.getExtremes.call(this);
  1283. };
  1284. /**
  1285. * Creates an object map from parent id to childrens index.
  1286. *
  1287. * @private
  1288. * @function Highcharts.Series#getListOfParents
  1289. *
  1290. * @param {Highcharts.SeriesTreemapDataOptions} [data]
  1291. * List of points set in options.
  1292. *
  1293. * @param {Array<string>} [existingIds]
  1294. * List of all point ids.
  1295. *
  1296. * @return {object}
  1297. * Map from parent id to children index in data.
  1298. */
  1299. TreemapSeries.prototype.getListOfParents = function (data, existingIds) {
  1300. var arr = isArray(data) ? data : [],
  1301. ids = isArray(existingIds) ? existingIds : [],
  1302. listOfParents = arr.reduce(function (prev,
  1303. curr,
  1304. i) {
  1305. var parent = pick(curr.parent, '');
  1306. if (typeof prev[parent] === 'undefined') {
  1307. prev[parent] = [];
  1308. }
  1309. prev[parent].push(i);
  1310. return prev;
  1311. }, {
  1312. '': [] // Root of tree
  1313. });
  1314. // If parent does not exist, hoist parent to root of tree.
  1315. TreemapUtilities.eachObject(listOfParents, function (children, parent, list) {
  1316. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  1317. children.forEach(function (child) {
  1318. list[''].push(child);
  1319. });
  1320. delete list[parent];
  1321. }
  1322. });
  1323. return listOfParents;
  1324. };
  1325. /**
  1326. * Creates a tree structured object from the series points.
  1327. * @private
  1328. */
  1329. TreemapSeries.prototype.getTree = function () {
  1330. var series = this,
  1331. allIds = this.data.map(function (d) {
  1332. return d.id;
  1333. }), parentList = series.getListOfParents(this.data, allIds);
  1334. series.nodeMap = {};
  1335. return series.buildNode('', -1, 0, parentList);
  1336. };
  1337. /**
  1338. * Define hasData function for non-cartesian series. Returns true if the
  1339. * series has points at all.
  1340. * @private
  1341. */
  1342. TreemapSeries.prototype.hasData = function () {
  1343. return !!this.processedXData.length; // != 0
  1344. };
  1345. TreemapSeries.prototype.init = function (chart, options) {
  1346. var series = this,
  1347. setOptionsEvent;
  1348. // If color series logic is loaded, add some properties
  1349. if (colorMapSeriesMixin) {
  1350. this.colorAttribs = colorMapSeriesMixin.colorAttribs;
  1351. }
  1352. setOptionsEvent = addEvent(series, 'setOptions', function (event) {
  1353. var options = event.userOptions;
  1354. if (defined(options.allowDrillToNode) &&
  1355. !defined(options.allowTraversingTree)) {
  1356. options.allowTraversingTree = options.allowDrillToNode;
  1357. delete options.allowDrillToNode;
  1358. }
  1359. if (defined(options.drillUpButton) &&
  1360. !defined(options.traverseUpButton)) {
  1361. options.traverseUpButton = options.drillUpButton;
  1362. delete options.drillUpButton;
  1363. }
  1364. });
  1365. Series.prototype.init.call(series, chart, options);
  1366. // Treemap's opacity is a different option from other series
  1367. delete series.opacity;
  1368. // Handle deprecated options.
  1369. series.eventsToUnbind.push(setOptionsEvent);
  1370. if (series.options.allowTraversingTree) {
  1371. series.eventsToUnbind.push(addEvent(series, 'click', series.onClickDrillToNode));
  1372. }
  1373. };
  1374. /**
  1375. * Add drilling on the suitable points.
  1376. * @private
  1377. */
  1378. TreemapSeries.prototype.onClickDrillToNode = function (event) {
  1379. var series = this,
  1380. point = event.point,
  1381. drillId = point && point.drillId;
  1382. // If a drill id is returned, add click event and cursor.
  1383. if (isString(drillId)) {
  1384. point.setState(''); // Remove hover
  1385. series.setRootNode(drillId, true, { trigger: 'click' });
  1386. }
  1387. };
  1388. /**
  1389. * Get presentational attributes
  1390. * @private
  1391. */
  1392. TreemapSeries.prototype.pointAttribs = function (point, state) {
  1393. var series = this,
  1394. mapOptionsToLevel = (isObject(series.mapOptionsToLevel) ?
  1395. series.mapOptionsToLevel :
  1396. {}),
  1397. level = point && mapOptionsToLevel[point.node.level] || {},
  1398. options = this.options,
  1399. attr,
  1400. stateOptions = (state && options.states[state]) || {},
  1401. className = (point && point.getClassName()) || '',
  1402. opacity;
  1403. // Set attributes by precedence. Point trumps level trumps series.
  1404. // Stroke width uses pick because it can be 0.
  1405. attr = {
  1406. 'stroke': (point && point.borderColor) ||
  1407. level.borderColor ||
  1408. stateOptions.borderColor ||
  1409. options.borderColor,
  1410. 'stroke-width': pick(point && point.borderWidth, level.borderWidth, stateOptions.borderWidth, options.borderWidth),
  1411. 'dashstyle': (point && point.borderDashStyle) ||
  1412. level.borderDashStyle ||
  1413. stateOptions.borderDashStyle ||
  1414. options.borderDashStyle,
  1415. 'fill': (point && point.color) || this.color
  1416. };
  1417. // Hide levels above the current view
  1418. if (className.indexOf('highcharts-above-level') !== -1) {
  1419. attr.fill = 'none';
  1420. attr['stroke-width'] = 0;
  1421. // Nodes with children that accept interaction
  1422. }
  1423. else if (className.indexOf('highcharts-internal-node-interactive') !== -1) {
  1424. opacity = pick(stateOptions.opacity, options.opacity);
  1425. attr.fill = color(attr.fill).setOpacity(opacity).get();
  1426. attr.cursor = 'pointer';
  1427. // Hide nodes that have children
  1428. }
  1429. else if (className.indexOf('highcharts-internal-node') !== -1) {
  1430. attr.fill = 'none';
  1431. }
  1432. else if (state) {
  1433. // Brighten and hoist the hover nodes
  1434. attr.fill = color(attr.fill)
  1435. .brighten(stateOptions.brightness)
  1436. .get();
  1437. }
  1438. return attr;
  1439. };
  1440. TreemapSeries.prototype.renderTraverseUpButton = function (rootId) {
  1441. var series = this,
  1442. nodeMap = series.nodeMap,
  1443. node = nodeMap[rootId],
  1444. name = node.name,
  1445. buttonOptions = series.options.traverseUpButton,
  1446. backText = pick(buttonOptions.text,
  1447. name, '◁ Back'),
  1448. attr,
  1449. states;
  1450. if (rootId === '' || (series.is('sunburst') &&
  1451. series.tree.children.length === 1 &&
  1452. rootId === series.tree.children[0].id)) {
  1453. if (series.drillUpButton) {
  1454. series.drillUpButton = series.drillUpButton.destroy();
  1455. }
  1456. }
  1457. else if (!this.drillUpButton) {
  1458. attr = buttonOptions.theme;
  1459. states = attr && attr.states;
  1460. this.drillUpButton = this.chart.renderer
  1461. .button(backText, 0, 0, function () {
  1462. series.drillUp();
  1463. }, attr, states && states.hover, states && states.select)
  1464. .addClass('highcharts-drillup-button')
  1465. .attr({
  1466. align: buttonOptions.position.align,
  1467. zIndex: 7
  1468. })
  1469. .add()
  1470. .align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
  1471. }
  1472. else {
  1473. this.drillUpButton.placed = false;
  1474. this.drillUpButton.attr({
  1475. text: backText
  1476. })
  1477. .align();
  1478. }
  1479. };
  1480. /**
  1481. * Set the node's color recursively, from the parent down.
  1482. * @private
  1483. */
  1484. TreemapSeries.prototype.setColorRecursive = function (node, parentColor, colorIndex, index, siblings) {
  1485. var series = this,
  1486. chart = series && series.chart,
  1487. colors = chart && chart.options && chart.options.colors,
  1488. colorInfo,
  1489. point;
  1490. if (node) {
  1491. colorInfo = getColor(node, {
  1492. colors: colors,
  1493. index: index,
  1494. mapOptionsToLevel: series.mapOptionsToLevel,
  1495. parentColor: parentColor,
  1496. parentColorIndex: colorIndex,
  1497. series: series,
  1498. siblings: siblings
  1499. });
  1500. point = series.points[node.i];
  1501. if (point) {
  1502. point.color = colorInfo.color;
  1503. point.colorIndex = colorInfo.colorIndex;
  1504. }
  1505. // Do it all again with the children
  1506. (node.children || []).forEach(function (child, i) {
  1507. series.setColorRecursive(child, colorInfo.color, colorInfo.colorIndex, i, node.children.length);
  1508. });
  1509. }
  1510. };
  1511. TreemapSeries.prototype.setPointValues = function () {
  1512. var series = this;
  1513. var points = series.points,
  1514. xAxis = series.xAxis,
  1515. yAxis = series.yAxis;
  1516. var styledMode = series.chart.styledMode;
  1517. // Get the crisp correction in classic mode. For this to work in
  1518. // styled mode, we would need to first add the shape (without x,
  1519. // y, width and height), then read the rendered stroke width
  1520. // using point.graphic.strokeWidth(), then modify and apply the
  1521. // shapeArgs. This applies also to column series, but the
  1522. // downside is performance and code complexity.
  1523. var getCrispCorrection = function (point) { return (styledMode ?
  1524. 0 :
  1525. ((series.pointAttribs(point)['stroke-width'] || 0) % 2) / 2); };
  1526. points.forEach(function (point) {
  1527. var _a = point.node,
  1528. values = _a.pointValues,
  1529. visible = _a.visible;
  1530. // Points which is ignored, have no values.
  1531. if (values && visible) {
  1532. var height = values.height,
  1533. width = values.width,
  1534. x = values.x,
  1535. y = values.y;
  1536. var crispCorr = getCrispCorrection(point);
  1537. var x1 = Math.round(xAxis.toPixels(x,
  1538. true)) - crispCorr;
  1539. var x2 = Math.round(xAxis.toPixels(x + width,
  1540. true)) - crispCorr;
  1541. var y1 = Math.round(yAxis.toPixels(y,
  1542. true)) - crispCorr;
  1543. var y2 = Math.round(yAxis.toPixels(y + height,
  1544. true)) - crispCorr;
  1545. // Set point values
  1546. var shapeArgs = {
  1547. x: Math.min(x1,
  1548. x2),
  1549. y: Math.min(y1,
  1550. y2),
  1551. width: Math.abs(x2 - x1),
  1552. height: Math.abs(y2 - y1)
  1553. };
  1554. point.plotX = shapeArgs.x + (shapeArgs.width / 2);
  1555. point.plotY = shapeArgs.y + (shapeArgs.height / 2);
  1556. point.shapeArgs = shapeArgs;
  1557. }
  1558. else {
  1559. // Reset visibility
  1560. delete point.plotX;
  1561. delete point.plotY;
  1562. }
  1563. });
  1564. };
  1565. /**
  1566. * Sets a new root node for the series.
  1567. *
  1568. * @private
  1569. * @function Highcharts.Series#setRootNode
  1570. *
  1571. * @param {string} id
  1572. * The id of the new root node.
  1573. *
  1574. * @param {boolean} [redraw=true]
  1575. * Wether to redraw the chart or not.
  1576. *
  1577. * @param {object} [eventArguments]
  1578. * Arguments to be accessed in event handler.
  1579. *
  1580. * @param {string} [eventArguments.newRootId]
  1581. * Id of the new root.
  1582. *
  1583. * @param {string} [eventArguments.previousRootId]
  1584. * Id of the previous root.
  1585. *
  1586. * @param {boolean} [eventArguments.redraw]
  1587. * Wether to redraw the chart after.
  1588. *
  1589. * @param {object} [eventArguments.series]
  1590. * The series to update the root of.
  1591. *
  1592. * @param {string} [eventArguments.trigger]
  1593. * The action which triggered the event. Undefined if the setRootNode is
  1594. * called directly.
  1595. *
  1596. * @fires Highcharts.Series#event:setRootNode
  1597. */
  1598. TreemapSeries.prototype.setRootNode = function (id, redraw, eventArguments) {
  1599. var series = this,
  1600. eventArgs = extend({
  1601. newRootId: id,
  1602. previousRootId: series.rootNode,
  1603. redraw: pick(redraw,
  1604. true),
  1605. series: series
  1606. },
  1607. eventArguments);
  1608. /**
  1609. * The default functionality of the setRootNode event.
  1610. *
  1611. * @private
  1612. * @param {object} args The event arguments.
  1613. * @param {string} args.newRootId Id of the new root.
  1614. * @param {string} args.previousRootId Id of the previous root.
  1615. * @param {boolean} args.redraw Wether to redraw the chart after.
  1616. * @param {object} args.series The series to update the root of.
  1617. * @param {string} [args.trigger=undefined] The action which
  1618. * triggered the event. Undefined if the setRootNode is called
  1619. * directly.
  1620. * @return {void}
  1621. */
  1622. var defaultFn = function (args) {
  1623. var series = args.series;
  1624. // Store previous and new root ids on the series.
  1625. series.idPreviousRoot = args.previousRootId;
  1626. series.rootNode = args.newRootId;
  1627. // Redraw the chart
  1628. series.isDirty = true; // Force redraw
  1629. if (args.redraw) {
  1630. series.chart.redraw();
  1631. }
  1632. };
  1633. // Fire setRootNode event.
  1634. fireEvent(series, 'setRootNode', eventArgs, defaultFn);
  1635. };
  1636. /**
  1637. * Workaround for `inactive` state. Since `series.opacity` option is
  1638. * already reserved, don't use that state at all by disabling
  1639. * `inactiveOtherPoints` and not inheriting states by points.
  1640. * @private
  1641. */
  1642. TreemapSeries.prototype.setState = function (state) {
  1643. this.options.inactiveOtherPoints = true;
  1644. Series.prototype.setState.call(this, state, false);
  1645. this.options.inactiveOtherPoints = false;
  1646. };
  1647. TreemapSeries.prototype.setTreeValues = function (tree) {
  1648. var series = this,
  1649. options = series.options,
  1650. idRoot = series.rootNode,
  1651. mapIdToNode = series.nodeMap,
  1652. nodeRoot = mapIdToNode[idRoot],
  1653. levelIsConstant = (TreemapUtilities.isBoolean(options.levelIsConstant) ?
  1654. options.levelIsConstant :
  1655. true),
  1656. childrenTotal = 0,
  1657. children = [],
  1658. val,
  1659. point = series.points[tree.i];
  1660. // First give the children some values
  1661. tree.children.forEach(function (child) {
  1662. child = series.setTreeValues(child);
  1663. children.push(child);
  1664. if (!child.ignore) {
  1665. childrenTotal += child.val;
  1666. }
  1667. });
  1668. // Sort the children
  1669. stableSort(children, function (a, b) {
  1670. return (a.sortIndex || 0) - (b.sortIndex || 0);
  1671. });
  1672. // Set the values
  1673. val = pick(point && point.options.value, childrenTotal);
  1674. if (point) {
  1675. point.value = val;
  1676. }
  1677. extend(tree, {
  1678. children: children,
  1679. childrenTotal: childrenTotal,
  1680. // Ignore this node if point is not visible
  1681. ignore: !(pick(point && point.visible, true) && (val > 0)),
  1682. isLeaf: tree.visible && !childrenTotal,
  1683. levelDynamic: (tree.level - (levelIsConstant ? 0 : nodeRoot.level)),
  1684. name: pick(point && point.name, ''),
  1685. sortIndex: pick(point && point.sortIndex, -val),
  1686. val: val
  1687. });
  1688. return tree;
  1689. };
  1690. TreemapSeries.prototype.sliceAndDice = function (parent, children) {
  1691. return this.algorithmFill(true, parent, children);
  1692. };
  1693. TreemapSeries.prototype.squarified = function (parent, children) {
  1694. return this.algorithmLowAspectRatio(true, parent, children);
  1695. };
  1696. TreemapSeries.prototype.strip = function (parent, children) {
  1697. return this.algorithmLowAspectRatio(false, parent, children);
  1698. };
  1699. TreemapSeries.prototype.stripes = function (parent, children) {
  1700. return this.algorithmFill(false, parent, children);
  1701. };
  1702. TreemapSeries.prototype.translate = function () {
  1703. var series = this,
  1704. options = series.options,
  1705. // NOTE: updateRootId modifies series.
  1706. rootId = updateRootId(series),
  1707. rootNode,
  1708. pointValues,
  1709. seriesArea,
  1710. tree,
  1711. val;
  1712. // Call prototype function
  1713. Series.prototype.translate.call(series);
  1714. // @todo Only if series.isDirtyData is true
  1715. tree = series.tree = series.getTree();
  1716. rootNode = series.nodeMap[rootId];
  1717. if (rootId !== '' &&
  1718. (!rootNode || !rootNode.children.length)) {
  1719. series.setRootNode('', false);
  1720. rootId = series.rootNode;
  1721. rootNode = series.nodeMap[rootId];
  1722. }
  1723. series.renderTraverseUpButton(rootId);
  1724. series.mapOptionsToLevel = getLevelOptions({
  1725. from: rootNode.level + 1,
  1726. levels: options.levels,
  1727. to: tree.height,
  1728. defaults: {
  1729. levelIsConstant: series.options.levelIsConstant,
  1730. colorByPoint: options.colorByPoint
  1731. }
  1732. });
  1733. // Parents of the root node is by default visible
  1734. TreemapUtilities.recursive(series.nodeMap[series.rootNode], function (node) {
  1735. var next = false,
  1736. p = node.parent;
  1737. node.visible = true;
  1738. if (p || p === '') {
  1739. next = series.nodeMap[p];
  1740. }
  1741. return next;
  1742. });
  1743. // Children of the root node is by default visible
  1744. TreemapUtilities.recursive(series.nodeMap[series.rootNode].children, function (children) {
  1745. var next = false;
  1746. children.forEach(function (child) {
  1747. child.visible = true;
  1748. if (child.children.length) {
  1749. next = (next || []).concat(child.children);
  1750. }
  1751. });
  1752. return next;
  1753. });
  1754. series.setTreeValues(tree);
  1755. // Calculate plotting values.
  1756. series.axisRatio = (series.xAxis.len / series.yAxis.len);
  1757. series.nodeMap[''].pointValues = pointValues = {
  1758. x: 0,
  1759. y: 0,
  1760. width: TreemapUtilities.AXIS_MAX,
  1761. height: TreemapUtilities.AXIS_MAX
  1762. };
  1763. series.nodeMap[''].values = seriesArea = merge(pointValues, {
  1764. width: (pointValues.width * series.axisRatio),
  1765. direction: (options.layoutStartingDirection === 'vertical' ? 0 : 1),
  1766. val: tree.val
  1767. });
  1768. series.calculateChildrenAreas(tree, seriesArea);
  1769. // Logic for point colors
  1770. if (!series.colorAxis &&
  1771. !options.colorByPoint) {
  1772. series.setColorRecursive(series.tree);
  1773. }
  1774. // Update axis extremes according to the root node.
  1775. if (options.allowTraversingTree) {
  1776. val = rootNode.pointValues;
  1777. series.xAxis.setExtremes(val.x, val.x + val.width, false);
  1778. series.yAxis.setExtremes(val.y, val.y + val.height, false);
  1779. series.xAxis.setScale();
  1780. series.yAxis.setScale();
  1781. }
  1782. // Assign values to points.
  1783. series.setPointValues();
  1784. };
  1785. /**
  1786. * A treemap displays hierarchical data using nested rectangles. The data
  1787. * can be laid out in varying ways depending on options.
  1788. *
  1789. * @sample highcharts/demo/treemap-large-dataset/
  1790. * Treemap
  1791. *
  1792. * @extends plotOptions.scatter
  1793. * @excluding dragDrop, marker, jitter, dataSorting
  1794. * @product highcharts
  1795. * @requires modules/treemap
  1796. * @optionparent plotOptions.treemap
  1797. */
  1798. TreemapSeries.defaultOptions = merge(ScatterSeries.defaultOptions, {
  1799. /**
  1800. * When enabled the user can click on a point which is a parent and
  1801. * zoom in on its children. Deprecated and replaced by
  1802. * [allowTraversingTree](#plotOptions.treemap.allowTraversingTree).
  1803. *
  1804. * @sample {highcharts} highcharts/plotoptions/treemap-allowdrilltonode/
  1805. * Enabled
  1806. *
  1807. * @deprecated
  1808. * @type {boolean}
  1809. * @default false
  1810. * @since 4.1.0
  1811. * @product highcharts
  1812. * @apioption plotOptions.treemap.allowDrillToNode
  1813. */
  1814. /**
  1815. * When enabled the user can click on a point which is a parent and
  1816. * zoom in on its children.
  1817. *
  1818. * @sample {highcharts} highcharts/plotoptions/treemap-allowtraversingtree/
  1819. * Enabled
  1820. *
  1821. * @since 7.0.3
  1822. * @product highcharts
  1823. */
  1824. allowTraversingTree: false,
  1825. animationLimit: 250,
  1826. /**
  1827. * When the series contains less points than the crop threshold, all
  1828. * points are drawn, event if the points fall outside the visible plot
  1829. * area at the current zoom. The advantage of drawing all points
  1830. * (including markers and columns), is that animation is performed on
  1831. * updates. On the other hand, when the series contains more points than
  1832. * the crop threshold, the series data is cropped to only contain points
  1833. * that fall within the plot area. The advantage of cropping away
  1834. * invisible points is to increase performance on large series.
  1835. *
  1836. * @type {number}
  1837. * @default 300
  1838. * @since 4.1.0
  1839. * @product highcharts
  1840. * @apioption plotOptions.treemap.cropThreshold
  1841. */
  1842. /**
  1843. * Fires on a request for change of root node for the tree, before the
  1844. * update is made. An event object is passed to the function, containing
  1845. * additional properties `newRootId`, `previousRootId`, `redraw` and
  1846. * `trigger`.
  1847. *
  1848. * @type {function}
  1849. * @default undefined
  1850. * @sample {highcharts} highcharts/plotoptions/treemap-events-setrootnode/
  1851. * Alert update information on setRootNode event.
  1852. * @since 7.0.3
  1853. * @product highcharts
  1854. * @apioption plotOptions.treemap.events.setRootNode
  1855. */
  1856. /**
  1857. * This option decides if the user can interact with the parent nodes
  1858. * or just the leaf nodes. When this option is undefined, it will be
  1859. * true by default. However when allowTraversingTree is true, then it
  1860. * will be false by default.
  1861. *
  1862. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-false/
  1863. * False
  1864. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-true-and-allowtraversingtree/
  1865. * InteractByLeaf and allowTraversingTree is true
  1866. *
  1867. * @type {boolean}
  1868. * @since 4.1.2
  1869. * @product highcharts
  1870. * @apioption plotOptions.treemap.interactByLeaf
  1871. */
  1872. /**
  1873. * The sort index of the point inside the treemap level.
  1874. *
  1875. * @sample {highcharts} highcharts/plotoptions/treemap-sortindex/
  1876. * Sort by years
  1877. *
  1878. * @type {number}
  1879. * @since 4.1.10
  1880. * @product highcharts
  1881. * @apioption plotOptions.treemap.sortIndex
  1882. */
  1883. /**
  1884. * A series specific or series type specific color set to apply instead
  1885. * of the global [colors](#colors) when
  1886. * [colorByPoint](#plotOptions.treemap.colorByPoint) is true.
  1887. *
  1888. * @type {Array<Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject>}
  1889. * @since 3.0
  1890. * @product highcharts
  1891. * @apioption plotOptions.treemap.colors
  1892. */
  1893. /**
  1894. * Whether to display this series type or specific series item in the
  1895. * legend.
  1896. */
  1897. showInLegend: false,
  1898. /**
  1899. * @ignore-option
  1900. */
  1901. marker: void 0,
  1902. /**
  1903. * When using automatic point colors pulled from the `options.colors`
  1904. * collection, this option determines whether the chart should receive
  1905. * one color per series or one color per point.
  1906. *
  1907. * @see [series colors](#plotOptions.treemap.colors)
  1908. *
  1909. * @since 2.0
  1910. * @product highcharts
  1911. * @apioption plotOptions.treemap.colorByPoint
  1912. */
  1913. colorByPoint: false,
  1914. /**
  1915. * @since 4.1.0
  1916. */
  1917. dataLabels: {
  1918. defer: false,
  1919. enabled: true,
  1920. formatter: function () {
  1921. var point = this && this.point ?
  1922. this.point :
  1923. {},
  1924. name = isString(point.name) ? point.name : '';
  1925. return name;
  1926. },
  1927. inside: true,
  1928. verticalAlign: 'middle'
  1929. },
  1930. tooltip: {
  1931. headerFormat: '',
  1932. pointFormat: '<b>{point.name}</b>: {point.value}<br/>'
  1933. },
  1934. /**
  1935. * Whether to ignore hidden points when the layout algorithm runs.
  1936. * If `false`, hidden points will leave open spaces.
  1937. *
  1938. * @since 5.0.8
  1939. */
  1940. ignoreHiddenPoint: true,
  1941. /**
  1942. * This option decides which algorithm is used for setting position
  1943. * and dimensions of the points.
  1944. *
  1945. * @see [How to write your own algorithm](https://www.highcharts.com/docs/chart-and-series-types/treemap)
  1946. *
  1947. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-sliceanddice/
  1948. * SliceAndDice by default
  1949. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-stripes/
  1950. * Stripes
  1951. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-squarified/
  1952. * Squarified
  1953. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-strip/
  1954. * Strip
  1955. *
  1956. * @since 4.1.0
  1957. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  1958. */
  1959. layoutAlgorithm: 'sliceAndDice',
  1960. /**
  1961. * Defines which direction the layout algorithm will start drawing.
  1962. *
  1963. * @since 4.1.0
  1964. * @validvalue ["vertical", "horizontal"]
  1965. */
  1966. layoutStartingDirection: 'vertical',
  1967. /**
  1968. * Enabling this option will make the treemap alternate the drawing
  1969. * direction between vertical and horizontal. The next levels starting
  1970. * direction will always be the opposite of the previous.
  1971. *
  1972. * @sample {highcharts} highcharts/plotoptions/treemap-alternatestartingdirection-true/
  1973. * Enabled
  1974. *
  1975. * @since 4.1.0
  1976. */
  1977. alternateStartingDirection: false,
  1978. /**
  1979. * Used together with the levels and allowTraversingTree options. When
  1980. * set to false the first level visible to be level one, which is
  1981. * dynamic when traversing the tree. Otherwise the level will be the
  1982. * same as the tree structure.
  1983. *
  1984. * @since 4.1.0
  1985. */
  1986. levelIsConstant: true,
  1987. /**
  1988. * Options for the button appearing when drilling down in a treemap.
  1989. * Deprecated and replaced by
  1990. * [traverseUpButton](#plotOptions.treemap.traverseUpButton).
  1991. *
  1992. * @deprecated
  1993. */
  1994. drillUpButton: {
  1995. /**
  1996. * The position of the button.
  1997. *
  1998. * @deprecated
  1999. */
  2000. position: {
  2001. /**
  2002. * Vertical alignment of the button.
  2003. *
  2004. * @deprecated
  2005. * @type {Highcharts.VerticalAlignValue}
  2006. * @default top
  2007. * @product highcharts
  2008. * @apioption plotOptions.treemap.drillUpButton.position.verticalAlign
  2009. */
  2010. /**
  2011. * Horizontal alignment of the button.
  2012. *
  2013. * @deprecated
  2014. * @type {Highcharts.AlignValue}
  2015. */
  2016. align: 'right',
  2017. /**
  2018. * Horizontal offset of the button.
  2019. *
  2020. * @deprecated
  2021. */
  2022. x: -10,
  2023. /**
  2024. * Vertical offset of the button.
  2025. *
  2026. * @deprecated
  2027. */
  2028. y: 10
  2029. }
  2030. },
  2031. /**
  2032. * Options for the button appearing when traversing down in a treemap.
  2033. */
  2034. traverseUpButton: {
  2035. /**
  2036. * The position of the button.
  2037. */
  2038. position: {
  2039. /**
  2040. * Vertical alignment of the button.
  2041. *
  2042. * @type {Highcharts.VerticalAlignValue}
  2043. * @default top
  2044. * @product highcharts
  2045. * @apioption plotOptions.treemap.traverseUpButton.position.verticalAlign
  2046. */
  2047. /**
  2048. * Horizontal alignment of the button.
  2049. *
  2050. * @type {Highcharts.AlignValue}
  2051. */
  2052. align: 'right',
  2053. /**
  2054. * Horizontal offset of the button.
  2055. */
  2056. x: -10,
  2057. /**
  2058. * Vertical offset of the button.
  2059. */
  2060. y: 10
  2061. }
  2062. },
  2063. /**
  2064. * Set options on specific levels. Takes precedence over series options,
  2065. * but not point options.
  2066. *
  2067. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  2068. * Styling dataLabels and borders
  2069. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  2070. * Different layoutAlgorithm
  2071. *
  2072. * @type {Array<*>}
  2073. * @since 4.1.0
  2074. * @product highcharts
  2075. * @apioption plotOptions.treemap.levels
  2076. */
  2077. /**
  2078. * Can set a `borderColor` on all points which lies on the same level.
  2079. *
  2080. * @type {Highcharts.ColorString}
  2081. * @since 4.1.0
  2082. * @product highcharts
  2083. * @apioption plotOptions.treemap.levels.borderColor
  2084. */
  2085. /**
  2086. * Set the dash style of the border of all the point which lies on the
  2087. * level. See
  2088. * [plotOptions.scatter.dashStyle](#plotoptions.scatter.dashstyle)
  2089. * for possible options.
  2090. *
  2091. * @type {Highcharts.DashStyleValue}
  2092. * @since 4.1.0
  2093. * @product highcharts
  2094. * @apioption plotOptions.treemap.levels.borderDashStyle
  2095. */
  2096. /**
  2097. * Can set the borderWidth on all points which lies on the same level.
  2098. *
  2099. * @type {number}
  2100. * @since 4.1.0
  2101. * @product highcharts
  2102. * @apioption plotOptions.treemap.levels.borderWidth
  2103. */
  2104. /**
  2105. * Can set a color on all points which lies on the same level.
  2106. *
  2107. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2108. * @since 4.1.0
  2109. * @product highcharts
  2110. * @apioption plotOptions.treemap.levels.color
  2111. */
  2112. /**
  2113. * A configuration object to define how the color of a child varies from
  2114. * the parent's color. The variation is distributed among the children
  2115. * of node. For example when setting brightness, the brightness change
  2116. * will range from the parent's original brightness on the first child,
  2117. * to the amount set in the `to` setting on the last node. This allows a
  2118. * gradient-like color scheme that sets children out from each other
  2119. * while highlighting the grouping on treemaps and sectors on sunburst
  2120. * charts.
  2121. *
  2122. * @sample highcharts/demo/sunburst/
  2123. * Sunburst with color variation
  2124. *
  2125. * @since 6.0.0
  2126. * @product highcharts
  2127. * @apioption plotOptions.treemap.levels.colorVariation
  2128. */
  2129. /**
  2130. * The key of a color variation. Currently supports `brightness` only.
  2131. *
  2132. * @type {string}
  2133. * @since 6.0.0
  2134. * @product highcharts
  2135. * @validvalue ["brightness"]
  2136. * @apioption plotOptions.treemap.levels.colorVariation.key
  2137. */
  2138. /**
  2139. * The ending value of a color variation. The last sibling will receive
  2140. * this value.
  2141. *
  2142. * @type {number}
  2143. * @since 6.0.0
  2144. * @product highcharts
  2145. * @apioption plotOptions.treemap.levels.colorVariation.to
  2146. */
  2147. /**
  2148. * Can set the options of dataLabels on each point which lies on the
  2149. * level.
  2150. * [plotOptions.treemap.dataLabels](#plotOptions.treemap.dataLabels) for
  2151. * possible values.
  2152. *
  2153. * @extends plotOptions.treemap.dataLabels
  2154. * @since 4.1.0
  2155. * @product highcharts
  2156. * @apioption plotOptions.treemap.levels.dataLabels
  2157. */
  2158. /**
  2159. * Can set the layoutAlgorithm option on a specific level.
  2160. *
  2161. * @type {string}
  2162. * @since 4.1.0
  2163. * @product highcharts
  2164. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  2165. * @apioption plotOptions.treemap.levels.layoutAlgorithm
  2166. */
  2167. /**
  2168. * Can set the layoutStartingDirection option on a specific level.
  2169. *
  2170. * @type {string}
  2171. * @since 4.1.0
  2172. * @product highcharts
  2173. * @validvalue ["vertical", "horizontal"]
  2174. * @apioption plotOptions.treemap.levels.layoutStartingDirection
  2175. */
  2176. /**
  2177. * Decides which level takes effect from the options set in the levels
  2178. * object.
  2179. *
  2180. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  2181. * Styling of both levels
  2182. *
  2183. * @type {number}
  2184. * @since 4.1.0
  2185. * @product highcharts
  2186. * @apioption plotOptions.treemap.levels.level
  2187. */
  2188. // Presentational options
  2189. /**
  2190. * The color of the border surrounding each tree map item.
  2191. *
  2192. * @type {Highcharts.ColorString}
  2193. */
  2194. borderColor: palette.neutralColor10,
  2195. /**
  2196. * The width of the border surrounding each tree map item.
  2197. */
  2198. borderWidth: 1,
  2199. colorKey: 'colorValue',
  2200. /**
  2201. * The opacity of a point in treemap. When a point has children, the
  2202. * visibility of the children is determined by the opacity.
  2203. *
  2204. * @since 4.2.4
  2205. */
  2206. opacity: 0.15,
  2207. /**
  2208. * A wrapper object for all the series options in specific states.
  2209. *
  2210. * @extends plotOptions.heatmap.states
  2211. */
  2212. states: {
  2213. /**
  2214. * Options for the hovered series
  2215. *
  2216. * @extends plotOptions.heatmap.states.hover
  2217. * @excluding halo
  2218. */
  2219. hover: {
  2220. /**
  2221. * The border color for the hovered state.
  2222. */
  2223. borderColor: palette.neutralColor40,
  2224. /**
  2225. * Brightness for the hovered point. Defaults to 0 if the
  2226. * heatmap series is loaded first, otherwise 0.1.
  2227. *
  2228. * @type {number}
  2229. * @default undefined
  2230. */
  2231. brightness: HeatmapSeries ? 0 : 0.1,
  2232. /**
  2233. * @extends plotOptions.heatmap.states.hover.halo
  2234. */
  2235. halo: false,
  2236. /**
  2237. * The opacity of a point in treemap. When a point has children,
  2238. * the visibility of the children is determined by the opacity.
  2239. *
  2240. * @since 4.2.4
  2241. */
  2242. opacity: 0.75,
  2243. /**
  2244. * The shadow option for hovered state.
  2245. */
  2246. shadow: false
  2247. }
  2248. }
  2249. });
  2250. return TreemapSeries;
  2251. }(ScatterSeries));
  2252. extend(TreemapSeries.prototype, {
  2253. buildKDTree: noop,
  2254. colorKey: 'colorValue',
  2255. directTouch: true,
  2256. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  2257. getExtremesFromAll: true,
  2258. getSymbol: noop,
  2259. optionalAxis: 'colorAxis',
  2260. parallelArrays: ['x', 'y', 'value', 'colorValue'],
  2261. pointArrayMap: ['value'],
  2262. pointClass: TreemapPoint,
  2263. trackerGroups: ['group', 'dataLabelsGroup'],
  2264. utils: {
  2265. recursive: TreemapUtilities.recursive
  2266. }
  2267. });
  2268. SeriesRegistry.registerSeriesType('treemap', TreemapSeries);
  2269. /* *
  2270. *
  2271. * Default Export
  2272. *
  2273. * */
  2274. /* *
  2275. *
  2276. * API Options
  2277. *
  2278. * */
  2279. /**
  2280. * A `treemap` series. If the [type](#series.treemap.type) option is
  2281. * not specified, it is inherited from [chart.type](#chart.type).
  2282. *
  2283. * @extends series,plotOptions.treemap
  2284. * @excluding dataParser, dataURL, stack, dataSorting
  2285. * @product highcharts
  2286. * @requires modules/treemap
  2287. * @apioption series.treemap
  2288. */
  2289. /**
  2290. * An array of data points for the series. For the `treemap` series
  2291. * type, points can be given in the following ways:
  2292. *
  2293. * 1. An array of numerical values. In this case, the numerical values will be
  2294. * interpreted as `value` options. Example:
  2295. * ```js
  2296. * data: [0, 5, 3, 5]
  2297. * ```
  2298. *
  2299. * 2. An array of objects with named values. The following snippet shows only a
  2300. * few settings, see the complete options set below. If the total number of
  2301. * data points exceeds the series'
  2302. * [turboThreshold](#series.treemap.turboThreshold),
  2303. * this option is not available.
  2304. * ```js
  2305. * data: [{
  2306. * value: 9,
  2307. * name: "Point2",
  2308. * color: "#00FF00"
  2309. * }, {
  2310. * value: 6,
  2311. * name: "Point1",
  2312. * color: "#FF00FF"
  2313. * }]
  2314. * ```
  2315. *
  2316. * @sample {highcharts} highcharts/chart/reflow-true/
  2317. * Numerical values
  2318. * @sample {highcharts} highcharts/series/data-array-of-objects/
  2319. * Config objects
  2320. *
  2321. * @type {Array<number|null|*>}
  2322. * @extends series.heatmap.data
  2323. * @excluding x, y
  2324. * @product highcharts
  2325. * @apioption series.treemap.data
  2326. */
  2327. /**
  2328. * The value of the point, resulting in a relative area of the point
  2329. * in the treemap.
  2330. *
  2331. * @type {number|null}
  2332. * @product highcharts
  2333. * @apioption series.treemap.data.value
  2334. */
  2335. /**
  2336. * Serves a purpose only if a `colorAxis` object is defined in the chart
  2337. * options. This value will decide which color the point gets from the
  2338. * scale of the colorAxis.
  2339. *
  2340. * @type {number}
  2341. * @since 4.1.0
  2342. * @product highcharts
  2343. * @apioption series.treemap.data.colorValue
  2344. */
  2345. /**
  2346. * Only for treemap. Use this option to build a tree structure. The
  2347. * value should be the id of the point which is the parent. If no points
  2348. * has a matching id, or this option is undefined, then the parent will
  2349. * be set to the root.
  2350. *
  2351. * @sample {highcharts} highcharts/point/parent/
  2352. * Point parent
  2353. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  2354. * Example where parent id is not matching
  2355. *
  2356. * @type {string}
  2357. * @since 4.1.0
  2358. * @product highcharts
  2359. * @apioption series.treemap.data.parent
  2360. */
  2361. ''; // adds doclets above to transpiled file
  2362. return TreemapSeries;
  2363. });
  2364. _registerModule(_modules, 'masters/modules/treemap.src.js', [], function () {
  2365. });
  2366. }));