sankey.src.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. /**
  2. * @license Highcharts JS v8.1.2 (2020-06-16)
  3. *
  4. * Sankey diagram module
  5. *
  6. * (c) 2010-2019 Torstein Honsi
  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/sankey', ['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, 'mixins/nodes.js', [_modules['parts/Globals.js'], _modules['parts/Point.js'], _modules['parts/Utilities.js']], function (H, Point, U) {
  32. /* *
  33. *
  34. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  35. *
  36. * */
  37. var defined = U.defined, extend = U.extend, find = U.find, pick = U.pick;
  38. H.NodesMixin = {
  39. /* eslint-disable valid-jsdoc */
  40. /**
  41. * Create a single node that holds information on incoming and outgoing
  42. * links.
  43. * @private
  44. */
  45. createNode: function (id) {
  46. /**
  47. * @private
  48. */
  49. function findById(nodes, id) {
  50. return find(nodes, function (node) {
  51. return node.id === id;
  52. });
  53. }
  54. var node = findById(this.nodes, id), PointClass = this.pointClass, options;
  55. if (!node) {
  56. options = this.options.nodes && findById(this.options.nodes, id);
  57. node = (new PointClass()).init(this, extend({
  58. className: 'highcharts-node',
  59. isNode: true,
  60. id: id,
  61. y: 1 // Pass isNull test
  62. }, options));
  63. node.linksTo = [];
  64. node.linksFrom = [];
  65. node.formatPrefix = 'node';
  66. node.name = node.name || node.options.id || ''; // for use in formats
  67. // Mass is used in networkgraph:
  68. node.mass = pick(
  69. // Node:
  70. node.options.mass, node.options.marker && node.options.marker.radius,
  71. // Series:
  72. this.options.marker && this.options.marker.radius,
  73. // Default:
  74. 4);
  75. /**
  76. * Return the largest sum of either the incoming or outgoing links.
  77. * @private
  78. */
  79. node.getSum = function () {
  80. var sumTo = 0, sumFrom = 0;
  81. node.linksTo.forEach(function (link) {
  82. sumTo += link.weight;
  83. });
  84. node.linksFrom.forEach(function (link) {
  85. sumFrom += link.weight;
  86. });
  87. return Math.max(sumTo, sumFrom);
  88. };
  89. /**
  90. * Get the offset in weight values of a point/link.
  91. * @private
  92. */
  93. node.offset = function (point, coll) {
  94. var offset = 0;
  95. for (var i = 0; i < node[coll].length; i++) {
  96. if (node[coll][i] === point) {
  97. return offset;
  98. }
  99. offset += node[coll][i].weight;
  100. }
  101. };
  102. // Return true if the node has a shape, otherwise all links are
  103. // outgoing.
  104. node.hasShape = function () {
  105. var outgoing = 0;
  106. node.linksTo.forEach(function (link) {
  107. if (link.outgoing) {
  108. outgoing++;
  109. }
  110. });
  111. return (!node.linksTo.length ||
  112. outgoing !== node.linksTo.length);
  113. };
  114. this.nodes.push(node);
  115. }
  116. return node;
  117. },
  118. /**
  119. * Extend generatePoints by adding the nodes, which are Point objects
  120. * but pushed to the this.nodes array.
  121. */
  122. generatePoints: function () {
  123. var chart = this.chart, nodeLookup = {};
  124. H.Series.prototype.generatePoints.call(this);
  125. if (!this.nodes) {
  126. this.nodes = []; // List of Point-like node items
  127. }
  128. this.colorCounter = 0;
  129. // Reset links from previous run
  130. this.nodes.forEach(function (node) {
  131. node.linksFrom.length = 0;
  132. node.linksTo.length = 0;
  133. node.level = node.options.level;
  134. });
  135. // Create the node list and set up links
  136. this.points.forEach(function (point) {
  137. if (defined(point.from)) {
  138. if (!nodeLookup[point.from]) {
  139. nodeLookup[point.from] = this.createNode(point.from);
  140. }
  141. nodeLookup[point.from].linksFrom.push(point);
  142. point.fromNode = nodeLookup[point.from];
  143. // Point color defaults to the fromNode's color
  144. if (chart.styledMode) {
  145. point.colorIndex = pick(point.options.colorIndex, nodeLookup[point.from].colorIndex);
  146. }
  147. else {
  148. point.color =
  149. point.options.color || nodeLookup[point.from].color;
  150. }
  151. }
  152. if (defined(point.to)) {
  153. if (!nodeLookup[point.to]) {
  154. nodeLookup[point.to] = this.createNode(point.to);
  155. }
  156. nodeLookup[point.to].linksTo.push(point);
  157. point.toNode = nodeLookup[point.to];
  158. }
  159. point.name = point.name || point.id; // for use in formats
  160. }, this);
  161. // Store lookup table for later use
  162. this.nodeLookup = nodeLookup;
  163. },
  164. // Destroy all nodes on setting new data
  165. setData: function () {
  166. if (this.nodes) {
  167. this.nodes.forEach(function (node) {
  168. node.destroy();
  169. });
  170. this.nodes.length = 0;
  171. }
  172. H.Series.prototype.setData.apply(this, arguments);
  173. },
  174. // Destroy alll nodes and links
  175. destroy: function () {
  176. // Nodes must also be destroyed (#8682, #9300)
  177. this.data = []
  178. .concat(this.points || [], this.nodes);
  179. return H.Series.prototype.destroy.apply(this, arguments);
  180. },
  181. /**
  182. * When hovering node, highlight all connected links. When hovering a link,
  183. * highlight all connected nodes.
  184. */
  185. setNodeState: function (state) {
  186. var args = arguments, others = this.isNode ? this.linksTo.concat(this.linksFrom) :
  187. [this.fromNode, this.toNode];
  188. if (state !== 'select') {
  189. others.forEach(function (linkOrNode) {
  190. if (linkOrNode && linkOrNode.series) {
  191. Point.prototype.setState.apply(linkOrNode, args);
  192. if (!linkOrNode.isNode) {
  193. if (linkOrNode.fromNode.graphic) {
  194. Point.prototype.setState.apply(linkOrNode.fromNode, args);
  195. }
  196. if (linkOrNode.toNode && linkOrNode.toNode.graphic) {
  197. Point.prototype.setState.apply(linkOrNode.toNode, args);
  198. }
  199. }
  200. }
  201. });
  202. }
  203. Point.prototype.setState.apply(this, args);
  204. }
  205. /* eslint-enable valid-jsdoc */
  206. };
  207. });
  208. _registerModule(_modules, 'mixins/tree-series.js', [_modules['parts/Color.js'], _modules['parts/Utilities.js']], function (Color, U) {
  209. /* *
  210. *
  211. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  212. *
  213. * */
  214. var extend = U.extend, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, merge = U.merge, pick = U.pick;
  215. var isBoolean = function (x) {
  216. return typeof x === 'boolean';
  217. }, isFn = function (x) {
  218. return typeof x === 'function';
  219. };
  220. /* eslint-disable valid-jsdoc */
  221. /**
  222. * @todo Combine buildTree and buildNode with setTreeValues
  223. * @todo Remove logic from Treemap and make it utilize this mixin.
  224. * @private
  225. */
  226. var setTreeValues = function setTreeValues(tree, options) {
  227. var before = options.before, idRoot = options.idRoot, mapIdToNode = options.mapIdToNode, nodeRoot = mapIdToNode[idRoot], levelIsConstant = (isBoolean(options.levelIsConstant) ?
  228. options.levelIsConstant :
  229. true), points = options.points, point = points[tree.i], optionsPoint = point && point.options || {}, childrenTotal = 0, children = [], value;
  230. extend(tree, {
  231. levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
  232. name: pick(point && point.name, ''),
  233. visible: (idRoot === tree.id ||
  234. (isBoolean(options.visible) ? options.visible : false))
  235. });
  236. if (isFn(before)) {
  237. tree = before(tree, options);
  238. }
  239. // First give the children some values
  240. tree.children.forEach(function (child, i) {
  241. var newOptions = extend({}, options);
  242. extend(newOptions, {
  243. index: i,
  244. siblings: tree.children.length,
  245. visible: tree.visible
  246. });
  247. child = setTreeValues(child, newOptions);
  248. children.push(child);
  249. if (child.visible) {
  250. childrenTotal += child.val;
  251. }
  252. });
  253. tree.visible = childrenTotal > 0 || tree.visible;
  254. // Set the values
  255. value = pick(optionsPoint.value, childrenTotal);
  256. extend(tree, {
  257. children: children,
  258. childrenTotal: childrenTotal,
  259. isLeaf: tree.visible && !childrenTotal,
  260. val: value
  261. });
  262. return tree;
  263. };
  264. /**
  265. * @private
  266. */
  267. var getColor = function getColor(node, options) {
  268. var index = options.index, mapOptionsToLevel = options.mapOptionsToLevel, parentColor = options.parentColor, parentColorIndex = options.parentColorIndex, series = options.series, colors = options.colors, siblings = options.siblings, points = series.points, getColorByPoint, chartOptionsChart = series.chart.options.chart, point, level, colorByPoint, colorIndexByPoint, color, colorIndex;
  269. /**
  270. * @private
  271. */
  272. function variation(color) {
  273. var colorVariation = level && level.colorVariation;
  274. if (colorVariation) {
  275. if (colorVariation.key === 'brightness') {
  276. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  277. }
  278. }
  279. return color;
  280. }
  281. if (node) {
  282. point = points[node.i];
  283. level = mapOptionsToLevel[node.level] || {};
  284. getColorByPoint = point && level.colorByPoint;
  285. if (getColorByPoint) {
  286. colorIndexByPoint = point.index % (colors ?
  287. colors.length :
  288. chartOptionsChart.colorCount);
  289. colorByPoint = colors && colors[colorIndexByPoint];
  290. }
  291. // Select either point color, level color or inherited color.
  292. if (!series.chart.styledMode) {
  293. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  294. }
  295. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  296. }
  297. return {
  298. color: color,
  299. colorIndex: colorIndex
  300. };
  301. };
  302. /**
  303. * Creates a map from level number to its given options.
  304. *
  305. * @private
  306. * @function getLevelOptions
  307. * @param {object} params
  308. * Object containing parameters.
  309. * - `defaults` Object containing default options. The default options
  310. * are merged with the userOptions to get the final options for a
  311. * specific level.
  312. * - `from` The lowest level number.
  313. * - `levels` User options from series.levels.
  314. * - `to` The highest level number.
  315. * @return {Highcharts.Dictionary<object>|null}
  316. * Returns a map from level number to its given options.
  317. */
  318. var getLevelOptions = function getLevelOptions(params) {
  319. var result = null, defaults, converted, i, from, to, levels;
  320. if (isObject(params)) {
  321. result = {};
  322. from = isNumber(params.from) ? params.from : 1;
  323. levels = params.levels;
  324. converted = {};
  325. defaults = isObject(params.defaults) ? params.defaults : {};
  326. if (isArray(levels)) {
  327. converted = levels.reduce(function (obj, item) {
  328. var level, levelIsConstant, options;
  329. if (isObject(item) && isNumber(item.level)) {
  330. options = merge({}, item);
  331. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  332. options.levelIsConstant :
  333. defaults.levelIsConstant);
  334. // Delete redundant properties.
  335. delete options.levelIsConstant;
  336. delete options.level;
  337. // Calculate which level these options apply to.
  338. level = item.level + (levelIsConstant ? 0 : from - 1);
  339. if (isObject(obj[level])) {
  340. extend(obj[level], options);
  341. }
  342. else {
  343. obj[level] = options;
  344. }
  345. }
  346. return obj;
  347. }, {});
  348. }
  349. to = isNumber(params.to) ? params.to : 1;
  350. for (i = 0; i <= to; i++) {
  351. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  352. }
  353. }
  354. return result;
  355. };
  356. /**
  357. * Update the rootId property on the series. Also makes sure that it is
  358. * accessible to exporting.
  359. *
  360. * @private
  361. * @function updateRootId
  362. *
  363. * @param {object} series
  364. * The series to operate on.
  365. *
  366. * @return {string}
  367. * Returns the resulting rootId after update.
  368. */
  369. var updateRootId = function (series) {
  370. var rootId, options;
  371. if (isObject(series)) {
  372. // Get the series options.
  373. options = isObject(series.options) ? series.options : {};
  374. // Calculate the rootId.
  375. rootId = pick(series.rootNode, options.rootId, '');
  376. // Set rootId on series.userOptions to pick it up in exporting.
  377. if (isObject(series.userOptions)) {
  378. series.userOptions.rootId = rootId;
  379. }
  380. // Set rootId on series to pick it up on next update.
  381. series.rootNode = rootId;
  382. }
  383. return rootId;
  384. };
  385. var result = {
  386. getColor: getColor,
  387. getLevelOptions: getLevelOptions,
  388. setTreeValues: setTreeValues,
  389. updateRootId: updateRootId
  390. };
  391. return result;
  392. });
  393. _registerModule(_modules, 'modules/sankey.src.js', [_modules['parts/Globals.js'], _modules['parts/Color.js'], _modules['parts/Point.js'], _modules['parts/Utilities.js'], _modules['mixins/tree-series.js']], function (H, Color, Point, U, mixinTreeSeries) {
  394. /* *
  395. *
  396. * Sankey diagram module
  397. *
  398. * (c) 2010-2020 Torstein Honsi
  399. *
  400. * License: www.highcharts.com/license
  401. *
  402. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  403. *
  404. * */
  405. /**
  406. * A node in a sankey diagram.
  407. *
  408. * @interface Highcharts.SankeyNodeObject
  409. * @extends Highcharts.Point
  410. * @product highcharts
  411. */ /**
  412. * The color of the auto generated node.
  413. *
  414. * @name Highcharts.SankeyNodeObject#color
  415. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  416. */ /**
  417. * The color index of the auto generated node, especially for use in styled
  418. * mode.
  419. *
  420. * @name Highcharts.SankeyNodeObject#colorIndex
  421. * @type {number}
  422. */ /**
  423. * An optional column index of where to place the node. The default behaviour is
  424. * to place it next to the preceding node.
  425. *
  426. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/sankey-node-column/|Highcharts-Demo:}
  427. * Specified node column
  428. *
  429. * @name Highcharts.SankeyNodeObject#column
  430. * @type {number}
  431. * @since 6.0.5
  432. */ /**
  433. * The id of the auto-generated node, refering to the `from` or `to` setting of
  434. * the link.
  435. *
  436. * @name Highcharts.SankeyNodeObject#id
  437. * @type {string}
  438. */ /**
  439. * The name to display for the node in data labels and tooltips. Use this when
  440. * the name is different from the `id`. Where the id must be unique for each
  441. * node, this is not necessary for the name.
  442. *
  443. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/css/sankey/|Highcharts-Demo:}
  444. * Sankey diagram with node options
  445. *
  446. * @name Highcharts.SankeyNodeObject#name
  447. * @type {string}
  448. * @product highcharts
  449. */ /**
  450. * The vertical offset of a node in terms of weight. Positive values shift the
  451. * node downwards, negative shift it upwards.
  452. *
  453. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/sankey-node-column/|Highcharts-Demo:}
  454. * Specified node offset
  455. *
  456. * @name Highcharts.SankeyNodeObject#offset
  457. * @type {number}
  458. * @default 0
  459. * @since 6.0.5
  460. */
  461. /**
  462. * Formatter callback function.
  463. *
  464. * @callback Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction
  465. *
  466. * @param {Highcharts.SeriesSankeyDataLabelsFormatterContextObject|Highcharts.PointLabelObject} this
  467. * Data label context to format
  468. *
  469. * @return {string|undefined}
  470. * Formatted data label text
  471. */
  472. /**
  473. * Context for the node formatter function.
  474. *
  475. * @interface Highcharts.SeriesSankeyDataLabelsFormatterContextObject
  476. * @extends Highcharts.PointLabelObject
  477. */ /**
  478. * The node object. The node name, if defined, is available through
  479. * `this.point.name`.
  480. * @name Highcharts.SeriesSankeyDataLabelsFormatterContextObject#point
  481. * @type {Highcharts.SankeyNodeObject}
  482. */
  483. var defined = U.defined, find = U.find, isObject = U.isObject, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength, seriesType = U.seriesType, stableSort = U.stableSort;
  484. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  485. // eslint-disable-next-line valid-jsdoc
  486. /**
  487. * @private
  488. */
  489. var getDLOptions = function getDLOptions(params) {
  490. var optionsPoint = (isObject(params.optionsPoint) ?
  491. params.optionsPoint.dataLabels :
  492. {}), optionsLevel = (isObject(params.level) ?
  493. params.level.dataLabels :
  494. {}), options = merge({
  495. style: {}
  496. }, optionsLevel, optionsPoint);
  497. return options;
  498. };
  499. /**
  500. * @private
  501. * @class
  502. * @name Highcharts.seriesTypes.sankey
  503. *
  504. * @augments Highcharts.Series
  505. */
  506. seriesType('sankey', 'column',
  507. /**
  508. * A sankey diagram is a type of flow diagram, in which the width of the
  509. * link between two nodes is shown proportionally to the flow quantity.
  510. *
  511. * @sample highcharts/demo/sankey-diagram/
  512. * Sankey diagram
  513. * @sample highcharts/plotoptions/sankey-inverted/
  514. * Inverted sankey diagram
  515. * @sample highcharts/plotoptions/sankey-outgoing
  516. * Sankey diagram with outgoing links
  517. *
  518. * @extends plotOptions.column
  519. * @since 6.0.0
  520. * @product highcharts
  521. * @excluding animationLimit, boostThreshold, borderRadius,
  522. * crisp, cropThreshold, colorAxis, colorKey, depth, dragDrop,
  523. * edgeColor, edgeWidth, findNearestPointBy, grouping,
  524. * groupPadding, groupZPadding, maxPointWidth, negativeColor,
  525. * pointInterval, pointIntervalUnit, pointPadding,
  526. * pointPlacement, pointRange, pointStart, pointWidth,
  527. * shadow, softThreshold, stacking, threshold, zoneAxis,
  528. * zones, minPointLength, dataSorting
  529. * @requires modules/sankey
  530. * @optionparent plotOptions.sankey
  531. */
  532. {
  533. borderWidth: 0,
  534. colorByPoint: true,
  535. /**
  536. * Higher numbers makes the links in a sankey diagram or dependency
  537. * wheelrender more curved. A `curveFactor` of 0 makes the lines
  538. * straight.
  539. *
  540. * @private
  541. */
  542. curveFactor: 0.33,
  543. /**
  544. * Options for the data labels appearing on top of the nodes and links.
  545. * For sankey charts, data labels are visible for the nodes by default,
  546. * but hidden for links. This is controlled by modifying the
  547. * `nodeFormat`, and the `format` that applies to links and is an empty
  548. * string by default.
  549. *
  550. * @declare Highcharts.SeriesSankeyDataLabelsOptionsObject
  551. *
  552. * @private
  553. */
  554. dataLabels: {
  555. enabled: true,
  556. backgroundColor: 'none',
  557. crop: false,
  558. /**
  559. * The
  560. * [format string](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  561. * specifying what to show for _nodes_ in the sankey diagram. By
  562. * default the `nodeFormatter` returns `{point.name}`.
  563. *
  564. * @sample highcharts/plotoptions/sankey-link-datalabels/
  565. * Node and link data labels
  566. *
  567. * @type {string}
  568. */
  569. nodeFormat: void 0,
  570. // eslint-disable-next-line valid-jsdoc
  571. /**
  572. * Callback to format data labels for _nodes_ in the sankey diagram.
  573. * The `nodeFormat` option takes precedence over the
  574. * `nodeFormatter`.
  575. *
  576. * @type {Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction}
  577. * @since 6.0.2
  578. */
  579. nodeFormatter: function () {
  580. return this.point.name;
  581. },
  582. format: void 0,
  583. // eslint-disable-next-line valid-jsdoc
  584. /**
  585. * @type {Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction}
  586. */
  587. formatter: function () {
  588. return;
  589. },
  590. inside: true
  591. },
  592. /**
  593. * @ignore-option
  594. *
  595. * @private
  596. */
  597. inactiveOtherPoints: true,
  598. /**
  599. * Set options on specific levels. Takes precedence over series options,
  600. * but not node and link options.
  601. *
  602. * @sample highcharts/demo/sunburst
  603. * Sunburst chart
  604. *
  605. * @type {Array<*>}
  606. * @since 7.1.0
  607. * @apioption plotOptions.sankey.levels
  608. */
  609. /**
  610. * Can set `borderColor` on all nodes which lay on the same level.
  611. *
  612. * @type {Highcharts.ColorString}
  613. * @apioption plotOptions.sankey.levels.borderColor
  614. */
  615. /**
  616. * Can set `borderWidth` on all nodes which lay on the same level.
  617. *
  618. * @type {number}
  619. * @apioption plotOptions.sankey.levels.borderWidth
  620. */
  621. /**
  622. * Can set `color` on all nodes which lay on the same level.
  623. *
  624. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  625. * @apioption plotOptions.sankey.levels.color
  626. */
  627. /**
  628. * Can set `colorByPoint` on all nodes which lay on the same level.
  629. *
  630. * @type {boolean}
  631. * @default true
  632. * @apioption plotOptions.sankey.levels.colorByPoint
  633. */
  634. /**
  635. * Can set `dataLabels` on all points which lay on the same level.
  636. *
  637. * @extends plotOptions.sankey.dataLabels
  638. * @apioption plotOptions.sankey.levels.dataLabels
  639. */
  640. /**
  641. * Decides which level takes effect from the options set in the levels
  642. * object.
  643. *
  644. * @type {number}
  645. * @apioption plotOptions.sankey.levels.level
  646. */
  647. /**
  648. * Can set `linkOpacity` on all points which lay on the same level.
  649. *
  650. * @type {number}
  651. * @default 0.5
  652. * @apioption plotOptions.sankey.levels.linkOpacity
  653. */
  654. /**
  655. * Can set `states` on all nodes and points which lay on the same level.
  656. *
  657. * @extends plotOptions.sankey.states
  658. * @apioption plotOptions.sankey.levels.states
  659. */
  660. /**
  661. * Opacity for the links between nodes in the sankey diagram.
  662. *
  663. * @private
  664. */
  665. linkOpacity: 0.5,
  666. /**
  667. * The minimal width for a line of a sankey. By default,
  668. * 0 values are not shown.
  669. *
  670. * @sample highcharts/plotoptions/sankey-minlinkwidth
  671. * Sankey diagram with minimal link height
  672. *
  673. * @type {number}
  674. * @since 7.1.3
  675. * @default 0
  676. * @apioption plotOptions.sankey.minLinkWidth
  677. *
  678. * @private
  679. */
  680. minLinkWidth: 0,
  681. /**
  682. * The pixel width of each node in a sankey diagram or dependency wheel,
  683. * or the height in case the chart is inverted.
  684. *
  685. * @private
  686. */
  687. nodeWidth: 20,
  688. /**
  689. * The padding between nodes in a sankey diagram or dependency wheel, in
  690. * pixels.
  691. *
  692. * If the number of nodes is so great that it is possible to lay them
  693. * out within the plot area with the given `nodePadding`, they will be
  694. * rendered with a smaller padding as a strategy to avoid overflow.
  695. *
  696. * @private
  697. */
  698. nodePadding: 10,
  699. showInLegend: false,
  700. states: {
  701. hover: {
  702. /**
  703. * Opacity for the links between nodes in the sankey diagram in
  704. * hover mode.
  705. */
  706. linkOpacity: 1
  707. },
  708. /**
  709. * The opposite state of a hover for a single point node/link.
  710. *
  711. * @declare Highcharts.SeriesStatesInactiveOptionsObject
  712. */
  713. inactive: {
  714. /**
  715. * Opacity for the links between nodes in the sankey diagram in
  716. * inactive mode.
  717. */
  718. linkOpacity: 0.1,
  719. /**
  720. * Opacity of inactive markers.
  721. *
  722. * @type {number}
  723. * @apioption plotOptions.series.states.inactive.opacity
  724. */
  725. opacity: 0.1,
  726. /**
  727. * Animation when not hovering over the marker.
  728. *
  729. * @type {boolean|Highcharts.AnimationOptionsObject}
  730. * @apioption plotOptions.series.states.inactive.animation
  731. */
  732. animation: {
  733. /** @internal */
  734. duration: 50
  735. }
  736. }
  737. },
  738. tooltip: {
  739. /**
  740. * A callback for defining the format for _nodes_ in the chart's
  741. * tooltip, as opposed to links.
  742. *
  743. * @type {Highcharts.FormatterCallbackFunction<Highcharts.SankeyNodeObject>}
  744. * @since 6.0.2
  745. * @apioption plotOptions.sankey.tooltip.nodeFormatter
  746. */
  747. /**
  748. * Whether the tooltip should follow the pointer or stay fixed on
  749. * the item.
  750. */
  751. followPointer: true,
  752. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  753. pointFormat: '{point.fromNode.name} \u2192 {point.toNode.name}: <b>{point.weight}</b><br/>',
  754. /**
  755. * The
  756. * [format string](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  757. * specifying what to show for _nodes_ in tooltip of a diagram
  758. * series, as opposed to links.
  759. */
  760. nodeFormat: '{point.name}: <b>{point.sum}</b><br/>'
  761. }
  762. }, {
  763. isCartesian: false,
  764. invertable: true,
  765. forceDL: true,
  766. orderNodes: true,
  767. pointArrayMap: ['from', 'to'],
  768. // Create a single node that holds information on incoming and outgoing
  769. // links.
  770. createNode: H.NodesMixin.createNode,
  771. searchPoint: H.noop,
  772. setData: H.NodesMixin.setData,
  773. destroy: H.NodesMixin.destroy,
  774. /* eslint-disable valid-jsdoc */
  775. /**
  776. * Overridable function to get node padding, overridden in dependency
  777. * wheel series type.
  778. * @private
  779. */
  780. getNodePadding: function () {
  781. var nodePadding = this.options.nodePadding || 0;
  782. // If the number of columns is so great that they will overflow with
  783. // the given nodePadding, we sacrifice the padding in order to
  784. // render all nodes within the plot area (#11917).
  785. if (this.nodeColumns) {
  786. var maxLength = this.nodeColumns.reduce(function (acc, col) { return Math.max(acc, col.length); }, 0);
  787. if (maxLength * nodePadding > this.chart.plotSizeY) {
  788. nodePadding = this.chart.plotSizeY / maxLength;
  789. }
  790. }
  791. return nodePadding;
  792. },
  793. /**
  794. * Create a node column.
  795. * @private
  796. */
  797. createNodeColumn: function () {
  798. var series = this, chart = this.chart, column = [];
  799. column.sum = function () {
  800. return this.reduce(function (sum, node) {
  801. return sum + node.getSum();
  802. }, 0);
  803. };
  804. // Get the offset in pixels of a node inside the column.
  805. column.offset = function (node, factor) {
  806. var offset = 0, totalNodeOffset, nodePadding = series.nodePadding;
  807. for (var i = 0; i < column.length; i++) {
  808. var sum = column[i].getSum();
  809. var height = Math.max(sum * factor, series.options.minLinkWidth);
  810. if (sum) {
  811. totalNodeOffset = height + nodePadding;
  812. }
  813. else {
  814. // If node sum equals 0 nodePadding is missed #12453
  815. totalNodeOffset = 0;
  816. }
  817. if (column[i] === node) {
  818. return {
  819. relativeTop: offset + relativeLength(node.options.offset || 0, totalNodeOffset)
  820. };
  821. }
  822. offset += totalNodeOffset;
  823. }
  824. };
  825. // Get the top position of the column in pixels.
  826. column.top = function (factor) {
  827. var nodePadding = series.nodePadding;
  828. var height = this.reduce(function (height, node) {
  829. if (height > 0) {
  830. height += nodePadding;
  831. }
  832. var nodeHeight = Math.max(node.getSum() * factor, series.options.minLinkWidth);
  833. height += nodeHeight;
  834. return height;
  835. }, 0);
  836. return (chart.plotSizeY - height) / 2;
  837. };
  838. return column;
  839. },
  840. /**
  841. * Create node columns by analyzing the nodes and the relations between
  842. * incoming and outgoing links.
  843. * @private
  844. */
  845. createNodeColumns: function () {
  846. var columns = [];
  847. this.nodes.forEach(function (node) {
  848. var fromColumn = -1, fromNode, i, point;
  849. if (!defined(node.options.column)) {
  850. // No links to this node, place it left
  851. if (node.linksTo.length === 0) {
  852. node.column = 0;
  853. // There are incoming links, place it to the right of the
  854. // highest order column that links to this one.
  855. }
  856. else {
  857. for (i = 0; i < node.linksTo.length; i++) {
  858. point = node.linksTo[0];
  859. if (point.fromNode.column > fromColumn) {
  860. fromNode = point.fromNode;
  861. fromColumn = fromNode.column;
  862. }
  863. }
  864. node.column = fromColumn + 1;
  865. // Hanging layout for organization chart
  866. if (fromNode &&
  867. fromNode.options.layout === 'hanging') {
  868. node.hangsFrom = fromNode;
  869. i = -1; // Reuse existing variable i
  870. find(fromNode.linksFrom, function (link, index) {
  871. var found = link.toNode === node;
  872. if (found) {
  873. i = index;
  874. }
  875. return found;
  876. });
  877. node.column += i;
  878. }
  879. }
  880. }
  881. if (!columns[node.column]) {
  882. columns[node.column] = this.createNodeColumn();
  883. }
  884. columns[node.column].push(node);
  885. }, this);
  886. // Fill in empty columns (#8865)
  887. for (var i = 0; i < columns.length; i++) {
  888. if (typeof columns[i] === 'undefined') {
  889. columns[i] = this.createNodeColumn();
  890. }
  891. }
  892. return columns;
  893. },
  894. /**
  895. * Define hasData function for non-cartesian series.
  896. * @private
  897. * @return {boolean}
  898. * Returns true if the series has points at all.
  899. */
  900. hasData: function () {
  901. return !!this.processedXData.length; // != 0
  902. },
  903. /**
  904. * Return the presentational attributes.
  905. * @private
  906. */
  907. pointAttribs: function (point, state) {
  908. var series = this, level = point.isNode ? point.level : point.fromNode.level, levelOptions = series.mapOptionsToLevel[level || 0] || {}, options = point.options, stateOptions = (levelOptions.states && levelOptions.states[state]) || {}, values = [
  909. 'colorByPoint', 'borderColor', 'borderWidth', 'linkOpacity'
  910. ].reduce(function (obj, key) {
  911. obj[key] = pick(stateOptions[key], options[key], levelOptions[key], series.options[key]);
  912. return obj;
  913. }, {}), color = pick(stateOptions.color, options.color, values.colorByPoint ? point.color : levelOptions.color);
  914. // Node attributes
  915. if (point.isNode) {
  916. return {
  917. fill: color,
  918. stroke: values.borderColor,
  919. 'stroke-width': values.borderWidth
  920. };
  921. }
  922. // Link attributes
  923. return {
  924. fill: Color.parse(color).setOpacity(values.linkOpacity).get()
  925. };
  926. },
  927. /**
  928. * Extend generatePoints by adding the nodes, which are Point objects
  929. * but pushed to the this.nodes array.
  930. * @private
  931. */
  932. generatePoints: function () {
  933. H.NodesMixin.generatePoints.apply(this, arguments);
  934. /**
  935. * Order the nodes, starting with the root node(s). (#9818)
  936. * @private
  937. */
  938. function order(node, level) {
  939. // Prevents circular recursion:
  940. if (typeof node.level === 'undefined') {
  941. node.level = level;
  942. node.linksFrom.forEach(function (link) {
  943. if (link.toNode) {
  944. order(link.toNode, level + 1);
  945. }
  946. });
  947. }
  948. }
  949. if (this.orderNodes) {
  950. this.nodes
  951. // Identify the root node(s)
  952. .filter(function (node) {
  953. return node.linksTo.length === 0;
  954. })
  955. // Start by the root node(s) and recursively set the level
  956. // on all following nodes.
  957. .forEach(function (node) {
  958. order(node, 0);
  959. });
  960. stableSort(this.nodes, function (a, b) {
  961. return a.level - b.level;
  962. });
  963. }
  964. },
  965. /**
  966. * Run translation operations for one node.
  967. * @private
  968. */
  969. translateNode: function (node, column) {
  970. var translationFactor = this.translationFactor, chart = this.chart, options = this.options, sum = node.getSum(), height = Math.max(Math.round(sum * translationFactor), this.options.minLinkWidth), crisp = Math.round(options.borderWidth) % 2 / 2, nodeOffset = column.offset(node, translationFactor), fromNodeTop = Math.floor(pick(nodeOffset.absoluteTop, (column.top(translationFactor) +
  971. nodeOffset.relativeTop))) + crisp, left = Math.floor(this.colDistance * node.column +
  972. options.borderWidth / 2) + crisp, nodeLeft = chart.inverted ?
  973. chart.plotSizeX - left :
  974. left, nodeWidth = Math.round(this.nodeWidth);
  975. node.sum = sum;
  976. // If node sum is 0, don't render the rect #12453
  977. if (sum) {
  978. // Draw the node
  979. node.shapeType = 'rect';
  980. node.nodeX = nodeLeft;
  981. node.nodeY = fromNodeTop;
  982. if (!chart.inverted) {
  983. node.shapeArgs = {
  984. x: nodeLeft,
  985. y: fromNodeTop,
  986. width: node.options.width || options.width || nodeWidth,
  987. height: node.options.height || options.height || height
  988. };
  989. }
  990. else {
  991. node.shapeArgs = {
  992. x: nodeLeft - nodeWidth,
  993. y: chart.plotSizeY - fromNodeTop - height,
  994. width: node.options.height || options.height || nodeWidth,
  995. height: node.options.width || options.width || height
  996. };
  997. }
  998. node.shapeArgs.display = node.hasShape() ? '' : 'none';
  999. // Calculate data label options for the point
  1000. node.dlOptions = getDLOptions({
  1001. level: this.mapOptionsToLevel[node.level],
  1002. optionsPoint: node.options
  1003. });
  1004. // Pass test in drawPoints
  1005. node.plotY = 1;
  1006. // Set the anchor position for tooltips
  1007. node.tooltipPos = chart.inverted ? [
  1008. chart.plotSizeY - node.shapeArgs.y - node.shapeArgs.height / 2,
  1009. chart.plotSizeX - node.shapeArgs.x - node.shapeArgs.width / 2
  1010. ] : [
  1011. node.shapeArgs.x + node.shapeArgs.width / 2,
  1012. node.shapeArgs.y + node.shapeArgs.height / 2
  1013. ];
  1014. }
  1015. else {
  1016. node.dlOptions = {
  1017. enabled: false
  1018. };
  1019. }
  1020. },
  1021. /**
  1022. * Run translation operations for one link.
  1023. * @private
  1024. */
  1025. translateLink: function (point) {
  1026. var getY = function (node, fromOrTo) {
  1027. var _a;
  1028. var linkTop = (node.offset(point, fromOrTo) *
  1029. translationFactor);
  1030. var y = Math.min(node.nodeY + linkTop,
  1031. // Prevent links from spilling below the node (#12014)
  1032. node.nodeY + ((_a = node.shapeArgs) === null || _a === void 0 ? void 0 : _a.height) - linkHeight);
  1033. return y;
  1034. };
  1035. var fromNode = point.fromNode, toNode = point.toNode, chart = this.chart, translationFactor = this.translationFactor, linkHeight = Math.max(point.weight * translationFactor, this.options.minLinkWidth), options = this.options, curvy = ((chart.inverted ? -this.colDistance : this.colDistance) *
  1036. options.curveFactor), fromY = getY(fromNode, 'linksFrom'), toY = getY(toNode, 'linksTo'), nodeLeft = fromNode.nodeX, nodeW = this.nodeWidth, right = toNode.column * this.colDistance, outgoing = point.outgoing, straight = right > nodeLeft + nodeW;
  1037. if (chart.inverted) {
  1038. fromY = chart.plotSizeY - fromY;
  1039. toY = (chart.plotSizeY || 0) - toY;
  1040. right = chart.plotSizeX - right;
  1041. nodeW = -nodeW;
  1042. linkHeight = -linkHeight;
  1043. straight = nodeLeft > right;
  1044. }
  1045. point.shapeType = 'path';
  1046. point.linkBase = [
  1047. fromY,
  1048. fromY + linkHeight,
  1049. toY,
  1050. toY + linkHeight
  1051. ];
  1052. // Links going from left to right
  1053. if (straight && typeof toY === 'number') {
  1054. point.shapeArgs = {
  1055. d: [
  1056. ['M', nodeLeft + nodeW, fromY],
  1057. [
  1058. 'C',
  1059. nodeLeft + nodeW + curvy,
  1060. fromY,
  1061. right - curvy,
  1062. toY,
  1063. right,
  1064. toY
  1065. ],
  1066. ['L', right + (outgoing ? nodeW : 0), toY + linkHeight / 2],
  1067. ['L', right, toY + linkHeight],
  1068. [
  1069. 'C',
  1070. right - curvy,
  1071. toY + linkHeight,
  1072. nodeLeft + nodeW + curvy,
  1073. fromY + linkHeight,
  1074. nodeLeft + nodeW, fromY + linkHeight
  1075. ],
  1076. ['Z']
  1077. ]
  1078. };
  1079. // Experimental: Circular links pointing backwards. In
  1080. // v6.1.0 this breaks the rendering completely, so even
  1081. // this experimental rendering is an improvement. #8218.
  1082. // @todo
  1083. // - Make room for the link in the layout
  1084. // - Automatically determine if the link should go up or
  1085. // down.
  1086. }
  1087. else if (typeof toY === 'number') {
  1088. var bend = 20, vDist = chart.plotHeight - fromY - linkHeight, x1 = right - bend - linkHeight, x2 = right - bend, x3 = right, x4 = nodeLeft + nodeW, x5 = x4 + bend, x6 = x5 + linkHeight, fy1 = fromY, fy2 = fromY + linkHeight, fy3 = fy2 + bend, y4 = fy3 + vDist, y5 = y4 + bend, y6 = y5 + linkHeight, ty1 = toY, ty2 = ty1 + linkHeight, ty3 = ty2 + bend, cfy1 = fy2 - linkHeight * 0.7, cy2 = y5 + linkHeight * 0.7, cty1 = ty2 - linkHeight * 0.7, cx1 = x3 - linkHeight * 0.7, cx2 = x4 + linkHeight * 0.7;
  1089. point.shapeArgs = {
  1090. d: [
  1091. ['M', x4, fy1],
  1092. ['C', cx2, fy1, x6, cfy1, x6, fy3],
  1093. ['L', x6, y4],
  1094. ['C', x6, cy2, cx2, y6, x4, y6],
  1095. ['L', x3, y6],
  1096. ['C', cx1, y6, x1, cy2, x1, y4],
  1097. ['L', x1, ty3],
  1098. ['C', x1, cty1, cx1, ty1, x3, ty1],
  1099. ['L', x3, ty2],
  1100. ['C', x2, ty2, x2, ty2, x2, ty3],
  1101. ['L', x2, y4],
  1102. ['C', x2, y5, x2, y5, x3, y5],
  1103. ['L', x4, y5],
  1104. ['C', x5, y5, x5, y5, x5, y4],
  1105. ['L', x5, fy3],
  1106. ['C', x5, fy2, x5, fy2, x4, fy2],
  1107. ['Z']
  1108. ]
  1109. };
  1110. }
  1111. // Place data labels in the middle
  1112. point.dlBox = {
  1113. x: nodeLeft + (right - nodeLeft + nodeW) / 2,
  1114. y: fromY + (toY - fromY) / 2,
  1115. height: linkHeight,
  1116. width: 0
  1117. };
  1118. // And set the tooltip anchor in the middle
  1119. point.tooltipPos = chart.inverted ? [
  1120. chart.plotSizeY - point.dlBox.y - linkHeight / 2,
  1121. chart.plotSizeX - point.dlBox.x
  1122. ] : [
  1123. point.dlBox.x,
  1124. point.dlBox.y + linkHeight / 2
  1125. ];
  1126. // Pass test in drawPoints
  1127. point.y = point.plotY = 1;
  1128. if (!point.color) {
  1129. point.color = fromNode.color;
  1130. }
  1131. },
  1132. /**
  1133. * Run pre-translation by generating the nodeColumns.
  1134. * @private
  1135. */
  1136. translate: function () {
  1137. var _this = this;
  1138. // Get the translation factor needed for each column to fill up the
  1139. // plot height
  1140. var getColumnTranslationFactor = function (column) {
  1141. var nodes = column.slice();
  1142. var minLinkWidth = _this.options.minLinkWidth || 0;
  1143. var exceedsMinLinkWidth;
  1144. var factor = 0;
  1145. var i;
  1146. var remainingHeight = chart.plotSizeY -
  1147. options.borderWidth - (column.length - 1) * series.nodePadding;
  1148. // Because the minLinkWidth option doesn't obey the direct
  1149. // translation, we need to run translation iteratively, check
  1150. // node heights, remove those nodes affected by minLinkWidth,
  1151. // check again, etc.
  1152. while (column.length) {
  1153. factor = remainingHeight / column.sum();
  1154. exceedsMinLinkWidth = false;
  1155. i = column.length;
  1156. while (i--) {
  1157. if (column[i].getSum() * factor < minLinkWidth) {
  1158. column.splice(i, 1);
  1159. remainingHeight -= minLinkWidth;
  1160. exceedsMinLinkWidth = true;
  1161. }
  1162. }
  1163. if (!exceedsMinLinkWidth) {
  1164. break;
  1165. }
  1166. }
  1167. // Re-insert original nodes
  1168. column.length = 0;
  1169. nodes.forEach(function (node) { return column.push(node); });
  1170. return factor;
  1171. };
  1172. if (!this.processedXData) {
  1173. this.processData();
  1174. }
  1175. this.generatePoints();
  1176. this.nodeColumns = this.createNodeColumns();
  1177. this.nodeWidth = relativeLength(this.options.nodeWidth, this.chart.plotSizeX);
  1178. var series = this, chart = this.chart, options = this.options, nodeWidth = this.nodeWidth, nodeColumns = this.nodeColumns;
  1179. this.nodePadding = this.getNodePadding();
  1180. // Find out how much space is needed. Base it on the translation
  1181. // factor of the most spaceous column.
  1182. this.translationFactor = nodeColumns.reduce(function (translationFactor, column) { return Math.min(translationFactor, getColumnTranslationFactor(column)); }, Infinity);
  1183. this.colDistance =
  1184. (chart.plotSizeX - nodeWidth -
  1185. options.borderWidth) / Math.max(1, nodeColumns.length - 1);
  1186. // Calculate level options used in sankey and organization
  1187. series.mapOptionsToLevel = getLevelOptions({
  1188. // NOTE: if support for allowTraversingTree is added, then from
  1189. // should be the level of the root node.
  1190. from: 1,
  1191. levels: options.levels,
  1192. to: nodeColumns.length - 1,
  1193. defaults: {
  1194. borderColor: options.borderColor,
  1195. borderRadius: options.borderRadius,
  1196. borderWidth: options.borderWidth,
  1197. color: series.color,
  1198. colorByPoint: options.colorByPoint,
  1199. // NOTE: if support for allowTraversingTree is added, then
  1200. // levelIsConstant should be optional.
  1201. levelIsConstant: true,
  1202. linkColor: options.linkColor,
  1203. linkLineWidth: options.linkLineWidth,
  1204. linkOpacity: options.linkOpacity,
  1205. states: options.states
  1206. }
  1207. });
  1208. // First translate all nodes so we can use them when drawing links
  1209. nodeColumns.forEach(function (column) {
  1210. column.forEach(function (node) {
  1211. series.translateNode(node, column);
  1212. });
  1213. }, this);
  1214. // Then translate links
  1215. this.nodes.forEach(function (node) {
  1216. // Translate the links from this node
  1217. node.linksFrom.forEach(function (linkPoint) {
  1218. // If weight is 0 - don't render the link path #12453,
  1219. // render null points (for organization chart)
  1220. if ((linkPoint.weight || linkPoint.isNull) && linkPoint.to) {
  1221. series.translateLink(linkPoint);
  1222. linkPoint.allowShadow = false;
  1223. }
  1224. });
  1225. });
  1226. },
  1227. /**
  1228. * Extend the render function to also render this.nodes together with
  1229. * the points.
  1230. * @private
  1231. */
  1232. render: function () {
  1233. var points = this.points;
  1234. this.points = this.points.concat(this.nodes || []);
  1235. H.seriesTypes.column.prototype.render.call(this);
  1236. this.points = points;
  1237. },
  1238. /* eslint-enable valid-jsdoc */
  1239. animate: H.Series.prototype.animate
  1240. }, {
  1241. applyOptions: function (options, x) {
  1242. Point.prototype.applyOptions.call(this, options, x);
  1243. // Treat point.level as a synonym of point.column
  1244. if (defined(this.options.level)) {
  1245. this.options.column = this.column = this.options.level;
  1246. }
  1247. return this;
  1248. },
  1249. setState: H.NodesMixin.setNodeState,
  1250. getClassName: function () {
  1251. return (this.isNode ? 'highcharts-node ' : 'highcharts-link ') +
  1252. Point.prototype.getClassName.call(this);
  1253. },
  1254. isValid: function () {
  1255. return this.isNode || typeof this.weight === 'number';
  1256. }
  1257. });
  1258. /**
  1259. * A `sankey` series. If the [type](#series.sankey.type) option is not
  1260. * specified, it is inherited from [chart.type](#chart.type).
  1261. *
  1262. * @extends series,plotOptions.sankey
  1263. * @excluding animationLimit, boostBlending, boostThreshold, borderColor,
  1264. * borderRadius, borderWidth, crisp, cropThreshold, dataParser,
  1265. * dataURL, depth, dragDrop, edgeColor, edgeWidth,
  1266. * findNearestPointBy, getExtremesFromAll, grouping, groupPadding,
  1267. * groupZPadding, label, maxPointWidth, negativeColor, pointInterval,
  1268. * pointIntervalUnit, pointPadding, pointPlacement, pointRange,
  1269. * pointStart, pointWidth, shadow, softThreshold, stacking,
  1270. * threshold, zoneAxis, zones, dataSorting
  1271. * @product highcharts
  1272. * @requires modules/sankey
  1273. * @apioption series.sankey
  1274. */
  1275. /**
  1276. * A collection of options for the individual nodes. The nodes in a sankey
  1277. * diagram are auto-generated instances of `Highcharts.Point`, but options can
  1278. * be applied here and linked by the `id`.
  1279. *
  1280. * @sample highcharts/css/sankey/
  1281. * Sankey diagram with node options
  1282. *
  1283. * @declare Highcharts.SeriesSankeyNodesOptionsObject
  1284. * @type {Array<*>}
  1285. * @product highcharts
  1286. * @apioption series.sankey.nodes
  1287. */
  1288. /**
  1289. * The id of the auto-generated node, refering to the `from` or `to` setting of
  1290. * the link.
  1291. *
  1292. * @type {string}
  1293. * @product highcharts
  1294. * @apioption series.sankey.nodes.id
  1295. */
  1296. /**
  1297. * The color of the auto generated node.
  1298. *
  1299. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1300. * @product highcharts
  1301. * @apioption series.sankey.nodes.color
  1302. */
  1303. /**
  1304. * The color index of the auto generated node, especially for use in styled
  1305. * mode.
  1306. *
  1307. * @type {number}
  1308. * @product highcharts
  1309. * @apioption series.sankey.nodes.colorIndex
  1310. */
  1311. /**
  1312. * An optional column index of where to place the node. The default behaviour is
  1313. * to place it next to the preceding node. Note that this option name is
  1314. * counter intuitive in inverted charts, like for example an organization chart
  1315. * rendered top down. In this case the "columns" are horizontal.
  1316. *
  1317. * @sample highcharts/plotoptions/sankey-node-column/
  1318. * Specified node column
  1319. *
  1320. * @type {number}
  1321. * @since 6.0.5
  1322. * @product highcharts
  1323. * @apioption series.sankey.nodes.column
  1324. */
  1325. /**
  1326. * Individual data label for each node. The options are the same as
  1327. * the ones for [series.sankey.dataLabels](#series.sankey.dataLabels).
  1328. *
  1329. * @extends plotOptions.sankey.dataLabels
  1330. * @apioption series.sankey.nodes.dataLabels
  1331. */
  1332. /**
  1333. * An optional level index of where to place the node. The default behaviour is
  1334. * to place it next to the preceding node. Alias of `nodes.column`, but in
  1335. * inverted sankeys and org charts, the levels are laid out as rows.
  1336. *
  1337. * @type {number}
  1338. * @since 7.1.0
  1339. * @product highcharts
  1340. * @apioption series.sankey.nodes.level
  1341. */
  1342. /**
  1343. * The name to display for the node in data labels and tooltips. Use this when
  1344. * the name is different from the `id`. Where the id must be unique for each
  1345. * node, this is not necessary for the name.
  1346. *
  1347. * @sample highcharts/css/sankey/
  1348. * Sankey diagram with node options
  1349. *
  1350. * @type {string}
  1351. * @product highcharts
  1352. * @apioption series.sankey.nodes.name
  1353. */
  1354. /**
  1355. * In a horizontal layout, the vertical offset of a node in terms of weight.
  1356. * Positive values shift the node downwards, negative shift it upwards. In a
  1357. * vertical layout, like organization chart, the offset is horizontal.
  1358. *
  1359. * If a percantage string is given, the node is offset by the percentage of the
  1360. * node size plus `nodePadding`.
  1361. *
  1362. * @sample highcharts/plotoptions/sankey-node-column/
  1363. * Specified node offset
  1364. *
  1365. * @type {number|string}
  1366. * @default 0
  1367. * @since 6.0.5
  1368. * @product highcharts
  1369. * @apioption series.sankey.nodes.offset
  1370. */
  1371. /**
  1372. * An array of data points for the series. For the `sankey` series type,
  1373. * points can be given in the following way:
  1374. *
  1375. * An array of objects with named values. The following snippet shows only a
  1376. * few settings, see the complete options set below. If the total number of data
  1377. * points exceeds the series' [turboThreshold](#series.area.turboThreshold),
  1378. * this option is not available.
  1379. *
  1380. * ```js
  1381. * data: [{
  1382. * from: 'Category1',
  1383. * to: 'Category2',
  1384. * weight: 2
  1385. * }, {
  1386. * from: 'Category1',
  1387. * to: 'Category3',
  1388. * weight: 5
  1389. * }]
  1390. * ```
  1391. *
  1392. * @sample {highcharts} highcharts/series/data-array-of-objects/
  1393. * Config objects
  1394. *
  1395. * @declare Highcharts.SeriesSankeyPointOptionsObject
  1396. * @type {Array<*>}
  1397. * @extends series.line.data
  1398. * @excluding dragDrop, drilldown, marker, x, y
  1399. * @product highcharts
  1400. * @apioption series.sankey.data
  1401. */
  1402. /**
  1403. * The color for the individual _link_. By default, the link color is the same
  1404. * as the node it extends from. The `series.fillOpacity` option also applies to
  1405. * the points, so when setting a specific link color, consider setting the
  1406. * `fillOpacity` to 1.
  1407. *
  1408. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1409. * @product highcharts
  1410. * @apioption series.sankey.data.color
  1411. */
  1412. /**
  1413. * @type {Highcharts.SeriesSankeyDataLabelsOptionsObject|Array<Highcharts.SeriesSankeyDataLabelsOptionsObject>}
  1414. * @product highcharts
  1415. * @apioption series.sankey.data.dataLabels
  1416. */
  1417. /**
  1418. * The node that the link runs from.
  1419. *
  1420. * @type {string}
  1421. * @product highcharts
  1422. * @apioption series.sankey.data.from
  1423. */
  1424. /**
  1425. * The node that the link runs to.
  1426. *
  1427. * @type {string}
  1428. * @product highcharts
  1429. * @apioption series.sankey.data.to
  1430. */
  1431. /**
  1432. * Whether the link goes out of the system.
  1433. *
  1434. * @sample highcharts/plotoptions/sankey-outgoing
  1435. * Sankey chart with outgoing links
  1436. *
  1437. * @type {boolean}
  1438. * @default false
  1439. * @product highcharts
  1440. * @apioption series.sankey.data.outgoing
  1441. */
  1442. /**
  1443. * The weight of the link.
  1444. *
  1445. * @type {number|null}
  1446. * @product highcharts
  1447. * @apioption series.sankey.data.weight
  1448. */
  1449. ''; // adds doclets above to transpiled file
  1450. });
  1451. _registerModule(_modules, 'masters/modules/sankey.src.js', [], function () {
  1452. });
  1453. }));