treegrid.src.js 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019
  1. /**
  2. * @license Highcharts Gantt JS v8.2.0 (2020-08-20)
  3. *
  4. * Tree Grid
  5. *
  6. * (c) 2016-2019 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-2020 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/Utilities.js']], function (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 = defined(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, '#666666')
  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.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/Options.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js']], function (Axis, H, O, 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 dateFormat = O.dateFormat;
  755. var addEvent = U.addEvent,
  756. defined = U.defined,
  757. erase = U.erase,
  758. find = U.find,
  759. isArray = U.isArray,
  760. isNumber = U.isNumber,
  761. merge = U.merge,
  762. pick = U.pick,
  763. timeUnits = U.timeUnits,
  764. wrap = U.wrap;
  765. var argsToArray = function (args) {
  766. return Array.prototype.slice.call(args, 1);
  767. }, isObject = function (x) {
  768. // Always use strict mode
  769. return U.isObject(x, true);
  770. }, Chart = H.Chart;
  771. var applyGridOptions = function applyGridOptions(axis) {
  772. var options = axis.options;
  773. // Center-align by default
  774. if (!options.labels) {
  775. options.labels = {};
  776. }
  777. options.labels.align = pick(options.labels.align, 'center');
  778. // @todo: Check against tickLabelPlacement between/on etc
  779. /* Prevents adding the last tick label if the axis is not a category
  780. axis.
  781. Since numeric labels are normally placed at starts and ends of a
  782. range of value, and this module makes the label point at the value,
  783. an "extra" label would appear. */
  784. if (!axis.categories) {
  785. options.showLastLabel = false;
  786. }
  787. // Prevents rotation of labels when squished, as rotating them would not
  788. // help.
  789. axis.labelRotation = 0;
  790. options.labels.rotation = 0;
  791. };
  792. /**
  793. * For a datetime axis, the scale will automatically adjust to the
  794. * appropriate unit. This member gives the default string
  795. * representations used for each unit. For intermediate values,
  796. * different units may be used, for example the `day` unit can be used
  797. * on midnight and `hour` unit be used for intermediate values on the
  798. * same axis.
  799. * For grid axes (like in Gantt charts),
  800. * it is possible to declare as a list to provide different
  801. * formats depending on available space.
  802. * For an overview of the replacement codes, see
  803. * [dateFormat](/class-reference/Highcharts#dateFormat).
  804. *
  805. * Defaults to:
  806. * ```js
  807. * {
  808. hour: {
  809. list: ['%H:%M', '%H']
  810. },
  811. day: {
  812. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  813. },
  814. week: {
  815. list: ['Week %W', 'W%W']
  816. },
  817. month: {
  818. list: ['%B', '%b', '%o']
  819. }
  820. },
  821. * ```
  822. *
  823. * @sample {gantt} gantt/demo/left-axis-table
  824. * Gantt Chart with custom axis date format.
  825. *
  826. * @product gantt
  827. * @apioption xAxis.dateTimeLabelFormats
  828. */
  829. /**
  830. * Set grid options for the axis labels. Requires Highcharts Gantt.
  831. *
  832. * @since 6.2.0
  833. * @product gantt
  834. * @apioption xAxis.grid
  835. */
  836. /**
  837. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  838. *
  839. * @type {boolean}
  840. * @default true
  841. * @since 6.2.0
  842. * @product gantt
  843. * @apioption xAxis.grid.enabled
  844. */
  845. /**
  846. * Set specific options for each column (or row for horizontal axes) in the
  847. * grid. Each extra column/row is its own axis, and the axis options can be set
  848. * here.
  849. *
  850. * @sample gantt/demo/left-axis-table
  851. * Left axis as a table
  852. *
  853. * @type {Array<Highcharts.XAxisOptions>}
  854. * @apioption xAxis.grid.columns
  855. */
  856. /**
  857. * Set border color for the label grid lines.
  858. *
  859. * @type {Highcharts.ColorString}
  860. * @apioption xAxis.grid.borderColor
  861. */
  862. /**
  863. * Set border width of the label grid lines.
  864. *
  865. * @type {number}
  866. * @default 1
  867. * @apioption xAxis.grid.borderWidth
  868. */
  869. /**
  870. * Set cell height for grid axis labels. By default this is calculated from font
  871. * size. This option only applies to horizontal axes.
  872. *
  873. * @sample gantt/grid-axis/cellheight
  874. * Gant chart with custom cell height
  875. * @type {number}
  876. * @apioption xAxis.grid.cellHeight
  877. */
  878. ''; // detach doclets above
  879. /**
  880. * Get the largest label width and height.
  881. *
  882. * @private
  883. * @function Highcharts.Axis#getMaxLabelDimensions
  884. *
  885. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  886. * All the ticks on one axis.
  887. *
  888. * @param {Array<number|string>} tickPositions
  889. * All the tick positions on one axis.
  890. *
  891. * @return {Highcharts.SizeObject}
  892. * Object containing the properties height and width.
  893. *
  894. * @todo Move this to the generic axis implementation, as it is used there.
  895. */
  896. Axis.prototype.getMaxLabelDimensions = function (ticks, tickPositions) {
  897. var dimensions = {
  898. width: 0,
  899. height: 0
  900. };
  901. tickPositions.forEach(function (pos) {
  902. var tick = ticks[pos],
  903. tickHeight = 0,
  904. tickWidth = 0,
  905. label;
  906. if (isObject(tick)) {
  907. label = isObject(tick.label) ? tick.label : {};
  908. // Find width and height of tick
  909. tickHeight = label.getBBox ? label.getBBox().height : 0;
  910. if (label.textStr) {
  911. // Set the tickWidth same as the label width after ellipsis
  912. // applied #10281
  913. tickWidth = Math.round(label.getBBox().width);
  914. }
  915. // Update the result if width and/or height are larger
  916. dimensions.height = Math.max(tickHeight, dimensions.height);
  917. dimensions.width = Math.max(tickWidth, dimensions.width);
  918. }
  919. });
  920. return dimensions;
  921. };
  922. // Adds week date format
  923. H.dateFormats.W = function (timestamp) {
  924. var d = new this.Date(timestamp);
  925. var firstDay = (this.get('Day',
  926. d) + 6) % 7;
  927. var thursday = new this.Date(d.valueOf());
  928. this.set('Date', thursday, this.get('Date', d) - firstDay + 3);
  929. var firstThursday = new this.Date(this.get('FullYear',
  930. thursday), 0, 1);
  931. if (this.get('Day', firstThursday) !== 4) {
  932. this.set('Month', d, 0);
  933. this.set('Date', d, 1 + (11 - this.get('Day', firstThursday)) % 7);
  934. }
  935. return (1 +
  936. Math.floor((thursday.valueOf() - firstThursday.valueOf()) / 604800000)).toString();
  937. };
  938. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  939. H.dateFormats.E = function (timestamp) {
  940. return dateFormat('%a', timestamp, true).charAt(0);
  941. };
  942. /* eslint-disable no-invalid-this */
  943. addEvent(Chart, 'afterSetChartSize', function () {
  944. this.axes.forEach(function (axis) {
  945. (axis.grid && axis.grid.columns || []).forEach(function (column) {
  946. column.setAxisSize();
  947. column.setAxisTranslation();
  948. });
  949. });
  950. });
  951. // Center tick labels in cells.
  952. addEvent(Tick, 'afterGetLabelPosition', function (e) {
  953. var tick = this,
  954. label = tick.label,
  955. axis = tick.axis,
  956. reversed = axis.reversed,
  957. chart = axis.chart,
  958. options = axis.options,
  959. gridOptions = options.grid || {},
  960. labelOpts = axis.options.labels,
  961. align = labelOpts.align,
  962. // verticalAlign is currently not supported for axis.labels.
  963. verticalAlign = 'middle', // labelOpts.verticalAlign,
  964. side = GridAxis.Side[axis.side],
  965. tickmarkOffset = e.tickmarkOffset,
  966. tickPositions = axis.tickPositions,
  967. tickPos = tick.pos - tickmarkOffset,
  968. nextTickPos = (isNumber(tickPositions[e.index + 1]) ?
  969. tickPositions[e.index + 1] - tickmarkOffset :
  970. axis.max + tickmarkOffset),
  971. tickSize = axis.tickSize('tick'),
  972. tickWidth = tickSize ? tickSize[0] : 0,
  973. crispCorr = tickSize ? tickSize[1] / 2 : 0,
  974. labelHeight,
  975. lblMetrics,
  976. lines,
  977. bottom,
  978. top,
  979. left,
  980. right;
  981. // Only center tick labels in grid axes
  982. if (gridOptions.enabled === true) {
  983. // Calculate top and bottom positions of the cell.
  984. if (side === 'top') {
  985. bottom = axis.top + axis.offset;
  986. top = bottom - tickWidth;
  987. }
  988. else if (side === 'bottom') {
  989. top = chart.chartHeight - axis.bottom + axis.offset;
  990. bottom = top + tickWidth;
  991. }
  992. else {
  993. bottom = axis.top + axis.len - axis.translate(reversed ? nextTickPos : tickPos);
  994. top = axis.top + axis.len - axis.translate(reversed ? tickPos : nextTickPos);
  995. }
  996. // Calculate left and right positions of the cell.
  997. if (side === 'right') {
  998. left = chart.chartWidth - axis.right + axis.offset;
  999. right = left + tickWidth;
  1000. }
  1001. else if (side === 'left') {
  1002. right = axis.left + axis.offset;
  1003. left = right - tickWidth;
  1004. }
  1005. else {
  1006. left = Math.round(axis.left + axis.translate(reversed ? nextTickPos : tickPos)) - crispCorr;
  1007. right = Math.round(axis.left + axis.translate(reversed ? tickPos : nextTickPos)) - crispCorr;
  1008. }
  1009. tick.slotWidth = right - left;
  1010. // Calculate the positioning of the label based on
  1011. // alignment.
  1012. e.pos.x = (align === 'left' ?
  1013. left :
  1014. align === 'right' ?
  1015. right :
  1016. left + ((right - left) / 2) // default to center
  1017. );
  1018. e.pos.y = (verticalAlign === 'top' ?
  1019. top :
  1020. verticalAlign === 'bottom' ?
  1021. bottom :
  1022. top + ((bottom - top) / 2) // default to middle
  1023. );
  1024. lblMetrics = chart.renderer.fontMetrics(labelOpts.style.fontSize, label.element);
  1025. labelHeight = label.getBBox().height;
  1026. // Adjustment to y position to align the label correctly.
  1027. // Would be better to have a setter or similar for this.
  1028. if (!labelOpts.useHTML) {
  1029. lines = Math.round(labelHeight / lblMetrics.h);
  1030. e.pos.y += (
  1031. // Center the label
  1032. // TODO: why does this actually center the label?
  1033. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  1034. // Adjust for height of additional lines.
  1035. -(((lines - 1) * lblMetrics.h) / 2));
  1036. }
  1037. else {
  1038. e.pos.y += (
  1039. // Readjust yCorr in htmlUpdateTransform
  1040. lblMetrics.b +
  1041. // Adjust for height of html label
  1042. -(labelHeight / 2));
  1043. }
  1044. e.pos.x += (axis.horiz && labelOpts.x || 0);
  1045. }
  1046. });
  1047. /* eslint-enable no-invalid-this */
  1048. /**
  1049. * Additions for grid axes.
  1050. * @private
  1051. * @class
  1052. */
  1053. var GridAxisAdditions = /** @class */ (function () {
  1054. /* *
  1055. *
  1056. * Constructors
  1057. *
  1058. * */
  1059. function GridAxisAdditions(axis) {
  1060. this.axis = axis;
  1061. }
  1062. /* *
  1063. *
  1064. * Functions
  1065. *
  1066. * */
  1067. /**
  1068. * Checks if an axis is the outer axis in its dimension. Since
  1069. * axes are placed outwards in order, the axis with the highest
  1070. * index is the outermost axis.
  1071. *
  1072. * Example: If there are multiple x-axes at the top of the chart,
  1073. * this function returns true if the axis supplied is the last
  1074. * of the x-axes.
  1075. *
  1076. * @private
  1077. *
  1078. * @return {boolean}
  1079. * True if the axis is the outermost axis in its dimension; false if
  1080. * not.
  1081. */
  1082. GridAxisAdditions.prototype.isOuterAxis = function () {
  1083. var axis = this.axis;
  1084. var chart = axis.chart;
  1085. var columnIndex = axis.grid.columnIndex;
  1086. var columns = (axis.linkedParent && axis.linkedParent.grid.columns ||
  1087. axis.grid.columns);
  1088. var parentAxis = columnIndex ? axis.linkedParent : axis;
  1089. var thisIndex = -1,
  1090. lastIndex = 0;
  1091. chart[axis.coll].forEach(function (otherAxis, index) {
  1092. if (otherAxis.side === axis.side && !otherAxis.options.isInternal) {
  1093. lastIndex = index;
  1094. if (otherAxis === parentAxis) {
  1095. // Get the index of the axis in question
  1096. thisIndex = index;
  1097. }
  1098. }
  1099. });
  1100. return (lastIndex === thisIndex &&
  1101. (isNumber(columnIndex) ? columns.length === columnIndex : true));
  1102. };
  1103. return GridAxisAdditions;
  1104. }());
  1105. /**
  1106. * Axis with grid support.
  1107. * @private
  1108. * @class
  1109. */
  1110. var GridAxis = /** @class */ (function () {
  1111. function GridAxis() {
  1112. }
  1113. /* *
  1114. *
  1115. * Static Functions
  1116. *
  1117. * */
  1118. /* eslint-disable valid-jsdoc */
  1119. /**
  1120. * Extends axis class with grid support.
  1121. * @private
  1122. */
  1123. GridAxis.compose = function (AxisClass) {
  1124. Axis.keepProps.push('grid');
  1125. wrap(AxisClass.prototype, 'unsquish', GridAxis.wrapUnsquish);
  1126. // Add event handlers
  1127. addEvent(AxisClass, 'init', GridAxis.onInit);
  1128. addEvent(AxisClass, 'afterGetOffset', GridAxis.onAfterGetOffset);
  1129. addEvent(AxisClass, 'afterGetTitlePosition', GridAxis.onAfterGetTitlePosition);
  1130. addEvent(AxisClass, 'afterInit', GridAxis.onAfterInit);
  1131. addEvent(AxisClass, 'afterRender', GridAxis.onAfterRender);
  1132. addEvent(AxisClass, 'afterSetAxisTranslation', GridAxis.onAfterSetAxisTranslation);
  1133. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions);
  1134. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions2);
  1135. addEvent(AxisClass, 'afterSetScale', GridAxis.onAfterSetScale);
  1136. addEvent(AxisClass, 'afterTickSize', GridAxis.onAfterTickSize);
  1137. addEvent(AxisClass, 'trimTicks', GridAxis.onTrimTicks);
  1138. addEvent(AxisClass, 'destroy', GridAxis.onDestroy);
  1139. };
  1140. /**
  1141. * Handle columns and getOffset.
  1142. * @private
  1143. */
  1144. GridAxis.onAfterGetOffset = function () {
  1145. var grid = this.grid;
  1146. (grid && grid.columns || []).forEach(function (column) {
  1147. column.getOffset();
  1148. });
  1149. };
  1150. /**
  1151. * @private
  1152. */
  1153. GridAxis.onAfterGetTitlePosition = function (e) {
  1154. var axis = this;
  1155. var options = axis.options;
  1156. var gridOptions = options.grid || {};
  1157. if (gridOptions.enabled === true) {
  1158. // compute anchor points for each of the title align options
  1159. var title = axis.axisTitle,
  1160. axisHeight = axis.height,
  1161. horiz = axis.horiz,
  1162. axisLeft = axis.left,
  1163. offset = axis.offset,
  1164. opposite = axis.opposite,
  1165. _a = axis.options.title,
  1166. axisTitleOptions = _a === void 0 ? {} : _a,
  1167. axisTop = axis.top,
  1168. axisWidth = axis.width;
  1169. var tickSize = axis.tickSize();
  1170. var titleWidth = title && title.getBBox().width;
  1171. var xOption = axisTitleOptions.x || 0;
  1172. var yOption = axisTitleOptions.y || 0;
  1173. var titleMargin = pick(axisTitleOptions.margin,
  1174. horiz ? 5 : 10);
  1175. var titleFontSize = axis.chart.renderer.fontMetrics(axisTitleOptions.style &&
  1176. axisTitleOptions.style.fontSize,
  1177. title).f;
  1178. var crispCorr = tickSize ? tickSize[0] / 2 : 0;
  1179. // TODO account for alignment
  1180. // the position in the perpendicular direction of the axis
  1181. var offAxis = ((horiz ? axisTop + axisHeight : axisLeft) +
  1182. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  1183. (opposite ? -1 : 1) * // so does opposite axes
  1184. crispCorr +
  1185. (axis.side === GridAxis.Side.bottom ? titleFontSize : 0));
  1186. e.titlePosition.x = horiz ?
  1187. axisLeft - titleWidth / 2 - titleMargin + xOption :
  1188. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  1189. e.titlePosition.y = horiz ?
  1190. (offAxis -
  1191. (opposite ? axisHeight : 0) +
  1192. (opposite ? titleFontSize : -titleFontSize) / 2 +
  1193. offset +
  1194. yOption) :
  1195. axisTop - titleMargin + yOption;
  1196. }
  1197. };
  1198. /**
  1199. * @private
  1200. */
  1201. GridAxis.onAfterInit = function () {
  1202. var axis = this;
  1203. var chart = axis.chart,
  1204. _a = axis.options.grid,
  1205. gridOptions = _a === void 0 ? {} : _a,
  1206. userOptions = axis.userOptions;
  1207. if (gridOptions.enabled) {
  1208. applyGridOptions(axis);
  1209. /* eslint-disable no-invalid-this */
  1210. // TODO: wrap the axis instead
  1211. wrap(axis, 'labelFormatter', function (proceed) {
  1212. var _a = this,
  1213. axis = _a.axis,
  1214. value = _a.value;
  1215. var tickPos = axis.tickPositions;
  1216. var series = (axis.isLinked ?
  1217. axis.linkedParent :
  1218. axis).series[0];
  1219. var isFirst = value === tickPos[0];
  1220. var isLast = value === tickPos[tickPos.length - 1];
  1221. var point = series && find(series.options.data,
  1222. function (p) {
  1223. return p[axis.isXAxis ? 'x' : 'y'] === value;
  1224. });
  1225. // Make additional properties available for the
  1226. // formatter
  1227. this.isFirst = isFirst;
  1228. this.isLast = isLast;
  1229. this.point = point;
  1230. // Call original labelFormatter
  1231. return proceed.call(this);
  1232. });
  1233. /* eslint-enable no-invalid-this */
  1234. }
  1235. if (gridOptions.columns) {
  1236. var columns = axis.grid.columns = [],
  1237. columnIndex = axis.grid.columnIndex = 0;
  1238. // Handle columns, each column is a grid axis
  1239. while (++columnIndex < gridOptions.columns.length) {
  1240. var columnOptions = merge(userOptions,
  1241. gridOptions.columns[gridOptions.columns.length - columnIndex - 1], {
  1242. linkedTo: 0,
  1243. // Force to behave like category axis
  1244. type: 'category',
  1245. // Disable by default the scrollbar on the grid axis
  1246. scrollbar: {
  1247. enabled: false
  1248. }
  1249. });
  1250. delete columnOptions.grid.columns; // Prevent recursion
  1251. var column = new Axis(axis.chart,
  1252. columnOptions);
  1253. column.grid.isColumn = true;
  1254. column.grid.columnIndex = columnIndex;
  1255. // Remove column axis from chart axes array, and place it
  1256. // in the columns array.
  1257. erase(chart.axes, column);
  1258. erase(chart[axis.coll], column);
  1259. columns.push(column);
  1260. }
  1261. }
  1262. };
  1263. /**
  1264. * Draw an extra line on the far side of the outermost axis,
  1265. * creating floor/roof/wall of a grid. And some padding.
  1266. * ```
  1267. * Make this:
  1268. * (axis.min) __________________________ (axis.max)
  1269. * | | | | |
  1270. * Into this:
  1271. * (axis.min) __________________________ (axis.max)
  1272. * ___|____|____|____|____|__
  1273. * ```
  1274. * @private
  1275. */
  1276. GridAxis.onAfterRender = function () {
  1277. var axis = this;
  1278. var grid = axis.grid;
  1279. var options = axis.options;
  1280. var renderer = axis.chart.renderer;
  1281. var gridOptions = options.grid || {};
  1282. var yStartIndex,
  1283. yEndIndex,
  1284. xStartIndex,
  1285. xEndIndex;
  1286. if (gridOptions.enabled === true) {
  1287. // @todo acutual label padding (top, bottom, left, right)
  1288. axis.maxLabelDimensions = axis.getMaxLabelDimensions(axis.ticks, axis.tickPositions);
  1289. // Remove right wall before rendering if updating
  1290. if (axis.rightWall) {
  1291. axis.rightWall.destroy();
  1292. }
  1293. /*
  1294. Draw an extra axis line on outer axes
  1295. >
  1296. Make this: |______|______|______|___
  1297. > _________________________
  1298. Into this: |______|______|______|__|
  1299. */
  1300. if (axis.grid && axis.grid.isOuterAxis() && axis.axisLine) {
  1301. var lineWidth = options.lineWidth;
  1302. if (lineWidth) {
  1303. var linePath = axis.getLinePath(lineWidth);
  1304. var startPoint = linePath[0];
  1305. var endPoint = linePath[1];
  1306. // Negate distance if top or left axis
  1307. // Subtract 1px to draw the line at the end of the tick
  1308. var tickLength = (axis.tickSize('tick') || [1])[0];
  1309. var distance = (tickLength - 1) * ((axis.side === GridAxis.Side.top ||
  1310. axis.side === GridAxis.Side.left) ? -1 : 1);
  1311. // If axis is horizontal, reposition line path vertically
  1312. if (startPoint[0] === 'M' && endPoint[0] === 'L') {
  1313. if (axis.horiz) {
  1314. startPoint[2] += distance;
  1315. endPoint[2] += distance;
  1316. }
  1317. else {
  1318. // If axis is vertical, reposition line path
  1319. // horizontally
  1320. startPoint[1] += distance;
  1321. endPoint[1] += distance;
  1322. }
  1323. }
  1324. if (!axis.grid.axisLineExtra) {
  1325. axis.grid.axisLineExtra = renderer
  1326. .path(linePath)
  1327. .attr({
  1328. zIndex: 7
  1329. })
  1330. .addClass('highcharts-axis-line')
  1331. .add(axis.axisGroup);
  1332. if (!renderer.styledMode) {
  1333. axis.grid.axisLineExtra.attr({
  1334. stroke: options.lineColor,
  1335. 'stroke-width': lineWidth
  1336. });
  1337. }
  1338. }
  1339. else {
  1340. axis.grid.axisLineExtra.animate({
  1341. d: linePath
  1342. });
  1343. }
  1344. // show or hide the line depending on
  1345. // options.showEmpty
  1346. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  1347. }
  1348. }
  1349. (grid && grid.columns || []).forEach(function (column) {
  1350. column.render();
  1351. });
  1352. }
  1353. };
  1354. /**
  1355. * @private
  1356. */
  1357. GridAxis.onAfterSetAxisTranslation = function () {
  1358. var axis = this;
  1359. var tickInfo = axis.tickPositions && axis.tickPositions.info;
  1360. var options = axis.options;
  1361. var gridOptions = options.grid || {};
  1362. var userLabels = axis.userOptions.labels || {};
  1363. if (axis.horiz) {
  1364. if (gridOptions.enabled === true) {
  1365. axis.series.forEach(function (series) {
  1366. series.options.pointRange = 0;
  1367. });
  1368. }
  1369. // Lower level time ticks, like hours or minutes, represent
  1370. // points in time and not ranges. These should be aligned
  1371. // left in the grid cell by default. The same applies to
  1372. // years of higher order.
  1373. if (tickInfo &&
  1374. options.dateTimeLabelFormats &&
  1375. options.labels &&
  1376. !defined(userLabels.align) &&
  1377. (options.dateTimeLabelFormats[tickInfo.unitName].range === false ||
  1378. tickInfo.count > 1 // years
  1379. )) {
  1380. options.labels.align = 'left';
  1381. if (!defined(userLabels.x)) {
  1382. options.labels.x = 3;
  1383. }
  1384. }
  1385. }
  1386. };
  1387. /**
  1388. * Creates a left and right wall on horizontal axes:
  1389. * - Places leftmost tick at the start of the axis, to create a left
  1390. * wall
  1391. * - Ensures that the rightmost tick is at the end of the axis, to
  1392. * create a right wall.
  1393. * @private
  1394. */
  1395. GridAxis.onAfterSetOptions = function (e) {
  1396. var options = this.options,
  1397. userOptions = e.userOptions,
  1398. gridAxisOptions,
  1399. gridOptions = ((options && isObject(options.grid)) ? options.grid : {});
  1400. if (gridOptions.enabled === true) {
  1401. // Merge the user options into default grid axis options so
  1402. // that when a user option is set, it takes presedence.
  1403. gridAxisOptions = merge(true, {
  1404. className: ('highcharts-grid-axis ' + (userOptions.className || '')),
  1405. dateTimeLabelFormats: {
  1406. hour: {
  1407. list: ['%H:%M', '%H']
  1408. },
  1409. day: {
  1410. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  1411. },
  1412. week: {
  1413. list: ['Week %W', 'W%W']
  1414. },
  1415. month: {
  1416. list: ['%B', '%b', '%o']
  1417. }
  1418. },
  1419. grid: {
  1420. borderWidth: 1
  1421. },
  1422. labels: {
  1423. padding: 2,
  1424. style: {
  1425. fontSize: '13px'
  1426. }
  1427. },
  1428. margin: 0,
  1429. title: {
  1430. text: null,
  1431. reserveSpace: false,
  1432. rotation: 0
  1433. },
  1434. // In a grid axis, only allow one unit of certain types,
  1435. // for example we shouln't have one grid cell spanning
  1436. // two days.
  1437. units: [[
  1438. 'millisecond',
  1439. [1, 10, 100]
  1440. ], [
  1441. 'second',
  1442. [1, 10]
  1443. ], [
  1444. 'minute',
  1445. [1, 5, 15]
  1446. ], [
  1447. 'hour',
  1448. [1, 6]
  1449. ], [
  1450. 'day',
  1451. [1]
  1452. ], [
  1453. 'week',
  1454. [1]
  1455. ], [
  1456. 'month',
  1457. [1]
  1458. ], [
  1459. 'year',
  1460. null
  1461. ]]
  1462. }, userOptions);
  1463. // X-axis specific options
  1464. if (this.coll === 'xAxis') {
  1465. // For linked axes, tickPixelInterval is used only if
  1466. // the tickPositioner below doesn't run or returns
  1467. // undefined (like multiple years)
  1468. if (defined(userOptions.linkedTo) &&
  1469. !defined(userOptions.tickPixelInterval)) {
  1470. gridAxisOptions.tickPixelInterval = 350;
  1471. }
  1472. // For the secondary grid axis, use the primary axis'
  1473. // tick intervals and return ticks one level higher.
  1474. if (
  1475. // Check for tick pixel interval in options
  1476. !defined(userOptions.tickPixelInterval) &&
  1477. // Only for linked axes
  1478. defined(userOptions.linkedTo) &&
  1479. !defined(userOptions.tickPositioner) &&
  1480. !defined(userOptions.tickInterval)) {
  1481. gridAxisOptions.tickPositioner = function (min, max) {
  1482. var parentInfo = (this.linkedParent &&
  1483. this.linkedParent.tickPositions &&
  1484. this.linkedParent.tickPositions.info);
  1485. if (parentInfo) {
  1486. var unitIdx,
  1487. count,
  1488. unitName,
  1489. i,
  1490. units = gridAxisOptions.units,
  1491. unitRange;
  1492. for (i = 0; i < units.length; i++) {
  1493. if (units[i][0] ===
  1494. parentInfo.unitName) {
  1495. unitIdx = i;
  1496. break;
  1497. }
  1498. }
  1499. // Get the first allowed count on the next
  1500. // unit.
  1501. if (units[unitIdx + 1]) {
  1502. unitName = units[unitIdx + 1][0];
  1503. count =
  1504. (units[unitIdx + 1][1] || [1])[0];
  1505. // In case the base X axis shows years, make
  1506. // the secondary axis show ten times the
  1507. // years (#11427)
  1508. }
  1509. else if (parentInfo.unitName === 'year') {
  1510. unitName = 'year';
  1511. count = parentInfo.count * 10;
  1512. }
  1513. unitRange = timeUnits[unitName];
  1514. this.tickInterval = unitRange * count;
  1515. return this.getTimeTicks({
  1516. unitRange: unitRange,
  1517. count: count,
  1518. unitName: unitName
  1519. }, min, max, this.options.startOfWeek);
  1520. }
  1521. };
  1522. }
  1523. }
  1524. // Now merge the combined options into the axis options
  1525. merge(true, this.options, gridAxisOptions);
  1526. if (this.horiz) {
  1527. /* _________________________
  1528. Make this: ___|_____|_____|_____|__|
  1529. ^ ^
  1530. _________________________
  1531. Into this: |_____|_____|_____|_____|
  1532. ^ ^ */
  1533. options.minPadding = pick(userOptions.minPadding, 0);
  1534. options.maxPadding = pick(userOptions.maxPadding, 0);
  1535. }
  1536. // If borderWidth is set, then use its value for tick and
  1537. // line width.
  1538. if (isNumber(options.grid.borderWidth)) {
  1539. options.tickWidth = options.lineWidth = gridOptions.borderWidth;
  1540. }
  1541. }
  1542. };
  1543. /**
  1544. * @private
  1545. */
  1546. GridAxis.onAfterSetOptions2 = function (e) {
  1547. var axis = this;
  1548. var userOptions = e.userOptions;
  1549. var gridOptions = userOptions && userOptions.grid || {};
  1550. var columns = gridOptions.columns;
  1551. // Add column options to the parent axis. Children has their column
  1552. // options set on init in onGridAxisAfterInit.
  1553. if (gridOptions.enabled && columns) {
  1554. merge(true, axis.options, columns[columns.length - 1]);
  1555. }
  1556. };
  1557. /**
  1558. * Handle columns and setScale.
  1559. * @private
  1560. */
  1561. GridAxis.onAfterSetScale = function () {
  1562. var axis = this;
  1563. (axis.grid.columns || []).forEach(function (column) {
  1564. column.setScale();
  1565. });
  1566. };
  1567. /**
  1568. * Draw vertical axis ticks extra long to create cell floors and roofs.
  1569. * Overrides the tickLength for vertical axes.
  1570. * @private
  1571. */
  1572. GridAxis.onAfterTickSize = function (e) {
  1573. var defaultLeftAxisOptions = Axis.defaultLeftAxisOptions;
  1574. var _a = this,
  1575. horiz = _a.horiz,
  1576. maxLabelDimensions = _a.maxLabelDimensions,
  1577. _b = _a.options.grid,
  1578. gridOptions = _b === void 0 ? {} : _b;
  1579. if (gridOptions.enabled && maxLabelDimensions) {
  1580. var labelPadding = (Math.abs(defaultLeftAxisOptions.labels.x) * 2);
  1581. var distance = horiz ?
  1582. gridOptions.cellHeight || labelPadding + maxLabelDimensions.height :
  1583. labelPadding + maxLabelDimensions.width;
  1584. if (isArray(e.tickSize)) {
  1585. e.tickSize[0] = distance;
  1586. }
  1587. else {
  1588. e.tickSize = [distance, 0];
  1589. }
  1590. }
  1591. };
  1592. /**
  1593. * @private
  1594. */
  1595. GridAxis.onDestroy = function (e) {
  1596. var grid = this.grid;
  1597. (grid.columns || []).forEach(function (column) {
  1598. column.destroy(e.keepEvents);
  1599. });
  1600. grid.columns = void 0;
  1601. };
  1602. /**
  1603. * Wraps axis init to draw cell walls on vertical axes.
  1604. * @private
  1605. */
  1606. GridAxis.onInit = function (e) {
  1607. var axis = this;
  1608. var userOptions = e.userOptions || {};
  1609. var gridOptions = userOptions.grid || {};
  1610. if (gridOptions.enabled && defined(gridOptions.borderColor)) {
  1611. userOptions.tickColor = userOptions.lineColor = gridOptions.borderColor;
  1612. }
  1613. if (!axis.grid) {
  1614. axis.grid = new GridAxisAdditions(axis);
  1615. }
  1616. };
  1617. /**
  1618. * Makes tick labels which are usually ignored in a linked axis
  1619. * displayed if they are within range of linkedParent.min.
  1620. * ```
  1621. * _____________________________
  1622. * | | | | |
  1623. * Make this: | | 2 | 3 | 4 |
  1624. * |___|_______|_______|_______|
  1625. * ^
  1626. * _____________________________
  1627. * | | | | |
  1628. * Into this: | 1 | 2 | 3 | 4 |
  1629. * |___|_______|_______|_______|
  1630. * ^
  1631. * ```
  1632. * @private
  1633. * @todo Does this function do what the drawing says? Seems to affect
  1634. * ticks and not the labels directly?
  1635. */
  1636. GridAxis.onTrimTicks = function () {
  1637. var axis = this;
  1638. var options = axis.options;
  1639. var gridOptions = options.grid || {};
  1640. var categoryAxis = axis.categories;
  1641. var tickPositions = axis.tickPositions;
  1642. var firstPos = tickPositions[0];
  1643. var lastPos = tickPositions[tickPositions.length - 1];
  1644. var linkedMin = axis.linkedParent && axis.linkedParent.min;
  1645. var linkedMax = axis.linkedParent && axis.linkedParent.max;
  1646. var min = linkedMin || axis.min;
  1647. var max = linkedMax || axis.max;
  1648. var tickInterval = axis.tickInterval;
  1649. var endMoreThanMin = (firstPos < min &&
  1650. firstPos + tickInterval > min);
  1651. var startLessThanMax = (lastPos > max &&
  1652. lastPos - tickInterval < max);
  1653. if (gridOptions.enabled === true &&
  1654. !categoryAxis &&
  1655. (axis.horiz || axis.isLinked)) {
  1656. if (endMoreThanMin && !options.startOnTick) {
  1657. tickPositions[0] = min;
  1658. }
  1659. if (startLessThanMax && !options.endOnTick) {
  1660. tickPositions[tickPositions.length - 1] = max;
  1661. }
  1662. }
  1663. };
  1664. /**
  1665. * Avoid altering tickInterval when reserving space.
  1666. * @private
  1667. */
  1668. GridAxis.wrapUnsquish = function (proceed) {
  1669. var axis = this;
  1670. var _a = axis.options.grid,
  1671. gridOptions = _a === void 0 ? {} : _a;
  1672. if (gridOptions.enabled === true && axis.categories) {
  1673. return axis.tickInterval;
  1674. }
  1675. return proceed.apply(axis, argsToArray(arguments));
  1676. };
  1677. return GridAxis;
  1678. }());
  1679. (function (GridAxis) {
  1680. /**
  1681. * Enum for which side the axis is on. Maps to axis.side.
  1682. * @private
  1683. */
  1684. var Side;
  1685. (function (Side) {
  1686. Side[Side["top"] = 0] = "top";
  1687. Side[Side["right"] = 1] = "right";
  1688. Side[Side["bottom"] = 2] = "bottom";
  1689. Side[Side["left"] = 3] = "left";
  1690. })(Side = GridAxis.Side || (GridAxis.Side = {}));
  1691. })(GridAxis || (GridAxis = {}));
  1692. GridAxis.compose(Axis);
  1693. return GridAxis;
  1694. });
  1695. _registerModule(_modules, 'Core/Axis/BrokenAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Extensions/Stacking.js']], function (Axis, H, U, StackItem) {
  1696. /* *
  1697. *
  1698. * (c) 2009-2020 Torstein Honsi
  1699. *
  1700. * License: www.highcharts.com/license
  1701. *
  1702. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1703. *
  1704. * */
  1705. var addEvent = U.addEvent,
  1706. find = U.find,
  1707. fireEvent = U.fireEvent,
  1708. isArray = U.isArray,
  1709. isNumber = U.isNumber,
  1710. pick = U.pick;
  1711. var Series = H.Series;
  1712. /* eslint-disable valid-jsdoc */
  1713. /**
  1714. * Provides support for broken axes.
  1715. * @private
  1716. * @class
  1717. */
  1718. var BrokenAxisAdditions = /** @class */ (function () {
  1719. /* *
  1720. *
  1721. * Constructors
  1722. *
  1723. * */
  1724. function BrokenAxisAdditions(axis) {
  1725. this.hasBreaks = false;
  1726. this.axis = axis;
  1727. }
  1728. /* *
  1729. *
  1730. * Static Functions
  1731. *
  1732. * */
  1733. /**
  1734. * @private
  1735. */
  1736. BrokenAxisAdditions.isInBreak = function (brk, val) {
  1737. var ret,
  1738. repeat = brk.repeat || Infinity,
  1739. from = brk.from,
  1740. length = brk.to - brk.from,
  1741. test = (val >= from ?
  1742. (val - from) % repeat :
  1743. repeat - ((from - val) % repeat));
  1744. if (!brk.inclusive) {
  1745. ret = test < length && test !== 0;
  1746. }
  1747. else {
  1748. ret = test <= length;
  1749. }
  1750. return ret;
  1751. };
  1752. /**
  1753. * @private
  1754. */
  1755. BrokenAxisAdditions.lin2Val = function (val) {
  1756. var axis = this;
  1757. var brokenAxis = axis.brokenAxis;
  1758. var breakArray = brokenAxis && brokenAxis.breakArray;
  1759. if (!breakArray) {
  1760. return val;
  1761. }
  1762. var nval = val,
  1763. brk,
  1764. i;
  1765. for (i = 0; i < breakArray.length; i++) {
  1766. brk = breakArray[i];
  1767. if (brk.from >= nval) {
  1768. break;
  1769. }
  1770. else if (brk.to < nval) {
  1771. nval += brk.len;
  1772. }
  1773. else if (BrokenAxisAdditions.isInBreak(brk, nval)) {
  1774. nval += brk.len;
  1775. }
  1776. }
  1777. return nval;
  1778. };
  1779. /**
  1780. * @private
  1781. */
  1782. BrokenAxisAdditions.val2Lin = function (val) {
  1783. var axis = this;
  1784. var brokenAxis = axis.brokenAxis;
  1785. var breakArray = brokenAxis && brokenAxis.breakArray;
  1786. if (!breakArray) {
  1787. return val;
  1788. }
  1789. var nval = val,
  1790. brk,
  1791. i;
  1792. for (i = 0; i < breakArray.length; i++) {
  1793. brk = breakArray[i];
  1794. if (brk.to <= val) {
  1795. nval -= brk.len;
  1796. }
  1797. else if (brk.from >= val) {
  1798. break;
  1799. }
  1800. else if (BrokenAxisAdditions.isInBreak(brk, val)) {
  1801. nval -= (val - brk.from);
  1802. break;
  1803. }
  1804. }
  1805. return nval;
  1806. };
  1807. /* *
  1808. *
  1809. * Functions
  1810. *
  1811. * */
  1812. /**
  1813. * Returns the first break found where the x is larger then break.from and
  1814. * smaller then break.to.
  1815. *
  1816. * @param {number} x
  1817. * The number which should be within a break.
  1818. *
  1819. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  1820. * The array of breaks to search within.
  1821. *
  1822. * @return {Highcharts.XAxisBreaksOptions|undefined}
  1823. * Returns the first break found that matches, returns false if no break is
  1824. * found.
  1825. */
  1826. BrokenAxisAdditions.prototype.findBreakAt = function (x, breaks) {
  1827. return find(breaks, function (b) {
  1828. return b.from < x && x < b.to;
  1829. });
  1830. };
  1831. /**
  1832. * @private
  1833. */
  1834. BrokenAxisAdditions.prototype.isInAnyBreak = function (val, testKeep) {
  1835. var brokenAxis = this;
  1836. var axis = brokenAxis.axis;
  1837. var breaks = axis.options.breaks,
  1838. i = breaks && breaks.length,
  1839. inbrk,
  1840. keep,
  1841. ret;
  1842. if (i) {
  1843. while (i--) {
  1844. if (BrokenAxisAdditions.isInBreak(breaks[i], val)) {
  1845. inbrk = true;
  1846. if (!keep) {
  1847. keep = pick(breaks[i].showPoints, !axis.isXAxis);
  1848. }
  1849. }
  1850. }
  1851. if (inbrk && testKeep) {
  1852. ret = inbrk && !keep;
  1853. }
  1854. else {
  1855. ret = inbrk;
  1856. }
  1857. }
  1858. return ret;
  1859. };
  1860. /**
  1861. * Dynamically set or unset breaks in an axis. This function in lighter than
  1862. * usin Axis.update, and it also preserves animation.
  1863. *
  1864. * @private
  1865. * @function Highcharts.Axis#setBreaks
  1866. *
  1867. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  1868. * The breaks to add. When `undefined` it removes existing breaks.
  1869. *
  1870. * @param {boolean} [redraw=true]
  1871. * Whether to redraw the chart immediately.
  1872. *
  1873. * @return {void}
  1874. */
  1875. BrokenAxisAdditions.prototype.setBreaks = function (breaks, redraw) {
  1876. var brokenAxis = this;
  1877. var axis = brokenAxis.axis;
  1878. var hasBreaks = (isArray(breaks) && !!breaks.length);
  1879. axis.isDirty = brokenAxis.hasBreaks !== hasBreaks;
  1880. brokenAxis.hasBreaks = hasBreaks;
  1881. axis.options.breaks = axis.userOptions.breaks = breaks;
  1882. axis.forceRedraw = true; // Force recalculation in setScale
  1883. // Recalculate series related to the axis.
  1884. axis.series.forEach(function (series) {
  1885. series.isDirty = true;
  1886. });
  1887. if (!hasBreaks && axis.val2lin === BrokenAxisAdditions.val2Lin) {
  1888. // Revert to prototype functions
  1889. delete axis.val2lin;
  1890. delete axis.lin2val;
  1891. }
  1892. if (hasBreaks) {
  1893. axis.userOptions.ordinal = false;
  1894. axis.lin2val = BrokenAxisAdditions.lin2Val;
  1895. axis.val2lin = BrokenAxisAdditions.val2Lin;
  1896. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  1897. // If trying to set extremes inside a break, extend min to
  1898. // after, and max to before the break ( #3857 )
  1899. if (brokenAxis.hasBreaks) {
  1900. var axisBreak,
  1901. breaks = this.options.breaks;
  1902. while ((axisBreak = brokenAxis.findBreakAt(newMin, breaks))) {
  1903. newMin = axisBreak.to;
  1904. }
  1905. while ((axisBreak = brokenAxis.findBreakAt(newMax, breaks))) {
  1906. newMax = axisBreak.from;
  1907. }
  1908. // If both min and max is within the same break.
  1909. if (newMax < newMin) {
  1910. newMax = newMin;
  1911. }
  1912. }
  1913. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  1914. };
  1915. axis.setAxisTranslation = function (saveOld) {
  1916. Axis.prototype.setAxisTranslation.call(this, saveOld);
  1917. brokenAxis.unitLength = null;
  1918. if (brokenAxis.hasBreaks) {
  1919. var breaks = axis.options.breaks || [],
  1920. // Temporary one:
  1921. breakArrayT = [],
  1922. breakArray = [],
  1923. length = 0,
  1924. inBrk,
  1925. repeat,
  1926. min = axis.userMin || axis.min,
  1927. max = axis.userMax || axis.max,
  1928. pointRangePadding = pick(axis.pointRangePadding, 0),
  1929. start,
  1930. i;
  1931. // Min & max check (#4247)
  1932. breaks.forEach(function (brk) {
  1933. repeat = brk.repeat || Infinity;
  1934. if (BrokenAxisAdditions.isInBreak(brk, min)) {
  1935. min +=
  1936. (brk.to % repeat) -
  1937. (min % repeat);
  1938. }
  1939. if (BrokenAxisAdditions.isInBreak(brk, max)) {
  1940. max -=
  1941. (max % repeat) -
  1942. (brk.from % repeat);
  1943. }
  1944. });
  1945. // Construct an array holding all breaks in the axis
  1946. breaks.forEach(function (brk) {
  1947. start = brk.from;
  1948. repeat = brk.repeat || Infinity;
  1949. while (start - repeat > min) {
  1950. start -= repeat;
  1951. }
  1952. while (start < min) {
  1953. start += repeat;
  1954. }
  1955. for (i = start; i < max; i += repeat) {
  1956. breakArrayT.push({
  1957. value: i,
  1958. move: 'in'
  1959. });
  1960. breakArrayT.push({
  1961. value: i + (brk.to - brk.from),
  1962. move: 'out',
  1963. size: brk.breakSize
  1964. });
  1965. }
  1966. });
  1967. breakArrayT.sort(function (a, b) {
  1968. return ((a.value === b.value) ?
  1969. ((a.move === 'in' ? 0 : 1) -
  1970. (b.move === 'in' ? 0 : 1)) :
  1971. a.value - b.value);
  1972. });
  1973. // Simplify the breaks
  1974. inBrk = 0;
  1975. start = min;
  1976. breakArrayT.forEach(function (brk) {
  1977. inBrk += (brk.move === 'in' ? 1 : -1);
  1978. if (inBrk === 1 && brk.move === 'in') {
  1979. start = brk.value;
  1980. }
  1981. if (inBrk === 0) {
  1982. breakArray.push({
  1983. from: start,
  1984. to: brk.value,
  1985. len: brk.value - start - (brk.size || 0)
  1986. });
  1987. length += brk.value - start - (brk.size || 0);
  1988. }
  1989. });
  1990. /**
  1991. * HC <= 8 backwards compatibility, used by demo samples.
  1992. * @deprecated
  1993. * @private
  1994. * @requires modules/broken-axis
  1995. */
  1996. axis.breakArray = brokenAxis.breakArray = breakArray;
  1997. // Used with staticScale, and below the actual axis length,
  1998. // when breaks are substracted.
  1999. brokenAxis.unitLength = max - min - length + pointRangePadding;
  2000. fireEvent(axis, 'afterBreaks');
  2001. if (axis.staticScale) {
  2002. axis.transA = axis.staticScale;
  2003. }
  2004. else if (brokenAxis.unitLength) {
  2005. axis.transA *=
  2006. (max - axis.min + pointRangePadding) /
  2007. brokenAxis.unitLength;
  2008. }
  2009. if (pointRangePadding) {
  2010. axis.minPixelPadding =
  2011. axis.transA * axis.minPointOffset;
  2012. }
  2013. axis.min = min;
  2014. axis.max = max;
  2015. }
  2016. };
  2017. }
  2018. if (pick(redraw, true)) {
  2019. axis.chart.redraw();
  2020. }
  2021. };
  2022. return BrokenAxisAdditions;
  2023. }());
  2024. /**
  2025. * Axis with support of broken data rows.
  2026. * @private
  2027. * @class
  2028. */
  2029. var BrokenAxis = /** @class */ (function () {
  2030. function BrokenAxis() {
  2031. }
  2032. /**
  2033. * Adds support for broken axes.
  2034. * @private
  2035. */
  2036. BrokenAxis.compose = function (AxisClass, SeriesClass) {
  2037. AxisClass.keepProps.push('brokenAxis');
  2038. var seriesProto = Series.prototype;
  2039. /**
  2040. * @private
  2041. */
  2042. seriesProto.drawBreaks = function (axis, keys) {
  2043. var series = this,
  2044. points = series.points,
  2045. breaks,
  2046. threshold,
  2047. eventName,
  2048. y;
  2049. if (axis && // #5950
  2050. axis.brokenAxis &&
  2051. axis.brokenAxis.hasBreaks) {
  2052. var brokenAxis_1 = axis.brokenAxis;
  2053. keys.forEach(function (key) {
  2054. breaks = brokenAxis_1 && brokenAxis_1.breakArray || [];
  2055. threshold = axis.isXAxis ?
  2056. axis.min :
  2057. pick(series.options.threshold, axis.min);
  2058. points.forEach(function (point) {
  2059. y = pick(point['stack' + key.toUpperCase()], point[key]);
  2060. breaks.forEach(function (brk) {
  2061. if (isNumber(threshold) && isNumber(y)) {
  2062. eventName = false;
  2063. if ((threshold < brk.from && y > brk.to) ||
  2064. (threshold > brk.from && y < brk.from)) {
  2065. eventName = 'pointBreak';
  2066. }
  2067. else if ((threshold < brk.from && y > brk.from && y < brk.to) ||
  2068. (threshold > brk.from && y > brk.to && y < brk.from)) {
  2069. eventName = 'pointInBreak';
  2070. }
  2071. if (eventName) {
  2072. fireEvent(axis, eventName, { point: point, brk: brk });
  2073. }
  2074. }
  2075. });
  2076. });
  2077. });
  2078. }
  2079. };
  2080. /**
  2081. * Extend getGraphPath by identifying gaps in the data so that we can
  2082. * draw a gap in the line or area. This was moved from ordinal axis
  2083. * module to broken axis module as of #5045.
  2084. *
  2085. * @private
  2086. * @function Highcharts.Series#gappedPath
  2087. *
  2088. * @return {Highcharts.SVGPathArray}
  2089. * Gapped path
  2090. */
  2091. seriesProto.gappedPath = function () {
  2092. var currentDataGrouping = this.currentDataGrouping,
  2093. groupingSize = currentDataGrouping && currentDataGrouping.gapSize,
  2094. gapSize = this.options.gapSize,
  2095. points = this.points.slice(),
  2096. i = points.length - 1,
  2097. yAxis = this.yAxis,
  2098. stack;
  2099. /**
  2100. * Defines when to display a gap in the graph, together with the
  2101. * [gapUnit](plotOptions.series.gapUnit) option.
  2102. *
  2103. * In case when `dataGrouping` is enabled, points can be grouped
  2104. * into a larger time span. This can make the grouped points to have
  2105. * a greater distance than the absolute value of `gapSize` property,
  2106. * which will result in disappearing graph completely. To prevent
  2107. * this situation the mentioned distance between grouped points is
  2108. * used instead of previously defined `gapSize`.
  2109. *
  2110. * In practice, this option is most often used to visualize gaps in
  2111. * time series. In a stock chart, intraday data is available for
  2112. * daytime hours, while gaps will appear in nights and weekends.
  2113. *
  2114. * @see [gapUnit](plotOptions.series.gapUnit)
  2115. * @see [xAxis.breaks](#xAxis.breaks)
  2116. *
  2117. * @sample {highstock} stock/plotoptions/series-gapsize/
  2118. * Setting the gap size to 2 introduces gaps for weekends
  2119. * in daily datasets.
  2120. *
  2121. * @type {number}
  2122. * @default 0
  2123. * @product highstock
  2124. * @requires modules/broken-axis
  2125. * @apioption plotOptions.series.gapSize
  2126. */
  2127. /**
  2128. * Together with [gapSize](plotOptions.series.gapSize), this option
  2129. * defines where to draw gaps in the graph.
  2130. *
  2131. * When the `gapUnit` is `"relative"` (default), a gap size of 5
  2132. * means that if the distance between two points is greater than
  2133. * 5 times that of the two closest points, the graph will be broken.
  2134. *
  2135. * When the `gapUnit` is `"value"`, the gap is based on absolute
  2136. * axis values, which on a datetime axis is milliseconds. This also
  2137. * applies to the navigator series that inherits gap options from
  2138. * the base series.
  2139. *
  2140. * @see [gapSize](plotOptions.series.gapSize)
  2141. *
  2142. * @type {string}
  2143. * @default relative
  2144. * @since 5.0.13
  2145. * @product highstock
  2146. * @validvalue ["relative", "value"]
  2147. * @requires modules/broken-axis
  2148. * @apioption plotOptions.series.gapUnit
  2149. */
  2150. if (gapSize && i > 0) { // #5008
  2151. // Gap unit is relative
  2152. if (this.options.gapUnit !== 'value') {
  2153. gapSize *= this.basePointRange;
  2154. }
  2155. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  2156. if (groupingSize &&
  2157. groupingSize > gapSize &&
  2158. // Except when DG is forced (e.g. from other series)
  2159. // and has lower granularity than actual points (#11351)
  2160. groupingSize >= this.basePointRange) {
  2161. gapSize = groupingSize;
  2162. }
  2163. // extension for ordinal breaks
  2164. var current = void 0,
  2165. next = void 0;
  2166. while (i--) {
  2167. // Reassign next if it is not visible
  2168. if (!(next && next.visible !== false)) {
  2169. next = points[i + 1];
  2170. }
  2171. current = points[i];
  2172. // Skip iteration if one of the points is not visible
  2173. if (next.visible === false || current.visible === false) {
  2174. continue;
  2175. }
  2176. if (next.x - current.x > gapSize) {
  2177. var xRange = (current.x + next.x) / 2;
  2178. points.splice(// insert after this one
  2179. i + 1, 0, {
  2180. isNull: true,
  2181. x: xRange
  2182. });
  2183. // For stacked chart generate empty stack items, #6546
  2184. if (yAxis.stacking && this.options.stacking) {
  2185. stack = yAxis.stacking.stacks[this.stackKey][xRange] =
  2186. new StackItem(yAxis, yAxis.options
  2187. .stackLabels, false, xRange, this.stack);
  2188. stack.total = 0;
  2189. }
  2190. }
  2191. // Assign current to next for the upcoming iteration
  2192. next = current;
  2193. }
  2194. }
  2195. // Call base method
  2196. return this.getGraphPath(points);
  2197. };
  2198. /* eslint-disable no-invalid-this */
  2199. addEvent(AxisClass, 'init', function () {
  2200. var axis = this;
  2201. if (!axis.brokenAxis) {
  2202. axis.brokenAxis = new BrokenAxisAdditions(axis);
  2203. }
  2204. });
  2205. addEvent(AxisClass, 'afterInit', function () {
  2206. if (typeof this.brokenAxis !== 'undefined') {
  2207. this.brokenAxis.setBreaks(this.options.breaks, false);
  2208. }
  2209. });
  2210. addEvent(AxisClass, 'afterSetTickPositions', function () {
  2211. var axis = this;
  2212. var brokenAxis = axis.brokenAxis;
  2213. if (brokenAxis &&
  2214. brokenAxis.hasBreaks) {
  2215. var tickPositions = this.tickPositions,
  2216. info = this.tickPositions.info,
  2217. newPositions = [],
  2218. i;
  2219. for (i = 0; i < tickPositions.length; i++) {
  2220. if (!brokenAxis.isInAnyBreak(tickPositions[i])) {
  2221. newPositions.push(tickPositions[i]);
  2222. }
  2223. }
  2224. this.tickPositions = newPositions;
  2225. this.tickPositions.info = info;
  2226. }
  2227. });
  2228. // Force Axis to be not-ordinal when breaks are defined
  2229. addEvent(AxisClass, 'afterSetOptions', function () {
  2230. if (this.brokenAxis && this.brokenAxis.hasBreaks) {
  2231. this.options.ordinal = false;
  2232. }
  2233. });
  2234. addEvent(SeriesClass, 'afterGeneratePoints', function () {
  2235. var _a = this,
  2236. isDirty = _a.isDirty,
  2237. connectNulls = _a.options.connectNulls,
  2238. points = _a.points,
  2239. xAxis = _a.xAxis,
  2240. yAxis = _a.yAxis;
  2241. // Set, or reset visibility of the points. Axis.setBreaks marks the
  2242. // series as isDirty
  2243. if (isDirty) {
  2244. var i = points.length;
  2245. while (i--) {
  2246. var point = points[i];
  2247. // Respect nulls inside the break (#4275)
  2248. var nullGap = point.y === null && connectNulls === false;
  2249. var isPointInBreak = (!nullGap && ((xAxis &&
  2250. xAxis.brokenAxis &&
  2251. xAxis.brokenAxis.isInAnyBreak(point.x,
  2252. true)) || (yAxis &&
  2253. yAxis.brokenAxis &&
  2254. yAxis.brokenAxis.isInAnyBreak(point.y,
  2255. true))));
  2256. // Set point.visible if in any break.
  2257. // If not in break, reset visible to original value.
  2258. point.visible = isPointInBreak ?
  2259. false :
  2260. point.options.visible !== false;
  2261. }
  2262. }
  2263. });
  2264. addEvent(SeriesClass, 'afterRender', function drawPointsWrapped() {
  2265. this.drawBreaks(this.xAxis, ['x']);
  2266. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  2267. });
  2268. };
  2269. return BrokenAxis;
  2270. }());
  2271. BrokenAxis.compose(Axis, Series); // @todo remove automatism
  2272. return BrokenAxis;
  2273. });
  2274. _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) {
  2275. /* *
  2276. *
  2277. * (c) 2016 Highsoft AS
  2278. * Authors: Jon Arild Nygard
  2279. *
  2280. * License: www.highcharts.com/license
  2281. *
  2282. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2283. *
  2284. * */
  2285. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  2286. var addEvent = U.addEvent,
  2287. find = U.find,
  2288. fireEvent = U.fireEvent,
  2289. isNumber = U.isNumber,
  2290. isObject = U.isObject,
  2291. isString = U.isString,
  2292. merge = U.merge,
  2293. pick = U.pick,
  2294. wrap = U.wrap;
  2295. /**
  2296. * @private
  2297. */
  2298. var TreeGridAxis;
  2299. (function (TreeGridAxis) {
  2300. /* *
  2301. *
  2302. * Interfaces
  2303. *
  2304. * */
  2305. /* *
  2306. *
  2307. * Variables
  2308. *
  2309. * */
  2310. var applied = false;
  2311. /* *
  2312. *
  2313. * Functions
  2314. *
  2315. * */
  2316. /**
  2317. * @private
  2318. */
  2319. function compose(AxisClass) {
  2320. if (!applied) {
  2321. wrap(AxisClass.prototype, 'generateTick', wrapGenerateTick);
  2322. wrap(AxisClass.prototype, 'getMaxLabelDimensions', wrapGetMaxLabelDimensions);
  2323. wrap(AxisClass.prototype, 'init', wrapInit);
  2324. wrap(AxisClass.prototype, 'setTickInterval', wrapSetTickInterval);
  2325. TreeGridTick.compose(Tick);
  2326. applied = true;
  2327. }
  2328. }
  2329. TreeGridAxis.compose = compose;
  2330. /**
  2331. * @private
  2332. */
  2333. function getBreakFromNode(node, max) {
  2334. var from = node.collapseStart || 0,
  2335. to = node.collapseEnd || 0;
  2336. // In broken-axis, the axis.max is minimized until it is not within a
  2337. // break. Therefore, if break.to is larger than axis.max, the axis.to
  2338. // should not add the 0.5 axis.tickMarkOffset, to avoid adding a break
  2339. // larger than axis.max.
  2340. // TODO consider simplifying broken-axis and this might solve itself
  2341. if (to >= max) {
  2342. from -= 0.5;
  2343. }
  2344. return {
  2345. from: from,
  2346. to: to,
  2347. showPoints: false
  2348. };
  2349. }
  2350. /**
  2351. * Creates a tree structure of the data, and the treegrid. Calculates
  2352. * categories, and y-values of points based on the tree.
  2353. *
  2354. * @private
  2355. * @function getTreeGridFromData
  2356. *
  2357. * @param {Array<Highcharts.GanttPointOptions>} data
  2358. * All the data points to display in the axis.
  2359. *
  2360. * @param {boolean} uniqueNames
  2361. * Wether or not the data node with the same name should share grid cell. If
  2362. * true they do share cell. False by default.
  2363. *
  2364. * @param {number} numberOfSeries
  2365. *
  2366. * @return {object}
  2367. * Returns an object containing categories, mapOfIdToNode,
  2368. * mapOfPosToGridNode, and tree.
  2369. *
  2370. * @todo There should be only one point per line.
  2371. * @todo It should be optional to have one category per point, or merge
  2372. * cells
  2373. * @todo Add unit-tests.
  2374. */
  2375. function getTreeGridFromData(data, uniqueNames, numberOfSeries) {
  2376. var categories = [],
  2377. collapsedNodes = [],
  2378. mapOfIdToNode = {},
  2379. mapOfPosToGridNode = {},
  2380. posIterator = -1,
  2381. uniqueNamesEnabled = typeof uniqueNames === 'boolean' ? uniqueNames : false,
  2382. tree;
  2383. // Build the tree from the series data.
  2384. var treeParams = {
  2385. // After the children has been created.
  2386. after: function (node) {
  2387. var gridNode = mapOfPosToGridNode[node.pos],
  2388. height = 0,
  2389. descendants = 0;
  2390. gridNode.children.forEach(function (child) {
  2391. descendants += (child.descendants || 0) + 1;
  2392. height = Math.max((child.height || 0) + 1, height);
  2393. });
  2394. gridNode.descendants = descendants;
  2395. gridNode.height = height;
  2396. if (gridNode.collapsed) {
  2397. collapsedNodes.push(gridNode);
  2398. }
  2399. },
  2400. // Before the children has been created.
  2401. before: function (node) {
  2402. var data = isObject(node.data,
  2403. true) ? node.data : {},
  2404. name = isString(data.name) ? data.name : '',
  2405. parentNode = mapOfIdToNode[node.parent],
  2406. parentGridNode = (isObject(parentNode,
  2407. true) ?
  2408. mapOfPosToGridNode[parentNode.pos] :
  2409. null),
  2410. hasSameName = function (x) {
  2411. return x.name === name;
  2412. }, gridNode, pos;
  2413. // If not unique names, look for sibling node with the same name
  2414. if (uniqueNamesEnabled &&
  2415. isObject(parentGridNode, true) &&
  2416. !!(gridNode = find(parentGridNode.children, hasSameName))) {
  2417. // If there is a gridNode with the same name, reuse position
  2418. pos = gridNode.pos;
  2419. // Add data node to list of nodes in the grid node.
  2420. gridNode.nodes.push(node);
  2421. }
  2422. else {
  2423. // If it is a new grid node, increment position.
  2424. pos = posIterator++;
  2425. }
  2426. // Add new grid node to map.
  2427. if (!mapOfPosToGridNode[pos]) {
  2428. mapOfPosToGridNode[pos] = gridNode = {
  2429. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  2430. name: name,
  2431. nodes: [node],
  2432. children: [],
  2433. pos: pos
  2434. };
  2435. // If not root, then add name to categories.
  2436. if (pos !== -1) {
  2437. categories.push(name);
  2438. }
  2439. // Add name to list of children.
  2440. if (isObject(parentGridNode, true)) {
  2441. parentGridNode.children.push(gridNode);
  2442. }
  2443. }
  2444. // Add data node to map
  2445. if (isString(node.id)) {
  2446. mapOfIdToNode[node.id] = node;
  2447. }
  2448. // If one of the points are collapsed, then start the grid node
  2449. // in collapsed state.
  2450. if (gridNode &&
  2451. data.collapsed === true) {
  2452. gridNode.collapsed = true;
  2453. }
  2454. // Assign pos to data node
  2455. node.pos = pos;
  2456. }
  2457. };
  2458. var updateYValuesAndTickPos = function (map,
  2459. numberOfSeries) {
  2460. var setValues = function (gridNode,
  2461. start,
  2462. result) {
  2463. var nodes = gridNode.nodes,
  2464. end = start + (start === -1 ? 0 : numberOfSeries - 1),
  2465. diff = (end - start) / 2,
  2466. padding = 0.5,
  2467. pos = start + diff;
  2468. nodes.forEach(function (node) {
  2469. var data = node.data;
  2470. if (isObject(data, true)) {
  2471. // Update point
  2472. data.y = start + (data.seriesIndex || 0);
  2473. // Remove the property once used
  2474. delete data.seriesIndex;
  2475. }
  2476. node.pos = pos;
  2477. });
  2478. result[pos] = gridNode;
  2479. gridNode.pos = pos;
  2480. gridNode.tickmarkOffset = diff + padding;
  2481. gridNode.collapseStart = end + padding;
  2482. gridNode.children.forEach(function (child) {
  2483. setValues(child, end + 1, result);
  2484. end = (child.collapseEnd || 0) - padding;
  2485. });
  2486. // Set collapseEnd to the end of the last child node.
  2487. gridNode.collapseEnd = end + padding;
  2488. return result;
  2489. };
  2490. return setValues(map['-1'], -1, {});
  2491. };
  2492. // Create tree from data
  2493. tree = Tree.getTree(data, treeParams);
  2494. // Update y values of data, and set calculate tick positions.
  2495. mapOfPosToGridNode = updateYValuesAndTickPos(mapOfPosToGridNode, numberOfSeries);
  2496. // Return the resulting data.
  2497. return {
  2498. categories: categories,
  2499. mapOfIdToNode: mapOfIdToNode,
  2500. mapOfPosToGridNode: mapOfPosToGridNode,
  2501. collapsedNodes: collapsedNodes,
  2502. tree: tree
  2503. };
  2504. }
  2505. /**
  2506. * Builds the tree of categories and calculates its positions.
  2507. * @private
  2508. * @param {object} e Event object
  2509. * @param {object} e.target The chart instance which the event was fired on.
  2510. * @param {object[]} e.target.axes The axes of the chart.
  2511. */
  2512. function onBeforeRender(e) {
  2513. var chart = e.target,
  2514. axes = chart.axes;
  2515. axes.filter(function (axis) {
  2516. return axis.options.type === 'treegrid';
  2517. }).forEach(function (axis) {
  2518. var options = axis.options || {},
  2519. labelOptions = options.labels,
  2520. uniqueNames = options.uniqueNames,
  2521. numberOfSeries = 0,
  2522. isDirty,
  2523. data,
  2524. treeGrid,
  2525. max = options.max;
  2526. // Check whether any of series is rendering for the first time,
  2527. // visibility has changed, or its data is dirty,
  2528. // and only then update. #10570, #10580
  2529. // Also check if mapOfPosToGridNode exists. #10887
  2530. isDirty = (!axis.treeGrid.mapOfPosToGridNode ||
  2531. axis.series.some(function (series) {
  2532. return !series.hasRendered ||
  2533. series.isDirtyData ||
  2534. series.isDirty;
  2535. }));
  2536. if (isDirty) {
  2537. // Concatenate data from all series assigned to this axis.
  2538. data = axis.series.reduce(function (arr, s) {
  2539. if (s.visible) {
  2540. // Push all data to array
  2541. (s.options.data || []).forEach(function (data) {
  2542. if (isObject(data, true)) {
  2543. // Set series index on data. Removed again
  2544. // after use.
  2545. data.seriesIndex = numberOfSeries;
  2546. arr.push(data);
  2547. }
  2548. });
  2549. // Increment series index
  2550. if (uniqueNames === true) {
  2551. numberOfSeries++;
  2552. }
  2553. }
  2554. return arr;
  2555. }, []);
  2556. // If max is higher than set data - add a
  2557. // dummy data to render categories #10779
  2558. if (max && data.length < max) {
  2559. for (var i = data.length; i <= max; i++) {
  2560. data.push({
  2561. // Use the zero-width character
  2562. // to avoid conflict with uniqueNames
  2563. name: i + '\u200B'
  2564. });
  2565. }
  2566. }
  2567. // setScale is fired after all the series is initialized,
  2568. // which is an ideal time to update the axis.categories.
  2569. treeGrid = getTreeGridFromData(data, uniqueNames || false, (uniqueNames === true) ? numberOfSeries : 1);
  2570. // Assign values to the axis.
  2571. axis.categories = treeGrid.categories;
  2572. axis.treeGrid.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  2573. axis.hasNames = true;
  2574. axis.treeGrid.tree = treeGrid.tree;
  2575. // Update yData now that we have calculated the y values
  2576. axis.series.forEach(function (series) {
  2577. var data = (series.options.data || []).map(function (d) {
  2578. return isObject(d,
  2579. true) ? merge(d) : d;
  2580. });
  2581. // Avoid destroying points when series is not visible
  2582. if (series.visible) {
  2583. series.setData(data, false);
  2584. }
  2585. });
  2586. // Calculate the label options for each level in the tree.
  2587. axis.treeGrid.mapOptionsToLevel =
  2588. getLevelOptions({
  2589. defaults: labelOptions,
  2590. from: 1,
  2591. levels: labelOptions && labelOptions.levels,
  2592. to: axis.treeGrid.tree && axis.treeGrid.tree.height
  2593. });
  2594. // Setting initial collapsed nodes
  2595. if (e.type === 'beforeRender') {
  2596. axis.treeGrid.collapsedNodes = treeGrid.collapsedNodes;
  2597. }
  2598. }
  2599. });
  2600. }
  2601. /**
  2602. * Generates a tick for initial positioning.
  2603. *
  2604. * @private
  2605. * @function Highcharts.GridAxis#generateTick
  2606. *
  2607. * @param {Function} proceed
  2608. * The original generateTick function.
  2609. *
  2610. * @param {number} pos
  2611. * The tick position in axis values.
  2612. */
  2613. function wrapGenerateTick(proceed, pos) {
  2614. var axis = this,
  2615. mapOptionsToLevel = axis.treeGrid.mapOptionsToLevel || {},
  2616. isTreeGrid = axis.options.type === 'treegrid',
  2617. ticks = axis.ticks;
  2618. var tick = ticks[pos],
  2619. levelOptions,
  2620. options,
  2621. gridNode;
  2622. if (isTreeGrid &&
  2623. axis.treeGrid.mapOfPosToGridNode) {
  2624. gridNode = axis.treeGrid.mapOfPosToGridNode[pos];
  2625. levelOptions = mapOptionsToLevel[gridNode.depth];
  2626. if (levelOptions) {
  2627. options = {
  2628. labels: levelOptions
  2629. };
  2630. }
  2631. if (!tick) {
  2632. ticks[pos] = tick =
  2633. new Tick(axis, pos, void 0, void 0, {
  2634. category: gridNode.name,
  2635. tickmarkOffset: gridNode.tickmarkOffset,
  2636. options: options
  2637. });
  2638. }
  2639. else {
  2640. // update labels depending on tick interval
  2641. tick.parameters.category = gridNode.name;
  2642. tick.options = options;
  2643. tick.addLabel();
  2644. }
  2645. }
  2646. else {
  2647. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2648. }
  2649. }
  2650. /**
  2651. * Override to add indentation to axis.maxLabelDimensions.
  2652. *
  2653. * @private
  2654. * @function Highcharts.GridAxis#getMaxLabelDimensions
  2655. *
  2656. * @param {Function} proceed
  2657. * The original function
  2658. */
  2659. function wrapGetMaxLabelDimensions(proceed) {
  2660. var axis = this,
  2661. options = axis.options,
  2662. labelOptions = options && options.labels,
  2663. indentation = (labelOptions && isNumber(labelOptions.indentation) ?
  2664. labelOptions.indentation :
  2665. 0),
  2666. retVal = proceed.apply(axis,
  2667. Array.prototype.slice.call(arguments, 1)),
  2668. isTreeGrid = axis.options.type === 'treegrid';
  2669. var treeDepth;
  2670. if (isTreeGrid && axis.treeGrid.mapOfPosToGridNode) {
  2671. treeDepth = axis.treeGrid.mapOfPosToGridNode[-1].height || 0;
  2672. retVal.width += indentation * (treeDepth - 1);
  2673. }
  2674. return retVal;
  2675. }
  2676. /**
  2677. * @private
  2678. */
  2679. function wrapInit(proceed, chart, userOptions) {
  2680. var axis = this,
  2681. isTreeGrid = userOptions.type === 'treegrid';
  2682. if (!axis.treeGrid) {
  2683. axis.treeGrid = new Additions(axis);
  2684. }
  2685. // Set default and forced options for TreeGrid
  2686. if (isTreeGrid) {
  2687. // Add event for updating the categories of a treegrid.
  2688. // NOTE Preferably these events should be set on the axis.
  2689. addEvent(chart, 'beforeRender', onBeforeRender);
  2690. addEvent(chart, 'beforeRedraw', onBeforeRender);
  2691. // Add new collapsed nodes on addseries
  2692. addEvent(chart, 'addSeries', function (e) {
  2693. if (e.options.data) {
  2694. var treeGrid = getTreeGridFromData(e.options.data,
  2695. userOptions.uniqueNames || false, 1);
  2696. axis.treeGrid.collapsedNodes = (axis.treeGrid.collapsedNodes || []).concat(treeGrid.collapsedNodes);
  2697. }
  2698. });
  2699. // Collapse all nodes in axis.treegrid.collapsednodes
  2700. // where collapsed equals true.
  2701. addEvent(axis, 'foundExtremes', function () {
  2702. if (axis.treeGrid.collapsedNodes) {
  2703. axis.treeGrid.collapsedNodes.forEach(function (node) {
  2704. var breaks = axis.treeGrid.collapse(node);
  2705. if (axis.brokenAxis) {
  2706. axis.brokenAxis.setBreaks(breaks, false);
  2707. // remove the node from the axis collapsedNodes
  2708. if (axis.treeGrid.collapsedNodes) {
  2709. axis.treeGrid.collapsedNodes = axis.treeGrid.collapsedNodes.filter(function (n) {
  2710. return node.collapseStart !== n.collapseStart ||
  2711. node.collapseEnd !== n.collapseEnd;
  2712. });
  2713. }
  2714. }
  2715. });
  2716. }
  2717. });
  2718. // If staticScale is not defined on the yAxis
  2719. // and chart height is set, set axis.isDirty
  2720. // to ensure collapsing works (#12012)
  2721. addEvent(axis, 'afterBreaks', function () {
  2722. var _a;
  2723. if (axis.coll === 'yAxis' && !axis.staticScale && ((_a = axis.chart.options.chart) === null || _a === void 0 ? void 0 : _a.height)) {
  2724. axis.isDirty = true;
  2725. }
  2726. });
  2727. userOptions = merge({
  2728. // Default options
  2729. grid: {
  2730. enabled: true
  2731. },
  2732. // TODO: add support for align in treegrid.
  2733. labels: {
  2734. align: 'left',
  2735. /**
  2736. * Set options on specific levels in a tree grid axis. Takes
  2737. * precedence over labels options.
  2738. *
  2739. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2740. * Levels on TreeGrid Labels
  2741. *
  2742. * @type {Array<*>}
  2743. * @product gantt
  2744. * @apioption yAxis.labels.levels
  2745. *
  2746. * @private
  2747. */
  2748. levels: [{
  2749. /**
  2750. * Specify the level which the options within this object
  2751. * applies to.
  2752. *
  2753. * @type {number}
  2754. * @product gantt
  2755. * @apioption yAxis.labels.levels.level
  2756. *
  2757. * @private
  2758. */
  2759. level: void 0
  2760. }, {
  2761. level: 1,
  2762. /**
  2763. * @type {Highcharts.CSSObject}
  2764. * @product gantt
  2765. * @apioption yAxis.labels.levels.style
  2766. *
  2767. * @private
  2768. */
  2769. style: {
  2770. /** @ignore-option */
  2771. fontWeight: 'bold'
  2772. }
  2773. }],
  2774. /**
  2775. * The symbol for the collapse and expand icon in a
  2776. * treegrid.
  2777. *
  2778. * @product gantt
  2779. * @optionparent yAxis.labels.symbol
  2780. *
  2781. * @private
  2782. */
  2783. symbol: {
  2784. /**
  2785. * The symbol type. Points to a definition function in
  2786. * the `Highcharts.Renderer.symbols` collection.
  2787. *
  2788. * @type {Highcharts.SymbolKeyValue}
  2789. *
  2790. * @private
  2791. */
  2792. type: 'triangle',
  2793. x: -5,
  2794. y: -5,
  2795. height: 10,
  2796. width: 10,
  2797. padding: 5
  2798. }
  2799. },
  2800. uniqueNames: false
  2801. }, userOptions, {
  2802. // Forced options
  2803. reversed: true,
  2804. // grid.columns is not supported in treegrid
  2805. grid: {
  2806. columns: void 0
  2807. }
  2808. });
  2809. }
  2810. // Now apply the original function with the original arguments,
  2811. // which are sliced off this function's arguments
  2812. proceed.apply(axis, [chart, userOptions]);
  2813. if (isTreeGrid) {
  2814. axis.hasNames = true;
  2815. axis.options.showLastLabel = true;
  2816. }
  2817. }
  2818. /**
  2819. * Set the tick positions, tickInterval, axis min and max.
  2820. *
  2821. * @private
  2822. * @function Highcharts.GridAxis#setTickInterval
  2823. *
  2824. * @param {Function} proceed
  2825. * The original setTickInterval function.
  2826. */
  2827. function wrapSetTickInterval(proceed) {
  2828. var axis = this,
  2829. options = axis.options,
  2830. isTreeGrid = options.type === 'treegrid';
  2831. if (isTreeGrid) {
  2832. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  2833. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  2834. fireEvent(axis, 'foundExtremes');
  2835. // setAxisTranslation modifies the min and max according to
  2836. // axis breaks.
  2837. axis.setAxisTranslation(true);
  2838. axis.tickmarkOffset = 0.5;
  2839. axis.tickInterval = 1;
  2840. axis.tickPositions = axis.treeGrid.mapOfPosToGridNode ?
  2841. axis.treeGrid.getTickPositions() :
  2842. [];
  2843. }
  2844. else {
  2845. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2846. }
  2847. }
  2848. /* *
  2849. *
  2850. * Classes
  2851. *
  2852. * */
  2853. /**
  2854. * @private
  2855. * @class
  2856. */
  2857. var Additions = /** @class */ (function () {
  2858. /* *
  2859. *
  2860. * Constructors
  2861. *
  2862. * */
  2863. /**
  2864. * @private
  2865. */
  2866. function Additions(axis) {
  2867. this.axis = axis;
  2868. }
  2869. /* *
  2870. *
  2871. * Functions
  2872. *
  2873. * */
  2874. /**
  2875. * Calculates the new axis breaks to collapse a node.
  2876. *
  2877. * @private
  2878. *
  2879. * @param {Highcharts.Axis} axis
  2880. * The axis to check against.
  2881. *
  2882. * @param {Highcharts.GridNode} node
  2883. * The node to collapse.
  2884. *
  2885. * @param {number} pos
  2886. * The tick position to collapse.
  2887. *
  2888. * @return {Array<object>}
  2889. * Returns an array of the new breaks for the axis.
  2890. */
  2891. Additions.prototype.collapse = function (node) {
  2892. var axis = this.axis,
  2893. breaks = (axis.options.breaks || []),
  2894. obj = getBreakFromNode(node,
  2895. axis.max);
  2896. breaks.push(obj);
  2897. return breaks;
  2898. };
  2899. /**
  2900. * Calculates the new axis breaks to expand a node.
  2901. *
  2902. * @private
  2903. *
  2904. * @param {Highcharts.Axis} axis
  2905. * The axis to check against.
  2906. *
  2907. * @param {Highcharts.GridNode} node
  2908. * The node to expand.
  2909. *
  2910. * @param {number} pos
  2911. * The tick position to expand.
  2912. *
  2913. * @return {Array<object>}
  2914. * Returns an array of the new breaks for the axis.
  2915. */
  2916. Additions.prototype.expand = function (node) {
  2917. var axis = this.axis,
  2918. breaks = (axis.options.breaks || []),
  2919. obj = getBreakFromNode(node,
  2920. axis.max);
  2921. // Remove the break from the axis breaks array.
  2922. return breaks.reduce(function (arr, b) {
  2923. if (b.to !== obj.to || b.from !== obj.from) {
  2924. arr.push(b);
  2925. }
  2926. return arr;
  2927. }, []);
  2928. };
  2929. /**
  2930. * Creates a list of positions for the ticks on the axis. Filters out
  2931. * positions that are outside min and max, or is inside an axis break.
  2932. *
  2933. * @private
  2934. *
  2935. * @return {Array<number>}
  2936. * List of positions.
  2937. */
  2938. Additions.prototype.getTickPositions = function () {
  2939. var axis = this.axis;
  2940. return Object.keys(axis.treeGrid.mapOfPosToGridNode || {}).reduce(function (arr, key) {
  2941. var pos = +key;
  2942. if (axis.min <= pos &&
  2943. axis.max >= pos &&
  2944. !(axis.brokenAxis && axis.brokenAxis.isInAnyBreak(pos))) {
  2945. arr.push(pos);
  2946. }
  2947. return arr;
  2948. }, []);
  2949. };
  2950. /**
  2951. * Check if a node is collapsed.
  2952. *
  2953. * @private
  2954. *
  2955. * @param {Highcharts.Axis} axis
  2956. * The axis to check against.
  2957. *
  2958. * @param {object} node
  2959. * The node to check if is collapsed.
  2960. *
  2961. * @param {number} pos
  2962. * The tick position to collapse.
  2963. *
  2964. * @return {boolean}
  2965. * Returns true if collapsed, false if expanded.
  2966. */
  2967. Additions.prototype.isCollapsed = function (node) {
  2968. var axis = this.axis,
  2969. breaks = (axis.options.breaks || []),
  2970. obj = getBreakFromNode(node,
  2971. axis.max);
  2972. return breaks.some(function (b) {
  2973. return b.from === obj.from && b.to === obj.to;
  2974. });
  2975. };
  2976. /**
  2977. * Calculates the new axis breaks after toggling the collapse/expand
  2978. * state of a node. If it is collapsed it will be expanded, and if it is
  2979. * exapended it will be collapsed.
  2980. *
  2981. * @private
  2982. *
  2983. * @param {Highcharts.Axis} axis
  2984. * The axis to check against.
  2985. *
  2986. * @param {Highcharts.GridNode} node
  2987. * The node to toggle.
  2988. *
  2989. * @return {Array<object>}
  2990. * Returns an array of the new breaks for the axis.
  2991. */
  2992. Additions.prototype.toggleCollapse = function (node) {
  2993. return (this.isCollapsed(node) ?
  2994. this.expand(node) :
  2995. this.collapse(node));
  2996. };
  2997. return Additions;
  2998. }());
  2999. TreeGridAxis.Additions = Additions;
  3000. })(TreeGridAxis || (TreeGridAxis = {}));
  3001. // Make utility functions available for testing.
  3002. Axis.prototype.utils = {
  3003. getNode: Tree.getNode
  3004. };
  3005. TreeGridAxis.compose(Axis);
  3006. return TreeGridAxis;
  3007. });
  3008. _registerModule(_modules, 'masters/modules/treegrid.src.js', [], function () {
  3009. });
  3010. }));