sunburst.src.js 131 KB

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