sunburst.src.js 101 KB

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