sunburst.src.js 124 KB

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