sankey.src.js 66 KB

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