TreemapSeries.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. /* *
  2. *
  3. * (c) 2014-2020 Highsoft AS
  4. *
  5. * Authors: Jon Arild Nygard / Oystein Moseng
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. import BaseSeries from '../Core/Series/Series.js';
  13. var seriesTypes = BaseSeries.seriesTypes;
  14. import Color from '../Core/Color/Color.js';
  15. var color = Color.parse;
  16. import ColorMapMixin from '../Mixins/ColorMapSeries.js';
  17. var colorMapSeriesMixin = ColorMapMixin.colorMapSeriesMixin;
  18. import DrawPointMixin from '../Mixins/DrawPoint.js';
  19. var drawPoint = DrawPointMixin.drawPoint;
  20. import H from '../Core/Globals.js';
  21. var noop = H.noop;
  22. import LegendSymbolMixin from '../Mixins/LegendSymbol.js';
  23. import Point from '../Core/Series/Point.js';
  24. import TreeSeriesMixin from '../Mixins/TreeSeries.js';
  25. var getColor = TreeSeriesMixin.getColor, getLevelOptions = TreeSeriesMixin.getLevelOptions, updateRootId = TreeSeriesMixin.updateRootId;
  26. import U from '../Core/Utilities.js';
  27. var addEvent = U.addEvent, correctFloat = U.correctFloat, defined = U.defined, error = U.error, extend = U.extend, fireEvent = U.fireEvent, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, isString = U.isString, merge = U.merge, objectEach = U.objectEach, pick = U.pick, stableSort = U.stableSort;
  28. import '../Core/Options.js';
  29. import './ScatterSeries.js';
  30. /* eslint-disable no-invalid-this */
  31. var AXIS_MAX = 100;
  32. // @todo Similar to eachObject, this function is likely redundant
  33. var isBoolean = function (x) {
  34. return typeof x === 'boolean';
  35. }, Series = H.Series,
  36. // @todo Similar to recursive, this function is likely redundant
  37. eachObject = function (list, func, context) {
  38. context = context || this;
  39. objectEach(list, function (val, key) {
  40. func.call(context, val, key, list);
  41. });
  42. },
  43. // @todo find correct name for this function.
  44. // @todo Similar to reduce, this function is likely redundant
  45. recursive = function (item, func, context) {
  46. var next;
  47. context = context || this;
  48. next = func.call(context, item);
  49. if (next !== false) {
  50. recursive(next, func, context);
  51. }
  52. }, treemapAxisDefaultValues = false;
  53. /* eslint-enable no-invalid-this */
  54. /**
  55. * @private
  56. * @class
  57. * @name Highcharts.seriesTypes.treemap
  58. *
  59. * @augments Highcharts.Series
  60. */
  61. BaseSeries.seriesType('treemap', 'scatter'
  62. /**
  63. * A treemap displays hierarchical data using nested rectangles. The data
  64. * can be laid out in varying ways depending on options.
  65. *
  66. * @sample highcharts/demo/treemap-large-dataset/
  67. * Treemap
  68. *
  69. * @extends plotOptions.scatter
  70. * @excluding dragDrop, marker, jitter, dataSorting
  71. * @product highcharts
  72. * @requires modules/treemap
  73. * @optionparent plotOptions.treemap
  74. */
  75. , {
  76. /**
  77. * When enabled the user can click on a point which is a parent and
  78. * zoom in on its children. Deprecated and replaced by
  79. * [allowTraversingTree](#plotOptions.treemap.allowTraversingTree).
  80. *
  81. * @sample {highcharts} highcharts/plotoptions/treemap-allowdrilltonode/
  82. * Enabled
  83. *
  84. * @deprecated
  85. * @type {boolean}
  86. * @default false
  87. * @since 4.1.0
  88. * @product highcharts
  89. * @apioption plotOptions.treemap.allowDrillToNode
  90. */
  91. /**
  92. * When enabled the user can click on a point which is a parent and
  93. * zoom in on its children.
  94. *
  95. * @sample {highcharts} highcharts/plotoptions/treemap-allowtraversingtree/
  96. * Enabled
  97. *
  98. * @since 7.0.3
  99. * @product highcharts
  100. */
  101. allowTraversingTree: false,
  102. animationLimit: 250,
  103. /**
  104. * When the series contains less points than the crop threshold, all
  105. * points are drawn, event if the points fall outside the visible plot
  106. * area at the current zoom. The advantage of drawing all points
  107. * (including markers and columns), is that animation is performed on
  108. * updates. On the other hand, when the series contains more points than
  109. * the crop threshold, the series data is cropped to only contain points
  110. * that fall within the plot area. The advantage of cropping away
  111. * invisible points is to increase performance on large series.
  112. *
  113. * @type {number}
  114. * @default 300
  115. * @since 4.1.0
  116. * @product highcharts
  117. * @apioption plotOptions.treemap.cropThreshold
  118. */
  119. /**
  120. * Fires on a request for change of root node for the tree, before the
  121. * update is made. An event object is passed to the function, containing
  122. * additional properties `newRootId`, `previousRootId`, `redraw` and
  123. * `trigger`.
  124. *
  125. * @type {function}
  126. * @default undefined
  127. * @sample {highcharts} highcharts/plotoptions/treemap-events-setrootnode/
  128. * Alert update information on setRootNode event.
  129. * @since 7.0.3
  130. * @product highcharts
  131. * @apioption plotOptions.treemap.events.setRootNode
  132. */
  133. /**
  134. * This option decides if the user can interact with the parent nodes
  135. * or just the leaf nodes. When this option is undefined, it will be
  136. * true by default. However when allowTraversingTree is true, then it
  137. * will be false by default.
  138. *
  139. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-false/
  140. * False
  141. * @sample {highcharts} highcharts/plotoptions/treemap-interactbyleaf-true-and-allowtraversingtree/
  142. * InteractByLeaf and allowTraversingTree is true
  143. *
  144. * @type {boolean}
  145. * @since 4.1.2
  146. * @product highcharts
  147. * @apioption plotOptions.treemap.interactByLeaf
  148. */
  149. /**
  150. * The sort index of the point inside the treemap level.
  151. *
  152. * @sample {highcharts} highcharts/plotoptions/treemap-sortindex/
  153. * Sort by years
  154. *
  155. * @type {number}
  156. * @since 4.1.10
  157. * @product highcharts
  158. * @apioption plotOptions.treemap.sortIndex
  159. */
  160. /**
  161. * A series specific or series type specific color set to apply instead
  162. * of the global [colors](#colors) when
  163. * [colorByPoint](#plotOptions.treemap.colorByPoint) is true.
  164. *
  165. * @type {Array<Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject>}
  166. * @since 3.0
  167. * @product highcharts
  168. * @apioption plotOptions.treemap.colors
  169. */
  170. /**
  171. * Whether to display this series type or specific series item in the
  172. * legend.
  173. */
  174. showInLegend: false,
  175. /**
  176. * @ignore-option
  177. */
  178. marker: void 0,
  179. /**
  180. * When using automatic point colors pulled from the `options.colors`
  181. * collection, this option determines whether the chart should receive
  182. * one color per series or one color per point.
  183. *
  184. * @see [series colors](#plotOptions.treemap.colors)
  185. *
  186. * @since 2.0
  187. * @product highcharts
  188. * @apioption plotOptions.treemap.colorByPoint
  189. */
  190. colorByPoint: false,
  191. /**
  192. * @since 4.1.0
  193. */
  194. dataLabels: {
  195. defer: false,
  196. enabled: true,
  197. formatter: function () {
  198. var point = this && this.point ?
  199. this.point :
  200. {}, name = isString(point.name) ? point.name : '';
  201. return name;
  202. },
  203. inside: true,
  204. verticalAlign: 'middle'
  205. },
  206. tooltip: {
  207. headerFormat: '',
  208. pointFormat: '<b>{point.name}</b>: {point.value}<br/>'
  209. },
  210. /**
  211. * Whether to ignore hidden points when the layout algorithm runs.
  212. * If `false`, hidden points will leave open spaces.
  213. *
  214. * @since 5.0.8
  215. */
  216. ignoreHiddenPoint: true,
  217. /**
  218. * This option decides which algorithm is used for setting position
  219. * and dimensions of the points.
  220. *
  221. * @see [How to write your own algorithm](https://www.highcharts.com/docs/chart-and-series-types/treemap)
  222. *
  223. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-sliceanddice/
  224. * SliceAndDice by default
  225. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-stripes/
  226. * Stripes
  227. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-squarified/
  228. * Squarified
  229. * @sample {highcharts} highcharts/plotoptions/treemap-layoutalgorithm-strip/
  230. * Strip
  231. *
  232. * @since 4.1.0
  233. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  234. */
  235. layoutAlgorithm: 'sliceAndDice',
  236. /**
  237. * Defines which direction the layout algorithm will start drawing.
  238. *
  239. * @since 4.1.0
  240. * @validvalue ["vertical", "horizontal"]
  241. */
  242. layoutStartingDirection: 'vertical',
  243. /**
  244. * Enabling this option will make the treemap alternate the drawing
  245. * direction between vertical and horizontal. The next levels starting
  246. * direction will always be the opposite of the previous.
  247. *
  248. * @sample {highcharts} highcharts/plotoptions/treemap-alternatestartingdirection-true/
  249. * Enabled
  250. *
  251. * @since 4.1.0
  252. */
  253. alternateStartingDirection: false,
  254. /**
  255. * Used together with the levels and allowTraversingTree options. When
  256. * set to false the first level visible to be level one, which is
  257. * dynamic when traversing the tree. Otherwise the level will be the
  258. * same as the tree structure.
  259. *
  260. * @since 4.1.0
  261. */
  262. levelIsConstant: true,
  263. /**
  264. * Options for the button appearing when drilling down in a treemap.
  265. * Deprecated and replaced by
  266. * [traverseUpButton](#plotOptions.treemap.traverseUpButton).
  267. *
  268. * @deprecated
  269. */
  270. drillUpButton: {
  271. /**
  272. * The position of the button.
  273. *
  274. * @deprecated
  275. */
  276. position: {
  277. /**
  278. * Vertical alignment of the button.
  279. *
  280. * @deprecated
  281. * @type {Highcharts.VerticalAlignValue}
  282. * @default top
  283. * @product highcharts
  284. * @apioption plotOptions.treemap.drillUpButton.position.verticalAlign
  285. */
  286. /**
  287. * Horizontal alignment of the button.
  288. *
  289. * @deprecated
  290. * @type {Highcharts.AlignValue}
  291. */
  292. align: 'right',
  293. /**
  294. * Horizontal offset of the button.
  295. *
  296. * @deprecated
  297. */
  298. x: -10,
  299. /**
  300. * Vertical offset of the button.
  301. *
  302. * @deprecated
  303. */
  304. y: 10
  305. }
  306. },
  307. /**
  308. * Options for the button appearing when traversing down in a treemap.
  309. */
  310. traverseUpButton: {
  311. /**
  312. * The position of the button.
  313. */
  314. position: {
  315. /**
  316. * Vertical alignment of the button.
  317. *
  318. * @type {Highcharts.VerticalAlignValue}
  319. * @default top
  320. * @product highcharts
  321. * @apioption plotOptions.treemap.traverseUpButton.position.verticalAlign
  322. */
  323. /**
  324. * Horizontal alignment of the button.
  325. *
  326. * @type {Highcharts.AlignValue}
  327. */
  328. align: 'right',
  329. /**
  330. * Horizontal offset of the button.
  331. */
  332. x: -10,
  333. /**
  334. * Vertical offset of the button.
  335. */
  336. y: 10
  337. }
  338. },
  339. /**
  340. * Set options on specific levels. Takes precedence over series options,
  341. * but not point options.
  342. *
  343. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  344. * Styling dataLabels and borders
  345. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  346. * Different layoutAlgorithm
  347. *
  348. * @type {Array<*>}
  349. * @since 4.1.0
  350. * @product highcharts
  351. * @apioption plotOptions.treemap.levels
  352. */
  353. /**
  354. * Can set a `borderColor` on all points which lies on the same level.
  355. *
  356. * @type {Highcharts.ColorString}
  357. * @since 4.1.0
  358. * @product highcharts
  359. * @apioption plotOptions.treemap.levels.borderColor
  360. */
  361. /**
  362. * Set the dash style of the border of all the point which lies on the
  363. * level. See
  364. * [plotOptions.scatter.dashStyle](#plotoptions.scatter.dashstyle)
  365. * for possible options.
  366. *
  367. * @type {Highcharts.DashStyleValue}
  368. * @since 4.1.0
  369. * @product highcharts
  370. * @apioption plotOptions.treemap.levels.borderDashStyle
  371. */
  372. /**
  373. * Can set the borderWidth on all points which lies on the same level.
  374. *
  375. * @type {number}
  376. * @since 4.1.0
  377. * @product highcharts
  378. * @apioption plotOptions.treemap.levels.borderWidth
  379. */
  380. /**
  381. * Can set a color on all points which lies on the same level.
  382. *
  383. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  384. * @since 4.1.0
  385. * @product highcharts
  386. * @apioption plotOptions.treemap.levels.color
  387. */
  388. /**
  389. * A configuration object to define how the color of a child varies from
  390. * the parent's color. The variation is distributed among the children
  391. * of node. For example when setting brightness, the brightness change
  392. * will range from the parent's original brightness on the first child,
  393. * to the amount set in the `to` setting on the last node. This allows a
  394. * gradient-like color scheme that sets children out from each other
  395. * while highlighting the grouping on treemaps and sectors on sunburst
  396. * charts.
  397. *
  398. * @sample highcharts/demo/sunburst/
  399. * Sunburst with color variation
  400. *
  401. * @since 6.0.0
  402. * @product highcharts
  403. * @apioption plotOptions.treemap.levels.colorVariation
  404. */
  405. /**
  406. * The key of a color variation. Currently supports `brightness` only.
  407. *
  408. * @type {string}
  409. * @since 6.0.0
  410. * @product highcharts
  411. * @validvalue ["brightness"]
  412. * @apioption plotOptions.treemap.levels.colorVariation.key
  413. */
  414. /**
  415. * The ending value of a color variation. The last sibling will receive
  416. * this value.
  417. *
  418. * @type {number}
  419. * @since 6.0.0
  420. * @product highcharts
  421. * @apioption plotOptions.treemap.levels.colorVariation.to
  422. */
  423. /**
  424. * Can set the options of dataLabels on each point which lies on the
  425. * level.
  426. * [plotOptions.treemap.dataLabels](#plotOptions.treemap.dataLabels) for
  427. * possible values.
  428. *
  429. * @extends plotOptions.treemap.dataLabels
  430. * @since 4.1.0
  431. * @product highcharts
  432. * @apioption plotOptions.treemap.levels.dataLabels
  433. */
  434. /**
  435. * Can set the layoutAlgorithm option on a specific level.
  436. *
  437. * @type {string}
  438. * @since 4.1.0
  439. * @product highcharts
  440. * @validvalue ["sliceAndDice", "stripes", "squarified", "strip"]
  441. * @apioption plotOptions.treemap.levels.layoutAlgorithm
  442. */
  443. /**
  444. * Can set the layoutStartingDirection option on a specific level.
  445. *
  446. * @type {string}
  447. * @since 4.1.0
  448. * @product highcharts
  449. * @validvalue ["vertical", "horizontal"]
  450. * @apioption plotOptions.treemap.levels.layoutStartingDirection
  451. */
  452. /**
  453. * Decides which level takes effect from the options set in the levels
  454. * object.
  455. *
  456. * @sample {highcharts} highcharts/plotoptions/treemap-levels/
  457. * Styling of both levels
  458. *
  459. * @type {number}
  460. * @since 4.1.0
  461. * @product highcharts
  462. * @apioption plotOptions.treemap.levels.level
  463. */
  464. // Presentational options
  465. /**
  466. * The color of the border surrounding each tree map item.
  467. *
  468. * @type {Highcharts.ColorString}
  469. */
  470. borderColor: '#e6e6e6',
  471. /**
  472. * The width of the border surrounding each tree map item.
  473. */
  474. borderWidth: 1,
  475. colorKey: 'colorValue',
  476. /**
  477. * The opacity of a point in treemap. When a point has children, the
  478. * visibility of the children is determined by the opacity.
  479. *
  480. * @since 4.2.4
  481. */
  482. opacity: 0.15,
  483. /**
  484. * A wrapper object for all the series options in specific states.
  485. *
  486. * @extends plotOptions.heatmap.states
  487. */
  488. states: {
  489. /**
  490. * Options for the hovered series
  491. *
  492. * @extends plotOptions.heatmap.states.hover
  493. * @excluding halo
  494. */
  495. hover: {
  496. /**
  497. * The border color for the hovered state.
  498. */
  499. borderColor: '#999999',
  500. /**
  501. * Brightness for the hovered point. Defaults to 0 if the
  502. * heatmap series is loaded first, otherwise 0.1.
  503. *
  504. * @type {number}
  505. * @default undefined
  506. */
  507. brightness: seriesTypes.heatmap ? 0 : 0.1,
  508. /**
  509. * @extends plotOptions.heatmap.states.hover.halo
  510. */
  511. halo: false,
  512. /**
  513. * The opacity of a point in treemap. When a point has children,
  514. * the visibility of the children is determined by the opacity.
  515. *
  516. * @since 4.2.4
  517. */
  518. opacity: 0.75,
  519. /**
  520. * The shadow option for hovered state.
  521. */
  522. shadow: false
  523. }
  524. }
  525. // Prototype members
  526. }, {
  527. pointArrayMap: ['value'],
  528. directTouch: true,
  529. optionalAxis: 'colorAxis',
  530. getSymbol: noop,
  531. parallelArrays: ['x', 'y', 'value', 'colorValue'],
  532. colorKey: 'colorValue',
  533. trackerGroups: ['group', 'dataLabelsGroup'],
  534. /* eslint-disable no-invalid-this, valid-jsdoc */
  535. /**
  536. * Creates an object map from parent id to childrens index.
  537. *
  538. * @private
  539. * @function Highcharts.Series#getListOfParents
  540. *
  541. * @param {Highcharts.SeriesTreemapDataOptions} [data]
  542. * List of points set in options.
  543. *
  544. * @param {Array<string>} [existingIds]
  545. * List of all point ids.
  546. *
  547. * @return {object}
  548. * Map from parent id to children index in data.
  549. */
  550. getListOfParents: function (data, existingIds) {
  551. var arr = isArray(data) ? data : [], ids = isArray(existingIds) ? existingIds : [], listOfParents = arr.reduce(function (prev, curr, i) {
  552. var parent = pick(curr.parent, '');
  553. if (typeof prev[parent] === 'undefined') {
  554. prev[parent] = [];
  555. }
  556. prev[parent].push(i);
  557. return prev;
  558. }, {
  559. '': [] // Root of tree
  560. });
  561. // If parent does not exist, hoist parent to root of tree.
  562. eachObject(listOfParents, function (children, parent, list) {
  563. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  564. children.forEach(function (child) {
  565. list[''].push(child);
  566. });
  567. delete list[parent];
  568. }
  569. });
  570. return listOfParents;
  571. },
  572. // Creates a tree structured object from the series points
  573. getTree: function () {
  574. var series = this, allIds = this.data.map(function (d) {
  575. return d.id;
  576. }), parentList = series.getListOfParents(this.data, allIds);
  577. series.nodeMap = {};
  578. return series.buildNode('', -1, 0, parentList);
  579. },
  580. // Define hasData function for non-cartesian series.
  581. // Returns true if the series has points at all.
  582. hasData: function () {
  583. return !!this.processedXData.length; // != 0
  584. },
  585. init: function (chart, options) {
  586. var series = this, setOptionsEvent;
  587. // If color series logic is loaded, add some properties
  588. if (colorMapSeriesMixin) {
  589. this.colorAttribs = colorMapSeriesMixin.colorAttribs;
  590. }
  591. setOptionsEvent = addEvent(series, 'setOptions', function (event) {
  592. var options = event.userOptions;
  593. if (defined(options.allowDrillToNode) &&
  594. !defined(options.allowTraversingTree)) {
  595. options.allowTraversingTree = options.allowDrillToNode;
  596. delete options.allowDrillToNode;
  597. }
  598. if (defined(options.drillUpButton) &&
  599. !defined(options.traverseUpButton)) {
  600. options.traverseUpButton = options.drillUpButton;
  601. delete options.drillUpButton;
  602. }
  603. });
  604. Series.prototype.init.call(series, chart, options);
  605. // Treemap's opacity is a different option from other series
  606. delete series.opacity;
  607. // Handle deprecated options.
  608. series.eventsToUnbind.push(setOptionsEvent);
  609. if (series.options.allowTraversingTree) {
  610. series.eventsToUnbind.push(addEvent(series, 'click', series.onClickDrillToNode));
  611. }
  612. },
  613. buildNode: function (id, i, level, list, parent) {
  614. var series = this, children = [], point = series.points[i], height = 0, node, child;
  615. // Actions
  616. ((list[id] || [])).forEach(function (i) {
  617. child = series.buildNode(series.points[i].id, i, (level + 1), list, id);
  618. height = Math.max(child.height + 1, height);
  619. children.push(child);
  620. });
  621. node = {
  622. id: id,
  623. i: i,
  624. children: children,
  625. height: height,
  626. level: level,
  627. parent: parent,
  628. visible: false // @todo move this to better location
  629. };
  630. series.nodeMap[node.id] = node;
  631. if (point) {
  632. point.node = node;
  633. }
  634. return node;
  635. },
  636. setTreeValues: function (tree) {
  637. var series = this, options = series.options, idRoot = series.rootNode, mapIdToNode = series.nodeMap, nodeRoot = mapIdToNode[idRoot], levelIsConstant = (isBoolean(options.levelIsConstant) ?
  638. options.levelIsConstant :
  639. true), childrenTotal = 0, children = [], val, point = series.points[tree.i];
  640. // First give the children some values
  641. tree.children.forEach(function (child) {
  642. child = series.setTreeValues(child);
  643. children.push(child);
  644. if (!child.ignore) {
  645. childrenTotal += child.val;
  646. }
  647. });
  648. // Sort the children
  649. stableSort(children, function (a, b) {
  650. return (a.sortIndex || 0) - (b.sortIndex || 0);
  651. });
  652. // Set the values
  653. val = pick(point && point.options.value, childrenTotal);
  654. if (point) {
  655. point.value = val;
  656. }
  657. extend(tree, {
  658. children: children,
  659. childrenTotal: childrenTotal,
  660. // Ignore this node if point is not visible
  661. ignore: !(pick(point && point.visible, true) && (val > 0)),
  662. isLeaf: tree.visible && !childrenTotal,
  663. levelDynamic: (tree.level - (levelIsConstant ? 0 : nodeRoot.level)),
  664. name: pick(point && point.name, ''),
  665. sortIndex: pick(point && point.sortIndex, -val),
  666. val: val
  667. });
  668. return tree;
  669. },
  670. /**
  671. * Recursive function which calculates the area for all children of a
  672. * node.
  673. *
  674. * @private
  675. * @function Highcharts.Series#calculateChildrenAreas
  676. *
  677. * @param {object} node
  678. * The node which is parent to the children.
  679. *
  680. * @param {object} area
  681. * The rectangular area of the parent.
  682. */
  683. calculateChildrenAreas: function (parent, area) {
  684. var series = this, options = series.options, mapOptionsToLevel = series.mapOptionsToLevel, level = mapOptionsToLevel[parent.level + 1], algorithm = pick((series[(level && level.layoutAlgorithm)] &&
  685. level.layoutAlgorithm), options.layoutAlgorithm), alternate = options.alternateStartingDirection, childrenValues = [], children;
  686. // Collect all children which should be included
  687. children = parent.children.filter(function (n) {
  688. return !n.ignore;
  689. });
  690. if (level && level.layoutStartingDirection) {
  691. area.direction = level.layoutStartingDirection === 'vertical' ?
  692. 0 :
  693. 1;
  694. }
  695. childrenValues = series[algorithm](area, children);
  696. children.forEach(function (child, index) {
  697. var values = childrenValues[index];
  698. child.values = merge(values, {
  699. val: child.childrenTotal,
  700. direction: (alternate ? 1 - area.direction : area.direction)
  701. });
  702. child.pointValues = merge(values, {
  703. x: (values.x / series.axisRatio),
  704. // Flip y-values to avoid visual regression with csvCoord in
  705. // Axis.translate at setPointValues. #12488
  706. y: AXIS_MAX - values.y - values.height,
  707. width: (values.width / series.axisRatio)
  708. });
  709. // If node has children, then call method recursively
  710. if (child.children.length) {
  711. series.calculateChildrenAreas(child, child.values);
  712. }
  713. });
  714. },
  715. setPointValues: function () {
  716. var series = this;
  717. var points = series.points, xAxis = series.xAxis, yAxis = series.yAxis;
  718. var styledMode = series.chart.styledMode;
  719. // Get the crisp correction in classic mode. For this to work in
  720. // styled mode, we would need to first add the shape (without x,
  721. // y, width and height), then read the rendered stroke width
  722. // using point.graphic.strokeWidth(), then modify and apply the
  723. // shapeArgs. This applies also to column series, but the
  724. // downside is performance and code complexity.
  725. var getCrispCorrection = function (point) { return (styledMode ?
  726. 0 :
  727. ((series.pointAttribs(point)['stroke-width'] || 0) % 2) / 2); };
  728. points.forEach(function (point) {
  729. var _a = point.node, values = _a.pointValues, visible = _a.visible;
  730. // Points which is ignored, have no values.
  731. if (values && visible) {
  732. var height = values.height, width = values.width, x = values.x, y = values.y;
  733. var crispCorr = getCrispCorrection(point);
  734. var x1 = Math.round(xAxis.toPixels(x, true)) - crispCorr;
  735. var x2 = Math.round(xAxis.toPixels(x + width, true)) - crispCorr;
  736. var y1 = Math.round(yAxis.toPixels(y, true)) - crispCorr;
  737. var y2 = Math.round(yAxis.toPixels(y + height, true)) - crispCorr;
  738. // Set point values
  739. point.shapeArgs = {
  740. x: Math.min(x1, x2),
  741. y: Math.min(y1, y2),
  742. width: Math.abs(x2 - x1),
  743. height: Math.abs(y2 - y1)
  744. };
  745. point.plotX =
  746. point.shapeArgs.x + (point.shapeArgs.width / 2);
  747. point.plotY =
  748. point.shapeArgs.y + (point.shapeArgs.height / 2);
  749. }
  750. else {
  751. // Reset visibility
  752. delete point.plotX;
  753. delete point.plotY;
  754. }
  755. });
  756. },
  757. // Set the node's color recursively, from the parent down.
  758. setColorRecursive: function (node, parentColor, colorIndex, index, siblings) {
  759. var series = this, chart = series && series.chart, colors = chart && chart.options && chart.options.colors, colorInfo, point;
  760. if (node) {
  761. colorInfo = getColor(node, {
  762. colors: colors,
  763. index: index,
  764. mapOptionsToLevel: series.mapOptionsToLevel,
  765. parentColor: parentColor,
  766. parentColorIndex: colorIndex,
  767. series: series,
  768. siblings: siblings
  769. });
  770. point = series.points[node.i];
  771. if (point) {
  772. point.color = colorInfo.color;
  773. point.colorIndex = colorInfo.colorIndex;
  774. }
  775. // Do it all again with the children
  776. (node.children || []).forEach(function (child, i) {
  777. series.setColorRecursive(child, colorInfo.color, colorInfo.colorIndex, i, node.children.length);
  778. });
  779. }
  780. },
  781. algorithmGroup: function (h, w, d, p) {
  782. this.height = h;
  783. this.width = w;
  784. this.plot = p;
  785. this.direction = d;
  786. this.startDirection = d;
  787. this.total = 0;
  788. this.nW = 0;
  789. this.lW = 0;
  790. this.nH = 0;
  791. this.lH = 0;
  792. this.elArr = [];
  793. this.lP = {
  794. total: 0,
  795. lH: 0,
  796. nH: 0,
  797. lW: 0,
  798. nW: 0,
  799. nR: 0,
  800. lR: 0,
  801. aspectRatio: function (w, h) {
  802. return Math.max((w / h), (h / w));
  803. }
  804. };
  805. this.addElement = function (el) {
  806. this.lP.total = this.elArr[this.elArr.length - 1];
  807. this.total = this.total + el;
  808. if (this.direction === 0) {
  809. // Calculate last point old aspect ratio
  810. this.lW = this.nW;
  811. this.lP.lH = this.lP.total / this.lW;
  812. this.lP.lR = this.lP.aspectRatio(this.lW, this.lP.lH);
  813. // Calculate last point new aspect ratio
  814. this.nW = this.total / this.height;
  815. this.lP.nH = this.lP.total / this.nW;
  816. this.lP.nR = this.lP.aspectRatio(this.nW, this.lP.nH);
  817. }
  818. else {
  819. // Calculate last point old aspect ratio
  820. this.lH = this.nH;
  821. this.lP.lW = this.lP.total / this.lH;
  822. this.lP.lR = this.lP.aspectRatio(this.lP.lW, this.lH);
  823. // Calculate last point new aspect ratio
  824. this.nH = this.total / this.width;
  825. this.lP.nW = this.lP.total / this.nH;
  826. this.lP.nR = this.lP.aspectRatio(this.lP.nW, this.nH);
  827. }
  828. this.elArr.push(el);
  829. };
  830. this.reset = function () {
  831. this.nW = 0;
  832. this.lW = 0;
  833. this.elArr = [];
  834. this.total = 0;
  835. };
  836. },
  837. algorithmCalcPoints: function (directionChange, last, group, childrenArea) {
  838. var pX, pY, pW, pH, gW = group.lW, gH = group.lH, plot = group.plot, keep, i = 0, end = group.elArr.length - 1;
  839. if (last) {
  840. gW = group.nW;
  841. gH = group.nH;
  842. }
  843. else {
  844. keep = group.elArr[group.elArr.length - 1];
  845. }
  846. group.elArr.forEach(function (p) {
  847. if (last || (i < end)) {
  848. if (group.direction === 0) {
  849. pX = plot.x;
  850. pY = plot.y;
  851. pW = gW;
  852. pH = p / pW;
  853. }
  854. else {
  855. pX = plot.x;
  856. pY = plot.y;
  857. pH = gH;
  858. pW = p / pH;
  859. }
  860. childrenArea.push({
  861. x: pX,
  862. y: pY,
  863. width: pW,
  864. height: correctFloat(pH)
  865. });
  866. if (group.direction === 0) {
  867. plot.y = plot.y + pH;
  868. }
  869. else {
  870. plot.x = plot.x + pW;
  871. }
  872. }
  873. i = i + 1;
  874. });
  875. // Reset variables
  876. group.reset();
  877. if (group.direction === 0) {
  878. group.width = group.width - gW;
  879. }
  880. else {
  881. group.height = group.height - gH;
  882. }
  883. plot.y = plot.parent.y + (plot.parent.height - group.height);
  884. plot.x = plot.parent.x + (plot.parent.width - group.width);
  885. if (directionChange) {
  886. group.direction = 1 - group.direction;
  887. }
  888. // If not last, then add uncalculated element
  889. if (!last) {
  890. group.addElement(keep);
  891. }
  892. },
  893. algorithmLowAspectRatio: function (directionChange, parent, children) {
  894. var childrenArea = [], series = this, pTot, plot = {
  895. x: parent.x,
  896. y: parent.y,
  897. parent: parent
  898. }, direction = parent.direction, i = 0, end = children.length - 1, group = new this.algorithmGroup(// eslint-disable-line new-cap
  899. parent.height, parent.width, direction, plot);
  900. // Loop through and calculate all areas
  901. children.forEach(function (child) {
  902. pTot =
  903. (parent.width * parent.height) * (child.val / parent.val);
  904. group.addElement(pTot);
  905. if (group.lP.nR > group.lP.lR) {
  906. series.algorithmCalcPoints(directionChange, false, group, childrenArea, plot // @todo no supported
  907. );
  908. }
  909. // If last child, then calculate all remaining areas
  910. if (i === end) {
  911. series.algorithmCalcPoints(directionChange, true, group, childrenArea, plot // @todo not supported
  912. );
  913. }
  914. i = i + 1;
  915. });
  916. return childrenArea;
  917. },
  918. algorithmFill: function (directionChange, parent, children) {
  919. var childrenArea = [], pTot, direction = parent.direction, x = parent.x, y = parent.y, width = parent.width, height = parent.height, pX, pY, pW, pH;
  920. children.forEach(function (child) {
  921. pTot =
  922. (parent.width * parent.height) * (child.val / parent.val);
  923. pX = x;
  924. pY = y;
  925. if (direction === 0) {
  926. pH = height;
  927. pW = pTot / pH;
  928. width = width - pW;
  929. x = x + pW;
  930. }
  931. else {
  932. pW = width;
  933. pH = pTot / pW;
  934. height = height - pH;
  935. y = y + pH;
  936. }
  937. childrenArea.push({
  938. x: pX,
  939. y: pY,
  940. width: pW,
  941. height: pH
  942. });
  943. if (directionChange) {
  944. direction = 1 - direction;
  945. }
  946. });
  947. return childrenArea;
  948. },
  949. strip: function (parent, children) {
  950. return this.algorithmLowAspectRatio(false, parent, children);
  951. },
  952. squarified: function (parent, children) {
  953. return this.algorithmLowAspectRatio(true, parent, children);
  954. },
  955. sliceAndDice: function (parent, children) {
  956. return this.algorithmFill(true, parent, children);
  957. },
  958. stripes: function (parent, children) {
  959. return this.algorithmFill(false, parent, children);
  960. },
  961. translate: function () {
  962. var series = this, options = series.options,
  963. // NOTE: updateRootId modifies series.
  964. rootId = updateRootId(series), rootNode, pointValues, seriesArea, tree, val;
  965. // Call prototype function
  966. Series.prototype.translate.call(series);
  967. // @todo Only if series.isDirtyData is true
  968. tree = series.tree = series.getTree();
  969. rootNode = series.nodeMap[rootId];
  970. series.renderTraverseUpButton(rootId);
  971. series.mapOptionsToLevel = getLevelOptions({
  972. from: rootNode.level + 1,
  973. levels: options.levels,
  974. to: tree.height,
  975. defaults: {
  976. levelIsConstant: series.options.levelIsConstant,
  977. colorByPoint: options.colorByPoint
  978. }
  979. });
  980. if (rootId !== '' &&
  981. (!rootNode || !rootNode.children.length)) {
  982. series.setRootNode('', false);
  983. rootId = series.rootNode;
  984. rootNode = series.nodeMap[rootId];
  985. }
  986. // Parents of the root node is by default visible
  987. recursive(series.nodeMap[series.rootNode], function (node) {
  988. var next = false, p = node.parent;
  989. node.visible = true;
  990. if (p || p === '') {
  991. next = series.nodeMap[p];
  992. }
  993. return next;
  994. });
  995. // Children of the root node is by default visible
  996. recursive(series.nodeMap[series.rootNode].children, function (children) {
  997. var next = false;
  998. children.forEach(function (child) {
  999. child.visible = true;
  1000. if (child.children.length) {
  1001. next = (next || []).concat(child.children);
  1002. }
  1003. });
  1004. return next;
  1005. });
  1006. series.setTreeValues(tree);
  1007. // Calculate plotting values.
  1008. series.axisRatio = (series.xAxis.len / series.yAxis.len);
  1009. series.nodeMap[''].pointValues = pointValues = {
  1010. x: 0,
  1011. y: 0,
  1012. width: AXIS_MAX,
  1013. height: AXIS_MAX
  1014. };
  1015. series.nodeMap[''].values = seriesArea = merge(pointValues, {
  1016. width: (pointValues.width * series.axisRatio),
  1017. direction: (options.layoutStartingDirection === 'vertical' ? 0 : 1),
  1018. val: tree.val
  1019. });
  1020. series.calculateChildrenAreas(tree, seriesArea);
  1021. // Logic for point colors
  1022. if (!series.colorAxis &&
  1023. !options.colorByPoint) {
  1024. series.setColorRecursive(series.tree);
  1025. }
  1026. // Update axis extremes according to the root node.
  1027. if (options.allowTraversingTree) {
  1028. val = rootNode.pointValues;
  1029. series.xAxis.setExtremes(val.x, val.x + val.width, false);
  1030. series.yAxis.setExtremes(val.y, val.y + val.height, false);
  1031. series.xAxis.setScale();
  1032. series.yAxis.setScale();
  1033. }
  1034. // Assign values to points.
  1035. series.setPointValues();
  1036. },
  1037. /**
  1038. * Extend drawDataLabels with logic to handle custom options related to
  1039. * the treemap series:
  1040. *
  1041. * - Points which is not a leaf node, has dataLabels disabled by
  1042. * default.
  1043. *
  1044. * - Options set on series.levels is merged in.
  1045. *
  1046. * - Width of the dataLabel is set to match the width of the point
  1047. * shape.
  1048. *
  1049. * @private
  1050. * @function Highcharts.Series#drawDataLabels
  1051. */
  1052. drawDataLabels: function () {
  1053. var series = this, mapOptionsToLevel = series.mapOptionsToLevel, points = series.points.filter(function (n) {
  1054. return n.node.visible;
  1055. }), options, level;
  1056. points.forEach(function (point) {
  1057. level = mapOptionsToLevel[point.node.level];
  1058. // Set options to new object to avoid problems with scope
  1059. options = { style: {} };
  1060. // If not a leaf, then label should be disabled as default
  1061. if (!point.node.isLeaf) {
  1062. options.enabled = false;
  1063. }
  1064. // If options for level exists, include them as well
  1065. if (level && level.dataLabels) {
  1066. options = merge(options, level.dataLabels);
  1067. series._hasPointLabels = true;
  1068. }
  1069. // Set dataLabel width to the width of the point shape.
  1070. if (point.shapeArgs) {
  1071. options.style.width = point.shapeArgs.width;
  1072. if (point.dataLabel) {
  1073. point.dataLabel.css({
  1074. width: point.shapeArgs.width + 'px'
  1075. });
  1076. }
  1077. }
  1078. // Merge custom options with point options
  1079. point.dlOptions = merge(options, point.options.dataLabels);
  1080. });
  1081. Series.prototype.drawDataLabels.call(this);
  1082. },
  1083. // Over the alignment method by setting z index
  1084. alignDataLabel: function (point, dataLabel, labelOptions) {
  1085. var style = labelOptions.style;
  1086. // #8160: Prevent the label from exceeding the point's
  1087. // boundaries in treemaps by applying ellipsis overflow.
  1088. // The issue was happening when datalabel's text contained a
  1089. // long sequence of characters without a whitespace.
  1090. if (!defined(style.textOverflow) &&
  1091. dataLabel.text &&
  1092. dataLabel.getBBox().width > dataLabel.text.textWidth) {
  1093. dataLabel.css({
  1094. textOverflow: 'ellipsis',
  1095. // unit (px) is required when useHTML is true
  1096. width: style.width += 'px'
  1097. });
  1098. }
  1099. seriesTypes.column.prototype.alignDataLabel.apply(this, arguments);
  1100. if (point.dataLabel) {
  1101. // point.node.zIndex could be undefined (#6956)
  1102. point.dataLabel.attr({ zIndex: (point.node.zIndex || 0) + 1 });
  1103. }
  1104. },
  1105. // Get presentational attributes
  1106. pointAttribs: function (point, state) {
  1107. var series = this, mapOptionsToLevel = (isObject(series.mapOptionsToLevel) ?
  1108. series.mapOptionsToLevel :
  1109. {}), level = point && mapOptionsToLevel[point.node.level] || {}, options = this.options, attr, stateOptions = (state && options.states[state]) || {}, className = (point && point.getClassName()) || '', opacity;
  1110. // Set attributes by precedence. Point trumps level trumps series.
  1111. // Stroke width uses pick because it can be 0.
  1112. attr = {
  1113. 'stroke': (point && point.borderColor) ||
  1114. level.borderColor ||
  1115. stateOptions.borderColor ||
  1116. options.borderColor,
  1117. 'stroke-width': pick(point && point.borderWidth, level.borderWidth, stateOptions.borderWidth, options.borderWidth),
  1118. 'dashstyle': (point && point.borderDashStyle) ||
  1119. level.borderDashStyle ||
  1120. stateOptions.borderDashStyle ||
  1121. options.borderDashStyle,
  1122. 'fill': (point && point.color) || this.color
  1123. };
  1124. // Hide levels above the current view
  1125. if (className.indexOf('highcharts-above-level') !== -1) {
  1126. attr.fill = 'none';
  1127. attr['stroke-width'] = 0;
  1128. // Nodes with children that accept interaction
  1129. }
  1130. else if (className.indexOf('highcharts-internal-node-interactive') !== -1) {
  1131. opacity = pick(stateOptions.opacity, options.opacity);
  1132. attr.fill = color(attr.fill).setOpacity(opacity).get();
  1133. attr.cursor = 'pointer';
  1134. // Hide nodes that have children
  1135. }
  1136. else if (className.indexOf('highcharts-internal-node') !== -1) {
  1137. attr.fill = 'none';
  1138. }
  1139. else if (state) {
  1140. // Brighten and hoist the hover nodes
  1141. attr.fill = color(attr.fill)
  1142. .brighten(stateOptions.brightness)
  1143. .get();
  1144. }
  1145. return attr;
  1146. },
  1147. // Override drawPoints
  1148. drawPoints: function () {
  1149. var series = this, chart = series.chart, renderer = chart.renderer, points = series.points, styledMode = chart.styledMode, options = series.options, shadow = styledMode ? {} : options.shadow, borderRadius = options.borderRadius, withinAnimationLimit = chart.pointCount < options.animationLimit, allowTraversingTree = options.allowTraversingTree;
  1150. points.forEach(function (point) {
  1151. var levelDynamic = point.node.levelDynamic, animatableAttribs = {}, attribs = {}, css = {}, groupKey = 'level-group-' + point.node.level, hasGraphic = !!point.graphic, shouldAnimate = withinAnimationLimit && hasGraphic, shapeArgs = point.shapeArgs;
  1152. // Don't bother with calculate styling if the point is not drawn
  1153. if (point.shouldDraw()) {
  1154. if (borderRadius) {
  1155. attribs.r = borderRadius;
  1156. }
  1157. merge(true, // Extend object
  1158. // Which object to extend
  1159. shouldAnimate ? animatableAttribs : attribs,
  1160. // Add shapeArgs to animate/attr if graphic exists
  1161. hasGraphic ? shapeArgs : {},
  1162. // Add style attribs if !styleMode
  1163. styledMode ?
  1164. {} :
  1165. series.pointAttribs(point, point.selected ? 'select' : void 0));
  1166. // In styled mode apply point.color. Use CSS, otherwise the
  1167. // fill used in the style sheet will take precedence over
  1168. // the fill attribute.
  1169. if (series.colorAttribs && styledMode) {
  1170. // Heatmap is loaded
  1171. extend(css, series.colorAttribs(point));
  1172. }
  1173. if (!series[groupKey]) {
  1174. series[groupKey] = renderer.g(groupKey)
  1175. .attr({
  1176. // @todo Set the zIndex based upon the number of
  1177. // levels, instead of using 1000
  1178. zIndex: 1000 - (levelDynamic || 0)
  1179. })
  1180. .add(series.group);
  1181. series[groupKey].survive = true;
  1182. }
  1183. }
  1184. // Draw the point
  1185. point.draw({
  1186. animatableAttribs: animatableAttribs,
  1187. attribs: attribs,
  1188. css: css,
  1189. group: series[groupKey],
  1190. renderer: renderer,
  1191. shadow: shadow,
  1192. shapeArgs: shapeArgs,
  1193. shapeType: 'rect'
  1194. });
  1195. // If setRootNode is allowed, set a point cursor on clickables &
  1196. // add drillId to point
  1197. if (allowTraversingTree && point.graphic) {
  1198. point.drillId = options.interactByLeaf ?
  1199. series.drillToByLeaf(point) :
  1200. series.drillToByGroup(point);
  1201. }
  1202. });
  1203. },
  1204. // Add drilling on the suitable points
  1205. onClickDrillToNode: function (event) {
  1206. var series = this, point = event.point, drillId = point && point.drillId;
  1207. // If a drill id is returned, add click event and cursor.
  1208. if (isString(drillId)) {
  1209. point.setState(''); // Remove hover
  1210. series.setRootNode(drillId, true, { trigger: 'click' });
  1211. }
  1212. },
  1213. /**
  1214. * Finds the drill id for a parent node. Returns false if point should
  1215. * not have a click event.
  1216. *
  1217. * @private
  1218. * @function Highcharts.Series#drillToByGroup
  1219. *
  1220. * @param {Highcharts.Point} point
  1221. *
  1222. * @return {boolean|string}
  1223. * Drill to id or false when point should not have a click
  1224. * event.
  1225. */
  1226. drillToByGroup: function (point) {
  1227. var series = this, drillId = false;
  1228. if ((point.node.level - series.nodeMap[series.rootNode].level) ===
  1229. 1 &&
  1230. !point.node.isLeaf) {
  1231. drillId = point.id;
  1232. }
  1233. return drillId;
  1234. },
  1235. /**
  1236. * Finds the drill id for a leaf node. Returns false if point should not
  1237. * have a click event
  1238. *
  1239. * @private
  1240. * @function Highcharts.Series#drillToByLeaf
  1241. *
  1242. * @param {Highcharts.Point} point
  1243. *
  1244. * @return {boolean|string}
  1245. * Drill to id or false when point should not have a click
  1246. * event.
  1247. */
  1248. drillToByLeaf: function (point) {
  1249. var series = this, drillId = false, nodeParent;
  1250. if ((point.node.parent !== series.rootNode) &&
  1251. point.node.isLeaf) {
  1252. nodeParent = point.node;
  1253. while (!drillId) {
  1254. nodeParent = series.nodeMap[nodeParent.parent];
  1255. if (nodeParent.parent === series.rootNode) {
  1256. drillId = nodeParent.id;
  1257. }
  1258. }
  1259. }
  1260. return drillId;
  1261. },
  1262. drillUp: function () {
  1263. var series = this, node = series.nodeMap[series.rootNode];
  1264. if (node && isString(node.parent)) {
  1265. series.setRootNode(node.parent, true, { trigger: 'traverseUpButton' });
  1266. }
  1267. },
  1268. // TODO remove this function at a suitable version.
  1269. drillToNode: function (id, redraw) {
  1270. error(32, false, void 0, { 'treemap.drillToNode': 'use treemap.setRootNode' });
  1271. this.setRootNode(id, redraw);
  1272. },
  1273. /**
  1274. * Sets a new root node for the series.
  1275. *
  1276. * @private
  1277. * @function Highcharts.Series#setRootNode
  1278. *
  1279. * @param {string} id The id of the new root node.
  1280. * @param {boolean} [redraw=true] Wether to redraw the chart or not.
  1281. * @param {object} [eventArguments] Arguments to be accessed in
  1282. * event handler.
  1283. * @param {string} [eventArguments.newRootId] Id of the new root.
  1284. * @param {string} [eventArguments.previousRootId] Id of the previous
  1285. * root.
  1286. * @param {boolean} [eventArguments.redraw] Wether to redraw the
  1287. * chart after.
  1288. * @param {object} [eventArguments.series] The series to update the root
  1289. * of.
  1290. * @param {string} [eventArguments.trigger] The action which
  1291. * triggered the event. Undefined if the setRootNode is called
  1292. * directly.
  1293. * @return {void}
  1294. *
  1295. * @fires Highcharts.Series#event:setRootNode
  1296. */
  1297. setRootNode: function (id, redraw, eventArguments) {
  1298. var series = this, eventArgs = extend({
  1299. newRootId: id,
  1300. previousRootId: series.rootNode,
  1301. redraw: pick(redraw, true),
  1302. series: series
  1303. }, eventArguments);
  1304. /**
  1305. * The default functionality of the setRootNode event.
  1306. *
  1307. * @private
  1308. * @param {object} args The event arguments.
  1309. * @param {string} args.newRootId Id of the new root.
  1310. * @param {string} args.previousRootId Id of the previous root.
  1311. * @param {boolean} args.redraw Wether to redraw the chart after.
  1312. * @param {object} args.series The series to update the root of.
  1313. * @param {string} [args.trigger=undefined] The action which
  1314. * triggered the event. Undefined if the setRootNode is called
  1315. * directly.
  1316. * @return {void}
  1317. */
  1318. var defaultFn = function (args) {
  1319. var series = args.series;
  1320. // Store previous and new root ids on the series.
  1321. series.idPreviousRoot = args.previousRootId;
  1322. series.rootNode = args.newRootId;
  1323. // Redraw the chart
  1324. series.isDirty = true; // Force redraw
  1325. if (args.redraw) {
  1326. series.chart.redraw();
  1327. }
  1328. };
  1329. // Fire setRootNode event.
  1330. fireEvent(series, 'setRootNode', eventArgs, defaultFn);
  1331. },
  1332. renderTraverseUpButton: function (rootId) {
  1333. var series = this, nodeMap = series.nodeMap, node = nodeMap[rootId], name = node.name, buttonOptions = series.options.traverseUpButton, backText = pick(buttonOptions.text, name, '◁ Back'), attr, states;
  1334. if (rootId === '' || (series.is('sunburst') &&
  1335. series.tree.children.length === 1 &&
  1336. rootId === series.tree.children[0].id)) {
  1337. if (series.drillUpButton) {
  1338. series.drillUpButton = series.drillUpButton.destroy();
  1339. }
  1340. }
  1341. else if (!this.drillUpButton) {
  1342. attr = buttonOptions.theme;
  1343. states = attr && attr.states;
  1344. this.drillUpButton = this.chart.renderer
  1345. .button(backText, 0, 0, function () {
  1346. series.drillUp();
  1347. }, attr, states && states.hover, states && states.select)
  1348. .addClass('highcharts-drillup-button')
  1349. .attr({
  1350. align: buttonOptions.position.align,
  1351. zIndex: 7
  1352. })
  1353. .add()
  1354. .align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
  1355. }
  1356. else {
  1357. this.drillUpButton.placed = false;
  1358. this.drillUpButton.attr({
  1359. text: backText
  1360. })
  1361. .align();
  1362. }
  1363. },
  1364. buildKDTree: noop,
  1365. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  1366. getExtremes: function () {
  1367. // Get the extremes from the value data
  1368. var _a = Series.prototype.getExtremes
  1369. .call(this, this.colorValueData), dataMin = _a.dataMin, dataMax = _a.dataMax;
  1370. this.valueMin = dataMin;
  1371. this.valueMax = dataMax;
  1372. // Get the extremes from the y data
  1373. return Series.prototype.getExtremes.call(this);
  1374. },
  1375. getExtremesFromAll: true,
  1376. /**
  1377. * Workaround for `inactive` state. Since `series.opacity` option is
  1378. * already reserved, don't use that state at all by disabling
  1379. * `inactiveOtherPoints` and not inheriting states by points.
  1380. *
  1381. * @private
  1382. */
  1383. setState: function (state) {
  1384. this.options.inactiveOtherPoints = true;
  1385. Series.prototype.setState.call(this, state, false);
  1386. this.options.inactiveOtherPoints = false;
  1387. },
  1388. utils: {
  1389. recursive: recursive
  1390. }
  1391. /* eslint-enable no-invalid-this, valid-jsdoc */
  1392. }, {
  1393. draw: drawPoint,
  1394. setVisible: seriesTypes.pie.prototype.pointClass.prototype.setVisible,
  1395. /* eslint-disable no-invalid-this, valid-jsdoc */
  1396. getClassName: function () {
  1397. var className = Point.prototype.getClassName.call(this), series = this.series, options = series.options;
  1398. // Above the current level
  1399. if (this.node.level <= series.nodeMap[series.rootNode].level) {
  1400. className += ' highcharts-above-level';
  1401. }
  1402. else if (!this.node.isLeaf &&
  1403. !pick(options.interactByLeaf, !options.allowTraversingTree)) {
  1404. className += ' highcharts-internal-node-interactive';
  1405. }
  1406. else if (!this.node.isLeaf) {
  1407. className += ' highcharts-internal-node';
  1408. }
  1409. return className;
  1410. },
  1411. /**
  1412. * A tree point is valid if it has han id too, assume it may be a parent
  1413. * item.
  1414. *
  1415. * @private
  1416. * @function Highcharts.Point#isValid
  1417. */
  1418. isValid: function () {
  1419. return Boolean(this.id || isNumber(this.value));
  1420. },
  1421. setState: function (state) {
  1422. Point.prototype.setState.call(this, state);
  1423. // Graphic does not exist when point is not visible.
  1424. if (this.graphic) {
  1425. this.graphic.attr({
  1426. zIndex: state === 'hover' ? 1 : 0
  1427. });
  1428. }
  1429. },
  1430. shouldDraw: function () {
  1431. return isNumber(this.plotY) && this.y !== null;
  1432. }
  1433. });
  1434. addEvent(H.Series, 'afterBindAxes', function () {
  1435. var series = this, xAxis = series.xAxis, yAxis = series.yAxis, treeAxis;
  1436. if (xAxis && yAxis) {
  1437. if (series.is('treemap')) {
  1438. treeAxis = {
  1439. endOnTick: false,
  1440. gridLineWidth: 0,
  1441. lineWidth: 0,
  1442. min: 0,
  1443. dataMin: 0,
  1444. minPadding: 0,
  1445. max: AXIS_MAX,
  1446. dataMax: AXIS_MAX,
  1447. maxPadding: 0,
  1448. startOnTick: false,
  1449. title: null,
  1450. tickPositions: []
  1451. };
  1452. extend(yAxis.options, treeAxis);
  1453. extend(xAxis.options, treeAxis);
  1454. treemapAxisDefaultValues = true;
  1455. }
  1456. else if (treemapAxisDefaultValues) {
  1457. yAxis.setOptions(yAxis.userOptions);
  1458. xAxis.setOptions(xAxis.userOptions);
  1459. treemapAxisDefaultValues = false;
  1460. }
  1461. }
  1462. });
  1463. /* eslint-enable no-invalid-this, valid-jsdoc */
  1464. /**
  1465. * A `treemap` series. If the [type](#series.treemap.type) option is
  1466. * not specified, it is inherited from [chart.type](#chart.type).
  1467. *
  1468. * @extends series,plotOptions.treemap
  1469. * @excluding dataParser, dataURL, stack, dataSorting
  1470. * @product highcharts
  1471. * @requires modules/treemap
  1472. * @apioption series.treemap
  1473. */
  1474. /**
  1475. * An array of data points for the series. For the `treemap` series
  1476. * type, points can be given in the following ways:
  1477. *
  1478. * 1. An array of numerical values. In this case, the numerical values will be
  1479. * interpreted as `value` options. Example:
  1480. * ```js
  1481. * data: [0, 5, 3, 5]
  1482. * ```
  1483. *
  1484. * 2. An array of objects with named values. The following snippet shows only a
  1485. * few settings, see the complete options set below. If the total number of
  1486. * data points exceeds the series'
  1487. * [turboThreshold](#series.treemap.turboThreshold),
  1488. * this option is not available.
  1489. * ```js
  1490. * data: [{
  1491. * value: 9,
  1492. * name: "Point2",
  1493. * color: "#00FF00"
  1494. * }, {
  1495. * value: 6,
  1496. * name: "Point1",
  1497. * color: "#FF00FF"
  1498. * }]
  1499. * ```
  1500. *
  1501. * @sample {highcharts} highcharts/chart/reflow-true/
  1502. * Numerical values
  1503. * @sample {highcharts} highcharts/series/data-array-of-objects/
  1504. * Config objects
  1505. *
  1506. * @type {Array<number|null|*>}
  1507. * @extends series.heatmap.data
  1508. * @excluding x, y
  1509. * @product highcharts
  1510. * @apioption series.treemap.data
  1511. */
  1512. /**
  1513. * The value of the point, resulting in a relative area of the point
  1514. * in the treemap.
  1515. *
  1516. * @type {number|null}
  1517. * @product highcharts
  1518. * @apioption series.treemap.data.value
  1519. */
  1520. /**
  1521. * Serves a purpose only if a `colorAxis` object is defined in the chart
  1522. * options. This value will decide which color the point gets from the
  1523. * scale of the colorAxis.
  1524. *
  1525. * @type {number}
  1526. * @since 4.1.0
  1527. * @product highcharts
  1528. * @apioption series.treemap.data.colorValue
  1529. */
  1530. /**
  1531. * Only for treemap. Use this option to build a tree structure. The
  1532. * value should be the id of the point which is the parent. If no points
  1533. * has a matching id, or this option is undefined, then the parent will
  1534. * be set to the root.
  1535. *
  1536. * @sample {highcharts} highcharts/point/parent/
  1537. * Point parent
  1538. * @sample {highcharts} highcharts/demo/treemap-with-levels/
  1539. * Example where parent id is not matching
  1540. *
  1541. * @type {string}
  1542. * @since 4.1.0
  1543. * @product highcharts
  1544. * @apioption series.treemap.data.parent
  1545. */
  1546. ''; // adds doclets above to transpiled file