sunburst.src.js 152 KB

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