sankey.src.js 73 KB

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