treegrid.src.js 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133
  1. /**
  2. * @license Highcharts Gantt JS v9.0.1 (2021-02-16)
  3. *
  4. * Tree Grid
  5. *
  6. * (c) 2016-2021 Jon Arild Nygard
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/treegrid', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Gantt/Tree.js', [_modules['Core/Utilities.js']], function (U) {
  32. /* *
  33. *
  34. * (c) 2016-2021 Highsoft AS
  35. *
  36. * Authors: Jon Arild Nygard
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. /* eslint no-console: 0 */
  44. var extend = U.extend,
  45. isNumber = U.isNumber,
  46. pick = U.pick;
  47. /**
  48. * Creates an object map from parent id to childrens index.
  49. *
  50. * @private
  51. * @function Highcharts.Tree#getListOfParents
  52. *
  53. * @param {Array<*>} data
  54. * List of points set in options. `Array.parent` is parent id of point.
  55. *
  56. * @param {Array<string>} ids
  57. * List of all point ids.
  58. *
  59. * @return {Highcharts.Dictionary<Array<*>>}
  60. * Map from parent id to children index in data
  61. */
  62. var getListOfParents = function (data,
  63. ids) {
  64. var listOfParents = data.reduce(function (prev,
  65. curr) {
  66. var parent = pick(curr.parent, '');
  67. if (typeof prev[parent] === 'undefined') {
  68. prev[parent] = [];
  69. }
  70. prev[parent].push(curr);
  71. return prev;
  72. }, {}), parents = Object.keys(listOfParents);
  73. // If parent does not exist, hoist parent to root of tree.
  74. parents.forEach(function (parent, list) {
  75. var children = listOfParents[parent];
  76. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  77. children.forEach(function (child) {
  78. list[''].push(child);
  79. });
  80. delete list[parent];
  81. }
  82. });
  83. return listOfParents;
  84. };
  85. var getNode = function (id,
  86. parent,
  87. level,
  88. data,
  89. mapOfIdToChildren,
  90. options) {
  91. var descendants = 0,
  92. height = 0,
  93. after = options && options.after,
  94. before = options && options.before,
  95. node = {
  96. data: data,
  97. depth: level - 1,
  98. id: id,
  99. level: level,
  100. parent: parent
  101. },
  102. start,
  103. end,
  104. children;
  105. // Allow custom logic before the children has been created.
  106. if (typeof before === 'function') {
  107. before(node, options);
  108. }
  109. // Call getNode recursively on the children. Calulate the height of the
  110. // node, and the number of descendants.
  111. children = ((mapOfIdToChildren[id] || [])).map(function (child) {
  112. var node = getNode(child.id,
  113. id, (level + 1),
  114. child,
  115. mapOfIdToChildren,
  116. options),
  117. childStart = child.start,
  118. childEnd = (child.milestone === true ?
  119. childStart :
  120. child.end);
  121. // Start should be the lowest child.start.
  122. start = ((!isNumber(start) || childStart < start) ?
  123. childStart :
  124. start);
  125. // End should be the largest child.end.
  126. // If child is milestone, then use start as end.
  127. end = ((!isNumber(end) || childEnd > end) ?
  128. childEnd :
  129. end);
  130. descendants = descendants + 1 + node.descendants;
  131. height = Math.max(node.height + 1, height);
  132. return node;
  133. });
  134. // Calculate start and end for point if it is not already explicitly set.
  135. if (data) {
  136. data.start = pick(data.start, start);
  137. data.end = pick(data.end, end);
  138. }
  139. extend(node, {
  140. children: children,
  141. descendants: descendants,
  142. height: height
  143. });
  144. // Allow custom logic after the children has been created.
  145. if (typeof after === 'function') {
  146. after(node, options);
  147. }
  148. return node;
  149. };
  150. var getTree = function (data,
  151. options) {
  152. var ids = data.map(function (d) {
  153. return d.id;
  154. }), mapOfIdToChildren = getListOfParents(data, ids);
  155. return getNode('', null, 1, null, mapOfIdToChildren, options);
  156. };
  157. var Tree = {
  158. getListOfParents: getListOfParents,
  159. getNode: getNode,
  160. getTree: getTree
  161. };
  162. return Tree;
  163. });
  164. _registerModule(_modules, 'Core/Axis/TreeGridTick.js', [_modules['Core/Color/Palette.js'], _modules['Core/Utilities.js']], function (palette, U) {
  165. /* *
  166. *
  167. * (c) 2016 Highsoft AS
  168. * Authors: Jon Arild Nygard
  169. *
  170. * License: www.highcharts.com/license
  171. *
  172. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  173. *
  174. * */
  175. var addEvent = U.addEvent,
  176. defined = U.defined,
  177. isObject = U.isObject,
  178. isNumber = U.isNumber,
  179. pick = U.pick,
  180. wrap = U.wrap;
  181. /**
  182. * @private
  183. */
  184. var TreeGridTick;
  185. (function (TreeGridTick) {
  186. /* *
  187. *
  188. * Interfaces
  189. *
  190. * */
  191. /* *
  192. *
  193. * Variables
  194. *
  195. * */
  196. var applied = false;
  197. /* *
  198. *
  199. * Functions
  200. *
  201. * */
  202. /**
  203. * @private
  204. */
  205. function compose(TickClass) {
  206. if (!applied) {
  207. addEvent(TickClass, 'init', onInit);
  208. wrap(TickClass.prototype, 'getLabelPosition', wrapGetLabelPosition);
  209. wrap(TickClass.prototype, 'renderLabel', wrapRenderLabel);
  210. // backwards compatibility
  211. TickClass.prototype.collapse = function (redraw) {
  212. this.treeGrid.collapse(redraw);
  213. };
  214. TickClass.prototype.expand = function (redraw) {
  215. this.treeGrid.expand(redraw);
  216. };
  217. TickClass.prototype.toggleCollapse = function (redraw) {
  218. this.treeGrid.toggleCollapse(redraw);
  219. };
  220. applied = true;
  221. }
  222. }
  223. TreeGridTick.compose = compose;
  224. /**
  225. * @private
  226. */
  227. function onInit() {
  228. var tick = this;
  229. if (!tick.treeGrid) {
  230. tick.treeGrid = new Additions(tick);
  231. }
  232. }
  233. /**
  234. * @private
  235. */
  236. function onTickHover(label) {
  237. label.addClass('highcharts-treegrid-node-active');
  238. if (!label.renderer.styledMode) {
  239. label.css({
  240. textDecoration: 'underline'
  241. });
  242. }
  243. }
  244. /**
  245. * @private
  246. */
  247. function onTickHoverExit(label, options) {
  248. var css = isObject(options.style) ? options.style : {};
  249. label.removeClass('highcharts-treegrid-node-active');
  250. if (!label.renderer.styledMode) {
  251. label.css({ textDecoration: css.textDecoration });
  252. }
  253. }
  254. /**
  255. * @private
  256. */
  257. function renderLabelIcon(tick, params) {
  258. var treeGrid = tick.treeGrid,
  259. isNew = !treeGrid.labelIcon,
  260. renderer = params.renderer,
  261. labelBox = params.xy,
  262. options = params.options,
  263. width = options.width,
  264. height = options.height,
  265. iconCenter = {
  266. x: labelBox.x - (width / 2) - options.padding,
  267. y: labelBox.y - (height / 2)
  268. },
  269. rotation = params.collapsed ? 90 : 180,
  270. shouldRender = params.show && isNumber(iconCenter.y);
  271. var icon = treeGrid.labelIcon;
  272. if (!icon) {
  273. treeGrid.labelIcon = icon = renderer
  274. .path(renderer.symbols[options.type](options.x, options.y, width, height))
  275. .addClass('highcharts-label-icon')
  276. .add(params.group);
  277. }
  278. // Set the new position, and show or hide
  279. if (!shouldRender) {
  280. icon.attr({ y: -9999 }); // #1338
  281. }
  282. // Presentational attributes
  283. if (!renderer.styledMode) {
  284. icon
  285. .attr({
  286. 'stroke-width': 1,
  287. 'fill': pick(params.color, palette.neutralColor60)
  288. })
  289. .css({
  290. cursor: 'pointer',
  291. stroke: options.lineColor,
  292. strokeWidth: options.lineWidth
  293. });
  294. }
  295. // Update the icon positions
  296. icon[isNew ? 'attr' : 'animate']({
  297. translateX: iconCenter.x,
  298. translateY: iconCenter.y,
  299. rotation: rotation
  300. });
  301. }
  302. /**
  303. * @private
  304. */
  305. function wrapGetLabelPosition(proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  306. var tick = this,
  307. lbOptions = pick(tick.options && tick.options.labels,
  308. labelOptions),
  309. pos = tick.pos,
  310. axis = tick.axis,
  311. options = axis.options,
  312. isTreeGrid = options.type === 'treegrid',
  313. result = proceed.apply(tick,
  314. [x,
  315. y,
  316. label,
  317. horiz,
  318. lbOptions,
  319. tickmarkOffset,
  320. index,
  321. step]);
  322. var symbolOptions,
  323. indentation,
  324. mapOfPosToGridNode,
  325. node,
  326. level;
  327. if (isTreeGrid) {
  328. symbolOptions = (lbOptions && isObject(lbOptions.symbol, true) ?
  329. lbOptions.symbol :
  330. {});
  331. indentation = (lbOptions && isNumber(lbOptions.indentation) ?
  332. lbOptions.indentation :
  333. 0);
  334. mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode;
  335. node = mapOfPosToGridNode && mapOfPosToGridNode[pos];
  336. level = (node && node.depth) || 1;
  337. result.x += (
  338. // Add space for symbols
  339. ((symbolOptions.width) + (symbolOptions.padding * 2)) +
  340. // Apply indentation
  341. ((level - 1) * indentation));
  342. }
  343. return result;
  344. }
  345. /**
  346. * @private
  347. */
  348. function wrapRenderLabel(proceed) {
  349. var tick = this, pos = tick.pos, axis = tick.axis, label = tick.label, mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode, options = axis.options, labelOptions = pick(tick.options && tick.options.labels, options && options.labels), symbolOptions = (labelOptions && isObject(labelOptions.symbol, true) ?
  350. labelOptions.symbol :
  351. {}), node = mapOfPosToGridNode && mapOfPosToGridNode[pos], level = node && node.depth, isTreeGrid = options.type === 'treegrid', shouldRender = axis.tickPositions.indexOf(pos) > -1, prefixClassName = 'highcharts-treegrid-node-', styledMode = axis.chart.styledMode;
  352. var collapsed,
  353. addClassName,
  354. removeClassName;
  355. if (isTreeGrid && node) {
  356. // Add class name for hierarchical styling.
  357. if (label &&
  358. label.element) {
  359. label.addClass(prefixClassName + 'level-' + level);
  360. }
  361. }
  362. proceed.apply(tick, Array.prototype.slice.call(arguments, 1));
  363. if (isTreeGrid &&
  364. label &&
  365. label.element &&
  366. node &&
  367. node.descendants &&
  368. node.descendants > 0) {
  369. collapsed = axis.treeGrid.isCollapsed(node);
  370. renderLabelIcon(tick, {
  371. color: !styledMode && label.styles && label.styles.color || '',
  372. collapsed: collapsed,
  373. group: label.parentGroup,
  374. options: symbolOptions,
  375. renderer: label.renderer,
  376. show: shouldRender,
  377. xy: label.xy
  378. });
  379. // Add class name for the node.
  380. addClassName = prefixClassName +
  381. (collapsed ? 'collapsed' : 'expanded');
  382. removeClassName = prefixClassName +
  383. (collapsed ? 'expanded' : 'collapsed');
  384. label
  385. .addClass(addClassName)
  386. .removeClass(removeClassName);
  387. if (!styledMode) {
  388. label.css({
  389. cursor: 'pointer'
  390. });
  391. }
  392. // Add events to both label text and icon
  393. [label, tick.treeGrid.labelIcon].forEach(function (object) {
  394. if (object && !object.attachedTreeGridEvents) {
  395. // On hover
  396. addEvent(object.element, 'mouseover', function () {
  397. onTickHover(label);
  398. });
  399. // On hover out
  400. addEvent(object.element, 'mouseout', function () {
  401. onTickHoverExit(label, labelOptions);
  402. });
  403. addEvent(object.element, 'click', function () {
  404. tick.treeGrid.toggleCollapse();
  405. });
  406. object.attachedTreeGridEvents = true;
  407. }
  408. });
  409. }
  410. }
  411. /* *
  412. *
  413. * Classes
  414. *
  415. * */
  416. /**
  417. * @private
  418. * @class
  419. */
  420. var Additions = /** @class */ (function () {
  421. /* *
  422. *
  423. * Constructors
  424. *
  425. * */
  426. /**
  427. * @private
  428. */
  429. function Additions(tick) {
  430. this.tick = tick;
  431. }
  432. /* *
  433. *
  434. * Functions
  435. *
  436. * */
  437. /**
  438. * Collapse the grid cell. Used when axis is of type treegrid.
  439. *
  440. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  441. *
  442. * @private
  443. * @function Highcharts.Tick#collapse
  444. *
  445. * @param {boolean} [redraw=true]
  446. * Whether to redraw the chart or wait for an explicit call to
  447. * {@link Highcharts.Chart#redraw}
  448. */
  449. Additions.prototype.collapse = function (redraw) {
  450. var tick = this.tick,
  451. axis = tick.axis,
  452. brokenAxis = axis.brokenAxis;
  453. if (brokenAxis &&
  454. axis.treeGrid.mapOfPosToGridNode) {
  455. var pos = tick.pos,
  456. node = axis.treeGrid.mapOfPosToGridNode[pos],
  457. breaks = axis.treeGrid.collapse(node);
  458. brokenAxis.setBreaks(breaks, pick(redraw, true));
  459. }
  460. };
  461. /**
  462. * Expand the grid cell. Used when axis is of type treegrid.
  463. *
  464. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  465. *
  466. * @private
  467. * @function Highcharts.Tick#expand
  468. *
  469. * @param {boolean} [redraw=true]
  470. * Whether to redraw the chart or wait for an explicit call to
  471. * {@link Highcharts.Chart#redraw}
  472. */
  473. Additions.prototype.expand = function (redraw) {
  474. var tick = this.tick,
  475. axis = tick.axis,
  476. brokenAxis = axis.brokenAxis;
  477. if (brokenAxis &&
  478. axis.treeGrid.mapOfPosToGridNode) {
  479. var pos = tick.pos,
  480. node = axis.treeGrid.mapOfPosToGridNode[pos],
  481. breaks = axis.treeGrid.expand(node);
  482. brokenAxis.setBreaks(breaks, pick(redraw, true));
  483. }
  484. };
  485. /**
  486. * Toggle the collapse/expand state of the grid cell. Used when axis is
  487. * of type treegrid.
  488. *
  489. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  490. *
  491. * @private
  492. * @function Highcharts.Tick#toggleCollapse
  493. *
  494. * @param {boolean} [redraw=true]
  495. * Whether to redraw the chart or wait for an explicit call to
  496. * {@link Highcharts.Chart#redraw}
  497. */
  498. Additions.prototype.toggleCollapse = function (redraw) {
  499. var tick = this.tick,
  500. axis = tick.axis,
  501. brokenAxis = axis.brokenAxis;
  502. if (brokenAxis &&
  503. axis.treeGrid.mapOfPosToGridNode) {
  504. var pos = tick.pos,
  505. node = axis.treeGrid.mapOfPosToGridNode[pos],
  506. breaks = axis.treeGrid.toggleCollapse(node);
  507. brokenAxis.setBreaks(breaks, pick(redraw, true));
  508. }
  509. };
  510. return Additions;
  511. }());
  512. TreeGridTick.Additions = Additions;
  513. })(TreeGridTick || (TreeGridTick = {}));
  514. return TreeGridTick;
  515. });
  516. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  517. /* *
  518. *
  519. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  520. *
  521. * */
  522. var extend = U.extend,
  523. isArray = U.isArray,
  524. isNumber = U.isNumber,
  525. isObject = U.isObject,
  526. merge = U.merge,
  527. pick = U.pick;
  528. var isBoolean = function (x) {
  529. return typeof x === 'boolean';
  530. }, isFn = function (x) {
  531. return typeof x === 'function';
  532. };
  533. /* eslint-disable valid-jsdoc */
  534. /**
  535. * @todo Combine buildTree and buildNode with setTreeValues
  536. * @todo Remove logic from Treemap and make it utilize this mixin.
  537. * @private
  538. */
  539. var setTreeValues = function setTreeValues(tree,
  540. options) {
  541. var before = options.before,
  542. idRoot = options.idRoot,
  543. mapIdToNode = options.mapIdToNode,
  544. nodeRoot = mapIdToNode[idRoot],
  545. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  546. options.levelIsConstant :
  547. true),
  548. points = options.points,
  549. point = points[tree.i],
  550. optionsPoint = point && point.options || {},
  551. childrenTotal = 0,
  552. children = [],
  553. value;
  554. extend(tree, {
  555. levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
  556. name: pick(point && point.name, ''),
  557. visible: (idRoot === tree.id ||
  558. (isBoolean(options.visible) ? options.visible : false))
  559. });
  560. if (isFn(before)) {
  561. tree = before(tree, options);
  562. }
  563. // First give the children some values
  564. tree.children.forEach(function (child, i) {
  565. var newOptions = extend({},
  566. options);
  567. extend(newOptions, {
  568. index: i,
  569. siblings: tree.children.length,
  570. visible: tree.visible
  571. });
  572. child = setTreeValues(child, newOptions);
  573. children.push(child);
  574. if (child.visible) {
  575. childrenTotal += child.val;
  576. }
  577. });
  578. tree.visible = childrenTotal > 0 || tree.visible;
  579. // Set the values
  580. value = pick(optionsPoint.value, childrenTotal);
  581. extend(tree, {
  582. children: children,
  583. childrenTotal: childrenTotal,
  584. isLeaf: tree.visible && !childrenTotal,
  585. val: value
  586. });
  587. return tree;
  588. };
  589. /**
  590. * @private
  591. */
  592. var getColor = function getColor(node,
  593. options) {
  594. var index = options.index,
  595. mapOptionsToLevel = options.mapOptionsToLevel,
  596. parentColor = options.parentColor,
  597. parentColorIndex = options.parentColorIndex,
  598. series = options.series,
  599. colors = options.colors,
  600. siblings = options.siblings,
  601. points = series.points,
  602. getColorByPoint,
  603. chartOptionsChart = series.chart.options.chart,
  604. point,
  605. level,
  606. colorByPoint,
  607. colorIndexByPoint,
  608. color,
  609. colorIndex;
  610. /**
  611. * @private
  612. */
  613. function variation(color) {
  614. var colorVariation = level && level.colorVariation;
  615. if (colorVariation) {
  616. if (colorVariation.key === 'brightness') {
  617. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  618. }
  619. }
  620. return color;
  621. }
  622. if (node) {
  623. point = points[node.i];
  624. level = mapOptionsToLevel[node.level] || {};
  625. getColorByPoint = point && level.colorByPoint;
  626. if (getColorByPoint) {
  627. colorIndexByPoint = point.index % (colors ?
  628. colors.length :
  629. chartOptionsChart.colorCount);
  630. colorByPoint = colors && colors[colorIndexByPoint];
  631. }
  632. // Select either point color, level color or inherited color.
  633. if (!series.chart.styledMode) {
  634. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  635. }
  636. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  637. }
  638. return {
  639. color: color,
  640. colorIndex: colorIndex
  641. };
  642. };
  643. /**
  644. * Creates a map from level number to its given options.
  645. *
  646. * @private
  647. * @function getLevelOptions
  648. * @param {object} params
  649. * Object containing parameters.
  650. * - `defaults` Object containing default options. The default options
  651. * are merged with the userOptions to get the final options for a
  652. * specific level.
  653. * - `from` The lowest level number.
  654. * - `levels` User options from series.levels.
  655. * - `to` The highest level number.
  656. * @return {Highcharts.Dictionary<object>|null}
  657. * Returns a map from level number to its given options.
  658. */
  659. var getLevelOptions = function getLevelOptions(params) {
  660. var result = null,
  661. defaults,
  662. converted,
  663. i,
  664. from,
  665. to,
  666. levels;
  667. if (isObject(params)) {
  668. result = {};
  669. from = isNumber(params.from) ? params.from : 1;
  670. levels = params.levels;
  671. converted = {};
  672. defaults = isObject(params.defaults) ? params.defaults : {};
  673. if (isArray(levels)) {
  674. converted = levels.reduce(function (obj, item) {
  675. var level,
  676. levelIsConstant,
  677. options;
  678. if (isObject(item) && isNumber(item.level)) {
  679. options = merge({}, item);
  680. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  681. options.levelIsConstant :
  682. defaults.levelIsConstant);
  683. // Delete redundant properties.
  684. delete options.levelIsConstant;
  685. delete options.level;
  686. // Calculate which level these options apply to.
  687. level = item.level + (levelIsConstant ? 0 : from - 1);
  688. if (isObject(obj[level])) {
  689. extend(obj[level], options);
  690. }
  691. else {
  692. obj[level] = options;
  693. }
  694. }
  695. return obj;
  696. }, {});
  697. }
  698. to = isNumber(params.to) ? params.to : 1;
  699. for (i = 0; i <= to; i++) {
  700. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  701. }
  702. }
  703. return result;
  704. };
  705. /**
  706. * Update the rootId property on the series. Also makes sure that it is
  707. * accessible to exporting.
  708. *
  709. * @private
  710. * @function updateRootId
  711. *
  712. * @param {object} series
  713. * The series to operate on.
  714. *
  715. * @return {string}
  716. * Returns the resulting rootId after update.
  717. */
  718. var updateRootId = function (series) {
  719. var rootId,
  720. options;
  721. if (isObject(series)) {
  722. // Get the series options.
  723. options = isObject(series.options) ? series.options : {};
  724. // Calculate the rootId.
  725. rootId = pick(series.rootNode, options.rootId, '');
  726. // Set rootId on series.userOptions to pick it up in exporting.
  727. if (isObject(series.userOptions)) {
  728. series.userOptions.rootId = rootId;
  729. }
  730. // Set rootId on series to pick it up on next update.
  731. series.rootNode = rootId;
  732. }
  733. return rootId;
  734. };
  735. var result = {
  736. getColor: getColor,
  737. getLevelOptions: getLevelOptions,
  738. setTreeValues: setTreeValues,
  739. updateRootId: updateRootId
  740. };
  741. return result;
  742. });
  743. _registerModule(_modules, 'Core/Axis/GridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js']], function (Axis, H, Tick, U) {
  744. /* *
  745. *
  746. * (c) 2016 Highsoft AS
  747. * Authors: Lars A. V. Cabrera
  748. *
  749. * License: www.highcharts.com/license
  750. *
  751. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  752. *
  753. * */
  754. var addEvent = U.addEvent,
  755. defined = U.defined,
  756. erase = U.erase,
  757. find = U.find,
  758. isArray = U.isArray,
  759. isNumber = U.isNumber,
  760. merge = U.merge,
  761. pick = U.pick,
  762. timeUnits = U.timeUnits,
  763. wrap = U.wrap;
  764. var argsToArray = function (args) {
  765. return Array.prototype.slice.call(args, 1);
  766. }, isObject = function (x) {
  767. // Always use strict mode
  768. return U.isObject(x, true);
  769. }, Chart = H.Chart;
  770. var applyGridOptions = function applyGridOptions(axis) {
  771. var options = axis.options;
  772. // Center-align by default
  773. if (!options.labels) {
  774. options.labels = {};
  775. }
  776. options.labels.align = pick(options.labels.align, 'center');
  777. // @todo: Check against tickLabelPlacement between/on etc
  778. /* Prevents adding the last tick label if the axis is not a category
  779. axis.
  780. Since numeric labels are normally placed at starts and ends of a
  781. range of value, and this module makes the label point at the value,
  782. an "extra" label would appear. */
  783. if (!axis.categories) {
  784. options.showLastLabel = false;
  785. }
  786. // Prevents rotation of labels when squished, as rotating them would not
  787. // help.
  788. axis.labelRotation = 0;
  789. options.labels.rotation = 0;
  790. };
  791. /**
  792. * @productdesc {gantt}
  793. * For grid axes (like in Gantt charts),
  794. * it is possible to declare as a list to provide different
  795. * formats depending on available space.
  796. *
  797. * Defaults to:
  798. * ```js
  799. * {
  800. * hour: { list: ['%H:%M', '%H'] },
  801. * day: { list: ['%A, %e. %B', '%a, %e. %b', '%E'] },
  802. * week: { list: ['Week %W', 'W%W'] },
  803. * month: { list: ['%B', '%b', '%o'] }
  804. * }
  805. * ```
  806. *
  807. * @sample {gantt} gantt/grid-axis/date-time-label-formats
  808. * Gantt chart with custom axis date format.
  809. *
  810. * @apioption xAxis.dateTimeLabelFormats
  811. */
  812. /**
  813. * Set grid options for the axis labels. Requires Highcharts Gantt.
  814. *
  815. * @since 6.2.0
  816. * @product gantt
  817. * @apioption xAxis.grid
  818. */
  819. /**
  820. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  821. *
  822. * @type {boolean}
  823. * @default true
  824. * @since 6.2.0
  825. * @product gantt
  826. * @apioption xAxis.grid.enabled
  827. */
  828. /**
  829. * Set specific options for each column (or row for horizontal axes) in the
  830. * grid. Each extra column/row is its own axis, and the axis options can be set
  831. * here.
  832. *
  833. * @sample gantt/demo/left-axis-table
  834. * Left axis as a table
  835. *
  836. * @type {Array<Highcharts.XAxisOptions>}
  837. * @apioption xAxis.grid.columns
  838. */
  839. /**
  840. * Set border color for the label grid lines.
  841. *
  842. * @type {Highcharts.ColorString}
  843. * @apioption xAxis.grid.borderColor
  844. */
  845. /**
  846. * Set border width of the label grid lines.
  847. *
  848. * @type {number}
  849. * @default 1
  850. * @apioption xAxis.grid.borderWidth
  851. */
  852. /**
  853. * Set cell height for grid axis labels. By default this is calculated from font
  854. * size. This option only applies to horizontal axes.
  855. *
  856. * @sample gantt/grid-axis/cellheight
  857. * Gant chart with custom cell height
  858. * @type {number}
  859. * @apioption xAxis.grid.cellHeight
  860. */
  861. ''; // detach doclets above
  862. /**
  863. * Get the largest label width and height.
  864. *
  865. * @private
  866. * @function Highcharts.Axis#getMaxLabelDimensions
  867. *
  868. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  869. * All the ticks on one axis.
  870. *
  871. * @param {Array<number|string>} tickPositions
  872. * All the tick positions on one axis.
  873. *
  874. * @return {Highcharts.SizeObject}
  875. * Object containing the properties height and width.
  876. *
  877. * @todo Move this to the generic axis implementation, as it is used there.
  878. */
  879. Axis.prototype.getMaxLabelDimensions = function (ticks, tickPositions) {
  880. var dimensions = {
  881. width: 0,
  882. height: 0
  883. };
  884. tickPositions.forEach(function (pos) {
  885. var tick = ticks[pos],
  886. labelHeight = 0,
  887. labelWidth = 0,
  888. label;
  889. if (isObject(tick)) {
  890. label = isObject(tick.label) ? tick.label : {};
  891. // Find width and height of label
  892. labelHeight = label.getBBox ? label.getBBox().height : 0;
  893. if (label.textStr && !isNumber(label.textPxLength)) {
  894. label.textPxLength = label.getBBox().width;
  895. }
  896. labelWidth = isNumber(label.textPxLength) ?
  897. // Math.round ensures crisp lines
  898. Math.round(label.textPxLength) :
  899. 0;
  900. if (label.textStr) {
  901. // Set the tickWidth same as the label width after ellipsis
  902. // applied #10281
  903. labelWidth = Math.round(label.getBBox().width);
  904. }
  905. // Update the result if width and/or height are larger
  906. dimensions.height = Math.max(labelHeight, dimensions.height);
  907. dimensions.width = Math.max(labelWidth, dimensions.width);
  908. }
  909. });
  910. return dimensions;
  911. };
  912. // Adds week date format
  913. H.dateFormats.W = function (timestamp) {
  914. var d = new this.Date(timestamp);
  915. var firstDay = (this.get('Day',
  916. d) + 6) % 7;
  917. var thursday = new this.Date(d.valueOf());
  918. this.set('Date', thursday, this.get('Date', d) - firstDay + 3);
  919. var firstThursday = new this.Date(this.get('FullYear',
  920. thursday), 0, 1);
  921. if (this.get('Day', firstThursday) !== 4) {
  922. this.set('Month', d, 0);
  923. this.set('Date', d, 1 + (11 - this.get('Day', firstThursday)) % 7);
  924. }
  925. return (1 +
  926. Math.floor((thursday.valueOf() - firstThursday.valueOf()) / 604800000)).toString();
  927. };
  928. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  929. H.dateFormats.E = function (timestamp) {
  930. return this.dateFormat('%a', timestamp, true).charAt(0);
  931. };
  932. /* eslint-disable no-invalid-this */
  933. addEvent(Chart, 'afterSetChartSize', function () {
  934. this.axes.forEach(function (axis) {
  935. (axis.grid && axis.grid.columns || []).forEach(function (column) {
  936. column.setAxisSize();
  937. column.setAxisTranslation();
  938. });
  939. });
  940. });
  941. // Center tick labels in cells.
  942. addEvent(Tick, 'afterGetLabelPosition', function (e) {
  943. var tick = this,
  944. label = tick.label,
  945. axis = tick.axis,
  946. reversed = axis.reversed,
  947. chart = axis.chart,
  948. options = axis.options,
  949. gridOptions = options.grid || {},
  950. labelOpts = axis.options.labels,
  951. align = labelOpts.align,
  952. // verticalAlign is currently not supported for axis.labels.
  953. verticalAlign = 'middle', // labelOpts.verticalAlign,
  954. side = GridAxis.Side[axis.side],
  955. tickmarkOffset = e.tickmarkOffset,
  956. tickPositions = axis.tickPositions,
  957. tickPos = tick.pos - tickmarkOffset,
  958. nextTickPos = (isNumber(tickPositions[e.index + 1]) ?
  959. tickPositions[e.index + 1] - tickmarkOffset :
  960. axis.max + tickmarkOffset),
  961. tickSize = axis.tickSize('tick'),
  962. tickWidth = tickSize ? tickSize[0] : 0,
  963. crispCorr = tickSize ? tickSize[1] / 2 : 0,
  964. labelHeight,
  965. lblMetrics,
  966. lines,
  967. bottom,
  968. top,
  969. left,
  970. right;
  971. // Only center tick labels in grid axes
  972. if (gridOptions.enabled === true) {
  973. // Calculate top and bottom positions of the cell.
  974. if (side === 'top') {
  975. bottom = axis.top + axis.offset;
  976. top = bottom - tickWidth;
  977. }
  978. else if (side === 'bottom') {
  979. top = chart.chartHeight - axis.bottom + axis.offset;
  980. bottom = top + tickWidth;
  981. }
  982. else {
  983. bottom = axis.top + axis.len - axis.translate(reversed ? nextTickPos : tickPos);
  984. top = axis.top + axis.len - axis.translate(reversed ? tickPos : nextTickPos);
  985. }
  986. // Calculate left and right positions of the cell.
  987. if (side === 'right') {
  988. left = chart.chartWidth - axis.right + axis.offset;
  989. right = left + tickWidth;
  990. }
  991. else if (side === 'left') {
  992. right = axis.left + axis.offset;
  993. left = right - tickWidth;
  994. }
  995. else {
  996. left = Math.round(axis.left + axis.translate(reversed ? nextTickPos : tickPos)) - crispCorr;
  997. right = Math.round(axis.left + axis.translate(reversed ? tickPos : nextTickPos)) - crispCorr;
  998. }
  999. tick.slotWidth = right - left;
  1000. // Calculate the positioning of the label based on
  1001. // alignment.
  1002. e.pos.x = (align === 'left' ?
  1003. left :
  1004. align === 'right' ?
  1005. right :
  1006. left + ((right - left) / 2) // default to center
  1007. );
  1008. e.pos.y = (verticalAlign === 'top' ?
  1009. top :
  1010. verticalAlign === 'bottom' ?
  1011. bottom :
  1012. top + ((bottom - top) / 2) // default to middle
  1013. );
  1014. lblMetrics = chart.renderer.fontMetrics(labelOpts.style.fontSize, label.element);
  1015. labelHeight = label.getBBox().height;
  1016. // Adjustment to y position to align the label correctly.
  1017. // Would be better to have a setter or similar for this.
  1018. if (!labelOpts.useHTML) {
  1019. lines = Math.round(labelHeight / lblMetrics.h);
  1020. e.pos.y += (
  1021. // Center the label
  1022. // TODO: why does this actually center the label?
  1023. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  1024. // Adjust for height of additional lines.
  1025. -(((lines - 1) * lblMetrics.h) / 2));
  1026. }
  1027. else {
  1028. e.pos.y += (
  1029. // Readjust yCorr in htmlUpdateTransform
  1030. lblMetrics.b +
  1031. // Adjust for height of html label
  1032. -(labelHeight / 2));
  1033. }
  1034. e.pos.x += (axis.horiz && labelOpts.x || 0);
  1035. }
  1036. });
  1037. /* eslint-enable no-invalid-this */
  1038. /**
  1039. * Additions for grid axes.
  1040. * @private
  1041. * @class
  1042. */
  1043. var GridAxisAdditions = /** @class */ (function () {
  1044. /* *
  1045. *
  1046. * Constructors
  1047. *
  1048. * */
  1049. function GridAxisAdditions(axis) {
  1050. this.axis = axis;
  1051. }
  1052. /* *
  1053. *
  1054. * Functions
  1055. *
  1056. * */
  1057. /**
  1058. * Checks if an axis is the outer axis in its dimension. Since
  1059. * axes are placed outwards in order, the axis with the highest
  1060. * index is the outermost axis.
  1061. *
  1062. * Example: If there are multiple x-axes at the top of the chart,
  1063. * this function returns true if the axis supplied is the last
  1064. * of the x-axes.
  1065. *
  1066. * @private
  1067. *
  1068. * @return {boolean}
  1069. * True if the axis is the outermost axis in its dimension; false if
  1070. * not.
  1071. */
  1072. GridAxisAdditions.prototype.isOuterAxis = function () {
  1073. var axis = this.axis;
  1074. var chart = axis.chart;
  1075. var columnIndex = axis.grid.columnIndex;
  1076. var columns = (axis.linkedParent && axis.linkedParent.grid.columns ||
  1077. axis.grid.columns);
  1078. var parentAxis = columnIndex ? axis.linkedParent : axis;
  1079. var thisIndex = -1,
  1080. lastIndex = 0;
  1081. chart[axis.coll].forEach(function (otherAxis, index) {
  1082. if (otherAxis.side === axis.side && !otherAxis.options.isInternal) {
  1083. lastIndex = index;
  1084. if (otherAxis === parentAxis) {
  1085. // Get the index of the axis in question
  1086. thisIndex = index;
  1087. }
  1088. }
  1089. });
  1090. return (lastIndex === thisIndex &&
  1091. (isNumber(columnIndex) ? columns.length === columnIndex : true));
  1092. };
  1093. /**
  1094. * Add extra border based on the provided path.
  1095. * *
  1096. * @private
  1097. *
  1098. * @param {SVGPath} path
  1099. * The path of the border.
  1100. *
  1101. * @return {Highcharts.SVGElement}
  1102. */
  1103. GridAxisAdditions.prototype.renderBorder = function (path) {
  1104. var axis = this.axis,
  1105. renderer = axis.chart.renderer,
  1106. options = axis.options,
  1107. extraBorderLine = renderer.path(path)
  1108. .addClass('highcharts-axis-line')
  1109. .add(axis.axisBorder);
  1110. if (!renderer.styledMode) {
  1111. extraBorderLine.attr({
  1112. stroke: options.lineColor,
  1113. 'stroke-width': options.lineWidth,
  1114. zIndex: 7
  1115. });
  1116. }
  1117. return extraBorderLine;
  1118. };
  1119. return GridAxisAdditions;
  1120. }());
  1121. /**
  1122. * Axis with grid support.
  1123. * @private
  1124. * @class
  1125. */
  1126. var GridAxis = /** @class */ (function () {
  1127. function GridAxis() {
  1128. }
  1129. /* *
  1130. *
  1131. * Static Functions
  1132. *
  1133. * */
  1134. /* eslint-disable valid-jsdoc */
  1135. /**
  1136. * Extends axis class with grid support.
  1137. * @private
  1138. */
  1139. GridAxis.compose = function (AxisClass) {
  1140. Axis.keepProps.push('grid');
  1141. wrap(AxisClass.prototype, 'unsquish', GridAxis.wrapUnsquish);
  1142. // Add event handlers
  1143. addEvent(AxisClass, 'init', GridAxis.onInit);
  1144. addEvent(AxisClass, 'afterGetOffset', GridAxis.onAfterGetOffset);
  1145. addEvent(AxisClass, 'afterGetTitlePosition', GridAxis.onAfterGetTitlePosition);
  1146. addEvent(AxisClass, 'afterInit', GridAxis.onAfterInit);
  1147. addEvent(AxisClass, 'afterRender', GridAxis.onAfterRender);
  1148. addEvent(AxisClass, 'afterSetAxisTranslation', GridAxis.onAfterSetAxisTranslation);
  1149. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions);
  1150. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions2);
  1151. addEvent(AxisClass, 'afterSetScale', GridAxis.onAfterSetScale);
  1152. addEvent(AxisClass, 'afterTickSize', GridAxis.onAfterTickSize);
  1153. addEvent(AxisClass, 'trimTicks', GridAxis.onTrimTicks);
  1154. addEvent(AxisClass, 'destroy', GridAxis.onDestroy);
  1155. };
  1156. /**
  1157. * Handle columns and getOffset.
  1158. * @private
  1159. */
  1160. GridAxis.onAfterGetOffset = function () {
  1161. var grid = this.grid;
  1162. (grid && grid.columns || []).forEach(function (column) {
  1163. column.getOffset();
  1164. });
  1165. };
  1166. /**
  1167. * @private
  1168. */
  1169. GridAxis.onAfterGetTitlePosition = function (e) {
  1170. var axis = this;
  1171. var options = axis.options;
  1172. var gridOptions = options.grid || {};
  1173. if (gridOptions.enabled === true) {
  1174. // compute anchor points for each of the title align options
  1175. var title = axis.axisTitle,
  1176. axisHeight = axis.height,
  1177. horiz = axis.horiz,
  1178. axisLeft = axis.left,
  1179. offset = axis.offset,
  1180. opposite = axis.opposite,
  1181. _a = axis.options.title,
  1182. axisTitleOptions = _a === void 0 ? {} : _a,
  1183. axisTop = axis.top,
  1184. axisWidth = axis.width;
  1185. var tickSize = axis.tickSize();
  1186. var titleWidth = title && title.getBBox().width;
  1187. var xOption = axisTitleOptions.x || 0;
  1188. var yOption = axisTitleOptions.y || 0;
  1189. var titleMargin = pick(axisTitleOptions.margin,
  1190. horiz ? 5 : 10);
  1191. var titleFontSize = axis.chart.renderer.fontMetrics(axisTitleOptions.style &&
  1192. axisTitleOptions.style.fontSize,
  1193. title).f;
  1194. var crispCorr = tickSize ? tickSize[0] / 2 : 0;
  1195. // TODO account for alignment
  1196. // the position in the perpendicular direction of the axis
  1197. var offAxis = ((horiz ? axisTop + axisHeight : axisLeft) +
  1198. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  1199. (opposite ? -1 : 1) * // so does opposite axes
  1200. crispCorr +
  1201. (axis.side === GridAxis.Side.bottom ? titleFontSize : 0));
  1202. e.titlePosition.x = horiz ?
  1203. axisLeft - titleWidth / 2 - titleMargin + xOption :
  1204. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  1205. e.titlePosition.y = horiz ?
  1206. (offAxis -
  1207. (opposite ? axisHeight : 0) +
  1208. (opposite ? titleFontSize : -titleFontSize) / 2 +
  1209. offset +
  1210. yOption) :
  1211. axisTop - titleMargin + yOption;
  1212. }
  1213. };
  1214. /**
  1215. * @private
  1216. */
  1217. GridAxis.onAfterInit = function () {
  1218. var axis = this;
  1219. var chart = axis.chart,
  1220. _a = axis.options.grid,
  1221. gridOptions = _a === void 0 ? {} : _a,
  1222. userOptions = axis.userOptions;
  1223. if (gridOptions.enabled) {
  1224. applyGridOptions(axis);
  1225. /* eslint-disable no-invalid-this */
  1226. // TODO: wrap the axis instead
  1227. wrap(axis, 'labelFormatter', function (proceed) {
  1228. var _a = this,
  1229. axis = _a.axis,
  1230. value = _a.value;
  1231. var tickPos = axis.tickPositions;
  1232. var series = (axis.isLinked ?
  1233. axis.linkedParent :
  1234. axis).series[0];
  1235. var isFirst = value === tickPos[0];
  1236. var isLast = value === tickPos[tickPos.length - 1];
  1237. var point = series && find(series.options.data,
  1238. function (p) {
  1239. return p[axis.isXAxis ? 'x' : 'y'] === value;
  1240. });
  1241. var pointCopy;
  1242. if (point && series.is('gantt')) {
  1243. // For the Gantt set point aliases to the pointCopy
  1244. // to do not change the original point
  1245. pointCopy = merge(point);
  1246. H.seriesTypes.gantt.prototype.pointClass.setGanttPointAliases(pointCopy);
  1247. }
  1248. // Make additional properties available for the
  1249. // formatter
  1250. this.isFirst = isFirst;
  1251. this.isLast = isLast;
  1252. this.point = pointCopy;
  1253. // Call original labelFormatter
  1254. return proceed.call(this);
  1255. });
  1256. /* eslint-enable no-invalid-this */
  1257. }
  1258. if (gridOptions.columns) {
  1259. var columns = axis.grid.columns = [],
  1260. columnIndex = axis.grid.columnIndex = 0;
  1261. // Handle columns, each column is a grid axis
  1262. while (++columnIndex < gridOptions.columns.length) {
  1263. var columnOptions = merge(userOptions,
  1264. gridOptions.columns[gridOptions.columns.length - columnIndex - 1], {
  1265. linkedTo: 0,
  1266. // Force to behave like category axis
  1267. type: 'category',
  1268. // Disable by default the scrollbar on the grid axis
  1269. scrollbar: {
  1270. enabled: false
  1271. }
  1272. });
  1273. delete columnOptions.grid.columns; // Prevent recursion
  1274. var column = new Axis(axis.chart,
  1275. columnOptions);
  1276. column.grid.isColumn = true;
  1277. column.grid.columnIndex = columnIndex;
  1278. // Remove column axis from chart axes array, and place it
  1279. // in the columns array.
  1280. erase(chart.axes, column);
  1281. erase(chart[axis.coll], column);
  1282. columns.push(column);
  1283. }
  1284. }
  1285. };
  1286. /**
  1287. * Draw an extra line on the far side of the outermost axis,
  1288. * creating floor/roof/wall of a grid. And some padding.
  1289. * ```
  1290. * Make this:
  1291. * (axis.min) __________________________ (axis.max)
  1292. * | | | | |
  1293. * Into this:
  1294. * (axis.min) __________________________ (axis.max)
  1295. * ___|____|____|____|____|__
  1296. * ```
  1297. * @private
  1298. */
  1299. GridAxis.onAfterRender = function () {
  1300. var _a;
  1301. var axis = this,
  1302. grid = axis.grid,
  1303. options = axis.options,
  1304. gridOptions = options.grid || {};
  1305. if (gridOptions.enabled === true) {
  1306. // @todo acutual label padding (top, bottom, left, right)
  1307. axis.maxLabelDimensions = axis.getMaxLabelDimensions(axis.ticks, axis.tickPositions);
  1308. // Remove right wall before rendering if updating
  1309. if (axis.rightWall) {
  1310. axis.rightWall.destroy();
  1311. }
  1312. /*
  1313. Draw an extra axis line on outer axes
  1314. >
  1315. Make this: |______|______|______|___
  1316. > _________________________
  1317. Into this: |______|______|______|__|
  1318. */
  1319. if (axis.grid && axis.grid.isOuterAxis() && axis.axisLine) {
  1320. var lineWidth = options.lineWidth;
  1321. if (lineWidth) {
  1322. var linePath = axis.getLinePath(lineWidth),
  1323. startPoint = linePath[0],
  1324. endPoint = linePath[1],
  1325. // Negate distance if top or left axis
  1326. // Subtract 1px to draw the line at the end of the tick
  1327. tickLength = (axis.tickSize('tick') || [1])[0],
  1328. distance = (tickLength - 1) * ((axis.side === GridAxis.Side.top ||
  1329. axis.side === GridAxis.Side.left) ? -1 : 1);
  1330. // If axis is horizontal, reposition line path vertically
  1331. if (startPoint[0] === 'M' && endPoint[0] === 'L') {
  1332. if (axis.horiz) {
  1333. startPoint[2] += distance;
  1334. endPoint[2] += distance;
  1335. }
  1336. else {
  1337. startPoint[1] += distance;
  1338. endPoint[1] += distance;
  1339. }
  1340. }
  1341. // If it doesn't exist, add an upper and lower border
  1342. // for the vertical grid axis.
  1343. if (!axis.horiz && axis.chart.marginRight) {
  1344. var upperBorderStartPoint = startPoint, upperBorderEndPoint = ['L', axis.left, startPoint[2]], upperBorderPath = [upperBorderStartPoint, upperBorderEndPoint], lowerBorderEndPoint = ['L', axis.chart.chartWidth - axis.chart.marginRight, axis.toPixels(axis.max + axis.tickmarkOffset)], lowerBorderStartPoint = ['M', endPoint[1], axis.toPixels(axis.max + axis.tickmarkOffset)], lowerBorderPath = [lowerBorderStartPoint, lowerBorderEndPoint];
  1345. if (!axis.grid.upperBorder && axis.min % 1 !== 0) {
  1346. axis.grid.upperBorder = axis.grid.renderBorder(upperBorderPath);
  1347. }
  1348. if (axis.grid.upperBorder) {
  1349. axis.grid.upperBorder.animate({
  1350. d: upperBorderPath
  1351. });
  1352. }
  1353. if (!axis.grid.lowerBorder && axis.max % 1 !== 0) {
  1354. axis.grid.lowerBorder = axis.grid.renderBorder(lowerBorderPath);
  1355. }
  1356. if (axis.grid.lowerBorder) {
  1357. axis.grid.lowerBorder.animate({
  1358. d: lowerBorderPath
  1359. });
  1360. }
  1361. }
  1362. // Render an extra line parallel to the existing axes,
  1363. // to close the grid.
  1364. if (!axis.grid.axisLineExtra) {
  1365. axis.grid.axisLineExtra = axis.grid.renderBorder(linePath);
  1366. }
  1367. else {
  1368. axis.grid.axisLineExtra.animate({
  1369. d: linePath
  1370. });
  1371. }
  1372. // show or hide the line depending on
  1373. // options.showEmpty
  1374. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  1375. }
  1376. }
  1377. (grid && grid.columns || []).forEach(function (column) {
  1378. column.render();
  1379. });
  1380. // Manipulate the tick mark visibility
  1381. // based on the axis.max- allows smooth scrolling.
  1382. if (!axis.horiz && axis.chart.hasRendered && (axis.scrollbar || ((_a = axis.linkedParent) === null || _a === void 0 ? void 0 : _a.scrollbar))) {
  1383. var max = axis.max,
  1384. min = axis.min,
  1385. tickmarkOffset = axis.tickmarkOffset,
  1386. lastTick = axis.tickPositions[axis.tickPositions.length - 1],
  1387. firstTick = axis.tickPositions[0];
  1388. // Hide/show firts tick label.
  1389. if (min - firstTick > tickmarkOffset) {
  1390. axis.ticks[firstTick].label.hide();
  1391. }
  1392. else {
  1393. axis.ticks[firstTick].label.show();
  1394. }
  1395. // Hide/show last tick mark/label.
  1396. if (lastTick - max > tickmarkOffset) {
  1397. axis.ticks[lastTick].label.hide();
  1398. }
  1399. else {
  1400. axis.ticks[lastTick].label.show();
  1401. }
  1402. if (lastTick - max < tickmarkOffset && lastTick - max > 0 && axis.ticks[lastTick].isLast) {
  1403. axis.ticks[lastTick].mark.hide();
  1404. }
  1405. else if (axis.ticks[lastTick - 1]) {
  1406. axis.ticks[lastTick - 1].mark.show();
  1407. }
  1408. }
  1409. }
  1410. };
  1411. /**
  1412. * @private
  1413. */
  1414. GridAxis.onAfterSetAxisTranslation = function () {
  1415. var _a;
  1416. var axis = this;
  1417. var tickInfo = axis.tickPositions && axis.tickPositions.info;
  1418. var options = axis.options;
  1419. var gridOptions = options.grid || {};
  1420. var userLabels = axis.userOptions.labels || {};
  1421. // Fire this only for the Gantt type chart, #14868.
  1422. if (gridOptions.enabled) {
  1423. if (axis.horiz) {
  1424. axis.series.forEach(function (series) {
  1425. series.options.pointRange = 0;
  1426. });
  1427. // Lower level time ticks, like hours or minutes, represent
  1428. // points in time and not ranges. These should be aligned
  1429. // left in the grid cell by default. The same applies to
  1430. // years of higher order.
  1431. if (tickInfo &&
  1432. options.dateTimeLabelFormats &&
  1433. options.labels &&
  1434. !defined(userLabels.align) &&
  1435. (options.dateTimeLabelFormats[tickInfo.unitName].range === false ||
  1436. tickInfo.count > 1 // years
  1437. )) {
  1438. options.labels.align = 'left';
  1439. if (!defined(userLabels.x)) {
  1440. options.labels.x = 3;
  1441. }
  1442. }
  1443. }
  1444. else {
  1445. // Don't trim ticks which not in min/max range but
  1446. // they are still in the min/max plus tickInterval.
  1447. if (this.options.type !== 'treegrid' && ((_a = axis.grid) === null || _a === void 0 ? void 0 : _a.columns)) {
  1448. this.minPointOffset = this.tickInterval;
  1449. }
  1450. }
  1451. }
  1452. };
  1453. /**
  1454. * Creates a left and right wall on horizontal axes:
  1455. * - Places leftmost tick at the start of the axis, to create a left
  1456. * wall
  1457. * - Ensures that the rightmost tick is at the end of the axis, to
  1458. * create a right wall.
  1459. * @private
  1460. */
  1461. GridAxis.onAfterSetOptions = function (e) {
  1462. var options = this.options,
  1463. userOptions = e.userOptions,
  1464. gridAxisOptions,
  1465. gridOptions = ((options && isObject(options.grid)) ? options.grid : {});
  1466. if (gridOptions.enabled === true) {
  1467. // Merge the user options into default grid axis options so
  1468. // that when a user option is set, it takes presedence.
  1469. gridAxisOptions = merge(true, {
  1470. className: ('highcharts-grid-axis ' + (userOptions.className || '')),
  1471. dateTimeLabelFormats: {
  1472. hour: {
  1473. list: ['%H:%M', '%H']
  1474. },
  1475. day: {
  1476. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  1477. },
  1478. week: {
  1479. list: ['Week %W', 'W%W']
  1480. },
  1481. month: {
  1482. list: ['%B', '%b', '%o']
  1483. }
  1484. },
  1485. grid: {
  1486. borderWidth: 1
  1487. },
  1488. labels: {
  1489. padding: 2,
  1490. style: {
  1491. fontSize: '13px'
  1492. }
  1493. },
  1494. margin: 0,
  1495. title: {
  1496. text: null,
  1497. reserveSpace: false,
  1498. rotation: 0
  1499. },
  1500. // In a grid axis, only allow one unit of certain types,
  1501. // for example we shouln't have one grid cell spanning
  1502. // two days.
  1503. units: [[
  1504. 'millisecond',
  1505. [1, 10, 100]
  1506. ], [
  1507. 'second',
  1508. [1, 10]
  1509. ], [
  1510. 'minute',
  1511. [1, 5, 15]
  1512. ], [
  1513. 'hour',
  1514. [1, 6]
  1515. ], [
  1516. 'day',
  1517. [1]
  1518. ], [
  1519. 'week',
  1520. [1]
  1521. ], [
  1522. 'month',
  1523. [1]
  1524. ], [
  1525. 'year',
  1526. null
  1527. ]]
  1528. }, userOptions);
  1529. // X-axis specific options
  1530. if (this.coll === 'xAxis') {
  1531. // For linked axes, tickPixelInterval is used only if
  1532. // the tickPositioner below doesn't run or returns
  1533. // undefined (like multiple years)
  1534. if (defined(userOptions.linkedTo) &&
  1535. !defined(userOptions.tickPixelInterval)) {
  1536. gridAxisOptions.tickPixelInterval = 350;
  1537. }
  1538. // For the secondary grid axis, use the primary axis'
  1539. // tick intervals and return ticks one level higher.
  1540. if (
  1541. // Check for tick pixel interval in options
  1542. !defined(userOptions.tickPixelInterval) &&
  1543. // Only for linked axes
  1544. defined(userOptions.linkedTo) &&
  1545. !defined(userOptions.tickPositioner) &&
  1546. !defined(userOptions.tickInterval)) {
  1547. gridAxisOptions.tickPositioner = function (min, max) {
  1548. var parentInfo = (this.linkedParent &&
  1549. this.linkedParent.tickPositions &&
  1550. this.linkedParent.tickPositions.info);
  1551. if (parentInfo) {
  1552. var unitIdx,
  1553. count,
  1554. unitName,
  1555. i,
  1556. units = gridAxisOptions.units,
  1557. unitRange;
  1558. for (i = 0; i < units.length; i++) {
  1559. if (units[i][0] ===
  1560. parentInfo.unitName) {
  1561. unitIdx = i;
  1562. break;
  1563. }
  1564. }
  1565. // Get the first allowed count on the next
  1566. // unit.
  1567. if (units[unitIdx + 1]) {
  1568. unitName = units[unitIdx + 1][0];
  1569. count =
  1570. (units[unitIdx + 1][1] || [1])[0];
  1571. // In case the base X axis shows years, make
  1572. // the secondary axis show ten times the
  1573. // years (#11427)
  1574. }
  1575. else if (parentInfo.unitName === 'year') {
  1576. unitName = 'year';
  1577. count = parentInfo.count * 10;
  1578. }
  1579. unitRange = timeUnits[unitName];
  1580. this.tickInterval = unitRange * count;
  1581. return this.getTimeTicks({
  1582. unitRange: unitRange,
  1583. count: count,
  1584. unitName: unitName
  1585. }, min, max, this.options.startOfWeek);
  1586. }
  1587. };
  1588. }
  1589. }
  1590. // Now merge the combined options into the axis options
  1591. merge(true, this.options, gridAxisOptions);
  1592. if (this.horiz) {
  1593. /* _________________________
  1594. Make this: ___|_____|_____|_____|__|
  1595. ^ ^
  1596. _________________________
  1597. Into this: |_____|_____|_____|_____|
  1598. ^ ^ */
  1599. options.minPadding = pick(userOptions.minPadding, 0);
  1600. options.maxPadding = pick(userOptions.maxPadding, 0);
  1601. }
  1602. // If borderWidth is set, then use its value for tick and
  1603. // line width.
  1604. if (isNumber(options.grid.borderWidth)) {
  1605. options.tickWidth = options.lineWidth = gridOptions.borderWidth;
  1606. }
  1607. }
  1608. };
  1609. /**
  1610. * @private
  1611. */
  1612. GridAxis.onAfterSetOptions2 = function (e) {
  1613. var axis = this;
  1614. var userOptions = e.userOptions;
  1615. var gridOptions = userOptions && userOptions.grid || {};
  1616. var columns = gridOptions.columns;
  1617. // Add column options to the parent axis. Children has their column
  1618. // options set on init in onGridAxisAfterInit.
  1619. if (gridOptions.enabled && columns) {
  1620. merge(true, axis.options, columns[columns.length - 1]);
  1621. }
  1622. };
  1623. /**
  1624. * Handle columns and setScale.
  1625. * @private
  1626. */
  1627. GridAxis.onAfterSetScale = function () {
  1628. var axis = this;
  1629. (axis.grid.columns || []).forEach(function (column) {
  1630. column.setScale();
  1631. });
  1632. };
  1633. /**
  1634. * Draw vertical axis ticks extra long to create cell floors and roofs.
  1635. * Overrides the tickLength for vertical axes.
  1636. * @private
  1637. */
  1638. GridAxis.onAfterTickSize = function (e) {
  1639. var defaultLeftAxisOptions = Axis.defaultLeftAxisOptions;
  1640. var _a = this,
  1641. horiz = _a.horiz,
  1642. maxLabelDimensions = _a.maxLabelDimensions,
  1643. _b = _a.options.grid,
  1644. gridOptions = _b === void 0 ? {} : _b;
  1645. if (gridOptions.enabled && maxLabelDimensions) {
  1646. var labelPadding = (Math.abs(defaultLeftAxisOptions.labels.x) * 2);
  1647. var distance = horiz ?
  1648. gridOptions.cellHeight || labelPadding + maxLabelDimensions.height :
  1649. labelPadding + maxLabelDimensions.width;
  1650. if (isArray(e.tickSize)) {
  1651. e.tickSize[0] = distance;
  1652. }
  1653. else {
  1654. e.tickSize = [distance, 0];
  1655. }
  1656. }
  1657. };
  1658. /**
  1659. * @private
  1660. */
  1661. GridAxis.onDestroy = function (e) {
  1662. var grid = this.grid;
  1663. (grid.columns || []).forEach(function (column) {
  1664. column.destroy(e.keepEvents);
  1665. });
  1666. grid.columns = void 0;
  1667. };
  1668. /**
  1669. * Wraps axis init to draw cell walls on vertical axes.
  1670. * @private
  1671. */
  1672. GridAxis.onInit = function (e) {
  1673. var axis = this;
  1674. var userOptions = e.userOptions || {};
  1675. var gridOptions = userOptions.grid || {};
  1676. if (gridOptions.enabled && defined(gridOptions.borderColor)) {
  1677. userOptions.tickColor = userOptions.lineColor = gridOptions.borderColor;
  1678. }
  1679. if (!axis.grid) {
  1680. axis.grid = new GridAxisAdditions(axis);
  1681. }
  1682. };
  1683. /**
  1684. * Makes tick labels which are usually ignored in a linked axis
  1685. * displayed if they are within range of linkedParent.min.
  1686. * ```
  1687. * _____________________________
  1688. * | | | | |
  1689. * Make this: | | 2 | 3 | 4 |
  1690. * |___|_______|_______|_______|
  1691. * ^
  1692. * _____________________________
  1693. * | | | | |
  1694. * Into this: | 1 | 2 | 3 | 4 |
  1695. * |___|_______|_______|_______|
  1696. * ^
  1697. * ```
  1698. * @private
  1699. * @todo Does this function do what the drawing says? Seems to affect
  1700. * ticks and not the labels directly?
  1701. */
  1702. GridAxis.onTrimTicks = function () {
  1703. var axis = this;
  1704. var options = axis.options;
  1705. var gridOptions = options.grid || {};
  1706. var categoryAxis = axis.categories;
  1707. var tickPositions = axis.tickPositions;
  1708. var firstPos = tickPositions[0];
  1709. var lastPos = tickPositions[tickPositions.length - 1];
  1710. var linkedMin = axis.linkedParent && axis.linkedParent.min;
  1711. var linkedMax = axis.linkedParent && axis.linkedParent.max;
  1712. var min = linkedMin || axis.min;
  1713. var max = linkedMax || axis.max;
  1714. var tickInterval = axis.tickInterval;
  1715. var endMoreThanMin = (firstPos < min &&
  1716. firstPos + tickInterval > min);
  1717. var startLessThanMax = (lastPos > max &&
  1718. lastPos - tickInterval < max);
  1719. if (gridOptions.enabled === true &&
  1720. !categoryAxis &&
  1721. (axis.horiz || axis.isLinked)) {
  1722. if (endMoreThanMin && !options.startOnTick) {
  1723. tickPositions[0] = min;
  1724. }
  1725. if (startLessThanMax && !options.endOnTick) {
  1726. tickPositions[tickPositions.length - 1] = max;
  1727. }
  1728. }
  1729. };
  1730. /**
  1731. * Avoid altering tickInterval when reserving space.
  1732. * @private
  1733. */
  1734. GridAxis.wrapUnsquish = function (proceed) {
  1735. var axis = this;
  1736. var _a = axis.options.grid,
  1737. gridOptions = _a === void 0 ? {} : _a;
  1738. if (gridOptions.enabled === true && axis.categories) {
  1739. return axis.tickInterval;
  1740. }
  1741. return proceed.apply(axis, argsToArray(arguments));
  1742. };
  1743. return GridAxis;
  1744. }());
  1745. (function (GridAxis) {
  1746. /**
  1747. * Enum for which side the axis is on. Maps to axis.side.
  1748. * @private
  1749. */
  1750. var Side;
  1751. (function (Side) {
  1752. Side[Side["top"] = 0] = "top";
  1753. Side[Side["right"] = 1] = "right";
  1754. Side[Side["bottom"] = 2] = "bottom";
  1755. Side[Side["left"] = 3] = "left";
  1756. })(Side = GridAxis.Side || (GridAxis.Side = {}));
  1757. })(GridAxis || (GridAxis = {}));
  1758. GridAxis.compose(Axis);
  1759. return GridAxis;
  1760. });
  1761. _registerModule(_modules, 'Core/Axis/BrokenAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Series/Series.js'], _modules['Extensions/Stacking.js'], _modules['Core/Utilities.js']], function (Axis, Series, StackItem, U) {
  1762. /* *
  1763. *
  1764. * (c) 2009-2021 Torstein Honsi
  1765. *
  1766. * License: www.highcharts.com/license
  1767. *
  1768. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1769. *
  1770. * */
  1771. var addEvent = U.addEvent,
  1772. find = U.find,
  1773. fireEvent = U.fireEvent,
  1774. isArray = U.isArray,
  1775. isNumber = U.isNumber,
  1776. pick = U.pick;
  1777. /* eslint-disable valid-jsdoc */
  1778. /**
  1779. * Provides support for broken axes.
  1780. * @private
  1781. * @class
  1782. */
  1783. var BrokenAxisAdditions = /** @class */ (function () {
  1784. /* *
  1785. *
  1786. * Constructors
  1787. *
  1788. * */
  1789. function BrokenAxisAdditions(axis) {
  1790. this.hasBreaks = false;
  1791. this.axis = axis;
  1792. }
  1793. /* *
  1794. *
  1795. * Static Functions
  1796. *
  1797. * */
  1798. /**
  1799. * @private
  1800. */
  1801. BrokenAxisAdditions.isInBreak = function (brk, val) {
  1802. var ret,
  1803. repeat = brk.repeat || Infinity,
  1804. from = brk.from,
  1805. length = brk.to - brk.from,
  1806. test = (val >= from ?
  1807. (val - from) % repeat :
  1808. repeat - ((from - val) % repeat));
  1809. if (!brk.inclusive) {
  1810. ret = test < length && test !== 0;
  1811. }
  1812. else {
  1813. ret = test <= length;
  1814. }
  1815. return ret;
  1816. };
  1817. /**
  1818. * @private
  1819. */
  1820. BrokenAxisAdditions.lin2Val = function (val) {
  1821. var axis = this;
  1822. var brokenAxis = axis.brokenAxis;
  1823. var breakArray = brokenAxis && brokenAxis.breakArray;
  1824. if (!breakArray) {
  1825. return val;
  1826. }
  1827. var nval = val,
  1828. brk,
  1829. i;
  1830. for (i = 0; i < breakArray.length; i++) {
  1831. brk = breakArray[i];
  1832. if (brk.from >= nval) {
  1833. break;
  1834. }
  1835. else if (brk.to < nval) {
  1836. nval += brk.len;
  1837. }
  1838. else if (BrokenAxisAdditions.isInBreak(brk, nval)) {
  1839. nval += brk.len;
  1840. }
  1841. }
  1842. return nval;
  1843. };
  1844. /**
  1845. * @private
  1846. */
  1847. BrokenAxisAdditions.val2Lin = function (val) {
  1848. var axis = this;
  1849. var brokenAxis = axis.brokenAxis;
  1850. var breakArray = brokenAxis && brokenAxis.breakArray;
  1851. if (!breakArray) {
  1852. return val;
  1853. }
  1854. var nval = val,
  1855. brk,
  1856. i;
  1857. for (i = 0; i < breakArray.length; i++) {
  1858. brk = breakArray[i];
  1859. if (brk.to <= val) {
  1860. nval -= brk.len;
  1861. }
  1862. else if (brk.from >= val) {
  1863. break;
  1864. }
  1865. else if (BrokenAxisAdditions.isInBreak(brk, val)) {
  1866. nval -= (val - brk.from);
  1867. break;
  1868. }
  1869. }
  1870. return nval;
  1871. };
  1872. /* *
  1873. *
  1874. * Functions
  1875. *
  1876. * */
  1877. /**
  1878. * Returns the first break found where the x is larger then break.from and
  1879. * smaller then break.to.
  1880. *
  1881. * @param {number} x
  1882. * The number which should be within a break.
  1883. *
  1884. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  1885. * The array of breaks to search within.
  1886. *
  1887. * @return {Highcharts.XAxisBreaksOptions|undefined}
  1888. * Returns the first break found that matches, returns false if no break is
  1889. * found.
  1890. */
  1891. BrokenAxisAdditions.prototype.findBreakAt = function (x, breaks) {
  1892. return find(breaks, function (b) {
  1893. return b.from < x && x < b.to;
  1894. });
  1895. };
  1896. /**
  1897. * @private
  1898. */
  1899. BrokenAxisAdditions.prototype.isInAnyBreak = function (val, testKeep) {
  1900. var brokenAxis = this;
  1901. var axis = brokenAxis.axis;
  1902. var breaks = axis.options.breaks,
  1903. i = breaks && breaks.length,
  1904. inbrk,
  1905. keep,
  1906. ret;
  1907. if (i) {
  1908. while (i--) {
  1909. if (BrokenAxisAdditions.isInBreak(breaks[i], val)) {
  1910. inbrk = true;
  1911. if (!keep) {
  1912. keep = pick(breaks[i].showPoints, !axis.isXAxis);
  1913. }
  1914. }
  1915. }
  1916. if (inbrk && testKeep) {
  1917. ret = inbrk && !keep;
  1918. }
  1919. else {
  1920. ret = inbrk;
  1921. }
  1922. }
  1923. return ret;
  1924. };
  1925. /**
  1926. * Dynamically set or unset breaks in an axis. This function in lighter than
  1927. * usin Axis.update, and it also preserves animation.
  1928. *
  1929. * @private
  1930. * @function Highcharts.Axis#setBreaks
  1931. *
  1932. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  1933. * The breaks to add. When `undefined` it removes existing breaks.
  1934. *
  1935. * @param {boolean} [redraw=true]
  1936. * Whether to redraw the chart immediately.
  1937. *
  1938. * @return {void}
  1939. */
  1940. BrokenAxisAdditions.prototype.setBreaks = function (breaks, redraw) {
  1941. var brokenAxis = this;
  1942. var axis = brokenAxis.axis;
  1943. var hasBreaks = (isArray(breaks) && !!breaks.length);
  1944. axis.isDirty = brokenAxis.hasBreaks !== hasBreaks;
  1945. brokenAxis.hasBreaks = hasBreaks;
  1946. axis.options.breaks = axis.userOptions.breaks = breaks;
  1947. axis.forceRedraw = true; // Force recalculation in setScale
  1948. // Recalculate series related to the axis.
  1949. axis.series.forEach(function (series) {
  1950. series.isDirty = true;
  1951. });
  1952. if (!hasBreaks && axis.val2lin === BrokenAxisAdditions.val2Lin) {
  1953. // Revert to prototype functions
  1954. delete axis.val2lin;
  1955. delete axis.lin2val;
  1956. }
  1957. if (hasBreaks) {
  1958. axis.userOptions.ordinal = false;
  1959. axis.lin2val = BrokenAxisAdditions.lin2Val;
  1960. axis.val2lin = BrokenAxisAdditions.val2Lin;
  1961. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  1962. // If trying to set extremes inside a break, extend min to
  1963. // after, and max to before the break ( #3857 )
  1964. if (brokenAxis.hasBreaks) {
  1965. var axisBreak,
  1966. breaks = this.options.breaks;
  1967. while ((axisBreak = brokenAxis.findBreakAt(newMin, breaks))) {
  1968. newMin = axisBreak.to;
  1969. }
  1970. while ((axisBreak = brokenAxis.findBreakAt(newMax, breaks))) {
  1971. newMax = axisBreak.from;
  1972. }
  1973. // If both min and max is within the same break.
  1974. if (newMax < newMin) {
  1975. newMax = newMin;
  1976. }
  1977. }
  1978. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  1979. };
  1980. axis.setAxisTranslation = function () {
  1981. Axis.prototype.setAxisTranslation.call(this);
  1982. brokenAxis.unitLength = null;
  1983. if (brokenAxis.hasBreaks) {
  1984. var breaks = axis.options.breaks || [],
  1985. // Temporary one:
  1986. breakArrayT = [],
  1987. breakArray = [],
  1988. length = 0,
  1989. inBrk,
  1990. repeat,
  1991. min = axis.userMin || axis.min,
  1992. max = axis.userMax || axis.max,
  1993. pointRangePadding = pick(axis.pointRangePadding, 0),
  1994. start,
  1995. i;
  1996. // Min & max check (#4247)
  1997. breaks.forEach(function (brk) {
  1998. repeat = brk.repeat || Infinity;
  1999. if (BrokenAxisAdditions.isInBreak(brk, min)) {
  2000. min +=
  2001. (brk.to % repeat) -
  2002. (min % repeat);
  2003. }
  2004. if (BrokenAxisAdditions.isInBreak(brk, max)) {
  2005. max -=
  2006. (max % repeat) -
  2007. (brk.from % repeat);
  2008. }
  2009. });
  2010. // Construct an array holding all breaks in the axis
  2011. breaks.forEach(function (brk) {
  2012. start = brk.from;
  2013. repeat = brk.repeat || Infinity;
  2014. while (start - repeat > min) {
  2015. start -= repeat;
  2016. }
  2017. while (start < min) {
  2018. start += repeat;
  2019. }
  2020. for (i = start; i < max; i += repeat) {
  2021. breakArrayT.push({
  2022. value: i,
  2023. move: 'in'
  2024. });
  2025. breakArrayT.push({
  2026. value: i + (brk.to - brk.from),
  2027. move: 'out',
  2028. size: brk.breakSize
  2029. });
  2030. }
  2031. });
  2032. breakArrayT.sort(function (a, b) {
  2033. return ((a.value === b.value) ?
  2034. ((a.move === 'in' ? 0 : 1) -
  2035. (b.move === 'in' ? 0 : 1)) :
  2036. a.value - b.value);
  2037. });
  2038. // Simplify the breaks
  2039. inBrk = 0;
  2040. start = min;
  2041. breakArrayT.forEach(function (brk) {
  2042. inBrk += (brk.move === 'in' ? 1 : -1);
  2043. if (inBrk === 1 && brk.move === 'in') {
  2044. start = brk.value;
  2045. }
  2046. if (inBrk === 0) {
  2047. breakArray.push({
  2048. from: start,
  2049. to: brk.value,
  2050. len: brk.value - start - (brk.size || 0)
  2051. });
  2052. length += brk.value - start - (brk.size || 0);
  2053. }
  2054. });
  2055. /**
  2056. * HC <= 8 backwards compatibility, used by demo samples.
  2057. * @deprecated
  2058. * @private
  2059. * @requires modules/broken-axis
  2060. */
  2061. axis.breakArray = brokenAxis.breakArray = breakArray;
  2062. // Used with staticScale, and below the actual axis length,
  2063. // when breaks are substracted.
  2064. brokenAxis.unitLength = max - min - length + pointRangePadding;
  2065. fireEvent(axis, 'afterBreaks');
  2066. if (axis.staticScale) {
  2067. axis.transA = axis.staticScale;
  2068. }
  2069. else if (brokenAxis.unitLength) {
  2070. axis.transA *=
  2071. (max - axis.min + pointRangePadding) /
  2072. brokenAxis.unitLength;
  2073. }
  2074. if (pointRangePadding) {
  2075. axis.minPixelPadding =
  2076. axis.transA * axis.minPointOffset;
  2077. }
  2078. axis.min = min;
  2079. axis.max = max;
  2080. }
  2081. };
  2082. }
  2083. if (pick(redraw, true)) {
  2084. axis.chart.redraw();
  2085. }
  2086. };
  2087. return BrokenAxisAdditions;
  2088. }());
  2089. /**
  2090. * Axis with support of broken data rows.
  2091. * @private
  2092. * @class
  2093. */
  2094. var BrokenAxis = /** @class */ (function () {
  2095. function BrokenAxis() {
  2096. }
  2097. /**
  2098. * Adds support for broken axes.
  2099. * @private
  2100. */
  2101. BrokenAxis.compose = function (AxisClass, SeriesClass) {
  2102. AxisClass.keepProps.push('brokenAxis');
  2103. var seriesProto = Series.prototype;
  2104. /**
  2105. * @private
  2106. */
  2107. seriesProto.drawBreaks = function (axis, keys) {
  2108. var series = this,
  2109. points = series.points,
  2110. breaks,
  2111. threshold,
  2112. eventName,
  2113. y;
  2114. if (axis && // #5950
  2115. axis.brokenAxis &&
  2116. axis.brokenAxis.hasBreaks) {
  2117. var brokenAxis_1 = axis.brokenAxis;
  2118. keys.forEach(function (key) {
  2119. breaks = brokenAxis_1 && brokenAxis_1.breakArray || [];
  2120. threshold = axis.isXAxis ?
  2121. axis.min :
  2122. pick(series.options.threshold, axis.min);
  2123. points.forEach(function (point) {
  2124. y = pick(point['stack' + key.toUpperCase()], point[key]);
  2125. breaks.forEach(function (brk) {
  2126. if (isNumber(threshold) && isNumber(y)) {
  2127. eventName = false;
  2128. if ((threshold < brk.from && y > brk.to) ||
  2129. (threshold > brk.from && y < brk.from)) {
  2130. eventName = 'pointBreak';
  2131. }
  2132. else if ((threshold < brk.from && y > brk.from && y < brk.to) ||
  2133. (threshold > brk.from && y > brk.to && y < brk.from)) {
  2134. eventName = 'pointInBreak';
  2135. }
  2136. if (eventName) {
  2137. fireEvent(axis, eventName, { point: point, brk: brk });
  2138. }
  2139. }
  2140. });
  2141. });
  2142. });
  2143. }
  2144. };
  2145. /**
  2146. * Extend getGraphPath by identifying gaps in the data so that we can
  2147. * draw a gap in the line or area. This was moved from ordinal axis
  2148. * module to broken axis module as of #5045.
  2149. *
  2150. * @private
  2151. * @function Highcharts.Series#gappedPath
  2152. *
  2153. * @return {Highcharts.SVGPathArray}
  2154. * Gapped path
  2155. */
  2156. seriesProto.gappedPath = function () {
  2157. var currentDataGrouping = this.currentDataGrouping,
  2158. groupingSize = currentDataGrouping && currentDataGrouping.gapSize,
  2159. gapSize = this.options.gapSize,
  2160. points = this.points.slice(),
  2161. i = points.length - 1,
  2162. yAxis = this.yAxis,
  2163. stack;
  2164. /**
  2165. * Defines when to display a gap in the graph, together with the
  2166. * [gapUnit](plotOptions.series.gapUnit) option.
  2167. *
  2168. * In case when `dataGrouping` is enabled, points can be grouped
  2169. * into a larger time span. This can make the grouped points to have
  2170. * a greater distance than the absolute value of `gapSize` property,
  2171. * which will result in disappearing graph completely. To prevent
  2172. * this situation the mentioned distance between grouped points is
  2173. * used instead of previously defined `gapSize`.
  2174. *
  2175. * In practice, this option is most often used to visualize gaps in
  2176. * time series. In a stock chart, intraday data is available for
  2177. * daytime hours, while gaps will appear in nights and weekends.
  2178. *
  2179. * @see [gapUnit](plotOptions.series.gapUnit)
  2180. * @see [xAxis.breaks](#xAxis.breaks)
  2181. *
  2182. * @sample {highstock} stock/plotoptions/series-gapsize/
  2183. * Setting the gap size to 2 introduces gaps for weekends
  2184. * in daily datasets.
  2185. *
  2186. * @type {number}
  2187. * @default 0
  2188. * @product highstock
  2189. * @requires modules/broken-axis
  2190. * @apioption plotOptions.series.gapSize
  2191. */
  2192. /**
  2193. * Together with [gapSize](plotOptions.series.gapSize), this option
  2194. * defines where to draw gaps in the graph.
  2195. *
  2196. * When the `gapUnit` is `"relative"` (default), a gap size of 5
  2197. * means that if the distance between two points is greater than
  2198. * 5 times that of the two closest points, the graph will be broken.
  2199. *
  2200. * When the `gapUnit` is `"value"`, the gap is based on absolute
  2201. * axis values, which on a datetime axis is milliseconds. This also
  2202. * applies to the navigator series that inherits gap options from
  2203. * the base series.
  2204. *
  2205. * @see [gapSize](plotOptions.series.gapSize)
  2206. *
  2207. * @type {string}
  2208. * @default relative
  2209. * @since 5.0.13
  2210. * @product highstock
  2211. * @validvalue ["relative", "value"]
  2212. * @requires modules/broken-axis
  2213. * @apioption plotOptions.series.gapUnit
  2214. */
  2215. if (gapSize && i > 0) { // #5008
  2216. // Gap unit is relative
  2217. if (this.options.gapUnit !== 'value') {
  2218. gapSize *= this.basePointRange;
  2219. }
  2220. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  2221. if (groupingSize &&
  2222. groupingSize > gapSize &&
  2223. // Except when DG is forced (e.g. from other series)
  2224. // and has lower granularity than actual points (#11351)
  2225. groupingSize >= this.basePointRange) {
  2226. gapSize = groupingSize;
  2227. }
  2228. // extension for ordinal breaks
  2229. var current = void 0,
  2230. next = void 0;
  2231. while (i--) {
  2232. // Reassign next if it is not visible
  2233. if (!(next && next.visible !== false)) {
  2234. next = points[i + 1];
  2235. }
  2236. current = points[i];
  2237. // Skip iteration if one of the points is not visible
  2238. if (next.visible === false || current.visible === false) {
  2239. continue;
  2240. }
  2241. if (next.x - current.x > gapSize) {
  2242. var xRange = (current.x + next.x) / 2;
  2243. points.splice(// insert after this one
  2244. i + 1, 0, {
  2245. isNull: true,
  2246. x: xRange
  2247. });
  2248. // For stacked chart generate empty stack items, #6546
  2249. if (yAxis.stacking && this.options.stacking) {
  2250. stack = yAxis.stacking.stacks[this.stackKey][xRange] =
  2251. new StackItem(yAxis, yAxis.options
  2252. .stackLabels, false, xRange, this.stack);
  2253. stack.total = 0;
  2254. }
  2255. }
  2256. // Assign current to next for the upcoming iteration
  2257. next = current;
  2258. }
  2259. }
  2260. // Call base method
  2261. return this.getGraphPath(points);
  2262. };
  2263. /* eslint-disable no-invalid-this */
  2264. addEvent(AxisClass, 'init', function () {
  2265. var axis = this;
  2266. if (!axis.brokenAxis) {
  2267. axis.brokenAxis = new BrokenAxisAdditions(axis);
  2268. }
  2269. });
  2270. addEvent(AxisClass, 'afterInit', function () {
  2271. if (typeof this.brokenAxis !== 'undefined') {
  2272. this.brokenAxis.setBreaks(this.options.breaks, false);
  2273. }
  2274. });
  2275. addEvent(AxisClass, 'afterSetTickPositions', function () {
  2276. var axis = this;
  2277. var brokenAxis = axis.brokenAxis;
  2278. if (brokenAxis &&
  2279. brokenAxis.hasBreaks) {
  2280. var tickPositions = this.tickPositions,
  2281. info = this.tickPositions.info,
  2282. newPositions = [],
  2283. i;
  2284. for (i = 0; i < tickPositions.length; i++) {
  2285. if (!brokenAxis.isInAnyBreak(tickPositions[i])) {
  2286. newPositions.push(tickPositions[i]);
  2287. }
  2288. }
  2289. this.tickPositions = newPositions;
  2290. this.tickPositions.info = info;
  2291. }
  2292. });
  2293. // Force Axis to be not-ordinal when breaks are defined
  2294. addEvent(AxisClass, 'afterSetOptions', function () {
  2295. if (this.brokenAxis && this.brokenAxis.hasBreaks) {
  2296. this.options.ordinal = false;
  2297. }
  2298. });
  2299. addEvent(SeriesClass, 'afterGeneratePoints', function () {
  2300. var _a = this,
  2301. isDirty = _a.isDirty,
  2302. connectNulls = _a.options.connectNulls,
  2303. points = _a.points,
  2304. xAxis = _a.xAxis,
  2305. yAxis = _a.yAxis;
  2306. // Set, or reset visibility of the points. Axis.setBreaks marks the
  2307. // series as isDirty
  2308. if (isDirty) {
  2309. var i = points.length;
  2310. while (i--) {
  2311. var point = points[i];
  2312. // Respect nulls inside the break (#4275)
  2313. var nullGap = point.y === null && connectNulls === false;
  2314. var isPointInBreak = (!nullGap && ((xAxis &&
  2315. xAxis.brokenAxis &&
  2316. xAxis.brokenAxis.isInAnyBreak(point.x,
  2317. true)) || (yAxis &&
  2318. yAxis.brokenAxis &&
  2319. yAxis.brokenAxis.isInAnyBreak(point.y,
  2320. true))));
  2321. // Set point.visible if in any break.
  2322. // If not in break, reset visible to original value.
  2323. point.visible = isPointInBreak ?
  2324. false :
  2325. point.options.visible !== false;
  2326. }
  2327. }
  2328. });
  2329. addEvent(SeriesClass, 'afterRender', function drawPointsWrapped() {
  2330. this.drawBreaks(this.xAxis, ['x']);
  2331. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  2332. });
  2333. };
  2334. return BrokenAxis;
  2335. }());
  2336. BrokenAxis.compose(Axis, Series); // @todo remove automatism
  2337. return BrokenAxis;
  2338. });
  2339. _registerModule(_modules, 'Core/Axis/TreeGridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/Tick.js'], _modules['Gantt/Tree.js'], _modules['Core/Axis/TreeGridTick.js'], _modules['Mixins/TreeSeries.js'], _modules['Core/Utilities.js']], function (Axis, Tick, Tree, TreeGridTick, mixinTreeSeries, U) {
  2340. /* *
  2341. *
  2342. * (c) 2016 Highsoft AS
  2343. * Authors: Jon Arild Nygard
  2344. *
  2345. * License: www.highcharts.com/license
  2346. *
  2347. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2348. *
  2349. * */
  2350. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  2351. var addEvent = U.addEvent,
  2352. find = U.find,
  2353. fireEvent = U.fireEvent,
  2354. isArray = U.isArray,
  2355. isNumber = U.isNumber,
  2356. isObject = U.isObject,
  2357. isString = U.isString,
  2358. merge = U.merge,
  2359. pick = U.pick,
  2360. wrap = U.wrap;
  2361. /**
  2362. * @private
  2363. */
  2364. var TreeGridAxis;
  2365. (function (TreeGridAxis) {
  2366. /* *
  2367. *
  2368. * Interfaces
  2369. *
  2370. * */
  2371. /* *
  2372. *
  2373. * Variables
  2374. *
  2375. * */
  2376. var applied = false;
  2377. /* *
  2378. *
  2379. * Functions
  2380. *
  2381. * */
  2382. /**
  2383. * @private
  2384. */
  2385. function compose(AxisClass) {
  2386. if (!applied) {
  2387. wrap(AxisClass.prototype, 'generateTick', wrapGenerateTick);
  2388. wrap(AxisClass.prototype, 'getMaxLabelDimensions', wrapGetMaxLabelDimensions);
  2389. wrap(AxisClass.prototype, 'init', wrapInit);
  2390. wrap(AxisClass.prototype, 'setTickInterval', wrapSetTickInterval);
  2391. TreeGridTick.compose(Tick);
  2392. applied = true;
  2393. }
  2394. }
  2395. TreeGridAxis.compose = compose;
  2396. /**
  2397. * @private
  2398. */
  2399. function getBreakFromNode(node, max) {
  2400. var from = node.collapseStart || 0,
  2401. to = node.collapseEnd || 0;
  2402. // In broken-axis, the axis.max is minimized until it is not within a
  2403. // break. Therefore, if break.to is larger than axis.max, the axis.to
  2404. // should not add the 0.5 axis.tickMarkOffset, to avoid adding a break
  2405. // larger than axis.max.
  2406. // TODO consider simplifying broken-axis and this might solve itself
  2407. if (to >= max) {
  2408. from -= 0.5;
  2409. }
  2410. return {
  2411. from: from,
  2412. to: to,
  2413. showPoints: false
  2414. };
  2415. }
  2416. /**
  2417. * Creates a tree structure of the data, and the treegrid. Calculates
  2418. * categories, and y-values of points based on the tree.
  2419. *
  2420. * @private
  2421. * @function getTreeGridFromData
  2422. *
  2423. * @param {Array<Highcharts.GanttPointOptions>} data
  2424. * All the data points to display in the axis.
  2425. *
  2426. * @param {boolean} uniqueNames
  2427. * Wether or not the data node with the same name should share grid cell. If
  2428. * true they do share cell. False by default.
  2429. *
  2430. * @param {number} numberOfSeries
  2431. *
  2432. * @return {object}
  2433. * Returns an object containing categories, mapOfIdToNode,
  2434. * mapOfPosToGridNode, and tree.
  2435. *
  2436. * @todo There should be only one point per line.
  2437. * @todo It should be optional to have one category per point, or merge
  2438. * cells
  2439. * @todo Add unit-tests.
  2440. */
  2441. function getTreeGridFromData(data, uniqueNames, numberOfSeries) {
  2442. var categories = [],
  2443. collapsedNodes = [],
  2444. mapOfIdToNode = {},
  2445. mapOfPosToGridNode = {},
  2446. posIterator = -1,
  2447. uniqueNamesEnabled = typeof uniqueNames === 'boolean' ? uniqueNames : false,
  2448. tree;
  2449. // Build the tree from the series data.
  2450. var treeParams = {
  2451. // After the children has been created.
  2452. after: function (node) {
  2453. var gridNode = mapOfPosToGridNode[node.pos],
  2454. height = 0,
  2455. descendants = 0;
  2456. gridNode.children.forEach(function (child) {
  2457. descendants += (child.descendants || 0) + 1;
  2458. height = Math.max((child.height || 0) + 1, height);
  2459. });
  2460. gridNode.descendants = descendants;
  2461. gridNode.height = height;
  2462. if (gridNode.collapsed) {
  2463. collapsedNodes.push(gridNode);
  2464. }
  2465. },
  2466. // Before the children has been created.
  2467. before: function (node) {
  2468. var data = isObject(node.data,
  2469. true) ? node.data : {},
  2470. name = isString(data.name) ? data.name : '',
  2471. parentNode = mapOfIdToNode[node.parent],
  2472. parentGridNode = (isObject(parentNode,
  2473. true) ?
  2474. mapOfPosToGridNode[parentNode.pos] :
  2475. null),
  2476. hasSameName = function (x) {
  2477. return x.name === name;
  2478. }, gridNode, pos;
  2479. // If not unique names, look for sibling node with the same name
  2480. if (uniqueNamesEnabled &&
  2481. isObject(parentGridNode, true) &&
  2482. !!(gridNode = find(parentGridNode.children, hasSameName))) {
  2483. // If there is a gridNode with the same name, reuse position
  2484. pos = gridNode.pos;
  2485. // Add data node to list of nodes in the grid node.
  2486. gridNode.nodes.push(node);
  2487. }
  2488. else {
  2489. // If it is a new grid node, increment position.
  2490. pos = posIterator++;
  2491. }
  2492. // Add new grid node to map.
  2493. if (!mapOfPosToGridNode[pos]) {
  2494. mapOfPosToGridNode[pos] = gridNode = {
  2495. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  2496. name: name,
  2497. id: data.id,
  2498. nodes: [node],
  2499. children: [],
  2500. pos: pos
  2501. };
  2502. // If not root, then add name to categories.
  2503. if (pos !== -1) {
  2504. categories.push(name);
  2505. }
  2506. // Add name to list of children.
  2507. if (isObject(parentGridNode, true)) {
  2508. parentGridNode.children.push(gridNode);
  2509. }
  2510. }
  2511. // Add data node to map
  2512. if (isString(node.id)) {
  2513. mapOfIdToNode[node.id] = node;
  2514. }
  2515. // If one of the points are collapsed, then start the grid node
  2516. // in collapsed state.
  2517. if (gridNode &&
  2518. data.collapsed === true) {
  2519. gridNode.collapsed = true;
  2520. }
  2521. // Assign pos to data node
  2522. node.pos = pos;
  2523. }
  2524. };
  2525. var updateYValuesAndTickPos = function (map,
  2526. numberOfSeries) {
  2527. var setValues = function (gridNode,
  2528. start,
  2529. result) {
  2530. var nodes = gridNode.nodes,
  2531. end = start + (start === -1 ? 0 : numberOfSeries - 1),
  2532. diff = (end - start) / 2,
  2533. padding = 0.5,
  2534. pos = start + diff;
  2535. nodes.forEach(function (node) {
  2536. var data = node.data;
  2537. if (isObject(data, true)) {
  2538. // Update point
  2539. data.y = start + (data.seriesIndex || 0);
  2540. // Remove the property once used
  2541. delete data.seriesIndex;
  2542. }
  2543. node.pos = pos;
  2544. });
  2545. result[pos] = gridNode;
  2546. gridNode.pos = pos;
  2547. gridNode.tickmarkOffset = diff + padding;
  2548. gridNode.collapseStart = end + padding;
  2549. gridNode.children.forEach(function (child) {
  2550. setValues(child, end + 1, result);
  2551. end = (child.collapseEnd || 0) - padding;
  2552. });
  2553. // Set collapseEnd to the end of the last child node.
  2554. gridNode.collapseEnd = end + padding;
  2555. return result;
  2556. };
  2557. return setValues(map['-1'], -1, {});
  2558. };
  2559. // Create tree from data
  2560. tree = Tree.getTree(data, treeParams);
  2561. // Update y values of data, and set calculate tick positions.
  2562. mapOfPosToGridNode = updateYValuesAndTickPos(mapOfPosToGridNode, numberOfSeries);
  2563. // Return the resulting data.
  2564. return {
  2565. categories: categories,
  2566. mapOfIdToNode: mapOfIdToNode,
  2567. mapOfPosToGridNode: mapOfPosToGridNode,
  2568. collapsedNodes: collapsedNodes,
  2569. tree: tree
  2570. };
  2571. }
  2572. /**
  2573. * Builds the tree of categories and calculates its positions.
  2574. * @private
  2575. * @param {object} e Event object
  2576. * @param {object} e.target The chart instance which the event was fired on.
  2577. * @param {object[]} e.target.axes The axes of the chart.
  2578. */
  2579. function onBeforeRender(e) {
  2580. var chart = e.target,
  2581. axes = chart.axes;
  2582. axes.filter(function (axis) {
  2583. return axis.options.type === 'treegrid';
  2584. }).forEach(function (axis) {
  2585. var options = axis.options || {},
  2586. labelOptions = options.labels,
  2587. uniqueNames = options.uniqueNames,
  2588. numberOfSeries = 0,
  2589. isDirty,
  2590. data,
  2591. treeGrid,
  2592. max = options.max;
  2593. // Check whether any of series is rendering for the first time,
  2594. // visibility has changed, or its data is dirty,
  2595. // and only then update. #10570, #10580
  2596. // Also check if mapOfPosToGridNode exists. #10887
  2597. isDirty = (!axis.treeGrid.mapOfPosToGridNode ||
  2598. axis.series.some(function (series) {
  2599. return !series.hasRendered ||
  2600. series.isDirtyData ||
  2601. series.isDirty;
  2602. }));
  2603. if (isDirty) {
  2604. // Concatenate data from all series assigned to this axis.
  2605. data = axis.series.reduce(function (arr, s) {
  2606. if (s.visible) {
  2607. // Push all data to array
  2608. (s.options.data || []).forEach(function (data) {
  2609. // For using keys - rebuild the data structure
  2610. if (s.options.keys && s.options.keys.length) {
  2611. data = s.pointClass.prototype.optionsToObject.call({ series: s }, data);
  2612. s.pointClass.setGanttPointAliases(data);
  2613. }
  2614. if (isObject(data, true)) {
  2615. // Set series index on data. Removed again
  2616. // after use.
  2617. data.seriesIndex = numberOfSeries;
  2618. arr.push(data);
  2619. }
  2620. });
  2621. // Increment series index
  2622. if (uniqueNames === true) {
  2623. numberOfSeries++;
  2624. }
  2625. }
  2626. return arr;
  2627. }, []);
  2628. // If max is higher than set data - add a
  2629. // dummy data to render categories #10779
  2630. if (max && data.length < max) {
  2631. for (var i = data.length; i <= max; i++) {
  2632. data.push({
  2633. // Use the zero-width character
  2634. // to avoid conflict with uniqueNames
  2635. name: i + '\u200B'
  2636. });
  2637. }
  2638. }
  2639. // setScale is fired after all the series is initialized,
  2640. // which is an ideal time to update the axis.categories.
  2641. treeGrid = getTreeGridFromData(data, uniqueNames || false, (uniqueNames === true) ? numberOfSeries : 1);
  2642. // Assign values to the axis.
  2643. axis.categories = treeGrid.categories;
  2644. axis.treeGrid.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  2645. axis.hasNames = true;
  2646. axis.treeGrid.tree = treeGrid.tree;
  2647. // Update yData now that we have calculated the y values
  2648. axis.series.forEach(function (series) {
  2649. var axisData = (series.options.data || []).map(function (d) {
  2650. if (isArray(d) && series.options.keys && series.options.keys.length) {
  2651. // Get the axisData from the data array used to
  2652. // build the treeGrid where has been modified
  2653. data.forEach(function (point) {
  2654. if (d.indexOf(point.x) >= 0 && d.indexOf(point.x2) >= 0) {
  2655. d = point;
  2656. }
  2657. });
  2658. }
  2659. return isObject(d, true) ? merge(d) : d;
  2660. });
  2661. // Avoid destroying points when series is not visible
  2662. if (series.visible) {
  2663. series.setData(axisData, false);
  2664. }
  2665. });
  2666. // Calculate the label options for each level in the tree.
  2667. axis.treeGrid.mapOptionsToLevel =
  2668. getLevelOptions({
  2669. defaults: labelOptions,
  2670. from: 1,
  2671. levels: labelOptions && labelOptions.levels,
  2672. to: axis.treeGrid.tree && axis.treeGrid.tree.height
  2673. });
  2674. // Setting initial collapsed nodes
  2675. if (e.type === 'beforeRender') {
  2676. axis.treeGrid.collapsedNodes = treeGrid.collapsedNodes;
  2677. }
  2678. }
  2679. });
  2680. }
  2681. /**
  2682. * Generates a tick for initial positioning.
  2683. *
  2684. * @private
  2685. * @function Highcharts.GridAxis#generateTick
  2686. *
  2687. * @param {Function} proceed
  2688. * The original generateTick function.
  2689. *
  2690. * @param {number} pos
  2691. * The tick position in axis values.
  2692. */
  2693. function wrapGenerateTick(proceed, pos) {
  2694. var axis = this,
  2695. mapOptionsToLevel = axis.treeGrid.mapOptionsToLevel || {},
  2696. isTreeGrid = axis.options.type === 'treegrid',
  2697. ticks = axis.ticks;
  2698. var tick = ticks[pos],
  2699. levelOptions,
  2700. options,
  2701. gridNode;
  2702. if (isTreeGrid &&
  2703. axis.treeGrid.mapOfPosToGridNode) {
  2704. gridNode = axis.treeGrid.mapOfPosToGridNode[pos];
  2705. levelOptions = mapOptionsToLevel[gridNode.depth];
  2706. if (levelOptions) {
  2707. options = {
  2708. labels: levelOptions
  2709. };
  2710. }
  2711. if (!tick) {
  2712. ticks[pos] = tick =
  2713. new Tick(axis, pos, void 0, void 0, {
  2714. category: gridNode.name,
  2715. tickmarkOffset: gridNode.tickmarkOffset,
  2716. options: options
  2717. });
  2718. }
  2719. else {
  2720. // update labels depending on tick interval
  2721. tick.parameters.category = gridNode.name;
  2722. tick.options = options;
  2723. tick.addLabel();
  2724. }
  2725. }
  2726. else {
  2727. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2728. }
  2729. }
  2730. /**
  2731. * Override to add indentation to axis.maxLabelDimensions.
  2732. *
  2733. * @private
  2734. * @function Highcharts.GridAxis#getMaxLabelDimensions
  2735. *
  2736. * @param {Function} proceed
  2737. * The original function
  2738. */
  2739. function wrapGetMaxLabelDimensions(proceed) {
  2740. var axis = this,
  2741. options = axis.options,
  2742. labelOptions = options && options.labels,
  2743. indentation = (labelOptions && isNumber(labelOptions.indentation) ?
  2744. labelOptions.indentation :
  2745. 0),
  2746. retVal = proceed.apply(axis,
  2747. Array.prototype.slice.call(arguments, 1)),
  2748. isTreeGrid = axis.options.type === 'treegrid';
  2749. var treeDepth;
  2750. if (isTreeGrid && axis.treeGrid.mapOfPosToGridNode) {
  2751. treeDepth = axis.treeGrid.mapOfPosToGridNode[-1].height || 0;
  2752. retVal.width += indentation * (treeDepth - 1);
  2753. }
  2754. return retVal;
  2755. }
  2756. /**
  2757. * @private
  2758. */
  2759. function wrapInit(proceed, chart, userOptions) {
  2760. var axis = this,
  2761. isTreeGrid = userOptions.type === 'treegrid';
  2762. if (!axis.treeGrid) {
  2763. axis.treeGrid = new Additions(axis);
  2764. }
  2765. // Set default and forced options for TreeGrid
  2766. if (isTreeGrid) {
  2767. // Add event for updating the categories of a treegrid.
  2768. // NOTE Preferably these events should be set on the axis.
  2769. addEvent(chart, 'beforeRender', onBeforeRender);
  2770. addEvent(chart, 'beforeRedraw', onBeforeRender);
  2771. // Add new collapsed nodes on addseries
  2772. addEvent(chart, 'addSeries', function (e) {
  2773. if (e.options.data) {
  2774. var treeGrid = getTreeGridFromData(e.options.data,
  2775. userOptions.uniqueNames || false, 1);
  2776. axis.treeGrid.collapsedNodes = (axis.treeGrid.collapsedNodes || []).concat(treeGrid.collapsedNodes);
  2777. }
  2778. });
  2779. // Collapse all nodes in axis.treegrid.collapsednodes
  2780. // where collapsed equals true.
  2781. addEvent(axis, 'foundExtremes', function () {
  2782. if (axis.treeGrid.collapsedNodes) {
  2783. axis.treeGrid.collapsedNodes.forEach(function (node) {
  2784. var breaks = axis.treeGrid.collapse(node);
  2785. if (axis.brokenAxis) {
  2786. axis.brokenAxis.setBreaks(breaks, false);
  2787. // remove the node from the axis collapsedNodes
  2788. if (axis.treeGrid.collapsedNodes) {
  2789. axis.treeGrid.collapsedNodes = axis.treeGrid.collapsedNodes.filter(function (n) {
  2790. return node.collapseStart !== n.collapseStart ||
  2791. node.collapseEnd !== n.collapseEnd;
  2792. });
  2793. }
  2794. }
  2795. });
  2796. }
  2797. });
  2798. // If staticScale is not defined on the yAxis
  2799. // and chart height is set, set axis.isDirty
  2800. // to ensure collapsing works (#12012)
  2801. addEvent(axis, 'afterBreaks', function () {
  2802. var _a;
  2803. if (axis.coll === 'yAxis' && !axis.staticScale && ((_a = axis.chart.options.chart) === null || _a === void 0 ? void 0 : _a.height)) {
  2804. axis.isDirty = true;
  2805. }
  2806. });
  2807. userOptions = merge({
  2808. // Default options
  2809. grid: {
  2810. enabled: true
  2811. },
  2812. // TODO: add support for align in treegrid.
  2813. labels: {
  2814. align: 'left',
  2815. /**
  2816. * Set options on specific levels in a tree grid axis. Takes
  2817. * precedence over labels options.
  2818. *
  2819. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2820. * Levels on TreeGrid Labels
  2821. *
  2822. * @type {Array<*>}
  2823. * @product gantt
  2824. * @apioption yAxis.labels.levels
  2825. *
  2826. * @private
  2827. */
  2828. levels: [{
  2829. /**
  2830. * Specify the level which the options within this object
  2831. * applies to.
  2832. *
  2833. * @type {number}
  2834. * @product gantt
  2835. * @apioption yAxis.labels.levels.level
  2836. *
  2837. * @private
  2838. */
  2839. level: void 0
  2840. }, {
  2841. level: 1,
  2842. /**
  2843. * @type {Highcharts.CSSObject}
  2844. * @product gantt
  2845. * @apioption yAxis.labels.levels.style
  2846. *
  2847. * @private
  2848. */
  2849. style: {
  2850. /** @ignore-option */
  2851. fontWeight: 'bold'
  2852. }
  2853. }],
  2854. /**
  2855. * The symbol for the collapse and expand icon in a
  2856. * treegrid.
  2857. *
  2858. * @product gantt
  2859. * @optionparent yAxis.labels.symbol
  2860. *
  2861. * @private
  2862. */
  2863. symbol: {
  2864. /**
  2865. * The symbol type. Points to a definition function in
  2866. * the `Highcharts.Renderer.symbols` collection.
  2867. *
  2868. * @type {Highcharts.SymbolKeyValue}
  2869. *
  2870. * @private
  2871. */
  2872. type: 'triangle',
  2873. x: -5,
  2874. y: -5,
  2875. height: 10,
  2876. width: 10,
  2877. padding: 5
  2878. }
  2879. },
  2880. uniqueNames: false
  2881. }, userOptions, {
  2882. // Forced options
  2883. reversed: true,
  2884. // grid.columns is not supported in treegrid
  2885. grid: {
  2886. columns: void 0
  2887. }
  2888. });
  2889. }
  2890. // Now apply the original function with the original arguments,
  2891. // which are sliced off this function's arguments
  2892. proceed.apply(axis, [chart, userOptions]);
  2893. if (isTreeGrid) {
  2894. axis.hasNames = true;
  2895. axis.options.showLastLabel = true;
  2896. }
  2897. }
  2898. /**
  2899. * Set the tick positions, tickInterval, axis min and max.
  2900. *
  2901. * @private
  2902. * @function Highcharts.GridAxis#setTickInterval
  2903. *
  2904. * @param {Function} proceed
  2905. * The original setTickInterval function.
  2906. */
  2907. function wrapSetTickInterval(proceed) {
  2908. var axis = this,
  2909. options = axis.options,
  2910. isTreeGrid = options.type === 'treegrid';
  2911. if (isTreeGrid) {
  2912. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  2913. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  2914. fireEvent(axis, 'foundExtremes');
  2915. // setAxisTranslation modifies the min and max according to
  2916. // axis breaks.
  2917. axis.setAxisTranslation();
  2918. axis.tickmarkOffset = 0.5;
  2919. axis.tickInterval = 1;
  2920. axis.tickPositions = axis.treeGrid.mapOfPosToGridNode ?
  2921. axis.treeGrid.getTickPositions() :
  2922. [];
  2923. }
  2924. else {
  2925. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2926. }
  2927. }
  2928. /* *
  2929. *
  2930. * Classes
  2931. *
  2932. * */
  2933. /**
  2934. * @private
  2935. * @class
  2936. */
  2937. var Additions = /** @class */ (function () {
  2938. /* *
  2939. *
  2940. * Constructors
  2941. *
  2942. * */
  2943. /**
  2944. * @private
  2945. */
  2946. function Additions(axis) {
  2947. this.axis = axis;
  2948. }
  2949. /* *
  2950. *
  2951. * Functions
  2952. *
  2953. * */
  2954. /**
  2955. * Set the collapse status.
  2956. *
  2957. * @private
  2958. *
  2959. * @param {Highcharts.Axis} axis
  2960. * The axis to check against.
  2961. *
  2962. * @param {Highcharts.GridNode} node
  2963. * The node to collapse.
  2964. */
  2965. Additions.prototype.setCollapsedStatus = function (node) {
  2966. var axis = this.axis,
  2967. chart = axis.chart;
  2968. axis.series.forEach(function (series) {
  2969. var data = series.options.data;
  2970. if (node.id && data) {
  2971. var point = chart.get(node.id),
  2972. dataPoint = data[series.data.indexOf(point)];
  2973. if (point && dataPoint) {
  2974. point.collapsed = node.collapsed;
  2975. dataPoint.collapsed = node.collapsed;
  2976. }
  2977. }
  2978. });
  2979. };
  2980. /**
  2981. * Calculates the new axis breaks to collapse a node.
  2982. *
  2983. * @private
  2984. *
  2985. * @param {Highcharts.Axis} axis
  2986. * The axis to check against.
  2987. *
  2988. * @param {Highcharts.GridNode} node
  2989. * The node to collapse.
  2990. *
  2991. * @param {number} pos
  2992. * The tick position to collapse.
  2993. *
  2994. * @return {Array<object>}
  2995. * Returns an array of the new breaks for the axis.
  2996. */
  2997. Additions.prototype.collapse = function (node) {
  2998. var axis = this.axis,
  2999. breaks = (axis.options.breaks || []),
  3000. obj = getBreakFromNode(node,
  3001. axis.max);
  3002. breaks.push(obj);
  3003. // Change the collapsed flag #13838
  3004. node.collapsed = true;
  3005. axis.treeGrid.setCollapsedStatus(node);
  3006. return breaks;
  3007. };
  3008. /**
  3009. * Calculates the new axis breaks to expand a node.
  3010. *
  3011. * @private
  3012. *
  3013. * @param {Highcharts.Axis} axis
  3014. * The axis to check against.
  3015. *
  3016. * @param {Highcharts.GridNode} node
  3017. * The node to expand.
  3018. *
  3019. * @param {number} pos
  3020. * The tick position to expand.
  3021. *
  3022. * @return {Array<object>}
  3023. * Returns an array of the new breaks for the axis.
  3024. */
  3025. Additions.prototype.expand = function (node) {
  3026. var axis = this.axis,
  3027. breaks = (axis.options.breaks || []),
  3028. obj = getBreakFromNode(node,
  3029. axis.max);
  3030. // Change the collapsed flag #13838
  3031. node.collapsed = false;
  3032. axis.treeGrid.setCollapsedStatus(node);
  3033. // Remove the break from the axis breaks array.
  3034. return breaks.reduce(function (arr, b) {
  3035. if (b.to !== obj.to || b.from !== obj.from) {
  3036. arr.push(b);
  3037. }
  3038. return arr;
  3039. }, []);
  3040. };
  3041. /**
  3042. * Creates a list of positions for the ticks on the axis. Filters out
  3043. * positions that are outside min and max, or is inside an axis break.
  3044. *
  3045. * @private
  3046. *
  3047. * @return {Array<number>}
  3048. * List of positions.
  3049. */
  3050. Additions.prototype.getTickPositions = function () {
  3051. var axis = this.axis,
  3052. roundedMin = Math.floor(axis.min / axis.tickInterval) * axis.tickInterval,
  3053. roundedMax = Math.ceil(axis.max / axis.tickInterval) * axis.tickInterval;
  3054. return Object.keys(axis.treeGrid.mapOfPosToGridNode || {}).reduce(function (arr, key) {
  3055. var pos = +key;
  3056. if (pos >= roundedMin &&
  3057. pos <= roundedMax &&
  3058. !(axis.brokenAxis && axis.brokenAxis.isInAnyBreak(pos))) {
  3059. arr.push(pos);
  3060. }
  3061. return arr;
  3062. }, []);
  3063. };
  3064. /**
  3065. * Check if a node is collapsed.
  3066. *
  3067. * @private
  3068. *
  3069. * @param {Highcharts.Axis} axis
  3070. * The axis to check against.
  3071. *
  3072. * @param {object} node
  3073. * The node to check if is collapsed.
  3074. *
  3075. * @param {number} pos
  3076. * The tick position to collapse.
  3077. *
  3078. * @return {boolean}
  3079. * Returns true if collapsed, false if expanded.
  3080. */
  3081. Additions.prototype.isCollapsed = function (node) {
  3082. var axis = this.axis,
  3083. breaks = (axis.options.breaks || []),
  3084. obj = getBreakFromNode(node,
  3085. axis.max);
  3086. return breaks.some(function (b) {
  3087. return b.from === obj.from && b.to === obj.to;
  3088. });
  3089. };
  3090. /**
  3091. * Calculates the new axis breaks after toggling the collapse/expand
  3092. * state of a node. If it is collapsed it will be expanded, and if it is
  3093. * exapended it will be collapsed.
  3094. *
  3095. * @private
  3096. *
  3097. * @param {Highcharts.Axis} axis
  3098. * The axis to check against.
  3099. *
  3100. * @param {Highcharts.GridNode} node
  3101. * The node to toggle.
  3102. *
  3103. * @return {Array<object>}
  3104. * Returns an array of the new breaks for the axis.
  3105. */
  3106. Additions.prototype.toggleCollapse = function (node) {
  3107. return (this.isCollapsed(node) ?
  3108. this.expand(node) :
  3109. this.collapse(node));
  3110. };
  3111. return Additions;
  3112. }());
  3113. TreeGridAxis.Additions = Additions;
  3114. })(TreeGridAxis || (TreeGridAxis = {}));
  3115. // Make utility functions available for testing.
  3116. Axis.prototype.utils = {
  3117. getNode: Tree.getNode
  3118. };
  3119. TreeGridAxis.compose(Axis);
  3120. return TreeGridAxis;
  3121. });
  3122. _registerModule(_modules, 'masters/modules/treegrid.src.js', [], function () {
  3123. });
  3124. }));