sunburst.src.js 152 KB

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