treemap.src.js 87 KB

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