sunburst.src.js 122 KB

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