SankeySeries.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. /* *
  2. *
  3. * Sankey diagram module
  4. *
  5. * (c) 2010-2021 Torstein Honsi
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. var __extends = (this && this.__extends) || (function () {
  14. var extendStatics = function (d, b) {
  15. extendStatics = Object.setPrototypeOf ||
  16. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  17. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  18. return extendStatics(d, b);
  19. };
  20. return function (d, b) {
  21. extendStatics(d, b);
  22. function __() { this.constructor = d; }
  23. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  24. };
  25. })();
  26. import Color from '../../Core/Color/Color.js';
  27. import H from '../../Core/Globals.js';
  28. import NodesMixin from '../../Mixins/Nodes.js';
  29. import SankeyPoint from './SankeyPoint.js';
  30. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  31. var Series = SeriesRegistry.series, ColumnSeries = SeriesRegistry.seriesTypes.column;
  32. import TreeSeriesMixin from '../../Mixins/TreeSeries.js';
  33. var getLevelOptions = TreeSeriesMixin.getLevelOptions;
  34. import U from '../../Core/Utilities.js';
  35. var defined = U.defined, extend = U.extend, find = U.find, isObject = U.isObject, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength, stableSort = U.stableSort;
  36. /* *
  37. *
  38. * Class
  39. *
  40. * */
  41. /**
  42. * @private
  43. * @class
  44. * @name Highcharts.seriesTypes.sankey
  45. *
  46. * @augments Highcharts.Series
  47. */
  48. var SankeySeries = /** @class */ (function (_super) {
  49. __extends(SankeySeries, _super);
  50. function SankeySeries() {
  51. /* *
  52. *
  53. * Static Properties
  54. *
  55. * */
  56. var _this = _super !== null && _super.apply(this, arguments) || this;
  57. /* *
  58. *
  59. * Properties
  60. *
  61. * */
  62. _this.colDistance = void 0;
  63. _this.data = void 0;
  64. _this.group = void 0;
  65. _this.nodeLookup = void 0;
  66. _this.nodePadding = void 0;
  67. _this.nodes = void 0;
  68. _this.nodeWidth = void 0;
  69. _this.options = void 0;
  70. _this.points = void 0;
  71. _this.translationFactor = void 0;
  72. return _this;
  73. /* eslint-enable valid-jsdoc */
  74. }
  75. /* *
  76. *
  77. * Static Functions
  78. *
  79. * */
  80. // eslint-disable-next-line valid-jsdoc
  81. /**
  82. * @private
  83. */
  84. SankeySeries.getDLOptions = function (params) {
  85. var optionsPoint = (isObject(params.optionsPoint) ?
  86. params.optionsPoint.dataLabels :
  87. {}), optionsLevel = (isObject(params.level) ?
  88. params.level.dataLabels :
  89. {}), options = merge({
  90. style: {}
  91. }, optionsLevel, optionsPoint);
  92. return options;
  93. };
  94. /* *
  95. *
  96. * Functions
  97. *
  98. * */
  99. /* eslint-disable valid-jsdoc */
  100. /**
  101. * Create a node column.
  102. * @private
  103. */
  104. SankeySeries.prototype.createNodeColumn = function () {
  105. var series = this, chart = this.chart, column = [];
  106. column.sum = function () {
  107. return this.reduce(function (sum, node) {
  108. return sum + node.getSum();
  109. }, 0);
  110. };
  111. // Get the offset in pixels of a node inside the column.
  112. column.offset = function (node, factor) {
  113. var offset = 0, totalNodeOffset, nodePadding = series.nodePadding;
  114. for (var i = 0; i < column.length; i++) {
  115. var sum = column[i].getSum();
  116. var height = Math.max(sum * factor, series.options.minLinkWidth);
  117. if (sum) {
  118. totalNodeOffset = height + nodePadding;
  119. }
  120. else {
  121. // If node sum equals 0 nodePadding is missed #12453
  122. totalNodeOffset = 0;
  123. }
  124. if (column[i] === node) {
  125. return {
  126. relativeTop: offset + relativeLength(node.options.offset || 0, totalNodeOffset)
  127. };
  128. }
  129. offset += totalNodeOffset;
  130. }
  131. };
  132. // Get the top position of the column in pixels.
  133. column.top = function (factor) {
  134. var nodePadding = series.nodePadding;
  135. var height = this.reduce(function (height, node) {
  136. if (height > 0) {
  137. height += nodePadding;
  138. }
  139. var nodeHeight = Math.max(node.getSum() * factor, series.options.minLinkWidth);
  140. height += nodeHeight;
  141. return height;
  142. }, 0);
  143. return (chart.plotSizeY - height) / 2;
  144. };
  145. return column;
  146. };
  147. /**
  148. * Create node columns by analyzing the nodes and the relations between
  149. * incoming and outgoing links.
  150. * @private
  151. */
  152. SankeySeries.prototype.createNodeColumns = function () {
  153. var columns = [];
  154. this.nodes.forEach(function (node) {
  155. var fromColumn = -1, fromNode, i, point;
  156. if (!defined(node.options.column)) {
  157. // No links to this node, place it left
  158. if (node.linksTo.length === 0) {
  159. node.column = 0;
  160. // There are incoming links, place it to the right of the
  161. // highest order column that links to this one.
  162. }
  163. else {
  164. for (i = 0; i < node.linksTo.length; i++) {
  165. point = node.linksTo[0];
  166. if (point.fromNode.column > fromColumn) {
  167. fromNode = point.fromNode;
  168. fromColumn = fromNode.column;
  169. }
  170. }
  171. node.column = fromColumn + 1;
  172. // Hanging layout for organization chart
  173. if (fromNode &&
  174. fromNode.options.layout === 'hanging') {
  175. node.hangsFrom = fromNode;
  176. i = -1; // Reuse existing variable i
  177. find(fromNode.linksFrom, function (link, index) {
  178. var found = link.toNode === node;
  179. if (found) {
  180. i = index;
  181. }
  182. return found;
  183. });
  184. node.column += i;
  185. }
  186. }
  187. }
  188. if (!columns[node.column]) {
  189. columns[node.column] = this.createNodeColumn();
  190. }
  191. columns[node.column].push(node);
  192. }, this);
  193. // Fill in empty columns (#8865)
  194. for (var i = 0; i < columns.length; i++) {
  195. if (typeof columns[i] === 'undefined') {
  196. columns[i] = this.createNodeColumn();
  197. }
  198. }
  199. return columns;
  200. };
  201. /**
  202. * Extend generatePoints by adding the nodes, which are Point objects
  203. * but pushed to the this.nodes array.
  204. * @private
  205. */
  206. SankeySeries.prototype.generatePoints = function () {
  207. NodesMixin.generatePoints.apply(this, arguments);
  208. /**
  209. * Order the nodes, starting with the root node(s). (#9818)
  210. * @private
  211. */
  212. function order(node, level) {
  213. // Prevents circular recursion:
  214. if (typeof node.level === 'undefined') {
  215. node.level = level;
  216. node.linksFrom.forEach(function (link) {
  217. if (link.toNode) {
  218. order(link.toNode, level + 1);
  219. }
  220. });
  221. }
  222. }
  223. if (this.orderNodes) {
  224. this.nodes
  225. // Identify the root node(s)
  226. .filter(function (node) {
  227. return node.linksTo.length === 0;
  228. })
  229. // Start by the root node(s) and recursively set the level
  230. // on all following nodes.
  231. .forEach(function (node) {
  232. order(node, 0);
  233. });
  234. stableSort(this.nodes, function (a, b) {
  235. return a.level - b.level;
  236. });
  237. }
  238. };
  239. /**
  240. * Overridable function to get node padding, overridden in dependency
  241. * wheel series type.
  242. * @private
  243. */
  244. SankeySeries.prototype.getNodePadding = function () {
  245. var nodePadding = this.options.nodePadding || 0;
  246. // If the number of columns is so great that they will overflow with
  247. // the given nodePadding, we sacrifice the padding in order to
  248. // render all nodes within the plot area (#11917).
  249. if (this.nodeColumns) {
  250. var maxLength = this.nodeColumns.reduce(function (acc, col) { return Math.max(acc, col.length); }, 0);
  251. if (maxLength * nodePadding > this.chart.plotSizeY) {
  252. nodePadding = this.chart.plotSizeY / maxLength;
  253. }
  254. }
  255. return nodePadding;
  256. };
  257. /**
  258. * Define hasData function for non-cartesian series.
  259. * @private
  260. * @return {boolean}
  261. * Returns true if the series has points at all.
  262. */
  263. SankeySeries.prototype.hasData = function () {
  264. return !!this.processedXData.length; // != 0
  265. };
  266. /**
  267. * Return the presentational attributes.
  268. * @private
  269. */
  270. SankeySeries.prototype.pointAttribs = function (point, state) {
  271. if (!point) {
  272. return {};
  273. }
  274. 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 = [
  275. 'colorByPoint', 'borderColor', 'borderWidth', 'linkOpacity'
  276. ].reduce(function (obj, key) {
  277. obj[key] = pick(stateOptions[key], options[key], levelOptions[key], series.options[key]);
  278. return obj;
  279. }, {}), color = pick(stateOptions.color, options.color, values.colorByPoint ? point.color : levelOptions.color);
  280. // Node attributes
  281. if (point.isNode) {
  282. return {
  283. fill: color,
  284. stroke: values.borderColor,
  285. 'stroke-width': values.borderWidth
  286. };
  287. }
  288. // Link attributes
  289. return {
  290. fill: Color.parse(color).setOpacity(values.linkOpacity).get()
  291. };
  292. };
  293. /**
  294. * Extend the render function to also render this.nodes together with
  295. * the points.
  296. * @private
  297. */
  298. SankeySeries.prototype.render = function () {
  299. var points = this.points;
  300. this.points = this.points.concat(this.nodes || []);
  301. ColumnSeries.prototype.render.call(this);
  302. this.points = points;
  303. };
  304. /**
  305. * Run pre-translation by generating the nodeColumns.
  306. * @private
  307. */
  308. SankeySeries.prototype.translate = function () {
  309. var _this = this;
  310. // Get the translation factor needed for each column to fill up the
  311. // plot height
  312. var getColumnTranslationFactor = function (column) {
  313. var nodes = column.slice();
  314. var minLinkWidth = _this.options.minLinkWidth || 0;
  315. var exceedsMinLinkWidth;
  316. var factor = 0;
  317. var i;
  318. var remainingHeight = chart.plotSizeY -
  319. options.borderWidth - (column.length - 1) * series.nodePadding;
  320. // Because the minLinkWidth option doesn't obey the direct
  321. // translation, we need to run translation iteratively, check
  322. // node heights, remove those nodes affected by minLinkWidth,
  323. // check again, etc.
  324. while (column.length) {
  325. factor = remainingHeight / column.sum();
  326. exceedsMinLinkWidth = false;
  327. i = column.length;
  328. while (i--) {
  329. if (column[i].getSum() * factor < minLinkWidth) {
  330. column.splice(i, 1);
  331. remainingHeight -= minLinkWidth;
  332. exceedsMinLinkWidth = true;
  333. }
  334. }
  335. if (!exceedsMinLinkWidth) {
  336. break;
  337. }
  338. }
  339. // Re-insert original nodes
  340. column.length = 0;
  341. nodes.forEach(function (node) { return column.push(node); });
  342. return factor;
  343. };
  344. if (!this.processedXData) {
  345. this.processData();
  346. }
  347. this.generatePoints();
  348. this.nodeColumns = this.createNodeColumns();
  349. this.nodeWidth = relativeLength(this.options.nodeWidth, this.chart.plotSizeX);
  350. var series = this, chart = this.chart, options = this.options, nodeWidth = this.nodeWidth, nodeColumns = this.nodeColumns;
  351. this.nodePadding = this.getNodePadding();
  352. // Find out how much space is needed. Base it on the translation
  353. // factor of the most spaceous column.
  354. this.translationFactor = nodeColumns.reduce(function (translationFactor, column) { return Math.min(translationFactor, getColumnTranslationFactor(column)); }, Infinity);
  355. this.colDistance =
  356. (chart.plotSizeX - nodeWidth -
  357. options.borderWidth) / Math.max(1, nodeColumns.length - 1);
  358. // Calculate level options used in sankey and organization
  359. series.mapOptionsToLevel = getLevelOptions({
  360. // NOTE: if support for allowTraversingTree is added, then from
  361. // should be the level of the root node.
  362. from: 1,
  363. levels: options.levels,
  364. to: nodeColumns.length - 1,
  365. defaults: {
  366. borderColor: options.borderColor,
  367. borderRadius: options.borderRadius,
  368. borderWidth: options.borderWidth,
  369. color: series.color,
  370. colorByPoint: options.colorByPoint,
  371. // NOTE: if support for allowTraversingTree is added, then
  372. // levelIsConstant should be optional.
  373. levelIsConstant: true,
  374. linkColor: options.linkColor,
  375. linkLineWidth: options.linkLineWidth,
  376. linkOpacity: options.linkOpacity,
  377. states: options.states
  378. }
  379. });
  380. // First translate all nodes so we can use them when drawing links
  381. nodeColumns.forEach(function (column) {
  382. column.forEach(function (node) {
  383. series.translateNode(node, column);
  384. });
  385. }, this);
  386. // Then translate links
  387. this.nodes.forEach(function (node) {
  388. // Translate the links from this node
  389. node.linksFrom.forEach(function (linkPoint) {
  390. // If weight is 0 - don't render the link path #12453,
  391. // render null points (for organization chart)
  392. if ((linkPoint.weight || linkPoint.isNull) && linkPoint.to) {
  393. series.translateLink(linkPoint);
  394. linkPoint.allowShadow = false;
  395. }
  396. });
  397. });
  398. };
  399. /**
  400. * Run translation operations for one link.
  401. * @private
  402. */
  403. SankeySeries.prototype.translateLink = function (point) {
  404. var getY = function (node, fromOrTo) {
  405. var linkTop = (node.offset(point, fromOrTo) *
  406. translationFactor);
  407. var y = Math.min(node.nodeY + linkTop,
  408. // Prevent links from spilling below the node (#12014)
  409. node.nodeY + (node.shapeArgs && node.shapeArgs.height || 0) - linkHeight);
  410. return y;
  411. };
  412. 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) *
  413. 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;
  414. if (chart.inverted) {
  415. fromY = chart.plotSizeY - fromY;
  416. toY = (chart.plotSizeY || 0) - toY;
  417. right = chart.plotSizeX - right;
  418. nodeW = -nodeW;
  419. linkHeight = -linkHeight;
  420. straight = nodeLeft > right;
  421. }
  422. point.shapeType = 'path';
  423. point.linkBase = [
  424. fromY,
  425. fromY + linkHeight,
  426. toY,
  427. toY + linkHeight
  428. ];
  429. // Links going from left to right
  430. if (straight && typeof toY === 'number') {
  431. point.shapeArgs = {
  432. d: [
  433. ['M', nodeLeft + nodeW, fromY],
  434. [
  435. 'C',
  436. nodeLeft + nodeW + curvy,
  437. fromY,
  438. right - curvy,
  439. toY,
  440. right,
  441. toY
  442. ],
  443. ['L', right + (outgoing ? nodeW : 0), toY + linkHeight / 2],
  444. ['L', right, toY + linkHeight],
  445. [
  446. 'C',
  447. right - curvy,
  448. toY + linkHeight,
  449. nodeLeft + nodeW + curvy,
  450. fromY + linkHeight,
  451. nodeLeft + nodeW, fromY + linkHeight
  452. ],
  453. ['Z']
  454. ]
  455. };
  456. // Experimental: Circular links pointing backwards. In
  457. // v6.1.0 this breaks the rendering completely, so even
  458. // this experimental rendering is an improvement. #8218.
  459. // @todo
  460. // - Make room for the link in the layout
  461. // - Automatically determine if the link should go up or
  462. // down.
  463. }
  464. else if (typeof toY === 'number') {
  465. var bend = 20, vDist = chart.plotHeight - fromY - linkHeight, x1 = right - bend - linkHeight, x2 = right - bend, x3 = right, x4 = nodeLeft + nodeW, x5 = x4 + bend, x6 = x5 + linkHeight, fy1 = fromY, fy2 = fromY + linkHeight, fy3 = fy2 + bend, y4 = fy3 + vDist, y5 = y4 + bend, y6 = y5 + linkHeight, ty1 = toY, ty2 = ty1 + linkHeight, ty3 = ty2 + bend, cfy1 = fy2 - linkHeight * 0.7, cy2 = y5 + linkHeight * 0.7, cty1 = ty2 - linkHeight * 0.7, cx1 = x3 - linkHeight * 0.7, cx2 = x4 + linkHeight * 0.7;
  466. point.shapeArgs = {
  467. d: [
  468. ['M', x4, fy1],
  469. ['C', cx2, fy1, x6, cfy1, x6, fy3],
  470. ['L', x6, y4],
  471. ['C', x6, cy2, cx2, y6, x4, y6],
  472. ['L', x3, y6],
  473. ['C', cx1, y6, x1, cy2, x1, y4],
  474. ['L', x1, ty3],
  475. ['C', x1, cty1, cx1, ty1, x3, ty1],
  476. ['L', x3, ty2],
  477. ['C', x2, ty2, x2, ty2, x2, ty3],
  478. ['L', x2, y4],
  479. ['C', x2, y5, x2, y5, x3, y5],
  480. ['L', x4, y5],
  481. ['C', x5, y5, x5, y5, x5, y4],
  482. ['L', x5, fy3],
  483. ['C', x5, fy2, x5, fy2, x4, fy2],
  484. ['Z']
  485. ]
  486. };
  487. }
  488. // Place data labels in the middle
  489. point.dlBox = {
  490. x: nodeLeft + (right - nodeLeft + nodeW) / 2,
  491. y: fromY + (toY - fromY) / 2,
  492. height: linkHeight,
  493. width: 0
  494. };
  495. // And set the tooltip anchor in the middle
  496. point.tooltipPos = chart.inverted ? [
  497. chart.plotSizeY - point.dlBox.y - linkHeight / 2,
  498. chart.plotSizeX - point.dlBox.x
  499. ] : [
  500. point.dlBox.x,
  501. point.dlBox.y + linkHeight / 2
  502. ];
  503. // Pass test in drawPoints
  504. point.y = point.plotY = 1;
  505. if (!point.color) {
  506. point.color = fromNode.color;
  507. }
  508. };
  509. /**
  510. * Run translation operations for one node.
  511. * @private
  512. */
  513. SankeySeries.prototype.translateNode = function (node, column) {
  514. var translationFactor = this.translationFactor, chart = this.chart, options = this.options, sum = node.getSum(), nodeHeight = Math.max(Math.round(sum * translationFactor), this.options.minLinkWidth), crisp = Math.round(options.borderWidth) % 2 / 2, nodeOffset = column.offset(node, translationFactor), fromNodeTop = Math.floor(pick(nodeOffset.absoluteTop, (column.top(translationFactor) +
  515. nodeOffset.relativeTop))) + crisp, left = Math.floor(this.colDistance * node.column +
  516. options.borderWidth / 2) + crisp, nodeLeft = chart.inverted ?
  517. chart.plotSizeX - left :
  518. left, nodeWidth = Math.round(this.nodeWidth);
  519. node.sum = sum;
  520. // If node sum is 0, don't render the rect #12453
  521. if (sum) {
  522. // Draw the node
  523. node.shapeType = 'rect';
  524. node.nodeX = nodeLeft;
  525. node.nodeY = fromNodeTop;
  526. var x = nodeLeft, y = fromNodeTop, width = node.options.width || options.width || nodeWidth, height = node.options.height || options.height || nodeHeight;
  527. if (chart.inverted) {
  528. x = nodeLeft - nodeWidth;
  529. y = chart.plotSizeY - fromNodeTop - nodeHeight;
  530. width = node.options.height || options.height || nodeWidth;
  531. height = node.options.width || options.width || nodeHeight;
  532. }
  533. // Calculate data label options for the point
  534. node.dlOptions = SankeySeries.getDLOptions({
  535. level: this.mapOptionsToLevel[node.level],
  536. optionsPoint: node.options
  537. });
  538. // Pass test in drawPoints
  539. node.plotX = 1;
  540. node.plotY = 1;
  541. // Set the anchor position for tooltips
  542. node.tooltipPos = chart.inverted ? [
  543. chart.plotSizeY - y - height / 2,
  544. chart.plotSizeX - x - width / 2
  545. ] : [
  546. x + width / 2,
  547. y + height / 2
  548. ];
  549. node.shapeArgs = {
  550. x: x,
  551. y: y,
  552. width: width,
  553. height: height,
  554. display: node.hasShape() ? '' : 'none'
  555. };
  556. }
  557. else {
  558. node.dlOptions = {
  559. enabled: false
  560. };
  561. }
  562. };
  563. /**
  564. * A sankey diagram is a type of flow diagram, in which the width of the
  565. * link between two nodes is shown proportionally to the flow quantity.
  566. *
  567. * @sample highcharts/demo/sankey-diagram/
  568. * Sankey diagram
  569. * @sample highcharts/plotoptions/sankey-inverted/
  570. * Inverted sankey diagram
  571. * @sample highcharts/plotoptions/sankey-outgoing
  572. * Sankey diagram with outgoing links
  573. *
  574. * @extends plotOptions.column
  575. * @since 6.0.0
  576. * @product highcharts
  577. * @excluding animationLimit, boostThreshold, borderRadius,
  578. * crisp, cropThreshold, colorAxis, colorKey, depth, dragDrop,
  579. * edgeColor, edgeWidth, findNearestPointBy, grouping,
  580. * groupPadding, groupZPadding, maxPointWidth, negativeColor,
  581. * pointInterval, pointIntervalUnit, pointPadding,
  582. * pointPlacement, pointRange, pointStart, pointWidth,
  583. * shadow, softThreshold, stacking, threshold, zoneAxis,
  584. * zones, minPointLength, dataSorting, boostBlending
  585. * @requires modules/sankey
  586. * @optionparent plotOptions.sankey
  587. */
  588. SankeySeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  589. borderWidth: 0,
  590. colorByPoint: true,
  591. /**
  592. * Higher numbers makes the links in a sankey diagram or dependency
  593. * wheelrender more curved. A `curveFactor` of 0 makes the lines
  594. * straight.
  595. *
  596. * @private
  597. */
  598. curveFactor: 0.33,
  599. /**
  600. * Options for the data labels appearing on top of the nodes and links.
  601. * For sankey charts, data labels are visible for the nodes by default,
  602. * but hidden for links. This is controlled by modifying the
  603. * `nodeFormat`, and the `format` that applies to links and is an empty
  604. * string by default.
  605. *
  606. * @declare Highcharts.SeriesSankeyDataLabelsOptionsObject
  607. *
  608. * @private
  609. */
  610. dataLabels: {
  611. enabled: true,
  612. backgroundColor: 'none',
  613. crop: false,
  614. /**
  615. * The
  616. * [format string](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  617. * specifying what to show for _nodes_ in the sankey diagram. By
  618. * default the `nodeFormatter` returns `{point.name}`.
  619. *
  620. * @sample highcharts/plotoptions/sankey-link-datalabels/
  621. * Node and link data labels
  622. *
  623. * @type {string}
  624. */
  625. nodeFormat: void 0,
  626. // eslint-disable-next-line valid-jsdoc
  627. /**
  628. * Callback to format data labels for _nodes_ in the sankey diagram.
  629. * The `nodeFormat` option takes precedence over the
  630. * `nodeFormatter`.
  631. *
  632. * @type {Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction}
  633. * @since 6.0.2
  634. */
  635. nodeFormatter: function () {
  636. return this.point.name;
  637. },
  638. format: void 0,
  639. // eslint-disable-next-line valid-jsdoc
  640. /**
  641. * @type {Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction}
  642. */
  643. formatter: function () {
  644. return;
  645. },
  646. inside: true
  647. },
  648. /**
  649. * @ignore-option
  650. *
  651. * @private
  652. */
  653. inactiveOtherPoints: true,
  654. /**
  655. * Set options on specific levels. Takes precedence over series options,
  656. * but not node and link options.
  657. *
  658. * @sample highcharts/demo/sunburst
  659. * Sunburst chart
  660. *
  661. * @type {Array<*>}
  662. * @since 7.1.0
  663. * @apioption plotOptions.sankey.levels
  664. */
  665. /**
  666. * Can set `borderColor` on all nodes which lay on the same level.
  667. *
  668. * @type {Highcharts.ColorString}
  669. * @apioption plotOptions.sankey.levels.borderColor
  670. */
  671. /**
  672. * Can set `borderWidth` on all nodes which lay on the same level.
  673. *
  674. * @type {number}
  675. * @apioption plotOptions.sankey.levels.borderWidth
  676. */
  677. /**
  678. * Can set `color` on all nodes which lay on the same level.
  679. *
  680. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  681. * @apioption plotOptions.sankey.levels.color
  682. */
  683. /**
  684. * Can set `colorByPoint` on all nodes which lay on the same level.
  685. *
  686. * @type {boolean}
  687. * @default true
  688. * @apioption plotOptions.sankey.levels.colorByPoint
  689. */
  690. /**
  691. * Can set `dataLabels` on all points which lay on the same level.
  692. *
  693. * @extends plotOptions.sankey.dataLabels
  694. * @apioption plotOptions.sankey.levels.dataLabels
  695. */
  696. /**
  697. * Decides which level takes effect from the options set in the levels
  698. * object.
  699. *
  700. * @type {number}
  701. * @apioption plotOptions.sankey.levels.level
  702. */
  703. /**
  704. * Can set `linkOpacity` on all points which lay on the same level.
  705. *
  706. * @type {number}
  707. * @default 0.5
  708. * @apioption plotOptions.sankey.levels.linkOpacity
  709. */
  710. /**
  711. * Can set `states` on all nodes and points which lay on the same level.
  712. *
  713. * @extends plotOptions.sankey.states
  714. * @apioption plotOptions.sankey.levels.states
  715. */
  716. /**
  717. * Opacity for the links between nodes in the sankey diagram.
  718. *
  719. * @private
  720. */
  721. linkOpacity: 0.5,
  722. /**
  723. * The minimal width for a line of a sankey. By default,
  724. * 0 values are not shown.
  725. *
  726. * @sample highcharts/plotoptions/sankey-minlinkwidth
  727. * Sankey diagram with minimal link height
  728. *
  729. * @type {number}
  730. * @since 7.1.3
  731. * @default 0
  732. * @apioption plotOptions.sankey.minLinkWidth
  733. *
  734. * @private
  735. */
  736. minLinkWidth: 0,
  737. /**
  738. * The pixel width of each node in a sankey diagram or dependency wheel,
  739. * or the height in case the chart is inverted.
  740. *
  741. * @private
  742. */
  743. nodeWidth: 20,
  744. /**
  745. * The padding between nodes in a sankey diagram or dependency wheel, in
  746. * pixels.
  747. *
  748. * If the number of nodes is so great that it is possible to lay them
  749. * out within the plot area with the given `nodePadding`, they will be
  750. * rendered with a smaller padding as a strategy to avoid overflow.
  751. *
  752. * @private
  753. */
  754. nodePadding: 10,
  755. showInLegend: false,
  756. states: {
  757. hover: {
  758. /**
  759. * Opacity for the links between nodes in the sankey diagram in
  760. * hover mode.
  761. */
  762. linkOpacity: 1
  763. },
  764. /**
  765. * The opposite state of a hover for a single point node/link.
  766. *
  767. * @declare Highcharts.SeriesStatesInactiveOptionsObject
  768. */
  769. inactive: {
  770. /**
  771. * Opacity for the links between nodes in the sankey diagram in
  772. * inactive mode.
  773. */
  774. linkOpacity: 0.1,
  775. /**
  776. * Opacity of inactive markers.
  777. *
  778. * @type {number}
  779. * @apioption plotOptions.series.states.inactive.opacity
  780. */
  781. opacity: 0.1,
  782. /**
  783. * Animation when not hovering over the marker.
  784. *
  785. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  786. * @apioption plotOptions.series.states.inactive.animation
  787. */
  788. animation: {
  789. /** @internal */
  790. duration: 50
  791. }
  792. }
  793. },
  794. tooltip: {
  795. /**
  796. * A callback for defining the format for _nodes_ in the chart's
  797. * tooltip, as opposed to links.
  798. *
  799. * @type {Highcharts.FormatterCallbackFunction<Highcharts.SankeyNodeObject>}
  800. * @since 6.0.2
  801. * @apioption plotOptions.sankey.tooltip.nodeFormatter
  802. */
  803. /**
  804. * Whether the tooltip should follow the pointer or stay fixed on
  805. * the item.
  806. */
  807. followPointer: true,
  808. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  809. pointFormat: '{point.fromNode.name} \u2192 {point.toNode.name}: <b>{point.weight}</b><br/>',
  810. /**
  811. * The
  812. * [format string](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  813. * specifying what to show for _nodes_ in tooltip of a diagram
  814. * series, as opposed to links.
  815. */
  816. nodeFormat: '{point.name}: <b>{point.sum}</b><br/>'
  817. }
  818. });
  819. return SankeySeries;
  820. }(ColumnSeries));
  821. extend(SankeySeries.prototype, {
  822. animate: Series.prototype.animate,
  823. // Create a single node that holds information on incoming and outgoing
  824. // links.
  825. createNode: NodesMixin.createNode,
  826. destroy: NodesMixin.destroy,
  827. forceDL: true,
  828. invertible: true,
  829. isCartesian: false,
  830. orderNodes: true,
  831. pointArrayMap: ['from', 'to'],
  832. pointClass: SankeyPoint,
  833. searchPoint: H.noop,
  834. setData: NodesMixin.setData
  835. });
  836. SeriesRegistry.registerSeriesType('sankey', SankeySeries);
  837. /* *
  838. *
  839. * Default Export
  840. *
  841. * */
  842. export default SankeySeries;
  843. /* *
  844. *
  845. * API Declarations
  846. *
  847. * */
  848. /**
  849. * A node in a sankey diagram.
  850. *
  851. * @interface Highcharts.SankeyNodeObject
  852. * @extends Highcharts.Point
  853. * @product highcharts
  854. */ /**
  855. * The color of the auto generated node.
  856. *
  857. * @name Highcharts.SankeyNodeObject#color
  858. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  859. */ /**
  860. * The color index of the auto generated node, especially for use in styled
  861. * mode.
  862. *
  863. * @name Highcharts.SankeyNodeObject#colorIndex
  864. * @type {number}
  865. */ /**
  866. * An optional column index of where to place the node. The default behaviour is
  867. * to place it next to the preceding node.
  868. *
  869. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/sankey-node-column/|Highcharts-Demo:}
  870. * Specified node column
  871. *
  872. * @name Highcharts.SankeyNodeObject#column
  873. * @type {number}
  874. * @since 6.0.5
  875. */ /**
  876. * The id of the auto-generated node, refering to the `from` or `to` setting of
  877. * the link.
  878. *
  879. * @name Highcharts.SankeyNodeObject#id
  880. * @type {string}
  881. */ /**
  882. * The name to display for the node in data labels and tooltips. Use this when
  883. * the name is different from the `id`. Where the id must be unique for each
  884. * node, this is not necessary for the name.
  885. *
  886. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/css/sankey/|Highcharts-Demo:}
  887. * Sankey diagram with node options
  888. *
  889. * @name Highcharts.SankeyNodeObject#name
  890. * @type {string}
  891. * @product highcharts
  892. */ /**
  893. * The vertical offset of a node in terms of weight. Positive values shift the
  894. * node downwards, negative shift it upwards.
  895. *
  896. * @see {@link https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/sankey-node-column/|Highcharts-Demo:}
  897. * Specified node offset
  898. *
  899. * @name Highcharts.SankeyNodeObject#offset
  900. * @type {number}
  901. * @default 0
  902. * @since 6.0.5
  903. */
  904. /**
  905. * Formatter callback function.
  906. *
  907. * @callback Highcharts.SeriesSankeyDataLabelsFormatterCallbackFunction
  908. *
  909. * @param {Highcharts.SeriesSankeyDataLabelsFormatterContextObject|Highcharts.PointLabelObject} this
  910. * Data label context to format
  911. *
  912. * @return {string|undefined}
  913. * Formatted data label text
  914. */
  915. /**
  916. * Context for the node formatter function.
  917. *
  918. * @interface Highcharts.SeriesSankeyDataLabelsFormatterContextObject
  919. * @extends Highcharts.PointLabelObject
  920. */ /**
  921. * The node object. The node name, if defined, is available through
  922. * `this.point.name`.
  923. * @name Highcharts.SeriesSankeyDataLabelsFormatterContextObject#point
  924. * @type {Highcharts.SankeyNodeObject}
  925. */
  926. ''; // detach doclets above
  927. /* *
  928. *
  929. * API Options
  930. *
  931. * */
  932. /**
  933. * A `sankey` series. If the [type](#series.sankey.type) option is not
  934. * specified, it is inherited from [chart.type](#chart.type).
  935. *
  936. * @extends series,plotOptions.sankey
  937. * @excluding animationLimit, boostBlending, boostThreshold, borderColor,
  938. * borderRadius, borderWidth, crisp, cropThreshold, dataParser,
  939. * dataURL, depth, dragDrop, edgeColor, edgeWidth,
  940. * findNearestPointBy, getExtremesFromAll, grouping, groupPadding,
  941. * groupZPadding, label, maxPointWidth, negativeColor, pointInterval,
  942. * pointIntervalUnit, pointPadding, pointPlacement, pointRange,
  943. * pointStart, pointWidth, shadow, softThreshold, stacking,
  944. * threshold, zoneAxis, zones, dataSorting
  945. * @product highcharts
  946. * @requires modules/sankey
  947. * @apioption series.sankey
  948. */
  949. /**
  950. * A collection of options for the individual nodes. The nodes in a sankey
  951. * diagram are auto-generated instances of `Highcharts.Point`, but options can
  952. * be applied here and linked by the `id`.
  953. *
  954. * @sample highcharts/css/sankey/
  955. * Sankey diagram with node options
  956. *
  957. * @declare Highcharts.SeriesSankeyNodesOptionsObject
  958. * @type {Array<*>}
  959. * @product highcharts
  960. * @apioption series.sankey.nodes
  961. */
  962. /**
  963. * The id of the auto-generated node, refering to the `from` or `to` setting of
  964. * the link.
  965. *
  966. * @type {string}
  967. * @product highcharts
  968. * @apioption series.sankey.nodes.id
  969. */
  970. /**
  971. * The color of the auto generated node.
  972. *
  973. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  974. * @product highcharts
  975. * @apioption series.sankey.nodes.color
  976. */
  977. /**
  978. * The color index of the auto generated node, especially for use in styled
  979. * mode.
  980. *
  981. * @type {number}
  982. * @product highcharts
  983. * @apioption series.sankey.nodes.colorIndex
  984. */
  985. /**
  986. * An optional column index of where to place the node. The default behaviour is
  987. * to place it next to the preceding node. Note that this option name is
  988. * counter intuitive in inverted charts, like for example an organization chart
  989. * rendered top down. In this case the "columns" are horizontal.
  990. *
  991. * @sample highcharts/plotoptions/sankey-node-column/
  992. * Specified node column
  993. *
  994. * @type {number}
  995. * @since 6.0.5
  996. * @product highcharts
  997. * @apioption series.sankey.nodes.column
  998. */
  999. /**
  1000. * Individual data label for each node. The options are the same as
  1001. * the ones for [series.sankey.dataLabels](#series.sankey.dataLabels).
  1002. *
  1003. * @extends plotOptions.sankey.dataLabels
  1004. * @apioption series.sankey.nodes.dataLabels
  1005. */
  1006. /**
  1007. * An optional level index of where to place the node. The default behaviour is
  1008. * to place it next to the preceding node. Alias of `nodes.column`, but in
  1009. * inverted sankeys and org charts, the levels are laid out as rows.
  1010. *
  1011. * @type {number}
  1012. * @since 7.1.0
  1013. * @product highcharts
  1014. * @apioption series.sankey.nodes.level
  1015. */
  1016. /**
  1017. * The name to display for the node in data labels and tooltips. Use this when
  1018. * the name is different from the `id`. Where the id must be unique for each
  1019. * node, this is not necessary for the name.
  1020. *
  1021. * @sample highcharts/css/sankey/
  1022. * Sankey diagram with node options
  1023. *
  1024. * @type {string}
  1025. * @product highcharts
  1026. * @apioption series.sankey.nodes.name
  1027. */
  1028. /**
  1029. * In a horizontal layout, the vertical offset of a node in terms of weight.
  1030. * Positive values shift the node downwards, negative shift it upwards. In a
  1031. * vertical layout, like organization chart, the offset is horizontal.
  1032. *
  1033. * If a percantage string is given, the node is offset by the percentage of the
  1034. * node size plus `nodePadding`.
  1035. *
  1036. * @sample highcharts/plotoptions/sankey-node-column/
  1037. * Specified node offset
  1038. *
  1039. * @type {number|string}
  1040. * @default 0
  1041. * @since 6.0.5
  1042. * @product highcharts
  1043. * @apioption series.sankey.nodes.offset
  1044. */
  1045. /**
  1046. * An array of data points for the series. For the `sankey` series type,
  1047. * points can be given in the following way:
  1048. *
  1049. * An array of objects with named values. The following snippet shows only a
  1050. * few settings, see the complete options set below. If the total number of data
  1051. * points exceeds the series' [turboThreshold](#series.area.turboThreshold),
  1052. * this option is not available.
  1053. *
  1054. * ```js
  1055. * data: [{
  1056. * from: 'Category1',
  1057. * to: 'Category2',
  1058. * weight: 2
  1059. * }, {
  1060. * from: 'Category1',
  1061. * to: 'Category3',
  1062. * weight: 5
  1063. * }]
  1064. * ```
  1065. *
  1066. * @sample {highcharts} highcharts/series/data-array-of-objects/
  1067. * Config objects
  1068. *
  1069. * @declare Highcharts.SeriesSankeyPointOptionsObject
  1070. * @type {Array<*>}
  1071. * @extends series.line.data
  1072. * @excluding dragDrop, drilldown, marker, x, y
  1073. * @product highcharts
  1074. * @apioption series.sankey.data
  1075. */
  1076. /**
  1077. * The color for the individual _link_. By default, the link color is the same
  1078. * as the node it extends from. The `series.fillOpacity` option also applies to
  1079. * the points, so when setting a specific link color, consider setting the
  1080. * `fillOpacity` to 1.
  1081. *
  1082. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1083. * @product highcharts
  1084. * @apioption series.sankey.data.color
  1085. */
  1086. /**
  1087. * @type {Highcharts.SeriesSankeyDataLabelsOptionsObject|Array<Highcharts.SeriesSankeyDataLabelsOptionsObject>}
  1088. * @product highcharts
  1089. * @apioption series.sankey.data.dataLabels
  1090. */
  1091. /**
  1092. * The node that the link runs from.
  1093. *
  1094. * @type {string}
  1095. * @product highcharts
  1096. * @apioption series.sankey.data.from
  1097. */
  1098. /**
  1099. * The node that the link runs to.
  1100. *
  1101. * @type {string}
  1102. * @product highcharts
  1103. * @apioption series.sankey.data.to
  1104. */
  1105. /**
  1106. * Whether the link goes out of the system.
  1107. *
  1108. * @sample highcharts/plotoptions/sankey-outgoing
  1109. * Sankey chart with outgoing links
  1110. *
  1111. * @type {boolean}
  1112. * @default false
  1113. * @product highcharts
  1114. * @apioption series.sankey.data.outgoing
  1115. */
  1116. /**
  1117. * The weight of the link.
  1118. *
  1119. * @type {number|null}
  1120. * @product highcharts
  1121. * @apioption series.sankey.data.weight
  1122. */
  1123. ''; // adds doclets above to transpiled file