sunburst.src.js 152 KB

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